soma-kit 0.1.11 → 0.1.12
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 +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -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 +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- 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 +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- 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 +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- 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 +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- 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 +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- 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/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -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 +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- 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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- 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 +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -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 +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- 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 +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- 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 +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- 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 +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -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 +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -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 +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -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/data/prompt-dialog.ts +0 -235
- 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/object-form.ts
CHANGED
|
@@ -16,33 +16,34 @@
|
|
|
16
16
|
// 字段用什么基础组件由 IR 的 KitCell 决定(本组件不挑选);模板里为每个已登记的基础组件各写一个 `item:<名>` 行模板,
|
|
17
17
|
// 按 `role_by: f.component` 选用。浏览器侧与编译侧必须用同一个已登记组件表(缺口 G21),所以导出 `createKitObjectForm(registered)`。
|
|
18
18
|
|
|
19
|
-
import type {
|
|
19
|
+
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
20
|
+
import { createKitController, wireKitTablist, type KitApi, type KitTablistHandle, type KitView } from '../base/shared';
|
|
20
21
|
import { matchSubmitKey } from 'soma-core/keyboard';
|
|
21
22
|
import { createFormDraft } from 'soma-foundation/data/validation';
|
|
22
23
|
import { KIT_FORM_LINKAGE_LIMITS } from 'soma-foundation/kit-limits';
|
|
23
|
-
import {
|
|
24
|
+
import { planOptionSourceRequest } from 'soma-foundation/data/declare';
|
|
25
|
+
import { testRegexGuarded } from 'soma-foundation/predicates';
|
|
26
|
+
import { SOMA_QUERY_LIMITS_CORE } from 'soma-foundation/data/generated';
|
|
24
27
|
import type { SomaOptionSourceParams } from 'soma-foundation/data/values';
|
|
25
28
|
import { KIT_CLASS_DEFAULTS, KIT_GRAMMAR, KIT_GROUP_MARKERS, KIT_REQUIRED_STAR_CLASS } from '../object-renderer/defaults';
|
|
26
29
|
import { KIT_BUSY_PROP_DEFS, cancelKitAction, isKitActionBusy, isKitActionCancelable, kitBusyOf, onKitActionBusy } from '../base/action-busy';
|
|
27
|
-
import { holds } from '../object-renderer/linkage';
|
|
28
|
-
import { adoptPlan, gateOutcomeNames, gateReason, sameValue, type KitAdoptDecl, type KitAdoptPlan, type KitGateDecl } from '../object-renderer/adopt-gate';
|
|
29
30
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
30
31
|
import { fetchRemoteOptionRows, rowsOfOptionsResponse } from './remote-options';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
32
|
+
import { getKitAppEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
33
|
+
import { flowOptionSlots, flowOptionsOfRows, withFlowOptions, type FlowOptionResolved, type FlowOptionSlot } from './flow-remote-options';
|
|
34
|
+
import { clearFlowNodeField, flowValueNodes } from './flow-node-options';
|
|
33
35
|
import { asyncResultOf, outcomePanelData } from './async-result-panel';
|
|
34
36
|
import { TONE_SOFT } from './shape-util';
|
|
35
|
-
import { isKitOutcomeStale } from '../object-renderer/outcome-draft';
|
|
36
37
|
import { registerKitFormDraft, type KitFormDraftHandle } from './form-draft-registry';
|
|
37
38
|
import { readDetailResponse, resolveDetailParams, type KitFormDetail } from '../object-renderer/form-detail';
|
|
38
39
|
import { kitText } from '../i18n/kit-text';
|
|
39
40
|
import { askKitConfirm } from './confirm-dialog';
|
|
40
|
-
import { rowColumnsOf, validateInlineRows } from './row-editor';
|
|
41
|
+
import { rowColumnsOf, validateInlineRowCells, validateInlineRows, type KitRowCellError } from './row-editor';
|
|
41
42
|
import { mergeClass } from '../object-renderer/merge-class';
|
|
42
|
-
import {
|
|
43
|
-
import { kitActionExtras } from '../biz/shared/runtime-hub';
|
|
44
|
-
import { onKitOptionsInvalidate } from './options-bus';
|
|
43
|
+
import { resolveDefaults as resolveFieldDefaults } from '../object-renderer/field-value';
|
|
45
44
|
import type { KitCell } from '../object-renderer/types';
|
|
45
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
46
|
+
import { kitControlRecipe } from '../recipes';
|
|
46
47
|
|
|
47
48
|
// M 波 G3:表单布局 / 筛选折叠 / 页签 / 离开守卫的类串与文案,全部读真源 formLinkage
|
|
48
49
|
const FL = KIT_GRAMMAR.formLinkage as {
|
|
@@ -53,6 +54,7 @@ const FL = KIT_GRAMMAR.formLinkage as {
|
|
|
53
54
|
optionsFrom: { rowsPathCandidates: string[] };
|
|
54
55
|
};
|
|
55
56
|
const FORM_BODY_CLASS = FL.formLayout.bodyClass;
|
|
57
|
+
const OPTIONS_RETRY_CLASS = kitControlRecipe({ variant: 'ghost', size: 'sm' });
|
|
56
58
|
|
|
57
59
|
// ── 默认类(语义色名 + 小闭集尺度) ──
|
|
58
60
|
|
|
@@ -62,12 +64,7 @@ export const KIT_FORM_CLASS = {
|
|
|
62
64
|
actions: 'mt-4 flex flex-wrap items-end justify-end gap-2',
|
|
63
65
|
notice: 'mb-4 flex flex-wrap items-center gap-3 rounded-lg border border-border-subtle bg-danger-soft px-3 py-2 text-sm text-danger-on-soft',
|
|
64
66
|
noticeHidden: 'hidden',
|
|
65
|
-
/**
|
|
66
|
-
adoptBar: 'mb-4 flex flex-wrap items-center gap-3 rounded-lg border border-border-subtle bg-info-soft px-3 py-2 text-sm text-info-on-soft',
|
|
67
|
-
adoptText: 'min-w-0 flex-1 basis-48 break-words',
|
|
68
|
-
adoptBtnWrap: 'shrink-0 whitespace-nowrap',
|
|
69
|
-
adoptedTag: 'ml-2 rounded-md bg-info-soft px-2 text-xs font-medium text-info-on-soft',
|
|
70
|
-
gateNote: 'w-full text-sm text-fg-muted',
|
|
67
|
+
/** 阶段闸门原因 */
|
|
71
68
|
/** 请求结果常驻槽(view.form.result):外框 + 随状态换的语气底色(TONE_SOFT) */
|
|
72
69
|
resultBox: 'mb-4 flex flex-col gap-1 rounded-md px-3 py-2 text-sm',
|
|
73
70
|
resultTitle: 'font-medium',
|
|
@@ -93,13 +90,14 @@ export const KIT_FORM_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
93
90
|
'mb-4', 'items-center', 'gap-3', 'rounded-lg', 'border', 'border-border-subtle', 'bg-danger-soft', 'px-3', 'py-2', 'text-sm', 'text-danger-on-soft',
|
|
94
91
|
'hidden', 'flex-col', 'gap-1', 'font-medium', 'text-fg', 'text-xs', 'text-fg-muted', 'col-span-6', '@md:col-span-3',
|
|
95
92
|
...[KIT_FORM_CLASS.resultBox, KIT_FORM_CLASS.resultTitle, KIT_FORM_CLASS.resultText, ...Object.values(TONE_SOFT)].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
96
|
-
...[KIT_FORM_CLASS.
|
|
93
|
+
...[KIT_FORM_CLASS.detailState].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
97
94
|
...Object.values(KIT_REQUIRED_STAR_CLASS).flatMap((s) => s.split(/\s+/)),
|
|
98
95
|
...[KIT_CLASS_DEFAULTS.groupTitle, KIT_CLASS_DEFAULTS.groupToggle, KIT_CLASS_DEFAULTS.groupMark].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
99
96
|
...[
|
|
100
97
|
FORM_BODY_CLASS, ...FL.formLayout.labelWidthClasses, ...Object.values(FL.formLayout.cellClass), ...Object.values(FL.formLayout.labelClass),
|
|
101
98
|
FL.filterOptions.badgeClass, FL.filterOptions.toggleWrapClass, FL.groupsAs.barClass, FL.groupsAs.tabClass,
|
|
102
99
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
100
|
+
...OPTIONS_RETRY_CLASS.split(/\s+/),
|
|
103
101
|
]);
|
|
104
102
|
|
|
105
103
|
// ── 对外形状与数据规整纯函数 ──
|
|
@@ -153,22 +151,22 @@ export interface KitObjectFormProps {
|
|
|
153
151
|
leaveGuard?: boolean;
|
|
154
152
|
/** 编辑详情:mode 为 edit 时先按行取详情再作初值(behavior.detail 编来;见 object-renderer/form-detail.ts) */
|
|
155
153
|
detail?: KitFormDetail;
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
|
|
154
|
+
/** 本页有效的业务信封(编译期按页面 > 应用解析后传入;缺省 / 空对象 = 未声明,运行时退回宿主查找) */
|
|
155
|
+
envelope?: KitEnvelope;
|
|
156
|
+
/** 底栏动作(view.form.footerActions 编来):点击抛槽位事件 footer_action_<序号> { id },页面事件给每个 request / download 动作各绑一条管道 */
|
|
157
|
+
footerActions?: Array<{ id: string; label: string }>;
|
|
160
158
|
/** 请求结果常驻槽(view.form.result):outcome 是 request 动作 into */
|
|
161
159
|
result?: { outcome: string; title?: string };
|
|
162
|
-
/**
|
|
163
|
-
adopt?: KitAdoptDecl;
|
|
164
|
-
/** StepForm 阶段闸门:不满足时提交按钮禁用并显示原因 */
|
|
165
|
-
gate?: KitGateDecl;
|
|
166
|
-
/** StepForm:各步已确认的 model { s<i>: {字段: 值} }(闸门谓词的 steps.s<i>.字段 取值来源;字段 default / options.params / derive 的 $steps 也读它) */
|
|
167
|
-
gateSteps?: Record<string, unknown>;
|
|
168
|
-
/** GB2 字段初值 { 字段: 字面量 | $filter.x | $row.x | $steps.s<i>.x }:只在新建时填「空且没改过」的字段 */
|
|
160
|
+
/** GB2 字段初值 { 字段: 字面量 }:只在新建时填「空且没改过」的字段 */
|
|
169
161
|
defaults?: Record<string, unknown>;
|
|
170
162
|
/** GB3 隐藏草稿字段:随草稿提交、不画;仍按字典 rules 校验,permission: create 的在编辑态不提交 */
|
|
171
163
|
hiddenFields?: string[];
|
|
164
|
+
/** 展示对象给出的字段状态 { 字段: { hidden / disabled / required } }(叶子由页面路径绑定求值成布尔):hidden 不画但值保留并随草稿提交,disabled 置灰,required 标星并在提交 / 即时校验里要求非空 */
|
|
165
|
+
/** 展示对象给出的提交闸门(路径已由 core 求成布尔):为真时禁用提交按钮,字段仍可编辑 */
|
|
166
|
+
submitDisabled?: boolean | string;
|
|
167
|
+
fieldState?: Record<string, { hidden?: boolean | string; disabled?: boolean | string; required?: boolean | string; /** 展示对象给出的候选项来源(view.<成员>,core 求成数组 [{ value, label }]):给了就替换该字段的静态 / 远程候选,不再自取 options.from */ options?: unknown; nodeOptions?: unknown }>;
|
|
168
|
+
/** 页面把草稿变化接给了展示对象方法(view.form.onDraft):草稿首次建好时补发一次 draft_change,让展示对象状态与空草稿对齐 */
|
|
169
|
+
draftNotify?: boolean;
|
|
172
170
|
}
|
|
173
171
|
|
|
174
172
|
const DEFAULT_SUBMIT_LABEL = 'soma.kit.submit';
|
|
@@ -205,8 +203,15 @@ function cellsOf(raw: unknown): KitCell[] {
|
|
|
205
203
|
return Array.isArray(raw) ? raw.filter((c): c is KitCell => isRec(c) && typeof c.field === 'string') : [];
|
|
206
204
|
}
|
|
207
205
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
206
|
+
/** 页签条的一枚页签(独立 tablist 条里的行,不再混在字段栅格里) */
|
|
207
|
+
export interface KitFormTabRow {
|
|
208
|
+
id: string;
|
|
209
|
+
label: string;
|
|
210
|
+
groupId: string;
|
|
211
|
+
/** aria-selected 取值 'true' | 'false' */
|
|
212
|
+
selected: string;
|
|
213
|
+
tabClass: string;
|
|
214
|
+
}
|
|
210
215
|
|
|
211
216
|
/** 一行字段的行变量(行模板按 `f.*` 读,不含函数) */
|
|
212
217
|
export interface KitFormRow {
|
|
@@ -233,17 +238,15 @@ export interface KitFormRow {
|
|
|
233
238
|
groupToggleClass: string;
|
|
234
239
|
/** 控件 + 说明 + 错误行的包裹类(标签在左时与标签并排) */
|
|
235
240
|
bodyClass: string;
|
|
236
|
-
/**
|
|
237
|
-
|
|
238
|
-
|
|
241
|
+
/** 远程选项失败时的显式单字段重试按钮 */
|
|
242
|
+
optionsRetry?: boolean;
|
|
243
|
+
optionsRetryClass?: string;
|
|
244
|
+
optionsRetryText?: string;
|
|
239
245
|
/** 必填星号(红色子元素,不并入标签文本):文字与类;不必填时文字为空、类为 hidden */
|
|
240
246
|
starStart?: string;
|
|
241
247
|
starStartClass?: string;
|
|
242
248
|
starEnd?: string;
|
|
243
249
|
starEndClass?: string;
|
|
244
|
-
/** 采纳标签(「已采纳」):当前值就是被采纳的建议值时有字,否则空串 + hidden */
|
|
245
|
-
adopted?: string;
|
|
246
|
-
adoptedClass?: string;
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
// ── 级联(Cascader)选项树 ──
|
|
@@ -306,7 +309,7 @@ function propDefaults(def: SomaComponentDefinition | undefined): Rec {
|
|
|
306
309
|
* @param registered 已登记的基础组件表(内置 13 个 + 应用 `App*`),名字 → 定义。
|
|
307
310
|
* 表里必须有 `Button`(按钮行用)与 `Text`(edit 模式下 create-only 字段画成只读)。
|
|
308
311
|
*/
|
|
309
|
-
export function createKitObjectForm(registered: Readonly<Record<string, SomaComponentDefinition>>): SomaComponentDefinition {
|
|
312
|
+
export function createKitObjectForm(registered: Readonly<Record<string, SomaComponentDefinition>> = {}): SomaComponentDefinition {
|
|
310
313
|
const names = Object.keys(registered);
|
|
311
314
|
const nameSet = new Set(names);
|
|
312
315
|
|
|
@@ -319,17 +322,18 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
319
322
|
+ `<span data-soma-id="lbls_${name}" class="hidden" aria-hidden="true"></span>`
|
|
320
323
|
+ `<span data-soma-id="lblt_${name}"></span>`
|
|
321
324
|
+ `<span data-soma-id="lble_${name}" class="hidden" aria-hidden="true"></span>`
|
|
322
|
-
+
|
|
325
|
+
+ '</label>'
|
|
323
326
|
+ `<div data-soma-id="body_${name}" class="${FORM_BODY_CLASS}">`
|
|
324
327
|
+ `<div data-soma-component="${name}" data-soma-id="fld_${name}"></div>`
|
|
325
328
|
+ `<p data-soma-id="help_${name}" class="${KIT_FORM_CLASS.errorHidden}"></p>`
|
|
326
329
|
+ `<p data-soma-id="err_${name}" role="alert" class="${KIT_FORM_CLASS.errorHidden}"></p>`
|
|
330
|
+
+ `<button type="button" data-soma-id="options_retry_${name}" class="hidden"></button>`
|
|
327
331
|
+ '</div></div></template>').join('');
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
+ '<button type="button" data-soma-id="tab_btn" data-kit-group-tab="" aria-
|
|
332
|
-
+ '</div
|
|
332
|
+
// 页签条(form.groups + groupsAs: tabs):独立 role=tablist 容器,页签 role=tab + aria-selected;
|
|
333
|
+
// roving tabindex / 方向键 / aria-controls / 面板(字段栅格)关联由 wireKitTablist(共享页签接线)在 DOM 同步里补齐
|
|
334
|
+
const tabbarTemplate = `<div data-soma-id="tabbar" role="tablist" class="hidden"><template data-soma-role="item">`
|
|
335
|
+
+ '<button type="button" data-soma-id="tab_btn" data-kit-group-tab="" data-kit-face="tab" role="tab" aria-selected="false" tabindex="-1"></button>'
|
|
336
|
+
+ '</template></div>';
|
|
333
337
|
// 分组标题行(form.groups 平铺后的标题格):_group = 可折叠(h4 里的 button),_grouptitle = 不可折叠的纯标题
|
|
334
338
|
const groupTemplates = '<template data-soma-role="item:_group">'
|
|
335
339
|
+ '<div data-soma-id="cell__group">'
|
|
@@ -350,16 +354,10 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
350
354
|
+ '<span data-soma-id="notice_text"></span>'
|
|
351
355
|
+ '<span data-soma-id="refresh_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_refresh"></div></span>'
|
|
352
356
|
+ '</div>'
|
|
353
|
-
// 采纳条:request 的结果返回了建议值时出现(只改草稿,不提交)
|
|
354
|
-
+ `<div data-soma-id="adopt_bar" role="status" class="${KIT_FORM_CLASS.noticeHidden}">`
|
|
355
|
-
+ `<span data-soma-id="adopt_text" class="${KIT_FORM_CLASS.adoptText}"></span>`
|
|
356
|
-
+ '<span data-soma-id="adopt_go_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_adopt"></div></span>'
|
|
357
|
-
+ '<span data-soma-id="adopt_skip_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_adopt_skip"></div></span>'
|
|
358
|
-
+ '<span data-soma-id="adopt_ask_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_adopt_ask"></div></span>'
|
|
359
|
-
+ '</div>'
|
|
360
357
|
// 编辑详情取数中:处理中状态块(取数失败走上面的 notice + 重试钮)
|
|
361
358
|
+ `<div data-soma-id="detail_state" role="status" class="${KIT_FORM_CLASS.noticeHidden}"></div>`
|
|
362
|
-
+
|
|
359
|
+
+ tabbarTemplate
|
|
360
|
+
+ `<div data-soma-id="grid" class="${KIT_FORM_CLASS.grid}">${itemTemplates}${groupTemplates}${fallbackTemplate}</div>`
|
|
363
361
|
// 请求结果常驻槽(view.form.result,GA3):进行中 / 失败 / 成功都留在表单里,不被弹窗遮罩盖住,也不止弹一次 toast
|
|
364
362
|
+ `<div data-soma-id="result_box" role="status" aria-live="polite" class="${KIT_FORM_CLASS.noticeHidden}">`
|
|
365
363
|
+ '<p data-soma-id="res_title"></p><p data-soma-id="res_text"></p>'
|
|
@@ -374,8 +372,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
374
372
|
// 底栏动作(view.form.footerActions):每项一个按钮,点击抛 footer_action { id }
|
|
375
373
|
+ '<span data-soma-id="extra"><template data-soma-role="item"><span data-soma-id="xa_wrap"><div data-soma-component="Button" data-soma-id="xa_btn"></div></span></template></span>'
|
|
376
374
|
// 阶段闸门原因:提交被闸门拦住时常驻显示,不允许静默拦截
|
|
377
|
-
+ `<p data-soma-id="gate_note" role="status" class="${KIT_FORM_CLASS.noticeHidden}"></p>`
|
|
378
|
-
+ '<span data-soma-id="gate_run_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_gate_run"></div></span>'
|
|
379
375
|
+ '</div>'
|
|
380
376
|
+ '</form>';
|
|
381
377
|
|
|
@@ -392,8 +388,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
392
388
|
[`lbls_${name}@class`]: 'f.starStartClass',
|
|
393
389
|
[`lble_${name}`]: 'f.starEnd',
|
|
394
390
|
[`lble_${name}@class`]: 'f.starEndClass',
|
|
395
|
-
[`adp_${name}`]: 'f.adopted',
|
|
396
|
-
[`adp_${name}@class`]: 'f.adoptedClass',
|
|
397
391
|
[`lbl_${name}@for`]: 'f.id',
|
|
398
392
|
[`lbl_${name}@class`]: 'f.labelClass',
|
|
399
393
|
[`body_${name}@class`]: 'f.bodyClass',
|
|
@@ -402,6 +396,8 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
402
396
|
[`help_${name}@class`]: 'f.helpClass',
|
|
403
397
|
[`err_${name}`]: 'f.error',
|
|
404
398
|
[`err_${name}@class`]: 'f.errorClass',
|
|
399
|
+
[`options_retry_${name}`]: 'f.optionsRetryText',
|
|
400
|
+
[`options_retry_${name}@class`]: 'f.optionsRetryClass',
|
|
405
401
|
},
|
|
406
402
|
};
|
|
407
403
|
}
|
|
@@ -418,15 +414,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
418
414
|
grp_mark: 'f.groupMark',
|
|
419
415
|
},
|
|
420
416
|
};
|
|
421
|
-
groupShow['item:_tab'] = {
|
|
422
|
-
show: {
|
|
423
|
-
'cell__tab@class': 'f.cellClass',
|
|
424
|
-
tab_btn: 'f.label',
|
|
425
|
-
'tab_btn@aria-pressed': 'f.tabPressed',
|
|
426
|
-
'tab_btn@data-kit-group': 'f.groupId',
|
|
427
|
-
'tab_btn@class': 'f.tabClass',
|
|
428
|
-
},
|
|
429
|
-
};
|
|
430
417
|
groupShow['item:_grouptitle'] = {
|
|
431
418
|
show: {
|
|
432
419
|
'cell__grouptitle@class': 'f.cellClass',
|
|
@@ -445,6 +432,16 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
445
432
|
detail_state: 'ctrl.detailStateText',
|
|
446
433
|
'refresh_wrap@class': 'ctrl.refreshWrapClass',
|
|
447
434
|
kit_refresh: { when: 'ctrl.conflict', props: { label: 'ctrl.refreshLabel', variant: 'ctrl.neutralVariant', size: 'ctrl.smallSize' } },
|
|
435
|
+
'tabbar@class': 'ctrl.tabbarClass',
|
|
436
|
+
tabbar: {
|
|
437
|
+
bind: { obj: 'ctrl.tabRows', var: 't' },
|
|
438
|
+
show: {
|
|
439
|
+
tab_btn: 't.label',
|
|
440
|
+
'tab_btn@aria-selected': 't.selected',
|
|
441
|
+
'tab_btn@data-kit-group': 't.groupId',
|
|
442
|
+
'tab_btn@class': 't.tabClass',
|
|
443
|
+
},
|
|
444
|
+
},
|
|
448
445
|
'grid@class': 'ctrl.gridClass',
|
|
449
446
|
grid: {
|
|
450
447
|
bind: { obj: 'ctrl.rows', var: 'f', role_by: 'f.component' },
|
|
@@ -479,18 +476,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
479
476
|
bind: { obj: 'ctrl.footerRows', var: 'x' },
|
|
480
477
|
show: { xa_btn: { props: { label: 'x.label', variant: 'x.variant', disabled: 'x.disabled' } } },
|
|
481
478
|
},
|
|
482
|
-
'adopt_bar@class': 'ctrl.adoptBarClass',
|
|
483
|
-
adopt_text: 'ctrl.adoptText',
|
|
484
|
-
'adopt_go_wrap@class': 'ctrl.adoptGoWrapClass',
|
|
485
|
-
kit_adopt: { props: { label: 'ctrl.adoptLabel', variant: 'ctrl.primaryVariant', size: 'ctrl.smallSize', disabled: 'ctrl.busy' } },
|
|
486
|
-
kit_adopt_skip: { props: { label: 'ctrl.adoptSkipLabel', variant: 'ctrl.ghostVariant', size: 'ctrl.smallSize' } },
|
|
487
|
-
'adopt_skip_wrap@class': 'ctrl.adoptSkipWrapClass',
|
|
488
|
-
'adopt_ask_wrap@class': 'ctrl.adoptAskWrapClass',
|
|
489
|
-
kit_adopt_ask: { props: { label: 'ctrl.adoptAskLabel', variant: 'ctrl.neutralVariant', size: 'ctrl.smallSize', disabled: 'ctrl.adoptAskDisabled' } },
|
|
490
|
-
'gate_note@class': 'ctrl.gateNoteClass',
|
|
491
|
-
gate_note: 'ctrl.gateNote',
|
|
492
|
-
'gate_run_wrap@class': 'ctrl.gateRunWrapClass',
|
|
493
|
-
kit_gate_run: { props: { label: 'ctrl.gateRunLabel', variant: 'ctrl.neutralVariant', size: 'ctrl.smallSize', disabled: 'ctrl.gateRunDisabled' } },
|
|
494
479
|
},
|
|
495
480
|
} as unknown as SomaComponentDefinition['uiConfig'];
|
|
496
481
|
|
|
@@ -503,21 +488,19 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
503
488
|
const searchEvents = names.filter((n) => emitsOf(n, 'search')).map((n) => ({ somaId: `fld_${n}`, domEvent: 'search', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldSearch' }));
|
|
504
489
|
// 级联的懒加载(Cascader 抛 load)
|
|
505
490
|
const loadEvents = names.filter((n) => emitsOf(n, 'load')).map((n) => ({ somaId: `fld_${n}`, domEvent: 'load', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldLoad' }));
|
|
491
|
+
const optionRetryEvents = names.map((n) => ({ somaId: `options_retry_${n}`, domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.retryOptions' }));
|
|
506
492
|
const eventConfig = [
|
|
507
493
|
...changeEvents,
|
|
508
494
|
...pickEvents,
|
|
509
495
|
...searchEvents,
|
|
510
496
|
...loadEvents,
|
|
497
|
+
...optionRetryEvents,
|
|
511
498
|
{ somaId: 'kit_submit', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.submitForm' },
|
|
512
499
|
{ somaId: 'kit_reset', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.resetForm' },
|
|
513
500
|
{ somaId: 'kit_toggle', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.toggleCollapsed' },
|
|
514
501
|
{ somaId: 'kit_cancel', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.cancelForm' },
|
|
515
502
|
{ somaId: 'xa_btn', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.onFooterAction' },
|
|
516
503
|
{ somaId: 'kit_refresh', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.refreshAfterConflict' },
|
|
517
|
-
{ somaId: 'kit_adopt', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.adoptSuggestion' },
|
|
518
|
-
{ somaId: 'kit_adopt_skip', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.dismissSuggestion' },
|
|
519
|
-
{ somaId: 'kit_adopt_ask', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.askSuggestion' },
|
|
520
|
-
{ somaId: 'kit_gate_run', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.runGate' },
|
|
521
504
|
] as unknown as SomaComponentDefinition['eventConfig'];
|
|
522
505
|
|
|
523
506
|
return {
|
|
@@ -538,9 +521,10 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
538
521
|
resetLabel: { type: 'string', default: '', desc: '重置按钮文字' },
|
|
539
522
|
cancelLabel: { type: 'string', default: '', desc: '取消按钮文字;空则不显示取消' },
|
|
540
523
|
disabled: { type: 'boolean', default: false },
|
|
524
|
+
submitDisabled: { type: 'boolean', default: false, desc: '展示对象给出(view.form.submitDisabled: view.<成员>):为真时只禁用提交按钮并拦下回车提交,字段仍可编辑(与整表 disabled 不同);筛选表单不吃' },
|
|
541
525
|
labelPosition: { type: 'string', default: '', desc: '标签位置 left / right(缺省在控件上方)' },
|
|
542
526
|
labelWidth: { type: 'number', default: 3, desc: '标签宽度档 1~5(left / right 生效)' },
|
|
543
|
-
scrollToError: { type: 'boolean', default:
|
|
527
|
+
scrollToError: { type: 'boolean', default: true, desc: '校验失败后滚到首个出错字段并聚焦' },
|
|
544
528
|
requiredMark: { type: 'string', default: '', desc: '必填星号位置:start = 标签前,缺省在后' },
|
|
545
529
|
collapsible: { type: 'boolean', default: false, desc: 'filter:折叠搜索区' },
|
|
546
530
|
collapsedRows: { type: 'number', default: 1, desc: 'filter 折叠时保留的行数' },
|
|
@@ -550,13 +534,12 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
550
534
|
validateOn: { type: 'array', default: [], desc: 'change / blur 时即时校验' },
|
|
551
535
|
leaveGuard: { type: 'boolean', default: false, desc: '草稿有改动时拦截离开' },
|
|
552
536
|
footerActions: { type: 'array', default: [], desc: '底栏动作 [{ id, label }](view.form.footerActions 编来):在提交旁多画按钮,点击抛 footer_action' },
|
|
553
|
-
changeFields: { type: 'array', default: [], desc: '字段变化触发请求(view.form.onChange 编来):列出的字段值变化后防抖抛 field_change { field, value };防抖毫秒读 kit-limits 的 formLinkage.requestExt.changeRequestDebounceMs' },
|
|
554
537
|
detail: { type: 'object', default: {}, desc: '编辑详情 { api, params?, unwrap? }:mode 为 edit 时先 GET 详情,成功后详情盖行作初值;取数中只显示处理中,失败照实报错并给重试、不渲染表单(behavior.detail 编来)' },
|
|
538
|
+
envelope: { type: 'object', default: {}, desc: '本页有效的业务信封(编译期按页面 > 应用解析后传入;空对象 = 未声明)' },
|
|
555
539
|
result: { type: 'object', default: {}, desc: '请求结果常驻槽 { outcome, title? }(view.form.result 编来):outcome 是某 request 动作的 into;在字段与按钮之间常驻显示它的进行中 / 失败 / 成功结果,不被弹窗遮罩盖住' },
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
defaults: { type: 'object', default: {}, desc: '字段初值 { 字段: 字面量 | $filter.x | $row.x | $steps.s<i>.x }:只在新建时填「空且用户没改过」的字段,取不到值就不填' },
|
|
540
|
+
defaults: { type: 'object', default: {}, desc: '字段初值 { 字段: 字面量 }:只在新建时填「空且用户没改过」的字段' },
|
|
541
|
+
fieldState: { type: 'object', default: {}, desc: '展示对象给出的字段状态 { 字段: { hidden, disabled, required, options } }:options 是展示对象给出的候选项数组(替换该字段候选,不再取 options.from);hidden 不画但值保留并随草稿提交;disabled 置灰;required 标星并要求非空(隐藏 / 置灰的字段不判必填)' },
|
|
542
|
+
draftNotify: { type: 'boolean', default: false, desc: '页面把草稿变化接给了展示对象方法:草稿首次建好时补发一次 draft_change' },
|
|
560
543
|
hiddenFields: { type: 'array', default: [], desc: '隐藏草稿字段名:值随草稿提交但不画;字典 rules 照常校验(不过时在提示条写明),permission: create 的编辑态不提交;不是安全边界,服务端必须自行校验' },
|
|
561
544
|
},
|
|
562
545
|
emits: {
|
|
@@ -572,88 +555,148 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
572
555
|
},
|
|
573
556
|
reset: { payload: { values: { type: 'object' }, object: { type: 'string' }, scope: { type: 'string' } }, desc: '重置(filter 的 values 为空对象)' },
|
|
574
557
|
cancel: { payload: { object: { type: 'string' }, scope: { type: 'string' }, model: { type: 'object' } }, desc: '取消(载荷带当前草稿,未校验)' },
|
|
575
|
-
draft_change: { payload: { values: { type: 'object' }, dirty: { type: 'boolean' } }, desc: '
|
|
576
|
-
|
|
558
|
+
draft_change: { payload: { values: { type: 'object' }, dirty: { type: 'boolean' }, field: { type: 'string' }, source: { type: 'string' } }, desc: '草稿变化;field = 本次变动的字段(用户输入或展示对象经 handle.set 写入时给出),source = input(用户输入)/ api(展示对象写入)/ 缺省(草稿重建、重置、详情到达)' },
|
|
559
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.footer, { id: { type: 'string' }, object: { type: 'string' }, scope: { type: 'string' } }, '点了底栏动作(view.form.footerActions);序号 = 动作在 footerActions 数组里的位置,页面事件给每个动作各绑一条 request / download 管道'),
|
|
560
|
+
dirty_change: { payload: { dirty: { type: 'boolean' } }, desc: '草稿是否有未保存改动;仅在该布尔值变化时抛,另外每个实例挂载后首次同步抛一次当前值;弹窗协调组件据此做「未保存拦截」(draft_change 留给展示对象的 onDraft)' },
|
|
561
|
+
busy_change: { payload: { busy: { type: 'boolean' } }, desc: '提交处理中状态变化(写入 pending / 宿主 busy / 所接具名动作在跑);挂载后第一次同步必报一次当前值,之后只在值变化时发;弹窗协调组件据此在提交中不让用户关窗,实例被换掉时也靠首报复位' },
|
|
577
562
|
saved: { payload: { object: { type: 'string' }, scope: { type: 'string' }, result: { type: 'object' } }, desc: '写入成功(关闭由第 3 层监听)' },
|
|
578
563
|
reload: { payload: { object: { type: 'string' }, scope: { type: 'string' } }, desc: '冲突后请求刷新' },
|
|
579
|
-
field_change: { payload: { field: { type: 'string' }, value: {}, values: { type: 'object' }, kit_auto: { type: 'boolean' }, object: { type: 'string' }, scope: { type: 'string' } }, desc: '字段值变化(view.form.onChange 列出的字段,防抖后抛);页面事件按 field 分流到 request.read 的动作,$event.value 即新值' },
|
|
580
|
-
gate_run: { payload: { object: { type: 'string' }, scope: { type: 'string' }, action: { type: 'string' } }, desc: '点阶段闸门提示旁的「去验证」(gate.run 指向的 request 动作由步骤接线发出)' },
|
|
581
|
-
adopt_ask: { payload: { object: { type: 'string' }, scope: { type: 'string' }, action: { type: 'string' } }, desc: '点采纳条上的「获取建议」(adopt.ask 指向的 request 动作由页面接线发出)' },
|
|
582
564
|
},
|
|
583
565
|
},
|
|
584
566
|
services: ['data', 'http'],
|
|
585
567
|
templateHtml,
|
|
586
568
|
uiConfig,
|
|
587
569
|
eventConfig,
|
|
588
|
-
controllerFactory: (
|
|
570
|
+
controllerFactory: createKitController((api) => createController(api, registered, nameSet) as unknown as KitView),
|
|
589
571
|
};
|
|
590
572
|
}
|
|
591
573
|
|
|
592
574
|
// ── 控制器 ────────────────────────────────────────────────────────
|
|
593
575
|
|
|
576
|
+
/** 表单实例计数(无障碍节点 id 的实例前缀) */
|
|
577
|
+
let formInstanceCount = 0;
|
|
578
|
+
|
|
594
579
|
function createController(
|
|
595
|
-
|
|
580
|
+
api: KitApi,
|
|
596
581
|
registered: Readonly<Record<string, SomaComponentDefinition>>,
|
|
597
582
|
nameSet: ReadonlySet<string>,
|
|
598
583
|
): Record<string, unknown> {
|
|
599
|
-
const P = (): Rec =>
|
|
584
|
+
const P = (): Rec => api.props() as Rec;
|
|
585
|
+
/** 本表单的有效信封:prop(编译期按页面 > 应用解析后传入)非空优先,否则退回按宿主元素查找(远程选项、句柄 envelope() 共用这一处) */
|
|
586
|
+
const effectiveEnvelope = (): KitEnvelope | undefined => {
|
|
587
|
+
const given = P().envelope;
|
|
588
|
+
return isRec(given) && Object.keys(given).length > 0 ? (given as KitEnvelope) : getKitAppEnvelope(api.host);
|
|
589
|
+
};
|
|
590
|
+
/** 表单实例前缀:帮助 / 错误节点的 id 用它隔开同页的多个表单 */
|
|
591
|
+
const formUid = `kit-form-${++formInstanceCount}`;
|
|
600
592
|
const dataPort = (): SomaDataPort | undefined => {
|
|
601
|
-
const port = (
|
|
593
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
602
594
|
return port && typeof port === 'object' ? port : undefined;
|
|
603
595
|
};
|
|
604
596
|
|
|
605
597
|
let draft = createFormDraft({ initial: {} });
|
|
606
598
|
let signature = '';
|
|
607
599
|
let errors: Record<string, string> = {};
|
|
600
|
+
const touchedFields = new Set<string>();
|
|
601
|
+
const invalidFields = new Set<string>();
|
|
602
|
+
let lastSubmitVerdictRef: Record<string, string> | null = null;
|
|
608
603
|
let notice = '';
|
|
609
604
|
let conflict = false;
|
|
610
605
|
/** 写入结果回显的"处理中"(data.submit 的 pending);表单提交永不乐观——处理中只显示忙态,结果回来才改界面 */
|
|
611
606
|
let busy = false;
|
|
612
607
|
let unsubBusy: (() => void) | undefined;
|
|
608
|
+
/** 已对外报出的处理中状态(busy_change 只在变化时发);undefined = 尚未报过,实例挂载后的第一次同步必报一次当前值(协调组件据此自愈) */
|
|
609
|
+
let busyReported: boolean | undefined;
|
|
610
|
+
const syncBusyEmit = (): void => {
|
|
611
|
+
const now = isBusy();
|
|
612
|
+
if (now === busyReported) return;
|
|
613
|
+
busyReported = now;
|
|
614
|
+
api.emit('busy_change', { busy: now });
|
|
615
|
+
};
|
|
616
|
+
/** 已对外报出的草稿脏状态(dirty_change 只在变化时发);undefined = 尚未报过,实例挂载后的第一次同步必报一次当前值 */
|
|
617
|
+
let dirtyReported: boolean | undefined;
|
|
618
|
+
const syncDirtyEmit = (): void => {
|
|
619
|
+
if (!alive) return;
|
|
620
|
+
const now = draft.isDirty();
|
|
621
|
+
if (now === dirtyReported) return;
|
|
622
|
+
dirtyReported = now;
|
|
623
|
+
api.emit('dirty_change', { dirty: now });
|
|
624
|
+
};
|
|
613
625
|
/** 处理中 = 写入结果 pending,或宿主给 busy / 所接具名动作在跑(base/action-busy 口径) */
|
|
614
626
|
const isBusy = (): boolean => busy || kitBusyOf(P());
|
|
615
627
|
let settledSeq = 0;
|
|
616
628
|
let pendingSeq = 0;
|
|
617
629
|
let unsubOutcome: (() => void) | undefined;
|
|
618
630
|
let cleanupDom: (() => void) | undefined;
|
|
631
|
+
/** 页签条的共享页签接线句柄(role=tab / aria-selected / roving tabindex / 方向键 Home End) */
|
|
632
|
+
let tabsHandle: KitTablistHandle | undefined;
|
|
619
633
|
let alive = true;
|
|
620
634
|
/** 已折叠的分组 id(form.groups 平铺后的标题格带 group.head);字段结构变化时按 group.open 重置 */
|
|
621
635
|
let collapsed = new Set<string>();
|
|
622
636
|
/** M 波 G3:filter 折叠态、页签当前组、远程选项缓存、防抖与离开守卫的清理 */
|
|
623
637
|
let filterCollapsed = true;
|
|
624
638
|
let activeTab = '';
|
|
625
|
-
const remote = new Map<string, {
|
|
639
|
+
const remote = new Map<string, {
|
|
640
|
+
key?: string;
|
|
641
|
+
loadedKey: string;
|
|
642
|
+
inflightKey: string;
|
|
643
|
+
failedKey?: string;
|
|
644
|
+
rows: Rec[];
|
|
645
|
+
seq: number;
|
|
646
|
+
keyword?: string;
|
|
647
|
+
children?: Map<string, Rec[]>;
|
|
648
|
+
pending?: boolean;
|
|
649
|
+
failed?: boolean;
|
|
650
|
+
error?: string | boolean;
|
|
651
|
+
}>();
|
|
626
652
|
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
627
|
-
/** H1e:字段变化触发请求的防抖计时(每个字段一个,再变化即取消上一次待发的) */
|
|
628
|
-
const changeTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
629
653
|
/** H1b:订阅选项源失效总线(写成功后点名重取 options.from) */
|
|
630
|
-
let offOptionsBus: (() => void) | undefined;
|
|
631
654
|
let pendingScroll = false;
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
655
|
+
/** 进入处理中前持有焦点的字段控件 id;处理中结束且无别的定位接管时还焦点 */
|
|
656
|
+
let focusBeforeBusy = '';
|
|
657
|
+
let busySeen = false;
|
|
658
|
+
/** focusBeforeBusy 刚记下、还没经过一次重绘:该次重绘若没进入忙态就丢弃它(只对紧接着的一次忙态有效) */
|
|
659
|
+
let focusArmed = false;
|
|
660
|
+
/** 提交 / 重置钮持焦点时提交:处理中钮进入 loading / 禁用态焦点会丢,整表错误或网络失败后靠它把焦点还给钮 */
|
|
661
|
+
let focusBeforeBusyButton: '' | 'kit_submit' | 'kit_reset' = '';
|
|
662
|
+
const resetFocusRestore = (): void => { focusBeforeBusy = ''; focusBeforeBusyButton = ''; busySeen = false; focusArmed = false; };
|
|
663
|
+
/** 冲突后点「刷新」时焦点在刷新按钮上:提示条随冲突清除而隐藏,下一次(字段已画出的)重绘后把焦点放到首个可用字段控件;一次性 */
|
|
664
|
+
let pendingRefreshFocus = false;
|
|
665
|
+
/** 摘掉「用户一有操作就作废标记」的一次性监听;未挂监听时为 undefined */
|
|
666
|
+
let offRefreshFocusGuard: (() => void) | undefined;
|
|
667
|
+
/** 清除刷新焦点标记并摘监听:所有清除路径(拿到焦点 / 用户操作 / 焦点已在别处 / 卸载 / 草稿重建)都经它 */
|
|
668
|
+
const disarmRefreshFocus = (): void => {
|
|
669
|
+
pendingRefreshFocus = false;
|
|
670
|
+
offRefreshFocusGuard?.();
|
|
671
|
+
offRefreshFocusGuard = undefined;
|
|
638
672
|
};
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
673
|
+
/** 置刷新焦点标记,同时在宿主文档挂捕获阶段 pointerdown / keydown 一次性监听:用户一有操作就作废,避免过时标记日后抢焦点 */
|
|
674
|
+
/** 置标记时的表单语境(模式 / 对象 / 作用域):草稿重建只在语境变了时作废标记——初值变化正是「刷新」本身带来的(宿主重取后下传新 initial),要保留 */
|
|
675
|
+
let refreshFocusContext = '';
|
|
676
|
+
const armRefreshFocus = (doc: Document): void => {
|
|
677
|
+
disarmRefreshFocus();
|
|
678
|
+
pendingRefreshFocus = true;
|
|
679
|
+
refreshFocusContext = formContextKey();
|
|
680
|
+
const onUserAction = (): void => disarmRefreshFocus();
|
|
681
|
+
doc.addEventListener('pointerdown', onUserAction, true);
|
|
682
|
+
doc.addEventListener('keydown', onUserAction, true);
|
|
683
|
+
offRefreshFocusGuard = () => {
|
|
684
|
+
doc.removeEventListener('pointerdown', onUserAction, true);
|
|
685
|
+
doc.removeEventListener('keydown', onUserAction, true);
|
|
686
|
+
};
|
|
642
687
|
};
|
|
688
|
+
let offGuard: (() => void) | undefined;
|
|
689
|
+
|
|
690
|
+
// ── 订阅 request 动作的结果(into),按需读,不另存业务数据 ──
|
|
643
691
|
const outcomes = new Map<string, KitOutcome>();
|
|
644
692
|
let outcomeSig = '';
|
|
645
693
|
let offOutcomes: Array<() => void> = [];
|
|
646
|
-
/** 已处理(采纳或忽略)到第几次写入;seq 更大的新结果才再出现采纳条 */
|
|
647
|
-
let adoptConsumedSeq = 0;
|
|
648
694
|
/** 结果槽(view.form.result)只显示 seq 大于它的结果 */
|
|
649
695
|
let resultBaseSeq = 0;
|
|
650
696
|
const resultOutcomeName = (): string => (isRec(P().result) && typeof (P().result as Rec).outcome === 'string' ? ((P().result as Rec).outcome as string) : '');
|
|
651
|
-
/** 已采纳的 { 字段: 建议值 }:当前值仍等于它才显示「已采纳」;用户再改、重置、保存成功后清掉 */
|
|
652
|
-
let adopted: Record<string, unknown> = {};
|
|
653
697
|
const syncOutcomes = (): void => {
|
|
654
|
-
const footerGateNames = Array.isArray(P().footerActions) ? (P().footerActions as unknown[]).filter(isRec).flatMap((a) => gateOutcomeNamesOf(gateFrom(a))) : [];
|
|
655
698
|
const resultName = isRec(P().result) && typeof (P().result as Rec).outcome === 'string' ? [(P().result as Rec).outcome as string] : [];
|
|
656
|
-
const names = [...new Set([...
|
|
699
|
+
const names = [...new Set([...resultName])];
|
|
657
700
|
const sig = names.join('|');
|
|
658
701
|
if (sig === outcomeSig) return;
|
|
659
702
|
outcomeSig = sig;
|
|
@@ -668,83 +711,8 @@ function createController(
|
|
|
668
711
|
}));
|
|
669
712
|
initial = false;
|
|
670
713
|
}
|
|
671
|
-
// 订阅之前就存在的结果不再当作新建议提供(可能属于别的行 / 上一次会话)
|
|
672
|
-
const from = adoptDecl()?.from;
|
|
673
|
-
if (from !== undefined) adoptConsumedSeq = Math.max(adoptConsumedSeq, outcomes.get(from)?.seq ?? 0);
|
|
674
714
|
resultBaseSeq = Math.max(resultBaseSeq, outcomes.get(resultOutcomeName())?.seq ?? 0);
|
|
675
715
|
};
|
|
676
|
-
/** 此刻允许被建议值回填的字段:本次会提交的、没被只读 / 禁用 / 条件禁用的 */
|
|
677
|
-
const adoptWritable = (withHidden = false): Set<string> => {
|
|
678
|
-
const vals = draft.values();
|
|
679
|
-
const byName = new Map(cells().map((c) => [c.field, c] as const));
|
|
680
|
-
return new Set(submitNames().filter((name) => {
|
|
681
|
-
const c = byName.get(name);
|
|
682
|
-
// H2c:隐藏草稿字段(本来就随草稿提交、编译期保证非只读)只在采纳条自己的方案里放开;别的组件回填的 patch 口不放开
|
|
683
|
-
if (c === undefined) return withHidden && hiddenNames().includes(name);
|
|
684
|
-
const props = isRec(c.props) ? c.props : {};
|
|
685
|
-
return props.readonly !== true && props.disabled !== true && !(c.disabledWhen !== undefined && holds(c.disabledWhen, vals));
|
|
686
|
-
}));
|
|
687
|
-
};
|
|
688
|
-
/** 采纳条上「获取建议」钮指向的 request 动作 id;没写 = '' */
|
|
689
|
-
const askAction = (): string => (typeof adoptDecl()?.ask === 'string' ? adoptDecl()!.ask! : '');
|
|
690
|
-
const askOutcome = (): KitOutcome | undefined => {
|
|
691
|
-
const from = adoptDecl()?.from;
|
|
692
|
-
return from === undefined ? undefined : outcomes.get(from);
|
|
693
|
-
};
|
|
694
|
-
/** 当前可提供的采纳方案;没有新的成功结果 = null */
|
|
695
|
-
const currentAdopt = (): { plan: KitAdoptPlan; seq: number } | null => {
|
|
696
|
-
const decl = adoptDecl();
|
|
697
|
-
if (decl === undefined || mode() === 'filter') return null;
|
|
698
|
-
const o = outcomes.get(decl.from);
|
|
699
|
-
if (o === undefined || o.status !== 'saved' || o.seq <= adoptConsumedSeq) return null;
|
|
700
|
-
const known = cells().filter((c) => c.placeholder !== true && c.component !== '').map((c) => c.field);
|
|
701
|
-
return { plan: adoptPlan(o.data, decl, adoptWritable(true), known, draft.values(), new Set(hiddenNames())), seq: o.seq };
|
|
702
|
-
};
|
|
703
|
-
/**
|
|
704
|
-
* 把建议值写进草稿(只改草稿,不提交)并标「已采纳」:依赖被改字段的远程选项字段值作废(除非它自己也被采纳)并重取候选,
|
|
705
|
-
* 被改字段的旧校验错误清掉。采纳条的「采纳」与登记的 patch 口共用这一处。返回实际写入的字段名
|
|
706
|
-
*/
|
|
707
|
-
const applyAdopted = (changes: Rec): string[] => {
|
|
708
|
-
const names = Object.keys(changes);
|
|
709
|
-
for (const name of names) {
|
|
710
|
-
draft.set(name, changes[name]);
|
|
711
|
-
adopted[name] = changes[name];
|
|
712
|
-
}
|
|
713
|
-
const queue = [...names];
|
|
714
|
-
while (queue.length > 0) {
|
|
715
|
-
const n = queue.shift()!;
|
|
716
|
-
for (const c of cells()) {
|
|
717
|
-
if (c.optionsFrom !== undefined && !names.includes(c.field) && optionSourceReloadOn({ reload: c.optionsFrom.deps }, [n]) && !isBlank(draft.get(c.field))) {
|
|
718
|
-
draft.set(c.field, '');
|
|
719
|
-
queue.push(c.field);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
if (names.some((n) => n in errors)) {
|
|
724
|
-
const next = { ...errors };
|
|
725
|
-
for (const n of names) delete next[n];
|
|
726
|
-
errors = next;
|
|
727
|
-
}
|
|
728
|
-
ensureOptions();
|
|
729
|
-
ctx.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
730
|
-
repaint();
|
|
731
|
-
return names;
|
|
732
|
-
};
|
|
733
|
-
/** 阶段闸门原因:满足 = '';不满足 = 必填的 message(提交按钮据此禁用并显示它) */
|
|
734
|
-
const blockedBy = (): string => {
|
|
735
|
-
if (mode() === 'filter') return '';
|
|
736
|
-
const vals = draft.values();
|
|
737
|
-
// 结果来自读了 $draft 的请求、而被读的字段之后改了:该结果过期,闸门重新拦住并提示重新验证
|
|
738
|
-
const view = new Map<string, KitOutcome & { stale: boolean }>();
|
|
739
|
-
for (const [name, o] of outcomes) view.set(name, { ...o, stale: isKitOutcomeStale(name, vals) });
|
|
740
|
-
return gateReason(gateDecl(), {
|
|
741
|
-
draft: vals,
|
|
742
|
-
outcomes: view,
|
|
743
|
-
steps: isRec(P().gateSteps) ? (P().gateSteps as Rec) : {},
|
|
744
|
-
staleMessage: kitText('soma.kit.gate_stale', undefined, ctx.host),
|
|
745
|
-
});
|
|
746
|
-
};
|
|
747
|
-
|
|
748
716
|
const initGroups = (): void => {
|
|
749
717
|
activeTab = cells().find((c) => c.group?.head === true)?.group?.id ?? '';
|
|
750
718
|
filterCollapsed = true;
|
|
@@ -789,42 +757,44 @@ function createController(
|
|
|
789
757
|
const effectiveInitial = (): Rec => (detailRecord !== null ? { ...initialOf(), ...detailRecord } : initialOf());
|
|
790
758
|
let draftHandle: KitFormDraftHandle | undefined;
|
|
791
759
|
|
|
792
|
-
// ──
|
|
793
|
-
/** 各步已确认的 model { s<i>: {字段: 值} }(StepForm 以外为空) */
|
|
794
|
-
const stepsOf = (): Rec => (isRec(P().gateSteps) ? (P().gateSteps as Rec) : {});
|
|
760
|
+
// ── GB2 / GB3:字段初值、隐藏草稿字段 ──
|
|
795
761
|
/** 隐藏草稿字段名(筛选表单不带) */
|
|
796
762
|
const hiddenNames = (): string[] => (mode() === 'filter' ? [] : stringList(P().hiddenFields));
|
|
797
|
-
/**
|
|
763
|
+
/** 展示对象给出的某字段状态(路径已由 core 求成布尔;筛选表单不吃) */
|
|
764
|
+
const stateOf = (name: string): { hidden: boolean; disabled: boolean; required: boolean } => {
|
|
765
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
766
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : {};
|
|
767
|
+
return { hidden: e.hidden === true, disabled: e.disabled === true, required: e.required === true };
|
|
768
|
+
};
|
|
769
|
+
/** 展示对象给出的某字段候选项(fieldState.<字段>.options,core 已求成数组);没绑定 / 未到数组返回 undefined(筛选表单不吃) */
|
|
770
|
+
const viewOptionsOf = (name: string): Rec[] | undefined => {
|
|
771
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
772
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
773
|
+
return e !== undefined && Array.isArray(e.options) ? (e.options as unknown[]).filter(isRec) : undefined;
|
|
774
|
+
};
|
|
775
|
+
/** 展示对象给出的画布节点候选项(fieldState.<字段>.nodeOptions,core 已求成对象 { "<类型>.<字段键>": [...] });没绑定返回 undefined */
|
|
776
|
+
const viewNodeOptionsOf = (name: string): Rec | undefined => {
|
|
777
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
778
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
779
|
+
return e !== undefined && isRec(e.nodeOptions) ? e.nodeOptions : undefined;
|
|
780
|
+
};
|
|
781
|
+
/** 解析 defaults 表(字面量初值);取不到值的字段不在结果里 */
|
|
798
782
|
const resolveDefaults = (): Rec => {
|
|
799
783
|
const decl = isRec(P().defaults) ? (P().defaults as Rec) : {};
|
|
800
784
|
if (Object.keys(decl).length === 0) return {};
|
|
801
|
-
|
|
802
|
-
return resolveFieldDefaults(decl, { filter: extras.filter(), row: extras.focusRow(), steps: stepsOf() });
|
|
803
|
-
};
|
|
804
|
-
/** 上一次解析出的 $ 取值路径初值签名:变了才对草稿补填(只补「空且没改过」的字段) */
|
|
805
|
-
let refDefaultsSig = '';
|
|
806
|
-
let lastStepsSig = '';
|
|
807
|
-
const applyRefDefaults = (): void => {
|
|
808
|
-
if (mode() !== 'create' || detailBlocked()) return;
|
|
809
|
-
const resolved = resolveDefaults();
|
|
810
|
-
const sig = JSON.stringify(resolved);
|
|
811
|
-
if (sig === refDefaultsSig) return;
|
|
812
|
-
refDefaultsSig = sig;
|
|
813
|
-
draft.applyDefaults(resolved);
|
|
785
|
+
return resolveFieldDefaults(decl);
|
|
814
786
|
};
|
|
815
787
|
|
|
816
788
|
const rebuildDraft = (): void => {
|
|
817
789
|
const defaults = mode() === 'create' ? resolveDefaults() : {};
|
|
818
|
-
refDefaultsSig = JSON.stringify(defaults);
|
|
819
790
|
draft = createFormDraft({ initial: { ...effectiveInitial() }, ...(Object.keys(defaults).length > 0 ? { defaults } : {}) });
|
|
820
791
|
errors = {};
|
|
792
|
+
touchedFields.clear();
|
|
793
|
+
invalidFields.clear();
|
|
794
|
+
lastSubmitVerdictRef = null;
|
|
821
795
|
notice = '';
|
|
822
796
|
conflict = false;
|
|
823
797
|
busy = false;
|
|
824
|
-
// 换了一行 / 重建草稿:上一份建议属于旧草稿,视为过期,已采纳标记也清掉
|
|
825
|
-
adopted = {};
|
|
826
|
-
const staleFrom = adoptDecl()?.from;
|
|
827
|
-
if (staleFrom !== undefined) adoptConsumedSeq = Math.max(adoptConsumedSeq, outcomes.get(staleFrom)?.seq ?? 0);
|
|
828
798
|
// 结果槽只显示草稿(行 / 模式)重建之后发生的请求结果;之前的属于上一行 / 上一次会话
|
|
829
799
|
resultBaseSeq = Math.max(resultBaseSeq, outcomes.get(resultOutcomeName())?.seq ?? 0);
|
|
830
800
|
const view = dataPort()?.writeOutcome?.(scopeKey());
|
|
@@ -832,26 +802,53 @@ function createController(
|
|
|
832
802
|
settledSeq = view?.status === 'pending' ? Math.max(0, pendingSeq - 1) : pendingSeq;
|
|
833
803
|
};
|
|
834
804
|
|
|
805
|
+
/** 表单语境键(模式 / 对象 / 作用域):刷新焦点标记据此判断草稿重建是不是换了一张表单 */
|
|
806
|
+
const formContextKey = (): string => JSON.stringify([mode(), objectName(), scopeKey()]);
|
|
835
807
|
const syncDraft = (): void => {
|
|
836
808
|
const sig = JSON.stringify([mode(), objectName(), scopeKey(), initialOf(), cells().map((c) => c.field)]);
|
|
837
|
-
if (sig === signature)
|
|
838
|
-
// 草稿没重建,但 $steps / $filter 取值路径的初值可能变了(前面的步骤刚确认):只补「空且没改过」的字段;依赖 $steps 的远程选项随之重取
|
|
839
|
-
applyRefDefaults();
|
|
840
|
-
const stepsSig = JSON.stringify(stepsOf());
|
|
841
|
-
if (stepsSig !== lastStepsSig) {
|
|
842
|
-
lastStepsSig = stepsSig;
|
|
843
|
-
if (cells().some((c) => hasStepParams(c.optionsFrom?.params)) && !detailBlocked()) ensureOptions();
|
|
844
|
-
}
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
809
|
+
if (sig === signature) return;
|
|
847
810
|
signature = sig;
|
|
848
|
-
|
|
811
|
+
// 草稿签名变化导致重建:换了模式 / 对象 / 作用域(另一张表单)时刷新焦点标记作废;只是初值变了(刷新后宿主下传新值)则保留,字段画出后照常归还焦点
|
|
812
|
+
if (pendingRefreshFocus && formContextKey() !== refreshFocusContext) disarmRefreshFocus();
|
|
849
813
|
detailRecord = null;
|
|
850
814
|
rebuildDraft();
|
|
851
815
|
initGroups();
|
|
852
816
|
remote.clear();
|
|
853
817
|
startDetail();
|
|
854
818
|
if (!detailBlocked()) ensureOptions();
|
|
819
|
+
// 草稿重建会把 busy 清零:异步补报(不在渲染读口里重入)
|
|
820
|
+
queueMicrotask(() => { if (alive) { syncBusyEmit(); syncDirtyEmit(); } });
|
|
821
|
+
// 展示对象对齐:草稿首次建好补发一次 draft_change(异步发,不在渲染读口里重入)
|
|
822
|
+
if (P().draftNotify === true && mode() !== 'filter' && !detailBlocked()) {
|
|
823
|
+
queueMicrotask(() => { if (alive) api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() }); });
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* 草稿读口登记(具名动作的 draft 读口与 $draft 取值):
|
|
829
|
+
* 筛选表单(mode: filter)不登记;动态切换到 filter 模式时注销,切换到 create/edit 模式时重新登记。
|
|
830
|
+
*/
|
|
831
|
+
const syncDraftRegistration = (): void => {
|
|
832
|
+
if (!alive) return;
|
|
833
|
+
const curMode = mode();
|
|
834
|
+
if (curMode === 'filter') {
|
|
835
|
+
if (draftHandle) {
|
|
836
|
+
draftHandle.dispose();
|
|
837
|
+
draftHandle = undefined;
|
|
838
|
+
}
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (!draftHandle) {
|
|
842
|
+
draftHandle = registerKitFormDraft({
|
|
843
|
+
get scope(): string { return scopeKey(); },
|
|
844
|
+
get object(): string { return objectName(); },
|
|
845
|
+
get mode(): 'create' | 'edit' { return mode() === 'edit' ? 'edit' : 'create'; },
|
|
846
|
+
host: api.host ?? null,
|
|
847
|
+
values: () => ({ ...draft.values() }),
|
|
848
|
+
dirty: () => draft.isDirty(),
|
|
849
|
+
ready: () => !detailBlocked(),
|
|
850
|
+
});
|
|
851
|
+
}
|
|
855
852
|
};
|
|
856
853
|
|
|
857
854
|
/** 取详情:成功 -> 详情盖行重建草稿;失败 / 缺参 -> 照实报错(notice)并给重试,不渲染表单 */
|
|
@@ -862,17 +859,17 @@ function createController(
|
|
|
862
859
|
if (d === null || mode() !== 'edit') { detailState = 'none'; return; }
|
|
863
860
|
const fail = (message: string): void => {
|
|
864
861
|
detailState = 'failed';
|
|
865
|
-
notice = message !== '' ? message : kitText('soma.kit.load_failed', undefined,
|
|
862
|
+
notice = message !== '' ? message : kitText('soma.kit.load_failed', undefined, api.host);
|
|
866
863
|
};
|
|
867
864
|
const { params, missing } = resolveDetailParams(d.params ?? {}, initialOf());
|
|
868
|
-
const http = (
|
|
865
|
+
const http = (api.services as { http?: { get<T>(url: string, config?: { params?: Record<string, string> }): Promise<T>; baseURL?: unknown } } | undefined)?.http;
|
|
869
866
|
if (missing.length > 0 || !http) { fail(''); return; }
|
|
870
867
|
const rawBase = http.baseURL;
|
|
871
868
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
872
|
-
const
|
|
869
|
+
const apiRoute = baseURL !== '' && baseURL !== '/' && d.api.startsWith(`${baseURL}/`) ? d.api.slice(baseURL.length) : d.api;
|
|
873
870
|
detailState = 'loading';
|
|
874
871
|
notice = '';
|
|
875
|
-
void http.get<unknown>(
|
|
872
|
+
void http.get<unknown>(apiRoute, { params }).then((res) => {
|
|
876
873
|
if (!alive || mine !== detailSeq) return;
|
|
877
874
|
const read = readDetailResponse(res, d.unwrap, d.envelope);
|
|
878
875
|
if (!read.ok) { fail(read.message); repaint(); return; }
|
|
@@ -882,7 +879,8 @@ function createController(
|
|
|
882
879
|
initGroups();
|
|
883
880
|
remote.clear();
|
|
884
881
|
ensureOptions();
|
|
885
|
-
|
|
882
|
+
syncDirtyEmit();
|
|
883
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
886
884
|
repaint();
|
|
887
885
|
}).catch((error: unknown) => {
|
|
888
886
|
if (!alive || mine !== detailSeq) return;
|
|
@@ -895,9 +893,8 @@ function createController(
|
|
|
895
893
|
const submitNames = (): string[] => {
|
|
896
894
|
const m = mode();
|
|
897
895
|
const skip = m === 'edit' ? createOnly() : new Set<string>();
|
|
898
|
-
const vals = draft.values();
|
|
899
896
|
const shown = cells()
|
|
900
|
-
.filter((c) => c.placeholder !== true && c.component !== '' && c.mode === 'edit' && !skip.has(c.field)
|
|
897
|
+
.filter((c) => c.placeholder !== true && c.component !== '' && c.mode === 'edit' && !skip.has(c.field))
|
|
901
898
|
.map((c) => c.field);
|
|
902
899
|
// GB3:隐藏草稿字段一并提交(permission: create 的编辑态照样不提交——hidden 不改变权限语义)
|
|
903
900
|
return [...shown, ...hiddenNames().filter((n) => !skip.has(n) && !shown.includes(n))];
|
|
@@ -930,8 +927,7 @@ function createController(
|
|
|
930
927
|
|
|
931
928
|
/** 校验用的整份值:含 edit 下 create-only 字段(它们不进 model,但字典里可能是必填) */
|
|
932
929
|
const validationValues = (): Rec => {
|
|
933
|
-
const
|
|
934
|
-
const names = [...cells().filter((c) => c.placeholder !== true && c.component !== '' && shownByCond(c, vals)).map((c) => c.field), ...hiddenNames()];
|
|
930
|
+
const names = [...cells().filter((c) => c.placeholder !== true && c.component !== '').map((c) => c.field), ...hiddenNames()];
|
|
935
931
|
const out = collect(names);
|
|
936
932
|
for (const key of stringList(P().keys)) {
|
|
937
933
|
const v = draft.get(key);
|
|
@@ -942,90 +938,299 @@ function createController(
|
|
|
942
938
|
|
|
943
939
|
const editableSet = (): Set<string> => new Set(submitNames());
|
|
944
940
|
|
|
941
|
+
/** 子表字段(控件为 RowEditor)是否参与校验:会提交的、显示着的、没被禁用 / 只读的(整表错误与单元格错误共用这一段前置判断) */
|
|
942
|
+
const rowsFieldActive = (c: KitCell, editable: ReadonlySet<string>): boolean => {
|
|
943
|
+
if (c.component !== 'RowEditor' || c.placeholder === true || !editable.has(c.field)) return false;
|
|
944
|
+
const props = isRec(c.props) ? c.props : {};
|
|
945
|
+
const st = stateOf(c.field);
|
|
946
|
+
return !(props.readonly === true || props.disabled === true || st.hidden || st.disabled);
|
|
947
|
+
};
|
|
948
|
+
|
|
945
949
|
/** 子表字段(控件为 RowEditor)的提交前校验:只看本次会提交的、显示着的、没被禁用 / 只读的字段 */
|
|
946
950
|
const rowsFieldErrors = (): Record<string, string> => {
|
|
947
951
|
const out: Record<string, string> = {};
|
|
948
952
|
const vals = draft.values();
|
|
949
953
|
const editable = editableSet();
|
|
950
954
|
for (const c of cells()) {
|
|
951
|
-
if (
|
|
955
|
+
if (!rowsFieldActive(c, editable)) continue;
|
|
952
956
|
const props = isRec(c.props) ? c.props : {};
|
|
953
|
-
if (props.readonly === true || props.disabled === true || (c.disabledWhen !== undefined && holds(c.disabledWhen, vals))) continue;
|
|
954
957
|
const rows = Array.isArray(vals[c.field]) ? (vals[c.field] as unknown[]).filter(isRec) : [];
|
|
955
|
-
const message = validateInlineRows(rowColumnsOf(props.columns,
|
|
958
|
+
const message = validateInlineRows(rowColumnsOf(props.columns, api.host), rows, {
|
|
956
959
|
minRows: Number(props.min_rows) || 0,
|
|
957
960
|
maxRows: Number(props.max_rows) || 0,
|
|
958
961
|
lockedKey: typeof props.locked_key === 'string' ? props.locked_key : '',
|
|
959
|
-
},
|
|
962
|
+
}, api.host);
|
|
960
963
|
if (message !== null) out[c.field] = message;
|
|
961
964
|
}
|
|
962
965
|
return out;
|
|
963
966
|
};
|
|
964
967
|
|
|
968
|
+
/**
|
|
969
|
+
* 子表字段的单元格级错误(全部,行下标 + 列 key):传给 RowEditor 的 cell_errors,让出错单元格标红、可聚焦。
|
|
970
|
+
* 字段处于出错期间每次构建行都按当前草稿重算(改好一格后只剩其余格),RowEditor 以入参为准;只读 / 禁用 / 隐藏的字段不产生单元格错误
|
|
971
|
+
*/
|
|
972
|
+
const rowsCellErrorsOf = (c: KitCell): KitRowCellError[] => {
|
|
973
|
+
if (!rowsFieldActive(c, editableSet())) return [];
|
|
974
|
+
const props = isRec(c.props) ? c.props : {};
|
|
975
|
+
const v = draft.values()[c.field];
|
|
976
|
+
const rows = Array.isArray(v) ? (v as unknown[]).filter(isRec) : [];
|
|
977
|
+
return validateInlineRowCells(rowColumnsOf(props.columns, api.host), rows, {
|
|
978
|
+
lockedKey: typeof props.locked_key === 'string' ? props.locked_key : '',
|
|
979
|
+
}, api.host);
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
/** 展示对象绑定为必填的字段:可编辑、没隐藏、没置灰、值为空 -> 必填提示(隐藏 / 置灰的字段用户填不了,不判) */
|
|
983
|
+
const boundRequiredErrors = (): Record<string, string> => {
|
|
984
|
+
const out: Record<string, string> = {};
|
|
985
|
+
const vals = draft.values();
|
|
986
|
+
const editable = editableSet();
|
|
987
|
+
for (const c of cells()) {
|
|
988
|
+
if (c.placeholder === true || !editable.has(c.field)) continue;
|
|
989
|
+
const st = stateOf(c.field);
|
|
990
|
+
if (!st.required || st.hidden || st.disabled) continue;
|
|
991
|
+
if (isBlank(vals[c.field])) out[c.field] = kitText('soma.kit.field_required', undefined, api.host);
|
|
992
|
+
}
|
|
993
|
+
return out;
|
|
994
|
+
};
|
|
995
|
+
|
|
965
996
|
/** 流程画布字段(控件为 FlowEditor)的提交前校验:必填(星号)时至少一个节点;只读 / 禁用的不查 */
|
|
966
997
|
const flowFieldErrors = (): Record<string, string> => {
|
|
967
998
|
const out: Record<string, string> = {};
|
|
968
999
|
const vals = draft.values();
|
|
969
1000
|
const editable = editableSet();
|
|
970
1001
|
for (const c of cells()) {
|
|
971
|
-
if (c.component !== 'FlowEditor' || c.placeholder === true || !editable.has(c.field)
|
|
1002
|
+
if (c.component !== 'FlowEditor' || c.placeholder === true || !editable.has(c.field)) continue;
|
|
972
1003
|
const props = isRec(c.props) ? c.props : {};
|
|
973
|
-
|
|
974
|
-
if (
|
|
1004
|
+
const st = stateOf(c.field);
|
|
1005
|
+
if (props.readonly === true || props.disabled === true || st.hidden || st.disabled) continue;
|
|
1006
|
+
if (starOf(c) === '') continue;
|
|
975
1007
|
const v = vals[c.field];
|
|
976
1008
|
const nodes = isRec(v) && Array.isArray(v.nodes) ? v.nodes : [];
|
|
977
|
-
if (nodes.length === 0) out[c.field] = kitText('soma.kit.flow_required', undefined,
|
|
1009
|
+
if (nodes.length === 0) out[c.field] = kitText('soma.kit.flow_required', undefined, api.host);
|
|
978
1010
|
}
|
|
979
1011
|
return out;
|
|
980
1012
|
};
|
|
981
1013
|
|
|
982
|
-
|
|
1014
|
+
const SUBMIT_UNREADY_TITLE = '请先完善必填项或修正校验错误';
|
|
1015
|
+
const computeSubmitTitle = (): string => {
|
|
1016
|
+
if (mode() === 'filter') return '';
|
|
1017
|
+
if (invalidFields.size > 0 || Object.values(errors).some((msg) => msg !== '')) {
|
|
1018
|
+
return SUBMIT_UNREADY_TITLE;
|
|
1019
|
+
}
|
|
1020
|
+
const vals = draft.values();
|
|
1021
|
+
const editable = editableSet();
|
|
1022
|
+
for (const c of cells()) {
|
|
1023
|
+
if (c.placeholder === true || !editable.has(c.field)) continue;
|
|
1024
|
+
const st = stateOf(c.field);
|
|
1025
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1026
|
+
if (st.hidden || st.disabled || props.disabled === true || props.readonly === true) continue;
|
|
1027
|
+
const rawRules = Array.isArray((c as unknown as Rec).rules)
|
|
1028
|
+
? ((c as unknown as Rec).rules as unknown[])
|
|
1029
|
+
: Array.isArray(props.rules)
|
|
1030
|
+
? (props.rules as unknown[])
|
|
1031
|
+
: [];
|
|
1032
|
+
const hasRuleRequired = rawRules.some((r) => isRec(r) && r.required === true);
|
|
1033
|
+
const isReq = c.required !== undefined || props.required === true || st.required || hasRuleRequired;
|
|
1034
|
+
if (isReq && isBlank(vals[c.field])) {
|
|
1035
|
+
return SUBMIT_UNREADY_TITLE;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
return '';
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
// ── aria-invalid(嵌套组件根在 render 之后才存在,同步 + 微任务双拍同步)──
|
|
983
1042
|
const syncInvalid = (): void => {
|
|
984
|
-
const host =
|
|
1043
|
+
const host = api.host;
|
|
985
1044
|
if (!host || typeof host.querySelectorAll !== 'function') return;
|
|
986
1045
|
for (const row of buildRows()) {
|
|
987
1046
|
// 字段名可含引号 / 反斜杠:转义后再进属性选择器,避免 querySelector 抛错
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1047
|
+
const escId = row.id.replace(/["\\]/g, '\\$&');
|
|
1048
|
+
const escName = row.name.replace(/["\\]/g, '\\$&');
|
|
1049
|
+
const el =
|
|
1050
|
+
host.querySelector<HTMLElement>(`[id="${escId}"]`) ??
|
|
1051
|
+
(escName !== '' ? host.querySelector<HTMLElement>(`[name="${escName}"], [data-field="${escName}"], [data-kit-field="${escName}"]`) : null);
|
|
1052
|
+
if (el) {
|
|
1053
|
+
if (row.error !== '') el.setAttribute('aria-invalid', 'true');
|
|
1054
|
+
else el.removeAttribute('aria-invalid');
|
|
1055
|
+
}
|
|
1056
|
+
const errEl = escName !== '' ? host.querySelector<HTMLElement>(`[data-field-error="${escName}"]`) : null;
|
|
1057
|
+
// 错误 / 帮助文字与控件关联:节点按行模板的确切 data-soma-id(help_/err_ + 组件名)取,且只在该单元格的直接结构里找,不进入嵌套组件;
|
|
1058
|
+
// 节点 id = 表单实例前缀 + 字段名 + 后缀(同页两个同对象表单也不重复),控件 id 不动
|
|
1059
|
+
const tpl = row.component.replace(/["\\]/g, '\\$&');
|
|
1060
|
+
const cellEl = el?.closest<HTMLElement>(`[data-soma-id="cell_${tpl}"]`) ?? null;
|
|
1061
|
+
const bodyOf = (kind: 'help' | 'err'): HTMLElement | null =>
|
|
1062
|
+
cellEl?.querySelector<HTMLElement>(`:scope > [data-soma-id="body_${tpl}"] > [data-soma-id="${kind}_${tpl}"]`) ?? null;
|
|
1063
|
+
const errNode = errEl ?? bodyOf('err');
|
|
1064
|
+
const helpNode = bodyOf('help');
|
|
1065
|
+
const nodeId = (suffix: 'help' | 'err'): string => `${formUid}-${encodeURIComponent(row.name).replace(/%/g, '_')}-${suffix}`;
|
|
1066
|
+
const described: string[] = [];
|
|
1067
|
+
if (helpNode) { helpNode.id = nodeId('help'); if (row.help !== '') described.push(helpNode.id); }
|
|
1068
|
+
if (errNode) { errNode.id = nodeId('err'); if (row.error !== '') described.push(errNode.id); }
|
|
1069
|
+
if (el) {
|
|
1070
|
+
if (described.length > 0) el.setAttribute('aria-describedby', described.join(' '));
|
|
1071
|
+
else el.removeAttribute('aria-describedby');
|
|
1072
|
+
}
|
|
1073
|
+
if (errEl) {
|
|
1074
|
+
errEl.textContent = row.error;
|
|
1075
|
+
errEl.className = row.error === '' ? KIT_FORM_CLASS.errorHidden : row.errorClass;
|
|
1076
|
+
} else if (el && row.error !== '' && errNode === null) {
|
|
1077
|
+
const p = host.ownerDocument.createElement('p');
|
|
1078
|
+
p.setAttribute('data-field-error', row.name);
|
|
1079
|
+
p.setAttribute('role', 'alert');
|
|
1080
|
+
p.className = row.errorClass;
|
|
1081
|
+
p.textContent = row.error;
|
|
1082
|
+
el.insertAdjacentElement('afterend', p);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
const submitTitle = computeSubmitTitle();
|
|
1086
|
+
const submitTargets = host.querySelectorAll<HTMLElement>('[data-soma-id="kit_submit"], [data-soma-id="kit_submit"] button, button[type="submit"]');
|
|
1087
|
+
for (const btn of Array.from(submitTargets)) {
|
|
1088
|
+
if (submitTitle !== '') btn.setAttribute('title', submitTitle);
|
|
1089
|
+
else btn.removeAttribute('title');
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
/** 记下当前持有焦点的字段控件 id(只认本表单字段) */
|
|
1093
|
+
const rememberFocus = (): void => {
|
|
1094
|
+
const host = api.host;
|
|
1095
|
+
const active = host?.ownerDocument?.activeElement;
|
|
1096
|
+
if (!host || !active || !host.contains(active)) return;
|
|
1097
|
+
for (const row of buildRows()) {
|
|
1098
|
+
if (row.id === '') continue;
|
|
1099
|
+
const ctl = host.querySelector<HTMLElement>(`[id="${row.id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1100
|
+
if (ctl && (ctl === active || ctl.contains(active))) { focusBeforeBusy = row.id; focusArmed = true; return; }
|
|
1101
|
+
}
|
|
1102
|
+
// 字段没命中:焦点在提交 / 重置钮内(键盘 Enter / 空格触发),记下钮 id 供处理结束后归还
|
|
1103
|
+
for (const id of ['kit_submit', 'kit_reset'] as const) {
|
|
1104
|
+
if (active.closest?.(`[data-soma-id="${id}"]`) && host.contains(active.closest(`[data-soma-id="${id}"]`))) {
|
|
1105
|
+
focusBeforeBusyButton = id; focusArmed = true; return;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
/** 首个出错字段所在分组被隐藏(页签未激活 / 分组折叠)时,先切到 / 展开该分组 */
|
|
1110
|
+
const revealFirstErrorGroup = (): void => {
|
|
1111
|
+
const first = cells().find((c) => c.placeholder !== true && (errors[c.field] ?? '') !== '');
|
|
1112
|
+
if (first?.group === undefined) return;
|
|
1113
|
+
if (P().groupTabs === true && mode() !== 'filter') activeTab = first.group.id;
|
|
1114
|
+
else collapsed.delete(first.group.id);
|
|
1115
|
+
};
|
|
1116
|
+
/**
|
|
1117
|
+
* 页签条 DOM 同步:选中态回灌接线、补 roving tabindex;每枚页签 aria-controls 指向字段栅格(唯一的面板),
|
|
1118
|
+
* 栅格写 role=tabpanel + aria-labelledby=当前选中页签;非页签模式撤掉栅格上的面板语义。
|
|
1119
|
+
* 页签行由 core 渲染,本函数在 render / repaint 的同步与微任务两拍里调。
|
|
1120
|
+
*/
|
|
1121
|
+
const syncTabsDom = (): void => {
|
|
1122
|
+
const host = api.host;
|
|
1123
|
+
if (!host || typeof host.querySelector !== 'function') return;
|
|
1124
|
+
const grid = host.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
1125
|
+
const panelId = `${formUid}-panel`;
|
|
1126
|
+
if (P().groupTabs !== true || mode() === 'filter') {
|
|
1127
|
+
if (grid && grid.id === panelId) {
|
|
1128
|
+
grid.removeAttribute('id');
|
|
1129
|
+
grid.removeAttribute('role');
|
|
1130
|
+
grid.removeAttribute('aria-labelledby');
|
|
1131
|
+
}
|
|
1132
|
+
return;
|
|
992
1133
|
}
|
|
1134
|
+
tabsHandle?.select(activeTab, { silent: true });
|
|
1135
|
+
tabsHandle?.refresh();
|
|
1136
|
+
const bar = host.querySelector<HTMLElement>('[data-soma-id="tabbar"]');
|
|
1137
|
+
if (!bar || !grid) return;
|
|
1138
|
+
const tabs = Array.from(bar.querySelectorAll<HTMLElement>('[data-kit-group-tab]'));
|
|
1139
|
+
tabs.forEach((tab, i) => {
|
|
1140
|
+
if (tab.id === '') tab.id = `${formUid}-tab-${i}`;
|
|
1141
|
+
tab.setAttribute('aria-controls', panelId);
|
|
1142
|
+
});
|
|
1143
|
+
grid.id = panelId;
|
|
1144
|
+
grid.setAttribute('role', 'tabpanel');
|
|
1145
|
+
const on = tabs.find((t) => t.getAttribute('aria-selected') === 'true');
|
|
1146
|
+
if (on) grid.setAttribute('aria-labelledby', on.id);
|
|
1147
|
+
else grid.removeAttribute('aria-labelledby');
|
|
993
1148
|
};
|
|
994
1149
|
const repaint = (): void => {
|
|
995
1150
|
draftHandle?.touch();
|
|
996
|
-
|
|
1151
|
+
api.refresh();
|
|
1152
|
+
if (isBusy()) busySeen = true;
|
|
1153
|
+
else if (focusArmed && !busySeen) { focusBeforeBusy = ''; focusBeforeBusyButton = ''; }
|
|
1154
|
+
focusArmed = false;
|
|
1155
|
+
if (alive) syncBusyEmit();
|
|
1156
|
+
if (alive) syncDirtyEmit();
|
|
1157
|
+
if (alive) syncInvalid();
|
|
1158
|
+
if (alive) syncTabsDom();
|
|
997
1159
|
queueMicrotask(() => {
|
|
998
1160
|
if (!alive) return;
|
|
999
1161
|
syncInvalid();
|
|
1162
|
+
syncTabsDom();
|
|
1000
1163
|
// scrollToError:校验失败后把首个出错字段滚入可视区并聚焦(减少动效下不平滑滚动)
|
|
1164
|
+
let focusTaken = false;
|
|
1001
1165
|
if (pendingScroll) {
|
|
1002
1166
|
pendingScroll = false;
|
|
1003
|
-
|
|
1004
|
-
|
|
1167
|
+
// 有字段级错误 → 滚到并聚焦首个出错字段;只有整表错误 → 滚到顶部提示条
|
|
1168
|
+
const target = api.host?.querySelector?.<HTMLElement>('[aria-invalid="true"]')
|
|
1169
|
+
?? (notice !== '' ? api.host?.querySelector?.<HTMLElement>('[data-soma-id="notice"]') ?? null : null);
|
|
1170
|
+
if (target) {
|
|
1005
1171
|
const reduce = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1006
|
-
|
|
1007
|
-
|
|
1172
|
+
target.scrollIntoView?.({ block: 'center', behavior: reduce ? 'auto' : 'smooth' });
|
|
1173
|
+
if (target.getAttribute('aria-invalid') === 'true') { target.focus?.({ preventScroll: true }); focusTaken = true; }
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
// 刷新按钮持焦点时点了刷新:字段画出后焦点落到首个可用字段控件(取数期间字段不画,标记保留)
|
|
1177
|
+
if (pendingRefreshFocus && !detailBlocked()) {
|
|
1178
|
+
const host = api.host;
|
|
1179
|
+
// 焦点已被用户放到别处(既不在 body / 空,也不在刷新钮所在壳内):不抢焦点,直接作废标记
|
|
1180
|
+
const active = host?.ownerDocument?.activeElement ?? null;
|
|
1181
|
+
const stolen = active !== null && active !== host?.ownerDocument?.body
|
|
1182
|
+
&& !host?.querySelector?.('[data-soma-id="refresh_wrap"]')?.contains(active);
|
|
1183
|
+
if (stolen) disarmRefreshFocus();
|
|
1184
|
+
else for (const row of buildRows()) {
|
|
1185
|
+
if (row.id === '') continue;
|
|
1186
|
+
const el = host?.querySelector?.<HTMLElement>(`[id="${row.id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1187
|
+
if (!el) continue;
|
|
1188
|
+
const ctl = el.matches?.('input,select,textarea,button,[tabindex]')
|
|
1189
|
+
? el
|
|
1190
|
+
: el.querySelector<HTMLElement>('input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),[tabindex]');
|
|
1191
|
+
if (!ctl || (ctl as HTMLInputElement).disabled === true) continue;
|
|
1192
|
+
ctl.focus?.({ preventScroll: true });
|
|
1193
|
+
// 折叠分组 / 未激活页签 / 被展示对象隐藏的字段格不可见,focus() 静默失败:确认真的拿到焦点才算,否则试下一个
|
|
1194
|
+
const root = ctl.getRootNode?.() as Document | ShadowRoot | undefined;
|
|
1195
|
+
if ((root?.activeElement ?? ctl.ownerDocument?.activeElement) !== ctl) continue;
|
|
1196
|
+
focusTaken = true;
|
|
1197
|
+
// 真的拿到焦点才清标记;没拿到(字段控件晚到 / 全部不可聚焦)保留,等下一次重绘再试
|
|
1198
|
+
disarmRefreshFocus();
|
|
1199
|
+
break;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
// 处理中结束且没有别的定位接管:焦点还给提交前的字段
|
|
1203
|
+
if (busySeen && !isBusy()) {
|
|
1204
|
+
const id = focusBeforeBusy;
|
|
1205
|
+
const btnId = focusBeforeBusyButton;
|
|
1206
|
+
resetFocusRestore();
|
|
1207
|
+
// 没有字段可还且焦点在提交 / 重置钮:处理结束后焦点掉在 body 才归还给该钮(优先内部 button)
|
|
1208
|
+
if (id === '' && btnId !== '' && !focusTaken) {
|
|
1209
|
+
const doc = api.host?.ownerDocument;
|
|
1210
|
+
if (doc?.activeElement === null || doc?.activeElement === doc?.body) {
|
|
1211
|
+
const wrap = api.host?.querySelector?.<HTMLElement>(`[data-soma-id="${btnId}"]`);
|
|
1212
|
+
(wrap?.querySelector<HTMLElement>('button') ?? wrap)?.focus?.({ preventScroll: true });
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (id !== '' && !focusTaken) {
|
|
1216
|
+
const ctl = api.host?.querySelector?.<HTMLElement>(`[id="${id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1217
|
+
const doc = api.host?.ownerDocument;
|
|
1218
|
+
if (ctl && (doc?.activeElement === null || doc?.activeElement === doc?.body)) ctl.focus?.({ preventScroll: true });
|
|
1008
1219
|
}
|
|
1009
1220
|
}
|
|
1010
1221
|
});
|
|
1011
1222
|
};
|
|
1012
1223
|
|
|
1013
|
-
// ── M 波 G3:条件 /
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
return c.scenes.includes(mode() === 'edit' ? 'edit' : 'add');
|
|
1017
|
-
};
|
|
1018
|
-
/** 场景与 showWhen 都放行(不看分组折叠);不显示的字段不进 model、不过校验 */
|
|
1019
|
-
const shownByCond = (c: KitCell, vals: Rec): boolean => sceneOk(c) && (c.showWhen === undefined || holds(c.showWhen, vals));
|
|
1020
|
-
/** 必填星号位置:静态必填取编译期结果,条件必填(requiredWhen)按草稿求值;'' = 不标 */
|
|
1021
|
-
const starOf = (c: KitCell, vals: Rec): 'start' | 'end' | '' => {
|
|
1224
|
+
// ── M 波 G3:条件 / 布局 / 筛选折叠的纯计算 ──
|
|
1225
|
+
/** 必填星号位置:取编译期结果;'' = 不标 */
|
|
1226
|
+
const starOf = (c: KitCell): 'start' | 'end' | '' => {
|
|
1022
1227
|
if (mode() === 'filter' || c.placeholder === true || c.label === '') return '';
|
|
1023
1228
|
if (c.required !== undefined) return c.required;
|
|
1024
|
-
|
|
1025
|
-
return P().requiredMark === 'start' ? 'start' : 'end';
|
|
1229
|
+
// 展示对象绑定的必填:星号位置随 requiredMark(缺省在后)
|
|
1230
|
+
return stateOf(c.field).required ? (P().requiredMark === 'start' ? 'start' : 'end') : '';
|
|
1026
1231
|
};
|
|
1027
|
-
const starFields = (c: KitCell
|
|
1028
|
-
const s = starOf(c
|
|
1232
|
+
const starFields = (c: KitCell): Pick<KitFormRow, 'starStart' | 'starStartClass' | 'starEnd' | 'starEndClass'> => {
|
|
1233
|
+
const s = starOf(c);
|
|
1029
1234
|
return {
|
|
1030
1235
|
starStart: s === 'start' ? '*' : '',
|
|
1031
1236
|
starStartClass: s === 'start' ? KIT_REQUIRED_STAR_CLASS.start : 'hidden',
|
|
@@ -1070,124 +1275,148 @@ function createController(
|
|
|
1070
1275
|
return cells().filter((c) => c.placeholder !== true && c.component !== '' && !isBlank(vals[c.field])).length;
|
|
1071
1276
|
};
|
|
1072
1277
|
|
|
1073
|
-
// ── 远程选项(options.from):经 services.http
|
|
1074
|
-
/**
|
|
1278
|
+
// ── 远程选项(options.from):经 services.http 取 ──
|
|
1279
|
+
/** 选项源请求计划 */
|
|
1075
1280
|
const planFor = (of: NonNullable<KitCell['optionsFrom']>, vals: Rec): ReturnType<typeof planOptionSourceRequest> => {
|
|
1076
|
-
if (hasStepParams(of.params)) {
|
|
1077
|
-
const bound = bindStepParams(of.params, stepsOf());
|
|
1078
|
-
if (bound.missing) return { action: 'empty', reason: 'upstream-empty' } as ReturnType<typeof planOptionSourceRequest>;
|
|
1079
|
-
return planOptionSourceRequest({ route: of.from, params: bound.params as SomaOptionSourceParams }, vals);
|
|
1080
|
-
}
|
|
1081
1281
|
return planOptionSourceRequest({ route: of.from, params: of.params as SomaOptionSourceParams }, vals);
|
|
1082
1282
|
};
|
|
1283
|
+
const stringParamsOf = (raw: Rec): Record<string, string> => {
|
|
1284
|
+
const params: Record<string, string> = {};
|
|
1285
|
+
for (const [k, v] of Object.entries(raw)) if (v !== null && v !== undefined) params[k] = String(v);
|
|
1286
|
+
return params;
|
|
1287
|
+
};
|
|
1288
|
+
const keepLoadedRemoteOptions = (st: NonNullable<ReturnType<typeof remote.get>>, key: string): boolean => {
|
|
1289
|
+
if (st.loadedKey !== key) return false;
|
|
1290
|
+
// 返回仍已加载的 key 时保留现有候选,同时使另一 key 的迟到请求失效。
|
|
1291
|
+
if (st.inflightKey !== '' && st.inflightKey !== key) st.seq += 1;
|
|
1292
|
+
st.inflightKey = '';
|
|
1293
|
+
st.key = key;
|
|
1294
|
+
st.failedKey = '';
|
|
1295
|
+
st.pending = false;
|
|
1296
|
+
st.failed = false;
|
|
1297
|
+
st.error = false;
|
|
1298
|
+
return true;
|
|
1299
|
+
};
|
|
1300
|
+
const requestFieldOptions = (of: NonNullable<KitCell['optionsFrom']>, st: NonNullable<ReturnType<typeof remote.get>>, params: Record<string, string>, key: string): void => {
|
|
1301
|
+
st.inflightKey = key;
|
|
1302
|
+
st.key = key;
|
|
1303
|
+
st.failedKey = '';
|
|
1304
|
+
st.error = false;
|
|
1305
|
+
st.seq += 1;
|
|
1306
|
+
st.children?.clear();
|
|
1307
|
+
const mine = st.seq;
|
|
1308
|
+
void fetchRemoteOptionRows(api.services as unknown as Record<string, unknown> | undefined, of.from, params, of.rowsPath, api.host, effectiveEnvelope()).then((rows) => {
|
|
1309
|
+
if (!alive || st.seq !== mine) return;
|
|
1310
|
+
st.inflightKey = '';
|
|
1311
|
+
st.loadedKey = key;
|
|
1312
|
+
st.key = key;
|
|
1313
|
+
st.failedKey = '';
|
|
1314
|
+
st.error = false;
|
|
1315
|
+
st.rows = rows;
|
|
1316
|
+
repaint();
|
|
1317
|
+
}).catch(() => {
|
|
1318
|
+
if (!alive || st.seq !== mine) return;
|
|
1319
|
+
st.inflightKey = '';
|
|
1320
|
+
st.loadedKey = '';
|
|
1321
|
+
st.key = key;
|
|
1322
|
+
st.failedKey = key;
|
|
1323
|
+
st.error = true;
|
|
1324
|
+
st.rows = [];
|
|
1325
|
+
repaint();
|
|
1326
|
+
});
|
|
1327
|
+
};
|
|
1083
1328
|
const ensureOptions = (): void => {
|
|
1084
1329
|
const vals = draft.values();
|
|
1085
1330
|
for (const c of cells()) {
|
|
1086
1331
|
const of = c.optionsFrom;
|
|
1087
1332
|
if (of === undefined) continue;
|
|
1088
|
-
|
|
1333
|
+
// 候选由展示对象给出:不自取 options.from
|
|
1334
|
+
if (viewOptionsOf(c.field) !== undefined) continue;
|
|
1335
|
+
const st = remote.get(c.field) ?? { loadedKey: '', inflightKey: '', failedKey: '', key: '', rows: [], seq: 0, error: false };
|
|
1089
1336
|
remote.set(c.field, st);
|
|
1090
1337
|
// 请求参数构造与上游为空判定只用 foundation 的选项源计划(planOptionSourceRequest),kit 只补字符串化与搜索关键字
|
|
1091
1338
|
const plan = planFor(of, vals);
|
|
1092
1339
|
if (plan.action !== 'fetch') {
|
|
1093
|
-
if (st.
|
|
1340
|
+
if (st.loadedKey !== '' || st.inflightKey !== '' || st.key !== '' || st.failedKey !== '' || st.rows.length > 0 || st.error) {
|
|
1341
|
+
st.loadedKey = '';
|
|
1342
|
+
st.inflightKey = '';
|
|
1343
|
+
st.key = '';
|
|
1344
|
+
st.failedKey = '';
|
|
1345
|
+
st.rows = [];
|
|
1346
|
+
st.error = false;
|
|
1347
|
+
st.seq += 1;
|
|
1348
|
+
st.children?.clear();
|
|
1349
|
+
}
|
|
1094
1350
|
continue;
|
|
1095
1351
|
}
|
|
1096
|
-
const params
|
|
1097
|
-
for (const [k, v] of Object.entries(plan.params)) {
|
|
1098
|
-
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1099
|
-
}
|
|
1352
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1100
1353
|
if (of.searchParam !== '' && st.keyword !== undefined && st.keyword !== '') params[of.searchParam] = st.keyword;
|
|
1101
1354
|
const key = JSON.stringify(params);
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
st
|
|
1106
|
-
const mine = st.seq;
|
|
1107
|
-
const http = (ctx.services as { http?: { get<T>(url: string, config?: { params?: Record<string, string> }): Promise<T>; baseURL?: unknown } } | undefined)?.http;
|
|
1108
|
-
if (!http) continue;
|
|
1109
|
-
const rawBase = http.baseURL;
|
|
1110
|
-
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
1111
|
-
const api = baseURL !== '' && baseURL !== '/' && of.from.startsWith(`${baseURL}/`) ? of.from.slice(baseURL.length) : of.from;
|
|
1112
|
-
void http.get<unknown>(api, { params }).then((res) => {
|
|
1113
|
-
if (!alive || st.seq !== mine) return;
|
|
1114
|
-
st.rows = rowsOfOptionsResponse(res, of.rowsPath);
|
|
1115
|
-
repaint();
|
|
1116
|
-
}).catch(() => {
|
|
1117
|
-
if (!alive || st.seq !== mine) return;
|
|
1118
|
-
st.rows = [];
|
|
1119
|
-
repaint();
|
|
1120
|
-
});
|
|
1355
|
+
if (keepLoadedRemoteOptions(st, key)
|
|
1356
|
+
|| (st.key === key && st.inflightKey === key)
|
|
1357
|
+
|| (st.key === key && st.failedKey === key)) continue;
|
|
1358
|
+
requestFieldOptions(of, st, params, key);
|
|
1121
1359
|
}
|
|
1122
1360
|
ensureFlowOptions();
|
|
1123
1361
|
};
|
|
1124
1362
|
|
|
1125
1363
|
// ── H2a:FlowEditor 字段的节点配置动态选项(props.nodeTypes.<类型>.fields[].options 写成对象)──
|
|
1126
|
-
// 取数状态存在 remote
|
|
1364
|
+
// 取数状态存在 remote 表里(键带前缀,避免和字段名相撞);失败照实标出,不吞成空列表
|
|
1127
1365
|
const flowSlotKey = (field: string, slot: FlowOptionSlot): string => `flow\u0001${field}\u0001${slot.id}`;
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1366
|
+
const requestFlowOptions = (slot: FlowOptionSlot, st: NonNullable<ReturnType<typeof remote.get>>, params: Record<string, string>, key: string): void => {
|
|
1367
|
+
st.inflightKey = key;
|
|
1368
|
+
st.key = key;
|
|
1369
|
+
st.failedKey = '';
|
|
1370
|
+
st.seq += 1;
|
|
1371
|
+
st.failed = false;
|
|
1372
|
+
st.error = false;
|
|
1373
|
+
st.pending = true;
|
|
1374
|
+
const mine = st.seq;
|
|
1375
|
+
void fetchRemoteOptionRows(api.services as unknown as Record<string, unknown> | undefined, slot.from, params, slot.rowsPath, api.host, effectiveEnvelope()).then((rows) => {
|
|
1376
|
+
if (!alive || st.seq !== mine) return;
|
|
1377
|
+
st.inflightKey = '';
|
|
1378
|
+
st.loadedKey = key;
|
|
1379
|
+
st.key = key;
|
|
1380
|
+
st.failedKey = '';
|
|
1381
|
+
st.rows = rows;
|
|
1382
|
+
st.pending = false;
|
|
1383
|
+
st.error = false;
|
|
1384
|
+
repaint();
|
|
1385
|
+
}).catch(() => {
|
|
1386
|
+
if (!alive || st.seq !== mine) return;
|
|
1387
|
+
st.inflightKey = '';
|
|
1388
|
+
st.loadedKey = '';
|
|
1389
|
+
st.key = key;
|
|
1390
|
+
st.failedKey = key;
|
|
1391
|
+
st.rows = [];
|
|
1392
|
+
st.pending = false;
|
|
1393
|
+
st.failed = true;
|
|
1394
|
+
st.error = true;
|
|
1395
|
+
repaint();
|
|
1396
|
+
});
|
|
1145
1397
|
};
|
|
1146
1398
|
const ensureFlowOptions = (): void => {
|
|
1147
1399
|
const vals = draft.values();
|
|
1148
1400
|
for (const c of cells()) {
|
|
1149
|
-
if (
|
|
1150
|
-
const slotList =
|
|
1401
|
+
if (c.component !== 'FlowEditor' || !isRec(c.props)) continue;
|
|
1402
|
+
const slotList = flowOptionSlots(c.props.nodeTypes);
|
|
1151
1403
|
for (const slot of slotList) {
|
|
1152
1404
|
const id = flowSlotKey(c.field, slot);
|
|
1153
|
-
const st = remote.get(id) ?? { key: '', rows: [], seq: 0 };
|
|
1405
|
+
const st = remote.get(id) ?? { loadedKey: '', inflightKey: '', failedKey: '', key: '', rows: [], seq: 0, error: false };
|
|
1154
1406
|
remote.set(id, st);
|
|
1155
1407
|
const plan = planOptionSourceRequest({ route: slot.from, params: slot.params as SomaOptionSourceParams }, vals);
|
|
1156
1408
|
if (plan.action !== 'fetch') {
|
|
1157
|
-
if (st.key !== '' || st.rows.length > 0 || st.failed === true || st.pending === true) {
|
|
1158
|
-
|
|
1159
|
-
st.key = ''; st.rows = []; st.seq += 1; st.failed = false; st.pending = false;
|
|
1160
|
-
// 依赖值被清空:之前有候选,现在一个都不成立,已选的值一并清掉
|
|
1161
|
-
if (hadKey) dropStaleFlowSelections(c.field, slot, new Set());
|
|
1409
|
+
if (st.loadedKey !== '' || st.inflightKey !== '' || st.key !== '' || st.failedKey !== '' || st.rows.length > 0 || st.failed === true || st.pending === true || st.error) {
|
|
1410
|
+
st.loadedKey = ''; st.inflightKey = ''; st.key = ''; st.failedKey = ''; st.rows = []; st.seq += 1; st.failed = false; st.pending = false; st.error = false;
|
|
1162
1411
|
}
|
|
1163
1412
|
continue;
|
|
1164
1413
|
}
|
|
1165
|
-
const params
|
|
1166
|
-
for (const [k, v] of Object.entries(plan.params)) {
|
|
1167
|
-
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1168
|
-
}
|
|
1414
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1169
1415
|
const key = JSON.stringify(params);
|
|
1170
|
-
if (
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
st
|
|
1174
|
-
st.seq += 1;
|
|
1175
|
-
st.failed = false;
|
|
1176
|
-
st.pending = true;
|
|
1177
|
-
const mine = st.seq;
|
|
1178
|
-
void fetchRemoteOptionRows(ctx.services as unknown as Record<string, unknown> | undefined, slot.from, params, slot.rowsPath).then((rows) => {
|
|
1179
|
-
if (!alive || st.seq !== mine) return;
|
|
1180
|
-
st.rows = rows;
|
|
1181
|
-
st.pending = false;
|
|
1182
|
-
if (recheck) dropStaleFlowSelections(c.field, slot, new Set(flowOptionsOfRows(slot, rows).map((o) => o.value)));
|
|
1183
|
-
repaint();
|
|
1184
|
-
}).catch(() => {
|
|
1185
|
-
if (!alive || st.seq !== mine) return;
|
|
1186
|
-
st.rows = [];
|
|
1187
|
-
st.pending = false;
|
|
1188
|
-
st.failed = true;
|
|
1189
|
-
repaint();
|
|
1190
|
-
});
|
|
1416
|
+
if (keepLoadedRemoteOptions(st, key)
|
|
1417
|
+
|| (st.key === key && st.inflightKey === key)
|
|
1418
|
+
|| (st.key === key && st.failedKey === key)) continue;
|
|
1419
|
+
requestFlowOptions(slot, st, params, key);
|
|
1191
1420
|
}
|
|
1192
1421
|
}
|
|
1193
1422
|
};
|
|
@@ -1196,15 +1425,58 @@ function createController(
|
|
|
1196
1425
|
const st = remote.get(flowSlotKey(field, slot));
|
|
1197
1426
|
if (st === undefined) return { state: 'idle', options: [] };
|
|
1198
1427
|
if (st.pending === true) return { state: 'loading', options: [] };
|
|
1199
|
-
if (st.failed === true) return { state: 'failed', options: [] };
|
|
1200
|
-
if (st.key === '') return { state: 'idle', options: [] };
|
|
1428
|
+
if (st.failed === true || st.error === true) return { state: 'failed', options: [] };
|
|
1429
|
+
if (st.loadedKey === '' && st.key === '') return { state: 'idle', options: [] };
|
|
1201
1430
|
return { state: 'ok', options: flowOptionsOfRows(slot, st.rows) };
|
|
1202
1431
|
};
|
|
1203
|
-
const flowPlaceholder = (state: string): string => (state === 'loading' ? kitText('soma.kit.rows_options_loading', undefined,
|
|
1432
|
+
const flowPlaceholder = (state: string): string => (state === 'loading' ? kitText('soma.kit.rows_options_loading', undefined, api.host) : state === 'failed' ? kitText('soma.kit.rows_options_failed', undefined, api.host) : '');
|
|
1204
1433
|
const flowNodeTypes = (field: string, nodeTypes: Rec): Rec => withFlowOptions(nodeTypes, flowResolver(field), flowPlaceholder);
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1434
|
+
const hasFailedOption = (c: KitCell): boolean => {
|
|
1435
|
+
if (viewOptionsOf(c.field) !== undefined) return false;
|
|
1436
|
+
const own = c.optionsFrom === undefined ? undefined : remote.get(c.field);
|
|
1437
|
+
if (own?.error === true && typeof own.failedKey === 'string' && own.failedKey !== '') return true;
|
|
1438
|
+
if (c.component !== 'FlowEditor' || !isRec(c.props)) return false;
|
|
1439
|
+
return flowOptionSlots(c.props.nodeTypes).some((slot) => {
|
|
1440
|
+
const st = remote.get(flowSlotKey(c.field, slot));
|
|
1441
|
+
return st?.error === true && typeof st.failedKey === 'string' && st.failedKey !== '';
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1444
|
+
const retryOptions = (row: unknown): boolean => {
|
|
1445
|
+
syncDraft();
|
|
1446
|
+
const name = isRec(row) ? strOf(row.name) : typeof row === 'string' ? row : '';
|
|
1447
|
+
const c = cells().find((item) => item.field === name);
|
|
1448
|
+
if (c === undefined || detailBlocked() || viewOptionsOf(name) !== undefined) return true;
|
|
1449
|
+
const vals = draft.values();
|
|
1450
|
+
if (c.optionsFrom !== undefined) {
|
|
1451
|
+
const st = remote.get(name);
|
|
1452
|
+
if (st?.error !== true || typeof st.failedKey !== 'string' || st.failedKey === '') return true;
|
|
1453
|
+
const plan = planFor(c.optionsFrom, vals);
|
|
1454
|
+
if (plan.action !== 'fetch') { ensureOptions(); return true; }
|
|
1455
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1456
|
+
if (c.optionsFrom.searchParam !== '' && st.keyword !== undefined && st.keyword !== '') params[c.optionsFrom.searchParam] = st.keyword;
|
|
1457
|
+
const key = JSON.stringify(params);
|
|
1458
|
+
if (key !== st.failedKey) { ensureOptions(); return true; }
|
|
1459
|
+
requestFieldOptions(c.optionsFrom, st, params, key);
|
|
1460
|
+
repaint();
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
if (c.component === 'FlowEditor' && isRec(c.props)) {
|
|
1464
|
+
let retried = false;
|
|
1465
|
+
for (const slot of flowOptionSlots(c.props.nodeTypes)) {
|
|
1466
|
+
const st = remote.get(flowSlotKey(name, slot));
|
|
1467
|
+
if (st?.error !== true || typeof st.failedKey !== 'string' || st.failedKey === '') continue;
|
|
1468
|
+
const plan = planOptionSourceRequest({ route: slot.from, params: slot.params as SomaOptionSourceParams }, vals);
|
|
1469
|
+
if (plan.action !== 'fetch') { ensureFlowOptions(); continue; }
|
|
1470
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1471
|
+
const key = JSON.stringify(params);
|
|
1472
|
+
if (key !== st.failedKey) { ensureFlowOptions(); continue; }
|
|
1473
|
+
requestFlowOptions(slot, st, params, key);
|
|
1474
|
+
retried = true;
|
|
1475
|
+
}
|
|
1476
|
+
if (retried) repaint();
|
|
1477
|
+
}
|
|
1478
|
+
return true;
|
|
1479
|
+
};
|
|
1208
1480
|
|
|
1209
1481
|
/** 级联按层懒加载:展开一个 lazy 节点时,以 `<lazy>=<该节点值>` 重取它的子级(根层参数同选项源计划) */
|
|
1210
1482
|
const loadChildren = (c: KitCell, path: readonly string[]): void => {
|
|
@@ -1218,18 +1490,18 @@ function createController(
|
|
|
1218
1490
|
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1219
1491
|
}
|
|
1220
1492
|
params[of.tree.lazy] = path[path.length - 1]!;
|
|
1221
|
-
const http = (
|
|
1493
|
+
const http = (api.services as { http?: { get<T>(url: string, config?: { params?: Record<string, string> }): Promise<T>; baseURL?: unknown } } | undefined)?.http;
|
|
1222
1494
|
if (!http) return;
|
|
1223
1495
|
const rawBase = http.baseURL;
|
|
1224
1496
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
1225
|
-
const
|
|
1497
|
+
const apiPath = baseURL !== '' && baseURL !== '/' && of.from.startsWith(`${baseURL}/`) ? of.from.slice(baseURL.length) : of.from;
|
|
1226
1498
|
const mine = st.seq;
|
|
1227
1499
|
const store = (rows: Rec[]): void => {
|
|
1228
1500
|
if (!alive || st.seq !== mine) return;
|
|
1229
1501
|
(st.children ??= new Map<string, Rec[]>()).set(cascadeKey(path), rows);
|
|
1230
1502
|
repaint();
|
|
1231
1503
|
};
|
|
1232
|
-
void http.get<unknown>(
|
|
1504
|
+
void http.get<unknown>(apiPath, { params }).then((res) => store(rowsOfOptionsResponse(res, of.rowsPath, effectiveEnvelope(), api.host))).catch(() => store([]));
|
|
1233
1505
|
};
|
|
1234
1506
|
|
|
1235
1507
|
const buildRows = (): KitFormRow[] => {
|
|
@@ -1237,40 +1509,15 @@ function createController(
|
|
|
1237
1509
|
const only = createOnly();
|
|
1238
1510
|
const values = draft.values();
|
|
1239
1511
|
const rows: KitFormRow[] = [];
|
|
1240
|
-
const noGroup = { groupId: '', groupExpanded: '', groupControls: '', groupMark: '', groupToggleClass: '', bodyClass: FORM_BODY_CLASS
|
|
1512
|
+
const noGroup = { groupId: '', groupExpanded: '', groupControls: '', groupMark: '', groupToggleClass: '', bodyClass: FORM_BODY_CLASS };
|
|
1241
1513
|
const tabs = P().groupTabs === true && m !== 'filter';
|
|
1242
1514
|
const hiddenRows = hiddenByFilterCollapse();
|
|
1243
|
-
const heads: KitFormRow[] = [];
|
|
1244
1515
|
for (const c of cells()) {
|
|
1245
1516
|
// 页签模式:分组分隔线不画(页签本身就是分隔)
|
|
1246
1517
|
if (tabs && c.divider === true) continue;
|
|
1247
1518
|
// form.groups 平铺:标题行(可折叠 = 按钮,否则纯标题);折叠节的字段格整格藏起(格类换成 hidden,不和 flex 同元素)
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
heads.push({
|
|
1251
|
-
id: `kit-${objectName()}-${c.field}`,
|
|
1252
|
-
name: c.field,
|
|
1253
|
-
component: '_tab',
|
|
1254
|
-
label: c.label,
|
|
1255
|
-
cellClass: TAB_CELL_CLASS,
|
|
1256
|
-
labelClass: '',
|
|
1257
|
-
errorClass: KIT_FORM_CLASS.errorHidden,
|
|
1258
|
-
error: '',
|
|
1259
|
-
help: '',
|
|
1260
|
-
helpClass: KIT_FORM_CLASS.errorHidden,
|
|
1261
|
-
text: '',
|
|
1262
|
-
pv: {},
|
|
1263
|
-
groupId: g.id,
|
|
1264
|
-
groupExpanded: '',
|
|
1265
|
-
groupControls: '',
|
|
1266
|
-
groupMark: '',
|
|
1267
|
-
groupToggleClass: '',
|
|
1268
|
-
bodyClass: '',
|
|
1269
|
-
tabPressed: activeTab === g.id ? 'true' : 'false',
|
|
1270
|
-
tabClass: FL.groupsAs.tabClass,
|
|
1271
|
-
});
|
|
1272
|
-
continue;
|
|
1273
|
-
}
|
|
1519
|
+
// 页签模式:标题格不进字段栅格(页签画在独立的 tablist 条里,见 buildTabRows)
|
|
1520
|
+
if (c.group?.head === true && tabs) continue;
|
|
1274
1521
|
if (c.group?.head === true) {
|
|
1275
1522
|
const g = c.group;
|
|
1276
1523
|
const collapsible = g.collapsible === true;
|
|
@@ -1295,20 +1542,20 @@ function createController(
|
|
|
1295
1542
|
groupMark: isOpen ? markers[1] : markers[0],
|
|
1296
1543
|
groupToggleClass: KIT_FORM_CLASS.groupToggle,
|
|
1297
1544
|
bodyClass: '',
|
|
1298
|
-
tabPressed: '',
|
|
1299
|
-
tabClass: '',
|
|
1300
1545
|
});
|
|
1301
1546
|
continue;
|
|
1302
1547
|
}
|
|
1303
1548
|
const hiddenByGroup = (c.group !== undefined && (tabs ? c.group.id !== activeTab : collapsed.has(c.group.id)))
|
|
1304
|
-
||
|
|
1549
|
+
|| hiddenRows.has(c.field)
|
|
1550
|
+
|| stateOf(c.field).hidden;
|
|
1305
1551
|
const readOnlyHere = m === 'edit' && only.has(c.field);
|
|
1306
1552
|
const wanted = c.placeholder === true || c.component === '' ? '' : readOnlyHere ? 'Text' : c.component;
|
|
1307
1553
|
const component = wanted === '' ? FALLBACK_ROLE : nameSet.has(wanted) ? wanted : FALLBACK_ROLE;
|
|
1308
1554
|
const id = `kit-${objectName()}-${c.field}`;
|
|
1309
1555
|
const error = errors[c.field] ?? '';
|
|
1310
|
-
|
|
1311
|
-
const
|
|
1556
|
+
const value = values[c.field];
|
|
1557
|
+
const st = remote.get(c.field);
|
|
1558
|
+
const optionsRetry = !readOnlyHere && hasFailedOption(c);
|
|
1312
1559
|
const given = isRec(c.props) ? c.props : {};
|
|
1313
1560
|
const pv: Rec = { ...propDefaults(registered[component]), ...given };
|
|
1314
1561
|
if (readOnlyHere) {
|
|
@@ -1318,33 +1565,58 @@ function createController(
|
|
|
1318
1565
|
delete pv.placeholder;
|
|
1319
1566
|
}
|
|
1320
1567
|
pv.value = value;
|
|
1568
|
+
if (component === 'RowEditor') pv.cell_errors = error !== '' ? rowsCellErrorsOf(c) : [];
|
|
1321
1569
|
pv.id = id;
|
|
1322
1570
|
pv.name = c.field;
|
|
1323
1571
|
if (c.valueClass !== '' && c.valueClass !== undefined) pv.class = c.valueClass;
|
|
1324
|
-
|
|
1325
|
-
if (!readOnlyHere && (isBusy() || P().disabled === true || given.disabled === true || disabledByCond) && 'disabled' in pv) pv.disabled = true;
|
|
1572
|
+
if (!readOnlyHere && (isBusy() || P().disabled === true || given.disabled === true || stateOf(c.field).disabled) && 'disabled' in pv) pv.disabled = true;
|
|
1326
1573
|
// 远程选项:候选来自 http(依赖值缺失时为空)
|
|
1327
1574
|
if (c.optionsFrom !== undefined) {
|
|
1328
1575
|
const of = c.optionsFrom;
|
|
1329
|
-
const st = remote.get(c.field);
|
|
1330
1576
|
pv.options = of.tree !== undefined
|
|
1331
1577
|
? cascadeOptions(st?.rows ?? [], of, of.tree, st?.children ?? new Map<string, Rec[]>(), [])
|
|
1332
1578
|
: (st?.rows ?? []).map((r) => ({ value: r[of.valueKey], label: strOf(r[of.labelKey], strOf(r[of.valueKey])) }));
|
|
1579
|
+
if (st?.inflightKey !== '' && st?.inflightKey !== undefined) {
|
|
1580
|
+
pv.loading = true;
|
|
1581
|
+
if (!readOnlyHere && (pv.placeholder === undefined || pv.placeholder === '')) {
|
|
1582
|
+
pv.placeholder = kitText('soma.kit.rows_options_loading', undefined, api.host);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
if (st?.error === true || st?.failed === true) {
|
|
1586
|
+
pv.optionsError = true;
|
|
1587
|
+
if (!readOnlyHere) {
|
|
1588
|
+
pv.placeholder = kitText('soma.kit.rows_options_failed', undefined, api.host);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
// 契约声明了 error_text 的组件(如 RecordPicker):失败文案下传,未失败为空串
|
|
1592
|
+
const declared = registered[component]?.contract.props ?? {};
|
|
1593
|
+
if ('error_text' in declared) {
|
|
1594
|
+
pv.error_text = st?.error === true || st?.failed === true ? kitText('soma.kit.rows_options_failed', undefined, api.host) : '';
|
|
1595
|
+
}
|
|
1596
|
+
// 远程搜索字段(options.searchParam):契约有 search_delay 的组件(Combobox)缺省按 design 的搜索防抖(search.debounceMs)去抖,
|
|
1597
|
+
// 不每敲一个字发一次请求;页面在 props 里显式给了 search_delay 时以页面为准
|
|
1598
|
+
if ('search_delay' in declared && of.searchParam !== '' && given.search_delay === undefined) {
|
|
1599
|
+
pv.search_delay = String(SOMA_QUERY_LIMITS_CORE.queryLimits.searchDebounceMs);
|
|
1600
|
+
}
|
|
1601
|
+
// 契约用 data 承载候选行(无 options)的组件:候选下传为 { id, title },有 searchParam 时开远程搜索
|
|
1602
|
+
if ('data' in declared && !('options' in declared) && given.data === undefined) {
|
|
1603
|
+
pv.data = (pv.options as Array<{ value: unknown; label: unknown }>).map((o) => ({ id: o.value, title: o.label }));
|
|
1604
|
+
if ('remote_search' in declared && of.searchParam !== '' && given.remote_search === undefined) pv.remote_search = true;
|
|
1605
|
+
}
|
|
1333
1606
|
}
|
|
1607
|
+
// 展示对象给出的候选项(options: view.<成员>):优先于静态 / 远程候选,只在 'options' 属性存在的组件上生效
|
|
1608
|
+
const viewOptions = viewOptionsOf(c.field);
|
|
1609
|
+
if (viewOptions !== undefined) pv.options = viewOptions;
|
|
1334
1610
|
// H2a:画布字段的节点配置动态选项(取到的并进 nodeTypes,画布只认静态选项)
|
|
1335
|
-
if (component === 'FlowEditor' && isRec(pv.nodeTypes)) pv.nodeTypes = flowNodeTypes(c.field, pv.nodeTypes);
|
|
1336
|
-
//
|
|
1337
|
-
if (component === '
|
|
1611
|
+
if (c.component === 'FlowEditor' && isRec(pv.nodeTypes)) pv.nodeTypes = flowNodeTypes(c.field, pv.nodeTypes);
|
|
1612
|
+
// 展示对象给出的节点字段候选项(nodeOptions: view.<成员>):交画布并进 nodeTypes,随展示对象整体替换引用重绘
|
|
1613
|
+
if (c.component === 'FlowEditor') { const nodeOptions = viewNodeOptionsOf(c.field); if (nodeOptions !== undefined) pv.nodeOptions = nodeOptions; }
|
|
1338
1614
|
rows.push({
|
|
1339
1615
|
id,
|
|
1340
1616
|
name: c.field,
|
|
1341
1617
|
component,
|
|
1342
1618
|
label: c.placeholder === true ? '' : c.label,
|
|
1343
|
-
...starFields(c
|
|
1344
|
-
// 「已采纳」只表示当前值仍是被采纳的建议值;用户再改了就不再标
|
|
1345
|
-
...(c.field in adopted && sameValue(value, adopted[c.field])
|
|
1346
|
-
? { adopted: kitText('soma.kit.adopted', undefined, ctx.host), adoptedClass: KIT_FORM_CLASS.adoptedTag }
|
|
1347
|
-
: { adopted: '', adoptedClass: KIT_FORM_CLASS.noticeHidden }),
|
|
1619
|
+
...starFields(c),
|
|
1348
1620
|
...noGroup,
|
|
1349
1621
|
cellClass: hiddenByGroup ? 'hidden' : cellClassOf(c),
|
|
1350
1622
|
labelClass: labelClassOf(c),
|
|
@@ -1352,11 +1624,31 @@ function createController(
|
|
|
1352
1624
|
error,
|
|
1353
1625
|
help: readOnlyHere ? '' : strOf(c.help),
|
|
1354
1626
|
helpClass: !readOnlyHere && strOf(c.help) !== '' ? KIT_FORM_CLASS.help : KIT_FORM_CLASS.errorHidden,
|
|
1627
|
+
optionsRetry,
|
|
1628
|
+
optionsRetryClass: optionsRetry ? OPTIONS_RETRY_CLASS : KIT_FORM_CLASS.errorHidden,
|
|
1629
|
+
optionsRetryText: kitText('soma.kit.ct_retry', undefined, api.host),
|
|
1355
1630
|
text: isBlank(value) ? '' : strOf(value),
|
|
1356
1631
|
pv,
|
|
1357
1632
|
});
|
|
1358
1633
|
}
|
|
1359
|
-
return
|
|
1634
|
+
return rows;
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
/** 页签条的行(仅 groupTabs 且非 filter 模式;详情取数中不画) */
|
|
1638
|
+
const buildTabRows = (): KitFormTabRow[] => {
|
|
1639
|
+
if (P().groupTabs !== true || mode() === 'filter' || detailBlocked()) return [];
|
|
1640
|
+
const out: KitFormTabRow[] = [];
|
|
1641
|
+
for (const c of cells()) {
|
|
1642
|
+
if (c.group?.head !== true) continue;
|
|
1643
|
+
out.push({
|
|
1644
|
+
id: `kit-${objectName()}-${c.field}`,
|
|
1645
|
+
label: c.label,
|
|
1646
|
+
groupId: c.group.id,
|
|
1647
|
+
selected: activeTab === c.group.id ? 'true' : 'false',
|
|
1648
|
+
tabClass: FL.groupsAs.tabClass,
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
return out;
|
|
1360
1652
|
};
|
|
1361
1653
|
|
|
1362
1654
|
const fieldErrorsFor = (raw: Record<string, string>): Record<string, string> => {
|
|
@@ -1366,6 +1658,51 @@ function createController(
|
|
|
1366
1658
|
return out;
|
|
1367
1659
|
};
|
|
1368
1660
|
|
|
1661
|
+
const syncInvalidFields = (): void => {
|
|
1662
|
+
invalidFields.clear();
|
|
1663
|
+
for (const [k, msg] of Object.entries(errors)) {
|
|
1664
|
+
if (msg !== '') invalidFields.add(k);
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
/** 单字段静态 / 动态规则校验(rules / 必填 / FlowEditor / RowEditor) */
|
|
1669
|
+
const validateCellRule = (name: string): string => {
|
|
1670
|
+
const c = cells().find((x) => x.field === name);
|
|
1671
|
+
if (!c || c.placeholder === true || !editableSet().has(name)) return '';
|
|
1672
|
+
const st = stateOf(name);
|
|
1673
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1674
|
+
if (st.hidden || st.disabled || props.disabled === true || props.readonly === true) return '';
|
|
1675
|
+
const val = draft.values()[name];
|
|
1676
|
+
const rawRules = Array.isArray((c as unknown as Rec).rules)
|
|
1677
|
+
? ((c as unknown as Rec).rules as unknown[])
|
|
1678
|
+
: Array.isArray(props.rules)
|
|
1679
|
+
? (props.rules as unknown[])
|
|
1680
|
+
: [];
|
|
1681
|
+
for (const r of rawRules) {
|
|
1682
|
+
if (!isRec(r)) continue;
|
|
1683
|
+
const msg = strOf(r.message) || kitText('soma.kit.field_required', undefined, api.host);
|
|
1684
|
+
if (r.required === true && isBlank(val)) return msg;
|
|
1685
|
+
if (!isBlank(val)) {
|
|
1686
|
+
const minLen = typeof r.min_len === 'number' ? r.min_len : typeof r.minLength === 'number' ? r.minLength : undefined;
|
|
1687
|
+
if (minLen !== undefined && String(val).length < minLen) return msg;
|
|
1688
|
+
const maxLen = typeof r.max_len === 'number' ? r.max_len : typeof r.maxLength === 'number' ? r.maxLength : undefined;
|
|
1689
|
+
if (maxLen !== undefined && String(val).length > maxLen) return msg;
|
|
1690
|
+
// 与字段规则同一份带防护的正则实现:模式非法 / 超长(null)放行,被测文本超长视为不通过且不执行匹配
|
|
1691
|
+
if (typeof r.pattern === 'string' && r.pattern !== '' && testRegexGuarded(r.pattern, String(val)) === false) return msg;
|
|
1692
|
+
if (typeof r.min === 'number' && Number(val) < r.min) return msg;
|
|
1693
|
+
if (typeof r.max === 'number' && Number(val) > r.max) return msg;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if ((c.required !== undefined || props.required === true || st.required) && isBlank(val)) {
|
|
1697
|
+
return kitText('soma.kit.field_required', undefined, api.host);
|
|
1698
|
+
}
|
|
1699
|
+
const flowErr = flowFieldErrors()[name];
|
|
1700
|
+
if (flowErr !== undefined) return flowErr;
|
|
1701
|
+
const rowErr = rowsFieldErrors()[name];
|
|
1702
|
+
if (rowErr !== undefined) return rowErr;
|
|
1703
|
+
return '';
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1369
1706
|
// ── 写入结果回显 ──
|
|
1370
1707
|
const onOutcome = (scope: string): void => {
|
|
1371
1708
|
if (scope !== scopeKey()) return;
|
|
@@ -1374,6 +1711,7 @@ function createController(
|
|
|
1374
1711
|
if (view.status === 'pending') {
|
|
1375
1712
|
if (view.seq <= pendingSeq || view.seq <= settledSeq) return;
|
|
1376
1713
|
pendingSeq = view.seq;
|
|
1714
|
+
rememberFocus();
|
|
1377
1715
|
busy = true;
|
|
1378
1716
|
repaint();
|
|
1379
1717
|
return;
|
|
@@ -1386,24 +1724,30 @@ function createController(
|
|
|
1386
1724
|
busy = false;
|
|
1387
1725
|
conflict = false;
|
|
1388
1726
|
errors = fieldErrorsFor({ ...view.fieldErrors });
|
|
1727
|
+
syncInvalidFields();
|
|
1389
1728
|
draft.recordSubmitError(Object.entries(errors).map(([field, message]) => ({ field, message })));
|
|
1390
|
-
notice = Object.keys(errors).length > 0 ? '' : (view.message !== '' ? view.message : kitText(FAILED_FALLBACK, undefined,
|
|
1729
|
+
notice = Object.keys(errors).length > 0 ? '' : (view.message !== '' ? view.message : kitText(FAILED_FALLBACK, undefined, api.host));
|
|
1730
|
+
revealFirstErrorGroup();
|
|
1731
|
+
pendingScroll = P().scrollToError !== false;
|
|
1391
1732
|
break;
|
|
1392
1733
|
}
|
|
1393
1734
|
case 'conflict':
|
|
1394
1735
|
busy = false;
|
|
1395
1736
|
conflict = true;
|
|
1396
1737
|
errors = {};
|
|
1397
|
-
|
|
1738
|
+
syncInvalidFields();
|
|
1739
|
+
notice = view.message !== '' ? view.message : kitText(CONFLICT_FALLBACK, undefined, api.host);
|
|
1398
1740
|
break;
|
|
1399
1741
|
case 'saved':
|
|
1400
1742
|
busy = false;
|
|
1401
1743
|
conflict = false;
|
|
1402
1744
|
errors = {};
|
|
1745
|
+
syncInvalidFields();
|
|
1403
1746
|
notice = '';
|
|
1747
|
+
resetFocusRestore();
|
|
1404
1748
|
draft.markSaved();
|
|
1405
|
-
|
|
1406
|
-
|
|
1749
|
+
syncDirtyEmit();
|
|
1750
|
+
api.emit('saved', { object: objectName(), scope: scopeKey(), result: view.result });
|
|
1407
1751
|
break;
|
|
1408
1752
|
default:
|
|
1409
1753
|
busy = false;
|
|
@@ -1411,15 +1755,39 @@ function createController(
|
|
|
1411
1755
|
repaint();
|
|
1412
1756
|
};
|
|
1413
1757
|
|
|
1414
|
-
/**
|
|
1758
|
+
/** 首次失焦后校验(focusout / blur),已出错或已触碰字段改动即复校(Reward Early, Punish Late) */
|
|
1415
1759
|
const instantValidate = (trigger: 'change' | 'blur', name: string): void => {
|
|
1416
|
-
if (mode() === 'filter' || !
|
|
1760
|
+
if (mode() === 'filter' || !editableSet().has(name)) return;
|
|
1761
|
+
if (trigger === 'blur') {
|
|
1762
|
+
touchedFields.add(name);
|
|
1763
|
+
} else if (!invalidFields.has(name) && !touchedFields.has(name) && !stringList(P().validateOn).includes('change')) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1417
1766
|
const port = dataPort();
|
|
1418
|
-
|
|
1419
|
-
|
|
1767
|
+
let msg = '';
|
|
1768
|
+
if (port?.validate) {
|
|
1769
|
+
const bad = port.validate(strOf(P().dictObject) || objectName(), validationValues(), trigger);
|
|
1770
|
+
const isStaticSubmitStub =
|
|
1771
|
+
trigger === 'change' &&
|
|
1772
|
+
!touchedFields.has(name) &&
|
|
1773
|
+
!stringList(P().validateOn).includes('change') &&
|
|
1774
|
+
bad === lastSubmitVerdictRef &&
|
|
1775
|
+
!isBlank(draft.get(name));
|
|
1776
|
+
if (!isStaticSubmitStub && typeof bad[name] === 'string' && bad[name] !== '') {
|
|
1777
|
+
msg = bad[name]!;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (msg === '') {
|
|
1781
|
+
msg = validateCellRule(name);
|
|
1782
|
+
}
|
|
1420
1783
|
const next = { ...errors };
|
|
1421
|
-
if (
|
|
1422
|
-
|
|
1784
|
+
if (msg !== '') {
|
|
1785
|
+
next[name] = msg;
|
|
1786
|
+
invalidFields.add(name);
|
|
1787
|
+
} else {
|
|
1788
|
+
delete next[name];
|
|
1789
|
+
invalidFields.delete(name);
|
|
1790
|
+
}
|
|
1423
1791
|
errors = next;
|
|
1424
1792
|
};
|
|
1425
1793
|
|
|
@@ -1428,15 +1796,16 @@ function createController(
|
|
|
1428
1796
|
syncDraft();
|
|
1429
1797
|
const m = mode();
|
|
1430
1798
|
// 阶段闸门不满足:提交被拦(按钮已禁用且原因常驻显示;回车提交同样被拦)
|
|
1431
|
-
if (isBusy() || P().disabled === true ||
|
|
1799
|
+
if (isBusy() || P().disabled === true || (m !== 'filter' && P().submitDisabled === true)) return true;
|
|
1432
1800
|
if (m === 'filter') {
|
|
1433
|
-
|
|
1801
|
+
api.emit('submit', { values: collectFilter(), object: objectName(), scope: scopeKey(), mode: 'filter' });
|
|
1434
1802
|
return true;
|
|
1435
1803
|
}
|
|
1436
1804
|
const port = dataPort();
|
|
1437
1805
|
{
|
|
1438
1806
|
const dictKey = strOf(P().dictObject) || objectName();
|
|
1439
1807
|
const verdict: Record<string, string> = port?.validate ? port.validate(dictKey, validationValues()) : {};
|
|
1808
|
+
lastSubmitVerdictRef = port?.validate ? verdict : null;
|
|
1440
1809
|
const bad: Record<string, string> = fieldErrorsFor(verdict);
|
|
1441
1810
|
const editable = editableSet();
|
|
1442
1811
|
for (const k of Object.keys(bad)) if (!editable.has(k)) delete bad[k];
|
|
@@ -1444,27 +1813,44 @@ function createController(
|
|
|
1444
1813
|
const hiddenBad = hiddenNames().filter((n) => editable.has(n) && typeof verdict[n] === 'string' && verdict[n] !== '');
|
|
1445
1814
|
if (hiddenBad.length > 0) {
|
|
1446
1815
|
errors = bad;
|
|
1447
|
-
|
|
1816
|
+
syncInvalidFields();
|
|
1817
|
+
notice = kitText('soma.kit.hidden_invalid', { field: hiddenBad[0]!, message: verdict[hiddenBad[0]!]! }, api.host);
|
|
1448
1818
|
pendingScroll = false;
|
|
1449
1819
|
repaint();
|
|
1450
1820
|
return true;
|
|
1451
1821
|
}
|
|
1452
1822
|
// GB4:流程画布字段必填时至少要有一个节点
|
|
1453
1823
|
for (const [k, message] of Object.entries(flowFieldErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
1824
|
+
// 展示对象绑定的必填
|
|
1825
|
+
for (const [k, message] of Object.entries(boundRequiredErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
1454
1826
|
// 子表字段(RowEditor):列上的 required / pattern / 数值范围与行数上下限,逐行校验(字段级 rules 已由字典判过必填)
|
|
1455
1827
|
for (const [k, message] of Object.entries(rowsFieldErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
1828
|
+
// 字段级显式 rules(cell.rules / cell.props.rules)
|
|
1829
|
+
for (const c of cells()) {
|
|
1830
|
+
if (c.placeholder === true || !editable.has(c.field) || bad[c.field] !== undefined) continue;
|
|
1831
|
+
const hasExplicitRules = Array.isArray((c as unknown as Rec).rules) || (isRec(c.props) && Array.isArray(c.props.rules));
|
|
1832
|
+
if (hasExplicitRules) {
|
|
1833
|
+
const ruleMsg = validateCellRule(c.field);
|
|
1834
|
+
if (ruleMsg !== '') bad[c.field] = ruleMsg;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1456
1837
|
if (Object.keys(bad).length > 0) {
|
|
1457
1838
|
errors = bad;
|
|
1839
|
+
syncInvalidFields();
|
|
1458
1840
|
notice = '';
|
|
1459
|
-
|
|
1841
|
+
revealFirstErrorGroup();
|
|
1842
|
+
pendingScroll = P().scrollToError !== false;
|
|
1460
1843
|
repaint();
|
|
1461
1844
|
return true;
|
|
1462
1845
|
}
|
|
1463
1846
|
}
|
|
1464
1847
|
errors = {};
|
|
1848
|
+
syncInvalidFields();
|
|
1465
1849
|
notice = '';
|
|
1850
|
+
resetFocusRestore();
|
|
1851
|
+
rememberFocus();
|
|
1466
1852
|
const model = collectModel();
|
|
1467
|
-
|
|
1853
|
+
api.emit('submit', {
|
|
1468
1854
|
values: draft.values(),
|
|
1469
1855
|
object: objectName(),
|
|
1470
1856
|
model,
|
|
@@ -1478,28 +1864,74 @@ function createController(
|
|
|
1478
1864
|
const resetForm = (): boolean => {
|
|
1479
1865
|
syncDraft();
|
|
1480
1866
|
errors = {};
|
|
1867
|
+
touchedFields.clear();
|
|
1868
|
+
invalidFields.clear();
|
|
1869
|
+
lastSubmitVerdictRef = null;
|
|
1481
1870
|
notice = '';
|
|
1482
1871
|
conflict = false;
|
|
1483
|
-
|
|
1872
|
+
resetFocusRestore();
|
|
1484
1873
|
if (mode() === 'filter') {
|
|
1485
1874
|
draft = createFormDraft({ initial: {} });
|
|
1486
|
-
|
|
1875
|
+
api.emit('reset', { values: {}, object: objectName(), scope: scopeKey() });
|
|
1487
1876
|
} else {
|
|
1488
1877
|
draft.reset();
|
|
1489
|
-
|
|
1878
|
+
api.emit('reset', { values: draft.values(), object: objectName(), scope: scopeKey() });
|
|
1490
1879
|
}
|
|
1491
|
-
|
|
1880
|
+
syncDirtyEmit();
|
|
1881
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
1492
1882
|
repaint();
|
|
1493
1883
|
return true;
|
|
1494
1884
|
};
|
|
1495
1885
|
|
|
1496
1886
|
const ctrl: Record<string, unknown> = {
|
|
1887
|
+
/**
|
|
1888
|
+
* 展示对象可调用的公开方法(core 的 ctx.component(id).call;kit 的 ctx.form(对象) 是它的具名糖):
|
|
1889
|
+
* 读草稿快照、写草稿字段值(与用户输入走同一条通道:即时校验、draft_change、重绘)。
|
|
1890
|
+
*/
|
|
1891
|
+
handle: {
|
|
1892
|
+
values: (): Rec => { syncDraft(); return { ...draft.values() }; },
|
|
1893
|
+
dirty: (): boolean => { syncDraft(); return draft.isDirty(); },
|
|
1894
|
+
mode: (): string => mode(),
|
|
1895
|
+
/** 本表单的有效信封(prop 非空用 prop,否则按宿主查找;都没有为 undefined):展示对象的级联选项等按它解包响应 */
|
|
1896
|
+
envelope: (): KitEnvelope | undefined => effectiveEnvelope(),
|
|
1897
|
+
set: (field: string, value: unknown): boolean => {
|
|
1898
|
+
syncDraft();
|
|
1899
|
+
if (detailBlocked() || typeof field !== 'string' || field === '') return false;
|
|
1900
|
+
const known = cells().some((c) => c.field === field) || hiddenNames().includes(field) || field in draft.values();
|
|
1901
|
+
if (!known) return false;
|
|
1902
|
+
return (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value, __viaHandle: true });
|
|
1903
|
+
},
|
|
1904
|
+
/** 画布字段(控件 FlowEditor)当前的节点(浅拷贝);不是画布字段返回 [] */
|
|
1905
|
+
flowNodes: (field: string): Rec[] => {
|
|
1906
|
+
syncDraft();
|
|
1907
|
+
const c = cells().find((x) => x.field === field);
|
|
1908
|
+
return c?.component === 'FlowEditor' ? flowValueNodes(draft.values()[field]) : [];
|
|
1909
|
+
},
|
|
1910
|
+
/** 清空画布字段里某类型节点的某个已选值(连带该字段声明的 resets);与 set 同一条通道,返回被清的节点数 */
|
|
1911
|
+
clearFlowNodeField: (field: string, type: string, key: string): number => {
|
|
1912
|
+
syncDraft();
|
|
1913
|
+
const c = cells().find((x) => x.field === field);
|
|
1914
|
+
if (c?.component !== 'FlowEditor' || detailBlocked()) return 0;
|
|
1915
|
+
const res = clearFlowNodeField(draft.values()[field], isRec(c.props) ? c.props.nodeTypes : undefined, type, key);
|
|
1916
|
+
if (res.cleared === 0) return 0;
|
|
1917
|
+
(ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value: res.value, __viaHandle: true });
|
|
1918
|
+
return res.cleared;
|
|
1919
|
+
},
|
|
1920
|
+
},
|
|
1497
1921
|
get rows(): KitFormRow[] {
|
|
1498
1922
|
syncDraft();
|
|
1499
1923
|
// 编辑详情取数中 / 失败:不画字段(不拿列表行的旧值顶替)
|
|
1500
1924
|
return detailBlocked() ? [] : buildRows();
|
|
1501
1925
|
},
|
|
1502
1926
|
get rootClass(): string { return mergeClass(KIT_FORM_CLASS.wrap, strOf(classesOf().wrap)); },
|
|
1927
|
+
get tabRows(): KitFormTabRow[] {
|
|
1928
|
+
syncDraft();
|
|
1929
|
+
return buildTabRows();
|
|
1930
|
+
},
|
|
1931
|
+
get tabbarClass(): string {
|
|
1932
|
+
syncDraft();
|
|
1933
|
+
return buildTabRows().length > 0 ? FL.groupsAs.barClass : 'hidden';
|
|
1934
|
+
},
|
|
1503
1935
|
get gridClass(): string {
|
|
1504
1936
|
syncDraft();
|
|
1505
1937
|
if (detailBlocked()) return KIT_FORM_CLASS.errorHidden;
|
|
@@ -1513,20 +1945,12 @@ function createController(
|
|
|
1513
1945
|
get footerRows(): Array<{ id: string; label: string; variant: string; disabled: boolean }> {
|
|
1514
1946
|
syncDraft();
|
|
1515
1947
|
if (mode() === 'filter' || detailBlocked() || !Array.isArray(P().footerActions)) return [];
|
|
1516
|
-
// GA2:底栏动作的状态条件——叶子读本表单草稿字段或 outcome.*;hiddenWhen 成立不画,disabledWhen 成立置灰
|
|
1517
|
-
const vals = draft.values();
|
|
1518
|
-
const reader = (name: string): { status: string; message: string; data: unknown } | undefined => {
|
|
1519
|
-
const o = outcomes.get(name);
|
|
1520
|
-
return o === undefined ? undefined : { status: o.status, message: o.message, data: o.data };
|
|
1521
|
-
};
|
|
1522
1948
|
return (P().footerActions as unknown[]).filter(isRec).flatMap((a) => {
|
|
1523
|
-
const state = evalActionGate(gateFrom(a), vals, reader);
|
|
1524
|
-
if (state.hidden) return [];
|
|
1525
1949
|
// request.cancelable 的底栏动作在途:原位置变「取消」且保持可点(点的是取消,真正中止请求)
|
|
1526
1950
|
const cancelNow = isKitActionCancelable(strOf(a.id));
|
|
1527
1951
|
return [{
|
|
1528
|
-
id: strOf(a.id), label: cancelNow ? kitText('soma.kit.cancel', undefined,
|
|
1529
|
-
disabled: cancelNow ? false :
|
|
1952
|
+
id: strOf(a.id), label: cancelNow ? kitText('soma.kit.cancel', undefined, api.host) : strOf(a.label), variant: 'neutral',
|
|
1953
|
+
disabled: cancelNow ? false : isKitActionBusy(strOf(a.id)),
|
|
1530
1954
|
}];
|
|
1531
1955
|
}).filter((a) => a.id !== '');
|
|
1532
1956
|
},
|
|
@@ -1539,10 +1963,10 @@ function createController(
|
|
|
1539
1963
|
if (o === undefined || o.seq <= resultBaseSeq) return null;
|
|
1540
1964
|
const panel = outcomePanelData(o);
|
|
1541
1965
|
const title = strOf(decl.title);
|
|
1542
|
-
if (panel.status === 'busy') return { status: 'busy', text: kitText('soma.kit.processing', undefined,
|
|
1966
|
+
if (panel.status === 'busy') return { status: 'busy', text: kitText('soma.kit.processing', undefined, api.host), title, lines: [], tone: 'neutral' };
|
|
1543
1967
|
if (panel.status === 'failed') {
|
|
1544
1968
|
const m = strOf(panel.message);
|
|
1545
|
-
return { status: 'failed', text: m !== '' ? m : kitText('soma.kit.request_failed', undefined,
|
|
1969
|
+
return { status: 'failed', text: m !== '' ? m : kitText('soma.kit.request_failed', undefined, api.host), title, lines: [], tone: 'danger' };
|
|
1546
1970
|
}
|
|
1547
1971
|
if (panel.status !== 'ready') return null;
|
|
1548
1972
|
const shaped = asyncResultOf(panel.result);
|
|
@@ -1561,14 +1985,17 @@ function createController(
|
|
|
1561
1985
|
get resultText(): string { return (this.resultView as { text: string } | null)?.text ?? ''; },
|
|
1562
1986
|
get resultTextClass(): string { return ((this.resultView as { text: string } | null)?.text ?? '') === '' ? KIT_FORM_CLASS.errorHidden : KIT_FORM_CLASS.resultText; },
|
|
1563
1987
|
get resultLines(): Array<{ label: string; labelClass: string; text: string }> { return (this.resultView as { lines: Array<{ label: string; labelClass: string; text: string }> } | null)?.lines ?? []; },
|
|
1564
|
-
/**
|
|
1988
|
+
/** 点底栏动作:抛槽位事件 footer_action_<序号> { id }(页面事件给每个 request / download 动作各绑一条管道) */
|
|
1565
1989
|
onFooterAction(row: unknown): boolean {
|
|
1566
1990
|
const id = isRec(row) ? strOf(row.id) : '';
|
|
1567
1991
|
if (id !== '' && isKitActionCancelable(id)) { cancelKitAction(id); return true; }
|
|
1568
|
-
if (id !== '' && !isKitActionBusy(id))
|
|
1992
|
+
if (id !== '' && !isKitActionBusy(id)) {
|
|
1993
|
+
const list = Array.isArray(P().footerActions) ? (P().footerActions as unknown[]) : [];
|
|
1994
|
+
emitActionSlot((n, p) => api.emit(n, p), KIT_ACTION_SLOT_BASE.footer, list.findIndex((a) => isRec(a) && strOf(a.id) === id), { id, object: objectName(), scope: scopeKey() });
|
|
1995
|
+
}
|
|
1569
1996
|
return true;
|
|
1570
1997
|
},
|
|
1571
|
-
get detailStateText(): string { syncDraft(); return detailState === 'loading' ? kitText('soma.kit.processing', undefined,
|
|
1998
|
+
get detailStateText(): string { syncDraft(); return detailState === 'loading' ? kitText('soma.kit.processing', undefined, api.host) : ''; },
|
|
1572
1999
|
get noticeClass(): string {
|
|
1573
2000
|
syncDraft();
|
|
1574
2001
|
return notice === '' ? KIT_FORM_CLASS.noticeHidden : mergeClass(KIT_FORM_CLASS.notice, strOf(classesOf().notice));
|
|
@@ -1577,116 +2004,34 @@ function createController(
|
|
|
1577
2004
|
// 冲突(请刷新)与编辑详情取数失败(请重试)共用同一个提示条上的按钮
|
|
1578
2005
|
get conflict(): boolean { return conflict || detailState === 'failed'; },
|
|
1579
2006
|
get busy(): boolean { return isBusy(); },
|
|
1580
|
-
get formDisabled(): boolean { syncDraft(); return P().disabled === true ||
|
|
1581
|
-
// 阶段闸门原因(常驻显示,不允许静默拦截)
|
|
1582
|
-
get gateNote(): string { syncDraft(); return blockedBy(); },
|
|
1583
|
-
get gateNoteClass(): string { return this.gateNote === '' ? KIT_FORM_CLASS.noticeHidden : KIT_FORM_CLASS.gateNote; },
|
|
1584
|
-
// 被拦住时才出「去验证」钮;请求在路上时禁用(防重复点)
|
|
1585
|
-
get gateRunWrapClass(): string { syncDraft(); return gateDecl()?.run !== undefined && blockedBy() !== '' ? '' : 'hidden'; },
|
|
1586
|
-
get gateRunLabel(): string {
|
|
1587
|
-
const given = gateDecl()?.runLabel;
|
|
1588
|
-
return typeof given === 'string' && given !== '' ? given : kitText('soma.kit.gate_run', undefined, ctx.host);
|
|
1589
|
-
},
|
|
1590
|
-
get gateRunDisabled(): boolean {
|
|
1591
|
-
const into = gateDecl()?.runOutcome;
|
|
1592
|
-
return (into !== undefined && outcomes.get(into)?.status === 'pending') || isBusy();
|
|
1593
|
-
},
|
|
1594
|
-
runGate(): boolean {
|
|
1595
|
-
syncDraft();
|
|
1596
|
-
const run = gateDecl()?.run;
|
|
1597
|
-
if (run === undefined || this.gateRunDisabled === true) return true;
|
|
1598
|
-
ctx.emit('gate_run', { object: objectName(), scope: scopeKey(), action: run });
|
|
1599
|
-
return true;
|
|
1600
|
-
},
|
|
1601
|
-
// 采纳条
|
|
1602
|
-
// 写了 ask(表单内的「获取建议」钮)时采纳条常驻;否则只在有新建议可采纳时出现
|
|
1603
|
-
get adoptBarClass(): string { return currentAdopt() === null && askAction() === '' ? KIT_FORM_CLASS.noticeHidden : KIT_FORM_CLASS.adoptBar; },
|
|
1604
|
-
get adoptGoWrapClass(): string {
|
|
1605
|
-
const cur = currentAdopt();
|
|
1606
|
-
return cur !== null && Object.keys(cur.plan.changes).length > 0 ? KIT_FORM_CLASS.adoptBtnWrap : 'hidden';
|
|
1607
|
-
},
|
|
1608
|
-
get adoptSkipWrapClass(): string { return currentAdopt() === null ? 'hidden' : KIT_FORM_CLASS.adoptBtnWrap; },
|
|
1609
|
-
get adoptAskWrapClass(): string { return askAction() === '' ? 'hidden' : KIT_FORM_CLASS.adoptBtnWrap; },
|
|
1610
|
-
get adoptAskLabel(): string {
|
|
1611
|
-
// request.cancelable 的获取请求在途:原位置变「取消」
|
|
1612
|
-
if (askOutcome()?.status === 'pending' && isKitActionCancelable(askAction())) return kitText('soma.kit.cancel', undefined, ctx.host);
|
|
1613
|
-
const given = adoptDecl()?.askLabel;
|
|
1614
|
-
return typeof given === 'string' && given !== '' ? given : kitText('soma.kit.adopt_ask', undefined, ctx.host);
|
|
1615
|
-
},
|
|
1616
|
-
get adoptAskDisabled(): boolean {
|
|
1617
|
-
// 可取消的在途获取请求:钮保持可点(点的是取消)
|
|
1618
|
-
if (askOutcome()?.status === 'pending' && isKitActionCancelable(askAction())) return false;
|
|
1619
|
-
return askOutcome()?.status === 'pending' || isBusy();
|
|
1620
|
-
},
|
|
1621
|
-
get adoptText(): string {
|
|
1622
|
-
syncDraft();
|
|
1623
|
-
const asked = askOutcome();
|
|
1624
|
-
// 请求在路上 / 失败:照实说,不静默(失败文案取自写入结果)
|
|
1625
|
-
if (askAction() !== '' && asked?.status === 'pending') return kitText('soma.kit.adopt_pending', undefined, ctx.host);
|
|
1626
|
-
if (askAction() !== '' && asked?.status === 'cancelled' && asked.seq > adoptConsumedSeq) return kitText('soma.kit.request_cancelled', undefined, ctx.host);
|
|
1627
|
-
if (askAction() !== '' && asked?.status === 'failed' && asked.seq > adoptConsumedSeq) {
|
|
1628
|
-
return asked.message !== '' ? asked.message : kitText('soma.kit.adopt_failed', undefined, ctx.host);
|
|
1629
|
-
}
|
|
1630
|
-
const cur = currentAdopt();
|
|
1631
|
-
if (cur === null) return askAction() === '' ? '' : kitText('soma.kit.adopt_hint', undefined, ctx.host);
|
|
1632
|
-
const n = Object.keys(cur.plan.changes).length;
|
|
1633
|
-
const skipped = cur.plan.skipped.length;
|
|
1634
|
-
const hiddenN = cur.plan.hidden.length;
|
|
1635
|
-
const head = n > 0 ? kitText('soma.kit.adopt_n', { n }, ctx.host) : kitText('soma.kit.adopt_none', undefined, ctx.host);
|
|
1636
|
-
// H2c:会改到不显示的隐藏字段时,采纳条明说『含 N 个隐藏字段』,不让用户糊涂采纳
|
|
1637
|
-
const withHidden = hiddenN > 0 ? `${head} ${kitText('soma.kit.adopt_hidden', { n: hiddenN }, ctx.host)}` : head;
|
|
1638
|
-
return skipped > 0 ? `${withHidden} ${kitText('soma.kit.adopt_skipped', { n: skipped }, ctx.host)}` : withHidden;
|
|
1639
|
-
},
|
|
1640
|
-
/** 点「获取建议」:交给页面级请求宿主发 ask 指向的 request 动作(body 里可取 $draft.*) */
|
|
1641
|
-
askSuggestion(): boolean {
|
|
1642
|
-
syncDraft();
|
|
1643
|
-
if (askAction() === '' || this.adoptAskDisabled === true) return true;
|
|
1644
|
-
if (askOutcome()?.status === 'pending' && isKitActionCancelable(askAction())) { cancelKitAction(askAction()); return true; }
|
|
1645
|
-
ctx.emit('adopt_ask', { object: objectName(), scope: scopeKey(), action: askAction() });
|
|
1646
|
-
return true;
|
|
1647
|
-
},
|
|
1648
|
-
get adoptLabel(): string {
|
|
1649
|
-
const given = adoptDecl()?.label;
|
|
1650
|
-
return typeof given === 'string' && given !== '' ? given : kitText('soma.kit.adopt', undefined, ctx.host);
|
|
1651
|
-
},
|
|
1652
|
-
get adoptSkipLabel(): string { return kitText('soma.kit.adopt_dismiss', undefined, ctx.host); },
|
|
1653
|
-
/** 点「采纳」:把建议值写进草稿(只改草稿,不提交),被改的字段旁出现「已采纳」 */
|
|
1654
|
-
adoptSuggestion(): boolean {
|
|
1655
|
-
syncDraft();
|
|
1656
|
-
const cur = currentAdopt();
|
|
1657
|
-
if (cur === null) return true;
|
|
1658
|
-
adoptConsumedSeq = cur.seq;
|
|
1659
|
-
applyAdopted(cur.plan.changes);
|
|
1660
|
-
return true;
|
|
1661
|
-
},
|
|
1662
|
-
/** 点「忽略」:这次建议不再提供,草稿不动 */
|
|
1663
|
-
dismissSuggestion(): boolean {
|
|
1664
|
-
const cur = currentAdopt();
|
|
1665
|
-
if (cur !== null) adoptConsumedSeq = cur.seq;
|
|
1666
|
-
repaint();
|
|
1667
|
-
return true;
|
|
1668
|
-
},
|
|
2007
|
+
get formDisabled(): boolean { syncDraft(); return P().disabled === true || (mode() !== 'filter' && P().submitDisabled === true); },
|
|
1669
2008
|
get showReset(): boolean { return mode() === 'filter' || strOf(P().resetLabel) !== ''; },
|
|
1670
2009
|
get showCancel(): boolean { return strOf(P().cancelLabel) !== ''; },
|
|
1671
2010
|
// filter 折叠:展开 / 收起钮与有值计数徽标(只在 collapsible 且确有被折起的行时出现)
|
|
1672
2011
|
get showToggle(): boolean { return P().collapsible === true && filterRows().rows > Math.max(1, Math.trunc(Number(P().collapsedRows) || 1)); },
|
|
1673
2012
|
get toggleWrapClass(): string { return this.showToggle === true ? FL.filterOptions.toggleWrapClass : 'hidden'; },
|
|
1674
|
-
get toggleText(): string { return kitText(filterCollapsed ? 'soma.kit.expand' : 'soma.kit.collapse', undefined,
|
|
1675
|
-
get badgeText(): string { const n = P().collapsible === true ? filledCount() : 0; return n > 0 ? kitText('soma.kit.filter_set_n', { n },
|
|
2013
|
+
get toggleText(): string { return kitText(filterCollapsed ? 'soma.kit.expand' : 'soma.kit.collapse', undefined, api.host); },
|
|
2014
|
+
get badgeText(): string { const n = P().collapsible === true ? filledCount() : 0; return n > 0 ? kitText('soma.kit.filter_set_n', { n }, api.host) : ''; },
|
|
1676
2015
|
get badgeClass(): string { return this.badgeText === '' ? 'hidden' : FL.filterOptions.badgeClass; },
|
|
1677
2016
|
get refreshWrapClass(): string { return conflict || detailState === 'failed' ? '' : 'hidden'; },
|
|
1678
2017
|
get resetWrapClass(): string { return (mode() === 'filter' || strOf(P().resetLabel) !== '') ? '' : 'hidden'; },
|
|
1679
2018
|
get cancelWrapClass(): string { return strOf(P().cancelLabel) !== '' ? '' : 'hidden'; },
|
|
1680
2019
|
get submitText(): string {
|
|
1681
2020
|
const given = strOf(P().submitLabel);
|
|
1682
|
-
return given !== '' ? given : kitText(mode() === 'filter' ? DEFAULT_FILTER_LABEL : DEFAULT_SUBMIT_LABEL, undefined,
|
|
2021
|
+
return given !== '' ? given : kitText(mode() === 'filter' ? DEFAULT_FILTER_LABEL : DEFAULT_SUBMIT_LABEL, undefined, api.host);
|
|
1683
2022
|
},
|
|
2023
|
+
get submitTitle(): string {
|
|
2024
|
+
syncDraft();
|
|
2025
|
+
return computeSubmitTitle();
|
|
2026
|
+
},
|
|
2027
|
+
get touchedFields(): ReadonlySet<string> { return touchedFields; },
|
|
2028
|
+
get invalidFields(): ReadonlySet<string> { return invalidFields; },
|
|
1684
2029
|
get resetText(): string {
|
|
1685
2030
|
const given = strOf(P().resetLabel);
|
|
1686
|
-
return given !== '' ? given : kitText(DEFAULT_RESET_LABEL, undefined,
|
|
2031
|
+
return given !== '' ? given : kitText(DEFAULT_RESET_LABEL, undefined, api.host);
|
|
1687
2032
|
},
|
|
1688
2033
|
get cancelText(): string { return strOf(P().cancelLabel); },
|
|
1689
|
-
get refreshLabel(): string { return kitText(detailState === 'failed' ? 'soma.kit.ct_retry' : DEFAULT_REFRESH_LABEL, undefined,
|
|
2034
|
+
get refreshLabel(): string { return kitText(detailState === 'failed' ? 'soma.kit.ct_retry' : DEFAULT_REFRESH_LABEL, undefined, api.host); },
|
|
1690
2035
|
get primaryVariant(): string { return 'primary'; },
|
|
1691
2036
|
get neutralVariant(): string { return 'neutral'; },
|
|
1692
2037
|
get ghostVariant(): string { return 'ghost'; },
|
|
@@ -1696,64 +2041,47 @@ function createController(
|
|
|
1696
2041
|
|
|
1697
2042
|
/** 行内基础组件的 change:第二参是 emit 载荷 { value },第一参是行变量 */
|
|
1698
2043
|
onFieldChange(row: unknown, payload: unknown): boolean {
|
|
2044
|
+
const viaHandle = isRec(payload) && payload.__viaHandle === true;
|
|
1699
2045
|
syncDraft();
|
|
1700
2046
|
const name = isRec(row) ? strOf(row.name) : '';
|
|
1701
2047
|
if (name === '' || !isRec(payload)) return true;
|
|
2048
|
+
const wasInvalid = invalidFields.has(name) || name in errors;
|
|
1702
2049
|
draft.set(name, payload.value);
|
|
1703
|
-
// 依赖字段变了:清掉依赖它的远程选项字段的值(连锁清),回填所选选项行的其它列(fill)
|
|
1704
|
-
const queue = [name];
|
|
1705
|
-
while (queue.length > 0) {
|
|
1706
|
-
const n = queue.shift()!;
|
|
1707
|
-
for (const c of cells()) {
|
|
1708
|
-
if (c.optionsFrom !== undefined && optionSourceReloadOn({ reload: c.optionsFrom.deps }, [n]) && !isBlank(draft.get(c.field))) {
|
|
1709
|
-
draft.set(c.field, '');
|
|
1710
|
-
queue.push(c.field);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
const picked = cells().find((c) => c.field === name)?.optionsFrom;
|
|
1715
|
-
if (picked !== undefined && Object.keys(picked.fill).length > 0) {
|
|
1716
|
-
const row = remote.get(name)?.rows.find((r) => strOf(r[picked.valueKey]) === strOf(payload.value));
|
|
1717
|
-
if (row !== undefined) for (const [from, to] of Object.entries(picked.fill)) draft.set(to, row[from]);
|
|
1718
|
-
}
|
|
1719
|
-
ensureOptions();
|
|
1720
2050
|
if (name in errors) {
|
|
1721
2051
|
const next = { ...errors };
|
|
1722
2052
|
delete next[name];
|
|
1723
2053
|
errors = next;
|
|
1724
2054
|
}
|
|
1725
|
-
|
|
2055
|
+
if (wasInvalid || touchedFields.has(name) || stringList(P().validateOn).includes('change')) {
|
|
2056
|
+
instantValidate('change', name);
|
|
2057
|
+
} else {
|
|
2058
|
+
invalidFields.delete(name);
|
|
2059
|
+
}
|
|
1726
2060
|
if (mode() === 'filter' && P().trigger === 'change') {
|
|
1727
2061
|
if (debounceTimer !== undefined) clearTimeout(debounceTimer);
|
|
1728
2062
|
debounceTimer = setTimeout(() => { debounceTimer = undefined; if (alive) submitForm(); }, KIT_FORM_LINKAGE_LIMITS.filterOptions.changeDebounceMs);
|
|
1729
2063
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
2064
|
+
ensureOptions();
|
|
2065
|
+
syncDirtyEmit();
|
|
2066
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty(), field: name, source: viaHandle ? 'api' : 'input' });
|
|
2067
|
+
repaint();
|
|
2068
|
+
return true;
|
|
2069
|
+
},
|
|
2070
|
+
/** 行内基础组件失焦:加入 touchedFields 并对单字段执行校验 */
|
|
2071
|
+
onFieldBlur(row: unknown): boolean {
|
|
2072
|
+
syncDraft();
|
|
2073
|
+
const name = isRec(row) ? strOf(row.name) : typeof row === 'string' ? row : '';
|
|
2074
|
+
if (name === '') return true;
|
|
2075
|
+
touchedFields.add(name);
|
|
2076
|
+
instantValidate('blur', name);
|
|
1742
2077
|
repaint();
|
|
1743
2078
|
return true;
|
|
1744
2079
|
},
|
|
1745
|
-
/** 选记录类组件(RecordPicker)抛 pick { value, values, item, items }
|
|
2080
|
+
/** 选记录类组件(RecordPicker)抛 pick { value, values, item, items }:value 写本字段 */
|
|
1746
2081
|
onFieldPick(row: unknown, payload: unknown): boolean {
|
|
1747
2082
|
syncDraft();
|
|
1748
2083
|
const name = isRec(row) ? strOf(row.name) : '';
|
|
1749
2084
|
if (name === '' || !isRec(payload)) return true;
|
|
1750
|
-
const fill = cells().find((c) => c.field === name)?.fill ?? {};
|
|
1751
|
-
const items = Array.isArray(payload.items) ? payload.items.filter(isRec) : [];
|
|
1752
|
-
const multi = Array.isArray(payload.value);
|
|
1753
|
-
for (const [from, to] of Object.entries(fill)) {
|
|
1754
|
-
if (multi) draft.set(to, items.map((it) => it[from]));
|
|
1755
|
-
else if (isRec(payload.item)) draft.set(to, payload.item[from]);
|
|
1756
|
-
}
|
|
1757
2085
|
return (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)(row, { value: payload.value });
|
|
1758
2086
|
},
|
|
1759
2087
|
/** 级联(Cascader)展开了还没有子级的 lazy 节点:抛 load { value: 路径, node },按 options.lazy 重取该节点的子级 */
|
|
@@ -1765,6 +2093,8 @@ function createController(
|
|
|
1765
2093
|
loadChildren(c, (payload.value as unknown[]).map((v) => strOf(v)));
|
|
1766
2094
|
return true;
|
|
1767
2095
|
},
|
|
2096
|
+
/** 按字段显式重试当前失败的同一选项 key(包括 FlowEditor 的一个失败槽);不广播其它请求 */
|
|
2097
|
+
retryOptions,
|
|
1768
2098
|
/** 带远程搜索的组件抛 search { keyword }:关键字作为 options.searchParam 重取候选 */
|
|
1769
2099
|
onFieldSearch(row: unknown, payload: unknown): boolean {
|
|
1770
2100
|
syncDraft();
|
|
@@ -1772,8 +2102,11 @@ function createController(
|
|
|
1772
2102
|
const of = cells().find((c) => c.field === name)?.optionsFrom;
|
|
1773
2103
|
const st = remote.get(name);
|
|
1774
2104
|
if (of === undefined || of.searchParam === '' || st === undefined || !isRec(payload)) return true;
|
|
1775
|
-
|
|
1776
|
-
|
|
2105
|
+
// 基础组件的 search 事件载荷是 { query }(Combobox / Mentions);keyword / value 为历史兼容
|
|
2106
|
+
st.keyword = strOf(payload.query ?? payload.keyword ?? payload.value);
|
|
2107
|
+
// 字段处于失败态:同一请求键由 retryOptions 重发(ensureOptions 会跳过相同失败键);键变了它自己回落到 ensureOptions
|
|
2108
|
+
if (st.error === true && typeof st.failedKey === 'string' && st.failedKey !== '') retryOptions({ name });
|
|
2109
|
+
else ensureOptions();
|
|
1777
2110
|
return true;
|
|
1778
2111
|
},
|
|
1779
2112
|
toggleCollapsed(): boolean {
|
|
@@ -1786,67 +2119,60 @@ function createController(
|
|
|
1786
2119
|
cancelForm(): boolean {
|
|
1787
2120
|
// 载荷只增不改:带上当前草稿(不校验),分步表单「上一步」靠它保存本步未提交的改动
|
|
1788
2121
|
syncDraft();
|
|
1789
|
-
|
|
2122
|
+
api.emit('cancel', { object: objectName(), scope: scopeKey(), model: collectModel() });
|
|
1790
2123
|
return true;
|
|
1791
2124
|
},
|
|
1792
2125
|
refreshAfterConflict(): boolean {
|
|
2126
|
+
// 提交处理中:不响应(等结果回来再说)
|
|
2127
|
+
if (isBusy()) return true;
|
|
1793
2128
|
// 编辑详情取数失败:重试就是重新取详情(不通知外层刷新)
|
|
1794
2129
|
if (detailState === 'failed') {
|
|
1795
2130
|
startDetail();
|
|
1796
2131
|
repaint();
|
|
1797
2132
|
return true;
|
|
1798
2133
|
}
|
|
1799
|
-
|
|
2134
|
+
// 刷新按钮持焦点:冲突清除后提示条隐藏,重绘后把焦点放到首个可用字段(无 DOM 环境跳过)
|
|
2135
|
+
const host = api.host;
|
|
2136
|
+
const doc = host?.ownerDocument;
|
|
2137
|
+
const wrap = host?.querySelector?.<HTMLElement>('[data-soma-id="refresh_wrap"]');
|
|
2138
|
+
if (conflict && doc && wrap && wrap.contains(doc.activeElement)) armRefreshFocus(doc);
|
|
2139
|
+
// 来源 A(表单自己配置了详情来源)的写入冲突:表单内部重新取详情,取回后 startDetail 重建草稿(放弃当前修改);
|
|
2140
|
+
// 先收起冲突提示,取详情期间由「取数中」占位;仍抛 reload 供外层刷新列表。来源 B(宿主下传 initial)由外层换行:
|
|
2141
|
+
// 编辑模式放弃本地修改、按当前 initial 重建草稿(保留页签 / 折叠 / 选项缓存),重取后 initial 变化时 syncDraft 再按最新数据重建;
|
|
2142
|
+
// 新建模式只收起冲突提示,不丢用户输入;最后照旧抛 reload
|
|
2143
|
+
if (conflict && detailOf() !== null && mode() === 'edit') {
|
|
2144
|
+
conflict = false;
|
|
2145
|
+
notice = '';
|
|
2146
|
+
startDetail();
|
|
2147
|
+
repaint();
|
|
2148
|
+
} else if (conflict && mode() === 'edit') {
|
|
2149
|
+
rebuildDraft();
|
|
2150
|
+
syncDirtyEmit();
|
|
2151
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
2152
|
+
repaint();
|
|
2153
|
+
} else if (conflict && mode() !== 'filter') {
|
|
2154
|
+
conflict = false;
|
|
2155
|
+
notice = '';
|
|
2156
|
+
repaint();
|
|
2157
|
+
}
|
|
2158
|
+
api.emit('reload', { object: objectName(), scope: scopeKey() });
|
|
1800
2159
|
return true;
|
|
1801
2160
|
},
|
|
1802
2161
|
|
|
1803
|
-
|
|
2162
|
+
busyAware: true,
|
|
2163
|
+
attach(root: HTMLElement) {
|
|
1804
2164
|
alive = true;
|
|
1805
2165
|
syncDraft();
|
|
1806
|
-
//
|
|
2166
|
+
// 草稿读口登记(具名动作的 draft 读口):筛选表单不登记;草稿仍是本表单自己的 draft,登记的只是读口
|
|
1807
2167
|
draftHandle?.dispose();
|
|
1808
2168
|
draftHandle = undefined;
|
|
1809
|
-
|
|
1810
|
-
draftHandle = registerKitFormDraft({
|
|
1811
|
-
get scope(): string { return scopeKey(); },
|
|
1812
|
-
get object(): string { return objectName(); },
|
|
1813
|
-
get mode(): 'create' | 'edit' { return mode() === 'edit' ? 'edit' : 'create'; },
|
|
1814
|
-
host: ctx.host ?? null,
|
|
1815
|
-
values: () => ({ ...draft.values() }),
|
|
1816
|
-
dirty: () => draft.isDirty(),
|
|
1817
|
-
ready: () => !detailBlocked(),
|
|
1818
|
-
// 采纳建议回填草稿(登记表的 patch 口):只写此刻可回填的字段(可见、可编辑、未禁用),与草稿相同的值不动;只改草稿,不提交
|
|
1819
|
-
patch: (values) => {
|
|
1820
|
-
syncDraft();
|
|
1821
|
-
const writable = adoptWritable();
|
|
1822
|
-
const changes: Rec = {};
|
|
1823
|
-
for (const [k, v] of Object.entries(values)) if (writable.has(k) && !sameValue(draft.get(k), v)) changes[k] = v;
|
|
1824
|
-
if (Object.keys(changes).length === 0) return false;
|
|
1825
|
-
applyAdopted(changes);
|
|
1826
|
-
draftHandle?.touch();
|
|
1827
|
-
return true;
|
|
1828
|
-
},
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
2169
|
+
syncDraftRegistration();
|
|
1831
2170
|
syncOutcomes();
|
|
1832
2171
|
const port = dataPort();
|
|
1833
2172
|
if (port?.onWriteOutcome) unsubOutcome = port.onWriteOutcome(onOutcome);
|
|
1834
2173
|
unsubBusy?.();
|
|
1835
2174
|
unsubBusy = onKitActionBusy(() => { if (alive) repaint(); });
|
|
1836
|
-
|
|
1837
|
-
offOptionsBus?.();
|
|
1838
|
-
offOptionsBus = onKitOptionsInvalidate((from) => {
|
|
1839
|
-
if (!alive) return;
|
|
1840
|
-
let hit = false;
|
|
1841
|
-
for (const c of cells()) {
|
|
1842
|
-
if (c.optionsFrom?.from !== from) continue;
|
|
1843
|
-
const st = remote.get(c.field);
|
|
1844
|
-
if (st !== undefined) st.key = '';
|
|
1845
|
-
hit = true;
|
|
1846
|
-
}
|
|
1847
|
-
if (hit) ensureOptions();
|
|
1848
|
-
});
|
|
1849
|
-
const form = ctx.host?.querySelector?.('form') ?? null;
|
|
2175
|
+
const form = api.host?.querySelector?.('form') ?? null;
|
|
1850
2176
|
if (form) {
|
|
1851
2177
|
const onSubmit = (event: Event): void => {
|
|
1852
2178
|
event.preventDefault();
|
|
@@ -1865,34 +2191,87 @@ function createController(
|
|
|
1865
2191
|
const id = btn?.getAttribute('data-kit-group') ?? '';
|
|
1866
2192
|
if (btn && id !== '') toggleGroup(id);
|
|
1867
2193
|
};
|
|
1868
|
-
//
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2194
|
+
// 页签模式:点击 / 方向键 / Home / End 都走共享页签接线(wireKitTablist),选中变化时切当前组并重画;
|
|
2195
|
+
// 键盘选中后页签行可能被 core 重画,焦点原在页签上的话重画后补回
|
|
2196
|
+
const tabbar = form.querySelector<HTMLElement>('[data-soma-id="tabbar"]');
|
|
2197
|
+
if (tabbar) {
|
|
2198
|
+
tabsHandle = wireKitTablist(tabbar, {
|
|
2199
|
+
tabs: () => Array.from(tabbar.querySelectorAll<HTMLElement>('[data-kit-group-tab]')),
|
|
2200
|
+
idOf: (tab) => tab.getAttribute('data-kit-group') ?? '',
|
|
2201
|
+
selected: activeTab,
|
|
2202
|
+
onSelect: (id, tab) => {
|
|
2203
|
+
if (id === '' || id === activeTab) return;
|
|
2204
|
+
const hadFocus = tab.ownerDocument.activeElement === tab;
|
|
2205
|
+
activeTab = id;
|
|
2206
|
+
repaint();
|
|
2207
|
+
if (hadFocus) {
|
|
2208
|
+
queueMicrotask(() => {
|
|
2209
|
+
if (!alive) return;
|
|
2210
|
+
const again = Array.from(tabbar.querySelectorAll<HTMLElement>('[data-kit-group-tab]')).find((t) => t.getAttribute('data-kit-group') === id);
|
|
2211
|
+
if (again && again.ownerDocument.activeElement !== again) again.focus({ preventScroll: true });
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
},
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
// 首次失焦后校验(focusout / blur),已出错或已触碰字段在 input / change 时即时复校
|
|
2218
|
+
const resolveFieldFromEvent = (event: Event): { name: string; el: HTMLElement } | null => {
|
|
2219
|
+
const rows = buildRows();
|
|
2220
|
+
const byId = new Map(rows.map((r) => [r.id, r.name] as const));
|
|
2221
|
+
const knownNames = new Set(rows.map((r) => r.name));
|
|
2222
|
+
for (let el = event.target as HTMLElement | null; el && el !== form; el = el.parentElement) {
|
|
2223
|
+
const byIdName = byId.get(el.id);
|
|
2224
|
+
if (byIdName !== undefined) return { name: byIdName, el };
|
|
2225
|
+
const attrName = el.getAttribute('name') ?? el.getAttribute('data-field') ?? el.getAttribute('data-kit-field') ?? '';
|
|
2226
|
+
if (attrName !== '' && knownNames.has(attrName)) return { name: attrName, el };
|
|
2227
|
+
}
|
|
2228
|
+
return null;
|
|
1873
2229
|
};
|
|
1874
|
-
// validate_on: blur:失焦字段(控件或其内部元素的 id 对得上行 id)即时校验
|
|
1875
2230
|
const onFocusOut = (event: Event): void => {
|
|
1876
|
-
if (
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
2231
|
+
if (mode() === 'filter') return;
|
|
2232
|
+
const hit = resolveFieldFromEvent(event);
|
|
2233
|
+
if (!hit) return;
|
|
2234
|
+
if ('value' in hit.el && typeof (hit.el as HTMLInputElement).value === 'string' && draft.get(hit.name) === undefined && (hit.el as HTMLInputElement).value !== '') {
|
|
2235
|
+
draft.set(hit.name, (hit.el as HTMLInputElement).value);
|
|
2236
|
+
}
|
|
2237
|
+
touchedFields.add(hit.name);
|
|
2238
|
+
instantValidate('blur', hit.name);
|
|
2239
|
+
repaint();
|
|
2240
|
+
};
|
|
2241
|
+
const onDomFieldInput = (event: Event): void => {
|
|
2242
|
+
if (mode() === 'filter') return;
|
|
2243
|
+
const hit = resolveFieldFromEvent(event);
|
|
2244
|
+
if (!hit) return;
|
|
2245
|
+
if ('value' in hit.el && typeof (hit.el as HTMLInputElement).value === 'string') {
|
|
2246
|
+
draft.set(hit.name, (hit.el as HTMLInputElement).value);
|
|
2247
|
+
}
|
|
2248
|
+
if (invalidFields.has(hit.name) || touchedFields.has(hit.name) || stringList(P().validateOn).includes('change')) {
|
|
2249
|
+
instantValidate('change', hit.name);
|
|
2250
|
+
repaint();
|
|
2251
|
+
} else {
|
|
2252
|
+
syncInvalid();
|
|
1881
2253
|
}
|
|
1882
2254
|
};
|
|
1883
2255
|
form.addEventListener('submit', onSubmit);
|
|
1884
2256
|
form.addEventListener('keydown', onKeydown as EventListener);
|
|
1885
2257
|
form.addEventListener('click', onGroupClick);
|
|
1886
|
-
form.addEventListener('click', onTabClick);
|
|
1887
2258
|
form.addEventListener('focusout', onFocusOut);
|
|
2259
|
+
form.addEventListener('blur', onFocusOut, true);
|
|
2260
|
+
form.addEventListener('input', onDomFieldInput);
|
|
2261
|
+
form.addEventListener('change', onDomFieldInput);
|
|
1888
2262
|
cleanupDom = () => {
|
|
1889
2263
|
form.removeEventListener('submit', onSubmit);
|
|
1890
2264
|
form.removeEventListener('keydown', onKeydown as EventListener);
|
|
1891
2265
|
form.removeEventListener('click', onGroupClick);
|
|
1892
|
-
|
|
2266
|
+
tabsHandle?.destroy();
|
|
2267
|
+
tabsHandle = undefined;
|
|
1893
2268
|
form.removeEventListener('focusout', onFocusOut);
|
|
2269
|
+
form.removeEventListener('blur', onFocusOut, true);
|
|
2270
|
+
form.removeEventListener('input', onDomFieldInput);
|
|
2271
|
+
form.removeEventListener('change', onDomFieldInput);
|
|
1894
2272
|
};
|
|
1895
2273
|
}
|
|
2274
|
+
syncInvalid();
|
|
1896
2275
|
// 离开守卫:草稿有改动时拦截刷新 / 关闭(beforeunload)与站内链接点击
|
|
1897
2276
|
offGuard?.();
|
|
1898
2277
|
offGuard = undefined;
|
|
@@ -1911,8 +2290,9 @@ function createController(
|
|
|
1911
2290
|
if (!a || a.target === '_blank') return;
|
|
1912
2291
|
event.preventDefault();
|
|
1913
2292
|
event.stopImmediatePropagation();
|
|
1914
|
-
void askKitConfirm({ message: FL.behaviorPassthrough.leaveGuard.confirmText, tone: 'danger', at:
|
|
2293
|
+
void askKitConfirm({ message: FL.behaviorPassthrough.leaveGuard.confirmText, tone: 'danger', at: api.host ?? null }).then((ok) => {
|
|
1915
2294
|
if (!ok || !alive) return;
|
|
2295
|
+
resetForm();
|
|
1916
2296
|
leaveApproved = true;
|
|
1917
2297
|
try { a.click(); } finally { leaveApproved = false; }
|
|
1918
2298
|
});
|
|
@@ -1924,34 +2304,42 @@ function createController(
|
|
|
1924
2304
|
document.removeEventListener('click', onLinkClick, true);
|
|
1925
2305
|
};
|
|
1926
2306
|
}
|
|
2307
|
+
return () => {
|
|
2308
|
+
// 销毁后实例的 emit 会被丢弃,不在此补报;协调组件靠新实例挂载后的首次 busy_change 复位
|
|
2309
|
+
busyReported = undefined;
|
|
2310
|
+
dirtyReported = undefined;
|
|
2311
|
+
alive = false;
|
|
2312
|
+
resetFocusRestore();
|
|
2313
|
+
disarmRefreshFocus();
|
|
2314
|
+
detailSeq += 1;
|
|
2315
|
+
draftHandle?.dispose();
|
|
2316
|
+
draftHandle = undefined;
|
|
2317
|
+
for (const off of offOutcomes) off();
|
|
2318
|
+
offOutcomes = [];
|
|
2319
|
+
outcomes.clear();
|
|
2320
|
+
outcomeSig = '';
|
|
2321
|
+
if (unsubOutcome) unsubOutcome();
|
|
2322
|
+
unsubOutcome = undefined;
|
|
2323
|
+
unsubBusy?.();
|
|
2324
|
+
unsubBusy = undefined;
|
|
2325
|
+
if (cleanupDom) cleanupDom();
|
|
2326
|
+
cleanupDom = undefined;
|
|
2327
|
+
offGuard?.();
|
|
2328
|
+
offGuard = undefined;
|
|
2329
|
+
if (debounceTimer !== undefined) clearTimeout(debounceTimer);
|
|
2330
|
+
debounceTimer = undefined;
|
|
2331
|
+
};
|
|
1927
2332
|
},
|
|
1928
|
-
|
|
2333
|
+
render(root: HTMLElement) {
|
|
1929
2334
|
syncDraft();
|
|
1930
2335
|
syncOutcomes();
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
offOutcomes = [];
|
|
1939
|
-
outcomes.clear();
|
|
1940
|
-
outcomeSig = '';
|
|
1941
|
-
if (unsubOutcome) unsubOutcome();
|
|
1942
|
-
unsubOutcome = undefined;
|
|
1943
|
-
unsubBusy?.();
|
|
1944
|
-
unsubBusy = undefined;
|
|
1945
|
-
if (cleanupDom) cleanupDom();
|
|
1946
|
-
cleanupDom = undefined;
|
|
1947
|
-
offGuard?.();
|
|
1948
|
-
offGuard = undefined;
|
|
1949
|
-
if (debounceTimer !== undefined) clearTimeout(debounceTimer);
|
|
1950
|
-
debounceTimer = undefined;
|
|
1951
|
-
for (const t of changeTimers.values()) clearTimeout(t);
|
|
1952
|
-
changeTimers.clear();
|
|
1953
|
-
offOptionsBus?.();
|
|
1954
|
-
offOptionsBus = undefined;
|
|
2336
|
+
syncInvalid();
|
|
2337
|
+
syncDraftRegistration();
|
|
2338
|
+
syncTabsDom();
|
|
2339
|
+
queueMicrotask(() => { if (alive) syncTabsDom(); });
|
|
2340
|
+
// 宿主直接改 busy 属性只触发 render(不经 repaint):异步补报 busy_change(不在渲染读口里重入;syncBusyEmit 按与上次报出值比较去重)
|
|
2341
|
+
// 草稿被宿主换行 / 重建(syncDraft)后脏状态可能变化,同样异步补报
|
|
2342
|
+
if (isBusy() !== busyReported || draft.isDirty() !== dirtyReported) queueMicrotask(() => { if (alive) { syncBusyEmit(); syncDirtyEmit(); } });
|
|
1955
2343
|
},
|
|
1956
2344
|
};
|
|
1957
2345
|
|