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,165 @@
|
|
|
1
|
+
// askKitPrompt:命令式的自绘输入对话框(取代浏览器原生 prompt,全 kit 只此一份实现;与 askKitConfirm 同族)。
|
|
2
|
+
//
|
|
3
|
+
// 壳用 mountKitModal(经 core 浮层端口挂出:Esc 走层栈只关栈顶、Tab 焦点陷阱、关闭后回焦);本文件只补字段与按钮:
|
|
4
|
+
// - 返回 Promise<Record<string, string> | null>:确认 = { 字段名: 值 };取消 / Esc / 点遮罩 / 关闭 = null。调用方一律 await;
|
|
5
|
+
// - 字段 type 只有 text(单行,Enter 提交)与 textarea(多行,Ctrl / ⌘ + Enter 提交);required 的字段空白时就地报错、不关窗;
|
|
6
|
+
// - 文案只用 textContent / value 写入,不经 innerHTML;
|
|
7
|
+
// - 值一律是字符串(原样,不 trim);调用方按需处理空串;
|
|
8
|
+
// - 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 null)。
|
|
9
|
+
// 页面里的 request.prompt(点动作先问再发请求)由页面级 KitActionHost 调本函数;展示对象里用 ctx.prompt。
|
|
10
|
+
|
|
11
|
+
import { kitText } from '../i18n/kit-text';
|
|
12
|
+
import { kitControlRecipe, kitTypographyRecipe, setKitFace } from '../recipes';
|
|
13
|
+
import { KIT_ERROR_TEXT } from '../recipes/typography';
|
|
14
|
+
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
15
|
+
import { KIT_DIALOG_HINT_CLASS, KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, kitDialogButton } from './confirm-dialog';
|
|
16
|
+
import { classTokens } from './shape-util';
|
|
17
|
+
|
|
18
|
+
const FIELD_CLASS = 'flex flex-col gap-1';
|
|
19
|
+
const LABEL_CLASS = kitTypographyRecipe('label');
|
|
20
|
+
const TEXTAREA_CLASS = kitControlRecipe({ multiline: true });
|
|
21
|
+
const ERROR_CLASS = KIT_ERROR_TEXT;
|
|
22
|
+
|
|
23
|
+
export const KIT_PROMPT_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
24
|
+
FIELD_CLASS, LABEL_CLASS, TEXTAREA_CLASS, ERROR_CLASS, KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, KIT_DIALOG_HINT_CLASS, KIT_MODAL_CLASS_CANDIDATES,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export interface KitPromptField {
|
|
28
|
+
/** 结果里的键 */
|
|
29
|
+
name: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
/** text(单行,缺省)/ textarea(多行) */
|
|
32
|
+
type?: 'text' | 'textarea';
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
initial?: string;
|
|
35
|
+
/** 必填:空白(去空格后为空)时就地报错、不关窗 */
|
|
36
|
+
required?: boolean;
|
|
37
|
+
/** 必填报错文案,缺省取词条「此项必填」 */
|
|
38
|
+
requiredMessage?: string;
|
|
39
|
+
help?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface KitPromptOptions {
|
|
43
|
+
title?: string;
|
|
44
|
+
/** 正文说明(纯文本) */
|
|
45
|
+
message?: string;
|
|
46
|
+
fields: readonly KitPromptField[];
|
|
47
|
+
submitLabel?: string;
|
|
48
|
+
cancelLabel?: string;
|
|
49
|
+
/** 调用方元素:取页面语言与书写方向,也是回焦参照 */
|
|
50
|
+
at?: Element | null;
|
|
51
|
+
/** 没有 DOM 时的结果,缺省 null */
|
|
52
|
+
whenNoDom?: Record<string, string> | null;
|
|
53
|
+
/** 调用方卸载 / 作废时中止:已中止直接 resolve(null);打开后中止就关闭对话框并 resolve(null) */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type Control = HTMLInputElement | HTMLTextAreaElement;
|
|
58
|
+
|
|
59
|
+
export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, string> | null> {
|
|
60
|
+
if (opts.signal?.aborted === true) return Promise.resolve(null);
|
|
61
|
+
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom ?? null);
|
|
62
|
+
const doc = opts.at?.ownerDocument ?? document;
|
|
63
|
+
return new Promise<Record<string, string> | null>((resolve) => {
|
|
64
|
+
let settled = false;
|
|
65
|
+
const modal = mountKitModal({
|
|
66
|
+
title: opts.title ?? kitText('soma.kit.confirm', undefined, opts.at),
|
|
67
|
+
size: 'sm',
|
|
68
|
+
at: opts.at ?? null,
|
|
69
|
+
showClose: false,
|
|
70
|
+
dismissOnScrim: false,
|
|
71
|
+
onClose: () => finish(null),
|
|
72
|
+
}, doc);
|
|
73
|
+
let watch: MutationObserver | null = null;
|
|
74
|
+
const finish = (value: Record<string, string> | null): void => {
|
|
75
|
+
if (settled) return;
|
|
76
|
+
settled = true;
|
|
77
|
+
watch?.disconnect();
|
|
78
|
+
watch = null;
|
|
79
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
80
|
+
modal.close();
|
|
81
|
+
modal.destroy();
|
|
82
|
+
resolve(value);
|
|
83
|
+
};
|
|
84
|
+
const onAbort = (): void => finish(null);
|
|
85
|
+
|
|
86
|
+
if (opts.message !== undefined && opts.message !== '') {
|
|
87
|
+
const msg = doc.createElement('p');
|
|
88
|
+
msg.className = KIT_DIALOG_MESSAGE_CLASS;
|
|
89
|
+
msg.textContent = opts.message;
|
|
90
|
+
modal.body.appendChild(msg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const controls: Array<{ field: KitPromptField; control: Control; error: HTMLElement }> = [];
|
|
94
|
+
opts.fields.forEach((field, i) => {
|
|
95
|
+
const wrap = doc.createElement('div');
|
|
96
|
+
wrap.className = FIELD_CLASS;
|
|
97
|
+
const id = `kit-prompt-${i}-${Math.random().toString(36).slice(2, 8)}`;
|
|
98
|
+
if (field.label !== undefined && field.label !== '') {
|
|
99
|
+
const label = doc.createElement('label');
|
|
100
|
+
label.className = LABEL_CLASS;
|
|
101
|
+
label.htmlFor = id;
|
|
102
|
+
label.textContent = field.required === true ? `${field.label} *` : field.label;
|
|
103
|
+
wrap.appendChild(label);
|
|
104
|
+
}
|
|
105
|
+
const multi = field.type === 'textarea';
|
|
106
|
+
const control: Control = multi ? doc.createElement('textarea') : doc.createElement('input');
|
|
107
|
+
if (control instanceof HTMLInputElement) { control.type = 'text'; control.autocomplete = 'off'; }
|
|
108
|
+
control.id = id;
|
|
109
|
+
control.className = multi ? TEXTAREA_CLASS : KIT_DIALOG_INPUT_CLASS;
|
|
110
|
+
setKitFace(control, 'field');
|
|
111
|
+
control.value = field.initial ?? '';
|
|
112
|
+
if (field.placeholder !== undefined) control.placeholder = field.placeholder;
|
|
113
|
+
wrap.appendChild(control);
|
|
114
|
+
const error = doc.createElement('p');
|
|
115
|
+
error.className = ERROR_CLASS;
|
|
116
|
+
error.hidden = true;
|
|
117
|
+
error.setAttribute('role', 'alert');
|
|
118
|
+
wrap.appendChild(error);
|
|
119
|
+
if (field.help !== undefined && field.help !== '') {
|
|
120
|
+
const help = doc.createElement('p');
|
|
121
|
+
help.className = KIT_DIALOG_HINT_CLASS;
|
|
122
|
+
help.textContent = field.help;
|
|
123
|
+
wrap.appendChild(help);
|
|
124
|
+
}
|
|
125
|
+
control.addEventListener('input', () => { error.hidden = true; error.textContent = ''; });
|
|
126
|
+
control.addEventListener('keydown', (event: Event) => {
|
|
127
|
+
const e = event as KeyboardEvent;
|
|
128
|
+
if (e.key !== 'Enter') return;
|
|
129
|
+
if (multi ? (e.ctrlKey || e.metaKey) : !e.isComposing) { e.preventDefault(); submit(); }
|
|
130
|
+
});
|
|
131
|
+
modal.body.appendChild(wrap);
|
|
132
|
+
controls.push({ field, control, error });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const submit = (): void => {
|
|
136
|
+
let first: Control | null = null;
|
|
137
|
+
for (const { field, control, error } of controls) {
|
|
138
|
+
if (field.required === true && control.value.trim() === '') {
|
|
139
|
+
error.textContent = field.requiredMessage ?? kitText('soma.kit.field_required', undefined, opts.at);
|
|
140
|
+
error.hidden = false;
|
|
141
|
+
first ??= control;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (first !== null) { first.focus(); return; }
|
|
145
|
+
const out: Record<string, string> = {};
|
|
146
|
+
for (const { field, control } of controls) out[field.name] = control.value;
|
|
147
|
+
finish(out);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const cancel = kitDialogButton(doc, 'neutral', opts.cancelLabel ?? kitText('soma.kit.cancel', undefined, opts.at));
|
|
151
|
+
cancel.addEventListener('click', () => finish(null));
|
|
152
|
+
const ok = kitDialogButton(doc, 'primary', opts.submitLabel ?? kitText('soma.kit.ok', undefined, opts.at));
|
|
153
|
+
ok.addEventListener('click', submit);
|
|
154
|
+
modal.footer.append(cancel, ok);
|
|
155
|
+
|
|
156
|
+
(opts.at?.isConnected === true ? opts.at.parentNode ?? doc.body : doc.body).appendChild(modal.layer);
|
|
157
|
+
modal.open();
|
|
158
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
159
|
+
watch = new MutationObserver(() => { if (!modal.layer.isConnected) finish(null); });
|
|
160
|
+
watch.observe(doc.body, { childList: true, subtree: true });
|
|
161
|
+
}
|
|
162
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
163
|
+
(controls[0]?.control ?? ok).focus();
|
|
164
|
+
});
|
|
165
|
+
}
|
package/src/data/reaction-bar.ts
CHANGED
|
@@ -13,15 +13,17 @@ import { setKitFace } from '../recipes';
|
|
|
13
13
|
import { classTokens, mk, rowsOf, textOf } from './shape-util';
|
|
14
14
|
import { REACTION_MAX_KINDS, REACTION_PALETTE } from './d9-limits';
|
|
15
15
|
import { attrEsc } from './d9-util';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
17
19
|
|
|
18
20
|
const ROOT_CLASS = 'relative flex flex-wrap items-center gap-2 text-sm text-fg';
|
|
19
|
-
const PILL_CLASS = 'inline-flex h-7 items-center gap-1 rounded-full border border-border bg-surface px-2.5 text-xs text-fg transition-colors
|
|
21
|
+
const PILL_CLASS = 'inline-flex h-7 items-center gap-1 rounded-full border border-border bg-surface px-2.5 text-xs text-fg transition-colors state-layer active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
20
22
|
const PILL_MINE = 'inline-flex h-7 items-center gap-1 rounded-full border border-primary bg-primary-soft px-2.5 text-xs font-medium text-primary-on-soft transition-colors hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
21
|
-
const ADD_CLASS = 'inline-flex size-7 items-center justify-center rounded-full border border-dashed border-border bg-surface text-sm text-fg-muted transition-colors
|
|
22
|
-
const PANEL_BASE_CLASS = 'absolute z-20 flex flex-wrap gap-1
|
|
23
|
+
const ADD_CLASS = 'inline-flex size-7 p-0 items-center justify-center rounded-full border border-dashed border-border bg-surface text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
24
|
+
const PANEL_BASE_CLASS = mergeClass('absolute z-20 flex flex-wrap gap-1 p-2', kitSurfaceRecipe('raised'));
|
|
23
25
|
const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
|
|
24
|
-
const CHOICE_CLASS = 'inline-flex size-8 items-center justify-center rounded-md text-base transition-colors hover:bg-
|
|
26
|
+
const CHOICE_CLASS = 'inline-flex size-8 p-0 items-center justify-center rounded-md text-base transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
25
27
|
|
|
26
28
|
export const KIT_REACTION_BAR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
27
29
|
ROOT_CLASS, PILL_CLASS, PILL_MINE, ADD_CLASS, PANEL_BASE_CLASS, PANEL_CLASS, CHOICE_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES,
|
package/src/data/record-card.ts
CHANGED
|
@@ -16,10 +16,11 @@ import {
|
|
|
16
16
|
} from './shape-util';
|
|
17
17
|
import { safeImgSrc } from './d9-util';
|
|
18
18
|
import { kitText } from '../i18n/kit-text';
|
|
19
|
+
import { applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS } from '../base/state-panel';
|
|
19
20
|
import type { SomaDataPort } from 'soma-core';
|
|
20
21
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
21
22
|
import { pickPath } from '../object-renderer/path-pick';
|
|
22
|
-
import type
|
|
23
|
+
import { emptyNode, type ShapeTone } from './shape-util';
|
|
23
24
|
|
|
24
25
|
export const KIT_RECORD_CARD_DEFAULT_MAP = Object.freeze({
|
|
25
26
|
title: 'title', subtitle: 'subtitle', status: 'status', tone: 'tone', facts: 'facts', tags: 'tags', progress: 'progress', actions: 'actions',
|
|
@@ -35,7 +36,7 @@ const VARIANT_CLASS: Readonly<Record<KitRecordVariant, string>> = Object.freeze(
|
|
|
35
36
|
filled: 'border border-transparent bg-surface-sunken',
|
|
36
37
|
});
|
|
37
38
|
const VARIANT_INTERACT: Readonly<Record<KitRecordVariant, string>> = Object.freeze({
|
|
38
|
-
outlined: 'cursor-pointer transition-colors
|
|
39
|
+
outlined: 'cursor-pointer transition-colors state-layer active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
39
40
|
elevated: 'cursor-pointer transition-shadow hover:shadow-xl active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
40
41
|
filled: 'cursor-pointer transition-colors hover:bg-surface-raised active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
41
42
|
});
|
|
@@ -155,6 +156,10 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
155
156
|
subscribing = false;
|
|
156
157
|
};
|
|
157
158
|
const currentProps = new WeakMap<HTMLElement, Record<string, unknown>>();
|
|
159
|
+
/** 错误态的重试钮要抛 retry:renderCard 也会被 outcome 回调直接调用(没有 api),所以按根存一份发射函数 */
|
|
160
|
+
const retryEmitters = new WeakMap<HTMLElement, () => void>();
|
|
161
|
+
/** 加载面板「最短显示」期满后重绘本组件(同样按根存,renderCard 没有 api) */
|
|
162
|
+
const repainters = new WeakMap<HTMLElement, () => void>();
|
|
158
163
|
/** 有效的 secret:配了 outcome 就只认请求结果(成功才有,进行中 / 失败 / 空闲都不显示,旧明文随新一轮请求消失);否则读 data.secret */
|
|
159
164
|
const secretOf = (root: HTMLElement, p: Record<string, unknown>, data: Record<string, unknown>, key: string): Record<string, unknown> => {
|
|
160
165
|
const st = outs.get(root);
|
|
@@ -183,10 +188,13 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
183
188
|
secret_hint: { type: 'string', default: '', desc: 'outcome 来源的 secret 说明(如「只显示一次」)' },
|
|
184
189
|
secret_copy_label: { type: 'string', default: '', desc: 'data.secret 的「复制并清除」钮文字;缺省取内置文案(按页面语言)' },
|
|
185
190
|
secret_cleared_text: { type: 'string', default: '', desc: 'data.secret 复制后显示的文字;缺省取内置「已复制」' },
|
|
191
|
+
empty_text: { type: 'string', default: '', desc: '没有记录(data 为空)时的文案;缺省取内置「暂无」文案' },
|
|
192
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
186
193
|
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
187
194
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
188
195
|
},
|
|
189
196
|
emits: {
|
|
197
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
190
198
|
select: { payload: { item: { type: 'object' } }, desc: '点整卡(selectable 时);item 是源数据对象' },
|
|
191
199
|
action: { payload: { key: { type: 'string' } }, desc: '点底部动作' },
|
|
192
200
|
copy: { payload: { key: { type: 'string' }, ok: { type: 'boolean' } }, desc: '点事实对旁的复制钮;key = 该事实的 label(不带文本,避免凭据再次上行)' },
|
|
@@ -263,6 +271,8 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
263
271
|
},
|
|
264
272
|
render(root, p, api) {
|
|
265
273
|
currentProps.set(root, p);
|
|
274
|
+
retryEmitters.set(root, () => { api.emit('retry', {}); });
|
|
275
|
+
repainters.set(root, () => api.refresh());
|
|
266
276
|
ensureOutcome(root, p, api.services);
|
|
267
277
|
renderCard(root, p);
|
|
268
278
|
},
|
|
@@ -286,6 +296,17 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
286
296
|
root.removeAttribute('tabindex');
|
|
287
297
|
}
|
|
288
298
|
root.textContent = '';
|
|
299
|
+
// 读状态(有读接口时编译器自动绑 loading / error_text):记录还没到时读取中 / 读取失败 + 重试,与集合三态同一画法(base/state-panel.ts);
|
|
300
|
+
// 记录已有时错误面板在卡内最前、卡保留,读取中只标 aria-busy
|
|
301
|
+
if (applyKitReadState(root, p, { hasContent: Object.keys(data).length > 0, onRetry: () => retryEmitters.get(root)?.(), repaint: () => repainters.get(root)?.() })) return;
|
|
302
|
+
// 没有记录(data 空、也没有 outcome 来源的 secret):画共享的紧凑空态,不画一张只有空标题的卡
|
|
303
|
+
if (Object.keys(data).length === 0 && Object.keys(secretOf(root, p, data, m.secret ?? 'secret')).length === 0) {
|
|
304
|
+
// 卡根是横排 flex:空态占满整行(否则缩成左上角一小块)
|
|
305
|
+
const empty = emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)), true);
|
|
306
|
+
empty.classList.add('flex-1');
|
|
307
|
+
root.appendChild(empty);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
289
310
|
|
|
290
311
|
// 有 media:根竖排,顶部整幅图 + 下面内容行;无 media 时内容行就是根本身
|
|
291
312
|
let body: HTMLElement = root;
|
|
@@ -24,11 +24,11 @@ import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
|
24
24
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
25
25
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
26
26
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
27
|
-
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
27
|
+
import { applyCompositeField, bool, createKitController, ID_PROPS, INVALID_PROPS, joinClass, num, setAttr, str } from '../base/shared';
|
|
28
28
|
import { kitIcon } from '../base/icons';
|
|
29
29
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
30
30
|
import { setKitFace } from '../recipes';
|
|
31
|
-
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, keyMap, mk, rowsOf, textOf } from './shape-util';
|
|
31
|
+
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, keyMap, mk, retryButton, rowsOf, textOf } from './shape-util';
|
|
32
32
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal, type KitModalHandle, type KitModalSize } from './modal-dialog';
|
|
33
33
|
|
|
34
34
|
// 尺寸闭集读语法,行数 / 选择数上限读 design 的 kit-limits
|
|
@@ -43,15 +43,15 @@ export const KIT_RECORD_PICKER_DEFAULT_MAP = Object.freeze({ id: 'id', title: 't
|
|
|
43
43
|
// ───────── 样式常量 ─────────
|
|
44
44
|
|
|
45
45
|
const ROOT_CLASS = 'flex items-center gap-2';
|
|
46
|
-
const TRIGGER_CLASS = 'inline-flex h-
|
|
46
|
+
const TRIGGER_CLASS = 'inline-flex h-8 min-w-0 flex-1 items-center justify-between gap-2 rounded-md border border-border bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
47
47
|
const TRIGGER_TEXT = 'min-w-0 truncate text-start';
|
|
48
48
|
const TRIGGER_PLACEHOLDER = 'min-w-0 truncate text-start text-fg-subtle';
|
|
49
49
|
const TRIGGER_CARET = 'shrink-0 text-fg-subtle';
|
|
50
|
-
const CLEAR_CLASS = 'inline-flex h-
|
|
50
|
+
const CLEAR_CLASS = 'inline-flex h-8 shrink-0 items-center justify-center rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
51
51
|
const SEARCH_ROW = 'flex items-center gap-2';
|
|
52
|
-
const SEARCH_CLASS = 'block h-
|
|
52
|
+
const SEARCH_CLASS = 'block h-8 min-w-0 flex-1 appearance-none autofill-clear rounded-md border border-border bg-surface px-2 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
53
53
|
const LIST_CLASS = 'flex max-h-80 min-h-24 flex-col gap-1 overflow-y-auto rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
54
|
-
const ITEM_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-fg transition-colors hover:bg-
|
|
54
|
+
const ITEM_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
55
55
|
const ITEM_ON_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md bg-primary-soft px-2 py-1.5 text-sm text-primary-on-soft';
|
|
56
56
|
const ITEM_OFF_CLASS = 'flex cursor-not-allowed items-center gap-2 rounded-md px-2 py-1.5 text-sm text-fg-subtle opacity-50';
|
|
57
57
|
const CURSOR_CLASS = 'ring-2 ring-ring';
|
|
@@ -159,6 +159,9 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
159
159
|
disabled: { type: 'boolean', default: false, desc: '禁用触发钮' },
|
|
160
160
|
size: { type: 'enum', values: LIMITS.sizes, default: 'md', desc: '弹窗宽度档' },
|
|
161
161
|
label: { type: 'string', default: '', desc: '触发钮的无障碍名称' },
|
|
162
|
+
id: ID_PROPS.id,
|
|
163
|
+
labelledby: ID_PROPS.labelledby,
|
|
164
|
+
...INVALID_PROPS,
|
|
162
165
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
163
166
|
},
|
|
164
167
|
emits: {
|
|
@@ -233,6 +236,9 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
233
236
|
trigger.disabled = bool(p.disabled);
|
|
234
237
|
if (str(p.label) !== '') trigger.setAttribute('aria-label', `${str(p.label)}${text === '' ? '' : `:${text}`}`);
|
|
235
238
|
else trigger.removeAttribute('aria-label');
|
|
239
|
+
// 作表单字段:触发钮接 id(label for / 点标签聚焦),根承载字段名 / 说明 / 错误关联与无效标记
|
|
240
|
+
setAttr(trigger, 'id', str(p.id));
|
|
241
|
+
applyCompositeField(root, p);
|
|
236
242
|
const clearBtn = clearBox.firstElementChild as HTMLButtonElement | null;
|
|
237
243
|
if (clearBtn) clearBtn.textContent = str(p.clear_text, kitText('soma.kit.clear', undefined, root));
|
|
238
244
|
clearBox.hidden = !(bool(p.clearable) && committed.length > 0 && !bool(p.disabled));
|
|
@@ -320,7 +326,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
320
326
|
if (failure !== '') {
|
|
321
327
|
const alert = mk('div', EMPTY_CLASS, failure);
|
|
322
328
|
alert.setAttribute('role', 'alert');
|
|
323
|
-
alert.appendChild(
|
|
329
|
+
alert.appendChild(retryButton('retry', kitText('soma.kit.ct_retry', undefined, root)));
|
|
324
330
|
list.appendChild(alert);
|
|
325
331
|
}
|
|
326
332
|
if (shown.length === 0) {
|
package/src/data/result-panel.ts
CHANGED
|
@@ -28,11 +28,13 @@ const ROOT_COMPACT_CLASS = '@container flex flex-col items-center gap-2 px-4 py-
|
|
|
28
28
|
const ICON_CLASS = 'flex h-16 w-16 items-center justify-center rounded-full text-2xl font-semibold';
|
|
29
29
|
const ICON_CODE_CLASS = 'flex h-16 min-w-24 items-center justify-center rounded-lg px-4 text-2xl font-semibold';
|
|
30
30
|
const TITLE_CLASS = 'text-xl font-semibold text-fg';
|
|
31
|
+
/** 整页 / 整卡结果(非 compact)的主标题:门户展示档(真源 structure.displayTier);compact 嵌在卡片里的结果仍用 TITLE_CLASS */
|
|
32
|
+
const TITLE_DISPLAY_CLASS = 'text-display text-fg';
|
|
31
33
|
const SUBTITLE_CLASS = 'max-w-md text-sm text-fg-muted';
|
|
32
34
|
const ACTIONS_CLASS = 'flex flex-wrap items-center justify-center gap-3 pt-4';
|
|
33
35
|
|
|
34
36
|
export const KIT_RESULT_PANEL_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
35
|
-
ROOT_CLASS, ROOT_COMPACT_CLASS, ICON_CLASS, ICON_CODE_CLASS, TITLE_CLASS, SUBTITLE_CLASS, ACTIONS_CLASS,
|
|
37
|
+
ROOT_CLASS, ROOT_COMPACT_CLASS, ICON_CLASS, ICON_CODE_CLASS, TITLE_CLASS, TITLE_DISPLAY_CLASS, SUBTITLE_CLASS, ACTIONS_CLASS,
|
|
36
38
|
Object.values(TONE_SOFT), BUTTON_CLASS_TOKENS,
|
|
37
39
|
);
|
|
38
40
|
|
|
@@ -145,7 +147,7 @@ export function createResultPanel(): SomaComponentDefinition {
|
|
|
145
147
|
icon.setAttribute('aria-hidden', 'true');
|
|
146
148
|
icon.setAttribute('data-kit-result-status', model.status);
|
|
147
149
|
root.appendChild(icon);
|
|
148
|
-
root.appendChild(mk('h2', TITLE_CLASS, model.title));
|
|
150
|
+
root.appendChild(mk('h2', compact ? TITLE_CLASS : TITLE_DISPLAY_CLASS, model.title));
|
|
149
151
|
if (model.subtitle !== '') root.appendChild(mk('p', SUBTITLE_CLASS, model.subtitle));
|
|
150
152
|
if (model.actions.length > 0) {
|
|
151
153
|
const bar = mk('div', ACTIONS_CLASS);
|
package/src/data/rich-text.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// `source: markdown`(A17):内容是 Markdown 文本,转成 HTML 后经同一净化器渲染,固定只读;见「Markdown(只读来源)」段。
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
-
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
13
|
+
import { ID_PROPS, INVALID_PROPS, applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
14
14
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
16
|
import { classTokens, mk, recOf } from './shape-util';
|
|
@@ -289,6 +289,8 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
289
289
|
source: { type: 'enum', values: ['html', 'markdown'], default: 'html', desc: '内容来源:markdown 时 value / data.markdown 是 Markdown 文本,转成 HTML 后经同一净化器渲染,组件固定只读(不出工具栏)' },
|
|
290
290
|
max_length: { type: 'number', default: 0, desc: '文字长度上限提示;非正数不显示计数。超出只变警示色,不截断' },
|
|
291
291
|
label: { type: 'string', default: '', desc: '编辑区的无障碍名称' },
|
|
292
|
+
...ID_PROPS,
|
|
293
|
+
...INVALID_PROPS,
|
|
292
294
|
link_text: { type: 'string', default: '', desc: '链接输入框的占位 / 无障碍名称' },
|
|
293
295
|
apply_text: { type: 'string', default: '', desc: '链接确认钮文案' },
|
|
294
296
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
@@ -608,6 +610,20 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
608
610
|
const init = initialHtml();
|
|
609
611
|
if (init !== lastInit) { lastInit = init; setContent(init); }
|
|
610
612
|
if (holder) holder.textContent = str(p.placeholder);
|
|
613
|
+
// 编辑区(role=textbox)承载 id / 可访问名 / 必填 / 无效 / 说明与标签关联;表单经 props 传入,重绘不丢
|
|
614
|
+
if (area) {
|
|
615
|
+
applyCommon(area, {
|
|
616
|
+
id: p.id,
|
|
617
|
+
aria_label: str(p.aria_label, str(p.label, kitText('soma.kit.rt_area', undefined, api.host))),
|
|
618
|
+
labelledby: p.labelledby,
|
|
619
|
+
required: ro ? false : p.required,
|
|
620
|
+
invalid: p.invalid,
|
|
621
|
+
describedby: p.describedby,
|
|
622
|
+
aria_describedby: p.aria_describedby,
|
|
623
|
+
errormessage: p.errormessage,
|
|
624
|
+
aria_errormessage: p.aria_errormessage,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
611
627
|
refresh();
|
|
612
628
|
},
|
|
613
629
|
};
|
package/src/data/row-editor.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// 录入草稿在组件内,重画与 columns 选项变化都不丢;数据只经 textContent / value 写入。
|
|
14
14
|
|
|
15
15
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
|
-
import { bool, createKitController, FIELD_CLASS, formatValue, joinClass, num, str, type KitApi } from '../base/shared';
|
|
16
|
+
import { applyCommon, bool, createKitController, FIELD_CLASS, formatValue, ID_PROPS, INVALID_PROPS, joinClass, nextUid, num, str, type KitApi } from '../base/shared';
|
|
17
17
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
18
18
|
import { setKitFace } from '../recipes';
|
|
19
19
|
import { KIT_BUSY_PROP_DEFS, kitBusyOf } from '../base/action-busy';
|
|
@@ -21,7 +21,8 @@ import { KIT_DATE_CLASS_CANDIDATES, mountKitDateField } from '../base/date';
|
|
|
21
21
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
22
22
|
import { createKitEmbedBag, mountKitSelectField, type KitEmbedBag } from './embed';
|
|
23
23
|
import { fetchRemoteOptionRows } from './remote-options';
|
|
24
|
-
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, recOf, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
24
|
+
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, recOf, retryButton, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
25
|
+
import { TEXT_ACTION_CLASS_TOKENS, textActionButton } from './text-action-button';
|
|
25
26
|
import type { SomaDataPort } from 'soma-core';
|
|
26
27
|
import { askKitConfirm } from './confirm-dialog';
|
|
27
28
|
import { watchKitOutcome } from './outcome-watch';
|
|
@@ -54,6 +55,14 @@ const CELL_CLASS = 'min-w-0 break-all text-sm text-fg';
|
|
|
54
55
|
const CELL_MONO = 'min-w-0 break-all font-mono text-xs text-fg-muted';
|
|
55
56
|
const CELL_MUTED = 'min-w-0 break-all text-sm text-fg-muted';
|
|
56
57
|
const END_CLASS = 'col-span-2 justify-self-end';
|
|
58
|
+
// 带操作列(结构可改)的行:横排弹性行——数据格按份数分宽(flex-<份数>,可缩可折行),操作格定宽不缩、内容靠右;
|
|
59
|
+
// 操作钮文案单行,不会被 12 栅格里 2 份的窄轨挤成逐字折行。不带操作列的行仍是 12 栅格,输出不变。
|
|
60
|
+
const FLEX_SPAN: Record<number, string> = {
|
|
61
|
+
1: 'flex-1', 2: 'flex-2', 3: 'flex-3', 4: 'flex-4', 5: 'flex-5', 6: 'flex-6',
|
|
62
|
+
7: 'flex-7', 8: 'flex-8', 9: 'flex-9', 10: 'flex-10', 11: 'flex-11', 12: 'flex-12',
|
|
63
|
+
};
|
|
64
|
+
const END_FLEX_CLASS = 'flex w-24 shrink-0 justify-end';
|
|
65
|
+
const toFlexRow = (cls: string): string => cls.replace('grid grid-cols-12', 'flex');
|
|
57
66
|
const FORM_CLASS = 'grid gap-3';
|
|
58
67
|
const FIELD_WRAP = 'flex flex-col gap-1';
|
|
59
68
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
@@ -63,6 +72,9 @@ const ERROR_CLASS = 'text-sm text-danger-on-soft';
|
|
|
63
72
|
const LIST_WRAP = 'flex flex-col';
|
|
64
73
|
const NUM_ALIGN = 'text-end tabular-nums';
|
|
65
74
|
const FOOTER_ROW_CLASS = 'grid grid-cols-12 items-center gap-2 border-t border-border-divider px-2 py-2 text-sm font-semibold text-fg';
|
|
75
|
+
const HEAD_END_CLASS = toFlexRow(HEAD_CLASS);
|
|
76
|
+
const ROW_END_CLASS = toFlexRow(ROW_CLASS);
|
|
77
|
+
const FOOTER_END_CLASS = toFlexRow(FOOTER_ROW_CLASS);
|
|
66
78
|
const COUNT_CLASS = 'text-xs text-fg-subtle';
|
|
67
79
|
/** 出错单元格的外框(令牌色环,不撑行高;圆角不在此处手写,沿用单元格自身) */
|
|
68
80
|
const CELL_ERROR_CLASS = 'ring-1 ring-danger';
|
|
@@ -71,8 +83,8 @@ const DATE_FIELD_CLASS = 'block h-9 w-full rounded-md border border-border bg-su
|
|
|
71
83
|
export const KIT_ROW_EDITOR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
72
84
|
ROOT_CLASS, TITLE_CLASS, HINT_CLASS, HEAD_CLASS, ROW_CLASS, CELL_CLASS, CELL_MONO, CELL_MUTED, END_CLASS, FORM_CLASS, FIELD_WRAP,
|
|
73
85
|
LABEL_CLASS, REQUIRED_MARK, TEXTAREA_LIKE, ERROR_CLASS, LIST_WRAP, Object.values(SPAN_CLASS), Object.values(FORM_COLS),
|
|
74
|
-
FIELD_CLASS.md, BUTTON_CLASS_TOKENS, 'self-end', '@container', NUM_ALIGN, FOOTER_ROW_CLASS, COUNT_CLASS, CELL_ERROR_CLASS, DATE_FIELD_CLASS, KIT_DATE_CLASS_CANDIDATES, KIT_LISTBOX_CLASS_CANDIDATES,
|
|
75
|
-
STAGE_BAR_CLASS, STAGE_BTNS_CLASS, STAGE_MARK_CLASS, STAGE_NOTE_CLASS,
|
|
86
|
+
FIELD_CLASS.md, BUTTON_CLASS_TOKENS, TEXT_ACTION_CLASS_TOKENS, 'self-end', '@container', NUM_ALIGN, FOOTER_ROW_CLASS, HEAD_END_CLASS, ROW_END_CLASS, FOOTER_END_CLASS, END_FLEX_CLASS, Object.values(FLEX_SPAN).join(' '), COUNT_CLASS, CELL_ERROR_CLASS, DATE_FIELD_CLASS, KIT_DATE_CLASS_CANDIDATES, KIT_LISTBOX_CLASS_CANDIDATES,
|
|
87
|
+
STAGE_BAR_CLASS, STAGE_BTNS_CLASS, STAGE_MARK_CLASS, STAGE_NOTE_CLASS, 'sr-only',
|
|
76
88
|
);
|
|
77
89
|
|
|
78
90
|
// ── 数据规整纯函数:列声明、单元格文字、录入校验、草稿转行 ──
|
|
@@ -454,7 +466,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
454
466
|
const box = mk('span', FIELD_WRAP);
|
|
455
467
|
box.appendChild(holder);
|
|
456
468
|
const loading = column.optionsRetryState === 'loading';
|
|
457
|
-
const retry =
|
|
469
|
+
const retry = retryButton('options_retry', column.optionsRetryLabel ?? kitText(loading ? 'soma.kit.rows_options_loading' : 'soma.kit.ct_retry'));
|
|
458
470
|
retry.setAttribute('data-kit-option-key', column.optionsKey);
|
|
459
471
|
if (loading) retry.setAttribute('aria-disabled', 'true');
|
|
460
472
|
box.appendChild(retry);
|
|
@@ -658,8 +670,8 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
658
670
|
props: {
|
|
659
671
|
data: { type: 'object', default: {}, desc: '{ title?, hint?, rows[], error? }' },
|
|
660
672
|
value: { type: 'array', default: [], desc: '行数组(作表单字段控件时由表单给出,优先于 data.rows);change { value } 抛出完整行数组' },
|
|
661
|
-
|
|
662
|
-
|
|
673
|
+
...ID_PROPS,
|
|
674
|
+
...INVALID_PROPS,
|
|
663
675
|
disabled: { type: 'boolean', default: false, desc: '禁用:同只读(无录入区、删除钮与单格编辑)' },
|
|
664
676
|
edit_mode: { type: 'enum', values: ['append', 'inline'], default: 'append', desc: 'append(缺省)= 下方录入区逐条添加;inline = 行内多行编辑,每行每格就地可改,每次改动抛 change(作表单字段时值随表单提交)' },
|
|
665
677
|
locked_key: { type: 'string', default: '', desc: '行级只读:该字段为真的行,所有列显示为纯文字、不可改(如敏感字段不允许勾选);提交校验也跳过这些行。只在 edit_mode: inline 生效' },
|
|
@@ -932,14 +944,33 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
932
944
|
// 自绘下拉的载体是 hidden input,可见且可聚焦的是同壳的 combobox
|
|
933
945
|
const visible = control.closest<HTMLElement>('[data-kit-select-host]')?.querySelector<HTMLElement>('[role="combobox"]') ?? control;
|
|
934
946
|
const wrap = control.closest<HTMLElement>('[data-kit-row] > span');
|
|
947
|
+
// 错误文字节点(仅读屏可见,不加行高):控件 aria-describedby 指向它,title 只作鼠标悬停的补充
|
|
948
|
+
const errNode = wrap?.querySelector<HTMLElement>('[data-kit-cell-error]') ?? null;
|
|
949
|
+
const describedTokens = (visible.getAttribute('aria-describedby') ?? '').split(/\s+/).filter((t) => t !== '');
|
|
935
950
|
if (message !== undefined) {
|
|
936
951
|
visible.setAttribute('aria-invalid', 'true');
|
|
937
952
|
wrap?.classList.add(...tokens);
|
|
938
953
|
wrap?.setAttribute('title', message);
|
|
954
|
+
if (wrap) {
|
|
955
|
+
const node = errNode ?? mk('span', 'sr-only');
|
|
956
|
+
if (!errNode) {
|
|
957
|
+
node.setAttribute('data-kit-cell-error', '');
|
|
958
|
+
node.id = nextUid('kit-cell-err');
|
|
959
|
+
wrap.appendChild(node);
|
|
960
|
+
}
|
|
961
|
+
node.textContent = message;
|
|
962
|
+
if (!describedTokens.includes(node.id)) visible.setAttribute('aria-describedby', [...describedTokens, node.id].join(' '));
|
|
963
|
+
}
|
|
939
964
|
} else {
|
|
940
965
|
visible.removeAttribute('aria-invalid');
|
|
941
966
|
wrap?.classList.remove(...tokens);
|
|
942
967
|
wrap?.removeAttribute('title');
|
|
968
|
+
if (errNode) {
|
|
969
|
+
const rest = describedTokens.filter((t) => t !== errNode.id);
|
|
970
|
+
if (rest.length > 0) visible.setAttribute('aria-describedby', rest.join(' '));
|
|
971
|
+
else visible.removeAttribute('aria-describedby');
|
|
972
|
+
errNode.remove();
|
|
973
|
+
}
|
|
943
974
|
}
|
|
944
975
|
});
|
|
945
976
|
// 根要能接住表单的 focus() 再转交给出错单元格
|
|
@@ -1020,21 +1051,24 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1020
1051
|
list.textContent = '';
|
|
1021
1052
|
const shown = cols.filter((c) => c.list);
|
|
1022
1053
|
const structural = !readonly && !fixedRows;
|
|
1023
|
-
const spanOf = (c: KitRowColumn): string => `${SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
1054
|
+
const spanOf = (c: KitRowColumn): string => `${structural ? `${FLEX_SPAN[c.span] ?? 'flex-2'} min-w-0` : SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
1024
1055
|
if (st.rows.length === 0) {
|
|
1025
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1056
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)), true));
|
|
1026
1057
|
} else {
|
|
1027
|
-
const head = mk('div', HEAD_CLASS);
|
|
1058
|
+
const head = mk('div', structural ? HEAD_END_CLASS : HEAD_CLASS);
|
|
1028
1059
|
for (const c of shown) {
|
|
1029
1060
|
const cell = mk('span', spanOf(c), c.label);
|
|
1030
1061
|
if (c.required && c.editable && !readonly) cell.appendChild(mk('span', REQUIRED_MARK, ' *'));
|
|
1031
1062
|
head.appendChild(cell);
|
|
1032
1063
|
}
|
|
1033
|
-
if (structural) head.appendChild(mk('span',
|
|
1064
|
+
if (structural) head.appendChild(mk('span', END_FLEX_CLASS, str(p.action_label)));
|
|
1034
1065
|
list.appendChild(head);
|
|
1035
1066
|
st.rows.forEach((row, index) => {
|
|
1036
|
-
const tr = mk('div', ROW_CLASS);
|
|
1067
|
+
const tr = mk('div', structural ? ROW_END_CLASS : ROW_CLASS);
|
|
1037
1068
|
tr.setAttribute('data-kit-row', String(index));
|
|
1069
|
+
const rowName = kitText('soma.kit.rows_row_n', { n: index + 1 }, root);
|
|
1070
|
+
tr.setAttribute('role', 'group');
|
|
1071
|
+
tr.setAttribute('aria-label', rowName);
|
|
1038
1072
|
for (const c of shown) {
|
|
1039
1073
|
const wrap = mk('span', `${spanOf(c)} min-w-0`);
|
|
1040
1074
|
if (readonly || !c.editable || (str(p.locked_key) !== '' && row[str(p.locked_key)] === true)) {
|
|
@@ -1047,9 +1081,10 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1047
1081
|
tr.appendChild(wrap);
|
|
1048
1082
|
}
|
|
1049
1083
|
if (structural) {
|
|
1050
|
-
const cell = mk('span',
|
|
1051
|
-
const btn =
|
|
1084
|
+
const cell = mk('span', END_FLEX_CLASS);
|
|
1085
|
+
const btn = textActionButton('remove', str(p.remove_label, kitText('soma.kit.delete', undefined, root)), 'danger');
|
|
1052
1086
|
btn.setAttribute('data-kit-index', String(index));
|
|
1087
|
+
btn.setAttribute('aria-label', `${str(p.remove_label, kitText('soma.kit.delete', undefined, root))} ${rowName}`);
|
|
1053
1088
|
cell.appendChild(btn);
|
|
1054
1089
|
tr.appendChild(cell);
|
|
1055
1090
|
}
|
|
@@ -1058,7 +1093,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1058
1093
|
if (str(p.footer, 'none') === 'sum') {
|
|
1059
1094
|
const totals = rowTotals(shown, st.rows);
|
|
1060
1095
|
const labelCol = shown.find((c) => totals[c.key] === undefined);
|
|
1061
|
-
const foot = mk('div', FOOTER_ROW_CLASS);
|
|
1096
|
+
const foot = mk('div', structural ? FOOTER_END_CLASS : FOOTER_ROW_CLASS);
|
|
1062
1097
|
foot.setAttribute('data-kit-footer', 'sum');
|
|
1063
1098
|
for (const c of shown) {
|
|
1064
1099
|
const total = totals[c.key];
|
|
@@ -1067,7 +1102,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1067
1102
|
if (total !== undefined) cell.setAttribute('data-kit-total', c.key);
|
|
1068
1103
|
foot.appendChild(cell);
|
|
1069
1104
|
}
|
|
1070
|
-
if (structural) foot.appendChild(mk('span',
|
|
1105
|
+
if (structural) foot.appendChild(mk('span', END_FLEX_CLASS));
|
|
1071
1106
|
list.appendChild(foot);
|
|
1072
1107
|
}
|
|
1073
1108
|
}
|
|
@@ -1131,6 +1166,19 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1131
1166
|
bindStageOutcome(root, p);
|
|
1132
1167
|
}
|
|
1133
1168
|
if (p.id !== undefined && str(p.id) !== '') root.id = str(p.id);
|
|
1169
|
+
// 根是一组行:role=group(不让具名 section 变成 region 地标);名字取表单传入的标签 id / aria_label / 标题;必填 / 无效 / 说明关联由 props 写入,重绘不丢
|
|
1170
|
+
root.setAttribute('role', 'group');
|
|
1171
|
+
applyCommon(root, {
|
|
1172
|
+
id: root.id,
|
|
1173
|
+
aria_label: str(p.aria_label, textOf(data.title)),
|
|
1174
|
+
labelledby: p.labelledby,
|
|
1175
|
+
required: p.required,
|
|
1176
|
+
invalid: p.invalid,
|
|
1177
|
+
describedby: p.describedby,
|
|
1178
|
+
aria_describedby: p.aria_describedby,
|
|
1179
|
+
errormessage: p.errormessage,
|
|
1180
|
+
aria_errormessage: p.aria_errormessage,
|
|
1181
|
+
});
|
|
1134
1182
|
const shown = cols.filter((c) => c.list);
|
|
1135
1183
|
root.className = joinClass(`@container ${ROOT_CLASS}`, p.class);
|
|
1136
1184
|
|
|
@@ -1166,25 +1214,30 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1166
1214
|
}
|
|
1167
1215
|
} else if (st.rows.length === 0) {
|
|
1168
1216
|
list.textContent = '';
|
|
1169
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1217
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)), true));
|
|
1170
1218
|
} else {
|
|
1171
1219
|
list.textContent = '';
|
|
1172
|
-
const
|
|
1173
|
-
const
|
|
1220
|
+
const structural = !readonly && !fixedRows;
|
|
1221
|
+
const head = mk('div', structural ? HEAD_END_CLASS : HEAD_CLASS);
|
|
1222
|
+
const spanOf = (c: KitRowColumn): string => `${structural ? `${FLEX_SPAN[c.span] ?? 'flex-2'} min-w-0` : SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
1174
1223
|
for (const c of shown) head.appendChild(mk('span', spanOf(c), c.label));
|
|
1175
|
-
if (
|
|
1224
|
+
if (structural) head.appendChild(mk('span', END_FLEX_CLASS, str(p.action_label)));
|
|
1176
1225
|
list.appendChild(head);
|
|
1177
1226
|
st.rows.forEach((row, index) => {
|
|
1178
|
-
const tr = mk('div', ROW_CLASS);
|
|
1227
|
+
const tr = mk('div', structural ? ROW_END_CLASS : ROW_CLASS);
|
|
1179
1228
|
tr.setAttribute('data-kit-row', textOf(row[key]));
|
|
1229
|
+
const rowName = kitText('soma.kit.rows_row_n', { n: index + 1 }, root);
|
|
1230
|
+
tr.setAttribute('role', 'group');
|
|
1231
|
+
tr.setAttribute('aria-label', rowName);
|
|
1180
1232
|
for (const c of shown) {
|
|
1181
1233
|
const cls = c.mono || c.kind === 'json' ? CELL_MONO : c.key === shown[0]?.key ? CELL_CLASS : CELL_MUTED;
|
|
1182
1234
|
tr.appendChild(mk('span', `${spanOf(c)} ${cls}`, rowCellText(c, row[c.key], str(p.locale))));
|
|
1183
1235
|
}
|
|
1184
|
-
if (
|
|
1185
|
-
const cell = mk('span',
|
|
1186
|
-
const btn =
|
|
1236
|
+
if (structural) {
|
|
1237
|
+
const cell = mk('span', END_FLEX_CLASS);
|
|
1238
|
+
const btn = textActionButton('remove', str(p.remove_label, kitText('soma.kit.delete', undefined, root)), 'danger');
|
|
1187
1239
|
btn.setAttribute('data-kit-index', String(index));
|
|
1240
|
+
btn.setAttribute('aria-label', `${str(p.remove_label, kitText('soma.kit.delete', undefined, root))} ${rowName}`);
|
|
1188
1241
|
cell.appendChild(btn);
|
|
1189
1242
|
tr.appendChild(cell);
|
|
1190
1243
|
}
|
|
@@ -1193,14 +1246,14 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1193
1246
|
if (str(p.footer, 'none') === 'sum') {
|
|
1194
1247
|
const totals = rowTotals(shown, st.rows);
|
|
1195
1248
|
const labelCol = shown.find((c) => totals[c.key] === undefined);
|
|
1196
|
-
const foot = mk('div', FOOTER_ROW_CLASS);
|
|
1249
|
+
const foot = mk('div', structural ? FOOTER_END_CLASS : FOOTER_ROW_CLASS);
|
|
1197
1250
|
foot.setAttribute('data-kit-footer', 'sum');
|
|
1198
1251
|
for (const c of shown) {
|
|
1199
1252
|
const total = totals[c.key];
|
|
1200
1253
|
const text = total !== undefined ? rowCellText(c, total, str(p.locale)) : c === labelCol ? str(p.total_label, kitText('soma.kit.total_label', undefined, root)) : '';
|
|
1201
1254
|
foot.appendChild(mk('span', spanOf(c), text));
|
|
1202
1255
|
}
|
|
1203
|
-
if (
|
|
1256
|
+
if (structural) foot.appendChild(mk('span', END_FLEX_CLASS));
|
|
1204
1257
|
list.appendChild(foot);
|
|
1205
1258
|
}
|
|
1206
1259
|
}
|