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/row-editor.ts
CHANGED
|
@@ -13,20 +13,23 @@
|
|
|
13
13
|
// 录入草稿在组件内,重画与 columns 选项变化都不丢;数据只经 textContent / value 写入。
|
|
14
14
|
|
|
15
15
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
|
-
import { bool, createKitController, FIELD_CLASS, formatValue, joinClass, num, str, type KitApi } from '../base/shared';
|
|
16
|
+
import { applyCommon, bool, createKitController, FIELD_CLASS, formatValue, ID_PROPS, INVALID_PROPS, joinClass, nextUid, num, str, type KitApi } from '../base/shared';
|
|
17
17
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
18
|
+
import { setKitFace } from '../recipes';
|
|
18
19
|
import { KIT_BUSY_PROP_DEFS, kitBusyOf } from '../base/action-busy';
|
|
19
20
|
import { KIT_DATE_CLASS_CANDIDATES, mountKitDateField } from '../base/date';
|
|
20
21
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
21
22
|
import { createKitEmbedBag, mountKitSelectField, type KitEmbedBag } from './embed';
|
|
22
23
|
import { fetchRemoteOptionRows } from './remote-options';
|
|
23
|
-
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, recOf, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
24
|
+
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, recOf, retryButton, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
25
|
+
import { TEXT_ACTION_CLASS_TOKENS, textActionButton } from './text-action-button';
|
|
24
26
|
import type { SomaDataPort } from 'soma-core';
|
|
25
27
|
import { askKitConfirm } from './confirm-dialog';
|
|
26
28
|
import { watchKitOutcome } from './outcome-watch';
|
|
27
29
|
import { stagedDiff, stagedHeadKeys, stagedMarks, stagedModel } from './staged-rows';
|
|
30
|
+
import { testRegexGuarded } from 'soma-foundation/predicates';
|
|
28
31
|
|
|
29
|
-
// 集合本地草稿(staged):未同步条与行小标的类串(条与小标的语气取 warning-soft
|
|
32
|
+
// 集合本地草稿(staged):未同步条与行小标的类串(条与小标的语气取 warning-soft)
|
|
30
33
|
const STAGE_BAR_CLASS = `flex flex-wrap items-center justify-between gap-2 rounded-md px-3 py-2 text-sm ${TONE_SOFT.warning}`;
|
|
31
34
|
const STAGE_BTNS_CLASS = 'flex items-center gap-2';
|
|
32
35
|
const STAGE_MARK_CLASS = `ms-2 rounded-full px-2 py-0.5 text-xs font-medium ${TONE_SOFT.warning}`;
|
|
@@ -52,6 +55,14 @@ const CELL_CLASS = 'min-w-0 break-all text-sm text-fg';
|
|
|
52
55
|
const CELL_MONO = 'min-w-0 break-all font-mono text-xs text-fg-muted';
|
|
53
56
|
const CELL_MUTED = 'min-w-0 break-all text-sm text-fg-muted';
|
|
54
57
|
const END_CLASS = 'col-span-2 justify-self-end';
|
|
58
|
+
// 带操作列(结构可改)的行:横排弹性行——数据格按份数分宽(flex-<份数>,可缩可折行),操作格定宽不缩、内容靠右;
|
|
59
|
+
// 操作钮文案单行,不会被 12 栅格里 2 份的窄轨挤成逐字折行。不带操作列的行仍是 12 栅格,输出不变。
|
|
60
|
+
const FLEX_SPAN: Record<number, string> = {
|
|
61
|
+
1: 'flex-1', 2: 'flex-2', 3: 'flex-3', 4: 'flex-4', 5: 'flex-5', 6: 'flex-6',
|
|
62
|
+
7: 'flex-7', 8: 'flex-8', 9: 'flex-9', 10: 'flex-10', 11: 'flex-11', 12: 'flex-12',
|
|
63
|
+
};
|
|
64
|
+
const END_FLEX_CLASS = 'flex w-24 shrink-0 justify-end';
|
|
65
|
+
const toFlexRow = (cls: string): string => cls.replace('grid grid-cols-12', 'flex');
|
|
55
66
|
const FORM_CLASS = 'grid gap-3';
|
|
56
67
|
const FIELD_WRAP = 'flex flex-col gap-1';
|
|
57
68
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
@@ -61,14 +72,19 @@ const ERROR_CLASS = 'text-sm text-danger-on-soft';
|
|
|
61
72
|
const LIST_WRAP = 'flex flex-col';
|
|
62
73
|
const NUM_ALIGN = 'text-end tabular-nums';
|
|
63
74
|
const FOOTER_ROW_CLASS = 'grid grid-cols-12 items-center gap-2 border-t border-border-divider px-2 py-2 text-sm font-semibold text-fg';
|
|
75
|
+
const HEAD_END_CLASS = toFlexRow(HEAD_CLASS);
|
|
76
|
+
const ROW_END_CLASS = toFlexRow(ROW_CLASS);
|
|
77
|
+
const FOOTER_END_CLASS = toFlexRow(FOOTER_ROW_CLASS);
|
|
64
78
|
const COUNT_CLASS = 'text-xs text-fg-subtle';
|
|
79
|
+
/** 出错单元格的外框(令牌色环,不撑行高;圆角不在此处手写,沿用单元格自身) */
|
|
80
|
+
const CELL_ERROR_CLASS = 'ring-1 ring-danger';
|
|
65
81
|
const DATE_FIELD_CLASS = 'block h-9 w-full rounded-md border border-border bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken';
|
|
66
82
|
|
|
67
83
|
export const KIT_ROW_EDITOR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
68
84
|
ROOT_CLASS, TITLE_CLASS, HINT_CLASS, HEAD_CLASS, ROW_CLASS, CELL_CLASS, CELL_MONO, CELL_MUTED, END_CLASS, FORM_CLASS, FIELD_WRAP,
|
|
69
85
|
LABEL_CLASS, REQUIRED_MARK, TEXTAREA_LIKE, ERROR_CLASS, LIST_WRAP, Object.values(SPAN_CLASS), Object.values(FORM_COLS),
|
|
70
|
-
FIELD_CLASS.md, BUTTON_CLASS_TOKENS, 'self-end', '@container', NUM_ALIGN, FOOTER_ROW_CLASS, COUNT_CLASS, DATE_FIELD_CLASS, KIT_DATE_CLASS_CANDIDATES, KIT_LISTBOX_CLASS_CANDIDATES,
|
|
71
|
-
STAGE_BAR_CLASS, STAGE_BTNS_CLASS, STAGE_MARK_CLASS, STAGE_NOTE_CLASS,
|
|
86
|
+
FIELD_CLASS.md, BUTTON_CLASS_TOKENS, TEXT_ACTION_CLASS_TOKENS, 'self-end', '@container', NUM_ALIGN, FOOTER_ROW_CLASS, HEAD_END_CLASS, ROW_END_CLASS, FOOTER_END_CLASS, END_FLEX_CLASS, Object.values(FLEX_SPAN).join(' '), COUNT_CLASS, CELL_ERROR_CLASS, DATE_FIELD_CLASS, KIT_DATE_CLASS_CANDIDATES, KIT_LISTBOX_CLASS_CANDIDATES,
|
|
87
|
+
STAGE_BAR_CLASS, STAGE_BTNS_CLASS, STAGE_MARK_CLASS, STAGE_NOTE_CLASS, 'sr-only',
|
|
72
88
|
);
|
|
73
89
|
|
|
74
90
|
// ── 数据规整纯函数:列声明、单元格文字、录入校验、草稿转行 ──
|
|
@@ -110,6 +126,11 @@ export interface KitRowColumn {
|
|
|
110
126
|
list: boolean;
|
|
111
127
|
/** GB5:select 列的远程选项(options 写成对象 { from, valueKey?, labelKey?, rowsPath?, params? });静态选项为 null */
|
|
112
128
|
optionsFrom: KitRowOptionsFrom | null;
|
|
129
|
+
/** 远程候选失败时附加到当前列视图的重试元数据 */
|
|
130
|
+
optionsError?: boolean;
|
|
131
|
+
optionsKey?: string;
|
|
132
|
+
optionsRetryState?: 'loading' | 'ok' | 'failed';
|
|
133
|
+
optionsRetryLabel?: string;
|
|
113
134
|
}
|
|
114
135
|
|
|
115
136
|
/** select 列的远程选项声明(规整后;键同 schema.<字段>.options 的对象写法,params 只许字面量) */
|
|
@@ -217,31 +238,61 @@ export function rowTotals(columns: readonly KitRowColumn[], rows: ReadonlyArray<
|
|
|
217
238
|
return out;
|
|
218
239
|
}
|
|
219
240
|
|
|
220
|
-
/**
|
|
221
|
-
|
|
241
|
+
/** 单列录入校验:通过返回 null,否则返回该列的第一条提示文字 */
|
|
242
|
+
function columnDraftError(c: KitRowColumn, draft: Readonly<Record<string, string>>, requiredText: string, at?: Element | string | null): string | null {
|
|
222
243
|
const T = (key: KitTextKey, params: Record<string, string | number>): string => kitText(key, params, at);
|
|
244
|
+
const v = (draft[c.key] ?? '').trim();
|
|
245
|
+
if (!c.editable) return null;
|
|
246
|
+
if (c.required && v === '') return c.requiredMessage !== '' ? c.requiredMessage : `${requiredText}${c.label}`;
|
|
247
|
+
if (isNumericRowKind(c.kind) && v !== '') {
|
|
248
|
+
const n = Number(v);
|
|
249
|
+
if (!Number.isFinite(n)) return T('soma.kit.field_number', { label: c.label });
|
|
250
|
+
if (c.min !== null && n < c.min) return T('soma.kit.field_min', { label: c.label, n: c.min });
|
|
251
|
+
if (c.max !== null && n > c.max) return T('soma.kit.field_max', { label: c.label, n: c.max });
|
|
252
|
+
const frac = v.includes('.') ? v.split('.')[1]!.length : 0;
|
|
253
|
+
if (c.decimals >= 0 && frac > c.decimals) return T('soma.kit.field_decimals', { label: c.label, n: c.decimals });
|
|
254
|
+
}
|
|
255
|
+
if (c.kind === 'date' && v !== '' && !isIsoDate(v)) return T('soma.kit.field_date', { label: c.label });
|
|
256
|
+
// 与字段规则同一份带防护的正则实现:模式非法 / 超长(null)放行,被测文本超长视为不通过且不执行匹配
|
|
257
|
+
if (c.pattern !== '' && v !== '' && testRegexGuarded(c.pattern, v) === false) {
|
|
258
|
+
return c.patternMessage !== '' ? c.patternMessage : T('soma.kit.field_format', { label: c.label });
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** 一行草稿的全部列错误(每列至多一条,按列序):col 为列 key */
|
|
264
|
+
export function rowDraftErrors(columns: readonly KitRowColumn[], draft: Readonly<Record<string, string>>, requiredText: string, at?: Element | string | null): Array<{ col: string; message: string }> {
|
|
265
|
+
const out: Array<{ col: string; message: string }> = [];
|
|
223
266
|
for (const c of columns) {
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (c.kind === 'date' && v !== '' && !isIsoDate(v)) return T('soma.kit.field_date', { label: c.label });
|
|
236
|
-
if (c.pattern !== '' && v !== '') {
|
|
237
|
-
let re: RegExp | null = null;
|
|
238
|
-
try { re = new RegExp(c.pattern); } catch { re = null; }
|
|
239
|
-
if (re && !re.test(v)) return c.patternMessage !== '' ? c.patternMessage : T('soma.kit.field_format', { label: c.label });
|
|
240
|
-
}
|
|
267
|
+
const message = columnDraftError(c, draft, requiredText, at);
|
|
268
|
+
if (message !== null) out.push({ col: c.key, message });
|
|
269
|
+
}
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** 录入校验(纯函数):通过返回 null,否则返回提示文字(第一条) */
|
|
274
|
+
export function validateRowDraft(columns: readonly KitRowColumn[], draft: Readonly<Record<string, string>>, requiredText: string, at?: Element | string | null): string | null {
|
|
275
|
+
for (const c of columns) {
|
|
276
|
+
const message = columnDraftError(c, draft, requiredText, at);
|
|
277
|
+
if (message !== null) return message;
|
|
241
278
|
}
|
|
242
279
|
return null;
|
|
243
280
|
}
|
|
244
281
|
|
|
282
|
+
/** 行是否有内容:任一列(含只读列:服务端回填的编号、名称)存在非空值(空串 / null / undefined / 空数组 / 等于列缺省值的都算空) */
|
|
283
|
+
function rowHasContent(columns: readonly KitRowColumn[], row: Readonly<Record<string, unknown>>): boolean {
|
|
284
|
+
for (const c of columns) {
|
|
285
|
+
const v = row[c.key];
|
|
286
|
+
if (v === undefined || v === null) continue;
|
|
287
|
+
if (Array.isArray(v)) { if (v.length > 0) return true; continue; }
|
|
288
|
+
const t = (typeof v === 'object' ? JSON.stringify(v) : String(v)).trim();
|
|
289
|
+
if (t === '' || t === c.dflt.trim()) continue;
|
|
290
|
+
if (c.kind === 'bool' && t === 'false' && c.dflt !== 'true') continue;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
245
296
|
/** 草稿 -> 行:bool 转布尔,json 能解析就解析,其余原样字符串(text 去首尾空白) */
|
|
246
297
|
export function draftToRow(columns: readonly KitRowColumn[], draft: Readonly<Record<string, string>>): Record<string, unknown> {
|
|
247
298
|
const row: Record<string, unknown> = {};
|
|
@@ -304,9 +355,28 @@ export function inlineCellValue(col: KitRowColumn, text: string): unknown {
|
|
|
304
355
|
return text;
|
|
305
356
|
}
|
|
306
357
|
|
|
358
|
+
/** 子表单元格错误:row 为行下标,col 为列 key */
|
|
359
|
+
export interface KitRowCellError { row: number; col: string; message: string }
|
|
360
|
+
|
|
361
|
+
/** 整张子表逐行逐格校验(纯函数,不含行数上下限):返回全部单元格错误,行序、列序;locked_key 行跳过 */
|
|
362
|
+
export function validateInlineRowCells(
|
|
363
|
+
columns: readonly KitRowColumn[],
|
|
364
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
365
|
+
opts: { requiredText?: string; lockedKey?: string } = {},
|
|
366
|
+
at?: Element | string | null,
|
|
367
|
+
): KitRowCellError[] {
|
|
368
|
+
const requiredText = opts.requiredText ?? kitText('soma.kit.row_required', undefined, at);
|
|
369
|
+
const out: KitRowCellError[] = [];
|
|
370
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
371
|
+
if (opts.lockedKey !== undefined && opts.lockedKey !== '' && rows[i]![opts.lockedKey] === true) continue;
|
|
372
|
+
for (const e of rowDraftErrors(columns, rowToDraft(columns, rows[i]!), requiredText, at)) out.push({ row: i, col: e.col, message: e.message });
|
|
373
|
+
}
|
|
374
|
+
return out;
|
|
375
|
+
}
|
|
376
|
+
|
|
307
377
|
/**
|
|
308
378
|
* 整张子表的提交前校验(纯函数):行数上下限,再逐行逐列沿用录入校验(required / pattern / 数值范围),
|
|
309
|
-
* 错误带「第 N
|
|
379
|
+
* 错误带「第 N 行:」前缀,只返回第一条。通过返回 null。全部错误用 validateInlineRowCells。
|
|
310
380
|
*/
|
|
311
381
|
export function validateInlineRows(
|
|
312
382
|
columns: readonly KitRowColumn[],
|
|
@@ -318,13 +388,8 @@ export function validateInlineRows(
|
|
|
318
388
|
const maxRows = Math.max(0, Math.floor(opts.maxRows ?? 0));
|
|
319
389
|
if (minRows > 0 && rows.length < minRows) return kitText('soma.kit.rows_min', { n: minRows }, at);
|
|
320
390
|
if (maxRows > 0 && rows.length > maxRows) return kitText('soma.kit.rows_max', { n: maxRows }, at);
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
if (opts.lockedKey !== undefined && opts.lockedKey !== '' && rows[i]![opts.lockedKey] === true) continue;
|
|
324
|
-
const message = validateRowDraft(columns, rowToDraft(columns, rows[i]!), requiredText, at);
|
|
325
|
-
if (message !== null) return kitText('soma.kit.rows_row_error', { n: i + 1, message }, at);
|
|
326
|
-
}
|
|
327
|
-
return null;
|
|
391
|
+
const first = validateInlineRowCells(columns, rows, opts, at)[0];
|
|
392
|
+
return first !== undefined ? kitText('soma.kit.rows_row_error', { n: first.row + 1, message: first.message }, at) : null;
|
|
328
393
|
}
|
|
329
394
|
|
|
330
395
|
// ── 组件 ──
|
|
@@ -335,9 +400,14 @@ interface EditorState {
|
|
|
335
400
|
rows: Array<Record<string, unknown>>;
|
|
336
401
|
rowsSig: string;
|
|
337
402
|
localError: string;
|
|
403
|
+
/** 父表单传来的单元格错误(本地可被单格修改逐个清除)与最近一次收到的入参签名 */
|
|
404
|
+
cellErrors: KitRowCellError[];
|
|
405
|
+
cellErrSig: string;
|
|
338
406
|
pendingClear: boolean;
|
|
339
407
|
/** 行内编辑模式的行表签名(结构不变就不重建,输入框焦点与光标不丢) */
|
|
340
408
|
listSig: string;
|
|
409
|
+
/** 最近向外派发 change 的本地快照记录(防止父级滞后回灌冲掉最新输入并失焦) */
|
|
410
|
+
emittedSnapshots: string[];
|
|
341
411
|
/** 行内编辑的单元格控件(自绘下拉 / 日期框):行表重建前统一释放 */
|
|
342
412
|
cellEmbeds: KitEmbedBag;
|
|
343
413
|
nodes: { list: HTMLElement; form: HTMLElement; err: HTMLElement; title: HTMLElement; hint: HTMLElement; count: HTMLElement } | null;
|
|
@@ -349,9 +419,18 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
349
419
|
const states = new WeakMap<HTMLElement, EditorState>();
|
|
350
420
|
const stateOf = (root: HTMLElement): EditorState => {
|
|
351
421
|
let s = states.get(root);
|
|
352
|
-
if (!s) { s = { columnsSig: '', draft: {}, rows: [], rowsSig: '', localError: '', pendingClear: false, listSig: '', cellEmbeds: createKitEmbedBag(), nodes: null, embeds: createKitEmbedBag() }; states.set(root, s); }
|
|
422
|
+
if (!s) { s = { columnsSig: '', draft: {}, rows: [], rowsSig: '', localError: '', cellErrors: [], cellErrSig: '', pendingClear: false, listSig: '', emittedSnapshots: [], cellEmbeds: createKitEmbedBag(), nodes: null, embeds: createKitEmbedBag() }; states.set(root, s); }
|
|
353
423
|
return s;
|
|
354
424
|
};
|
|
425
|
+
const recordSnapshot = (st: EditorState): void => {
|
|
426
|
+
try {
|
|
427
|
+
const snap = JSON.stringify(st.rows);
|
|
428
|
+
st.emittedSnapshots.push(snap);
|
|
429
|
+
if (st.emittedSnapshots.length > 30) {
|
|
430
|
+
st.emittedSnapshots.splice(0, st.emittedSnapshots.length - 30);
|
|
431
|
+
}
|
|
432
|
+
} catch {}
|
|
433
|
+
};
|
|
355
434
|
const resetDraft = (st: EditorState, cols: readonly KitRowColumn[]): void => {
|
|
356
435
|
for (const c of cols) st.draft[c.key] = c.kind === 'bool' ? (c.dflt === 'true' ? 'true' : 'false') : c.dflt;
|
|
357
436
|
st.columnsSig = '';
|
|
@@ -374,11 +453,25 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
374
453
|
}
|
|
375
454
|
const stages = new WeakMap<HTMLElement, StageState>();
|
|
376
455
|
const apis = new WeakMap<HTMLElement, KitApi>();
|
|
456
|
+
/** 删行确认框打开期间的组件根(防重复点击叠弹窗) */
|
|
457
|
+
const removeAsking = new WeakSet<HTMLElement>();
|
|
377
458
|
|
|
378
459
|
// ── GB5:select 列的远程选项(options.from)──
|
|
379
460
|
// 按根登记已取回的候选;key = from + params + rowsPath。取数中显示『选项加载中…』、失败显示『选项加载失败』,都不假装有选项。
|
|
380
461
|
interface RemoteSlot { state: 'loading' | 'ok' | 'failed'; options: Array<{ value: string; label: string }> }
|
|
381
462
|
const remotes = new WeakMap<HTMLElement, Map<string, RemoteSlot>>();
|
|
463
|
+
const optionsKeyOf = (of: KitRowOptionsFrom): string => JSON.stringify([of.from, of.params, of.rowsPath, of.valueKey, of.labelKey]);
|
|
464
|
+
const withOptionsRetry = (holder: HTMLElement, column: KitRowColumn): HTMLElement => {
|
|
465
|
+
if ((column.optionsRetryState !== 'failed' && column.optionsRetryState !== 'loading') || column.optionsKey === undefined) return holder;
|
|
466
|
+
const box = mk('span', FIELD_WRAP);
|
|
467
|
+
box.appendChild(holder);
|
|
468
|
+
const loading = column.optionsRetryState === 'loading';
|
|
469
|
+
const retry = retryButton('options_retry', column.optionsRetryLabel ?? kitText(loading ? 'soma.kit.rows_options_loading' : 'soma.kit.ct_retry'));
|
|
470
|
+
retry.setAttribute('data-kit-option-key', column.optionsKey);
|
|
471
|
+
if (loading) retry.setAttribute('aria-disabled', 'true');
|
|
472
|
+
box.appendChild(retry);
|
|
473
|
+
return box;
|
|
474
|
+
};
|
|
382
475
|
/** 把远程选项叠到列声明上(纯叠加;取数在这里发起,回来后整体重绘) */
|
|
383
476
|
const overlayRemote = (root: HTMLElement, cols: KitRowColumn[]): KitRowColumn[] => {
|
|
384
477
|
if (!cols.some((c) => c.optionsFrom !== null)) return cols;
|
|
@@ -388,7 +481,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
388
481
|
return cols.map((c) => {
|
|
389
482
|
const of = c.optionsFrom;
|
|
390
483
|
if (of === null) return c;
|
|
391
|
-
const key =
|
|
484
|
+
const key = optionsKeyOf(of);
|
|
392
485
|
let slot = mine.get(key);
|
|
393
486
|
if (slot === undefined) {
|
|
394
487
|
const fresh: RemoteSlot = { state: 'loading', options: [] };
|
|
@@ -401,18 +494,43 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
401
494
|
const api = apis.get(root);
|
|
402
495
|
if (api) paint(root, api.props());
|
|
403
496
|
};
|
|
404
|
-
|
|
497
|
+
// 第 5 参 root:按组件所在页面宿主取信封(同一文档多宿主时不串)
|
|
498
|
+
fetchRemoteOptionRows(apis.get(root)?.services, of.from, of.params, of.rowsPath, root)
|
|
405
499
|
.then((rows) => done('ok', rows.map((r) => ({ value: textOf(r[of.valueKey]), label: textOf(r[of.labelKey]) || textOf(r[of.valueKey]) })).filter((o) => o.value !== '')))
|
|
406
500
|
.catch(() => done('failed', []));
|
|
407
501
|
}
|
|
408
502
|
return {
|
|
409
503
|
...c,
|
|
410
504
|
options: slot.options,
|
|
505
|
+
optionsError: slot.state === 'failed',
|
|
506
|
+
optionsKey: key,
|
|
507
|
+
optionsRetryState: slot.state,
|
|
508
|
+
optionsRetryLabel: kitText(slot.state === 'loading' ? 'soma.kit.rows_options_loading' : 'soma.kit.ct_retry', undefined, root),
|
|
411
509
|
placeholder: slot.state === 'loading' ? kitText('soma.kit.rows_options_loading', undefined, root)
|
|
412
510
|
: slot.state === 'failed' ? kitText('soma.kit.rows_options_failed', undefined, root) : c.placeholder,
|
|
413
511
|
};
|
|
414
512
|
});
|
|
415
513
|
};
|
|
514
|
+
const retryRemoteOptions = (root: HTMLElement, key: string): void => {
|
|
515
|
+
const mine = remotes.get(root);
|
|
516
|
+
const previous = mine?.get(key);
|
|
517
|
+
const api = apis.get(root);
|
|
518
|
+
if (!mine || previous?.state !== 'failed' || !api) return;
|
|
519
|
+
const column = rowColumnsOf(api.props().columns, root).find((c) => c.optionsFrom !== null && optionsKeyOf(c.optionsFrom) === key);
|
|
520
|
+
if (!column?.optionsFrom) return;
|
|
521
|
+
const fresh: RemoteSlot = { state: 'loading', options: [] };
|
|
522
|
+
mine.set(key, fresh);
|
|
523
|
+
const done = (state: 'ok' | 'failed', options: Array<{ value: string; label: string }>): void => {
|
|
524
|
+
if (remotes.get(root) !== mine || mine.get(key) !== fresh) return;
|
|
525
|
+
fresh.state = state;
|
|
526
|
+
fresh.options = options;
|
|
527
|
+
paint(root, api.props());
|
|
528
|
+
};
|
|
529
|
+
paint(root, api.props());
|
|
530
|
+
fetchRemoteOptionRows(api.services, column.optionsFrom.from, column.optionsFrom.params, column.optionsFrom.rowsPath, root)
|
|
531
|
+
.then((rows) => done('ok', rows.map((r) => ({ value: textOf(r[column.optionsFrom!.valueKey]), label: textOf(r[column.optionsFrom!.labelKey]) || textOf(r[column.optionsFrom!.valueKey]) })).filter((o) => o.value !== '')))
|
|
532
|
+
.catch(() => done('failed', []));
|
|
533
|
+
};
|
|
416
534
|
const stageOf = (root: HTMLElement): StageState => {
|
|
417
535
|
let s = stages.get(root);
|
|
418
536
|
if (!s) { s = { base: null, sent: null, stale: false, awaiting: false, syncing: false, failMsg: '', scope: '', off: null, bar: null, barSig: '', lastCount: 0 }; stages.set(root, s); }
|
|
@@ -552,13 +670,14 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
552
670
|
props: {
|
|
553
671
|
data: { type: 'object', default: {}, desc: '{ title?, hint?, rows[], error? }' },
|
|
554
672
|
value: { type: 'array', default: [], desc: '行数组(作表单字段控件时由表单给出,优先于 data.rows);change { value } 抛出完整行数组' },
|
|
555
|
-
|
|
556
|
-
|
|
673
|
+
...ID_PROPS,
|
|
674
|
+
...INVALID_PROPS,
|
|
557
675
|
disabled: { type: 'boolean', default: false, desc: '禁用:同只读(无录入区、删除钮与单格编辑)' },
|
|
558
676
|
edit_mode: { type: 'enum', values: ['append', 'inline'], default: 'append', desc: 'append(缺省)= 下方录入区逐条添加;inline = 行内多行编辑,每行每格就地可改,每次改动抛 change(作表单字段时值随表单提交)' },
|
|
559
677
|
locked_key: { type: 'string', default: '', desc: '行级只读:该字段为真的行,所有列显示为纯文字、不可改(如敏感字段不允许勾选);提交校验也跳过这些行。只在 edit_mode: inline 生效' },
|
|
560
678
|
fixed_rows: { type: 'boolean', default: false, desc: '行由数据给定,不可增删(无添加钮与删除钮),只改 editable 的列;常用于「字段策略」这类逐行勾选' },
|
|
561
679
|
columns: { type: 'array', default: [], desc: '列 [{ key, label, kind?: text|select|bool|json|number|money|date, min?, max?, decimals?, currency?, sum?(number/money 参与合计,缺省真), options?, placeholder?, required?, pattern?, pattern_message?, mono?, span?, default?, true_label?, false_label?, required_message?, editable?(假=只读展示列), list?(假=只在录入区) }]' },
|
|
680
|
+
cell_errors: { type: 'array', default: [], desc: '单元格错误 [{ row, col, message }](row 行下标、col 列 key):由表单提交校验失败后传入,对应单元格控件标 aria-invalid、外框标红并以 title 给出该格消息;改某格即清除该格标记。只在 edit_mode: inline 生效' },
|
|
562
681
|
row_key: { type: 'string', default: '', desc: '主键列(同主键视为替换),缺省第一列' },
|
|
563
682
|
readonly: { type: 'boolean', default: false, desc: '只读:无录入区与删除钮' },
|
|
564
683
|
...KIT_BUSY_PROP_DEFS,
|
|
@@ -593,7 +712,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
593
712
|
},
|
|
594
713
|
services: ['data', 'http'],
|
|
595
714
|
templateHtml: `<section data-soma-id="root" class="@container ${ROOT_CLASS}"></section>`,
|
|
596
|
-
controllerFactory: createKitController({
|
|
715
|
+
controllerFactory: createKitController(() => ({
|
|
597
716
|
busyAware: true,
|
|
598
717
|
attach(root, api) {
|
|
599
718
|
apis.set(root, api);
|
|
@@ -618,6 +737,13 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
618
737
|
const next = inlineCellValue(col, el.value);
|
|
619
738
|
if (JSON.stringify(row[cell]) === JSON.stringify(next)) return;
|
|
620
739
|
st.rows = st.rows.map((r, i) => (i === index ? { ...r, [cell]: next } : r));
|
|
740
|
+
recordSnapshot(st);
|
|
741
|
+
// 改了这一格:该格的校验错误标记即时清除(其余格保留,等下次提交重算)
|
|
742
|
+
if (st.cellErrors.some((e) => e.row === index && e.col === cell)) {
|
|
743
|
+
st.cellErrors = st.cellErrors.filter((e) => !(e.row === index && e.col === cell));
|
|
744
|
+
st.cellErrSig = ''; // 下次下传的列表(哪怕与上次内容相同)也要重新采用
|
|
745
|
+
applyCellErrors(root, st);
|
|
746
|
+
}
|
|
621
747
|
// st.rowsSig 不动:它记的是「上次收到的外部行」,表单回灌与本地副本一致的值时 paint 不重建
|
|
622
748
|
const allCols = rowColumnsOf(p.columns, root);
|
|
623
749
|
api.emit('change', { value: st.rows, totals: rowTotals(allCols, st.rows) });
|
|
@@ -637,6 +763,11 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
637
763
|
const cols = rowColumnsOf(p.columns, root);
|
|
638
764
|
const key = keyOf();
|
|
639
765
|
const act = btn.getAttribute('data-kit-action');
|
|
766
|
+
if (act === 'options_retry') {
|
|
767
|
+
const optionKey = btn.getAttribute('data-kit-option-key');
|
|
768
|
+
if (optionKey !== null && btn.getAttribute('aria-disabled') !== 'true') retryRemoteOptions(root, optionKey);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
640
771
|
if (act === 'stage_sync') { stageSync(root, p); return; }
|
|
641
772
|
if (act === 'stage_discard') { void stageDiscard(root, p); return; }
|
|
642
773
|
if (act === 'add_row') {
|
|
@@ -653,6 +784,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
653
784
|
for (const c of cols) blank[c.key] = c.kind === 'bool' ? (c.dflt === 'true' ? 'true' : 'false') : c.dflt;
|
|
654
785
|
st.rows = [...st.rows, draftToRow(cols, blank)];
|
|
655
786
|
st.localError = '';
|
|
787
|
+
recordSnapshot(st);
|
|
656
788
|
api.emit('change', { value: st.rows, totals: rowTotals(cols, st.rows) });
|
|
657
789
|
paint(root, api.props());
|
|
658
790
|
const last = root.querySelectorAll<HTMLElement>(`[data-kit-index="${st.rows.length - 1}"][data-kit-cell]`);
|
|
@@ -671,17 +803,46 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
671
803
|
api.emit('invalid', { message: msg });
|
|
672
804
|
return;
|
|
673
805
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
806
|
+
// 先按引用定位;确认期间外部换了行数据(引用失效)时,按主键值重新定位(主键值为空或不唯一则放弃)
|
|
807
|
+
const locate = (): number => {
|
|
808
|
+
const byRef = st.rows.indexOf(row);
|
|
809
|
+
if (byRef >= 0) return byRef;
|
|
810
|
+
const kv = key !== '' ? textOf(row[key]) : '';
|
|
811
|
+
if (kv === '') return -1;
|
|
812
|
+
const hits: number[] = [];
|
|
813
|
+
st.rows.forEach((r, i) => { if (textOf(r[key]) === kv) hits.push(i); });
|
|
814
|
+
return hits.length === 1 ? hits[0]! : -1;
|
|
815
|
+
};
|
|
816
|
+
const doRemove = (): void => {
|
|
817
|
+
const at = locate();
|
|
818
|
+
if (at < 0 || !root.isConnected) return;
|
|
819
|
+
const live = api.props();
|
|
820
|
+
api.emit('remove', { key: textOf(st.rows[at]![key]), row: st.rows[at]!, index: at });
|
|
821
|
+
if (bool(live.auto_apply) || bool(live.staged) || str(live.edit_mode) === 'inline') {
|
|
822
|
+
st.rows = st.rows.filter((_, i) => i !== at);
|
|
823
|
+
st.rowsSig = incomingSig(live);
|
|
824
|
+
st.localError = '';
|
|
825
|
+
st.cellErrors = []; // 行下标整体位移,旧的单元格错误失效
|
|
826
|
+
st.cellErrSig = '';
|
|
827
|
+
recordSnapshot(st);
|
|
828
|
+
api.emit('change', { value: st.rows, totals: rowTotals(cols, st.rows) });
|
|
829
|
+
paint(root, live);
|
|
830
|
+
// 行表重绘后焦点会丢:落到同位置(或最后一行)的删除钮,没有行了就落到录入区第一格
|
|
831
|
+
const removes = root.querySelectorAll<HTMLElement>('[data-kit-action="remove"]');
|
|
832
|
+
(removes[Math.min(at, removes.length - 1)] ?? root.querySelector<HTMLElement>('[data-kit-field]'))?.focus();
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
// 有内容的行先自绘确认(danger),空行直接删;确认弹出期间重复点击不叠加
|
|
836
|
+
if (rowHasContent(cols, row)) {
|
|
837
|
+
if (removeAsking.has(root)) return;
|
|
838
|
+
removeAsking.add(root);
|
|
839
|
+
void askKitConfirm({ message: kitText('soma.kit.confirm_remove', undefined, root), tone: 'danger', at: root })
|
|
840
|
+
.then((ok) => { if (ok) doRemove(); })
|
|
841
|
+
.catch((err) => { console.error('[soma-kit] 删除行失败', err); }) // 不成为未处理的拒绝;确认框已关闭,行保持原样
|
|
842
|
+
.finally(() => { removeAsking.delete(root); });
|
|
843
|
+
return;
|
|
684
844
|
}
|
|
845
|
+
doRemove();
|
|
685
846
|
return;
|
|
686
847
|
}
|
|
687
848
|
if (act === 'add') {
|
|
@@ -707,6 +868,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
707
868
|
if (bool(p.auto_apply) || bool(p.staged)) {
|
|
708
869
|
st.rows = key === '' ? [...st.rows, row] : [...st.rows.filter((r) => textOf(r[key]) !== textOf(row[key])), row];
|
|
709
870
|
st.rowsSig = incomingSig(p);
|
|
871
|
+
recordSnapshot(st);
|
|
710
872
|
api.emit('change', { value: st.rows, totals: rowTotals(cols, st.rows) });
|
|
711
873
|
resetDraft(st, cols);
|
|
712
874
|
paint(root, api.props());
|
|
@@ -725,11 +887,18 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
725
887
|
event.preventDefault();
|
|
726
888
|
add.click();
|
|
727
889
|
};
|
|
890
|
+
// 表单把 aria-invalid 也标在组件根上(文档顺序里先于单元格):根被聚焦时转交给首个出错单元格
|
|
891
|
+
const onRootFocus = (event: Event): void => {
|
|
892
|
+
if (event.target !== root) return;
|
|
893
|
+
root.querySelector<HTMLElement>('[data-kit-row] [aria-invalid="true"]')?.focus({ preventScroll: true });
|
|
894
|
+
};
|
|
895
|
+
root.addEventListener('focus', onRootFocus);
|
|
728
896
|
root.addEventListener('input', onInput);
|
|
729
897
|
root.addEventListener('change', onInput);
|
|
730
898
|
root.addEventListener('click', onClick);
|
|
731
899
|
root.addEventListener('keydown', onKeydown);
|
|
732
900
|
return () => {
|
|
901
|
+
root.removeEventListener('focus', onRootFocus);
|
|
733
902
|
root.removeEventListener('input', onInput);
|
|
734
903
|
root.removeEventListener('change', onInput);
|
|
735
904
|
root.removeEventListener('click', onClick);
|
|
@@ -746,9 +915,69 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
746
915
|
render(root, p) {
|
|
747
916
|
paint(root, p);
|
|
748
917
|
},
|
|
749
|
-
}),
|
|
918
|
+
})),
|
|
750
919
|
};
|
|
751
920
|
|
|
921
|
+
/** 入参 cell_errors -> 本地:入参签名变了就整体采用(含空列表);表单在字段出错期间每次都按当前草稿重算后下传,入参即真相 */
|
|
922
|
+
function adoptCellErrors(st: EditorState, raw: unknown): void {
|
|
923
|
+
const list: KitRowCellError[] = [];
|
|
924
|
+
if (Array.isArray(raw)) {
|
|
925
|
+
for (const e of raw) {
|
|
926
|
+
const r = recOf(e);
|
|
927
|
+
const row = Number(r.row);
|
|
928
|
+
if (Number.isInteger(row) && row >= 0 && typeof r.col === 'string') list.push({ row, col: r.col, message: textOf(r.message) });
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
const sig = JSON.stringify(list);
|
|
932
|
+
if (sig === st.cellErrSig) return;
|
|
933
|
+
st.cellErrSig = sig;
|
|
934
|
+
st.cellErrors = list;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/** 把 st.cellErrors 画到单元格:控件 aria-invalid、外框令牌色环、单元格 title 给出消息(不加行高);无错的格还原 */
|
|
938
|
+
function applyCellErrors(root: HTMLElement, st: EditorState): void {
|
|
939
|
+
const bad = new Map<string, string>();
|
|
940
|
+
for (const e of st.cellErrors) bad.set(`${e.row}\u0000${e.col}`, e.message);
|
|
941
|
+
const tokens = CELL_ERROR_CLASS.split(' ');
|
|
942
|
+
root.querySelectorAll<HTMLElement>('[data-kit-cell]').forEach((control) => {
|
|
943
|
+
const message = bad.get(`${control.getAttribute('data-kit-index')}\u0000${control.getAttribute('data-kit-cell')}`);
|
|
944
|
+
// 自绘下拉的载体是 hidden input,可见且可聚焦的是同壳的 combobox
|
|
945
|
+
const visible = control.closest<HTMLElement>('[data-kit-select-host]')?.querySelector<HTMLElement>('[role="combobox"]') ?? control;
|
|
946
|
+
const wrap = control.closest<HTMLElement>('[data-kit-row] > span');
|
|
947
|
+
// 错误文字节点(仅读屏可见,不加行高):控件 aria-describedby 指向它,title 只作鼠标悬停的补充
|
|
948
|
+
const errNode = wrap?.querySelector<HTMLElement>('[data-kit-cell-error]') ?? null;
|
|
949
|
+
const describedTokens = (visible.getAttribute('aria-describedby') ?? '').split(/\s+/).filter((t) => t !== '');
|
|
950
|
+
if (message !== undefined) {
|
|
951
|
+
visible.setAttribute('aria-invalid', 'true');
|
|
952
|
+
wrap?.classList.add(...tokens);
|
|
953
|
+
wrap?.setAttribute('title', message);
|
|
954
|
+
if (wrap) {
|
|
955
|
+
const node = errNode ?? mk('span', 'sr-only');
|
|
956
|
+
if (!errNode) {
|
|
957
|
+
node.setAttribute('data-kit-cell-error', '');
|
|
958
|
+
node.id = nextUid('kit-cell-err');
|
|
959
|
+
wrap.appendChild(node);
|
|
960
|
+
}
|
|
961
|
+
node.textContent = message;
|
|
962
|
+
if (!describedTokens.includes(node.id)) visible.setAttribute('aria-describedby', [...describedTokens, node.id].join(' '));
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
visible.removeAttribute('aria-invalid');
|
|
966
|
+
wrap?.classList.remove(...tokens);
|
|
967
|
+
wrap?.removeAttribute('title');
|
|
968
|
+
if (errNode) {
|
|
969
|
+
const rest = describedTokens.filter((t) => t !== errNode.id);
|
|
970
|
+
if (rest.length > 0) visible.setAttribute('aria-describedby', rest.join(' '));
|
|
971
|
+
else visible.removeAttribute('aria-describedby');
|
|
972
|
+
errNode.remove();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
// 根要能接住表单的 focus() 再转交给出错单元格
|
|
977
|
+
if (st.cellErrors.length > 0) root.setAttribute('tabindex', '-1');
|
|
978
|
+
else root.removeAttribute('tabindex');
|
|
979
|
+
}
|
|
980
|
+
|
|
752
981
|
function showError(root: HTMLElement, st: EditorState, external: string): void {
|
|
753
982
|
const text = st.localError !== '' ? st.localError : external;
|
|
754
983
|
const err = st.nodes?.err;
|
|
@@ -782,6 +1011,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
782
1011
|
holder = field.el;
|
|
783
1012
|
} else {
|
|
784
1013
|
const input = mk('input', c.mono || c.kind === 'json' ? `${FIELD_CLASS.md} ${TEXTAREA_LIKE}` : isNumericRowKind(c.kind) ? `${FIELD_CLASS.md} ${NUM_ALIGN}` : FIELD_CLASS.md);
|
|
1014
|
+
setKitFace(input, 'field');
|
|
785
1015
|
input.type = 'text';
|
|
786
1016
|
if (isNumericRowKind(c.kind)) input.inputMode = 'decimal';
|
|
787
1017
|
input.placeholder = c.placeholder;
|
|
@@ -793,7 +1023,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
793
1023
|
}
|
|
794
1024
|
control.setAttribute('data-kit-cell', c.key);
|
|
795
1025
|
control.setAttribute('data-kit-index', String(index));
|
|
796
|
-
return holder;
|
|
1026
|
+
return withOptionsRetry(holder, c);
|
|
797
1027
|
}
|
|
798
1028
|
|
|
799
1029
|
/** 行内编辑的合计行:随单格改动就地刷新数字(不重建行表,输入焦点不丢) */
|
|
@@ -808,25 +1038,37 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
808
1038
|
|
|
809
1039
|
/** 行内多行编辑的行表:每行每格就地可改;readonly / disabled 时退回纯文字;fixed_rows 时没有添加 / 删除 */
|
|
810
1040
|
function paintInlineList(root: HTMLElement, st: EditorState, p: Record<string, unknown>, list: HTMLElement, cols: readonly KitRowColumn[], readonly: boolean, fixedRows: boolean): void {
|
|
1041
|
+
let focusRestore: { index: string; cell: string; start: number | null; end: number | null } | null = null;
|
|
1042
|
+
const active = typeof document !== 'undefined' ? document.activeElement : null;
|
|
1043
|
+
if (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) {
|
|
1044
|
+
const idx = active.getAttribute('data-kit-index');
|
|
1045
|
+
const cell = active.getAttribute('data-kit-cell');
|
|
1046
|
+
if (idx !== null && cell !== null && list.contains(active)) {
|
|
1047
|
+
focusRestore = { index: idx, cell, start: active.selectionStart, end: active.selectionEnd };
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
811
1050
|
st.cellEmbeds.release(list);
|
|
812
1051
|
list.textContent = '';
|
|
813
1052
|
const shown = cols.filter((c) => c.list);
|
|
814
1053
|
const structural = !readonly && !fixedRows;
|
|
815
|
-
const spanOf = (c: KitRowColumn): string => `${SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
1054
|
+
const spanOf = (c: KitRowColumn): string => `${structural ? `${FLEX_SPAN[c.span] ?? 'flex-2'} min-w-0` : SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
816
1055
|
if (st.rows.length === 0) {
|
|
817
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1056
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)), true));
|
|
818
1057
|
} else {
|
|
819
|
-
const head = mk('div', HEAD_CLASS);
|
|
1058
|
+
const head = mk('div', structural ? HEAD_END_CLASS : HEAD_CLASS);
|
|
820
1059
|
for (const c of shown) {
|
|
821
1060
|
const cell = mk('span', spanOf(c), c.label);
|
|
822
1061
|
if (c.required && c.editable && !readonly) cell.appendChild(mk('span', REQUIRED_MARK, ' *'));
|
|
823
1062
|
head.appendChild(cell);
|
|
824
1063
|
}
|
|
825
|
-
if (structural) head.appendChild(mk('span',
|
|
1064
|
+
if (structural) head.appendChild(mk('span', END_FLEX_CLASS, str(p.action_label)));
|
|
826
1065
|
list.appendChild(head);
|
|
827
1066
|
st.rows.forEach((row, index) => {
|
|
828
|
-
const tr = mk('div', ROW_CLASS);
|
|
1067
|
+
const tr = mk('div', structural ? ROW_END_CLASS : ROW_CLASS);
|
|
829
1068
|
tr.setAttribute('data-kit-row', String(index));
|
|
1069
|
+
const rowName = kitText('soma.kit.rows_row_n', { n: index + 1 }, root);
|
|
1070
|
+
tr.setAttribute('role', 'group');
|
|
1071
|
+
tr.setAttribute('aria-label', rowName);
|
|
830
1072
|
for (const c of shown) {
|
|
831
1073
|
const wrap = mk('span', `${spanOf(c)} min-w-0`);
|
|
832
1074
|
if (readonly || !c.editable || (str(p.locked_key) !== '' && row[str(p.locked_key)] === true)) {
|
|
@@ -839,9 +1081,10 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
839
1081
|
tr.appendChild(wrap);
|
|
840
1082
|
}
|
|
841
1083
|
if (structural) {
|
|
842
|
-
const cell = mk('span',
|
|
843
|
-
const btn =
|
|
1084
|
+
const cell = mk('span', END_FLEX_CLASS);
|
|
1085
|
+
const btn = textActionButton('remove', str(p.remove_label, kitText('soma.kit.delete', undefined, root)), 'danger');
|
|
844
1086
|
btn.setAttribute('data-kit-index', String(index));
|
|
1087
|
+
btn.setAttribute('aria-label', `${str(p.remove_label, kitText('soma.kit.delete', undefined, root))} ${rowName}`);
|
|
845
1088
|
cell.appendChild(btn);
|
|
846
1089
|
tr.appendChild(cell);
|
|
847
1090
|
}
|
|
@@ -850,7 +1093,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
850
1093
|
if (str(p.footer, 'none') === 'sum') {
|
|
851
1094
|
const totals = rowTotals(shown, st.rows);
|
|
852
1095
|
const labelCol = shown.find((c) => totals[c.key] === undefined);
|
|
853
|
-
const foot = mk('div', FOOTER_ROW_CLASS);
|
|
1096
|
+
const foot = mk('div', structural ? FOOTER_END_CLASS : FOOTER_ROW_CLASS);
|
|
854
1097
|
foot.setAttribute('data-kit-footer', 'sum');
|
|
855
1098
|
for (const c of shown) {
|
|
856
1099
|
const total = totals[c.key];
|
|
@@ -859,7 +1102,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
859
1102
|
if (total !== undefined) cell.setAttribute('data-kit-total', c.key);
|
|
860
1103
|
foot.appendChild(cell);
|
|
861
1104
|
}
|
|
862
|
-
if (structural) foot.appendChild(mk('span',
|
|
1105
|
+
if (structural) foot.appendChild(mk('span', END_FLEX_CLASS));
|
|
863
1106
|
list.appendChild(foot);
|
|
864
1107
|
}
|
|
865
1108
|
}
|
|
@@ -868,6 +1111,17 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
868
1111
|
bar.appendChild(actionButton({ key: 'add_row', label: str(p.add_label, kitText('soma.kit.rows_add_row', undefined, root)), tone: 'neutral', disabled: false, reason: '' }));
|
|
869
1112
|
list.appendChild(bar);
|
|
870
1113
|
}
|
|
1114
|
+
if (focusRestore !== null) {
|
|
1115
|
+
const target = list.querySelector<HTMLInputElement | HTMLTextAreaElement>(
|
|
1116
|
+
`[data-kit-index="${focusRestore.index}"][data-kit-cell="${focusRestore.cell}"]`,
|
|
1117
|
+
);
|
|
1118
|
+
if (target) {
|
|
1119
|
+
target.focus();
|
|
1120
|
+
if (focusRestore.start !== null && focusRestore.end !== null) {
|
|
1121
|
+
try { target.setSelectionRange(focusRestore.start, focusRestore.end); } catch {}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
871
1125
|
}
|
|
872
1126
|
|
|
873
1127
|
function paint(root: HTMLElement, p: Record<string, unknown>): void {
|
|
@@ -888,12 +1142,22 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
888
1142
|
// 本地有未同步变更:服务端数据换新时不覆盖工作副本(否则会悄悄丢掉用户的编辑),只换基线并提示「已在别处更新」
|
|
889
1143
|
stg.base = cloneRows(next);
|
|
890
1144
|
stg.stale = true;
|
|
891
|
-
} else
|
|
892
|
-
|
|
893
|
-
st.rows
|
|
894
|
-
|
|
895
|
-
if (
|
|
896
|
-
|
|
1145
|
+
} else {
|
|
1146
|
+
const nextJson = JSON.stringify(next);
|
|
1147
|
+
const currJson = JSON.stringify(st.rows);
|
|
1148
|
+
const isEcho = given !== null && (nextJson === currJson || st.emittedSnapshots.includes(nextJson));
|
|
1149
|
+
if (isEcho) {
|
|
1150
|
+
// 父级回灌的值等于本地当前行或任一刚发出的滞后快照(回声):视为滞后回灌,不冲掉本地编辑,不重建 DOM
|
|
1151
|
+
const idx = st.emittedSnapshots.indexOf(nextJson);
|
|
1152
|
+
if (idx >= 0) st.emittedSnapshots.splice(0, idx + 1);
|
|
1153
|
+
} else {
|
|
1154
|
+
// 真正外部换新才更新本地行与触发重建
|
|
1155
|
+
st.emittedSnapshots = [];
|
|
1156
|
+
st.rows = next;
|
|
1157
|
+
st.listSig = '';
|
|
1158
|
+
if (st.pendingClear) { st.pendingClear = false; resetDraft(st, cols); }
|
|
1159
|
+
if (stg !== null) { stg.base = cloneRows(next); stg.stale = false; }
|
|
1160
|
+
}
|
|
897
1161
|
}
|
|
898
1162
|
}
|
|
899
1163
|
if (bool(p.staged)) {
|
|
@@ -902,6 +1166,19 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
902
1166
|
bindStageOutcome(root, p);
|
|
903
1167
|
}
|
|
904
1168
|
if (p.id !== undefined && str(p.id) !== '') root.id = str(p.id);
|
|
1169
|
+
// 根是一组行:role=group(不让具名 section 变成 region 地标);名字取表单传入的标签 id / aria_label / 标题;必填 / 无效 / 说明关联由 props 写入,重绘不丢
|
|
1170
|
+
root.setAttribute('role', 'group');
|
|
1171
|
+
applyCommon(root, {
|
|
1172
|
+
id: root.id,
|
|
1173
|
+
aria_label: str(p.aria_label, textOf(data.title)),
|
|
1174
|
+
labelledby: p.labelledby,
|
|
1175
|
+
required: p.required,
|
|
1176
|
+
invalid: p.invalid,
|
|
1177
|
+
describedby: p.describedby,
|
|
1178
|
+
aria_describedby: p.aria_describedby,
|
|
1179
|
+
errormessage: p.errormessage,
|
|
1180
|
+
aria_errormessage: p.aria_errormessage,
|
|
1181
|
+
});
|
|
905
1182
|
const shown = cols.filter((c) => c.list);
|
|
906
1183
|
root.className = joinClass(`@container ${ROOT_CLASS}`, p.class);
|
|
907
1184
|
|
|
@@ -937,25 +1214,30 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
937
1214
|
}
|
|
938
1215
|
} else if (st.rows.length === 0) {
|
|
939
1216
|
list.textContent = '';
|
|
940
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1217
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)), true));
|
|
941
1218
|
} else {
|
|
942
1219
|
list.textContent = '';
|
|
943
|
-
const
|
|
944
|
-
const
|
|
1220
|
+
const structural = !readonly && !fixedRows;
|
|
1221
|
+
const head = mk('div', structural ? HEAD_END_CLASS : HEAD_CLASS);
|
|
1222
|
+
const spanOf = (c: KitRowColumn): string => `${structural ? `${FLEX_SPAN[c.span] ?? 'flex-2'} min-w-0` : SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
945
1223
|
for (const c of shown) head.appendChild(mk('span', spanOf(c), c.label));
|
|
946
|
-
if (
|
|
1224
|
+
if (structural) head.appendChild(mk('span', END_FLEX_CLASS, str(p.action_label)));
|
|
947
1225
|
list.appendChild(head);
|
|
948
1226
|
st.rows.forEach((row, index) => {
|
|
949
|
-
const tr = mk('div', ROW_CLASS);
|
|
1227
|
+
const tr = mk('div', structural ? ROW_END_CLASS : ROW_CLASS);
|
|
950
1228
|
tr.setAttribute('data-kit-row', textOf(row[key]));
|
|
1229
|
+
const rowName = kitText('soma.kit.rows_row_n', { n: index + 1 }, root);
|
|
1230
|
+
tr.setAttribute('role', 'group');
|
|
1231
|
+
tr.setAttribute('aria-label', rowName);
|
|
951
1232
|
for (const c of shown) {
|
|
952
1233
|
const cls = c.mono || c.kind === 'json' ? CELL_MONO : c.key === shown[0]?.key ? CELL_CLASS : CELL_MUTED;
|
|
953
1234
|
tr.appendChild(mk('span', `${spanOf(c)} ${cls}`, rowCellText(c, row[c.key], str(p.locale))));
|
|
954
1235
|
}
|
|
955
|
-
if (
|
|
956
|
-
const cell = mk('span',
|
|
957
|
-
const btn =
|
|
1236
|
+
if (structural) {
|
|
1237
|
+
const cell = mk('span', END_FLEX_CLASS);
|
|
1238
|
+
const btn = textActionButton('remove', str(p.remove_label, kitText('soma.kit.delete', undefined, root)), 'danger');
|
|
958
1239
|
btn.setAttribute('data-kit-index', String(index));
|
|
1240
|
+
btn.setAttribute('aria-label', `${str(p.remove_label, kitText('soma.kit.delete', undefined, root))} ${rowName}`);
|
|
959
1241
|
cell.appendChild(btn);
|
|
960
1242
|
tr.appendChild(cell);
|
|
961
1243
|
}
|
|
@@ -964,14 +1246,14 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
964
1246
|
if (str(p.footer, 'none') === 'sum') {
|
|
965
1247
|
const totals = rowTotals(shown, st.rows);
|
|
966
1248
|
const labelCol = shown.find((c) => totals[c.key] === undefined);
|
|
967
|
-
const foot = mk('div', FOOTER_ROW_CLASS);
|
|
1249
|
+
const foot = mk('div', structural ? FOOTER_END_CLASS : FOOTER_ROW_CLASS);
|
|
968
1250
|
foot.setAttribute('data-kit-footer', 'sum');
|
|
969
1251
|
for (const c of shown) {
|
|
970
1252
|
const total = totals[c.key];
|
|
971
1253
|
const text = total !== undefined ? rowCellText(c, total, str(p.locale)) : c === labelCol ? str(p.total_label, kitText('soma.kit.total_label', undefined, root)) : '';
|
|
972
1254
|
foot.appendChild(mk('span', spanOf(c), text));
|
|
973
1255
|
}
|
|
974
|
-
if (
|
|
1256
|
+
if (structural) foot.appendChild(mk('span', END_FLEX_CLASS));
|
|
975
1257
|
list.appendChild(foot);
|
|
976
1258
|
}
|
|
977
1259
|
}
|
|
@@ -1025,6 +1307,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1025
1307
|
holder = field.el;
|
|
1026
1308
|
} else {
|
|
1027
1309
|
const input = mk('input', c.mono || c.kind === 'json' ? `${FIELD_CLASS.md} ${TEXTAREA_LIKE}` : isNumericRowKind(c.kind) ? `${FIELD_CLASS.md} ${NUM_ALIGN}` : FIELD_CLASS.md);
|
|
1310
|
+
setKitFace(input, 'field');
|
|
1028
1311
|
input.type = 'text';
|
|
1029
1312
|
if (isNumericRowKind(c.kind)) input.inputMode = 'decimal';
|
|
1030
1313
|
input.placeholder = c.placeholder;
|
|
@@ -1033,7 +1316,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1033
1316
|
control = input;
|
|
1034
1317
|
}
|
|
1035
1318
|
control.setAttribute('data-kit-field', c.key);
|
|
1036
|
-
wrap.appendChild(holder ?? control);
|
|
1319
|
+
wrap.appendChild(withOptionsRetry(holder ?? control, c));
|
|
1037
1320
|
grid.appendChild(wrap);
|
|
1038
1321
|
}
|
|
1039
1322
|
const last = mk('div', `${FIELD_WRAP} self-end`);
|
|
@@ -1044,6 +1327,9 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1044
1327
|
form.hidden = noEntry || !cols.some((c) => c.editable);
|
|
1045
1328
|
}
|
|
1046
1329
|
showError(root, st, textOf(data.error));
|
|
1330
|
+
adoptCellErrors(st, p.cell_errors);
|
|
1331
|
+
if (!inline) { st.cellErrors = []; st.cellErrSig = ''; }
|
|
1332
|
+
applyCellErrors(root, st);
|
|
1047
1333
|
refreshStage(root, p);
|
|
1048
1334
|
// 忙闲通道:所接动作(add / remove / change)在进行中时添加、删除钮禁用并挂 aria-busy,结束后恢复(只还原自己置的禁用)
|
|
1049
1335
|
const busy = kitBusyOf(p);
|