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
package/src/data/embed.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { releaseDropdownsIn } from '../base/popup';
|
|
10
10
|
import { createSelect } from '../base/select';
|
|
11
|
+
import { createInput } from '../base/input';
|
|
12
|
+
import { createTextarea } from '../base/textarea';
|
|
13
|
+
import { createCheckbox } from '../base/checkbox';
|
|
11
14
|
import { hintUndeclaredKitUse } from './wrapped-candidates';
|
|
12
15
|
import { kitFail } from '../compile/kit-error';
|
|
13
16
|
|
|
@@ -80,17 +83,12 @@ export function mountKitComponent(
|
|
|
80
83
|
|
|
81
84
|
// ── 命令式下拉选择(data 层不走组件树的调用方:分页器页长、字段映射、行内编辑、规则构建器等)──────────
|
|
82
85
|
|
|
83
|
-
export interface KitSelectFieldOptions {
|
|
86
|
+
export interface KitSelectFieldOptions extends KitFieldA11yOptions {
|
|
84
87
|
options: ReadonlyArray<{ value: string; label: string; disabled?: boolean }>;
|
|
85
88
|
value?: string;
|
|
86
89
|
placeholder?: string;
|
|
87
90
|
size?: 'sm' | 'md' | 'lg';
|
|
88
|
-
disabled?: boolean;
|
|
89
91
|
searchable?: boolean;
|
|
90
|
-
/** 加在 Select 根上的类(如固定宽度 w-36;须已在调用方的候选类里) */
|
|
91
|
-
className?: string;
|
|
92
|
-
ariaLabel?: string;
|
|
93
|
-
name?: string;
|
|
94
92
|
/** 用户选中后调(hidden 载体的 value 已更新) */
|
|
95
93
|
onChange?(value: string): void;
|
|
96
94
|
}
|
|
@@ -105,27 +103,141 @@ export interface KitSelectField {
|
|
|
105
103
|
setValue(value: string): void;
|
|
106
104
|
setOptions(options: KitSelectFieldOptions['options']): void;
|
|
107
105
|
setDisabled(disabled: boolean): void;
|
|
106
|
+
/** 改禁用 / 只读 / 必填 / 无效 / 标签与说明关联 */
|
|
107
|
+
setState(next: KitFieldState): void;
|
|
108
|
+
dispose(): void;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ── 命令式表单字段的统一实现(Select / Input / Textarea / Checkbox 共用一份)──────────
|
|
112
|
+
|
|
113
|
+
/** 表单字段的无障碍 / 校验 / 状态选项(各 `mountKit*Field` 共用;缺省的键不写,输出与没有该键时相同) */
|
|
114
|
+
export interface KitFieldA11yOptions {
|
|
115
|
+
/** 无可见标签时的可访问名 */
|
|
116
|
+
ariaLabel?: string;
|
|
117
|
+
/** 可见标签元素 id(写 aria-labelledby) */
|
|
118
|
+
labelledby?: string;
|
|
119
|
+
/** 说明 / 错误元素 id(写 aria-describedby / aria-errormessage) */
|
|
120
|
+
describedby?: string;
|
|
121
|
+
errormessage?: string;
|
|
122
|
+
/** 必填(aria-required)/ 校验无效(aria-invalid + 错误态边框) */
|
|
123
|
+
required?: boolean;
|
|
124
|
+
invalid?: boolean;
|
|
125
|
+
disabled?: boolean;
|
|
126
|
+
readonly?: boolean;
|
|
127
|
+
/** 控件 id / 表单字段名 */
|
|
128
|
+
id?: string;
|
|
129
|
+
name?: string;
|
|
130
|
+
/** 加在控件根上的类(须已在调用方候选类里) */
|
|
131
|
+
className?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 挂载后可改的状态键(给了哪些改哪些) */
|
|
135
|
+
export type KitFieldState = Pick<KitFieldA11yOptions, 'disabled' | 'readonly' | 'required' | 'invalid' | 'ariaLabel' | 'labelledby' | 'describedby' | 'errormessage'>;
|
|
136
|
+
|
|
137
|
+
/** 选项里写了的键 -> 组件 props(只含已写的键) */
|
|
138
|
+
function fieldStateProps(o: KitFieldState): Record<string, unknown> {
|
|
139
|
+
const out: Record<string, unknown> = {};
|
|
140
|
+
if (o.disabled !== undefined) out.disabled = o.disabled;
|
|
141
|
+
if (o.readonly !== undefined) out.readonly = o.readonly;
|
|
142
|
+
if (o.required !== undefined) out.required = o.required;
|
|
143
|
+
if (o.invalid !== undefined) out.invalid = o.invalid;
|
|
144
|
+
if (o.ariaLabel !== undefined) out.aria_label = o.ariaLabel;
|
|
145
|
+
if (o.labelledby !== undefined) out.labelledby = o.labelledby;
|
|
146
|
+
if (o.describedby !== undefined) out.describedby = o.describedby;
|
|
147
|
+
if (o.errormessage !== undefined) out.errormessage = o.errormessage;
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 无障碍选项里除 `fieldStateProps` 之外的挂载期键(id / name / class) */
|
|
152
|
+
function fieldMountProps(o: KitFieldA11yOptions): Record<string, unknown> {
|
|
153
|
+
const out = fieldStateProps(o);
|
|
154
|
+
if (o.id !== undefined) out.id = o.id;
|
|
155
|
+
if (o.name !== undefined) out.name = o.name;
|
|
156
|
+
if (o.className !== undefined) out.class = o.className;
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface KitComponentField<V> {
|
|
161
|
+
/** 要挂进 DOM 的外壳 */
|
|
162
|
+
el: HTMLElement;
|
|
163
|
+
/** 可聚焦的控件本体:focus、读写 aria-* 落在它上面 */
|
|
164
|
+
field: HTMLElement;
|
|
165
|
+
setValue(value: V): void;
|
|
166
|
+
/** 直接改组件 props(如 Input 的 placeholder、Select 的 options) */
|
|
167
|
+
setProps(next: Record<string, unknown>): void;
|
|
168
|
+
/** 改禁用 / 只读 / 必填 / 无效 / 标签与说明关联 */
|
|
169
|
+
setState(next: KitFieldState): void;
|
|
108
170
|
dispose(): void;
|
|
109
171
|
}
|
|
110
172
|
|
|
173
|
+
interface KitComponentFieldConfig<V> {
|
|
174
|
+
def: SomaComponentDefinition;
|
|
175
|
+
props: Record<string, unknown>;
|
|
176
|
+
/** 外壳里可聚焦的控件本体 */
|
|
177
|
+
focusSelector: string;
|
|
178
|
+
/** change 载荷里取出值 */
|
|
179
|
+
read(payload: { value?: unknown }): V;
|
|
180
|
+
/** 值是否回写 props.value(文本框不回写:输入框已显示最新键入,回写会让光标跳动) */
|
|
181
|
+
echo: boolean;
|
|
182
|
+
/** 用户改值后调(已回写 / 已更新载体) */
|
|
183
|
+
onChange?(value: V): void;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 把一个内置表单组件挂成命令式字段(唯一实现:各 `mountKit*Field` 只给组件、props 与取值口径) */
|
|
187
|
+
function mountKitComponentField<V>(cfg: KitComponentFieldConfig<V>): KitComponentField<V> {
|
|
188
|
+
const stage = document.createElement('div');
|
|
189
|
+
const mount = mountKitComponent(cfg.def, stage, cfg.props, {
|
|
190
|
+
change: (payload: { value?: unknown }) => {
|
|
191
|
+
const next = cfg.read(payload);
|
|
192
|
+
if (cfg.echo) mount.setProps({ value: next });
|
|
193
|
+
cfg.onChange?.(next);
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
const el = mount.host;
|
|
197
|
+
el.remove();
|
|
198
|
+
const field = el.querySelector<HTMLElement>(cfg.focusSelector) ?? el;
|
|
199
|
+
return {
|
|
200
|
+
el,
|
|
201
|
+
field,
|
|
202
|
+
setValue: (value) => mount.setProps({ value }),
|
|
203
|
+
setProps: (next) => mount.setProps(next),
|
|
204
|
+
setState: (next) => mount.setProps(fieldStateProps(next)),
|
|
205
|
+
dispose: () => mount.destroy(),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const textOfPayload = (payload: { value?: unknown }): string => (payload?.value === undefined || payload.value === null ? '' : String(payload.value));
|
|
210
|
+
|
|
111
211
|
/** 在命令式 DOM 里画一个自绘 Select(和页面里的 Select 组件同一份实现,没有原生 <select>) */
|
|
112
212
|
export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField {
|
|
113
|
-
const stage = document.createElement('div');
|
|
114
213
|
let input: HTMLInputElement | null = null;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
214
|
+
const field = mountKitComponentField<string>({
|
|
215
|
+
def: createSelect(),
|
|
216
|
+
props: {
|
|
217
|
+
options: opts.options.map((o) => ({ ...o })),
|
|
218
|
+
value: opts.value ?? '',
|
|
219
|
+
placeholder: opts.placeholder ?? '',
|
|
220
|
+
size: opts.size ?? 'md',
|
|
221
|
+
disabled: opts.disabled === true,
|
|
222
|
+
searchable: opts.searchable === true,
|
|
223
|
+
aria_label: opts.ariaLabel ?? '',
|
|
224
|
+
name: opts.name ?? '',
|
|
225
|
+
class: opts.className ?? '',
|
|
226
|
+
// 以下键只在写了时才传:缺省时输出与没有这些键完全相同
|
|
227
|
+
...fieldMountProps({
|
|
228
|
+
...(opts.labelledby !== undefined ? { labelledby: opts.labelledby } : {}),
|
|
229
|
+
...(opts.describedby !== undefined ? { describedby: opts.describedby } : {}),
|
|
230
|
+
...(opts.errormessage !== undefined ? { errormessage: opts.errormessage } : {}),
|
|
231
|
+
...(opts.required !== undefined ? { required: opts.required } : {}),
|
|
232
|
+
...(opts.invalid !== undefined ? { invalid: opts.invalid } : {}),
|
|
233
|
+
...(opts.readonly !== undefined ? { readonly: opts.readonly } : {}),
|
|
234
|
+
...(opts.id !== undefined ? { id: opts.id } : {}),
|
|
235
|
+
}),
|
|
236
|
+
},
|
|
237
|
+
focusSelector: '[role="combobox"]',
|
|
238
|
+
read: textOfPayload,
|
|
239
|
+
echo: true,
|
|
240
|
+
onChange: (next) => {
|
|
129
241
|
if (input) {
|
|
130
242
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
131
243
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
@@ -133,8 +245,7 @@ export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField
|
|
|
133
245
|
opts.onChange?.(next);
|
|
134
246
|
},
|
|
135
247
|
});
|
|
136
|
-
const el =
|
|
137
|
-
el.remove();
|
|
248
|
+
const el = field.el;
|
|
138
249
|
input = el.querySelector<HTMLInputElement>('input[data-kit-value]');
|
|
139
250
|
if (input === null) {
|
|
140
251
|
input = el.ownerDocument.createElement('input');
|
|
@@ -142,18 +253,109 @@ export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField
|
|
|
142
253
|
input.setAttribute('data-kit-value', '');
|
|
143
254
|
el.appendChild(input);
|
|
144
255
|
}
|
|
145
|
-
const field = el.querySelector<HTMLElement>('[role="combobox"]') ?? el;
|
|
146
256
|
return {
|
|
147
257
|
el,
|
|
148
258
|
input,
|
|
149
|
-
field,
|
|
150
|
-
setValue:
|
|
151
|
-
setOptions: (options) =>
|
|
152
|
-
setDisabled: (disabled) =>
|
|
153
|
-
|
|
259
|
+
field: field.field,
|
|
260
|
+
setValue: field.setValue,
|
|
261
|
+
setOptions: (options) => field.setProps({ options: options.map((o) => ({ ...o })) }),
|
|
262
|
+
setDisabled: (disabled) => field.setState({ disabled }),
|
|
263
|
+
setState: field.setState,
|
|
264
|
+
dispose: field.dispose,
|
|
154
265
|
};
|
|
155
266
|
}
|
|
156
267
|
|
|
268
|
+
export interface KitInputFieldOptions extends KitFieldA11yOptions {
|
|
269
|
+
value?: string;
|
|
270
|
+
placeholder?: string;
|
|
271
|
+
/** 最大字符数;0 / 缺省 = 不限 */
|
|
272
|
+
max?: number;
|
|
273
|
+
size?: 'sm' | 'md' | 'lg';
|
|
274
|
+
clearable?: boolean;
|
|
275
|
+
/** 用户键入后调(值由调用方持有;字段不回写 props,输入框已显示最新键入) */
|
|
276
|
+
onChange?(value: string): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 在命令式 DOM 里画一个 kit Input(单行文本,与页面里的 Input 组件同一份实现) */
|
|
280
|
+
export function mountKitInputField(opts: KitInputFieldOptions = {}): KitComponentField<string> {
|
|
281
|
+
return mountKitComponentField<string>({
|
|
282
|
+
def: createInput(),
|
|
283
|
+
props: {
|
|
284
|
+
value: opts.value ?? '',
|
|
285
|
+
...(opts.placeholder !== undefined ? { placeholder: opts.placeholder } : {}),
|
|
286
|
+
...(opts.max !== undefined ? { max: opts.max } : {}),
|
|
287
|
+
...(opts.size !== undefined ? { size: opts.size } : {}),
|
|
288
|
+
...(opts.clearable !== undefined ? { clearable: opts.clearable } : {}),
|
|
289
|
+
...fieldMountProps(opts),
|
|
290
|
+
},
|
|
291
|
+
focusSelector: 'input:not([type="hidden"])',
|
|
292
|
+
read: textOfPayload,
|
|
293
|
+
echo: false,
|
|
294
|
+
...(opts.onChange !== undefined ? { onChange: opts.onChange } : {}),
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface KitTextareaFieldOptions extends KitFieldA11yOptions {
|
|
299
|
+
value?: string;
|
|
300
|
+
placeholder?: string;
|
|
301
|
+
rows?: number;
|
|
302
|
+
max?: number;
|
|
303
|
+
size?: 'sm' | 'md' | 'lg';
|
|
304
|
+
onChange?(value: string): void;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** 在命令式 DOM 里画一个 kit Textarea(多行文本) */
|
|
308
|
+
export function mountKitTextareaField(opts: KitTextareaFieldOptions = {}): KitComponentField<string> {
|
|
309
|
+
return mountKitComponentField<string>({
|
|
310
|
+
def: createTextarea(),
|
|
311
|
+
props: {
|
|
312
|
+
value: opts.value ?? '',
|
|
313
|
+
...(opts.placeholder !== undefined ? { placeholder: opts.placeholder } : {}),
|
|
314
|
+
...(opts.rows !== undefined ? { rows: opts.rows } : {}),
|
|
315
|
+
...(opts.max !== undefined ? { max: opts.max } : {}),
|
|
316
|
+
...(opts.size !== undefined ? { size: opts.size } : {}),
|
|
317
|
+
...fieldMountProps(opts),
|
|
318
|
+
},
|
|
319
|
+
focusSelector: 'textarea',
|
|
320
|
+
read: textOfPayload,
|
|
321
|
+
echo: false,
|
|
322
|
+
...(opts.onChange !== undefined ? { onChange: opts.onChange } : {}),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface KitCheckboxFieldOptions extends KitFieldA11yOptions {
|
|
327
|
+
/** 单个勾选框:布尔;有 options 的多选组:选中值数组 */
|
|
328
|
+
value?: boolean | readonly unknown[];
|
|
329
|
+
/** 单个勾选框的文字 */
|
|
330
|
+
label?: string;
|
|
331
|
+
/** 多选组的选项 */
|
|
332
|
+
options?: ReadonlyArray<{ value: unknown; label?: string; disabled?: boolean }>;
|
|
333
|
+
orientation?: 'horizontal' | 'vertical';
|
|
334
|
+
onChange?(value: boolean | unknown[]): void;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** 在命令式 DOM 里画一个 kit Checkbox(单个勾选框或多选组) */
|
|
338
|
+
export function mountKitCheckboxField(opts: KitCheckboxFieldOptions = {}): KitComponentField<boolean | readonly unknown[]> {
|
|
339
|
+
const grouped = opts.options !== undefined;
|
|
340
|
+
return mountKitComponentField<boolean | readonly unknown[]>({
|
|
341
|
+
def: createCheckbox(),
|
|
342
|
+
props: {
|
|
343
|
+
value: opts.value ?? (grouped ? [] : false),
|
|
344
|
+
...(opts.label !== undefined ? { label: opts.label } : {}),
|
|
345
|
+
...(grouped ? { options: opts.options!.map((o) => ({ ...o })) } : {}),
|
|
346
|
+
...(opts.orientation !== undefined ? { orientation: opts.orientation } : {}),
|
|
347
|
+
...fieldMountProps(opts),
|
|
348
|
+
},
|
|
349
|
+
focusSelector: 'input[type="checkbox"]',
|
|
350
|
+
read: (payload) => {
|
|
351
|
+
const v = payload?.value;
|
|
352
|
+
return Array.isArray(v) ? [...v] : v === true;
|
|
353
|
+
},
|
|
354
|
+
echo: true,
|
|
355
|
+
...(opts.onChange !== undefined ? { onChange: (v: boolean | readonly unknown[]) => opts.onChange!(Array.isArray(v) ? [...v] : v === true) } : {}),
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
157
359
|
// ── 嵌入件释放袋(会整块重建的容器统一用)──────────
|
|
158
360
|
|
|
159
361
|
/** 命令式嵌入件的释放口:组件挂载句柄(destroy)或命令式字段(dispose)二选一 */
|
package/src/data/field-mapper.ts
CHANGED
|
@@ -31,10 +31,10 @@ const LABEL_CLASS = 'text-fg';
|
|
|
31
31
|
const KEY_CLASS = 'text-xs text-fg-muted';
|
|
32
32
|
const REQ_CLASS = 'ms-1 text-xs text-danger-on-soft';
|
|
33
33
|
const ARROW_CLASS = 'shrink-0 text-fg-subtle';
|
|
34
|
-
const CONTROL_CLASS = 'block h-
|
|
35
|
-
const REMOVE_CLASS = 'inline-flex h-
|
|
34
|
+
const CONTROL_CLASS = 'block h-8 w-48 max-w-full 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 disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle';
|
|
35
|
+
const REMOVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-sm text-danger-on-soft hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
36
36
|
const ADD_ROW_CLASS = 'flex flex-wrap items-center gap-2 pt-2';
|
|
37
|
-
const BTN_CLASS = 'inline-flex h-
|
|
37
|
+
const BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
38
38
|
const NOTICE_CLASS = 'rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-on-soft';
|
|
39
39
|
const PREVIEW_TITLE_CLASS = 'text-xs text-fg-muted';
|
|
40
40
|
const PREVIEW_WRAP_CLASS = 'overflow-x-auto rounded-lg border border-border-subtle';
|
|
@@ -44,7 +44,7 @@ const PREVIEW_CELL_CLASS = 'border-t border-border-subtle px-2 py-1 text-fg';
|
|
|
44
44
|
/** 来源下拉(自绘 Select)根上的宽度类,和文本框来源控件同宽 */
|
|
45
45
|
const SELECT_ROOT_CLASS = 'w-48 max-w-full';
|
|
46
46
|
const FOOT_CLASS ='flex items-center justify-end gap-2';
|
|
47
|
-
const SAVE_CLASS = 'inline-flex h-
|
|
47
|
+
const SAVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
48
48
|
const EMPTY_CLASS = 'px-3 py-6 text-center text-fg-muted';
|
|
49
49
|
|
|
50
50
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
@@ -18,6 +18,13 @@ export const FLOW_EDITOR_CONTRACT = {
|
|
|
18
18
|
value: { type: 'object', default: {}, desc: '作表单字段控件时的图 { nodes, edges, mappings? }(表单草稿里的字段值,优先于 data;change 抛出的 value 即整图)' },
|
|
19
19
|
name: { type: 'string', default: '', desc: '字段名(表单字段控件用;非空时图取 value 而非 data)' },
|
|
20
20
|
id: { type: 'string', default: '', desc: '根节点 id(表单用它定位出错字段)' },
|
|
21
|
+
labelledby: { type: 'string', default: '', desc: '可见标签元素 id(写在画布 aria-labelledby,表单自动传入)' },
|
|
22
|
+
required: { type: 'boolean', default: false, desc: '必填态(画布写 aria-required="true")' },
|
|
23
|
+
invalid: { type: 'boolean', default: false, desc: '校验无效态(画布写 aria-invalid="true")' },
|
|
24
|
+
describedby: { type: 'string', default: '', desc: '关联说明/错误元素 id(与画布自带说明合并写 aria-describedby)' },
|
|
25
|
+
errormessage: { type: 'string', default: '', desc: '关联错误消息元素 id(写 aria-errormessage)' },
|
|
26
|
+
aria_describedby: { type: 'string', default: '', desc: '同 describedby' },
|
|
27
|
+
aria_errormessage: { type: 'string', default: '', desc: '同 errormessage' },
|
|
21
28
|
disabled: { type: 'boolean', default: false, desc: '禁用:同只读(表单禁用该字段时由表单置真)' },
|
|
22
29
|
validation: { type: 'array', default: [], desc: '外部传入的问题 [{ target: node | edge, id, level: error | warning, message }],按节点或连线标记' },
|
|
23
30
|
suggestions: { type: 'array', default: [], desc: 'AI 建议 [{ id, label, reason?, nodes, edges }],画成虚影,可采纳或拒绝' },
|
package/src/data/flow-editor.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { clearFlowNodeField, withNodeOptions } from './flow-node-options';
|
|
|
17
17
|
import { FLOW_EDITOR_CONTRACT } from './flow-editor-contract';
|
|
18
18
|
import { designFlowEditorGeometry } from 'soma-foundation/layout';
|
|
19
19
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
-
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
20
|
+
import { applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
21
21
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
22
|
import { setKitFace } from '../recipes';
|
|
23
23
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
@@ -196,7 +196,7 @@ export function fmt(template: string, vars: Record<string, string | number>): st
|
|
|
196
196
|
export const FLOW_CLASS = Object.freeze({
|
|
197
197
|
root: 'flex w-full flex-col gap-2',
|
|
198
198
|
toolbar: 'flex flex-wrap items-center gap-2',
|
|
199
|
-
btn: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-
|
|
199
|
+
btn: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-button-edge 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-60',
|
|
200
200
|
btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-primary bg-primary px-3 text-sm text-primary-fg transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
201
201
|
zoomLabel: 'text-xs text-fg-muted',
|
|
202
202
|
row: 'flex w-full items-start gap-2',
|
|
@@ -224,9 +224,9 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
224
224
|
line: 'truncate text-xs text-fg-muted',
|
|
225
225
|
lineError: 'truncate text-xs text-danger-on-soft',
|
|
226
226
|
lineWarning: 'truncate text-xs text-warning-on-soft',
|
|
227
|
-
cfgBtn: 'shrink-0 rounded-sm px-1 text-xs text-fg-muted transition-colors hover:bg-
|
|
227
|
+
cfgBtn: 'shrink-0 rounded-sm px-1 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-ring',
|
|
228
228
|
inPort: 'pointer-events-none absolute -left-1 top-10 -mt-1 h-2 w-2 rounded-full border border-border bg-surface',
|
|
229
|
-
outPort: 'absolute -right-2 top-10 -mt-2 h-4 w-4 cursor-crosshair rounded-full border border-border bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
229
|
+
outPort: 'absolute -right-2 top-10 -mt-2 h-4 w-4 p-0 cursor-crosshair rounded-full border border-border bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
230
230
|
bar: 'box-border flex h-full w-full items-center gap-1 rounded-md border border-border bg-surface px-2 text-xs text-fg shadow-sm',
|
|
231
231
|
edgeG: 'group cursor-pointer outline-none',
|
|
232
232
|
edgeHit: 'fill-none stroke-transparent stroke-12',
|
|
@@ -238,8 +238,8 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
238
238
|
marqueeRect: 'fill-primary-soft stroke-primary opacity-50',
|
|
239
239
|
menuFo: 'pointer-events-auto overflow-visible',
|
|
240
240
|
menuInner: 'box-border flex w-full flex-col gap-1 rounded-md border border-border bg-surface p-1 shadow-lg',
|
|
241
|
-
menuItem: 'rounded-sm px-2 py-1 text-start text-sm text-fg transition-colors hover:bg-
|
|
242
|
-
menuItemDanger: 'rounded-sm px-2 py-1 text-start text-sm text-danger-on-soft transition-colors hover:bg-
|
|
241
|
+
menuItem: 'rounded-sm px-2 py-1 text-start text-sm text-fg 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',
|
|
242
|
+
menuItemDanger: 'rounded-sm px-2 py-1 text-start text-sm text-danger-on-soft 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',
|
|
243
243
|
status: 'text-xs text-fg-muted',
|
|
244
244
|
srOnly: 'sr-only',
|
|
245
245
|
hidden: 'hidden',
|
|
@@ -1722,6 +1722,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1722
1722
|
if (!s || !editable()) return;
|
|
1723
1723
|
const base = withPositions(graph);
|
|
1724
1724
|
const next = applySuggestion(base, s, ghostPosCache);
|
|
1725
|
+
// 并入后虚影按节点 / 连线 id 去重自然退场(撤销后虚影回来);建议本身由展示对象在 onDraft 里清掉
|
|
1725
1726
|
commit(next);
|
|
1726
1727
|
api.emit('suggestion_accept', { id: sid });
|
|
1727
1728
|
};
|
|
@@ -1837,7 +1838,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1837
1838
|
};
|
|
1838
1839
|
|
|
1839
1840
|
/** 节点 = foreignObject(x、y、宽、高是几何属性)里放一个 HTML 卡片 */
|
|
1840
|
-
const buildNode = (n: FlowNode, at: Pt, opts: { ghost: boolean; issues?: FlowIssue[] }): SVGForeignObjectElement => {
|
|
1841
|
+
const buildNode = (n: FlowNode, at: Pt, opts: { ghost: boolean; issues?: FlowIssue[]; ghostOf?: string }): SVGForeignObjectElement => {
|
|
1841
1842
|
const key = keyOfNode(n.id);
|
|
1842
1843
|
const def = typeOf(n);
|
|
1843
1844
|
const sel = !opts.ghost && selected.has(key);
|
|
@@ -1850,7 +1851,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1850
1851
|
if (opts.ghost) {
|
|
1851
1852
|
node.setAttribute('data-flow-ghost', '');
|
|
1852
1853
|
node.setAttribute('role', 'img');
|
|
1853
|
-
node.setAttribute('aria-label', `${t('suggestion', { label: n.label })}`);
|
|
1854
|
+
node.setAttribute('aria-label', `${t('suggestion', { label: opts.ghostOf !== undefined && opts.ghostOf !== '' ? `${opts.ghostOf} · ${n.label}` : n.label })}`);
|
|
1854
1855
|
} else {
|
|
1855
1856
|
node.setAttribute('data-flow-key', key);
|
|
1856
1857
|
node.setAttribute('role', 'article');
|
|
@@ -2025,7 +2026,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2025
2026
|
}
|
|
2026
2027
|
}
|
|
2027
2028
|
const gh = ghostsOf();
|
|
2028
|
-
|
|
2029
|
+
const sugLabels = new Map(visibleSuggestions().map((s) => [s.id, s.label] as const));
|
|
2030
|
+
for (const n of gh.nodes) nodesLayer.appendChild(buildNode(n, ghostPosCache.get(n.id) ?? { x: 0, y: 0 }, { ghost: true, ghostOf: n.sid === undefined ? undefined : sugLabels.get(n.sid) }));
|
|
2029
2031
|
for (const s of visibleSuggestions()) {
|
|
2030
2032
|
const first = gh.nodes.find((n) => n.sid === s.id);
|
|
2031
2033
|
const anchor = first ? ghostPosCache.get(first.id) : undefined;
|
|
@@ -2105,6 +2107,20 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2105
2107
|
// GB4 作表单字段控件(表单给了字段名 name):图来自 value(草稿里的值),否则来自 data
|
|
2106
2108
|
const data = graphOf(typeof p.name === 'string' && p.name !== '' ? p.value : p.data);
|
|
2107
2109
|
if (root && typeof p.id === 'string' && p.id !== '') root.id = p.id;
|
|
2110
|
+
// 画布(可聚焦的 group)承载表单传入的标签关联 / 必填 / 无效 / 说明:与自带的说明节点合并,重绘不丢
|
|
2111
|
+
if (stage) {
|
|
2112
|
+
applyCommon(stage, {
|
|
2113
|
+
id: stage.id,
|
|
2114
|
+
aria_label: t('canvas'),
|
|
2115
|
+
labelledby: p.labelledby,
|
|
2116
|
+
required: p.required,
|
|
2117
|
+
invalid: p.invalid,
|
|
2118
|
+
describedby: p.describedby,
|
|
2119
|
+
aria_describedby: p.aria_describedby,
|
|
2120
|
+
errormessage: p.errormessage,
|
|
2121
|
+
aria_errormessage: p.aria_errormessage,
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2108
2124
|
const dsig = graphSig(data);
|
|
2109
2125
|
if (first || (dsig !== lastDataSig && dsig !== graphSig(graph))) {
|
|
2110
2126
|
// 节点集合不变(宿主只回灌了规整后的 meta)时保持视口,不重新适应画布
|
|
@@ -32,23 +32,53 @@ function optionRows(raw: unknown): Rec[] {
|
|
|
32
32
|
value,
|
|
33
33
|
label: typeof item.label === 'string' && item.label !== '' ? item.label : value,
|
|
34
34
|
...(isRec(item.meta) ? { meta: item.meta } : {}),
|
|
35
|
+
// mapping 字段的映射目标:分组(对应 targets_by 字段的值)与提示文字
|
|
36
|
+
...(typeof item.group === 'string' ? { group: item.group } : {}),
|
|
37
|
+
...(typeof item.hint === 'string' && item.hint !== '' ? { hint: item.hint } : {}),
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
return out;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
/** 候选行(已规整)-> mapping 字段的映射目标 { key, label, hint? } */
|
|
44
|
+
function mapTargetOf(row: Rec): Rec {
|
|
45
|
+
return { key: row.value, label: row.label, ...(typeof row.hint === 'string' ? { hint: row.hint } : {}) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 把 columnOptions 并进子表字段(RowEditor)的 columns(数组):返回新数组,不改入参。
|
|
50
|
+
* columnOptions 形如 { "<列键>": [{ value, label }] },只作用于 kind 为 select 的列;
|
|
51
|
+
* 表里给了键(哪怕是空数组)就以它为准(替换该列的静态 / 远程候选),键不在表里的列保持自己的候选。
|
|
52
|
+
*/
|
|
53
|
+
export function withColumnOptions(columns: unknown, columnOptions: unknown): unknown {
|
|
54
|
+
if (!Array.isArray(columns) || !isRec(columnOptions) || Object.keys(columnOptions).length === 0) return columns;
|
|
55
|
+
return columns.map((c) => {
|
|
56
|
+
if (!isRec(c) || c.kind !== 'select' || typeof c.key !== 'string' || !Object.prototype.hasOwnProperty.call(columnOptions, c.key)) return c;
|
|
57
|
+
return { ...c, options: optionRows(columnOptions[c.key]).map((o) => ({ value: o.value, label: o.label })) };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
40
61
|
/**
|
|
41
62
|
* 把 nodeOptions 并进 nodeTypes(原始配置,数组或对象两种写法都认):返回新对象,不改入参。
|
|
42
|
-
*
|
|
63
|
+
* 作用于 kind 为 select(候选项)与 mapping(映射目标候选,可按 group 分组)的字段;没给 nodeOptions(或不是对象)原样返回。
|
|
43
64
|
*/
|
|
44
65
|
export function withNodeOptions(nodeTypes: unknown, nodeOptions: unknown): unknown {
|
|
45
66
|
if (!isRec(nodeOptions) || Object.keys(nodeOptions).length === 0) return nodeTypes;
|
|
46
67
|
const patch = (type: string, def: unknown): unknown => {
|
|
47
68
|
if (!isRec(def) || !Array.isArray(def.fields)) return def;
|
|
48
69
|
const fields = def.fields.map((f) => {
|
|
49
|
-
if (!isRec(f) || f.kind !== 'select' || typeof f.key !== 'string') return f;
|
|
70
|
+
if (!isRec(f) || (f.kind !== 'select' && f.kind !== 'mapping') || typeof f.key !== 'string') return f;
|
|
50
71
|
const k = flowNodeOptionKey(type, f.key);
|
|
51
|
-
|
|
72
|
+
if (!Object.prototype.hasOwnProperty.call(nodeOptions, k)) return f;
|
|
73
|
+
const rows = optionRows(nodeOptions[k]);
|
|
74
|
+
if (f.kind === 'select') return { ...f, options: rows };
|
|
75
|
+
// mapping:候选行换成映射目标;字段写了 targets_by 时按候选的 group 分组(节点取自己依赖别名那一组)
|
|
76
|
+
if (typeof f.targets_by === 'string' && f.targets_by !== '') {
|
|
77
|
+
const grouped: Record<string, Rec[]> = {};
|
|
78
|
+
for (const r of rows) (grouped[typeof r.group === 'string' ? r.group : ''] ??= []).push(mapTargetOf(r));
|
|
79
|
+
return { ...f, targets: [], targets_map: grouped };
|
|
80
|
+
}
|
|
81
|
+
return { ...f, targets: rows.map(mapTargetOf) };
|
|
52
82
|
});
|
|
53
83
|
return { ...def, fields };
|
|
54
84
|
};
|
package/src/data/gantt.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
// 画面用一张 SVG(任务条、进度、刻度线、今日线、依赖线),左栏与表头是 HTML;SVG 只用语义色名类与属性,无内联样式。
|
|
19
19
|
|
|
20
20
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
21
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
21
22
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
22
23
|
import { kitText } from '../i18n/kit-text';
|
|
23
24
|
|
|
@@ -201,7 +202,7 @@ const TICKS_CLASS = 'flex flex-1';
|
|
|
201
202
|
const TICK_CLASS = 'flex-1 border-l border-border-subtle px-1 py-1 text-xs text-fg-muted';
|
|
202
203
|
const BODY_CLASS = 'flex';
|
|
203
204
|
const LABELS_CLASS = 'flex w-40 shrink-0 flex-col';
|
|
204
|
-
const ROW_BTN_CLASS = 'flex h-8 w-full items-center gap-2 px-2 text-start text-sm text-fg transition-colors hover:bg-
|
|
205
|
+
const ROW_BTN_CLASS = 'flex h-8 w-full items-center gap-2 px-2 text-start text-sm text-fg 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';
|
|
205
206
|
const ROW_TITLE_CLASS = 'min-w-0 flex-1 truncate';
|
|
206
207
|
const ROW_OWNER_CLASS = 'shrink-0 text-xs text-fg-muted';
|
|
207
208
|
const GROUP_ROW_CLASS = 'flex h-8 items-center bg-surface-sunken px-2 text-xs font-medium text-fg-muted';
|
|
@@ -386,7 +387,9 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
386
387
|
const pct = showProgress && t.progress > 0 ? kitText('soma.kit.gantt_done', { n: Math.round(t.progress) }, root) : '';
|
|
387
388
|
const ownerPart = t.owner !== '' ? ` ${t.owner}` : '';
|
|
388
389
|
btn.setAttribute('aria-label', kitText('soma.kit.gantt_range', { title: t.title, owner: ownerPart, start: t.startText, end: t.endText, pct }, root));
|
|
389
|
-
|
|
390
|
+
const rowTitle = el('span', ROW_TITLE_CLASS, t.title);
|
|
391
|
+
rowTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
392
|
+
btn.appendChild(rowTitle);
|
|
390
393
|
if (t.owner !== '') btn.appendChild(el('span', ROW_OWNER_CLASS, t.owner));
|
|
391
394
|
labels.appendChild(btn);
|
|
392
395
|
}
|
package/src/data/hero.ts
CHANGED
|
@@ -20,7 +20,8 @@ const CENTER_CLASS = 'mx-auto flex max-w-2xl flex-col items-center gap-4 text-ce
|
|
|
20
20
|
const SPLIT_CLASS = 'flex flex-col gap-8 @md:flex-row @md:items-center';
|
|
21
21
|
const TEXT_CLASS = 'flex flex-1 flex-col gap-3';
|
|
22
22
|
const TEXT_CENTER_CLASS = 'flex flex-col items-center gap-3';
|
|
23
|
-
|
|
23
|
+
// 主标题取展示档(真源 structure.displayTier:字号随密度、字重 / 字距 / 行高统一,工具类 text-display)
|
|
24
|
+
const TITLE_CLASS = 'text-display text-fg';
|
|
24
25
|
const SUBTITLE_CLASS = 'text-lg font-medium text-fg-muted';
|
|
25
26
|
const DESC_CLASS = 'text-base text-fg-muted';
|
|
26
27
|
const ACTIONS_CLASS = 'flex flex-wrap items-center gap-3 pt-2';
|
package/src/data/image-viewer.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// `open` / `index` prop 只在它们自己变化时覆盖内部状态。
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
13
14
|
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
14
15
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
15
16
|
import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util';
|
|
@@ -22,15 +23,15 @@ export const KIT_IMAGE_VIEWER_DEFAULT_MAP = Object.freeze({ id: 'id', src: 'src'
|
|
|
22
23
|
|
|
23
24
|
const ROOT_CLASS = 'flex flex-col gap-3 text-sm text-fg';
|
|
24
25
|
const THUMBS_CLASS = 'grid grid-cols-3 gap-2 @md:grid-cols-4 @xl:grid-cols-6';
|
|
25
|
-
const THUMB_CLASS = 'aspect-square overflow-hidden rounded-lg border border-border-subtle bg-surface-sunken transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
26
|
+
const THUMB_CLASS = 'aspect-square overflow-hidden p-0 rounded-lg border border-border-subtle bg-surface-sunken transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
26
27
|
const THUMB_IMG = 'size-full object-cover';
|
|
27
28
|
const LAYER_CLASS = 'fixed inset-0 z-50 flex flex-col bg-scrim focus-visible:outline-none';
|
|
28
29
|
const BAR_CLASS = 'flex flex-wrap items-center gap-2 border-b border-border-subtle bg-surface-raised px-4 py-2';
|
|
29
30
|
const BAR_TITLE = 'min-w-0 flex-1 truncate font-medium text-fg';
|
|
30
31
|
const BAR_TEXT = 'text-xs text-fg-muted';
|
|
31
|
-
const BAR_BTN = 'inline-flex h-8 min-w-8 items-center justify-center cursor-pointer rounded-md bg-transparent px-2 text-sm text-fg transition-colors hover:bg-
|
|
32
|
+
const BAR_BTN = 'inline-flex h-8 min-w-8 items-center justify-center cursor-pointer rounded-md bg-transparent px-2 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press active:opacity-80 disabled:cursor-not-allowed disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
32
33
|
const STAGE_CLASS = 'flex flex-1 items-center justify-center overflow-hidden p-4';
|
|
33
|
-
const STAGE_IMG = 'max-h-full max-w-full object-contain
|
|
34
|
+
const STAGE_IMG = 'max-h-full max-w-full object-contain motion-safe:transition-transform';
|
|
34
35
|
|
|
35
36
|
/** 缩放档 -> 完整类名(写死,不拼接) */
|
|
36
37
|
const SCALE_CLASS: Readonly<Record<number, string>> = Object.freeze({
|
|
@@ -260,7 +261,9 @@ export function createImageViewer(): SomaComponentDefinition {
|
|
|
260
261
|
layer.setAttribute('data-kit-layer', '');
|
|
261
262
|
layer.tabIndex = -1;
|
|
262
263
|
const bar = mk('div', BAR_CLASS);
|
|
263
|
-
|
|
264
|
+
const barTitle = mk('span', BAR_TITLE, cur.title);
|
|
265
|
+
barTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
266
|
+
bar.appendChild(barTitle);
|
|
264
267
|
bar.appendChild(mk('span', BAR_TEXT, `${index + 1} / ${list.length}`));
|
|
265
268
|
const btn = (act: string, text: string, disabled = false): HTMLButtonElement => {
|
|
266
269
|
const b = mk('button', BAR_BTN, text);
|
package/src/data/index.ts
CHANGED
|
@@ -47,12 +47,15 @@ export { mountKitModal, KIT_MODAL_CLASS_CANDIDATES } from './modal-dialog';
|
|
|
47
47
|
export type { KitModalHandle, KitModalOptions, KitModalSize } from './modal-dialog';
|
|
48
48
|
export { askKitConfirm, KIT_CONFIRM_CLASS_CANDIDATES } from './confirm-dialog';
|
|
49
49
|
export type { KitConfirmOptions } from './confirm-dialog';
|
|
50
|
-
export {
|
|
50
|
+
export { askKitPrompt, KIT_PROMPT_CLASS_CANDIDATES } from './prompt-dialog';
|
|
51
|
+
export type { KitPromptField, KitPromptOptions } from './prompt-dialog';
|
|
52
|
+
export { mountKitComponent, mountKitSelectField, mountKitInputField, mountKitTextareaField, mountKitCheckboxField, createKitEmbedBag } from './embed';
|
|
51
53
|
export type { KitEmitHandlers, KitMount, KitSelectField, KitSelectFieldOptions, KitEmbedBag, KitEmbedHandle } from './embed';
|
|
52
54
|
export { declareKitUses } from './wrapped-candidates';
|
|
53
55
|
export { wrapKitDataComponent, composeKitDataComponents, mapKeys } from './wrap';
|
|
54
56
|
export type { PackProps, WrapDataOptions, WrapOptions, ComposeDataPart, ComposeDataOptions, ComposeEventForward } from './wrap';
|
|
55
57
|
export { createItemList, listItemsOf, KIT_ITEM_LIST_CLASS_CANDIDATES } from './item-list';
|
|
58
|
+
export { createNoticeList, noticeItemsOf, noticeFoldOf, KIT_NOTICE_LIST_CLASS_CANDIDATES } from './notice-list';
|
|
56
59
|
export { createSystemSwitcher, systemItemsOf, filterSystems, KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES } from './system-switcher';
|
|
57
60
|
export { createCalendar, calendarEventsOf, calendarRangeOf, calendarStepDate, KIT_CALENDAR_CLASS_CANDIDATES } from './calendar';
|
|
58
61
|
export { createImageViewer, imageEntriesOf, zoomStep, KIT_IMAGE_VIEWER_CLASS_CANDIDATES } from './image-viewer';
|
|
@@ -163,6 +166,7 @@ import { KIT_FOOTER_CLASS_CANDIDATES } from './footer';
|
|
|
163
166
|
import { KIT_PRICING_TABLE_CLASS_CANDIDATES } from './pricing-table';
|
|
164
167
|
import { KIT_CODE_VIEW_CLASS_CANDIDATES } from './code-view';
|
|
165
168
|
import { KIT_ITEM_LIST_CLASS_CANDIDATES } from './item-list';
|
|
169
|
+
import { KIT_NOTICE_LIST_CLASS_CANDIDATES } from './notice-list';
|
|
166
170
|
import { KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES } from './system-switcher';
|
|
167
171
|
import { KIT_CALENDAR_CLASS_CANDIDATES } from './calendar';
|
|
168
172
|
import { KIT_IMAGE_VIEWER_CLASS_CANDIDATES } from './image-viewer';
|
|
@@ -223,6 +227,7 @@ export const KIT_DATA_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
|
223
227
|
...KIT_PRICING_TABLE_CLASS_CANDIDATES,
|
|
224
228
|
...KIT_CODE_VIEW_CLASS_CANDIDATES,
|
|
225
229
|
...KIT_ITEM_LIST_CLASS_CANDIDATES,
|
|
230
|
+
...KIT_NOTICE_LIST_CLASS_CANDIDATES,
|
|
226
231
|
...KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES,
|
|
227
232
|
...KIT_CALENDAR_CLASS_CANDIDATES,
|
|
228
233
|
...KIT_IMAGE_VIEWER_CLASS_CANDIDATES,
|