soma-kit 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/data/object-form.ts
CHANGED
|
@@ -16,33 +16,40 @@
|
|
|
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, KIT_INVALID_MARK, 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
|
-
import { KIT_CLASS_DEFAULTS, KIT_GRAMMAR, KIT_GROUP_MARKERS, KIT_REQUIRED_STAR_CLASS } from '../object-renderer/defaults';
|
|
28
|
+
import { KIT_CLASS_DEFAULTS, KIT_GRAMMAR, KIT_GROUP_MARKERS, KIT_REQUIRED_STAR_CLASS, KIT_WIDTH } from '../object-renderer/defaults';
|
|
29
|
+
import { kitRuleTableOf } from 'soma-foundation/kit-layout';
|
|
26
30
|
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
31
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
30
32
|
import { fetchRemoteOptionRows, rowsOfOptionsResponse } from './remote-options';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
+
import { getKitAppEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
34
|
+
import { flowOptionSlots, flowOptionsOfRows, withFlowOptions, type FlowOptionResolved, type FlowOptionSlot } from './flow-remote-options';
|
|
35
|
+
import { clearFlowNodeField, flowValueNodes, withColumnOptions } from './flow-node-options';
|
|
33
36
|
import { asyncResultOf, outcomePanelData } from './async-result-panel';
|
|
34
37
|
import { TONE_SOFT } from './shape-util';
|
|
35
|
-
import { isKitOutcomeStale } from '../object-renderer/outcome-draft';
|
|
36
38
|
import { registerKitFormDraft, type KitFormDraftHandle } from './form-draft-registry';
|
|
37
39
|
import { readDetailResponse, resolveDetailParams, type KitFormDetail } from '../object-renderer/form-detail';
|
|
38
40
|
import { kitText } from '../i18n/kit-text';
|
|
39
41
|
import { askKitConfirm } from './confirm-dialog';
|
|
40
|
-
import { rowColumnsOf, validateInlineRows } from './row-editor';
|
|
42
|
+
import { rowColumnsOf, validateInlineRowCells, validateInlineRows, type KitRowCellError } from './row-editor';
|
|
41
43
|
import { mergeClass } from '../object-renderer/merge-class';
|
|
42
|
-
import {
|
|
43
|
-
import { kitActionExtras } from '../biz/shared/runtime-hub';
|
|
44
|
-
import { onKitOptionsInvalidate } from './options-bus';
|
|
44
|
+
import { resolveDefaults as resolveFieldDefaults } from '../object-renderer/field-value';
|
|
45
45
|
import type { KitCell } from '../object-renderer/types';
|
|
46
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
47
|
+
import { KIT_STATE_LOADING_BOX, kitRetryRecipe } from '../recipes/placeholder';
|
|
48
|
+
import { kitHelpTriggerRecipe } from '../recipes';
|
|
49
|
+
import {
|
|
50
|
+
KIT_OVERLAY_FOOT_ATTR, KIT_OVERLAY_FORM_FOOTER_CLASS, KIT_OVERLAY_FORM_HOST_CLASS, KIT_OVERLAY_FORM_SCROLL_ATTR, kitOverlayFormScrollClass,
|
|
51
|
+
} from '../recipes/overlay';
|
|
52
|
+
import { kitIconHtml } from '../base/icons';
|
|
46
53
|
|
|
47
54
|
// M 波 G3:表单布局 / 筛选折叠 / 页签 / 离开守卫的类串与文案,全部读真源 formLinkage
|
|
48
55
|
const FL = KIT_GRAMMAR.formLinkage as {
|
|
@@ -53,29 +60,46 @@ const FL = KIT_GRAMMAR.formLinkage as {
|
|
|
53
60
|
optionsFrom: { rowsPathCandidates: string[] };
|
|
54
61
|
};
|
|
55
62
|
const FORM_BODY_CLASS = FL.formLayout.bodyClass;
|
|
63
|
+
/** 流式筛选:字段间距(rem,取布局规则表 filter.gapRem)与比较余量 */
|
|
64
|
+
const KIT_FILTER_FLOW_GAP_REM = kitRuleTableOf().filter.gapRem;
|
|
65
|
+
const FLOW_EPS = 0.01;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 流式筛选里一个字段格在宿主宽 hostRem(rem)下的占宽:类串里 `@<档>:w-N`(N 是 0.25rem 的个数)在宿主宽达到该档下界时生效(取最大的已达档),
|
|
69
|
+
* 都没到就是 `w-full`(占满整行 = hostRem)。纯函数,档下界读 design 容器档。
|
|
70
|
+
*/
|
|
71
|
+
export function flowCellRem(cellClass: string, hostRem: number): number {
|
|
72
|
+
let best: { tierRem: number; rem: number } | null = null;
|
|
73
|
+
for (const t of cellClass.split(/\s+/)) {
|
|
74
|
+
const m = /^@([a-z0-9]+):w-(\d+)$/.exec(t);
|
|
75
|
+
if (m === null) continue;
|
|
76
|
+
const tierRem = KIT_WIDTH.tierRem[m[1]!];
|
|
77
|
+
if (tierRem === undefined || hostRem < tierRem) continue;
|
|
78
|
+
if (best === null || tierRem > best.tierRem) best = { tierRem, rem: Number(m[2]) / 4 };
|
|
79
|
+
}
|
|
80
|
+
return best === null ? hostRem : Math.min(best.rem, hostRem);
|
|
81
|
+
}
|
|
82
|
+
// 选项加载失败的重试钮:全 kit 唯一的重试配方;self-start 让它靠字段左缘(不居中、不撑满),紧挨失败提示
|
|
83
|
+
const OPTIONS_RETRY_CLASS = mergeClass(kitRetryRecipe('neutral'), 'self-start');
|
|
56
84
|
|
|
57
85
|
// ── 默认类(语义色名 + 小闭集尺度) ──
|
|
58
86
|
|
|
59
87
|
export const KIT_FORM_CLASS = {
|
|
60
|
-
wrap:
|
|
88
|
+
wrap: `@container ${KIT_OVERLAY_FORM_HOST_CLASS}`,
|
|
61
89
|
grid: 'grid grid-cols-12 gap-4',
|
|
62
|
-
|
|
90
|
+
// 在对话框 / 抽屉里(祖先 group + data-kit-overlay-scroll)底栏是滚动区之外的 shrink-0 兄弟:内容区滚动、按钮栏固定在浮层底部(U1c)
|
|
91
|
+
actions: `mt-4 flex flex-wrap items-end justify-end gap-2 ${KIT_OVERLAY_FORM_FOOTER_CLASS}`,
|
|
63
92
|
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
93
|
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',
|
|
94
|
+
/** 阶段闸门原因 */
|
|
71
95
|
/** 请求结果常驻槽(view.form.result):外框 + 随状态换的语气底色(TONE_SOFT) */
|
|
72
96
|
resultBox: 'mb-4 flex flex-col gap-1 rounded-md px-3 py-2 text-sm',
|
|
73
97
|
resultTitle: 'font-medium',
|
|
74
98
|
resultText: 'text-sm',
|
|
75
99
|
/** 编辑详情取数中的占位块(取回前字段与按钮都不画) */
|
|
76
|
-
detailState:
|
|
100
|
+
detailState: KIT_STATE_LOADING_BOX,
|
|
77
101
|
cell: 'flex flex-col gap-1',
|
|
78
|
-
label: 'text-
|
|
102
|
+
label: 'text-xs font-normal text-fg',
|
|
79
103
|
error: 'text-xs text-danger-on-soft',
|
|
80
104
|
errorHidden: 'hidden',
|
|
81
105
|
/** 字段说明文字(fields[].help),控件下、错误行上;无 help 时 hidden */
|
|
@@ -89,17 +113,20 @@ export const KIT_FORM_CLASS = {
|
|
|
89
113
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
90
114
|
export const KIT_FORM_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
91
115
|
'@container', 'grid', 'grid-cols-12', 'gap-4',
|
|
92
|
-
|
|
116
|
+
...[KIT_FORM_CLASS.wrap, KIT_OVERLAY_FORM_HOST_CLASS, kitOverlayFormScrollClass()].flatMap((s) => s.split(/\s+/)),
|
|
117
|
+
'mt-4', 'flex', 'flex-wrap', 'items-end', 'gap-2', 'contents',
|
|
118
|
+
...KIT_FORM_CLASS.actions.split(/\s+/).filter((c) => c !== ''),
|
|
93
119
|
'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
120
|
'hidden', 'flex-col', 'gap-1', 'font-medium', 'text-fg', 'text-xs', 'text-fg-muted', 'col-span-6', '@md:col-span-3',
|
|
95
121
|
...[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.
|
|
122
|
+
...[KIT_FORM_CLASS.detailState].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
97
123
|
...Object.values(KIT_REQUIRED_STAR_CLASS).flatMap((s) => s.split(/\s+/)),
|
|
98
124
|
...[KIT_CLASS_DEFAULTS.groupTitle, KIT_CLASS_DEFAULTS.groupToggle, KIT_CLASS_DEFAULTS.groupMark].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
99
125
|
...[
|
|
100
126
|
FORM_BODY_CLASS, ...FL.formLayout.labelWidthClasses, ...Object.values(FL.formLayout.cellClass), ...Object.values(FL.formLayout.labelClass),
|
|
101
127
|
FL.filterOptions.badgeClass, FL.filterOptions.toggleWrapClass, FL.groupsAs.barClass, FL.groupsAs.tabClass,
|
|
102
128
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
|
|
129
|
+
...OPTIONS_RETRY_CLASS.split(/\s+/),
|
|
103
130
|
]);
|
|
104
131
|
|
|
105
132
|
// ── 对外形状与数据规整纯函数 ──
|
|
@@ -113,6 +140,8 @@ export interface KitObjectFormClasses {
|
|
|
113
140
|
grid?: string;
|
|
114
141
|
/** 按钮行类 */
|
|
115
142
|
actions?: string;
|
|
143
|
+
/** 按钮行顶部「标签行占位」的显隐类(与字段标签同一类、不可见);缺省隐藏。筛选流式版式靠它让按钮与输入框同一结构对齐 */
|
|
144
|
+
pad?: string;
|
|
116
145
|
/** 顶部提示条类(失败 / 冲突) */
|
|
117
146
|
notice?: string;
|
|
118
147
|
}
|
|
@@ -145,6 +174,8 @@ export interface KitObjectFormProps {
|
|
|
145
174
|
collapsible?: boolean;
|
|
146
175
|
collapsedRows?: number;
|
|
147
176
|
trigger?: 'submit' | 'change';
|
|
177
|
+
/** filter 的流式版式(定宽字段 + 紧跟的按钮):折起哪些字段按宿主宽度逐行现算,而不是 12 份栅格的份数 */
|
|
178
|
+
flow?: boolean;
|
|
148
179
|
/** form.groups 画成页签 */
|
|
149
180
|
groupTabs?: boolean;
|
|
150
181
|
/** write.validate_on:change / blur 时即时校验 */
|
|
@@ -153,22 +184,23 @@ export interface KitObjectFormProps {
|
|
|
153
184
|
leaveGuard?: boolean;
|
|
154
185
|
/** 编辑详情:mode 为 edit 时先按行取详情再作初值(behavior.detail 编来;见 object-renderer/form-detail.ts) */
|
|
155
186
|
detail?: KitFormDetail;
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
|
|
187
|
+
/** 本页有效的业务信封(编译期按页面 > 应用解析后传入;缺省 / 空对象 = 未声明,运行时退回宿主查找) */
|
|
188
|
+
envelope?: KitEnvelope;
|
|
189
|
+
/** 底栏动作(view.form.footerActions 编来):点击抛槽位事件 footer_action_<序号> { id },页面事件给每个 request / download 动作各绑一条管道 */
|
|
190
|
+
footerActions?: Array<{ id: string; label: string }>;
|
|
191
|
+
/** 展示对象给出的底栏动作状态 { 动作id: { disabled?, hidden? } }(叶子由页面路径绑定求值成布尔):disabled 置灰且点不到,hidden 不画 */
|
|
192
|
+
footerState?: Record<string, { disabled?: boolean | string; hidden?: boolean | string }>;
|
|
160
193
|
/** 请求结果常驻槽(view.form.result):outcome 是 request 动作 into */
|
|
161
|
-
result?: { outcome: string; title?: string };
|
|
162
|
-
/** 采纳建议:某 request 动作 into 的结果返回建议值,点「采纳」才写进草稿(不提交) */
|
|
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 }:只在新建时填「空且没改过」的字段 */
|
|
194
|
+
result?: { outcome: string; title?: string }; /** GB2 字段初值 { 字段: 字面量 }:只在新建时填「空且没改过」的字段 */
|
|
169
195
|
defaults?: Record<string, unknown>;
|
|
170
196
|
/** GB3 隐藏草稿字段:随草稿提交、不画;仍按字典 rules 校验,permission: create 的在编辑态不提交 */
|
|
171
197
|
hiddenFields?: string[];
|
|
198
|
+
/** 展示对象给出的字段状态 { 字段: { hidden / disabled / required } }(叶子由页面路径绑定求值成布尔):hidden 不画但值保留并随草稿提交,disabled 置灰,required 标星并在提交 / 即时校验里要求非空 */
|
|
199
|
+
/** 展示对象给出的提交闸门(路径已由 core 求成布尔):为真时禁用提交按钮,字段仍可编辑 */
|
|
200
|
+
submitDisabled?: boolean | string;
|
|
201
|
+
fieldState?: Record<string, { hidden?: boolean | string; disabled?: boolean | string; required?: boolean | string; /** 展示对象给出的候选项来源(view.<成员>,core 求成数组 [{ value, label }]):给了就替换该字段的静态 / 远程候选,不再自取 options.from */ options?: unknown; nodeOptions?: unknown; columnOptions?: unknown; /** 展示对象持有的画布 AI 建议(view.<成员>,core 求成数组 [{ id, label, reason?, nodes, edges }]) */ suggestions?: unknown }>;
|
|
202
|
+
/** 页面把草稿变化接给了展示对象方法(view.form.onDraft):草稿首次建好时补发一次 draft_change,让展示对象状态与空草稿对齐 */
|
|
203
|
+
draftNotify?: boolean;
|
|
172
204
|
}
|
|
173
205
|
|
|
174
206
|
const DEFAULT_SUBMIT_LABEL = 'soma.kit.submit';
|
|
@@ -205,8 +237,15 @@ function cellsOf(raw: unknown): KitCell[] {
|
|
|
205
237
|
return Array.isArray(raw) ? raw.filter((c): c is KitCell => isRec(c) && typeof c.field === 'string') : [];
|
|
206
238
|
}
|
|
207
239
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
240
|
+
/** 页签条的一枚页签(独立 tablist 条里的行,不再混在字段栅格里) */
|
|
241
|
+
export interface KitFormTabRow {
|
|
242
|
+
id: string;
|
|
243
|
+
label: string;
|
|
244
|
+
groupId: string;
|
|
245
|
+
/** aria-selected 取值 'true' | 'false' */
|
|
246
|
+
selected: string;
|
|
247
|
+
tabClass: string;
|
|
248
|
+
}
|
|
210
249
|
|
|
211
250
|
/** 一行字段的行变量(行模板按 `f.*` 读,不含函数) */
|
|
212
251
|
export interface KitFormRow {
|
|
@@ -221,6 +260,10 @@ export interface KitFormRow {
|
|
|
221
260
|
/** 字段说明文字与其类(无说明 = '' / hidden) */
|
|
222
261
|
help: string;
|
|
223
262
|
helpClass: string;
|
|
263
|
+
/** 只读行的说明气泡钮(标签尾):说明文字 / 读屏名 / 类(无说明 = '' / hidden);可编辑行用上面的说明行 */
|
|
264
|
+
helpTip?: string;
|
|
265
|
+
helpTipLabel?: string;
|
|
266
|
+
helpTipClass?: string;
|
|
224
267
|
/** 兜底行模板显示的文字 */
|
|
225
268
|
text: string;
|
|
226
269
|
/** 传给基础组件的全部 props(契约默认值 + IR props + 草稿值) */
|
|
@@ -233,17 +276,21 @@ export interface KitFormRow {
|
|
|
233
276
|
groupToggleClass: string;
|
|
234
277
|
/** 控件 + 说明 + 错误行的包裹类(标签在左时与标签并排) */
|
|
235
278
|
bodyClass: string;
|
|
236
|
-
/**
|
|
237
|
-
|
|
238
|
-
|
|
279
|
+
/** 远程选项失败时的显式单字段重试按钮 */
|
|
280
|
+
optionsRetry?: boolean;
|
|
281
|
+
optionsRetryClass?: string;
|
|
282
|
+
optionsRetryText?: string;
|
|
239
283
|
/** 必填星号(红色子元素,不并入标签文本):文字与类;不必填时文字为空、类为 hidden */
|
|
240
284
|
starStart?: string;
|
|
241
285
|
starStartClass?: string;
|
|
242
286
|
starEnd?: string;
|
|
243
287
|
starEndClass?: string;
|
|
244
|
-
/**
|
|
245
|
-
|
|
246
|
-
|
|
288
|
+
/** 标签 / 说明 / 错误节点的稳定 id(表单实例前缀 + 字段名 + 后缀):控件的 aria-labelledby / aria-describedby 指向它们 */
|
|
289
|
+
labelId?: string;
|
|
290
|
+
helpNodeId?: string;
|
|
291
|
+
errNodeId?: string;
|
|
292
|
+
/** 标签 `for` 指向的控件 id;组控件(单选组 / 多选组)与非原生可标注控件不指(点标签聚焦由表单接线负责) */
|
|
293
|
+
labelFor?: string;
|
|
247
294
|
}
|
|
248
295
|
|
|
249
296
|
// ── 级联(Cascader)选项树 ──
|
|
@@ -291,6 +338,28 @@ export function cascadeOptions(
|
|
|
291
338
|
|
|
292
339
|
const FALLBACK_ROLE = '_default';
|
|
293
340
|
|
|
341
|
+
const FIELD_FOCUSABLE = 'input:not([type="hidden"]):not([disabled]),textarea:not([disabled]),select:not([disabled]),button:not([disabled]),[contenteditable="true"],[tabindex]:not([tabindex="-1"])';
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 字段控件宿主 -> 真正接焦点的元素(点标签 / 滚到出错字段用):
|
|
345
|
+
* 单选 / 多选组里取已选项,否则第一项;宿主自己可聚焦(原生控件、tabindex、contenteditable)就是它;
|
|
346
|
+
* 否则取内部 roving 的 tabindex=0 项,再退到第一个可聚焦后代。
|
|
347
|
+
*/
|
|
348
|
+
export function fieldFocusTarget(host: HTMLElement): HTMLElement | null {
|
|
349
|
+
const isChoice = (el: Element): el is HTMLInputElement => el instanceof HTMLInputElement && (el.type === 'radio' || el.type === 'checkbox');
|
|
350
|
+
if (isChoice(host)) {
|
|
351
|
+
const group = host.closest<HTMLElement>('[role="radiogroup"],[role="group"]');
|
|
352
|
+
return group?.querySelector<HTMLElement>('input:checked:not([disabled])') ?? host;
|
|
353
|
+
}
|
|
354
|
+
if (host.matches('[role="radiogroup"],[role="group"]')) {
|
|
355
|
+
const inputs = Array.from(host.querySelectorAll<HTMLInputElement>('input[type="radio"]:not([disabled]),input[type="checkbox"]:not([disabled])'));
|
|
356
|
+
if (inputs.length > 0) return inputs.find((i) => i.checked) ?? inputs[0]!;
|
|
357
|
+
}
|
|
358
|
+
// 有 tabindex 属性(含 -1:程序化可聚焦,如行编辑根会把焦点转交给首个出错单元格)的宿主自己接焦点
|
|
359
|
+
if (host.matches(FIELD_FOCUSABLE) || host.hasAttribute('tabindex')) return host;
|
|
360
|
+
return host.querySelector<HTMLElement>('[tabindex="0"]') ?? host.querySelector<HTMLElement>(FIELD_FOCUSABLE);
|
|
361
|
+
}
|
|
362
|
+
|
|
294
363
|
function propDefaults(def: SomaComponentDefinition | undefined): Rec {
|
|
295
364
|
const out: Rec = {};
|
|
296
365
|
for (const [key, spec] of Object.entries(def?.contract.props ?? {})) {
|
|
@@ -306,7 +375,7 @@ function propDefaults(def: SomaComponentDefinition | undefined): Rec {
|
|
|
306
375
|
* @param registered 已登记的基础组件表(内置 13 个 + 应用 `App*`),名字 → 定义。
|
|
307
376
|
* 表里必须有 `Button`(按钮行用)与 `Text`(edit 模式下 create-only 字段画成只读)。
|
|
308
377
|
*/
|
|
309
|
-
export function createKitObjectForm(registered: Readonly<Record<string, SomaComponentDefinition>>): SomaComponentDefinition {
|
|
378
|
+
export function createKitObjectForm(registered: Readonly<Record<string, SomaComponentDefinition>> = {}): SomaComponentDefinition {
|
|
310
379
|
const names = Object.keys(registered);
|
|
311
380
|
const nameSet = new Set(names);
|
|
312
381
|
|
|
@@ -319,17 +388,20 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
319
388
|
+ `<span data-soma-id="lbls_${name}" class="hidden" aria-hidden="true"></span>`
|
|
320
389
|
+ `<span data-soma-id="lblt_${name}"></span>`
|
|
321
390
|
+ `<span data-soma-id="lble_${name}" class="hidden" aria-hidden="true"></span>`
|
|
322
|
-
|
|
391
|
+
// 只读行的字段说明(J9 / F-5):标签尾的「i」图标钮,随行变量绑定(无说明 = hidden,不位移);气泡由 base/hint-tips 的委托按需建
|
|
392
|
+
+ `<button type="button" data-soma-id="lblh_${name}" class="hidden">${kitIconHtml('info', 'sm')}</button>`
|
|
393
|
+
+ '</label>'
|
|
323
394
|
+ `<div data-soma-id="body_${name}" class="${FORM_BODY_CLASS}">`
|
|
324
395
|
+ `<div data-soma-component="${name}" data-soma-id="fld_${name}"></div>`
|
|
325
396
|
+ `<p data-soma-id="help_${name}" class="${KIT_FORM_CLASS.errorHidden}"></p>`
|
|
326
397
|
+ `<p data-soma-id="err_${name}" role="alert" class="${KIT_FORM_CLASS.errorHidden}"></p>`
|
|
398
|
+
+ `<button type="button" data-soma-id="options_retry_${name}" class="hidden"></button>`
|
|
327
399
|
+ '</div></div></template>').join('');
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
+ '<button type="button" data-soma-id="tab_btn" data-kit-group-tab="" aria-
|
|
332
|
-
+ '</div
|
|
400
|
+
// 页签条(form.groups + groupsAs: tabs):独立 role=tablist 容器,页签 role=tab + aria-selected;
|
|
401
|
+
// roving tabindex / 方向键 / aria-controls / 面板(字段栅格)关联由 wireKitTablist(共享页签接线)在 DOM 同步里补齐
|
|
402
|
+
const tabbarTemplate = `<div data-soma-id="tabbar" role="tablist" class="hidden"><template data-soma-role="item">`
|
|
403
|
+
+ '<button type="button" data-soma-id="tab_btn" data-kit-group-tab="" data-kit-face="tab" role="tab" aria-selected="false" tabindex="-1"></button>'
|
|
404
|
+
+ '</template></div>';
|
|
333
405
|
// 分组标题行(form.groups 平铺后的标题格):_group = 可折叠(h4 里的 button),_grouptitle = 不可折叠的纯标题
|
|
334
406
|
const groupTemplates = '<template data-soma-role="item:_group">'
|
|
335
407
|
+ '<div data-soma-id="cell__group">'
|
|
@@ -346,36 +418,34 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
346
418
|
+ '</div></template>';
|
|
347
419
|
|
|
348
420
|
const templateHtml = `<form data-soma-id="root" class="${KIT_FORM_CLASS.wrap}" novalidate>`
|
|
421
|
+
// 滚动区(底栏之外的全部内容):页面级 contents 不产生盒;浮层里是 flex-1 min-h-0 overflow-y-auto,底栏在它之外(shrink-0),不随内容滚动
|
|
422
|
+
+ `<div data-soma-id="scroll" ${KIT_OVERLAY_FORM_SCROLL_ATTR}="" class="${kitOverlayFormScrollClass()}">`
|
|
349
423
|
+ `<div data-soma-id="notice" role="alert" class="${KIT_FORM_CLASS.noticeHidden}">`
|
|
350
424
|
+ '<span data-soma-id="notice_text"></span>'
|
|
351
425
|
+ '<span data-soma-id="refresh_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_refresh"></div></span>'
|
|
352
426
|
+ '</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
427
|
// 编辑详情取数中:处理中状态块(取数失败走上面的 notice + 重试钮)
|
|
361
428
|
+ `<div data-soma-id="detail_state" role="status" class="${KIT_FORM_CLASS.noticeHidden}"></div>`
|
|
362
|
-
+
|
|
429
|
+
+ tabbarTemplate
|
|
430
|
+
+ `<div data-soma-id="grid" class="${KIT_FORM_CLASS.grid}">${itemTemplates}${groupTemplates}${fallbackTemplate}</div>`
|
|
363
431
|
// 请求结果常驻槽(view.form.result,GA3):进行中 / 失败 / 成功都留在表单里,不被弹窗遮罩盖住,也不止弹一次 toast
|
|
364
432
|
+ `<div data-soma-id="result_box" role="status" aria-live="polite" class="${KIT_FORM_CLASS.noticeHidden}">`
|
|
365
433
|
+ '<p data-soma-id="res_title"></p><p data-soma-id="res_text"></p>'
|
|
366
434
|
+ '<div data-soma-id="res_lines"><template data-soma-role="item"><p data-soma-id="rl_row"><span data-soma-id="rl_label"></span><span data-soma-id="rl_text"></span></p></template></div>'
|
|
367
435
|
+ '</div>'
|
|
368
|
-
+
|
|
436
|
+
+ '</div>'
|
|
437
|
+
+ `<div data-soma-id="actions" ${KIT_OVERLAY_FOOT_ATTR}="" class="${KIT_FORM_CLASS.actions}">`
|
|
438
|
+
// 标签行占位(筛选流式版式):与字段格同一「标签行 + 控件行」结构,按钮落在控件行,与输入框同一水平线;默认 hidden,不占位
|
|
439
|
+
+ '<span data-soma-id="actions_pad" class="hidden" aria-hidden="true"> </span>'
|
|
369
440
|
+ '<span data-soma-id="cancel_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_cancel"></div></span>'
|
|
370
441
|
+ '<div data-soma-component="Button" data-soma-id="kit_submit"></div>'
|
|
371
442
|
+ '<span data-soma-id="toggle_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_toggle"></div>'
|
|
372
443
|
+ '<span data-soma-id="badge" class="hidden"></span></span>'
|
|
373
444
|
+ '<span data-soma-id="reset_wrap" class="hidden"><div data-soma-component="Button" data-soma-id="kit_reset"></div></span>'
|
|
374
445
|
// 底栏动作(view.form.footerActions):每项一个按钮,点击抛 footer_action { id }
|
|
375
|
-
|
|
446
|
+
// extra 用 contents:空的行容器不参与 flex 排版,否则最后多出一个零宽项 + gap-2,按钮组右缘比字段右缘内缩 8px(U1c)
|
|
447
|
+
+ '<span data-soma-id="extra" class="contents"><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
448
|
// 阶段闸门原因:提交被闸门拦住时常驻显示,不允许静默拦截
|
|
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
449
|
+ '</div>'
|
|
380
450
|
+ '</form>';
|
|
381
451
|
|
|
@@ -392,16 +462,22 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
392
462
|
[`lbls_${name}@class`]: 'f.starStartClass',
|
|
393
463
|
[`lble_${name}`]: 'f.starEnd',
|
|
394
464
|
[`lble_${name}@class`]: 'f.starEndClass',
|
|
395
|
-
[`
|
|
396
|
-
[`
|
|
397
|
-
[`
|
|
465
|
+
[`lblh_${name}@class`]: 'f.helpTipClass',
|
|
466
|
+
[`lblh_${name}@data-kit-help`]: 'f.helpTip',
|
|
467
|
+
[`lblh_${name}@aria-label`]: 'f.helpTipLabel',
|
|
468
|
+
[`lbl_${name}@for`]: 'f.labelFor',
|
|
469
|
+
[`lbl_${name}@id`]: 'f.labelId',
|
|
398
470
|
[`lbl_${name}@class`]: 'f.labelClass',
|
|
399
471
|
[`body_${name}@class`]: 'f.bodyClass',
|
|
400
472
|
[`fld_${name}`]: { props },
|
|
401
473
|
[`help_${name}`]: 'f.help',
|
|
474
|
+
[`help_${name}@id`]: 'f.helpNodeId',
|
|
402
475
|
[`help_${name}@class`]: 'f.helpClass',
|
|
476
|
+
[`err_${name}@id`]: 'f.errNodeId',
|
|
403
477
|
[`err_${name}`]: 'f.error',
|
|
404
478
|
[`err_${name}@class`]: 'f.errorClass',
|
|
479
|
+
[`options_retry_${name}`]: 'f.optionsRetryText',
|
|
480
|
+
[`options_retry_${name}@class`]: 'f.optionsRetryClass',
|
|
405
481
|
},
|
|
406
482
|
};
|
|
407
483
|
}
|
|
@@ -418,15 +494,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
418
494
|
grp_mark: 'f.groupMark',
|
|
419
495
|
},
|
|
420
496
|
};
|
|
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
497
|
groupShow['item:_grouptitle'] = {
|
|
431
498
|
show: {
|
|
432
499
|
'cell__grouptitle@class': 'f.cellClass',
|
|
@@ -445,6 +512,16 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
445
512
|
detail_state: 'ctrl.detailStateText',
|
|
446
513
|
'refresh_wrap@class': 'ctrl.refreshWrapClass',
|
|
447
514
|
kit_refresh: { when: 'ctrl.conflict', props: { label: 'ctrl.refreshLabel', variant: 'ctrl.neutralVariant', size: 'ctrl.smallSize' } },
|
|
515
|
+
'tabbar@class': 'ctrl.tabbarClass',
|
|
516
|
+
tabbar: {
|
|
517
|
+
bind: { obj: 'ctrl.tabRows', var: 't' },
|
|
518
|
+
show: {
|
|
519
|
+
tab_btn: 't.label',
|
|
520
|
+
'tab_btn@aria-selected': 't.selected',
|
|
521
|
+
'tab_btn@data-kit-group': 't.groupId',
|
|
522
|
+
'tab_btn@class': 't.tabClass',
|
|
523
|
+
},
|
|
524
|
+
},
|
|
448
525
|
'grid@class': 'ctrl.gridClass',
|
|
449
526
|
grid: {
|
|
450
527
|
bind: { obj: 'ctrl.rows', var: 'f', role_by: 'f.component' },
|
|
@@ -466,6 +543,7 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
466
543
|
show: { rl_label: 'rl.label', 'rl_label@class': 'rl.labelClass', rl_text: 'rl.text' },
|
|
467
544
|
},
|
|
468
545
|
'actions@class': 'ctrl.actionsClass',
|
|
546
|
+
'actions_pad@class': 'ctrl.actionsPadClass',
|
|
469
547
|
kit_submit: { props: { label: 'ctrl.submitText', variant: 'ctrl.primaryVariant', loading: 'ctrl.busy', disabled: 'ctrl.formDisabled' } },
|
|
470
548
|
'toggle_wrap@class': 'ctrl.toggleWrapClass',
|
|
471
549
|
kit_toggle: { when: 'ctrl.showToggle', props: { label: 'ctrl.toggleText', variant: 'ctrl.ghostVariant' } },
|
|
@@ -479,18 +557,6 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
479
557
|
bind: { obj: 'ctrl.footerRows', var: 'x' },
|
|
480
558
|
show: { xa_btn: { props: { label: 'x.label', variant: 'x.variant', disabled: 'x.disabled' } } },
|
|
481
559
|
},
|
|
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
560
|
},
|
|
495
561
|
} as unknown as SomaComponentDefinition['uiConfig'];
|
|
496
562
|
|
|
@@ -501,23 +567,27 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
501
567
|
const emitsOf = (name: string, ev: string): boolean => Boolean(registered[name]!.contract.emits && ev in (registered[name]!.contract.emits ?? {}));
|
|
502
568
|
const pickEvents = names.filter((n) => emitsOf(n, 'pick')).map((n) => ({ somaId: `fld_${n}`, domEvent: 'pick', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldPick' }));
|
|
503
569
|
const searchEvents = names.filter((n) => emitsOf(n, 'search')).map((n) => ({ somaId: `fld_${n}`, domEvent: 'search', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldSearch' }));
|
|
570
|
+
// 画布的 AI 建议采纳 / 忽略:交表单转成带 suggestion 载荷的 draft_change(页面只绑 view.form.onDraft,状态归展示对象)
|
|
571
|
+
const suggestionEvents = names.flatMap((n) => [
|
|
572
|
+
...(emitsOf(n, 'suggestion_accept') ? [{ somaId: `fld_${n}`, domEvent: 'suggestion_accept', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldSuggestionAccept' }] : []),
|
|
573
|
+
...(emitsOf(n, 'suggestion_reject') ? [{ somaId: `fld_${n}`, domEvent: 'suggestion_reject', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldSuggestionReject' }] : []),
|
|
574
|
+
]);
|
|
504
575
|
// 级联的懒加载(Cascader 抛 load)
|
|
505
576
|
const loadEvents = names.filter((n) => emitsOf(n, 'load')).map((n) => ({ somaId: `fld_${n}`, domEvent: 'load', type: 'UI_REFRESH', funcPath: 'ctrl.onFieldLoad' }));
|
|
577
|
+
const optionRetryEvents = names.map((n) => ({ somaId: `options_retry_${n}`, domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.retryOptions' }));
|
|
506
578
|
const eventConfig = [
|
|
507
579
|
...changeEvents,
|
|
508
580
|
...pickEvents,
|
|
509
581
|
...searchEvents,
|
|
582
|
+
...suggestionEvents,
|
|
510
583
|
...loadEvents,
|
|
584
|
+
...optionRetryEvents,
|
|
511
585
|
{ somaId: 'kit_submit', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.submitForm' },
|
|
512
586
|
{ somaId: 'kit_reset', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.resetForm' },
|
|
513
587
|
{ somaId: 'kit_toggle', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.toggleCollapsed' },
|
|
514
588
|
{ somaId: 'kit_cancel', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.cancelForm' },
|
|
515
589
|
{ somaId: 'xa_btn', domEvent: 'click', type: 'UI_REFRESH', funcPath: 'ctrl.onFooterAction' },
|
|
516
590
|
{ 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
591
|
] as unknown as SomaComponentDefinition['eventConfig'];
|
|
522
592
|
|
|
523
593
|
return {
|
|
@@ -531,16 +601,18 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
531
601
|
mode: { type: 'enum', values: ['create', 'edit', 'filter'], default: 'create', desc: '新建 / 编辑 / 筛选' },
|
|
532
602
|
fields: { type: 'array', default: [], desc: '编译器给出的字段格(KitCell[])' },
|
|
533
603
|
initial: { type: 'object', default: {}, desc: '初值:新建是默认值,编辑是整行' },
|
|
534
|
-
classes: { type: 'object', default: {}, desc: '编译器给出的容器类 { wrap, grid, actions, notice }' },
|
|
604
|
+
classes: { type: 'object', default: {}, desc: '编译器给出的容器类 { wrap, grid, actions, pad, notice }' },
|
|
605
|
+
flow: { type: 'boolean', default: false, desc: 'filter 流式版式:折叠按宿主宽度逐行现算折起的字段' },
|
|
535
606
|
createOnly: { type: 'array', default: [], desc: 'permission: create 的字段名:编辑时只读且不进 model' },
|
|
536
607
|
keys: { type: 'array', default: [], desc: 'key 字段名:编辑时必进 model' },
|
|
537
608
|
submitLabel: { type: 'string', default: '', desc: '提交按钮文字;缺省按 mode' },
|
|
538
609
|
resetLabel: { type: 'string', default: '', desc: '重置按钮文字' },
|
|
539
610
|
cancelLabel: { type: 'string', default: '', desc: '取消按钮文字;空则不显示取消' },
|
|
540
611
|
disabled: { type: 'boolean', default: false },
|
|
612
|
+
submitDisabled: { type: 'boolean', default: false, desc: '展示对象给出(view.form.submitDisabled: view.<成员>):为真时只禁用提交按钮并拦下回车提交,字段仍可编辑(与整表 disabled 不同);筛选表单不吃' },
|
|
541
613
|
labelPosition: { type: 'string', default: '', desc: '标签位置 left / right(缺省在控件上方)' },
|
|
542
614
|
labelWidth: { type: 'number', default: 3, desc: '标签宽度档 1~5(left / right 生效)' },
|
|
543
|
-
scrollToError: { type: 'boolean', default:
|
|
615
|
+
scrollToError: { type: 'boolean', default: true, desc: '校验失败后滚到首个出错字段并聚焦' },
|
|
544
616
|
requiredMark: { type: 'string', default: '', desc: '必填星号位置:start = 标签前,缺省在后' },
|
|
545
617
|
collapsible: { type: 'boolean', default: false, desc: 'filter:折叠搜索区' },
|
|
546
618
|
collapsedRows: { type: 'number', default: 1, desc: 'filter 折叠时保留的行数' },
|
|
@@ -550,13 +622,13 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
550
622
|
validateOn: { type: 'array', default: [], desc: 'change / blur 时即时校验' },
|
|
551
623
|
leaveGuard: { type: 'boolean', default: false, desc: '草稿有改动时拦截离开' },
|
|
552
624
|
footerActions: { type: 'array', default: [], desc: '底栏动作 [{ id, label }](view.form.footerActions 编来):在提交旁多画按钮,点击抛 footer_action' },
|
|
553
|
-
|
|
625
|
+
footerState: { type: 'object', default: {}, desc: '展示对象给出的底栏动作状态 { 动作id: { disabled, hidden } }(底栏动作写 disabled / hidden: view.<成员> 编来):disabled 为真置灰且点不到,hidden 为真不画;在途的可取消动作仍可点(点的是取消)' },
|
|
554
626
|
detail: { type: 'object', default: {}, desc: '编辑详情 { api, params?, unwrap? }:mode 为 edit 时先 GET 详情,成功后详情盖行作初值;取数中只显示处理中,失败照实报错并给重试、不渲染表单(behavior.detail 编来)' },
|
|
627
|
+
envelope: { type: 'object', default: {}, desc: '本页有效的业务信封(编译期按页面 > 应用解析后传入;空对象 = 未声明)' },
|
|
555
628
|
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 }:只在新建时填「空且用户没改过」的字段,取不到值就不填' },
|
|
629
|
+
defaults: { type: 'object', default: {}, desc: '字段初值 { 字段: 字面量 }:只在新建时填「空且用户没改过」的字段' },
|
|
630
|
+
fieldState: { type: 'object', default: {}, desc: '展示对象给出的字段状态 { 字段: { hidden, disabled, required, options } }:options 是展示对象给出的候选项数组(替换该字段候选,不再取 options.from);hidden 不画但值保留并随草稿提交;disabled 置灰;required 标星并要求非空(隐藏 / 置灰的字段不判必填)' },
|
|
631
|
+
draftNotify: { type: 'boolean', default: false, desc: '页面把草稿变化接给了展示对象方法:草稿首次建好时补发一次 draft_change' },
|
|
560
632
|
hiddenFields: { type: 'array', default: [], desc: '隐藏草稿字段名:值随草稿提交但不画;字典 rules 照常校验(不过时在提示条写明),permission: create 的编辑态不提交;不是安全边界,服务端必须自行校验' },
|
|
561
633
|
},
|
|
562
634
|
emits: {
|
|
@@ -572,88 +644,151 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
|
|
|
572
644
|
},
|
|
573
645
|
reset: { payload: { values: { type: 'object' }, object: { type: 'string' }, scope: { type: 'string' } }, desc: '重置(filter 的 values 为空对象)' },
|
|
574
646
|
cancel: { payload: { object: { type: 'string' }, scope: { type: 'string' }, model: { type: 'object' } }, desc: '取消(载荷带当前草稿,未校验)' },
|
|
575
|
-
draft_change: { payload: { values: { type: 'object' }, dirty: { type: 'boolean' } }, desc: '
|
|
576
|
-
|
|
647
|
+
draft_change: { payload: { values: { type: 'object' }, dirty: { type: 'boolean' }, field: { type: 'string' }, source: { type: 'string' }, suggestion: { type: 'object' } }, desc: '草稿变化;field = 本次变动的字段(用户输入或展示对象经 handle.set 写入时给出),source = input(用户输入)/ api(展示对象写入)/ suggestion(画布 AI 建议被采纳 / 忽略,suggestion = { id, action: accept | reject },采纳时值已并入 values)/ 缺省(草稿重建、重置、详情到达)' },
|
|
648
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.footer, { id: { type: 'string' }, object: { type: 'string' }, scope: { type: 'string' } }, '点了底栏动作(view.form.footerActions);序号 = 动作在 footerActions 数组里的位置,页面事件给每个动作各绑一条 request / download 管道'),
|
|
649
|
+
dirty_change: { payload: { dirty: { type: 'boolean' } }, desc: '草稿是否有未保存改动;仅在该布尔值变化时抛,另外每个实例挂载后首次同步抛一次当前值;弹窗协调组件据此做「未保存拦截」(draft_change 留给展示对象的 onDraft)' },
|
|
650
|
+
busy_change: { payload: { busy: { type: 'boolean' } }, desc: '提交处理中状态变化(写入 pending / 宿主 busy / 所接具名动作在跑);挂载后第一次同步必报一次当前值,之后只在值变化时发;弹窗协调组件据此在提交中不让用户关窗,实例被换掉时也靠首报复位' },
|
|
577
651
|
saved: { payload: { object: { type: 'string' }, scope: { type: 'string' }, result: { type: 'object' } }, desc: '写入成功(关闭由第 3 层监听)' },
|
|
578
652
|
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
653
|
},
|
|
583
654
|
},
|
|
584
655
|
services: ['data', 'http'],
|
|
585
656
|
templateHtml,
|
|
586
657
|
uiConfig,
|
|
587
658
|
eventConfig,
|
|
588
|
-
controllerFactory: (
|
|
659
|
+
controllerFactory: createKitController((api) => createController(api, registered, nameSet) as unknown as KitView),
|
|
589
660
|
};
|
|
590
661
|
}
|
|
591
662
|
|
|
592
663
|
// ── 控制器 ────────────────────────────────────────────────────────
|
|
593
664
|
|
|
665
|
+
/** 表单实例计数(无障碍节点 id 的实例前缀) */
|
|
666
|
+
let formInstanceCount = 0;
|
|
667
|
+
|
|
594
668
|
function createController(
|
|
595
|
-
|
|
669
|
+
api: KitApi,
|
|
596
670
|
registered: Readonly<Record<string, SomaComponentDefinition>>,
|
|
597
671
|
nameSet: ReadonlySet<string>,
|
|
598
672
|
): Record<string, unknown> {
|
|
599
|
-
const P = (): Rec =>
|
|
673
|
+
const P = (): Rec => api.props() as Rec;
|
|
674
|
+
/** 本表单的有效信封:prop(编译期按页面 > 应用解析后传入)非空优先,否则退回按宿主元素查找(远程选项、句柄 envelope() 共用这一处) */
|
|
675
|
+
const effectiveEnvelope = (): KitEnvelope | undefined => {
|
|
676
|
+
const given = P().envelope;
|
|
677
|
+
return isRec(given) && Object.keys(given).length > 0 ? (given as KitEnvelope) : getKitAppEnvelope(api.host);
|
|
678
|
+
};
|
|
679
|
+
/** 表单实例前缀:帮助 / 错误节点的 id 用它隔开同页的多个表单 */
|
|
680
|
+
const formUid = `kit-form-${++formInstanceCount}`;
|
|
681
|
+
/** 字段的标签 / 说明 / 错误节点 id:同页两个同对象表单也不重复,字段名里的特殊字符转成下划线编码 */
|
|
682
|
+
const fieldNodeId = (name: string, suffix: 'lbl' | 'help' | 'err'): string => `${formUid}-${encodeURIComponent(name).replace(/%/g, '_')}-${suffix}`;
|
|
600
683
|
const dataPort = (): SomaDataPort | undefined => {
|
|
601
|
-
const port = (
|
|
684
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
602
685
|
return port && typeof port === 'object' ? port : undefined;
|
|
603
686
|
};
|
|
604
687
|
|
|
605
688
|
let draft = createFormDraft({ initial: {} });
|
|
606
689
|
let signature = '';
|
|
607
690
|
let errors: Record<string, string> = {};
|
|
691
|
+
const touchedFields = new Set<string>();
|
|
692
|
+
const invalidFields = new Set<string>();
|
|
693
|
+
let lastSubmitVerdictRef: Record<string, string> | null = null;
|
|
608
694
|
let notice = '';
|
|
609
695
|
let conflict = false;
|
|
610
696
|
/** 写入结果回显的"处理中"(data.submit 的 pending);表单提交永不乐观——处理中只显示忙态,结果回来才改界面 */
|
|
611
697
|
let busy = false;
|
|
612
698
|
let unsubBusy: (() => void) | undefined;
|
|
699
|
+
let stopFlowWatch: (() => void) | undefined;
|
|
700
|
+
/** 已对外报出的处理中状态(busy_change 只在变化时发);undefined = 尚未报过,实例挂载后的第一次同步必报一次当前值(协调组件据此自愈) */
|
|
701
|
+
let busyReported: boolean | undefined;
|
|
702
|
+
const syncBusyEmit = (): void => {
|
|
703
|
+
const now = isBusy();
|
|
704
|
+
if (now === busyReported) return;
|
|
705
|
+
busyReported = now;
|
|
706
|
+
api.emit('busy_change', { busy: now });
|
|
707
|
+
};
|
|
708
|
+
/** 已对外报出的草稿脏状态(dirty_change 只在变化时发);undefined = 尚未报过,实例挂载后的第一次同步必报一次当前值 */
|
|
709
|
+
let dirtyReported: boolean | undefined;
|
|
710
|
+
const syncDirtyEmit = (): void => {
|
|
711
|
+
if (!alive) return;
|
|
712
|
+
const now = draft.isDirty();
|
|
713
|
+
if (now === dirtyReported) return;
|
|
714
|
+
dirtyReported = now;
|
|
715
|
+
api.emit('dirty_change', { dirty: now });
|
|
716
|
+
};
|
|
613
717
|
/** 处理中 = 写入结果 pending,或宿主给 busy / 所接具名动作在跑(base/action-busy 口径) */
|
|
614
718
|
const isBusy = (): boolean => busy || kitBusyOf(P());
|
|
615
719
|
let settledSeq = 0;
|
|
616
720
|
let pendingSeq = 0;
|
|
617
721
|
let unsubOutcome: (() => void) | undefined;
|
|
618
722
|
let cleanupDom: (() => void) | undefined;
|
|
723
|
+
/** 页签条的共享页签接线句柄(role=tab / aria-selected / roving tabindex / 方向键 Home End) */
|
|
724
|
+
let tabsHandle: KitTablistHandle | undefined;
|
|
619
725
|
let alive = true;
|
|
620
726
|
/** 已折叠的分组 id(form.groups 平铺后的标题格带 group.head);字段结构变化时按 group.open 重置 */
|
|
621
727
|
let collapsed = new Set<string>();
|
|
622
728
|
/** M 波 G3:filter 折叠态、页签当前组、远程选项缓存、防抖与离开守卫的清理 */
|
|
623
729
|
let filterCollapsed = true;
|
|
624
730
|
let activeTab = '';
|
|
625
|
-
const remote = new Map<string, {
|
|
731
|
+
const remote = new Map<string, {
|
|
732
|
+
key?: string;
|
|
733
|
+
loadedKey: string;
|
|
734
|
+
inflightKey: string;
|
|
735
|
+
failedKey?: string;
|
|
736
|
+
rows: Rec[];
|
|
737
|
+
seq: number;
|
|
738
|
+
keyword?: string;
|
|
739
|
+
children?: Map<string, Rec[]>;
|
|
740
|
+
pending?: boolean;
|
|
741
|
+
failed?: boolean;
|
|
742
|
+
error?: string | boolean;
|
|
743
|
+
}>();
|
|
626
744
|
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
627
|
-
/** H1e:字段变化触发请求的防抖计时(每个字段一个,再变化即取消上一次待发的) */
|
|
628
|
-
const changeTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
629
745
|
/** H1b:订阅选项源失效总线(写成功后点名重取 options.from) */
|
|
630
|
-
let offOptionsBus: (() => void) | undefined;
|
|
631
746
|
let pendingScroll = false;
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
747
|
+
/** 进入处理中前持有焦点的字段控件 id;处理中结束且无别的定位接管时还焦点 */
|
|
748
|
+
let focusBeforeBusy = '';
|
|
749
|
+
let busySeen = false;
|
|
750
|
+
/** focusBeforeBusy 刚记下、还没经过一次重绘:该次重绘若没进入忙态就丢弃它(只对紧接着的一次忙态有效) */
|
|
751
|
+
let focusArmed = false;
|
|
752
|
+
/** 提交 / 重置钮持焦点时提交:处理中钮进入 loading / 禁用态焦点会丢,整表错误或网络失败后靠它把焦点还给钮 */
|
|
753
|
+
let focusBeforeBusyButton: '' | 'kit_submit' | 'kit_reset' = '';
|
|
754
|
+
const resetFocusRestore = (): void => { focusBeforeBusy = ''; focusBeforeBusyButton = ''; busySeen = false; focusArmed = false; };
|
|
755
|
+
/** 冲突后点「刷新」时焦点在刷新按钮上:提示条随冲突清除而隐藏,下一次(字段已画出的)重绘后把焦点放到首个可用字段控件;一次性 */
|
|
756
|
+
let pendingRefreshFocus = false;
|
|
757
|
+
/** 摘掉「用户一有操作就作废标记」的一次性监听;未挂监听时为 undefined */
|
|
758
|
+
let offRefreshFocusGuard: (() => void) | undefined;
|
|
759
|
+
/** 清除刷新焦点标记并摘监听:所有清除路径(拿到焦点 / 用户操作 / 焦点已在别处 / 卸载 / 草稿重建)都经它 */
|
|
760
|
+
const disarmRefreshFocus = (): void => {
|
|
761
|
+
pendingRefreshFocus = false;
|
|
762
|
+
offRefreshFocusGuard?.();
|
|
763
|
+
offRefreshFocusGuard = undefined;
|
|
638
764
|
};
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
765
|
+
/** 置刷新焦点标记,同时在宿主文档挂捕获阶段 pointerdown / keydown 一次性监听:用户一有操作就作废,避免过时标记日后抢焦点 */
|
|
766
|
+
/** 置标记时的表单语境(模式 / 对象 / 作用域):草稿重建只在语境变了时作废标记——初值变化正是「刷新」本身带来的(宿主重取后下传新 initial),要保留 */
|
|
767
|
+
let refreshFocusContext = '';
|
|
768
|
+
const armRefreshFocus = (doc: Document): void => {
|
|
769
|
+
disarmRefreshFocus();
|
|
770
|
+
pendingRefreshFocus = true;
|
|
771
|
+
refreshFocusContext = formContextKey();
|
|
772
|
+
const onUserAction = (): void => disarmRefreshFocus();
|
|
773
|
+
doc.addEventListener('pointerdown', onUserAction, true);
|
|
774
|
+
doc.addEventListener('keydown', onUserAction, true);
|
|
775
|
+
offRefreshFocusGuard = () => {
|
|
776
|
+
doc.removeEventListener('pointerdown', onUserAction, true);
|
|
777
|
+
doc.removeEventListener('keydown', onUserAction, true);
|
|
778
|
+
};
|
|
642
779
|
};
|
|
780
|
+
let offGuard: (() => void) | undefined;
|
|
781
|
+
|
|
782
|
+
// ── 订阅 request 动作的结果(into),按需读,不另存业务数据 ──
|
|
643
783
|
const outcomes = new Map<string, KitOutcome>();
|
|
644
784
|
let outcomeSig = '';
|
|
645
785
|
let offOutcomes: Array<() => void> = [];
|
|
646
|
-
/** 已处理(采纳或忽略)到第几次写入;seq 更大的新结果才再出现采纳条 */
|
|
647
|
-
let adoptConsumedSeq = 0;
|
|
648
786
|
/** 结果槽(view.form.result)只显示 seq 大于它的结果 */
|
|
649
787
|
let resultBaseSeq = 0;
|
|
650
788
|
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
789
|
const syncOutcomes = (): void => {
|
|
654
|
-
const footerGateNames = Array.isArray(P().footerActions) ? (P().footerActions as unknown[]).filter(isRec).flatMap((a) => gateOutcomeNamesOf(gateFrom(a))) : [];
|
|
655
790
|
const resultName = isRec(P().result) && typeof (P().result as Rec).outcome === 'string' ? [(P().result as Rec).outcome as string] : [];
|
|
656
|
-
const names = [...new Set([...
|
|
791
|
+
const names = [...new Set([...resultName])];
|
|
657
792
|
const sig = names.join('|');
|
|
658
793
|
if (sig === outcomeSig) return;
|
|
659
794
|
outcomeSig = sig;
|
|
@@ -668,83 +803,8 @@ function createController(
|
|
|
668
803
|
}));
|
|
669
804
|
initial = false;
|
|
670
805
|
}
|
|
671
|
-
// 订阅之前就存在的结果不再当作新建议提供(可能属于别的行 / 上一次会话)
|
|
672
|
-
const from = adoptDecl()?.from;
|
|
673
|
-
if (from !== undefined) adoptConsumedSeq = Math.max(adoptConsumedSeq, outcomes.get(from)?.seq ?? 0);
|
|
674
806
|
resultBaseSeq = Math.max(resultBaseSeq, outcomes.get(resultOutcomeName())?.seq ?? 0);
|
|
675
807
|
};
|
|
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
808
|
const initGroups = (): void => {
|
|
749
809
|
activeTab = cells().find((c) => c.group?.head === true)?.group?.id ?? '';
|
|
750
810
|
filterCollapsed = true;
|
|
@@ -789,42 +849,56 @@ function createController(
|
|
|
789
849
|
const effectiveInitial = (): Rec => (detailRecord !== null ? { ...initialOf(), ...detailRecord } : initialOf());
|
|
790
850
|
let draftHandle: KitFormDraftHandle | undefined;
|
|
791
851
|
|
|
792
|
-
// ──
|
|
793
|
-
/** 各步已确认的 model { s<i>: {字段: 值} }(StepForm 以外为空) */
|
|
794
|
-
const stepsOf = (): Rec => (isRec(P().gateSteps) ? (P().gateSteps as Rec) : {});
|
|
852
|
+
// ── GB2 / GB3:字段初值、隐藏草稿字段 ──
|
|
795
853
|
/** 隐藏草稿字段名(筛选表单不带) */
|
|
796
854
|
const hiddenNames = (): string[] => (mode() === 'filter' ? [] : stringList(P().hiddenFields));
|
|
797
|
-
/**
|
|
855
|
+
/** 展示对象给出的某字段状态(路径已由 core 求成布尔;筛选表单不吃) */
|
|
856
|
+
const stateOf = (name: string): { hidden: boolean; disabled: boolean; required: boolean } => {
|
|
857
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
858
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : {};
|
|
859
|
+
return { hidden: e.hidden === true, disabled: e.disabled === true, required: e.required === true };
|
|
860
|
+
};
|
|
861
|
+
/** 展示对象给出的某字段候选项(fieldState.<字段>.options,core 已求成数组);没绑定 / 未到数组返回 undefined(筛选表单同样吃:编译期只放行 options 一个键) */
|
|
862
|
+
const viewOptionsOf = (name: string): Rec[] | undefined => {
|
|
863
|
+
const all = P().fieldState;
|
|
864
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
865
|
+
return e !== undefined && Array.isArray(e.options) ? (e.options as unknown[]).filter(isRec) : undefined;
|
|
866
|
+
};
|
|
867
|
+
/** 展示对象给出的画布节点候选项(fieldState.<字段>.nodeOptions,core 已求成对象 { "<类型>.<字段键>": [...] });没绑定返回 undefined */
|
|
868
|
+
const viewNodeOptionsOf = (name: string): Rec | undefined => {
|
|
869
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
870
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
871
|
+
return e !== undefined && isRec(e.nodeOptions) ? e.nodeOptions : undefined;
|
|
872
|
+
};
|
|
873
|
+
/** 展示对象持有的画布 AI 建议(fieldState.<字段>.suggestions,core 已求成数组);没绑定返回 undefined */
|
|
874
|
+
const viewSuggestionsOf = (name: string): unknown[] | undefined => {
|
|
875
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
876
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
877
|
+
return e !== undefined && Array.isArray(e.suggestions) ? (e.suggestions as unknown[]) : undefined;
|
|
878
|
+
};
|
|
879
|
+
/** 展示对象给出的子表列候选项(fieldState.<字段>.columnOptions,core 已求成对象 { "<列键>": [...] });没绑定返回 undefined */
|
|
880
|
+
const viewColumnOptionsOf = (name: string): Rec | undefined => {
|
|
881
|
+
const all = mode() === 'filter' ? undefined : P().fieldState;
|
|
882
|
+
const e = isRec(all) && isRec(all[name]) ? all[name] as Rec : undefined;
|
|
883
|
+
return e !== undefined && isRec(e.columnOptions) ? e.columnOptions : undefined;
|
|
884
|
+
};
|
|
885
|
+
/** 解析 defaults 表(字面量初值);取不到值的字段不在结果里 */
|
|
798
886
|
const resolveDefaults = (): Rec => {
|
|
799
887
|
const decl = isRec(P().defaults) ? (P().defaults as Rec) : {};
|
|
800
888
|
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);
|
|
889
|
+
return resolveFieldDefaults(decl);
|
|
814
890
|
};
|
|
815
891
|
|
|
816
892
|
const rebuildDraft = (): void => {
|
|
817
893
|
const defaults = mode() === 'create' ? resolveDefaults() : {};
|
|
818
|
-
refDefaultsSig = JSON.stringify(defaults);
|
|
819
894
|
draft = createFormDraft({ initial: { ...effectiveInitial() }, ...(Object.keys(defaults).length > 0 ? { defaults } : {}) });
|
|
820
895
|
errors = {};
|
|
896
|
+
touchedFields.clear();
|
|
897
|
+
invalidFields.clear();
|
|
898
|
+
lastSubmitVerdictRef = null;
|
|
821
899
|
notice = '';
|
|
822
900
|
conflict = false;
|
|
823
901
|
busy = false;
|
|
824
|
-
// 换了一行 / 重建草稿:上一份建议属于旧草稿,视为过期,已采纳标记也清掉
|
|
825
|
-
adopted = {};
|
|
826
|
-
const staleFrom = adoptDecl()?.from;
|
|
827
|
-
if (staleFrom !== undefined) adoptConsumedSeq = Math.max(adoptConsumedSeq, outcomes.get(staleFrom)?.seq ?? 0);
|
|
828
902
|
// 结果槽只显示草稿(行 / 模式)重建之后发生的请求结果;之前的属于上一行 / 上一次会话
|
|
829
903
|
resultBaseSeq = Math.max(resultBaseSeq, outcomes.get(resultOutcomeName())?.seq ?? 0);
|
|
830
904
|
const view = dataPort()?.writeOutcome?.(scopeKey());
|
|
@@ -832,26 +906,53 @@ function createController(
|
|
|
832
906
|
settledSeq = view?.status === 'pending' ? Math.max(0, pendingSeq - 1) : pendingSeq;
|
|
833
907
|
};
|
|
834
908
|
|
|
909
|
+
/** 表单语境键(模式 / 对象 / 作用域):刷新焦点标记据此判断草稿重建是不是换了一张表单 */
|
|
910
|
+
const formContextKey = (): string => JSON.stringify([mode(), objectName(), scopeKey()]);
|
|
835
911
|
const syncDraft = (): void => {
|
|
836
912
|
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
|
-
}
|
|
913
|
+
if (sig === signature) return;
|
|
847
914
|
signature = sig;
|
|
848
|
-
|
|
915
|
+
// 草稿签名变化导致重建:换了模式 / 对象 / 作用域(另一张表单)时刷新焦点标记作废;只是初值变了(刷新后宿主下传新值)则保留,字段画出后照常归还焦点
|
|
916
|
+
if (pendingRefreshFocus && formContextKey() !== refreshFocusContext) disarmRefreshFocus();
|
|
849
917
|
detailRecord = null;
|
|
850
918
|
rebuildDraft();
|
|
851
919
|
initGroups();
|
|
852
920
|
remote.clear();
|
|
853
921
|
startDetail();
|
|
854
922
|
if (!detailBlocked()) ensureOptions();
|
|
923
|
+
// 草稿重建会把 busy 清零:异步补报(不在渲染读口里重入)
|
|
924
|
+
queueMicrotask(() => { if (alive) { syncBusyEmit(); syncDirtyEmit(); } });
|
|
925
|
+
// 展示对象对齐:草稿首次建好补发一次 draft_change(异步发,不在渲染读口里重入)
|
|
926
|
+
if (P().draftNotify === true && mode() !== 'filter' && !detailBlocked()) {
|
|
927
|
+
queueMicrotask(() => { if (alive) api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() }); });
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* 草稿读口登记(具名动作的 draft 读口与 $draft 取值):
|
|
933
|
+
* 筛选表单(mode: filter)不登记;动态切换到 filter 模式时注销,切换到 create/edit 模式时重新登记。
|
|
934
|
+
*/
|
|
935
|
+
const syncDraftRegistration = (): void => {
|
|
936
|
+
if (!alive) return;
|
|
937
|
+
const curMode = mode();
|
|
938
|
+
if (curMode === 'filter') {
|
|
939
|
+
if (draftHandle) {
|
|
940
|
+
draftHandle.dispose();
|
|
941
|
+
draftHandle = undefined;
|
|
942
|
+
}
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (!draftHandle) {
|
|
946
|
+
draftHandle = registerKitFormDraft({
|
|
947
|
+
get scope(): string { return scopeKey(); },
|
|
948
|
+
get object(): string { return objectName(); },
|
|
949
|
+
get mode(): 'create' | 'edit' { return mode() === 'edit' ? 'edit' : 'create'; },
|
|
950
|
+
host: api.host ?? null,
|
|
951
|
+
values: () => ({ ...draft.values() }),
|
|
952
|
+
dirty: () => draft.isDirty(),
|
|
953
|
+
ready: () => !detailBlocked(),
|
|
954
|
+
});
|
|
955
|
+
}
|
|
855
956
|
};
|
|
856
957
|
|
|
857
958
|
/** 取详情:成功 -> 详情盖行重建草稿;失败 / 缺参 -> 照实报错(notice)并给重试,不渲染表单 */
|
|
@@ -862,17 +963,17 @@ function createController(
|
|
|
862
963
|
if (d === null || mode() !== 'edit') { detailState = 'none'; return; }
|
|
863
964
|
const fail = (message: string): void => {
|
|
864
965
|
detailState = 'failed';
|
|
865
|
-
notice = message !== '' ? message : kitText('soma.kit.load_failed', undefined,
|
|
966
|
+
notice = message !== '' ? message : kitText('soma.kit.load_failed', undefined, api.host);
|
|
866
967
|
};
|
|
867
968
|
const { params, missing } = resolveDetailParams(d.params ?? {}, initialOf());
|
|
868
|
-
const http = (
|
|
969
|
+
const http = (api.services as { http?: { get<T>(url: string, config?: { params?: Record<string, string> }): Promise<T>; baseURL?: unknown } } | undefined)?.http;
|
|
869
970
|
if (missing.length > 0 || !http) { fail(''); return; }
|
|
870
971
|
const rawBase = http.baseURL;
|
|
871
972
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
872
|
-
const
|
|
973
|
+
const apiRoute = baseURL !== '' && baseURL !== '/' && d.api.startsWith(`${baseURL}/`) ? d.api.slice(baseURL.length) : d.api;
|
|
873
974
|
detailState = 'loading';
|
|
874
975
|
notice = '';
|
|
875
|
-
void http.get<unknown>(
|
|
976
|
+
void http.get<unknown>(apiRoute, { params }).then((res) => {
|
|
876
977
|
if (!alive || mine !== detailSeq) return;
|
|
877
978
|
const read = readDetailResponse(res, d.unwrap, d.envelope);
|
|
878
979
|
if (!read.ok) { fail(read.message); repaint(); return; }
|
|
@@ -882,7 +983,8 @@ function createController(
|
|
|
882
983
|
initGroups();
|
|
883
984
|
remote.clear();
|
|
884
985
|
ensureOptions();
|
|
885
|
-
|
|
986
|
+
syncDirtyEmit();
|
|
987
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
886
988
|
repaint();
|
|
887
989
|
}).catch((error: unknown) => {
|
|
888
990
|
if (!alive || mine !== detailSeq) return;
|
|
@@ -895,9 +997,8 @@ function createController(
|
|
|
895
997
|
const submitNames = (): string[] => {
|
|
896
998
|
const m = mode();
|
|
897
999
|
const skip = m === 'edit' ? createOnly() : new Set<string>();
|
|
898
|
-
const vals = draft.values();
|
|
899
1000
|
const shown = cells()
|
|
900
|
-
.filter((c) => c.placeholder !== true && c.component !== '' && c.mode === 'edit' && !skip.has(c.field)
|
|
1001
|
+
.filter((c) => c.placeholder !== true && c.component !== '' && c.mode === 'edit' && !skip.has(c.field))
|
|
901
1002
|
.map((c) => c.field);
|
|
902
1003
|
// GB3:隐藏草稿字段一并提交(permission: create 的编辑态照样不提交——hidden 不改变权限语义)
|
|
903
1004
|
return [...shown, ...hiddenNames().filter((n) => !skip.has(n) && !shown.includes(n))];
|
|
@@ -930,8 +1031,7 @@ function createController(
|
|
|
930
1031
|
|
|
931
1032
|
/** 校验用的整份值:含 edit 下 create-only 字段(它们不进 model,但字典里可能是必填) */
|
|
932
1033
|
const validationValues = (): Rec => {
|
|
933
|
-
const
|
|
934
|
-
const names = [...cells().filter((c) => c.placeholder !== true && c.component !== '' && shownByCond(c, vals)).map((c) => c.field), ...hiddenNames()];
|
|
1034
|
+
const names = [...cells().filter((c) => c.placeholder !== true && c.component !== '').map((c) => c.field), ...hiddenNames()];
|
|
935
1035
|
const out = collect(names);
|
|
936
1036
|
for (const key of stringList(P().keys)) {
|
|
937
1037
|
const v = draft.get(key);
|
|
@@ -942,90 +1042,300 @@ function createController(
|
|
|
942
1042
|
|
|
943
1043
|
const editableSet = (): Set<string> => new Set(submitNames());
|
|
944
1044
|
|
|
1045
|
+
/** 子表字段(控件为 RowEditor)是否参与校验:会提交的、显示着的、没被禁用 / 只读的(整表错误与单元格错误共用这一段前置判断) */
|
|
1046
|
+
const rowsFieldActive = (c: KitCell, editable: ReadonlySet<string>): boolean => {
|
|
1047
|
+
if (c.component !== 'RowEditor' || c.placeholder === true || !editable.has(c.field)) return false;
|
|
1048
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1049
|
+
const st = stateOf(c.field);
|
|
1050
|
+
return !(props.readonly === true || props.disabled === true || st.hidden || st.disabled);
|
|
1051
|
+
};
|
|
1052
|
+
|
|
945
1053
|
/** 子表字段(控件为 RowEditor)的提交前校验:只看本次会提交的、显示着的、没被禁用 / 只读的字段 */
|
|
946
1054
|
const rowsFieldErrors = (): Record<string, string> => {
|
|
947
1055
|
const out: Record<string, string> = {};
|
|
948
1056
|
const vals = draft.values();
|
|
949
1057
|
const editable = editableSet();
|
|
950
1058
|
for (const c of cells()) {
|
|
951
|
-
if (
|
|
1059
|
+
if (!rowsFieldActive(c, editable)) continue;
|
|
952
1060
|
const props = isRec(c.props) ? c.props : {};
|
|
953
|
-
if (props.readonly === true || props.disabled === true || (c.disabledWhen !== undefined && holds(c.disabledWhen, vals))) continue;
|
|
954
1061
|
const rows = Array.isArray(vals[c.field]) ? (vals[c.field] as unknown[]).filter(isRec) : [];
|
|
955
|
-
const message = validateInlineRows(rowColumnsOf(props.columns,
|
|
1062
|
+
const message = validateInlineRows(rowColumnsOf(props.columns, api.host), rows, {
|
|
956
1063
|
minRows: Number(props.min_rows) || 0,
|
|
957
1064
|
maxRows: Number(props.max_rows) || 0,
|
|
958
1065
|
lockedKey: typeof props.locked_key === 'string' ? props.locked_key : '',
|
|
959
|
-
},
|
|
1066
|
+
}, api.host);
|
|
960
1067
|
if (message !== null) out[c.field] = message;
|
|
961
1068
|
}
|
|
962
1069
|
return out;
|
|
963
1070
|
};
|
|
964
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* 子表字段的单元格级错误(全部,行下标 + 列 key):传给 RowEditor 的 cell_errors,让出错单元格标红、可聚焦。
|
|
1074
|
+
* 字段处于出错期间每次构建行都按当前草稿重算(改好一格后只剩其余格),RowEditor 以入参为准;只读 / 禁用 / 隐藏的字段不产生单元格错误
|
|
1075
|
+
*/
|
|
1076
|
+
const rowsCellErrorsOf = (c: KitCell): KitRowCellError[] => {
|
|
1077
|
+
if (!rowsFieldActive(c, editableSet())) return [];
|
|
1078
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1079
|
+
const v = draft.values()[c.field];
|
|
1080
|
+
const rows = Array.isArray(v) ? (v as unknown[]).filter(isRec) : [];
|
|
1081
|
+
return validateInlineRowCells(rowColumnsOf(props.columns, api.host), rows, {
|
|
1082
|
+
lockedKey: typeof props.locked_key === 'string' ? props.locked_key : '',
|
|
1083
|
+
}, api.host);
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
/** 展示对象绑定为必填的字段:可编辑、没隐藏、没置灰、值为空 -> 必填提示(隐藏 / 置灰的字段用户填不了,不判) */
|
|
1087
|
+
const boundRequiredErrors = (): Record<string, string> => {
|
|
1088
|
+
const out: Record<string, string> = {};
|
|
1089
|
+
const vals = draft.values();
|
|
1090
|
+
const editable = editableSet();
|
|
1091
|
+
for (const c of cells()) {
|
|
1092
|
+
if (c.placeholder === true || !editable.has(c.field)) continue;
|
|
1093
|
+
const st = stateOf(c.field);
|
|
1094
|
+
if (!st.required || st.hidden || st.disabled) continue;
|
|
1095
|
+
if (isBlank(vals[c.field])) out[c.field] = kitText('soma.kit.field_required', undefined, api.host);
|
|
1096
|
+
}
|
|
1097
|
+
return out;
|
|
1098
|
+
};
|
|
1099
|
+
|
|
965
1100
|
/** 流程画布字段(控件为 FlowEditor)的提交前校验:必填(星号)时至少一个节点;只读 / 禁用的不查 */
|
|
966
1101
|
const flowFieldErrors = (): Record<string, string> => {
|
|
967
1102
|
const out: Record<string, string> = {};
|
|
968
1103
|
const vals = draft.values();
|
|
969
1104
|
const editable = editableSet();
|
|
970
1105
|
for (const c of cells()) {
|
|
971
|
-
if (c.component !== 'FlowEditor' || c.placeholder === true || !editable.has(c.field)
|
|
1106
|
+
if (c.component !== 'FlowEditor' || c.placeholder === true || !editable.has(c.field)) continue;
|
|
972
1107
|
const props = isRec(c.props) ? c.props : {};
|
|
973
|
-
|
|
974
|
-
if (
|
|
1108
|
+
const st = stateOf(c.field);
|
|
1109
|
+
if (props.readonly === true || props.disabled === true || st.hidden || st.disabled) continue;
|
|
1110
|
+
if (starOf(c) === '') continue;
|
|
975
1111
|
const v = vals[c.field];
|
|
976
1112
|
const nodes = isRec(v) && Array.isArray(v.nodes) ? v.nodes : [];
|
|
977
|
-
if (nodes.length === 0) out[c.field] = kitText('soma.kit.flow_required', undefined,
|
|
1113
|
+
if (nodes.length === 0) out[c.field] = kitText('soma.kit.flow_required', undefined, api.host);
|
|
978
1114
|
}
|
|
979
1115
|
return out;
|
|
980
1116
|
};
|
|
981
1117
|
|
|
982
|
-
|
|
1118
|
+
const SUBMIT_UNREADY_TITLE = '请先完善必填项或修正校验错误';
|
|
1119
|
+
const computeSubmitTitle = (): string => {
|
|
1120
|
+
if (mode() === 'filter') return '';
|
|
1121
|
+
if (invalidFields.size > 0 || Object.values(errors).some((msg) => msg !== '')) {
|
|
1122
|
+
return SUBMIT_UNREADY_TITLE;
|
|
1123
|
+
}
|
|
1124
|
+
const vals = draft.values();
|
|
1125
|
+
const editable = editableSet();
|
|
1126
|
+
for (const c of cells()) {
|
|
1127
|
+
if (c.placeholder === true || !editable.has(c.field)) continue;
|
|
1128
|
+
const st = stateOf(c.field);
|
|
1129
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1130
|
+
if (st.hidden || st.disabled || props.disabled === true || props.readonly === true) continue;
|
|
1131
|
+
const rawRules = Array.isArray((c as unknown as Rec).rules)
|
|
1132
|
+
? ((c as unknown as Rec).rules as unknown[])
|
|
1133
|
+
: Array.isArray(props.rules)
|
|
1134
|
+
? (props.rules as unknown[])
|
|
1135
|
+
: [];
|
|
1136
|
+
const hasRuleRequired = rawRules.some((r) => isRec(r) && r.required === true);
|
|
1137
|
+
const isReq = c.required !== undefined || props.required === true || st.required || hasRuleRequired;
|
|
1138
|
+
if (isReq && isBlank(vals[c.field])) {
|
|
1139
|
+
return SUBMIT_UNREADY_TITLE;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return '';
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
// ── aria-invalid(嵌套组件根在 render 之后才存在,同步 + 微任务双拍同步)──
|
|
983
1146
|
const syncInvalid = (): void => {
|
|
984
|
-
const host =
|
|
1147
|
+
const host = api.host;
|
|
985
1148
|
if (!host || typeof host.querySelectorAll !== 'function') return;
|
|
986
1149
|
for (const row of buildRows()) {
|
|
987
1150
|
// 字段名可含引号 / 反斜杠:转义后再进属性选择器,避免 querySelector 抛错
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1151
|
+
const escId = row.id.replace(/["\\]/g, '\\$&');
|
|
1152
|
+
const escName = row.name.replace(/["\\]/g, '\\$&');
|
|
1153
|
+
const el =
|
|
1154
|
+
host.querySelector<HTMLElement>(`[id="${escId}"]`) ??
|
|
1155
|
+
(escName !== '' ? host.querySelector<HTMLElement>(`[name="${escName}"], [data-field="${escName}"], [data-kit-field="${escName}"]`) : null);
|
|
1156
|
+
// aria-invalid / aria-describedby / aria-required / aria-labelledby 不在这里往控件上写:由 buildRows 经 props(invalid / describedby / required / labelledby)
|
|
1157
|
+
// 交给控件自己的 applyCommon,重绘时随 props 重写,不会被子组件重渲染抹掉
|
|
1158
|
+
const errEl = escName !== '' ? host.querySelector<HTMLElement>(`[data-field-error="${escName}"]`) : null;
|
|
1159
|
+
// 错误 / 帮助文字与控件关联:节点按行模板的确切 data-soma-id(help_/err_ + 组件名)取,且只在该单元格的直接结构里找,不进入嵌套组件;
|
|
1160
|
+
// 节点 id = 表单实例前缀 + 字段名 + 后缀(同页两个同对象表单也不重复),控件 id 不动
|
|
1161
|
+
const tpl = row.component.replace(/["\\]/g, '\\$&');
|
|
1162
|
+
const cellEl = el?.closest<HTMLElement>(`[data-soma-id="cell_${tpl}"]`) ?? null;
|
|
1163
|
+
const bodyOf = (kind: 'help' | 'err'): HTMLElement | null =>
|
|
1164
|
+
cellEl?.querySelector<HTMLElement>(`:scope > [data-soma-id="body_${tpl}"] > [data-soma-id="${kind}_${tpl}"]`) ?? null;
|
|
1165
|
+
const errNode = errEl ?? bodyOf('err');
|
|
1166
|
+
const helpNode = bodyOf('help');
|
|
1167
|
+
if (helpNode) helpNode.id = fieldNodeId(row.name, 'help');
|
|
1168
|
+
if (errNode) errNode.id = fieldNodeId(row.name, 'err');
|
|
1169
|
+
if (errEl) {
|
|
1170
|
+
errEl.textContent = row.error;
|
|
1171
|
+
errEl.className = row.error === '' ? KIT_FORM_CLASS.errorHidden : row.errorClass;
|
|
1172
|
+
} else if (el && row.error !== '' && errNode === null) {
|
|
1173
|
+
const p = host.ownerDocument.createElement('p');
|
|
1174
|
+
p.setAttribute('data-field-error', row.name);
|
|
1175
|
+
p.setAttribute('role', 'alert');
|
|
1176
|
+
p.className = row.errorClass;
|
|
1177
|
+
p.textContent = row.error;
|
|
1178
|
+
el.insertAdjacentElement('afterend', p);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
const submitTitle = computeSubmitTitle();
|
|
1182
|
+
const submitTargets = host.querySelectorAll<HTMLElement>('[data-soma-id="kit_submit"], [data-soma-id="kit_submit"] button, [data-soma-scoped-id="kit_submit"] button, button[type="submit"]');
|
|
1183
|
+
for (const btn of Array.from(submitTargets)) {
|
|
1184
|
+
if (submitTitle !== '') btn.setAttribute('title', submitTitle);
|
|
1185
|
+
else btn.removeAttribute('title');
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
/** 记下当前持有焦点的字段控件 id(只认本表单字段) */
|
|
1189
|
+
const rememberFocus = (): void => {
|
|
1190
|
+
const host = api.host;
|
|
1191
|
+
const active = host?.ownerDocument?.activeElement;
|
|
1192
|
+
if (!host || !active || !host.contains(active)) return;
|
|
1193
|
+
for (const row of buildRows()) {
|
|
1194
|
+
if (row.id === '') continue;
|
|
1195
|
+
const ctl = host.querySelector<HTMLElement>(`[id="${row.id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1196
|
+
if (ctl && (ctl === active || ctl.contains(active))) { focusBeforeBusy = row.id; focusArmed = true; return; }
|
|
992
1197
|
}
|
|
1198
|
+
// 字段没命中:焦点在提交 / 重置钮内(键盘 Enter / 空格触发),记下钮 id 供处理结束后归还
|
|
1199
|
+
for (const id of ['kit_submit', 'kit_reset'] as const) {
|
|
1200
|
+
if (active.closest?.(`[data-soma-id="${id}"]`) && host.contains(active.closest(`[data-soma-id="${id}"]`))) {
|
|
1201
|
+
focusBeforeBusyButton = id; focusArmed = true; return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
/** 首个出错字段所在分组被隐藏(页签未激活 / 分组折叠)时,先切到 / 展开该分组 */
|
|
1206
|
+
const revealFirstErrorGroup = (): void => {
|
|
1207
|
+
const first = cells().find((c) => c.placeholder !== true && (errors[c.field] ?? '') !== '');
|
|
1208
|
+
if (first?.group === undefined) return;
|
|
1209
|
+
if (P().groupTabs === true && mode() !== 'filter') activeTab = first.group.id;
|
|
1210
|
+
else collapsed.delete(first.group.id);
|
|
1211
|
+
};
|
|
1212
|
+
/**
|
|
1213
|
+
* 页签条 DOM 同步:选中态回灌接线、补 roving tabindex;每枚页签 aria-controls 指向字段栅格(唯一的面板),
|
|
1214
|
+
* 栅格写 role=tabpanel + aria-labelledby=当前选中页签;非页签模式撤掉栅格上的面板语义。
|
|
1215
|
+
* 页签行由 core 渲染,本函数在 render / repaint 的同步与微任务两拍里调。
|
|
1216
|
+
*/
|
|
1217
|
+
const syncTabsDom = (): void => {
|
|
1218
|
+
const host = api.host;
|
|
1219
|
+
if (!host || typeof host.querySelector !== 'function') return;
|
|
1220
|
+
const grid = host.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
1221
|
+
const panelId = `${formUid}-panel`;
|
|
1222
|
+
if (P().groupTabs !== true || mode() === 'filter') {
|
|
1223
|
+
if (grid && grid.id === panelId) {
|
|
1224
|
+
grid.removeAttribute('id');
|
|
1225
|
+
grid.removeAttribute('role');
|
|
1226
|
+
grid.removeAttribute('aria-labelledby');
|
|
1227
|
+
}
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
tabsHandle?.select(activeTab, { silent: true });
|
|
1231
|
+
tabsHandle?.refresh();
|
|
1232
|
+
const bar = host.querySelector<HTMLElement>('[data-soma-id="tabbar"]');
|
|
1233
|
+
if (!bar || !grid) return;
|
|
1234
|
+
const tabs = Array.from(bar.querySelectorAll<HTMLElement>('[data-kit-group-tab]'));
|
|
1235
|
+
tabs.forEach((tab, i) => {
|
|
1236
|
+
if (tab.id === '') tab.id = `${formUid}-tab-${i}`;
|
|
1237
|
+
tab.setAttribute('aria-controls', panelId);
|
|
1238
|
+
});
|
|
1239
|
+
grid.id = panelId;
|
|
1240
|
+
grid.setAttribute('role', 'tabpanel');
|
|
1241
|
+
const on = tabs.find((t) => t.getAttribute('aria-selected') === 'true');
|
|
1242
|
+
if (on) grid.setAttribute('aria-labelledby', on.id);
|
|
1243
|
+
else grid.removeAttribute('aria-labelledby');
|
|
993
1244
|
};
|
|
994
1245
|
const repaint = (): void => {
|
|
995
1246
|
draftHandle?.touch();
|
|
996
|
-
|
|
1247
|
+
api.refresh();
|
|
1248
|
+
if (isBusy()) busySeen = true;
|
|
1249
|
+
else if (focusArmed && !busySeen) { focusBeforeBusy = ''; focusBeforeBusyButton = ''; }
|
|
1250
|
+
focusArmed = false;
|
|
1251
|
+
if (alive) syncBusyEmit();
|
|
1252
|
+
if (alive) syncDirtyEmit();
|
|
1253
|
+
if (alive) syncInvalid();
|
|
1254
|
+
if (alive) syncTabsDom();
|
|
997
1255
|
queueMicrotask(() => {
|
|
998
1256
|
if (!alive) return;
|
|
999
1257
|
syncInvalid();
|
|
1258
|
+
syncTabsDom();
|
|
1000
1259
|
// scrollToError:校验失败后把首个出错字段滚入可视区并聚焦(减少动效下不平滑滚动)
|
|
1260
|
+
let focusTaken = false;
|
|
1001
1261
|
if (pendingScroll) {
|
|
1002
1262
|
pendingScroll = false;
|
|
1003
|
-
|
|
1004
|
-
|
|
1263
|
+
// 有字段级错误 → 滚到并聚焦首个出错字段;只有整表错误 → 滚到顶部提示条
|
|
1264
|
+
// 出错字段按行数据(首个有错误的行)找控件宿主:aria-invalid 经 props 由控件自己写,子组件重绘可能晚于这一拍,不能只靠它定位
|
|
1265
|
+
const badRow = buildRows().find((r) => r.error !== '' && r.id !== '');
|
|
1266
|
+
const badHost = badRow
|
|
1267
|
+
? api.host?.querySelector?.<HTMLElement>(`[id="${badRow.id.replace(/["\\]/g, '\\$&')}"]`) ?? null
|
|
1268
|
+
: null;
|
|
1269
|
+
const fieldTarget = badHost
|
|
1270
|
+
?? api.host?.querySelector?.<HTMLElement>(`[aria-invalid="true"],[${KIT_INVALID_MARK}="true"]`)
|
|
1271
|
+
?? null;
|
|
1272
|
+
const target = fieldTarget
|
|
1273
|
+
?? (notice !== '' ? api.host?.querySelector?.<HTMLElement>('[data-soma-id="notice"]') ?? null : null);
|
|
1274
|
+
if (target) {
|
|
1005
1275
|
const reduce = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1006
|
-
|
|
1007
|
-
|
|
1276
|
+
target.scrollIntoView?.({ block: 'center', behavior: reduce ? 'auto' : 'smooth' });
|
|
1277
|
+
if (target === fieldTarget) { (fieldFocusTarget(target) ?? target).focus?.({ preventScroll: true }); focusTaken = true; }
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
// 刷新按钮持焦点时点了刷新:字段画出后焦点落到首个可用字段控件(取数期间字段不画,标记保留)
|
|
1281
|
+
if (pendingRefreshFocus && !detailBlocked()) {
|
|
1282
|
+
const host = api.host;
|
|
1283
|
+
// 焦点已被用户放到别处(既不在 body / 空,也不在刷新钮所在壳内):不抢焦点,直接作废标记
|
|
1284
|
+
const active = host?.ownerDocument?.activeElement ?? null;
|
|
1285
|
+
const stolen = active !== null && active !== host?.ownerDocument?.body
|
|
1286
|
+
&& !host?.querySelector?.('[data-soma-id="refresh_wrap"]')?.contains(active);
|
|
1287
|
+
if (stolen) disarmRefreshFocus();
|
|
1288
|
+
else for (const row of buildRows()) {
|
|
1289
|
+
if (row.id === '') continue;
|
|
1290
|
+
const el = host?.querySelector?.<HTMLElement>(`[id="${row.id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1291
|
+
if (!el) continue;
|
|
1292
|
+
const ctl = el.matches?.('input,select,textarea,button,[tabindex]')
|
|
1293
|
+
? el
|
|
1294
|
+
: el.querySelector<HTMLElement>('input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),[tabindex]');
|
|
1295
|
+
if (!ctl || (ctl as HTMLInputElement).disabled === true) continue;
|
|
1296
|
+
ctl.focus?.({ preventScroll: true });
|
|
1297
|
+
// 折叠分组 / 未激活页签 / 被展示对象隐藏的字段格不可见,focus() 静默失败:确认真的拿到焦点才算,否则试下一个
|
|
1298
|
+
const root = ctl.getRootNode?.() as Document | ShadowRoot | undefined;
|
|
1299
|
+
if ((root?.activeElement ?? ctl.ownerDocument?.activeElement) !== ctl) continue;
|
|
1300
|
+
focusTaken = true;
|
|
1301
|
+
// 真的拿到焦点才清标记;没拿到(字段控件晚到 / 全部不可聚焦)保留,等下一次重绘再试
|
|
1302
|
+
disarmRefreshFocus();
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
// 处理中结束且没有别的定位接管:焦点还给提交前的字段
|
|
1307
|
+
if (busySeen && !isBusy()) {
|
|
1308
|
+
const id = focusBeforeBusy;
|
|
1309
|
+
const btnId = focusBeforeBusyButton;
|
|
1310
|
+
resetFocusRestore();
|
|
1311
|
+
// 没有字段可还且焦点在提交 / 重置钮:处理结束后焦点掉在 body 才归还给该钮(优先内部 button)
|
|
1312
|
+
if (id === '' && btnId !== '' && !focusTaken) {
|
|
1313
|
+
const doc = api.host?.ownerDocument;
|
|
1314
|
+
if (doc?.activeElement === null || doc?.activeElement === doc?.body) {
|
|
1315
|
+
const wrap = api.host?.querySelector?.<HTMLElement>(`[data-soma-id="${btnId}"]`);
|
|
1316
|
+
(wrap?.querySelector<HTMLElement>('button') ?? wrap)?.focus?.({ preventScroll: true });
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
if (id !== '' && !focusTaken) {
|
|
1320
|
+
const ctl = api.host?.querySelector?.<HTMLElement>(`[id="${id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1321
|
+
const doc = api.host?.ownerDocument;
|
|
1322
|
+
if (ctl && (doc?.activeElement === null || doc?.activeElement === doc?.body)) ctl.focus?.({ preventScroll: true });
|
|
1008
1323
|
}
|
|
1009
1324
|
}
|
|
1010
1325
|
});
|
|
1011
1326
|
};
|
|
1012
1327
|
|
|
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' | '' => {
|
|
1328
|
+
// ── M 波 G3:条件 / 布局 / 筛选折叠的纯计算 ──
|
|
1329
|
+
/** 必填星号位置:取编译期结果;'' = 不标 */
|
|
1330
|
+
const starOf = (c: KitCell): 'start' | 'end' | '' => {
|
|
1022
1331
|
if (mode() === 'filter' || c.placeholder === true || c.label === '') return '';
|
|
1023
1332
|
if (c.required !== undefined) return c.required;
|
|
1024
|
-
|
|
1025
|
-
return P().requiredMark === 'start' ? 'start' : 'end';
|
|
1333
|
+
// 展示对象绑定的必填:星号位置随 requiredMark(缺省在后)
|
|
1334
|
+
return stateOf(c.field).required ? (P().requiredMark === 'start' ? 'start' : 'end') : '';
|
|
1026
1335
|
};
|
|
1027
|
-
const starFields = (c: KitCell,
|
|
1028
|
-
|
|
1336
|
+
const starFields = (c: KitCell, readOnlyHere = false): Pick<KitFormRow, 'starStart' | 'starStartClass' | 'starEnd' | 'starEndClass'> => {
|
|
1337
|
+
// 编辑态下只读的字段(permission: create 的字段在 edit 模式画成只读文本)不是待填项,不标必填星
|
|
1338
|
+
const s = readOnlyHere ? '' : starOf(c);
|
|
1029
1339
|
return {
|
|
1030
1340
|
starStart: s === 'start' ? '*' : '',
|
|
1031
1341
|
starStartClass: s === 'start' ? KIT_REQUIRED_STAR_CLASS.start : 'hidden',
|
|
@@ -1042,17 +1352,47 @@ function createController(
|
|
|
1042
1352
|
for (const t of FL.formLayout.cellClass[pos]!.split(/\s+/)) if (!tokens.includes(t)) tokens.push(t);
|
|
1043
1353
|
return tokens.join(' ');
|
|
1044
1354
|
};
|
|
1355
|
+
/** 只读行(edit 下 create-only 字段画成只读)的说明气泡钮变量:有 help 才显,读屏名「<字段名>说明」;其余行全隐 */
|
|
1356
|
+
const readOnlyHelpTip = (c: KitCell, readOnlyHere: boolean): Pick<KitFormRow, 'helpTip' | 'helpTipLabel' | 'helpTipClass'> => {
|
|
1357
|
+
const text = readOnlyHere && c.placeholder !== true ? strOf(c.help).trim() : '';
|
|
1358
|
+
if (text === '' || c.label === '') return { helpTip: '', helpTipLabel: '', helpTipClass: KIT_FORM_CLASS.errorHidden };
|
|
1359
|
+
return { helpTip: text, helpTipLabel: kitText('soma.kit.help_of', { label: c.label }, api.host), helpTipClass: kitHelpTriggerRecipe() };
|
|
1360
|
+
};
|
|
1045
1361
|
const labelClassOf = (c: KitCell): string => {
|
|
1046
1362
|
const pos = posOf();
|
|
1047
1363
|
if (pos === '') return c.labelClass;
|
|
1048
1364
|
const level = Math.min(FL.formLayout.labelWidthClasses.length, Math.max(1, Math.trunc(Number(P().labelWidth) || KIT_FORM_LINKAGE_LIMITS.formLayout.labelWidthDefault)));
|
|
1049
1365
|
return `${FL.formLayout.labelClass[pos]!} ${FL.formLayout.labelWidthClasses[level - 1]!}`;
|
|
1050
1366
|
};
|
|
1051
|
-
/**
|
|
1367
|
+
/** 宿主当前宽(rem);量不到(无布局环境 / 宽 0)为 0 */
|
|
1368
|
+
const flowHostRem = (): number => {
|
|
1369
|
+
const el = api.host as HTMLElement | undefined;
|
|
1370
|
+
const px = el?.clientWidth ?? 0;
|
|
1371
|
+
if (!(px > 0) || el === undefined) return 0;
|
|
1372
|
+
const view = el.ownerDocument?.defaultView;
|
|
1373
|
+
const root = view !== null && view !== undefined && typeof view.getComputedStyle === 'function' ? parseFloat(view.getComputedStyle(el.ownerDocument.documentElement).fontSize) : 16;
|
|
1374
|
+
return px / (root > 0 ? root : 16);
|
|
1375
|
+
};
|
|
1376
|
+
/** filter 折叠:按各格 12 份制份数累计折行(流式版式按宿主宽逐行现算),超出保留行数的格要藏起;返回藏起的字段名与总行数 */
|
|
1052
1377
|
const filterRows = (): { hidden: Set<string>; rows: number } => {
|
|
1053
1378
|
const hidden = new Set<string>();
|
|
1054
1379
|
if (mode() !== 'filter') return { hidden, rows: 0 };
|
|
1055
1380
|
const keep = Math.max(1, Math.trunc(Number(P().collapsedRows) || 1));
|
|
1381
|
+
// 流式版式(定宽字段 + 紧跟的按钮):每行放几个字段取决于宿主宽度,按宿主实测宽逐行现算;量不到宽度时退回份数折行
|
|
1382
|
+
const flowWidth = flowHostRem();
|
|
1383
|
+
if (P().flow === true && flowWidth > 0) {
|
|
1384
|
+
const gap = KIT_FILTER_FLOW_GAP_REM;
|
|
1385
|
+
let used = 0;
|
|
1386
|
+
let line = 0;
|
|
1387
|
+
for (const c of cells()) {
|
|
1388
|
+
if (c.placeholder === true || c.component === '') continue;
|
|
1389
|
+
const w = flowCellRem(c.cellClass, flowWidth);
|
|
1390
|
+
if (used > 0 && used + gap + w > flowWidth + FLOW_EPS) { line += 1; used = 0; }
|
|
1391
|
+
used += (used > 0 ? gap : 0) + w;
|
|
1392
|
+
if (line >= keep) hidden.add(c.field);
|
|
1393
|
+
}
|
|
1394
|
+
return { hidden, rows: line + 1 };
|
|
1395
|
+
}
|
|
1056
1396
|
let acc = 0;
|
|
1057
1397
|
let row = 0;
|
|
1058
1398
|
for (const c of cells()) {
|
|
@@ -1070,124 +1410,148 @@ function createController(
|
|
|
1070
1410
|
return cells().filter((c) => c.placeholder !== true && c.component !== '' && !isBlank(vals[c.field])).length;
|
|
1071
1411
|
};
|
|
1072
1412
|
|
|
1073
|
-
// ── 远程选项(options.from):经 services.http
|
|
1074
|
-
/**
|
|
1413
|
+
// ── 远程选项(options.from):经 services.http 取 ──
|
|
1414
|
+
/** 选项源请求计划 */
|
|
1075
1415
|
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
1416
|
return planOptionSourceRequest({ route: of.from, params: of.params as SomaOptionSourceParams }, vals);
|
|
1082
1417
|
};
|
|
1418
|
+
const stringParamsOf = (raw: Rec): Record<string, string> => {
|
|
1419
|
+
const params: Record<string, string> = {};
|
|
1420
|
+
for (const [k, v] of Object.entries(raw)) if (v !== null && v !== undefined) params[k] = String(v);
|
|
1421
|
+
return params;
|
|
1422
|
+
};
|
|
1423
|
+
const keepLoadedRemoteOptions = (st: NonNullable<ReturnType<typeof remote.get>>, key: string): boolean => {
|
|
1424
|
+
if (st.loadedKey !== key) return false;
|
|
1425
|
+
// 返回仍已加载的 key 时保留现有候选,同时使另一 key 的迟到请求失效。
|
|
1426
|
+
if (st.inflightKey !== '' && st.inflightKey !== key) st.seq += 1;
|
|
1427
|
+
st.inflightKey = '';
|
|
1428
|
+
st.key = key;
|
|
1429
|
+
st.failedKey = '';
|
|
1430
|
+
st.pending = false;
|
|
1431
|
+
st.failed = false;
|
|
1432
|
+
st.error = false;
|
|
1433
|
+
return true;
|
|
1434
|
+
};
|
|
1435
|
+
const requestFieldOptions = (of: NonNullable<KitCell['optionsFrom']>, st: NonNullable<ReturnType<typeof remote.get>>, params: Record<string, string>, key: string): void => {
|
|
1436
|
+
st.inflightKey = key;
|
|
1437
|
+
st.key = key;
|
|
1438
|
+
st.failedKey = '';
|
|
1439
|
+
st.error = false;
|
|
1440
|
+
st.seq += 1;
|
|
1441
|
+
st.children?.clear();
|
|
1442
|
+
const mine = st.seq;
|
|
1443
|
+
void fetchRemoteOptionRows(api.services as unknown as Record<string, unknown> | undefined, of.from, params, of.rowsPath, api.host, effectiveEnvelope()).then((rows) => {
|
|
1444
|
+
if (!alive || st.seq !== mine) return;
|
|
1445
|
+
st.inflightKey = '';
|
|
1446
|
+
st.loadedKey = key;
|
|
1447
|
+
st.key = key;
|
|
1448
|
+
st.failedKey = '';
|
|
1449
|
+
st.error = false;
|
|
1450
|
+
st.rows = rows;
|
|
1451
|
+
repaint();
|
|
1452
|
+
}).catch(() => {
|
|
1453
|
+
if (!alive || st.seq !== mine) return;
|
|
1454
|
+
st.inflightKey = '';
|
|
1455
|
+
st.loadedKey = '';
|
|
1456
|
+
st.key = key;
|
|
1457
|
+
st.failedKey = key;
|
|
1458
|
+
st.error = true;
|
|
1459
|
+
st.rows = [];
|
|
1460
|
+
repaint();
|
|
1461
|
+
});
|
|
1462
|
+
};
|
|
1083
1463
|
const ensureOptions = (): void => {
|
|
1084
1464
|
const vals = draft.values();
|
|
1085
1465
|
for (const c of cells()) {
|
|
1086
1466
|
const of = c.optionsFrom;
|
|
1087
1467
|
if (of === undefined) continue;
|
|
1088
|
-
|
|
1468
|
+
// 候选由展示对象给出:不自取 options.from
|
|
1469
|
+
if (viewOptionsOf(c.field) !== undefined) continue;
|
|
1470
|
+
const st = remote.get(c.field) ?? { loadedKey: '', inflightKey: '', failedKey: '', key: '', rows: [], seq: 0, error: false };
|
|
1089
1471
|
remote.set(c.field, st);
|
|
1090
1472
|
// 请求参数构造与上游为空判定只用 foundation 的选项源计划(planOptionSourceRequest),kit 只补字符串化与搜索关键字
|
|
1091
1473
|
const plan = planFor(of, vals);
|
|
1092
1474
|
if (plan.action !== 'fetch') {
|
|
1093
|
-
if (st.
|
|
1475
|
+
if (st.loadedKey !== '' || st.inflightKey !== '' || st.key !== '' || st.failedKey !== '' || st.rows.length > 0 || st.error) {
|
|
1476
|
+
st.loadedKey = '';
|
|
1477
|
+
st.inflightKey = '';
|
|
1478
|
+
st.key = '';
|
|
1479
|
+
st.failedKey = '';
|
|
1480
|
+
st.rows = [];
|
|
1481
|
+
st.error = false;
|
|
1482
|
+
st.seq += 1;
|
|
1483
|
+
st.children?.clear();
|
|
1484
|
+
}
|
|
1094
1485
|
continue;
|
|
1095
1486
|
}
|
|
1096
|
-
const params
|
|
1097
|
-
for (const [k, v] of Object.entries(plan.params)) {
|
|
1098
|
-
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1099
|
-
}
|
|
1487
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1100
1488
|
if (of.searchParam !== '' && st.keyword !== undefined && st.keyword !== '') params[of.searchParam] = st.keyword;
|
|
1101
1489
|
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
|
-
});
|
|
1490
|
+
if (keepLoadedRemoteOptions(st, key)
|
|
1491
|
+
|| (st.key === key && st.inflightKey === key)
|
|
1492
|
+
|| (st.key === key && st.failedKey === key)) continue;
|
|
1493
|
+
requestFieldOptions(of, st, params, key);
|
|
1121
1494
|
}
|
|
1122
1495
|
ensureFlowOptions();
|
|
1123
1496
|
};
|
|
1124
1497
|
|
|
1125
1498
|
// ── H2a:FlowEditor 字段的节点配置动态选项(props.nodeTypes.<类型>.fields[].options 写成对象)──
|
|
1126
|
-
// 取数状态存在 remote
|
|
1499
|
+
// 取数状态存在 remote 表里(键带前缀,避免和字段名相撞);失败照实标出,不吞成空列表
|
|
1127
1500
|
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
|
-
|
|
1501
|
+
const requestFlowOptions = (slot: FlowOptionSlot, st: NonNullable<ReturnType<typeof remote.get>>, params: Record<string, string>, key: string): void => {
|
|
1502
|
+
st.inflightKey = key;
|
|
1503
|
+
st.key = key;
|
|
1504
|
+
st.failedKey = '';
|
|
1505
|
+
st.seq += 1;
|
|
1506
|
+
st.failed = false;
|
|
1507
|
+
st.error = false;
|
|
1508
|
+
st.pending = true;
|
|
1509
|
+
const mine = st.seq;
|
|
1510
|
+
void fetchRemoteOptionRows(api.services as unknown as Record<string, unknown> | undefined, slot.from, params, slot.rowsPath, api.host, effectiveEnvelope()).then((rows) => {
|
|
1511
|
+
if (!alive || st.seq !== mine) return;
|
|
1512
|
+
st.inflightKey = '';
|
|
1513
|
+
st.loadedKey = key;
|
|
1514
|
+
st.key = key;
|
|
1515
|
+
st.failedKey = '';
|
|
1516
|
+
st.rows = rows;
|
|
1517
|
+
st.pending = false;
|
|
1518
|
+
st.error = false;
|
|
1519
|
+
repaint();
|
|
1520
|
+
}).catch(() => {
|
|
1521
|
+
if (!alive || st.seq !== mine) return;
|
|
1522
|
+
st.inflightKey = '';
|
|
1523
|
+
st.loadedKey = '';
|
|
1524
|
+
st.key = key;
|
|
1525
|
+
st.failedKey = key;
|
|
1526
|
+
st.rows = [];
|
|
1527
|
+
st.pending = false;
|
|
1528
|
+
st.failed = true;
|
|
1529
|
+
st.error = true;
|
|
1530
|
+
repaint();
|
|
1531
|
+
});
|
|
1145
1532
|
};
|
|
1146
1533
|
const ensureFlowOptions = (): void => {
|
|
1147
1534
|
const vals = draft.values();
|
|
1148
1535
|
for (const c of cells()) {
|
|
1149
|
-
if (
|
|
1150
|
-
const slotList =
|
|
1536
|
+
if (c.component !== 'FlowEditor' || !isRec(c.props)) continue;
|
|
1537
|
+
const slotList = flowOptionSlots(c.props.nodeTypes);
|
|
1151
1538
|
for (const slot of slotList) {
|
|
1152
1539
|
const id = flowSlotKey(c.field, slot);
|
|
1153
|
-
const st = remote.get(id) ?? { key: '', rows: [], seq: 0 };
|
|
1540
|
+
const st = remote.get(id) ?? { loadedKey: '', inflightKey: '', failedKey: '', key: '', rows: [], seq: 0, error: false };
|
|
1154
1541
|
remote.set(id, st);
|
|
1155
1542
|
const plan = planOptionSourceRequest({ route: slot.from, params: slot.params as SomaOptionSourceParams }, vals);
|
|
1156
1543
|
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());
|
|
1544
|
+
if (st.loadedKey !== '' || st.inflightKey !== '' || st.key !== '' || st.failedKey !== '' || st.rows.length > 0 || st.failed === true || st.pending === true || st.error) {
|
|
1545
|
+
st.loadedKey = ''; st.inflightKey = ''; st.key = ''; st.failedKey = ''; st.rows = []; st.seq += 1; st.failed = false; st.pending = false; st.error = false;
|
|
1162
1546
|
}
|
|
1163
1547
|
continue;
|
|
1164
1548
|
}
|
|
1165
|
-
const params
|
|
1166
|
-
for (const [k, v] of Object.entries(plan.params)) {
|
|
1167
|
-
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1168
|
-
}
|
|
1549
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1169
1550
|
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
|
-
});
|
|
1551
|
+
if (keepLoadedRemoteOptions(st, key)
|
|
1552
|
+
|| (st.key === key && st.inflightKey === key)
|
|
1553
|
+
|| (st.key === key && st.failedKey === key)) continue;
|
|
1554
|
+
requestFlowOptions(slot, st, params, key);
|
|
1191
1555
|
}
|
|
1192
1556
|
}
|
|
1193
1557
|
};
|
|
@@ -1196,15 +1560,58 @@ function createController(
|
|
|
1196
1560
|
const st = remote.get(flowSlotKey(field, slot));
|
|
1197
1561
|
if (st === undefined) return { state: 'idle', options: [] };
|
|
1198
1562
|
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: [] };
|
|
1563
|
+
if (st.failed === true || st.error === true) return { state: 'failed', options: [] };
|
|
1564
|
+
if (st.loadedKey === '' && st.key === '') return { state: 'idle', options: [] };
|
|
1201
1565
|
return { state: 'ok', options: flowOptionsOfRows(slot, st.rows) };
|
|
1202
1566
|
};
|
|
1203
|
-
const flowPlaceholder = (state: string): string => (state === 'loading' ? kitText('soma.kit.rows_options_loading', undefined,
|
|
1567
|
+
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
1568
|
const flowNodeTypes = (field: string, nodeTypes: Rec): Rec => withFlowOptions(nodeTypes, flowResolver(field), flowPlaceholder);
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1569
|
+
const hasFailedOption = (c: KitCell): boolean => {
|
|
1570
|
+
if (viewOptionsOf(c.field) !== undefined) return false;
|
|
1571
|
+
const own = c.optionsFrom === undefined ? undefined : remote.get(c.field);
|
|
1572
|
+
if (own?.error === true && typeof own.failedKey === 'string' && own.failedKey !== '') return true;
|
|
1573
|
+
if (c.component !== 'FlowEditor' || !isRec(c.props)) return false;
|
|
1574
|
+
return flowOptionSlots(c.props.nodeTypes).some((slot) => {
|
|
1575
|
+
const st = remote.get(flowSlotKey(c.field, slot));
|
|
1576
|
+
return st?.error === true && typeof st.failedKey === 'string' && st.failedKey !== '';
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
1579
|
+
const retryOptions = (row: unknown): boolean => {
|
|
1580
|
+
syncDraft();
|
|
1581
|
+
const name = isRec(row) ? strOf(row.name) : typeof row === 'string' ? row : '';
|
|
1582
|
+
const c = cells().find((item) => item.field === name);
|
|
1583
|
+
if (c === undefined || detailBlocked() || viewOptionsOf(name) !== undefined) return true;
|
|
1584
|
+
const vals = draft.values();
|
|
1585
|
+
if (c.optionsFrom !== undefined) {
|
|
1586
|
+
const st = remote.get(name);
|
|
1587
|
+
if (st?.error !== true || typeof st.failedKey !== 'string' || st.failedKey === '') return true;
|
|
1588
|
+
const plan = planFor(c.optionsFrom, vals);
|
|
1589
|
+
if (plan.action !== 'fetch') { ensureOptions(); return true; }
|
|
1590
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1591
|
+
if (c.optionsFrom.searchParam !== '' && st.keyword !== undefined && st.keyword !== '') params[c.optionsFrom.searchParam] = st.keyword;
|
|
1592
|
+
const key = JSON.stringify(params);
|
|
1593
|
+
if (key !== st.failedKey) { ensureOptions(); return true; }
|
|
1594
|
+
requestFieldOptions(c.optionsFrom, st, params, key);
|
|
1595
|
+
repaint();
|
|
1596
|
+
return true;
|
|
1597
|
+
}
|
|
1598
|
+
if (c.component === 'FlowEditor' && isRec(c.props)) {
|
|
1599
|
+
let retried = false;
|
|
1600
|
+
for (const slot of flowOptionSlots(c.props.nodeTypes)) {
|
|
1601
|
+
const st = remote.get(flowSlotKey(name, slot));
|
|
1602
|
+
if (st?.error !== true || typeof st.failedKey !== 'string' || st.failedKey === '') continue;
|
|
1603
|
+
const plan = planOptionSourceRequest({ route: slot.from, params: slot.params as SomaOptionSourceParams }, vals);
|
|
1604
|
+
if (plan.action !== 'fetch') { ensureFlowOptions(); continue; }
|
|
1605
|
+
const params = stringParamsOf(plan.params as Rec);
|
|
1606
|
+
const key = JSON.stringify(params);
|
|
1607
|
+
if (key !== st.failedKey) { ensureFlowOptions(); continue; }
|
|
1608
|
+
requestFlowOptions(slot, st, params, key);
|
|
1609
|
+
retried = true;
|
|
1610
|
+
}
|
|
1611
|
+
if (retried) repaint();
|
|
1612
|
+
}
|
|
1613
|
+
return true;
|
|
1614
|
+
};
|
|
1208
1615
|
|
|
1209
1616
|
/** 级联按层懒加载:展开一个 lazy 节点时,以 `<lazy>=<该节点值>` 重取它的子级(根层参数同选项源计划) */
|
|
1210
1617
|
const loadChildren = (c: KitCell, path: readonly string[]): void => {
|
|
@@ -1218,18 +1625,86 @@ function createController(
|
|
|
1218
1625
|
if (v !== null && v !== undefined) params[k] = String(v);
|
|
1219
1626
|
}
|
|
1220
1627
|
params[of.tree.lazy] = path[path.length - 1]!;
|
|
1221
|
-
const http = (
|
|
1628
|
+
const http = (api.services as { http?: { get<T>(url: string, config?: { params?: Record<string, string> }): Promise<T>; baseURL?: unknown } } | undefined)?.http;
|
|
1222
1629
|
if (!http) return;
|
|
1223
1630
|
const rawBase = http.baseURL;
|
|
1224
1631
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
1225
|
-
const
|
|
1632
|
+
const apiPath = baseURL !== '' && baseURL !== '/' && of.from.startsWith(`${baseURL}/`) ? of.from.slice(baseURL.length) : of.from;
|
|
1226
1633
|
const mine = st.seq;
|
|
1227
1634
|
const store = (rows: Rec[]): void => {
|
|
1228
1635
|
if (!alive || st.seq !== mine) return;
|
|
1229
1636
|
(st.children ??= new Map<string, Rec[]>()).set(cascadeKey(path), rows);
|
|
1230
1637
|
repaint();
|
|
1231
1638
|
};
|
|
1232
|
-
void http.get<unknown>(
|
|
1639
|
+
void http.get<unknown>(apiPath, { params }).then((res) => store(rowsOfOptionsResponse(res, of.rowsPath, effectiveEnvelope(), api.host))).catch(() => store([]));
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
/** 字段是否必填(编译期 required / 展示对象绑定 / props.required / 规则 required);筛选模式与占位格不算 */
|
|
1643
|
+
const isRequiredCell = (c: KitCell): boolean => {
|
|
1644
|
+
if (mode() === 'filter' || c.placeholder === true) return false;
|
|
1645
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1646
|
+
const rawRules = Array.isArray((c as unknown as Rec).rules)
|
|
1647
|
+
? ((c as unknown as Rec).rules as unknown[])
|
|
1648
|
+
: Array.isArray(props.rules) ? (props.rules as unknown[]) : [];
|
|
1649
|
+
return c.required !== undefined || props.required === true || stateOf(c.field).required || rawRules.some((r) => isRec(r) && r.required === true);
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
// ── J8:绑定候选(options: view.<成员>)被替换且不再含当前值 -> 经表单正常改值通道清掉旧值(表单与筛选栏同一套;组件行为,不进页面语法)──
|
|
1653
|
+
// 「已加载」判据只用 viewOptionsOf 已有的状态:成员此刻是数组才有判断依据(未绑定 / 成员还不是数组 = 未加载,不动);
|
|
1654
|
+
// 候选值集合此前出现过非空、之后变化(含变成显式空数组)才清;第一次到达(含首次非空)与从未非空的空数组都不动。
|
|
1655
|
+
// 候选值集合没变(只是引用换了 / 标签变了)不清;静态候选与远程候选(options.from)不在此列(viewOptionsOf 为 undefined);
|
|
1656
|
+
// 带 children 的层级候选(Cascader / Tree 的路径值)不是平铺候选,不处理。
|
|
1657
|
+
const optionTrack = new Map<string, { sig: string; seenNonEmpty: boolean }>();
|
|
1658
|
+
let staleQueued = false;
|
|
1659
|
+
const flatOptionValues = (opts: Rec[]): Set<string> | null => {
|
|
1660
|
+
const out = new Set<string>();
|
|
1661
|
+
for (const o of opts) {
|
|
1662
|
+
if (Array.isArray(o.children) && o.children.length > 0) return null;
|
|
1663
|
+
out.add(String(o.value));
|
|
1664
|
+
}
|
|
1665
|
+
return out;
|
|
1666
|
+
};
|
|
1667
|
+
/** 旧值在这批候选里的去留:返回 undefined = 不用动;否则是要写回的新值(单值 -> '',多值 -> 去掉缺席项) */
|
|
1668
|
+
const staleReplacement = (current: unknown, valid: ReadonlySet<string>): unknown => {
|
|
1669
|
+
if (Array.isArray(current)) {
|
|
1670
|
+
const kept = current.filter((x) => (x !== null && typeof x === 'object') || valid.has(String(x)));
|
|
1671
|
+
return kept.length === current.length ? undefined : kept;
|
|
1672
|
+
}
|
|
1673
|
+
if (current === undefined || current === null || current === '' || typeof current === 'object') return undefined;
|
|
1674
|
+
return valid.has(String(current)) ? undefined : '';
|
|
1675
|
+
};
|
|
1676
|
+
const sweepStaleViewOptions = (): void => {
|
|
1677
|
+
if (staleQueued || detailBlocked()) return;
|
|
1678
|
+
const changed: string[] = [];
|
|
1679
|
+
for (const c of cells()) {
|
|
1680
|
+
const cur = viewOptionsOf(c.field);
|
|
1681
|
+
if (cur === undefined) continue;
|
|
1682
|
+
const valid = flatOptionValues(cur);
|
|
1683
|
+
if (valid === null) continue;
|
|
1684
|
+
const sig = JSON.stringify([...valid]);
|
|
1685
|
+
const t = optionTrack.get(c.field);
|
|
1686
|
+
if (t !== undefined && t.sig === sig) continue;
|
|
1687
|
+
// 只在「到达过非空候选之后再变化」时清;第一次到达不清——编辑态已加载的旧值可能不在候选里(如已停用的选项),不能被悄悄抹掉
|
|
1688
|
+
const act = t?.seenNonEmpty === true;
|
|
1689
|
+
optionTrack.set(c.field, { sig, seenNonEmpty: cur.length > 0 || t?.seenNonEmpty === true });
|
|
1690
|
+
if (act) changed.push(c.field);
|
|
1691
|
+
}
|
|
1692
|
+
if (changed.length === 0) return;
|
|
1693
|
+
staleQueued = true;
|
|
1694
|
+
// 异步清(不在渲染读口里重入);逐字段走 onFieldChange(与 ctx.form().set 同一条通道:校验、draft_change{source:'api'}、重绘各一次)
|
|
1695
|
+
queueMicrotask(() => {
|
|
1696
|
+
staleQueued = false;
|
|
1697
|
+
if (!alive || detailBlocked()) return;
|
|
1698
|
+
const only = mode() === 'edit' ? createOnly() : new Set<string>();
|
|
1699
|
+
for (const field of changed) {
|
|
1700
|
+
if (only.has(field)) continue;
|
|
1701
|
+
const cur = viewOptionsOf(field);
|
|
1702
|
+
const valid = cur === undefined ? null : flatOptionValues(cur);
|
|
1703
|
+
if (valid === null) continue;
|
|
1704
|
+
const next = staleReplacement(draft.values()[field], valid);
|
|
1705
|
+
if (next !== undefined) (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value: next, __viaHandle: true });
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1233
1708
|
};
|
|
1234
1709
|
|
|
1235
1710
|
const buildRows = (): KitFormRow[] => {
|
|
@@ -1237,40 +1712,15 @@ function createController(
|
|
|
1237
1712
|
const only = createOnly();
|
|
1238
1713
|
const values = draft.values();
|
|
1239
1714
|
const rows: KitFormRow[] = [];
|
|
1240
|
-
const noGroup = { groupId: '', groupExpanded: '', groupControls: '', groupMark: '', groupToggleClass: '', bodyClass: FORM_BODY_CLASS
|
|
1715
|
+
const noGroup = { groupId: '', groupExpanded: '', groupControls: '', groupMark: '', groupToggleClass: '', bodyClass: FORM_BODY_CLASS };
|
|
1241
1716
|
const tabs = P().groupTabs === true && m !== 'filter';
|
|
1242
1717
|
const hiddenRows = hiddenByFilterCollapse();
|
|
1243
|
-
const heads: KitFormRow[] = [];
|
|
1244
1718
|
for (const c of cells()) {
|
|
1245
1719
|
// 页签模式:分组分隔线不画(页签本身就是分隔)
|
|
1246
1720
|
if (tabs && c.divider === true) continue;
|
|
1247
1721
|
// 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
|
-
}
|
|
1722
|
+
// 页签模式:标题格不进字段栅格(页签画在独立的 tablist 条里,见 buildTabRows)
|
|
1723
|
+
if (c.group?.head === true && tabs) continue;
|
|
1274
1724
|
if (c.group?.head === true) {
|
|
1275
1725
|
const g = c.group;
|
|
1276
1726
|
const collapsible = g.collapsible === true;
|
|
@@ -1295,68 +1745,144 @@ function createController(
|
|
|
1295
1745
|
groupMark: isOpen ? markers[1] : markers[0],
|
|
1296
1746
|
groupToggleClass: KIT_FORM_CLASS.groupToggle,
|
|
1297
1747
|
bodyClass: '',
|
|
1298
|
-
tabPressed: '',
|
|
1299
|
-
tabClass: '',
|
|
1300
1748
|
});
|
|
1301
1749
|
continue;
|
|
1302
1750
|
}
|
|
1303
1751
|
const hiddenByGroup = (c.group !== undefined && (tabs ? c.group.id !== activeTab : collapsed.has(c.group.id)))
|
|
1304
|
-
||
|
|
1752
|
+
|| hiddenRows.has(c.field)
|
|
1753
|
+
|| stateOf(c.field).hidden;
|
|
1305
1754
|
const readOnlyHere = m === 'edit' && only.has(c.field);
|
|
1306
|
-
|
|
1755
|
+
// 状态呈现表(design statePresentation.createOnlyInEdit):有 disabled prop 的控件画成禁用控件(保留原控件形态与选项),没有的回退纯文本
|
|
1756
|
+
const keepAsDisabled = readOnlyHere && c.component !== '' && nameSet.has(c.component) && 'disabled' in (registered[c.component]?.contract.props ?? {});
|
|
1757
|
+
const wanted = c.placeholder === true || c.component === '' ? '' : readOnlyHere && !keepAsDisabled ? 'Text' : c.component;
|
|
1307
1758
|
const component = wanted === '' ? FALLBACK_ROLE : nameSet.has(wanted) ? wanted : FALLBACK_ROLE;
|
|
1308
1759
|
const id = `kit-${objectName()}-${c.field}`;
|
|
1309
1760
|
const error = errors[c.field] ?? '';
|
|
1310
|
-
|
|
1311
|
-
const
|
|
1761
|
+
const value = values[c.field];
|
|
1762
|
+
const st = remote.get(c.field);
|
|
1763
|
+
const optionsRetry = !readOnlyHere && hasFailedOption(c);
|
|
1312
1764
|
const given = isRec(c.props) ? c.props : {};
|
|
1313
1765
|
const pv: Rec = { ...propDefaults(registered[component]), ...given };
|
|
1314
1766
|
if (readOnlyHere) {
|
|
1315
|
-
// 只读展示:保留格式与选项,丢掉输入态的 prop
|
|
1767
|
+
// 只读展示:保留格式与选项,丢掉输入态的 prop;禁用控件形态保留 disabled(下面置 true),同样不留占位提示
|
|
1316
1768
|
delete pv.disabled;
|
|
1317
1769
|
delete pv.readonly;
|
|
1318
1770
|
delete pv.placeholder;
|
|
1771
|
+
if (keepAsDisabled) pv.disabled = true;
|
|
1319
1772
|
}
|
|
1320
1773
|
pv.value = value;
|
|
1774
|
+
if (component === 'RowEditor') pv.cell_errors = error !== '' ? rowsCellErrorsOf(c) : [];
|
|
1321
1775
|
pv.id = id;
|
|
1322
1776
|
pv.name = c.field;
|
|
1323
1777
|
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;
|
|
1778
|
+
if (!readOnlyHere && (isBusy() || P().disabled === true || given.disabled === true || stateOf(c.field).disabled) && 'disabled' in pv) pv.disabled = true;
|
|
1326
1779
|
// 远程选项:候选来自 http(依赖值缺失时为空)
|
|
1327
1780
|
if (c.optionsFrom !== undefined) {
|
|
1328
1781
|
const of = c.optionsFrom;
|
|
1329
|
-
const st = remote.get(c.field);
|
|
1330
1782
|
pv.options = of.tree !== undefined
|
|
1331
1783
|
? cascadeOptions(st?.rows ?? [], of, of.tree, st?.children ?? new Map<string, Rec[]>(), [])
|
|
1332
1784
|
: (st?.rows ?? []).map((r) => ({ value: r[of.valueKey], label: strOf(r[of.labelKey], strOf(r[of.valueKey])) }));
|
|
1785
|
+
if (st?.inflightKey !== '' && st?.inflightKey !== undefined) {
|
|
1786
|
+
pv.loading = true;
|
|
1787
|
+
if (!readOnlyHere && (pv.placeholder === undefined || pv.placeholder === '')) {
|
|
1788
|
+
pv.placeholder = kitText('soma.kit.rows_options_loading', undefined, api.host);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
if (st?.error === true || st?.failed === true) {
|
|
1792
|
+
pv.optionsError = true;
|
|
1793
|
+
if (!readOnlyHere) {
|
|
1794
|
+
pv.placeholder = kitText('soma.kit.rows_options_failed', undefined, api.host);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
// 契约声明了 error_text 的组件(如 RecordPicker):失败文案下传,未失败为空串
|
|
1798
|
+
const declared = registered[component]?.contract.props ?? {};
|
|
1799
|
+
if ('error_text' in declared) {
|
|
1800
|
+
pv.error_text = st?.error === true || st?.failed === true ? kitText('soma.kit.rows_options_failed', undefined, api.host) : '';
|
|
1801
|
+
}
|
|
1802
|
+
// 远程搜索字段(options.searchParam):契约有 search_delay 的组件(Combobox)缺省按 design 的搜索防抖(search.debounceMs)去抖,
|
|
1803
|
+
// 不每敲一个字发一次请求;页面在 props 里显式给了 search_delay 时以页面为准
|
|
1804
|
+
if ('search_delay' in declared && of.searchParam !== '' && given.search_delay === undefined) {
|
|
1805
|
+
pv.search_delay = String(SOMA_QUERY_LIMITS_CORE.queryLimits.searchDebounceMs);
|
|
1806
|
+
}
|
|
1807
|
+
// 契约用 data 承载候选行(无 options)的组件:候选下传为 { id, title },有 searchParam 时开远程搜索
|
|
1808
|
+
if ('data' in declared && !('options' in declared) && given.data === undefined) {
|
|
1809
|
+
pv.data = (pv.options as Array<{ value: unknown; label: unknown }>).map((o) => ({ id: o.value, title: o.label }));
|
|
1810
|
+
if ('remote_search' in declared && of.searchParam !== '' && given.remote_search === undefined) pv.remote_search = true;
|
|
1811
|
+
}
|
|
1333
1812
|
}
|
|
1813
|
+
// 展示对象给出的候选项(options: view.<成员>):优先于静态 / 远程候选,只在 'options' 属性存在的组件上生效
|
|
1814
|
+
const viewOptions = viewOptionsOf(c.field);
|
|
1815
|
+
if (viewOptions !== undefined) pv.options = viewOptions;
|
|
1334
1816
|
// H2a:画布字段的节点配置动态选项(取到的并进 nodeTypes,画布只认静态选项)
|
|
1335
|
-
if (component === 'FlowEditor' && isRec(pv.nodeTypes)) pv.nodeTypes = flowNodeTypes(c.field, pv.nodeTypes);
|
|
1336
|
-
//
|
|
1337
|
-
if (component === '
|
|
1817
|
+
if (c.component === 'FlowEditor' && isRec(pv.nodeTypes)) pv.nodeTypes = flowNodeTypes(c.field, pv.nodeTypes);
|
|
1818
|
+
// 展示对象给出的节点字段候选项(nodeOptions: view.<成员>):交画布并进 nodeTypes,随展示对象整体替换引用重绘
|
|
1819
|
+
if (c.component === 'FlowEditor') { const nodeOptions = viewNodeOptionsOf(c.field); if (nodeOptions !== undefined) pv.nodeOptions = nodeOptions; }
|
|
1820
|
+
// 展示对象持有的 AI 建议(suggestions: view.<成员>):画布画成虚影;采纳 / 忽略经 draft_change 的 suggestion 载荷回到展示对象(整体替换引用即重绘)
|
|
1821
|
+
if (c.component === 'FlowEditor') { const suggestions = viewSuggestionsOf(c.field); if (suggestions !== undefined) pv.suggestions = suggestions; }
|
|
1822
|
+
// 展示对象给出的子表列候选项(columnOptions: view.<成员>):并进 columns 里对应 select 列的 options(整体替换引用即重绘)
|
|
1823
|
+
if (c.component === 'RowEditor') { const columnOptions = viewColumnOptionsOf(c.field); if (columnOptions !== undefined && Array.isArray(pv.columns)) pv.columns = withColumnOptions(pv.columns, columnOptions); }
|
|
1824
|
+
// 无障碍关联:名字(可见标签)/ 必填 / 无效 / 说明与错误节点全部经 props 交给控件自己写(重绘不丢),表单不再往宿主外写 aria-*
|
|
1825
|
+
const labelId = fieldNodeId(c.field, 'lbl');
|
|
1826
|
+
const helpNodeId = fieldNodeId(c.field, 'help');
|
|
1827
|
+
const errNodeId = fieldNodeId(c.field, 'err');
|
|
1828
|
+
// 说明走标签旁的「i」气泡而不占行高:只读行(create-only 的编辑态)与筛选区一律如此(筛选条一行放不下说明行,说明行把筛选栏撑高)
|
|
1829
|
+
const helpAsTip = readOnlyHere || m === 'filter';
|
|
1830
|
+
const helpText = helpAsTip ? '' : strOf(c.help);
|
|
1831
|
+
// 禁用控件仍是控件:名字照常关联(纯文本回退没有控件,不需要)
|
|
1832
|
+
if (!readOnlyHere || keepAsDisabled) {
|
|
1833
|
+
if (c.placeholder !== true && c.label !== '' && given.labelledby === undefined) pv.labelledby = labelId;
|
|
1834
|
+
}
|
|
1835
|
+
if (!readOnlyHere) {
|
|
1836
|
+
if (isRequiredCell(c)) pv.required = true;
|
|
1837
|
+
if (error !== '' || given.invalid === true) pv.invalid = true;
|
|
1838
|
+
const described = [strOf(given.describedby), helpText !== '' ? helpNodeId : '', error !== '' ? errNodeId : ''].filter((t) => t !== '');
|
|
1839
|
+
if (described.length > 0) pv.describedby = described.join(' ');
|
|
1840
|
+
}
|
|
1841
|
+
const optionCount = Array.isArray(pv.options) ? pv.options.length : 0;
|
|
1842
|
+
const groupLike = component === 'Radio' || (component === 'Checkbox' && optionCount > 0);
|
|
1338
1843
|
rows.push({
|
|
1339
1844
|
id,
|
|
1845
|
+
labelId,
|
|
1846
|
+
helpNodeId,
|
|
1847
|
+
errNodeId,
|
|
1848
|
+
labelFor: groupLike ? '' : id,
|
|
1340
1849
|
name: c.field,
|
|
1341
1850
|
component,
|
|
1342
1851
|
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 }),
|
|
1852
|
+
...starFields(c, readOnlyHere),
|
|
1348
1853
|
...noGroup,
|
|
1349
1854
|
cellClass: hiddenByGroup ? 'hidden' : cellClassOf(c),
|
|
1350
1855
|
labelClass: labelClassOf(c),
|
|
1351
1856
|
errorClass: error === '' ? KIT_FORM_CLASS.errorHidden : (c.errorClass.split(/\s+/).filter((t) => t !== '' && t !== 'hidden').join(' ') || KIT_FORM_CLASS.error),
|
|
1352
1857
|
error,
|
|
1353
|
-
help:
|
|
1354
|
-
helpClass: !
|
|
1858
|
+
help: helpAsTip ? '' : strOf(c.help),
|
|
1859
|
+
helpClass: !helpAsTip && strOf(c.help) !== '' ? KIT_FORM_CLASS.help : KIT_FORM_CLASS.errorHidden,
|
|
1860
|
+
...readOnlyHelpTip(c, helpAsTip),
|
|
1861
|
+
optionsRetry,
|
|
1862
|
+
optionsRetryClass: optionsRetry ? OPTIONS_RETRY_CLASS : KIT_FORM_CLASS.errorHidden,
|
|
1863
|
+
optionsRetryText: kitText('soma.kit.ct_retry', undefined, api.host),
|
|
1355
1864
|
text: isBlank(value) ? '' : strOf(value),
|
|
1356
1865
|
pv,
|
|
1357
1866
|
});
|
|
1358
1867
|
}
|
|
1359
|
-
return
|
|
1868
|
+
return rows;
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
/** 页签条的行(仅 groupTabs 且非 filter 模式;详情取数中不画) */
|
|
1872
|
+
const buildTabRows = (): KitFormTabRow[] => {
|
|
1873
|
+
if (P().groupTabs !== true || mode() === 'filter' || detailBlocked()) return [];
|
|
1874
|
+
const out: KitFormTabRow[] = [];
|
|
1875
|
+
for (const c of cells()) {
|
|
1876
|
+
if (c.group?.head !== true) continue;
|
|
1877
|
+
out.push({
|
|
1878
|
+
id: `kit-${objectName()}-${c.field}`,
|
|
1879
|
+
label: c.label,
|
|
1880
|
+
groupId: c.group.id,
|
|
1881
|
+
selected: activeTab === c.group.id ? 'true' : 'false',
|
|
1882
|
+
tabClass: FL.groupsAs.tabClass,
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
return out;
|
|
1360
1886
|
};
|
|
1361
1887
|
|
|
1362
1888
|
const fieldErrorsFor = (raw: Record<string, string>): Record<string, string> => {
|
|
@@ -1366,6 +1892,51 @@ function createController(
|
|
|
1366
1892
|
return out;
|
|
1367
1893
|
};
|
|
1368
1894
|
|
|
1895
|
+
const syncInvalidFields = (): void => {
|
|
1896
|
+
invalidFields.clear();
|
|
1897
|
+
for (const [k, msg] of Object.entries(errors)) {
|
|
1898
|
+
if (msg !== '') invalidFields.add(k);
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1902
|
+
/** 单字段静态 / 动态规则校验(rules / 必填 / FlowEditor / RowEditor) */
|
|
1903
|
+
const validateCellRule = (name: string): string => {
|
|
1904
|
+
const c = cells().find((x) => x.field === name);
|
|
1905
|
+
if (!c || c.placeholder === true || !editableSet().has(name)) return '';
|
|
1906
|
+
const st = stateOf(name);
|
|
1907
|
+
const props = isRec(c.props) ? c.props : {};
|
|
1908
|
+
if (st.hidden || st.disabled || props.disabled === true || props.readonly === true) return '';
|
|
1909
|
+
const val = draft.values()[name];
|
|
1910
|
+
const rawRules = Array.isArray((c as unknown as Rec).rules)
|
|
1911
|
+
? ((c as unknown as Rec).rules as unknown[])
|
|
1912
|
+
: Array.isArray(props.rules)
|
|
1913
|
+
? (props.rules as unknown[])
|
|
1914
|
+
: [];
|
|
1915
|
+
for (const r of rawRules) {
|
|
1916
|
+
if (!isRec(r)) continue;
|
|
1917
|
+
const msg = strOf(r.message) || kitText('soma.kit.field_required', undefined, api.host);
|
|
1918
|
+
if (r.required === true && isBlank(val)) return msg;
|
|
1919
|
+
if (!isBlank(val)) {
|
|
1920
|
+
const minLen = typeof r.min_len === 'number' ? r.min_len : typeof r.minLength === 'number' ? r.minLength : undefined;
|
|
1921
|
+
if (minLen !== undefined && String(val).length < minLen) return msg;
|
|
1922
|
+
const maxLen = typeof r.max_len === 'number' ? r.max_len : typeof r.maxLength === 'number' ? r.maxLength : undefined;
|
|
1923
|
+
if (maxLen !== undefined && String(val).length > maxLen) return msg;
|
|
1924
|
+
// 与字段规则同一份带防护的正则实现:模式非法 / 超长(null)放行,被测文本超长视为不通过且不执行匹配
|
|
1925
|
+
if (typeof r.pattern === 'string' && r.pattern !== '' && testRegexGuarded(r.pattern, String(val)) === false) return msg;
|
|
1926
|
+
if (typeof r.min === 'number' && Number(val) < r.min) return msg;
|
|
1927
|
+
if (typeof r.max === 'number' && Number(val) > r.max) return msg;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
if ((c.required !== undefined || props.required === true || st.required) && isBlank(val)) {
|
|
1931
|
+
return kitText('soma.kit.field_required', undefined, api.host);
|
|
1932
|
+
}
|
|
1933
|
+
const flowErr = flowFieldErrors()[name];
|
|
1934
|
+
if (flowErr !== undefined) return flowErr;
|
|
1935
|
+
const rowErr = rowsFieldErrors()[name];
|
|
1936
|
+
if (rowErr !== undefined) return rowErr;
|
|
1937
|
+
return '';
|
|
1938
|
+
};
|
|
1939
|
+
|
|
1369
1940
|
// ── 写入结果回显 ──
|
|
1370
1941
|
const onOutcome = (scope: string): void => {
|
|
1371
1942
|
if (scope !== scopeKey()) return;
|
|
@@ -1374,6 +1945,7 @@ function createController(
|
|
|
1374
1945
|
if (view.status === 'pending') {
|
|
1375
1946
|
if (view.seq <= pendingSeq || view.seq <= settledSeq) return;
|
|
1376
1947
|
pendingSeq = view.seq;
|
|
1948
|
+
rememberFocus();
|
|
1377
1949
|
busy = true;
|
|
1378
1950
|
repaint();
|
|
1379
1951
|
return;
|
|
@@ -1386,24 +1958,30 @@ function createController(
|
|
|
1386
1958
|
busy = false;
|
|
1387
1959
|
conflict = false;
|
|
1388
1960
|
errors = fieldErrorsFor({ ...view.fieldErrors });
|
|
1961
|
+
syncInvalidFields();
|
|
1389
1962
|
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,
|
|
1963
|
+
notice = Object.keys(errors).length > 0 ? '' : (view.message !== '' ? view.message : kitText(FAILED_FALLBACK, undefined, api.host));
|
|
1964
|
+
revealFirstErrorGroup();
|
|
1965
|
+
pendingScroll = P().scrollToError !== false;
|
|
1391
1966
|
break;
|
|
1392
1967
|
}
|
|
1393
1968
|
case 'conflict':
|
|
1394
1969
|
busy = false;
|
|
1395
1970
|
conflict = true;
|
|
1396
1971
|
errors = {};
|
|
1397
|
-
|
|
1972
|
+
syncInvalidFields();
|
|
1973
|
+
notice = view.message !== '' ? view.message : kitText(CONFLICT_FALLBACK, undefined, api.host);
|
|
1398
1974
|
break;
|
|
1399
1975
|
case 'saved':
|
|
1400
1976
|
busy = false;
|
|
1401
1977
|
conflict = false;
|
|
1402
1978
|
errors = {};
|
|
1979
|
+
syncInvalidFields();
|
|
1403
1980
|
notice = '';
|
|
1981
|
+
resetFocusRestore();
|
|
1404
1982
|
draft.markSaved();
|
|
1405
|
-
|
|
1406
|
-
|
|
1983
|
+
syncDirtyEmit();
|
|
1984
|
+
api.emit('saved', { object: objectName(), scope: scopeKey(), result: view.result });
|
|
1407
1985
|
break;
|
|
1408
1986
|
default:
|
|
1409
1987
|
busy = false;
|
|
@@ -1411,15 +1989,39 @@ function createController(
|
|
|
1411
1989
|
repaint();
|
|
1412
1990
|
};
|
|
1413
1991
|
|
|
1414
|
-
/**
|
|
1992
|
+
/** 首次失焦后校验(focusout / blur),已出错或已触碰字段改动即复校(Reward Early, Punish Late) */
|
|
1415
1993
|
const instantValidate = (trigger: 'change' | 'blur', name: string): void => {
|
|
1416
|
-
if (mode() === 'filter' || !
|
|
1994
|
+
if (mode() === 'filter' || !editableSet().has(name)) return;
|
|
1995
|
+
if (trigger === 'blur') {
|
|
1996
|
+
touchedFields.add(name);
|
|
1997
|
+
} else if (!invalidFields.has(name) && !touchedFields.has(name) && !stringList(P().validateOn).includes('change')) {
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
1417
2000
|
const port = dataPort();
|
|
1418
|
-
|
|
1419
|
-
|
|
2001
|
+
let msg = '';
|
|
2002
|
+
if (port?.validate) {
|
|
2003
|
+
const bad = port.validate(strOf(P().dictObject) || objectName(), validationValues(), trigger);
|
|
2004
|
+
const isStaticSubmitStub =
|
|
2005
|
+
trigger === 'change' &&
|
|
2006
|
+
!touchedFields.has(name) &&
|
|
2007
|
+
!stringList(P().validateOn).includes('change') &&
|
|
2008
|
+
bad === lastSubmitVerdictRef &&
|
|
2009
|
+
!isBlank(draft.get(name));
|
|
2010
|
+
if (!isStaticSubmitStub && typeof bad[name] === 'string' && bad[name] !== '') {
|
|
2011
|
+
msg = bad[name]!;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
if (msg === '') {
|
|
2015
|
+
msg = validateCellRule(name);
|
|
2016
|
+
}
|
|
1420
2017
|
const next = { ...errors };
|
|
1421
|
-
if (
|
|
1422
|
-
|
|
2018
|
+
if (msg !== '') {
|
|
2019
|
+
next[name] = msg;
|
|
2020
|
+
invalidFields.add(name);
|
|
2021
|
+
} else {
|
|
2022
|
+
delete next[name];
|
|
2023
|
+
invalidFields.delete(name);
|
|
2024
|
+
}
|
|
1423
2025
|
errors = next;
|
|
1424
2026
|
};
|
|
1425
2027
|
|
|
@@ -1428,15 +2030,16 @@ function createController(
|
|
|
1428
2030
|
syncDraft();
|
|
1429
2031
|
const m = mode();
|
|
1430
2032
|
// 阶段闸门不满足:提交被拦(按钮已禁用且原因常驻显示;回车提交同样被拦)
|
|
1431
|
-
if (isBusy() || P().disabled === true ||
|
|
2033
|
+
if (isBusy() || P().disabled === true || (m !== 'filter' && P().submitDisabled === true)) return true;
|
|
1432
2034
|
if (m === 'filter') {
|
|
1433
|
-
|
|
2035
|
+
api.emit('submit', { values: collectFilter(), object: objectName(), scope: scopeKey(), mode: 'filter' });
|
|
1434
2036
|
return true;
|
|
1435
2037
|
}
|
|
1436
2038
|
const port = dataPort();
|
|
1437
2039
|
{
|
|
1438
2040
|
const dictKey = strOf(P().dictObject) || objectName();
|
|
1439
2041
|
const verdict: Record<string, string> = port?.validate ? port.validate(dictKey, validationValues()) : {};
|
|
2042
|
+
lastSubmitVerdictRef = port?.validate ? verdict : null;
|
|
1440
2043
|
const bad: Record<string, string> = fieldErrorsFor(verdict);
|
|
1441
2044
|
const editable = editableSet();
|
|
1442
2045
|
for (const k of Object.keys(bad)) if (!editable.has(k)) delete bad[k];
|
|
@@ -1444,28 +2047,47 @@ function createController(
|
|
|
1444
2047
|
const hiddenBad = hiddenNames().filter((n) => editable.has(n) && typeof verdict[n] === 'string' && verdict[n] !== '');
|
|
1445
2048
|
if (hiddenBad.length > 0) {
|
|
1446
2049
|
errors = bad;
|
|
1447
|
-
|
|
2050
|
+
syncInvalidFields();
|
|
2051
|
+
notice = kitText('soma.kit.hidden_invalid', { field: hiddenBad[0]!, message: verdict[hiddenBad[0]!]! }, api.host);
|
|
1448
2052
|
pendingScroll = false;
|
|
1449
2053
|
repaint();
|
|
1450
2054
|
return true;
|
|
1451
2055
|
}
|
|
1452
2056
|
// GB4:流程画布字段必填时至少要有一个节点
|
|
1453
2057
|
for (const [k, message] of Object.entries(flowFieldErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
2058
|
+
// 展示对象绑定的必填
|
|
2059
|
+
for (const [k, message] of Object.entries(boundRequiredErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
1454
2060
|
// 子表字段(RowEditor):列上的 required / pattern / 数值范围与行数上下限,逐行校验(字段级 rules 已由字典判过必填)
|
|
1455
2061
|
for (const [k, message] of Object.entries(rowsFieldErrors())) if (bad[k] === undefined) bad[k] = message;
|
|
2062
|
+
// 字段级显式 rules(cell.rules / cell.props.rules)
|
|
2063
|
+
for (const c of cells()) {
|
|
2064
|
+
if (c.placeholder === true || !editable.has(c.field) || bad[c.field] !== undefined) continue;
|
|
2065
|
+
const hasExplicitRules = Array.isArray((c as unknown as Rec).rules) || (isRec(c.props) && Array.isArray(c.props.rules));
|
|
2066
|
+
if (hasExplicitRules) {
|
|
2067
|
+
const ruleMsg = validateCellRule(c.field);
|
|
2068
|
+
if (ruleMsg !== '') bad[c.field] = ruleMsg;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
1456
2071
|
if (Object.keys(bad).length > 0) {
|
|
1457
2072
|
errors = bad;
|
|
2073
|
+
syncInvalidFields();
|
|
1458
2074
|
notice = '';
|
|
1459
|
-
|
|
2075
|
+
revealFirstErrorGroup();
|
|
2076
|
+
pendingScroll = P().scrollToError !== false;
|
|
1460
2077
|
repaint();
|
|
1461
2078
|
return true;
|
|
1462
2079
|
}
|
|
1463
2080
|
}
|
|
1464
2081
|
errors = {};
|
|
2082
|
+
syncInvalidFields();
|
|
1465
2083
|
notice = '';
|
|
2084
|
+
resetFocusRestore();
|
|
2085
|
+
rememberFocus();
|
|
1466
2086
|
const model = collectModel();
|
|
1467
|
-
|
|
1468
|
-
|
|
2087
|
+
// 状态呈现表 createOnlyInEdit:值不进更新载荷(values 与 model 一致,不带 create-only 字段)
|
|
2088
|
+
const submitValues = m === 'edit' ? Object.fromEntries(Object.entries(draft.values()).filter(([k]) => !createOnly().has(k))) : draft.values();
|
|
2089
|
+
api.emit('submit', {
|
|
2090
|
+
values: submitValues,
|
|
1469
2091
|
object: objectName(),
|
|
1470
2092
|
model,
|
|
1471
2093
|
mode: m === 'edit' ? 'update' : 'create',
|
|
@@ -1478,28 +2100,85 @@ function createController(
|
|
|
1478
2100
|
const resetForm = (): boolean => {
|
|
1479
2101
|
syncDraft();
|
|
1480
2102
|
errors = {};
|
|
2103
|
+
touchedFields.clear();
|
|
2104
|
+
invalidFields.clear();
|
|
2105
|
+
lastSubmitVerdictRef = null;
|
|
1481
2106
|
notice = '';
|
|
1482
2107
|
conflict = false;
|
|
1483
|
-
|
|
2108
|
+
resetFocusRestore();
|
|
1484
2109
|
if (mode() === 'filter') {
|
|
1485
2110
|
draft = createFormDraft({ initial: {} });
|
|
1486
|
-
|
|
2111
|
+
api.emit('reset', { values: {}, object: objectName(), scope: scopeKey() });
|
|
1487
2112
|
} else {
|
|
1488
2113
|
draft.reset();
|
|
1489
|
-
|
|
2114
|
+
api.emit('reset', { values: draft.values(), object: objectName(), scope: scopeKey() });
|
|
1490
2115
|
}
|
|
1491
|
-
|
|
2116
|
+
syncDirtyEmit();
|
|
2117
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
1492
2118
|
repaint();
|
|
1493
2119
|
return true;
|
|
1494
2120
|
};
|
|
1495
2121
|
|
|
2122
|
+
const emitSuggestionDraft = (row: unknown, payload: unknown, action: 'accept' | 'reject'): boolean => {
|
|
2123
|
+
syncDraft();
|
|
2124
|
+
const name = isRec(row) ? strOf(row.name) : '';
|
|
2125
|
+
const id = isRec(payload) ? strOf(payload.id) : '';
|
|
2126
|
+
if (name === '' || id === '') return true;
|
|
2127
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty(), field: name, source: 'suggestion', suggestion: { id, action } });
|
|
2128
|
+
return true;
|
|
2129
|
+
};
|
|
2130
|
+
|
|
1496
2131
|
const ctrl: Record<string, unknown> = {
|
|
2132
|
+
/**
|
|
2133
|
+
* 展示对象可调用的公开方法(core 的 ctx.component(id).call;kit 的 ctx.form(对象) 是它的具名糖):
|
|
2134
|
+
* 读草稿快照、写草稿字段值(与用户输入走同一条通道:即时校验、draft_change、重绘)。
|
|
2135
|
+
*/
|
|
2136
|
+
handle: {
|
|
2137
|
+
values: (): Rec => { syncDraft(); return { ...draft.values() }; },
|
|
2138
|
+
dirty: (): boolean => { syncDraft(); return draft.isDirty(); },
|
|
2139
|
+
mode: (): string => mode(),
|
|
2140
|
+
/** 本表单的有效信封(prop 非空用 prop,否则按宿主查找;都没有为 undefined):展示对象的级联选项等按它解包响应 */
|
|
2141
|
+
envelope: (): KitEnvelope | undefined => effectiveEnvelope(),
|
|
2142
|
+
set: (field: string, value: unknown): boolean => {
|
|
2143
|
+
syncDraft();
|
|
2144
|
+
if (detailBlocked() || typeof field !== 'string' || field === '') return false;
|
|
2145
|
+
const known = cells().some((c) => c.field === field) || hiddenNames().includes(field) || field in draft.values();
|
|
2146
|
+
if (!known) return false;
|
|
2147
|
+
return (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value, __viaHandle: true });
|
|
2148
|
+
},
|
|
2149
|
+
/** 画布字段(控件 FlowEditor)当前的节点(浅拷贝);不是画布字段返回 [] */
|
|
2150
|
+
flowNodes: (field: string): Rec[] => {
|
|
2151
|
+
syncDraft();
|
|
2152
|
+
const c = cells().find((x) => x.field === field);
|
|
2153
|
+
return c?.component === 'FlowEditor' ? flowValueNodes(draft.values()[field]) : [];
|
|
2154
|
+
},
|
|
2155
|
+
/** 清空画布字段里某类型节点的某个已选值(连带该字段声明的 resets);与 set 同一条通道,返回被清的节点数 */
|
|
2156
|
+
clearFlowNodeField: (field: string, type: string, key: string): number => {
|
|
2157
|
+
syncDraft();
|
|
2158
|
+
const c = cells().find((x) => x.field === field);
|
|
2159
|
+
if (c?.component !== 'FlowEditor' || detailBlocked()) return 0;
|
|
2160
|
+
const res = clearFlowNodeField(draft.values()[field], isRec(c.props) ? c.props.nodeTypes : undefined, type, key);
|
|
2161
|
+
if (res.cleared === 0) return 0;
|
|
2162
|
+
(ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value: res.value, __viaHandle: true });
|
|
2163
|
+
return res.cleared;
|
|
2164
|
+
},
|
|
2165
|
+
},
|
|
1497
2166
|
get rows(): KitFormRow[] {
|
|
1498
2167
|
syncDraft();
|
|
1499
2168
|
// 编辑详情取数中 / 失败:不画字段(不拿列表行的旧值顶替)
|
|
1500
|
-
|
|
2169
|
+
if (detailBlocked()) return [];
|
|
2170
|
+
sweepStaleViewOptions();
|
|
2171
|
+
return buildRows();
|
|
1501
2172
|
},
|
|
1502
2173
|
get rootClass(): string { return mergeClass(KIT_FORM_CLASS.wrap, strOf(classesOf().wrap)); },
|
|
2174
|
+
get tabRows(): KitFormTabRow[] {
|
|
2175
|
+
syncDraft();
|
|
2176
|
+
return buildTabRows();
|
|
2177
|
+
},
|
|
2178
|
+
get tabbarClass(): string {
|
|
2179
|
+
syncDraft();
|
|
2180
|
+
return buildTabRows().length > 0 ? FL.groupsAs.barClass : 'hidden';
|
|
2181
|
+
},
|
|
1503
2182
|
get gridClass(): string {
|
|
1504
2183
|
syncDraft();
|
|
1505
2184
|
if (detailBlocked()) return KIT_FORM_CLASS.errorHidden;
|
|
@@ -1507,26 +2186,24 @@ function createController(
|
|
|
1507
2186
|
return g !== '' ? g : KIT_FORM_CLASS.grid;
|
|
1508
2187
|
},
|
|
1509
2188
|
get actionsClass(): string { syncDraft(); return detailBlocked() ? KIT_FORM_CLASS.errorHidden : mergeClass(KIT_FORM_CLASS.actions, strOf(classesOf().actions)); },
|
|
2189
|
+
get actionsPadClass(): string { const pad = strOf(classesOf().pad); return pad === '' ? KIT_FORM_CLASS.errorHidden : mergeClass(KIT_FORM_CLASS.label, pad); },
|
|
1510
2190
|
/** 编辑详情取数中的处理中状态块 */
|
|
1511
2191
|
get detailStateClass(): string { syncDraft(); return detailState === 'loading' ? KIT_FORM_CLASS.detailState : KIT_FORM_CLASS.errorHidden; },
|
|
1512
2192
|
/** 底栏动作按钮行(只有可编辑表单,且不在取详情中) */
|
|
1513
2193
|
get footerRows(): Array<{ id: string; label: string; variant: string; disabled: boolean }> {
|
|
1514
2194
|
syncDraft();
|
|
1515
2195
|
if (mode() === 'filter' || detailBlocked() || !Array.isArray(P().footerActions)) return [];
|
|
1516
|
-
|
|
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
|
-
};
|
|
2196
|
+
const states = isRec(P().footerState) ? (P().footerState as Rec) : {};
|
|
1522
2197
|
return (P().footerActions as unknown[]).filter(isRec).flatMap((a) => {
|
|
1523
|
-
const state =
|
|
1524
|
-
|
|
2198
|
+
const state = isRec(states[strOf(a.id)]) ? (states[strOf(a.id)] as Rec) : {};
|
|
2199
|
+
// 展示对象给出的 hidden:不画(路径已由 core 求成布尔)
|
|
2200
|
+
if (state.hidden === true || state.hidden === 'true') return [];
|
|
1525
2201
|
// request.cancelable 的底栏动作在途:原位置变「取消」且保持可点(点的是取消,真正中止请求)
|
|
1526
2202
|
const cancelNow = isKitActionCancelable(strOf(a.id));
|
|
2203
|
+
const gated = state.disabled === true || state.disabled === 'true';
|
|
1527
2204
|
return [{
|
|
1528
|
-
id: strOf(a.id), label: cancelNow ? kitText('soma.kit.cancel', undefined,
|
|
1529
|
-
disabled: cancelNow ? false :
|
|
2205
|
+
id: strOf(a.id), label: cancelNow ? kitText('soma.kit.cancel', undefined, api.host) : strOf(a.label), variant: 'neutral',
|
|
2206
|
+
disabled: cancelNow ? false : gated || isKitActionBusy(strOf(a.id)),
|
|
1530
2207
|
}];
|
|
1531
2208
|
}).filter((a) => a.id !== '');
|
|
1532
2209
|
},
|
|
@@ -1539,10 +2216,10 @@ function createController(
|
|
|
1539
2216
|
if (o === undefined || o.seq <= resultBaseSeq) return null;
|
|
1540
2217
|
const panel = outcomePanelData(o);
|
|
1541
2218
|
const title = strOf(decl.title);
|
|
1542
|
-
if (panel.status === 'busy') return { status: 'busy', text: kitText('soma.kit.processing', undefined,
|
|
2219
|
+
if (panel.status === 'busy') return { status: 'busy', text: kitText('soma.kit.processing', undefined, api.host), title, lines: [], tone: 'neutral' };
|
|
1543
2220
|
if (panel.status === 'failed') {
|
|
1544
2221
|
const m = strOf(panel.message);
|
|
1545
|
-
return { status: 'failed', text: m !== '' ? m : kitText('soma.kit.request_failed', undefined,
|
|
2222
|
+
return { status: 'failed', text: m !== '' ? m : kitText('soma.kit.request_failed', undefined, api.host), title, lines: [], tone: 'danger' };
|
|
1546
2223
|
}
|
|
1547
2224
|
if (panel.status !== 'ready') return null;
|
|
1548
2225
|
const shaped = asyncResultOf(panel.result);
|
|
@@ -1561,14 +2238,22 @@ function createController(
|
|
|
1561
2238
|
get resultText(): string { return (this.resultView as { text: string } | null)?.text ?? ''; },
|
|
1562
2239
|
get resultTextClass(): string { return ((this.resultView as { text: string } | null)?.text ?? '') === '' ? KIT_FORM_CLASS.errorHidden : KIT_FORM_CLASS.resultText; },
|
|
1563
2240
|
get resultLines(): Array<{ label: string; labelClass: string; text: string }> { return (this.resultView as { lines: Array<{ label: string; labelClass: string; text: string }> } | null)?.lines ?? []; },
|
|
1564
|
-
/**
|
|
2241
|
+
/** 点底栏动作:抛槽位事件 footer_action_<序号> { id }(页面事件给每个 request / download 动作各绑一条管道) */
|
|
1565
2242
|
onFooterAction(row: unknown): boolean {
|
|
1566
2243
|
const id = isRec(row) ? strOf(row.id) : '';
|
|
1567
2244
|
if (id !== '' && isKitActionCancelable(id)) { cancelKitAction(id); return true; }
|
|
1568
|
-
|
|
2245
|
+
const gatedNow = ((): boolean => {
|
|
2246
|
+
const st = isRec(P().footerState) && isRec((P().footerState as Rec)[id]) ? ((P().footerState as Rec)[id] as Rec) : {};
|
|
2247
|
+
return st.disabled === true || st.disabled === 'true' || st.hidden === true || st.hidden === 'true';
|
|
2248
|
+
})();
|
|
2249
|
+
if (id !== '' && !isKitActionBusy(id) && !gatedNow) {
|
|
2250
|
+
const list = Array.isArray(P().footerActions) ? (P().footerActions as unknown[]) : [];
|
|
2251
|
+
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() });
|
|
2252
|
+
}
|
|
1569
2253
|
return true;
|
|
1570
2254
|
},
|
|
1571
|
-
|
|
2255
|
+
// 编辑详情取数中:与集合 / 数据组件同一条加载文案与盒(recipes 的 KIT_STATE_LOADING_BOX),不再是「处理中…」
|
|
2256
|
+
get detailStateText(): string { syncDraft(); return detailState === 'loading' ? kitText('soma.kit.loading', undefined, api.host) : ''; },
|
|
1572
2257
|
get noticeClass(): string {
|
|
1573
2258
|
syncDraft();
|
|
1574
2259
|
return notice === '' ? KIT_FORM_CLASS.noticeHidden : mergeClass(KIT_FORM_CLASS.notice, strOf(classesOf().notice));
|
|
@@ -1577,116 +2262,34 @@ function createController(
|
|
|
1577
2262
|
// 冲突(请刷新)与编辑详情取数失败(请重试)共用同一个提示条上的按钮
|
|
1578
2263
|
get conflict(): boolean { return conflict || detailState === 'failed'; },
|
|
1579
2264
|
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
|
-
},
|
|
2265
|
+
get formDisabled(): boolean { syncDraft(); return P().disabled === true || (mode() !== 'filter' && P().submitDisabled === true); },
|
|
1669
2266
|
get showReset(): boolean { return mode() === 'filter' || strOf(P().resetLabel) !== ''; },
|
|
1670
2267
|
get showCancel(): boolean { return strOf(P().cancelLabel) !== ''; },
|
|
1671
2268
|
// filter 折叠:展开 / 收起钮与有值计数徽标(只在 collapsible 且确有被折起的行时出现)
|
|
1672
2269
|
get showToggle(): boolean { return P().collapsible === true && filterRows().rows > Math.max(1, Math.trunc(Number(P().collapsedRows) || 1)); },
|
|
1673
2270
|
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 },
|
|
2271
|
+
get toggleText(): string { return kitText(filterCollapsed ? 'soma.kit.expand' : 'soma.kit.collapse', undefined, api.host); },
|
|
2272
|
+
get badgeText(): string { const n = P().collapsible === true ? filledCount() : 0; return n > 0 ? kitText('soma.kit.filter_set_n', { n }, api.host) : ''; },
|
|
1676
2273
|
get badgeClass(): string { return this.badgeText === '' ? 'hidden' : FL.filterOptions.badgeClass; },
|
|
1677
2274
|
get refreshWrapClass(): string { return conflict || detailState === 'failed' ? '' : 'hidden'; },
|
|
1678
2275
|
get resetWrapClass(): string { return (mode() === 'filter' || strOf(P().resetLabel) !== '') ? '' : 'hidden'; },
|
|
1679
2276
|
get cancelWrapClass(): string { return strOf(P().cancelLabel) !== '' ? '' : 'hidden'; },
|
|
1680
2277
|
get submitText(): string {
|
|
1681
2278
|
const given = strOf(P().submitLabel);
|
|
1682
|
-
return given !== '' ? given : kitText(mode() === 'filter' ? DEFAULT_FILTER_LABEL : DEFAULT_SUBMIT_LABEL, undefined,
|
|
2279
|
+
return given !== '' ? given : kitText(mode() === 'filter' ? DEFAULT_FILTER_LABEL : DEFAULT_SUBMIT_LABEL, undefined, api.host);
|
|
1683
2280
|
},
|
|
2281
|
+
get submitTitle(): string {
|
|
2282
|
+
syncDraft();
|
|
2283
|
+
return computeSubmitTitle();
|
|
2284
|
+
},
|
|
2285
|
+
get touchedFields(): ReadonlySet<string> { return touchedFields; },
|
|
2286
|
+
get invalidFields(): ReadonlySet<string> { return invalidFields; },
|
|
1684
2287
|
get resetText(): string {
|
|
1685
2288
|
const given = strOf(P().resetLabel);
|
|
1686
|
-
return given !== '' ? given : kitText(DEFAULT_RESET_LABEL, undefined,
|
|
2289
|
+
return given !== '' ? given : kitText(DEFAULT_RESET_LABEL, undefined, api.host);
|
|
1687
2290
|
},
|
|
1688
2291
|
get cancelText(): string { return strOf(P().cancelLabel); },
|
|
1689
|
-
get refreshLabel(): string { return kitText(detailState === 'failed' ? 'soma.kit.ct_retry' : DEFAULT_REFRESH_LABEL, undefined,
|
|
2292
|
+
get refreshLabel(): string { return kitText(detailState === 'failed' ? 'soma.kit.ct_retry' : DEFAULT_REFRESH_LABEL, undefined, api.host); },
|
|
1690
2293
|
get primaryVariant(): string { return 'primary'; },
|
|
1691
2294
|
get neutralVariant(): string { return 'neutral'; },
|
|
1692
2295
|
get ghostVariant(): string { return 'ghost'; },
|
|
@@ -1696,66 +2299,59 @@ function createController(
|
|
|
1696
2299
|
|
|
1697
2300
|
/** 行内基础组件的 change:第二参是 emit 载荷 { value },第一参是行变量 */
|
|
1698
2301
|
onFieldChange(row: unknown, payload: unknown): boolean {
|
|
2302
|
+
const viaHandle = isRec(payload) && payload.__viaHandle === true;
|
|
1699
2303
|
syncDraft();
|
|
1700
2304
|
const name = isRec(row) ? strOf(row.name) : '';
|
|
1701
2305
|
if (name === '' || !isRec(payload)) return true;
|
|
2306
|
+
const wasInvalid = invalidFields.has(name) || name in errors;
|
|
1702
2307
|
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
2308
|
if (name in errors) {
|
|
1721
2309
|
const next = { ...errors };
|
|
1722
2310
|
delete next[name];
|
|
1723
2311
|
errors = next;
|
|
1724
2312
|
}
|
|
1725
|
-
|
|
2313
|
+
if (wasInvalid || touchedFields.has(name) || stringList(P().validateOn).includes('change')) {
|
|
2314
|
+
instantValidate('change', name);
|
|
2315
|
+
} else {
|
|
2316
|
+
invalidFields.delete(name);
|
|
2317
|
+
}
|
|
1726
2318
|
if (mode() === 'filter' && P().trigger === 'change') {
|
|
1727
2319
|
if (debounceTimer !== undefined) clearTimeout(debounceTimer);
|
|
1728
2320
|
debounceTimer = setTimeout(() => { debounceTimer = undefined; if (alive) submitForm(); }, KIT_FORM_LINKAGE_LIMITS.filterOptions.changeDebounceMs);
|
|
1729
2321
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
2322
|
+
ensureOptions();
|
|
2323
|
+
syncDirtyEmit();
|
|
2324
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty(), field: name, source: viaHandle ? 'api' : 'input' });
|
|
2325
|
+
repaint();
|
|
2326
|
+
return true;
|
|
2327
|
+
},
|
|
2328
|
+
/** 行内基础组件失焦:加入 touchedFields 并对单字段执行校验 */
|
|
2329
|
+
onFieldBlur(row: unknown): boolean {
|
|
2330
|
+
syncDraft();
|
|
2331
|
+
const name = isRec(row) ? strOf(row.name) : typeof row === 'string' ? row : '';
|
|
2332
|
+
if (name === '') return true;
|
|
2333
|
+
touchedFields.add(name);
|
|
2334
|
+
instantValidate('blur', name);
|
|
1742
2335
|
repaint();
|
|
1743
2336
|
return true;
|
|
1744
2337
|
},
|
|
1745
|
-
/** 选记录类组件(RecordPicker)抛 pick { value, values, item, items }
|
|
2338
|
+
/** 选记录类组件(RecordPicker)抛 pick { value, values, item, items }:value 写本字段 */
|
|
1746
2339
|
onFieldPick(row: unknown, payload: unknown): boolean {
|
|
1747
2340
|
syncDraft();
|
|
1748
2341
|
const name = isRec(row) ? strOf(row.name) : '';
|
|
1749
2342
|
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
2343
|
return (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)(row, { value: payload.value });
|
|
1758
2344
|
},
|
|
2345
|
+
/**
|
|
2346
|
+
* 画布(FlowEditor)采纳 / 忽略一条 AI 建议:采纳时画布已把建议并进图并先抛过 change(草稿值已是合并后的图);
|
|
2347
|
+
* 这里再抛一次 draft_change,载荷带 suggestion { id, action },展示对象在 onDraft 里清掉对应建议(建议状态归展示对象)
|
|
2348
|
+
*/
|
|
2349
|
+
onFieldSuggestionAccept(row: unknown, payload: unknown): boolean {
|
|
2350
|
+
return emitSuggestionDraft(row, payload, 'accept');
|
|
2351
|
+
},
|
|
2352
|
+
onFieldSuggestionReject(row: unknown, payload: unknown): boolean {
|
|
2353
|
+
return emitSuggestionDraft(row, payload, 'reject');
|
|
2354
|
+
},
|
|
1759
2355
|
/** 级联(Cascader)展开了还没有子级的 lazy 节点:抛 load { value: 路径, node },按 options.lazy 重取该节点的子级 */
|
|
1760
2356
|
onFieldLoad(row: unknown, payload: unknown): boolean {
|
|
1761
2357
|
syncDraft();
|
|
@@ -1765,6 +2361,8 @@ function createController(
|
|
|
1765
2361
|
loadChildren(c, (payload.value as unknown[]).map((v) => strOf(v)));
|
|
1766
2362
|
return true;
|
|
1767
2363
|
},
|
|
2364
|
+
/** 按字段显式重试当前失败的同一选项 key(包括 FlowEditor 的一个失败槽);不广播其它请求 */
|
|
2365
|
+
retryOptions,
|
|
1768
2366
|
/** 带远程搜索的组件抛 search { keyword }:关键字作为 options.searchParam 重取候选 */
|
|
1769
2367
|
onFieldSearch(row: unknown, payload: unknown): boolean {
|
|
1770
2368
|
syncDraft();
|
|
@@ -1772,8 +2370,11 @@ function createController(
|
|
|
1772
2370
|
const of = cells().find((c) => c.field === name)?.optionsFrom;
|
|
1773
2371
|
const st = remote.get(name);
|
|
1774
2372
|
if (of === undefined || of.searchParam === '' || st === undefined || !isRec(payload)) return true;
|
|
1775
|
-
|
|
1776
|
-
|
|
2373
|
+
// 基础组件的 search 事件载荷是 { query }(Combobox / Mentions);keyword / value 为历史兼容
|
|
2374
|
+
st.keyword = strOf(payload.query ?? payload.keyword ?? payload.value);
|
|
2375
|
+
// 字段处于失败态:同一请求键由 retryOptions 重发(ensureOptions 会跳过相同失败键);键变了它自己回落到 ensureOptions
|
|
2376
|
+
if (st.error === true && typeof st.failedKey === 'string' && st.failedKey !== '') retryOptions({ name });
|
|
2377
|
+
else ensureOptions();
|
|
1777
2378
|
return true;
|
|
1778
2379
|
},
|
|
1779
2380
|
toggleCollapsed(): boolean {
|
|
@@ -1786,67 +2387,76 @@ function createController(
|
|
|
1786
2387
|
cancelForm(): boolean {
|
|
1787
2388
|
// 载荷只增不改:带上当前草稿(不校验),分步表单「上一步」靠它保存本步未提交的改动
|
|
1788
2389
|
syncDraft();
|
|
1789
|
-
|
|
2390
|
+
api.emit('cancel', { object: objectName(), scope: scopeKey(), model: collectModel() });
|
|
1790
2391
|
return true;
|
|
1791
2392
|
},
|
|
1792
2393
|
refreshAfterConflict(): boolean {
|
|
2394
|
+
// 提交处理中:不响应(等结果回来再说)
|
|
2395
|
+
if (isBusy()) return true;
|
|
1793
2396
|
// 编辑详情取数失败:重试就是重新取详情(不通知外层刷新)
|
|
1794
2397
|
if (detailState === 'failed') {
|
|
1795
2398
|
startDetail();
|
|
1796
2399
|
repaint();
|
|
1797
2400
|
return true;
|
|
1798
2401
|
}
|
|
1799
|
-
|
|
2402
|
+
// 刷新按钮持焦点:冲突清除后提示条隐藏,重绘后把焦点放到首个可用字段(无 DOM 环境跳过)
|
|
2403
|
+
const host = api.host;
|
|
2404
|
+
const doc = host?.ownerDocument;
|
|
2405
|
+
const wrap = host?.querySelector?.<HTMLElement>('[data-soma-id="refresh_wrap"]');
|
|
2406
|
+
if (conflict && doc && wrap && wrap.contains(doc.activeElement)) armRefreshFocus(doc);
|
|
2407
|
+
// 来源 A(表单自己配置了详情来源)的写入冲突:表单内部重新取详情,取回后 startDetail 重建草稿(放弃当前修改);
|
|
2408
|
+
// 先收起冲突提示,取详情期间由「取数中」占位;仍抛 reload 供外层刷新列表。来源 B(宿主下传 initial)由外层换行:
|
|
2409
|
+
// 编辑模式放弃本地修改、按当前 initial 重建草稿(保留页签 / 折叠 / 选项缓存),重取后 initial 变化时 syncDraft 再按最新数据重建;
|
|
2410
|
+
// 新建模式只收起冲突提示,不丢用户输入;最后照旧抛 reload
|
|
2411
|
+
if (conflict && detailOf() !== null && mode() === 'edit') {
|
|
2412
|
+
conflict = false;
|
|
2413
|
+
notice = '';
|
|
2414
|
+
startDetail();
|
|
2415
|
+
repaint();
|
|
2416
|
+
} else if (conflict && mode() === 'edit') {
|
|
2417
|
+
rebuildDraft();
|
|
2418
|
+
syncDirtyEmit();
|
|
2419
|
+
api.emit('draft_change', { values: draft.values(), dirty: draft.isDirty() });
|
|
2420
|
+
repaint();
|
|
2421
|
+
} else if (conflict && mode() !== 'filter') {
|
|
2422
|
+
conflict = false;
|
|
2423
|
+
notice = '';
|
|
2424
|
+
repaint();
|
|
2425
|
+
}
|
|
2426
|
+
api.emit('reload', { object: objectName(), scope: scopeKey() });
|
|
1800
2427
|
return true;
|
|
1801
2428
|
},
|
|
1802
2429
|
|
|
1803
|
-
|
|
2430
|
+
busyAware: true,
|
|
2431
|
+
attach(root: HTMLElement) {
|
|
1804
2432
|
alive = true;
|
|
1805
2433
|
syncDraft();
|
|
1806
|
-
//
|
|
2434
|
+
// 草稿读口登记(具名动作的 draft 读口):筛选表单不登记;草稿仍是本表单自己的 draft,登记的只是读口
|
|
1807
2435
|
draftHandle?.dispose();
|
|
1808
2436
|
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
|
-
}
|
|
2437
|
+
syncDraftRegistration();
|
|
1831
2438
|
syncOutcomes();
|
|
1832
2439
|
const port = dataPort();
|
|
1833
2440
|
if (port?.onWriteOutcome) unsubOutcome = port.onWriteOutcome(onOutcome);
|
|
1834
2441
|
unsubBusy?.();
|
|
1835
2442
|
unsubBusy = onKitActionBusy(() => { if (alive) repaint(); });
|
|
1836
|
-
//
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
let
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
2443
|
+
// 流式折叠筛选:宿主宽变了折起的字段 / 总行数可能变,签名变了才重绘
|
|
2444
|
+
stopFlowWatch?.();
|
|
2445
|
+
stopFlowWatch = undefined;
|
|
2446
|
+
if (mode() === 'filter' && P().flow === true && P().collapsible === true && typeof ResizeObserver !== 'undefined' && api.host) {
|
|
2447
|
+
let last = '';
|
|
2448
|
+
const sig = (): string => { const r = filterRows(); return `${r.rows}:${[...r.hidden].join(',')}`; };
|
|
2449
|
+
const ro = new ResizeObserver(() => {
|
|
2450
|
+
if (!alive) return;
|
|
2451
|
+
const now = sig();
|
|
2452
|
+
if (now === last) return;
|
|
2453
|
+
last = now;
|
|
2454
|
+
repaint();
|
|
2455
|
+
});
|
|
2456
|
+
ro.observe(api.host);
|
|
2457
|
+
stopFlowWatch = () => ro.disconnect();
|
|
2458
|
+
}
|
|
2459
|
+
const form = api.host?.querySelector?.('form') ?? null;
|
|
1850
2460
|
if (form) {
|
|
1851
2461
|
const onSubmit = (event: Event): void => {
|
|
1852
2462
|
event.preventDefault();
|
|
@@ -1865,34 +2475,107 @@ function createController(
|
|
|
1865
2475
|
const id = btn?.getAttribute('data-kit-group') ?? '';
|
|
1866
2476
|
if (btn && id !== '') toggleGroup(id);
|
|
1867
2477
|
};
|
|
1868
|
-
//
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2478
|
+
// 页签模式:点击 / 方向键 / Home / End 都走共享页签接线(wireKitTablist),选中变化时切当前组并重画;
|
|
2479
|
+
// 键盘选中后页签行可能被 core 重画,焦点原在页签上的话重画后补回
|
|
2480
|
+
const tabbar = form.querySelector<HTMLElement>('[data-soma-id="tabbar"]');
|
|
2481
|
+
if (tabbar) {
|
|
2482
|
+
tabsHandle = wireKitTablist(tabbar, {
|
|
2483
|
+
tabs: () => Array.from(tabbar.querySelectorAll<HTMLElement>('[data-kit-group-tab]')),
|
|
2484
|
+
idOf: (tab) => tab.getAttribute('data-kit-group') ?? '',
|
|
2485
|
+
selected: activeTab,
|
|
2486
|
+
onSelect: (id, tab) => {
|
|
2487
|
+
if (id === '' || id === activeTab) return;
|
|
2488
|
+
const hadFocus = tab.ownerDocument.activeElement === tab;
|
|
2489
|
+
activeTab = id;
|
|
2490
|
+
repaint();
|
|
2491
|
+
if (hadFocus) {
|
|
2492
|
+
queueMicrotask(() => {
|
|
2493
|
+
if (!alive) return;
|
|
2494
|
+
const again = Array.from(tabbar.querySelectorAll<HTMLElement>('[data-kit-group-tab]')).find((t) => t.getAttribute('data-kit-group') === id);
|
|
2495
|
+
if (again && again.ownerDocument.activeElement !== again) again.focus({ preventScroll: true });
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
},
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
// 首次失焦后校验(focusout / blur),已出错或已触碰字段在 input / change 时即时复校
|
|
2502
|
+
const resolveFieldFromEvent = (event: Event): { name: string; el: HTMLElement } | null => {
|
|
2503
|
+
const rows = buildRows();
|
|
2504
|
+
const byId = new Map(rows.map((r) => [r.id, r.name] as const));
|
|
2505
|
+
const knownNames = new Set(rows.map((r) => r.name));
|
|
2506
|
+
for (let el = event.target as HTMLElement | null; el && el !== form; el = el.parentElement) {
|
|
2507
|
+
const byIdName = byId.get(el.id);
|
|
2508
|
+
if (byIdName !== undefined) return { name: byIdName, el };
|
|
2509
|
+
const attrName = el.getAttribute('name') ?? el.getAttribute('data-field') ?? el.getAttribute('data-kit-field') ?? '';
|
|
2510
|
+
if (attrName !== '' && knownNames.has(attrName)) return { name: attrName, el };
|
|
2511
|
+
}
|
|
2512
|
+
return null;
|
|
1873
2513
|
};
|
|
1874
|
-
// validate_on: blur:失焦字段(控件或其内部元素的 id 对得上行 id)即时校验
|
|
1875
2514
|
const onFocusOut = (event: Event): void => {
|
|
1876
|
-
if (
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
2515
|
+
if (mode() === 'filter') return;
|
|
2516
|
+
const hit = resolveFieldFromEvent(event);
|
|
2517
|
+
if (!hit) return;
|
|
2518
|
+
if ('value' in hit.el && typeof (hit.el as HTMLInputElement).value === 'string' && draft.get(hit.name) === undefined && (hit.el as HTMLInputElement).value !== '') {
|
|
2519
|
+
draft.set(hit.name, (hit.el as HTMLInputElement).value);
|
|
2520
|
+
}
|
|
2521
|
+
touchedFields.add(hit.name);
|
|
2522
|
+
instantValidate('blur', hit.name);
|
|
2523
|
+
repaint();
|
|
2524
|
+
};
|
|
2525
|
+
const onDomFieldInput = (event: Event): void => {
|
|
2526
|
+
if (mode() === 'filter') return;
|
|
2527
|
+
const hit = resolveFieldFromEvent(event);
|
|
2528
|
+
if (!hit) return;
|
|
2529
|
+
if ('value' in hit.el && typeof (hit.el as HTMLInputElement).value === 'string') {
|
|
2530
|
+
draft.set(hit.name, (hit.el as HTMLInputElement).value);
|
|
2531
|
+
}
|
|
2532
|
+
if (invalidFields.has(hit.name) || touchedFields.has(hit.name) || stringList(P().validateOn).includes('change')) {
|
|
2533
|
+
instantValidate('change', hit.name);
|
|
2534
|
+
repaint();
|
|
2535
|
+
} else {
|
|
2536
|
+
syncInvalid();
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
// 点字段标签聚焦该字段的焦点目标:Select 是 div role=combobox、单选 / 多选组、评分、验证码、富文本、行编辑等不是原生可标注元素,label for 对它们无效
|
|
2540
|
+
const onLabelClick = (event: Event): void => {
|
|
2541
|
+
const t = event.target as HTMLElement | null;
|
|
2542
|
+
if (!t || t.closest('input,select,textarea,button,a')) return;
|
|
2543
|
+
const label = t.closest<HTMLElement>('label[id]');
|
|
2544
|
+
if (!label || !form.contains(label)) return;
|
|
2545
|
+
const row = buildRows().find((r) => r.labelId === label.id);
|
|
2546
|
+
if (!row || row.id === '') return;
|
|
2547
|
+
const host = form.querySelector<HTMLElement>(`[id="${row.id.replace(/["\\]/g, '\\$&')}"]`);
|
|
2548
|
+
if (!host) return;
|
|
2549
|
+
// 原生可标注且不是组成员(labelFor 有值):浏览器已按 for 处理
|
|
2550
|
+
if (row.labelFor !== '' && host.matches('input:not([type="hidden"]),select,textarea,button')) return;
|
|
2551
|
+
const target = fieldFocusTarget(host);
|
|
2552
|
+
if (target && !(target as HTMLInputElement).disabled) {
|
|
2553
|
+
event.preventDefault();
|
|
2554
|
+
target.focus({ preventScroll: false });
|
|
1881
2555
|
}
|
|
1882
2556
|
};
|
|
2557
|
+
form.addEventListener('click', onLabelClick);
|
|
1883
2558
|
form.addEventListener('submit', onSubmit);
|
|
1884
2559
|
form.addEventListener('keydown', onKeydown as EventListener);
|
|
1885
2560
|
form.addEventListener('click', onGroupClick);
|
|
1886
|
-
form.addEventListener('click', onTabClick);
|
|
1887
2561
|
form.addEventListener('focusout', onFocusOut);
|
|
2562
|
+
form.addEventListener('blur', onFocusOut, true);
|
|
2563
|
+
form.addEventListener('input', onDomFieldInput);
|
|
2564
|
+
form.addEventListener('change', onDomFieldInput);
|
|
1888
2565
|
cleanupDom = () => {
|
|
1889
2566
|
form.removeEventListener('submit', onSubmit);
|
|
1890
2567
|
form.removeEventListener('keydown', onKeydown as EventListener);
|
|
1891
2568
|
form.removeEventListener('click', onGroupClick);
|
|
1892
|
-
form.removeEventListener('click',
|
|
2569
|
+
form.removeEventListener('click', onLabelClick);
|
|
2570
|
+
tabsHandle?.destroy();
|
|
2571
|
+
tabsHandle = undefined;
|
|
1893
2572
|
form.removeEventListener('focusout', onFocusOut);
|
|
2573
|
+
form.removeEventListener('blur', onFocusOut, true);
|
|
2574
|
+
form.removeEventListener('input', onDomFieldInput);
|
|
2575
|
+
form.removeEventListener('change', onDomFieldInput);
|
|
1894
2576
|
};
|
|
1895
2577
|
}
|
|
2578
|
+
syncInvalid();
|
|
1896
2579
|
// 离开守卫:草稿有改动时拦截刷新 / 关闭(beforeunload)与站内链接点击
|
|
1897
2580
|
offGuard?.();
|
|
1898
2581
|
offGuard = undefined;
|
|
@@ -1911,8 +2594,9 @@ function createController(
|
|
|
1911
2594
|
if (!a || a.target === '_blank') return;
|
|
1912
2595
|
event.preventDefault();
|
|
1913
2596
|
event.stopImmediatePropagation();
|
|
1914
|
-
void askKitConfirm({ message: FL.behaviorPassthrough.leaveGuard.confirmText, tone: 'danger', at:
|
|
2597
|
+
void askKitConfirm({ message: FL.behaviorPassthrough.leaveGuard.confirmText, tone: 'danger', at: api.host ?? null }).then((ok) => {
|
|
1915
2598
|
if (!ok || !alive) return;
|
|
2599
|
+
resetForm();
|
|
1916
2600
|
leaveApproved = true;
|
|
1917
2601
|
try { a.click(); } finally { leaveApproved = false; }
|
|
1918
2602
|
});
|
|
@@ -1924,34 +2608,44 @@ function createController(
|
|
|
1924
2608
|
document.removeEventListener('click', onLinkClick, true);
|
|
1925
2609
|
};
|
|
1926
2610
|
}
|
|
2611
|
+
return () => {
|
|
2612
|
+
// 销毁后实例的 emit 会被丢弃,不在此补报;协调组件靠新实例挂载后的首次 busy_change 复位
|
|
2613
|
+
busyReported = undefined;
|
|
2614
|
+
dirtyReported = undefined;
|
|
2615
|
+
alive = false;
|
|
2616
|
+
resetFocusRestore();
|
|
2617
|
+
disarmRefreshFocus();
|
|
2618
|
+
detailSeq += 1;
|
|
2619
|
+
draftHandle?.dispose();
|
|
2620
|
+
draftHandle = undefined;
|
|
2621
|
+
for (const off of offOutcomes) off();
|
|
2622
|
+
offOutcomes = [];
|
|
2623
|
+
outcomes.clear();
|
|
2624
|
+
outcomeSig = '';
|
|
2625
|
+
if (unsubOutcome) unsubOutcome();
|
|
2626
|
+
unsubOutcome = undefined;
|
|
2627
|
+
unsubBusy?.();
|
|
2628
|
+
unsubBusy = undefined;
|
|
2629
|
+
stopFlowWatch?.();
|
|
2630
|
+
stopFlowWatch = undefined;
|
|
2631
|
+
if (cleanupDom) cleanupDom();
|
|
2632
|
+
cleanupDom = undefined;
|
|
2633
|
+
offGuard?.();
|
|
2634
|
+
offGuard = undefined;
|
|
2635
|
+
if (debounceTimer !== undefined) clearTimeout(debounceTimer);
|
|
2636
|
+
debounceTimer = undefined;
|
|
2637
|
+
};
|
|
1927
2638
|
},
|
|
1928
|
-
|
|
2639
|
+
render(root: HTMLElement) {
|
|
1929
2640
|
syncDraft();
|
|
1930
2641
|
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;
|
|
2642
|
+
syncInvalid();
|
|
2643
|
+
syncDraftRegistration();
|
|
2644
|
+
syncTabsDom();
|
|
2645
|
+
queueMicrotask(() => { if (alive) syncTabsDom(); });
|
|
2646
|
+
// 宿主直接改 busy 属性只触发 render(不经 repaint):异步补报 busy_change(不在渲染读口里重入;syncBusyEmit 按与上次报出值比较去重)
|
|
2647
|
+
// 草稿被宿主换行 / 重建(syncDraft)后脏状态可能变化,同样异步补报
|
|
2648
|
+
if (isBusy() !== busyReported || draft.isDirty() !== dirtyReported) queueMicrotask(() => { if (alive) { syncBusyEmit(); syncDirtyEmit(); } });
|
|
1955
2649
|
},
|
|
1956
2650
|
};
|
|
1957
2651
|
|