soma-kit 0.1.11 → 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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- 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/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- 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 +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- 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 +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- 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 +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- 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/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -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/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- 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 +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/data/embed.ts
CHANGED
|
@@ -8,7 +8,11 @@
|
|
|
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';
|
|
15
|
+
import { kitFail } from '../compile/kit-error';
|
|
12
16
|
|
|
13
17
|
export type KitEmitHandlers = Record<string, (payload: any) => void>;
|
|
14
18
|
|
|
@@ -26,7 +30,7 @@ export interface KitMount {
|
|
|
26
30
|
const UNSAFE_TEMPLATE = /<\s*\/?\s*(script|iframe|object|embed)\b|\son[a-z]+\s*=|javascript\s*:/i;
|
|
27
31
|
|
|
28
32
|
export function assertTrustedTemplate(html: string): string {
|
|
29
|
-
if (UNSAFE_TEMPLATE.test(html))
|
|
33
|
+
if (UNSAFE_TEMPLATE.test(html)) kitFail('KIT-COMP-005', 'templateHtml', 'mountKitComponent: templateHtml 含脚本 / 事件属性 / javascript: 地址,拒绝挂载', '模板里去掉 script / iframe / on* 属性 / javascript: 地址;交互走组件控制器,数据走 props');
|
|
30
34
|
return html;
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -79,17 +83,12 @@ export function mountKitComponent(
|
|
|
79
83
|
|
|
80
84
|
// ── 命令式下拉选择(data 层不走组件树的调用方:分页器页长、字段映射、行内编辑、规则构建器等)──────────
|
|
81
85
|
|
|
82
|
-
export interface KitSelectFieldOptions {
|
|
86
|
+
export interface KitSelectFieldOptions extends KitFieldA11yOptions {
|
|
83
87
|
options: ReadonlyArray<{ value: string; label: string; disabled?: boolean }>;
|
|
84
88
|
value?: string;
|
|
85
89
|
placeholder?: string;
|
|
86
90
|
size?: 'sm' | 'md' | 'lg';
|
|
87
|
-
disabled?: boolean;
|
|
88
91
|
searchable?: boolean;
|
|
89
|
-
/** 加在 Select 根上的类(如固定宽度 w-36;须已在调用方的候选类里) */
|
|
90
|
-
className?: string;
|
|
91
|
-
ariaLabel?: string;
|
|
92
|
-
name?: string;
|
|
93
92
|
/** 用户选中后调(hidden 载体的 value 已更新) */
|
|
94
93
|
onChange?(value: string): void;
|
|
95
94
|
}
|
|
@@ -104,27 +103,141 @@ export interface KitSelectField {
|
|
|
104
103
|
setValue(value: string): void;
|
|
105
104
|
setOptions(options: KitSelectFieldOptions['options']): void;
|
|
106
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;
|
|
107
170
|
dispose(): void;
|
|
108
171
|
}
|
|
109
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
|
+
|
|
110
211
|
/** 在命令式 DOM 里画一个自绘 Select(和页面里的 Select 组件同一份实现,没有原生 <select>) */
|
|
111
212
|
export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField {
|
|
112
|
-
const stage = document.createElement('div');
|
|
113
213
|
let input: HTMLInputElement | null = null;
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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) => {
|
|
128
241
|
if (input) {
|
|
129
242
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
130
243
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
@@ -132,8 +245,7 @@ export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField
|
|
|
132
245
|
opts.onChange?.(next);
|
|
133
246
|
},
|
|
134
247
|
});
|
|
135
|
-
const el =
|
|
136
|
-
el.remove();
|
|
248
|
+
const el = field.el;
|
|
137
249
|
input = el.querySelector<HTMLInputElement>('input[data-kit-value]');
|
|
138
250
|
if (input === null) {
|
|
139
251
|
input = el.ownerDocument.createElement('input');
|
|
@@ -141,18 +253,109 @@ export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField
|
|
|
141
253
|
input.setAttribute('data-kit-value', '');
|
|
142
254
|
el.appendChild(input);
|
|
143
255
|
}
|
|
144
|
-
const field = el.querySelector<HTMLElement>('[role="combobox"]') ?? el;
|
|
145
256
|
return {
|
|
146
257
|
el,
|
|
147
258
|
input,
|
|
148
|
-
field,
|
|
149
|
-
setValue:
|
|
150
|
-
setOptions: (options) =>
|
|
151
|
-
setDisabled: (disabled) =>
|
|
152
|
-
|
|
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,
|
|
153
265
|
};
|
|
154
266
|
}
|
|
155
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
|
+
|
|
156
359
|
// ── 嵌入件释放袋(会整块重建的容器统一用)──────────
|
|
157
360
|
|
|
158
361
|
/** 命令式嵌入件的释放口:组件挂载句柄(destroy)或命令式字段(dispose)二选一 */
|
package/src/data/field-mapper.ts
CHANGED
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
// 每次改动抛 `change { value, ready }`(ready = 必填都已映射且至少映射了一项);
|
|
12
12
|
// save_label 非空时出现保存钮(未就绪时禁用),抛 `saved { value }`;cancel_label 非空时出现取消钮,抛 `cancel {}`。
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
import { bool,
|
|
14
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
15
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
16
16
|
import { kitIcon } from '../base/icons';
|
|
17
17
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
18
|
+
import { setKitFace } from '../recipes';
|
|
18
19
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
19
20
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
20
21
|
import { createKitEmbedBag, mountKitSelectField, type KitSelectField } from './embed';
|
|
@@ -30,10 +31,10 @@ const LABEL_CLASS = 'text-fg';
|
|
|
30
31
|
const KEY_CLASS = 'text-xs text-fg-muted';
|
|
31
32
|
const REQ_CLASS = 'ms-1 text-xs text-danger-on-soft';
|
|
32
33
|
const ARROW_CLASS = 'shrink-0 text-fg-subtle';
|
|
33
|
-
const CONTROL_CLASS = 'block h-
|
|
34
|
-
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';
|
|
35
36
|
const ADD_ROW_CLASS = 'flex flex-wrap items-center gap-2 pt-2';
|
|
36
|
-
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';
|
|
37
38
|
const NOTICE_CLASS = 'rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-on-soft';
|
|
38
39
|
const PREVIEW_TITLE_CLASS = 'text-xs text-fg-muted';
|
|
39
40
|
const PREVIEW_WRAP_CLASS = 'overflow-x-auto rounded-lg border border-border-subtle';
|
|
@@ -43,7 +44,7 @@ const PREVIEW_CELL_CLASS = 'border-t border-border-subtle px-2 py-1 text-fg';
|
|
|
43
44
|
/** 来源下拉(自绘 Select)根上的宽度类,和文本框来源控件同宽 */
|
|
44
45
|
const SELECT_ROOT_CLASS = 'w-48 max-w-full';
|
|
45
46
|
const FOOT_CLASS ='flex items-center justify-end gap-2';
|
|
46
|
-
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';
|
|
47
48
|
const EMPTY_CLASS = 'px-3 py-6 text-center text-fg-muted';
|
|
48
49
|
|
|
49
50
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
@@ -194,9 +195,9 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
194
195
|
},
|
|
195
196
|
},
|
|
196
197
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
197
|
-
controllerFactory: (
|
|
198
|
-
const P = (): Record<string, unknown> =>
|
|
199
|
-
const tx = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params,
|
|
198
|
+
controllerFactory: createKitController((api) => {
|
|
199
|
+
const P = (): Record<string, unknown> => api.props();
|
|
200
|
+
const tx = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params, api.host);
|
|
200
201
|
let root: HTMLElement | null = null;
|
|
201
202
|
let parsed: ParsedMapperData = { targets: [], sources: [], mapping: {}, arrayShape: false, sample: [] };
|
|
202
203
|
let draft: KitFieldMapping = {};
|
|
@@ -262,6 +263,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
262
263
|
return { node: field.el, control: field.input };
|
|
263
264
|
}
|
|
264
265
|
const input = el('input', CONTROL_CLASS);
|
|
266
|
+
setKitFace(input, 'field');
|
|
265
267
|
input.type = 'text';
|
|
266
268
|
input.setAttribute('autocomplete', 'off');
|
|
267
269
|
input.setAttribute('aria-label', label);
|
|
@@ -345,6 +347,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
345
347
|
if (allowAdd()) {
|
|
346
348
|
const add = el('div', ADD_ROW_CLASS);
|
|
347
349
|
const target = el('input', CONTROL_CLASS);
|
|
350
|
+
setKitFace(target, 'field');
|
|
348
351
|
target.type = 'text';
|
|
349
352
|
target.placeholder = tx('soma.kit.fm_target');
|
|
350
353
|
target.setAttribute('aria-label', tx('soma.kit.fm_add_target'));
|
|
@@ -359,6 +362,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
359
362
|
add.appendChild(src.node);
|
|
360
363
|
const btn = el('button', BTN_CLASS, tx('soma.kit.add'));
|
|
361
364
|
btn.type = 'button';
|
|
365
|
+
setKitFace(btn, 'raised');
|
|
362
366
|
btn.setAttribute('data-kit-add', '');
|
|
363
367
|
btn.disabled = locked();
|
|
364
368
|
add.appendChild(btn);
|
|
@@ -407,7 +411,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
407
411
|
|
|
408
412
|
const commit = (): void => {
|
|
409
413
|
paintStatus();
|
|
410
|
-
|
|
414
|
+
api.emit('change', { value: exportMapping(draft, parsed.arrayShape), ready: ready() });
|
|
411
415
|
};
|
|
412
416
|
|
|
413
417
|
const setField = (key: string, source: string): void => {
|
|
@@ -443,12 +447,15 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
443
447
|
foot.setAttribute('data-kit-foot', '');
|
|
444
448
|
const reset = el('button', BTN_CLASS);
|
|
445
449
|
reset.type = 'button';
|
|
450
|
+
setKitFace(reset, 'raised');
|
|
446
451
|
reset.setAttribute('data-kit-reset', '');
|
|
447
452
|
const cancel = el('button', BTN_CLASS);
|
|
448
453
|
cancel.type = 'button';
|
|
454
|
+
setKitFace(cancel, 'raised');
|
|
449
455
|
cancel.setAttribute('data-kit-cancel', '');
|
|
450
456
|
saveBtn = el('button', SAVE_CLASS);
|
|
451
457
|
saveBtn.type = 'button';
|
|
458
|
+
setKitFace(saveBtn, 'raised');
|
|
452
459
|
saveBtn.setAttribute('data-kit-save', '');
|
|
453
460
|
const boxOf = (child: HTMLElement): HTMLElement => { const b = el('div', ''); b.appendChild(child); return b; };
|
|
454
461
|
boxes.reset = boxOf(reset);
|
|
@@ -504,41 +511,39 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
504
511
|
if (t?.closest('[data-kit-cancel]')) {
|
|
505
512
|
draft = { ...parsed.mapping };
|
|
506
513
|
rebuildRows();
|
|
507
|
-
|
|
514
|
+
api.emit('cancel', {});
|
|
508
515
|
return;
|
|
509
516
|
}
|
|
510
517
|
if (t?.closest('[data-kit-save]')) {
|
|
511
518
|
if (locked() || !ready() || kb.busy()) return;
|
|
512
519
|
const value = exportMapping(draft, parsed.arrayShape);
|
|
513
|
-
|
|
520
|
+
api.emit('saved', { values: { value }, object: str(P().object), model: { value }, mode: str(P().mode, 'edit'), value });
|
|
514
521
|
}
|
|
515
522
|
});
|
|
516
523
|
};
|
|
517
524
|
|
|
518
525
|
return {
|
|
519
|
-
|
|
520
|
-
|
|
526
|
+
busyAware: true,
|
|
527
|
+
attach(rootEl) {
|
|
528
|
+
root = rootEl;
|
|
521
529
|
build(root);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
530
|
+
return () => {
|
|
531
|
+
embeds.release(rowsBox);
|
|
532
|
+
for (const fn of removers) fn();
|
|
533
|
+
removers = [];
|
|
534
|
+
root = null;
|
|
535
|
+
rowsBox = null;
|
|
536
|
+
noticeEl = null;
|
|
537
|
+
previewBox = null;
|
|
538
|
+
saveBtn = null;
|
|
539
|
+
};
|
|
525
540
|
},
|
|
526
|
-
|
|
541
|
+
render(rootEl) {
|
|
542
|
+
root = rootEl;
|
|
527
543
|
if (!sync()) paintStatus();
|
|
528
544
|
paintChrome();
|
|
529
545
|
},
|
|
530
|
-
onUnmount(): void {
|
|
531
|
-
kb.dispose();
|
|
532
|
-
embeds.release(rowsBox);
|
|
533
|
-
for (const fn of removers) fn();
|
|
534
|
-
removers = [];
|
|
535
|
-
root = null;
|
|
536
|
-
rowsBox = null;
|
|
537
|
-
noticeEl = null;
|
|
538
|
-
previewBox = null;
|
|
539
|
-
saveBtn = null;
|
|
540
|
-
},
|
|
541
546
|
};
|
|
542
|
-
},
|
|
547
|
+
}),
|
|
543
548
|
};
|
|
544
549
|
}
|
|
@@ -18,10 +18,17 @@ 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 }],画成虚影,可采纳或拒绝' },
|
|
24
|
-
|
|
31
|
+
nodeOptions: { type: 'object', default: {}, desc: '节点字段候选项 { "<节点类型>.<字段键>": [{ value, label, meta? }] }(页面写 nodeOptions: view.<成员>,由展示对象按别的字段取数后整体替换引用写入):并进该类型 select 字段的 options,meta 在选中时并入节点;键不在表里的字段保持自己的静态 / 远程候选,键在表里(含空数组)以它为准' },
|
|
25
32
|
allowCycles: { type: 'boolean', default: false, desc: '允许成环;缺省拒绝形成环的连线' },
|
|
26
33
|
statusTones: { type: 'object', default: {}, desc: '节点状态值 -> 语气(neutral / info / success / warning / danger / primary)' },
|
|
27
34
|
texts: { type: 'object', default: {}, desc: '文案覆盖(键见 FLOW_DEFAULT_TEXTS)' },
|