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
|
@@ -10,37 +10,45 @@
|
|
|
10
10
|
// 组件不改数据:写入只抛事件;勾选只抛 select_change(载荷 rows 批量,协调组件维护已选)。
|
|
11
11
|
// 记忆(列显隐、行高):localStorage,键含页面路径与对象名,读写全包 try/catch。
|
|
12
12
|
|
|
13
|
-
import type
|
|
13
|
+
import { substituteConfirmText, type SomaComponentDefinition, type SomaDataPort, type SomaRegionPort } from 'soma-core';
|
|
14
|
+
import { tableQuerySignature } from './collection-table';
|
|
15
|
+
import { KIT_ROW_TONE_CLASS } from './view-binding';
|
|
16
|
+
import { KIT_FACE_FIELD, KIT_FACE_RAISED, kitDisabledRecipe, setKitFace, type KitFaceKind } from '../recipes';
|
|
14
17
|
import { CLASS_PROP, createKitController, num, str } from '../base/shared';
|
|
15
18
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, onOutsidePress, overlayVerdict, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
16
19
|
import { permissionCheckerOf } from '../base/permission-gate';
|
|
17
|
-
import { KIT_CHECK_CLASS_CANDIDATES, attachMarkEvents, createCheck, paintCheck } from '../base/check-core';
|
|
20
|
+
import { KIT_CHECK_CLASS_CANDIDATES, attachMarkEvents, createCheck, isMark, markInput, paintCheck } from '../base/check-core';
|
|
18
21
|
import { attachSpin } from '../base/qty-stepper';
|
|
19
22
|
import { KIT_DATE_CLASS_CANDIDATES, mountKitDateField } from '../base/date';
|
|
20
23
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
21
24
|
import { createKitEmbedBag, mountKitSelectField, type KitEmbedHandle } from '../data/embed';
|
|
22
25
|
import { KIT_TABLE_ACTIONS_CLASS_CANDIDATES, ACTION_BUTTON_CLASS } from './table-actions';
|
|
23
|
-
import { KIT_TABLE_EXT } from './defaults';
|
|
26
|
+
import { KIT_TABLE_DENSITIES, KIT_TABLE_DENSITY_DEFAULT, KIT_TABLE_EXT, type KitTableDensity } from './defaults';
|
|
24
27
|
import { attachResizeHandle, type ResizeHandle } from '../frames/resize-handle';
|
|
25
28
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
29
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
30
|
+
import { isKitActionBusy, onKitActionBusy } from '../base/action-busy';
|
|
31
|
+
|
|
32
|
+
/** 按语气取质感标记:primary 实心 / neutral 描边有面;danger 是透明底幽灵钮,无面不标 */
|
|
33
|
+
const faceOfTone = (tone: 'primary' | 'danger' | 'neutral'): KitFaceKind | null => (tone === 'danger' ? null : KIT_FACE_RAISED);
|
|
26
34
|
|
|
27
35
|
// ---------------------------------------------------------------- 类(整串字面量)
|
|
28
36
|
|
|
29
37
|
const ROOT_CLASS = 'flex flex-wrap items-center justify-between gap-2 pb-2';
|
|
30
38
|
const GROUP_CLASS = 'flex flex-wrap items-center gap-2';
|
|
31
|
-
const TOOL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
32
|
-
const SEG_GROUP_CLASS = 'inline-flex items-center rounded-md border border-border bg-surface p-0.5';
|
|
39
|
+
const TOOL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
40
|
+
const SEG_GROUP_CLASS = 'inline-flex items-center rounded-md border border-border-subtle bg-surface p-0.5';
|
|
33
41
|
const SEG_BTN_CLASS = 'inline-flex h-7 items-center justify-center rounded-md px-2 text-xs font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
34
42
|
const SEG_BTN_ON_CLASS = 'inline-flex h-7 items-center justify-center rounded-md bg-primary-soft px-2 text-xs font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
35
43
|
const BATCH_BAR_CLASS = 'flex w-full flex-wrap items-center gap-2 rounded-lg bg-primary-soft px-3 py-1.5 text-sm text-primary-on-soft';
|
|
36
44
|
const BATCH_TEXT_CLASS = 'font-medium';
|
|
37
45
|
const LINK_BTN_CLASS = 'inline-flex h-8 items-center rounded-md px-2 text-sm font-medium text-primary-on-soft underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
38
46
|
const CHECK_TEXT_CLASS = 'text-sm text-fg';
|
|
39
|
-
const PANEL_CHECK_CLASS = 'w-full px-2 py-1 text-sm text-fg hover:bg-
|
|
47
|
+
const PANEL_CHECK_CLASS = 'w-full px-2 py-1 text-sm text-fg hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
40
48
|
const PANEL_CHECK_LOCKED_CLASS = 'w-full px-2 py-1 text-sm';
|
|
41
49
|
const ANCHOR_CLASS = 'relative inline-flex';
|
|
42
50
|
const PANEL_BASE = 'absolute z-20 w-56 rounded-lg border border-border-subtle bg-surface-raised p-2 text-sm text-fg shadow-lg';
|
|
43
|
-
const PANEL_ITEM_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-
|
|
51
|
+
const PANEL_ITEM_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
44
52
|
const PANEL_ITEM_LOCKED_CLASS = 'flex cursor-not-allowed items-center gap-2 rounded-md px-2 py-1 text-fg-subtle';
|
|
45
53
|
const PANEL_FOOT_CLASS = 'mt-1 flex justify-end border-t border-border-subtle pt-1';
|
|
46
54
|
const NOTICE_CLASS = 'text-xs text-fg-muted';
|
|
@@ -51,7 +59,25 @@ const EDIT_SELECT_CLASS = 'min-w-0';
|
|
|
51
59
|
const EDIT_DATE_CLASS ='block h-8 w-full min-w-0 rounded-md border border-primary bg-surface ps-2 pe-8 text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
52
60
|
const EDIT_ERR_CLASS = 'block text-xs text-danger-on-soft';
|
|
53
61
|
const HIDDEN_CLASS = 'hidden';
|
|
62
|
+
/** 重新读取中(已有行):表格外壳降不透明度;刷新按钮置灰 */
|
|
63
|
+
const BUSY_TABLE_CLASS = `${KIT_ROW_TONE_CLASS.muted} transition-opacity`;
|
|
64
|
+
const BUSY_BTN_CLASS = kitDisabledRecipe('button');
|
|
54
65
|
const SR_ONLY_CLASS = 'sr-only';
|
|
66
|
+
/** 工具栏 / 批量条 / 列面板里可交互元素的标识属性:整体重建后按「属性 + 值」把焦点还给同一个控件 */
|
|
67
|
+
const FOCUS_ID_ATTRS: readonly string[] = [
|
|
68
|
+
'data-kit-tool', 'data-kit-table-density', 'data-kit-batch', 'data-kit-batch-yes', 'data-kit-batch-no',
|
|
69
|
+
'data-kit-cols-reset', 'data-kit-col-toggle', 'data-kit-sel-clear', 'data-kit-select-all',
|
|
70
|
+
'data-kit-page-select', 'data-kit-page-all',
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* 同标识控件消失时的焦点接力(批量二次确认的进出):键为原控件标识属性,值为接力目标。
|
|
74
|
+
* 进确认条:批量钮 -> 取消钮(最不具破坏性);确认 / 取消后:回到同 id 的批量钮。
|
|
75
|
+
*/
|
|
76
|
+
const FOCUS_RELAY: Readonly<Record<string, { attr: string; sameValue: boolean }>> = {
|
|
77
|
+
'data-kit-batch': { attr: 'data-kit-batch-no', sameValue: false },
|
|
78
|
+
'data-kit-batch-yes': { attr: 'data-kit-batch', sameValue: true },
|
|
79
|
+
'data-kit-batch-no': { attr: 'data-kit-batch', sameValue: true },
|
|
80
|
+
};
|
|
55
81
|
|
|
56
82
|
/** 列宽拖拽(Q 波 G4)运行期换上的类:10 档预置宽 `w-N`(N 取 scroll.minSteps)+ 叶子表头格 / 手柄类;拖到的档位类必须全在候选里,否则按页裁剪后缺类 */
|
|
57
83
|
export const KIT_TABLE_RESIZE_CLASS_CANDIDATES: readonly string[] = [
|
|
@@ -64,7 +90,7 @@ export const KIT_TABLE_TOOLS_CLASS_CANDIDATES: readonly string[] = [
|
|
|
64
90
|
SR_ONLY_CLASS,
|
|
65
91
|
ROOT_CLASS, GROUP_CLASS, TOOL_BTN_CLASS, SEG_GROUP_CLASS, SEG_BTN_CLASS, SEG_BTN_ON_CLASS, BATCH_BAR_CLASS, BATCH_TEXT_CLASS, LINK_BTN_CLASS,
|
|
66
92
|
CHECK_TEXT_CLASS, PANEL_CHECK_CLASS, PANEL_CHECK_LOCKED_CLASS, ...KIT_CHECK_CLASS_CANDIDATES, ANCHOR_CLASS, PANEL_BASE, PANEL_ITEM_CLASS, PANEL_ITEM_LOCKED_CLASS, PANEL_FOOT_CLASS, NOTICE_CLASS, NOTICE_ERR_CLASS,
|
|
67
|
-
EDIT_CELL_CLASS, EDIT_INPUT_CLASS, EDIT_DATE_CLASS, EDIT_SELECT_CLASS, EDIT_ERR_CLASS, HIDDEN_CLASS,
|
|
93
|
+
EDIT_CELL_CLASS, EDIT_INPUT_CLASS, EDIT_DATE_CLASS, EDIT_SELECT_CLASS, EDIT_ERR_CLASS, HIDDEN_CLASS, BUSY_TABLE_CLASS, BUSY_BTN_CLASS,
|
|
68
94
|
...KIT_DATE_CLASS_CANDIDATES, ...KIT_LISTBOX_CLASS_CANDIDATES,
|
|
69
95
|
...Object.values(ACTION_BUTTON_CLASS), ...KIT_TABLE_ACTIONS_CLASS_CANDIDATES, ...KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
70
96
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== ''));
|
|
@@ -141,37 +167,30 @@ export function rowKeyOf(row: unknown, keyField: string): string {
|
|
|
141
167
|
return v !== undefined && v !== null ? String(v) : JSON.stringify(row);
|
|
142
168
|
}
|
|
143
169
|
|
|
144
|
-
|
|
145
|
-
export
|
|
146
|
-
let text: string;
|
|
147
|
-
if (value === null || value === undefined) text = '';
|
|
148
|
-
else if (typeof value === 'number' || typeof value === 'boolean') text = String(value);
|
|
149
|
-
else if (Array.isArray(value)) text = value.map((v) => String(v)).join(';');
|
|
150
|
-
else if (typeof value === 'object') text = JSON.stringify(value);
|
|
151
|
-
else {
|
|
152
|
-
text = String(value);
|
|
153
|
-
if (text !== '' && KIT_TABLE_EXT.export.formulaGuard.includes(text.charAt(0))) text = `'${text}`;
|
|
154
|
-
}
|
|
155
|
-
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
156
|
-
}
|
|
170
|
+
import { csvCell } from '../shared/escape';
|
|
171
|
+
export { csvCell };
|
|
157
172
|
|
|
158
173
|
/** 导出 CSV 文本:表头 + 行;枚举列导出选项文案;超过 maxRows 截断 */
|
|
159
174
|
export function buildCsv(columns: readonly ToolsColumn[], rows: readonly unknown[]): string {
|
|
160
|
-
const
|
|
175
|
+
const formulaGuard = KIT_TABLE_EXT.export.formulaGuard;
|
|
176
|
+
const lines: string[] = [columns.map((c) => csvCell(c.group !== undefined && c.group !== '' ? `${c.group} / ${c.label}` : c.label, formulaGuard)).join(',')];
|
|
161
177
|
for (const row of rows.slice(0, KIT_TABLE_EXT.export.maxRows)) {
|
|
162
178
|
const rec = isRec(row) ? row : {};
|
|
163
179
|
lines.push(columns.map((c) => {
|
|
164
180
|
const raw = rec[c.field];
|
|
165
181
|
const hit = c.options.find((o) => String(o.value) === String(raw));
|
|
166
|
-
return csvCell(hit !== undefined ? hit.label : raw);
|
|
182
|
+
return csvCell(hit !== undefined ? hit.label : raw, formulaGuard);
|
|
167
183
|
}).join(','));
|
|
168
184
|
}
|
|
169
185
|
return `${KIT_TABLE_EXT.export.bom ? '' : ''}${lines.join('\r\n')}\r\n`;
|
|
170
186
|
}
|
|
171
187
|
|
|
172
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* 批量条的两步确认文案:{n} 换成已选个数。占位文法与代入口径只有 core 的 confirm-spec 一份(substituteConfirmText:
|
|
190
|
+
* `{{` / `}}` 转义、非标识符花括号原样保留;批量只许 {n},其余名字编译期已拒,这里万一遇到按 core 口径代入「—」)。
|
|
191
|
+
*/
|
|
173
192
|
export function confirmText(template: string, n: number): string {
|
|
174
|
-
return template
|
|
193
|
+
return substituteConfirmText(template, { count: n });
|
|
175
194
|
}
|
|
176
195
|
|
|
177
196
|
/** 记忆键:kit-table:页面路径:对象名:列设置|密度 */
|
|
@@ -207,12 +226,17 @@ export function parseHidden(raw: string | null, known: readonly string[]): Set<s
|
|
|
207
226
|
}
|
|
208
227
|
}
|
|
209
228
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
229
|
+
// 行高三档就是九维 density 枚举(COMPACT_DENSE / STANDARD_BALANCED / SPACIOUS_AIRY),名字与真源同一份
|
|
230
|
+
type Density = KitTableDensity;
|
|
231
|
+
const DENSITY_LABEL: Readonly<Record<Density, KitTextKey>> = {
|
|
232
|
+
COMPACT_DENSE: 'soma.kit.density_compact_dense',
|
|
233
|
+
STANDARD_BALANCED: 'soma.kit.density_standard_balanced',
|
|
234
|
+
SPACIOUS_AIRY: 'soma.kit.density_spacious_airy',
|
|
235
|
+
};
|
|
236
|
+
const DENSITIES: ReadonlyArray<{ id: Density; label: KitTextKey }> = KIT_TABLE_DENSITIES.map((id) => ({ id, label: DENSITY_LABEL[id] }));
|
|
237
|
+
const isDensity = (v: unknown): v is Density => typeof v === 'string' && (KIT_TABLE_DENSITIES as readonly string[]).includes(v);
|
|
214
238
|
|
|
215
|
-
interface BatchItem { id: string; name: string; tone: 'primary' | 'danger' | 'neutral'; confirm: string; permission: string }
|
|
239
|
+
interface BatchItem { id: string; name: string; tone: 'primary' | 'danger' | 'neutral'; confirm: string; permission: string; busyAction: string }
|
|
216
240
|
|
|
217
241
|
function batchOf(raw: unknown): BatchItem[] {
|
|
218
242
|
if (!Array.isArray(raw)) return [];
|
|
@@ -220,9 +244,14 @@ function batchOf(raw: unknown): BatchItem[] {
|
|
|
220
244
|
id: str(b.id), name: str(b.name, str(b.id)),
|
|
221
245
|
tone: b.tone === 'primary' || b.tone === 'danger' ? b.tone : 'neutral',
|
|
222
246
|
confirm: str(b.confirm), permission: str(b.permission),
|
|
247
|
+
busyAction: str(b.busyAction),
|
|
223
248
|
})).filter((b) => b.id !== '');
|
|
224
249
|
}
|
|
225
250
|
|
|
251
|
+
function batchBusyNames(b: BatchItem): string {
|
|
252
|
+
return b.busyAction !== '' ? `${b.id},${b.busyAction}` : b.id;
|
|
253
|
+
}
|
|
254
|
+
|
|
226
255
|
// ---------------------------------------------------------------- 组件
|
|
227
256
|
|
|
228
257
|
export function createKitTableTools(): SomaComponentDefinition {
|
|
@@ -238,17 +267,29 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
238
267
|
keyField: { type: 'string', default: '', desc: '行主键字段名' },
|
|
239
268
|
columns: { type: 'array', default: [], desc: '列元信息 [{ field, label, fixed?, editable?, kind?, options?, format? }]' },
|
|
240
269
|
items: { type: 'array', default: [], desc: '工具栏项:reload / density / columns / export' },
|
|
241
|
-
density: { type: 'string', default: 'standard', desc: '表格默认行高档(记忆的行高优先)' },
|
|
242
270
|
scroll: { type: 'boolean', default: false, desc: '表格处于滚动模式(影响滚动边缘标记)' },
|
|
243
271
|
editMode: { type: 'string', default: '', desc: '就地编辑方式:cell / row;空 = 不编辑' },
|
|
244
272
|
selectMode: { type: 'string', default: 'none', desc: '勾选列模式 none / single / multi' },
|
|
245
273
|
selectScope: { type: 'string', default: 'all', desc: '勾选范围:all 跨页保留 / page 翻页丢弃不在本页的勾选' },
|
|
246
274
|
selected: { type: 'array', default: [], desc: '已选行数组(协调组件 focus 切片 sel 的镜像);配 batch 才有' },
|
|
247
275
|
batch: { type: 'array', default: [], desc: '批量动作 [{ id, name, tone, confirm, permission? }];confirm 里 {n} 换成已选个数' },
|
|
276
|
+
params: { type: 'object', default: {}, desc: '查询与筛选参数(变化时自动退出跨页全选全部模式)' },
|
|
277
|
+
query: { type: 'object', default: {}, desc: '查询条件参数(变化时自动退出跨页全选全部模式)' },
|
|
278
|
+
filters: { type: 'object', default: {}, desc: '筛选条件参数(变化时自动退出跨页全选全部模式)' },
|
|
279
|
+
readState: { type: 'string', default: '', desc: '列表对象的读状态(page.data.<对象>.readState);loading 且已有行 = 重新读取中:表格外壳 aria-busy + 降不透明度,刷新按钮置灰' },
|
|
248
280
|
class: CLASS_PROP,
|
|
249
281
|
},
|
|
250
282
|
emits: {
|
|
251
283
|
reload: { payload: {}, desc: '点工具栏「刷新」' },
|
|
284
|
+
export: {
|
|
285
|
+
payload: {
|
|
286
|
+
rows: { type: 'array', desc: '导出的当前页或已选行数组' },
|
|
287
|
+
csv: { type: 'string', desc: '导出的 CSV 文本' },
|
|
288
|
+
scope: { type: 'string', desc: '导出范围(固定为 page)' },
|
|
289
|
+
count: { type: 'number', desc: '导出的行数' },
|
|
290
|
+
},
|
|
291
|
+
desc: '点工具栏「导出」按钮(默认导出当前页数据)',
|
|
292
|
+
},
|
|
252
293
|
select_change: {
|
|
253
294
|
payload: {
|
|
254
295
|
rows: { type: 'array', desc: '被改变勾选的行(批量)' },
|
|
@@ -258,17 +299,14 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
258
299
|
},
|
|
259
300
|
desc: '批量条的「全选本页 / 清除」或翻页丢弃:与 row_select 同语义事件(载荷多了 rows)',
|
|
260
301
|
},
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
},
|
|
270
|
-
desc: '点批量动作(有 confirm 时已在批量条里确认过)',
|
|
271
|
-
},
|
|
302
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.batch, {
|
|
303
|
+
kit_action: { type: 'string', desc: '动作判别键' },
|
|
304
|
+
id: { type: 'string', desc: '动作 id' },
|
|
305
|
+
name: { type: 'string', desc: '动作显示名' },
|
|
306
|
+
rows: { type: 'array', desc: '已选行' },
|
|
307
|
+
count: { type: 'number', desc: '作用的行数(all 时为总数)' },
|
|
308
|
+
all: { type: 'boolean', desc: '用户选了「选择全部 N 项」:服务端按当前筛选条件处理' },
|
|
309
|
+
}, '点批量动作(有 confirm 时已在批量条里确认过),序号 = 动作在 batch 数组里的位置'),
|
|
272
310
|
cell_edit: {
|
|
273
311
|
payload: {
|
|
274
312
|
object: { type: 'string', desc: '对象名' },
|
|
@@ -281,15 +319,30 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
281
319
|
desc: '就地编辑保存:页面接 ACTION | data.submit',
|
|
282
320
|
},
|
|
283
321
|
},
|
|
322
|
+
scope: { slices: ['filter', 'view'] },
|
|
284
323
|
},
|
|
285
|
-
services: ['data', 'permission'],
|
|
324
|
+
services: ['data', 'permission', 'region'],
|
|
286
325
|
templateHtml: `<div data-soma-id="root" class="${HIDDEN_CLASS}"></div>`,
|
|
287
|
-
controllerFactory: (
|
|
288
|
-
const check = permissionCheckerOf(
|
|
326
|
+
controllerFactory: createKitController((api) => {
|
|
327
|
+
const check = permissionCheckerOf(api as unknown as any);
|
|
289
328
|
const dataPort = (): SomaDataPort | undefined => {
|
|
290
|
-
const port = (
|
|
329
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
291
330
|
return port && typeof port === 'object' ? port : undefined;
|
|
292
331
|
};
|
|
332
|
+
const regionPort = (): SomaRegionPort | null => {
|
|
333
|
+
const scope = str(P().scope);
|
|
334
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
335
|
+
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
336
|
+
};
|
|
337
|
+
const regionColFilterOf = (): Record<string, unknown> | null => {
|
|
338
|
+
const v = regionPort()?.slice('view')?.get();
|
|
339
|
+
if (!isRec(v)) return null;
|
|
340
|
+
const cf: Record<string, unknown> = {};
|
|
341
|
+
for (const [k, val] of Object.entries(v)) {
|
|
342
|
+
if (k.startsWith(KIT_TABLE_EXT.columnFilter.paramPrefix)) cf[k] = val;
|
|
343
|
+
}
|
|
344
|
+
return Object.keys(cf).length > 0 ? cf : null;
|
|
345
|
+
};
|
|
293
346
|
// ---- 状态
|
|
294
347
|
let hidden = new Set<string>();
|
|
295
348
|
// 列宽拖拽:字段 -> 档位下标(scroll.minSteps);touched = 有过改动、需要在新渲染的格上重放的列。宽度不持久化
|
|
@@ -298,20 +351,30 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
298
351
|
const resizeHandles = new Map<HTMLElement, ResizeHandle>();
|
|
299
352
|
let density: Density | null = null;
|
|
300
353
|
let panelOpen = false;
|
|
354
|
+
/** 当前列面板元素:面板经浮层端口挂在 root 之外,焦点归还要单独认它;面板关闭时为 null */
|
|
355
|
+
let colsPanelEl: HTMLElement | null = null;
|
|
301
356
|
// 列设置面板挂到浮层端口后不再是工具栏的后代,root 上的委托收不到它的事件:面板挂出后由 attach 里登记的函数直接绑在面板上
|
|
302
357
|
let panelBind: ((panel: HTMLElement) => void) | null = null;
|
|
303
358
|
let confirming: string | null = null;
|
|
359
|
+
let confirmingBatch = false;
|
|
304
360
|
let allMode = false;
|
|
361
|
+
let lastQuerySig = '';
|
|
305
362
|
let notice: { text: string; error: boolean } | null = null;
|
|
306
363
|
let table: HTMLElement | null = null;
|
|
307
364
|
let rootEl: HTMLElement | null = null;
|
|
308
365
|
let apiRef: { props: () => Rec } | null = null;
|
|
309
366
|
let rebuild: () => void = () => undefined;
|
|
367
|
+
// 组件正常重绘(新 props)已更新工具栏:取消挂起的那次重建
|
|
368
|
+
let cancelHeldRebuild: () => void = () => undefined;
|
|
369
|
+
// 指针按下窗口内的重绘入口:窗口开着则只记「待重绘(按最新 props)」并返回 true
|
|
370
|
+
let deferRender: () => boolean = () => false;
|
|
371
|
+
// 刷新由键盘触发(click.detail 为 0):读取期间按钮被禁用、焦点掉到 body,读取结束重建时还回去;鼠标触发不归还
|
|
372
|
+
let reloadHadFocus = false;
|
|
310
373
|
// 常驻播报区(sr-only,role=status):批量条每次重绘都会换新节点,节点内的 aria-live 播不出变化,所以播报走这一个不重建的节点
|
|
311
374
|
let liveEl: HTMLElement | null = null;
|
|
312
375
|
let liveLast = '';
|
|
313
376
|
// 内置文案:按宿主所在页面语言取词(运行期读法)
|
|
314
|
-
const T = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params,
|
|
377
|
+
const T = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params, api.host);
|
|
315
378
|
let selAnnounced = false;
|
|
316
379
|
const announce =(text: string): void => {
|
|
317
380
|
if (!liveEl || text === liveLast) return;
|
|
@@ -319,7 +382,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
319
382
|
liveEl.textContent = text;
|
|
320
383
|
};
|
|
321
384
|
|
|
322
|
-
const P =(): Rec => apiRef?.props() ??
|
|
385
|
+
const P =(): Rec => (apiRef?.props() ?? api.props()) as Rec;
|
|
323
386
|
const cols = (): ToolsColumn[] => columnsOf(P().columns);
|
|
324
387
|
const object = (): string => str(P().object);
|
|
325
388
|
const rowsList = (): unknown[] => (Array.isArray(P().rows) ? (P().rows as unknown[]) : []);
|
|
@@ -329,18 +392,16 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
329
392
|
const pathname = (): string => (typeof location === 'undefined' ? '' : location.pathname);
|
|
330
393
|
|
|
331
394
|
const effectiveDensity = (): Density => {
|
|
332
|
-
|
|
333
|
-
const d = str(P().density, 'standard');
|
|
334
|
-
return d === 'compact' || d === 'comfortable' ? d : 'standard';
|
|
395
|
+
return density ?? KIT_TABLE_DENSITY_DEFAULT;
|
|
335
396
|
};
|
|
336
397
|
|
|
337
398
|
// ---- 对表格外壳的作用
|
|
338
399
|
const applyDensity = (): void => {
|
|
339
400
|
if (!table) return;
|
|
340
401
|
const d = effectiveDensity();
|
|
341
|
-
if (d === '
|
|
402
|
+
if (d === 'COMPACT_DENSE') table.setAttribute('data-kit-dense', '');
|
|
342
403
|
else table.removeAttribute('data-kit-dense');
|
|
343
|
-
if (d === '
|
|
404
|
+
if (d === 'SPACIOUS_AIRY') table.setAttribute('data-kit-roomy', '');
|
|
344
405
|
else table.removeAttribute('data-kit-roomy');
|
|
345
406
|
};
|
|
346
407
|
|
|
@@ -460,10 +521,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
460
521
|
|
|
461
522
|
const applyCells = (): void => {
|
|
462
523
|
if (!table) return;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (text !== '' && el.getAttribute('title') !== text) el.setAttribute('title', text);
|
|
466
|
-
});
|
|
524
|
+
// 省略列的全文提示不在这里逐格写原生 title:改由 base/hint-tips.ts 的委托在悬停 / 聚焦到单元格时现量、真被截断才挂 kitTooltip
|
|
525
|
+
//(表格外壳带 data-kit-tips 标出作用范围;大表 / 虚拟表不为每个单元格建任何东西)
|
|
467
526
|
if (str(P().editMode) !== '') {
|
|
468
527
|
table.querySelectorAll<HTMLElement>('[data-kit-editable]').forEach((el) => {
|
|
469
528
|
if (el.hasAttribute('data-kit-edit-ready')) return;
|
|
@@ -490,7 +549,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
490
549
|
// ---- 勾选 / 批量
|
|
491
550
|
const selectRows = (rows: unknown[], checked: boolean): void => {
|
|
492
551
|
if (rows.length === 0) return;
|
|
493
|
-
|
|
552
|
+
api.emit('select_change', { rows, checked, mode: 'multi', keyField: keyField() });
|
|
494
553
|
};
|
|
495
554
|
/** 本页勾选状态:全未选 false / 部分选 'mixed' / 全选 true */
|
|
496
555
|
const pageState = (): boolean | 'mixed' => {
|
|
@@ -507,6 +566,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
507
566
|
const picked = selectedList();
|
|
508
567
|
const rows = picked.length > 0 ? picked : rowsList();
|
|
509
568
|
const text = buildCsv(visible, rows);
|
|
569
|
+
api.emit('export', { rows, csv: text, scope: 'page', count: rows.length });
|
|
510
570
|
const doc = rootEl?.ownerDocument;
|
|
511
571
|
if (!doc || typeof URL === 'undefined' || typeof URL.createObjectURL !== 'function') return;
|
|
512
572
|
const blob = new Blob([text], { type: 'text/csv;charset=utf-8' });
|
|
@@ -581,6 +641,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
581
641
|
input.setAttribute('type', 'text');
|
|
582
642
|
input.value = value === null || value === undefined ? '' : String(value);
|
|
583
643
|
input.className = EDIT_INPUT_CLASS;
|
|
644
|
+
setKitFace(input, KIT_FACE_FIELD);
|
|
584
645
|
// 数字列:自绘数字框(过滤非数字、↑↓ 调值),不用原生 type=number;随输入框一起卸载
|
|
585
646
|
if (col.kind === 'number') attachSpin(input, () => ({ step: 1 }));
|
|
586
647
|
return { control: input, valueEl: input, shell: input, handle: null };
|
|
@@ -591,7 +652,9 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
591
652
|
if (mode === '' || cell.getAttribute('data-kit-editable') === null) return;
|
|
592
653
|
const hit = rowOfCell(cell);
|
|
593
654
|
if (!hit) return;
|
|
594
|
-
|
|
655
|
+
// 点到同表另一格:旧编辑与「点到别处」同一套(有改动提交、无改动取消);校验没过则留在旧编辑
|
|
656
|
+
settleEdit();
|
|
657
|
+
if (editing) return;
|
|
595
658
|
const doc = cell.ownerDocument;
|
|
596
659
|
const targets = mode === 'row'
|
|
597
660
|
? Array.from(cell.parentElement?.querySelectorAll<HTMLElement>('[data-kit-editable]') ?? [cell])
|
|
@@ -631,9 +694,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
631
694
|
return raw;
|
|
632
695
|
};
|
|
633
696
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const e = editing;
|
|
697
|
+
/** 当前输入值相对编辑开始时的行值有哪些改动(Enter 提交与外部点击共用) */
|
|
698
|
+
const changesOf = (e: NonNullable<typeof editing>): Rec => {
|
|
637
699
|
const changes: Rec = {};
|
|
638
700
|
for (const c of e.cells) {
|
|
639
701
|
const next = valueOf(c);
|
|
@@ -641,8 +703,26 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
641
703
|
const same = (next === null || next === '') && (prev === null || prev === undefined || prev === '') ? true : String(next) === String(prev);
|
|
642
704
|
if (!same) changes[c.col.field] = next;
|
|
643
705
|
}
|
|
706
|
+
return changes;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
/** 点到别处 / 点另一个可编辑单元格:有未提交改动走与 Enter 相同的提交路径(不抢焦点),值没变才取消。
|
|
710
|
+
* 校验没过:留在编辑态并显示错误(不静默丢输入)。表体被后台重建时不走这里(见 MutationObserver:只取消,不提交半截输入) */
|
|
711
|
+
const settleEdit = (): void => {
|
|
712
|
+
if (!editing) return;
|
|
713
|
+
if (Object.keys(changesOf(editing)).length > 0) {
|
|
714
|
+
commitEdit(false);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
cancelEdit(false);
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
const commitEdit = (refocus = true): void => {
|
|
721
|
+
if (!editing) return;
|
|
722
|
+
const e = editing;
|
|
723
|
+
const changes = changesOf(e);
|
|
644
724
|
if (Object.keys(changes).length === 0) {
|
|
645
|
-
cancelEdit(
|
|
725
|
+
cancelEdit(refocus);
|
|
646
726
|
return;
|
|
647
727
|
}
|
|
648
728
|
// 前端即时校验:沿用对象字典的 rules,只看被改的字段
|
|
@@ -671,33 +751,42 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
671
751
|
const key = keyField();
|
|
672
752
|
if (key === '' || e.row[key] === undefined) {
|
|
673
753
|
notice = { text: T('soma.kit.save_no_key'), error: true };
|
|
674
|
-
cancelEdit(
|
|
754
|
+
cancelEdit(refocus);
|
|
675
755
|
rebuild();
|
|
676
756
|
return;
|
|
677
757
|
}
|
|
678
758
|
const model: Rec = { [key]: e.row[key], ...changes };
|
|
679
|
-
cancelEdit(
|
|
759
|
+
cancelEdit(refocus);
|
|
680
760
|
notice = { text: T('soma.kit.saving'), error: false };
|
|
681
761
|
rebuild();
|
|
682
|
-
|
|
762
|
+
api.emit('cell_edit', { object: object(), scope: cellScope(), model, mode: 'update', field: Object.keys(changes).join(','), row: e.row });
|
|
683
763
|
};
|
|
684
764
|
|
|
685
765
|
// ---- 工具栏 / 批量条 渲染
|
|
686
|
-
|
|
766
|
+
/** 工具栏 / 批量条按钮;face 由调用方按创建处的样式决定(有实心 / 描边 / 浅底才标 raised,幽灵 / 链接钮传 null),不在运行时解析类串 */
|
|
767
|
+
const btn = (doc: Document, cls: string, text: string, attrs: Record<string, string> = {}, face: KitFaceKind | null = null): HTMLButtonElement => {
|
|
687
768
|
const b = doc.createElement('button');
|
|
688
769
|
b.setAttribute('type', 'button');
|
|
689
770
|
b.className = cls;
|
|
771
|
+
setKitFace(b, face);
|
|
690
772
|
b.textContent = text;
|
|
691
773
|
for (const [k, v] of Object.entries(attrs)) b.setAttribute(k, v);
|
|
692
774
|
return b;
|
|
693
775
|
};
|
|
694
776
|
|
|
695
|
-
|
|
777
|
+
/** 重新读取中:读状态 loading 且当前已有行(首次加载无行,走三态骨架,不叠加) */
|
|
778
|
+
const reading = (p: Rec): boolean => str(p.readState) === 'loading' && Array.isArray(p.rows) && p.rows.length > 0;
|
|
779
|
+
|
|
780
|
+
const renderToolbar = (doc: Document, items: string[], busy: boolean): HTMLElement => {
|
|
696
781
|
const group = doc.createElement('div');
|
|
697
782
|
group.className = GROUP_CLASS;
|
|
698
783
|
for (const it of items) {
|
|
699
784
|
if (it === 'reload') {
|
|
700
|
-
group.appendChild(btn(
|
|
785
|
+
group.appendChild(btn(
|
|
786
|
+
doc, busy ? `${TOOL_BTN_CLASS} ${BUSY_BTN_CLASS}` : TOOL_BTN_CLASS, T('soma.kit.refresh'),
|
|
787
|
+
busy ? { 'data-kit-tool': 'reload', disabled: '', 'aria-busy': 'true' } : { 'data-kit-tool': 'reload' },
|
|
788
|
+
KIT_FACE_RAISED,
|
|
789
|
+
));
|
|
701
790
|
} else if (it === 'density') {
|
|
702
791
|
const seg = doc.createElement('div');
|
|
703
792
|
seg.className = SEG_GROUP_CLASS;
|
|
@@ -705,18 +794,18 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
705
794
|
seg.setAttribute('aria-label', T('soma.kit.row_height'));
|
|
706
795
|
for (const d of DENSITIES) {
|
|
707
796
|
const on = effectiveDensity() === d.id;
|
|
708
|
-
const b = btn(doc, on ? SEG_BTN_ON_CLASS : SEG_BTN_CLASS, T(d.label), { 'data-kit-density': d.id, 'aria-pressed': on ? 'true' : 'false' });
|
|
797
|
+
const b = btn(doc, on ? SEG_BTN_ON_CLASS : SEG_BTN_CLASS, T(d.label), { 'data-kit-table-density': d.id, 'aria-pressed': on ? 'true' : 'false' }, on ? KIT_FACE_RAISED : null);
|
|
709
798
|
seg.appendChild(b);
|
|
710
799
|
}
|
|
711
800
|
group.appendChild(seg);
|
|
712
801
|
} else if (it === 'columns') {
|
|
713
802
|
const anchor = doc.createElement('div');
|
|
714
803
|
anchor.className = ANCHOR_CLASS;
|
|
715
|
-
anchor.appendChild(btn(doc, TOOL_BTN_CLASS, T('soma.kit.columns'), { 'data-kit-tool': 'columns', 'aria-haspopup': 'dialog', 'aria-expanded': panelOpen ? 'true' : 'false' }));
|
|
804
|
+
anchor.appendChild(btn(doc, TOOL_BTN_CLASS, T('soma.kit.columns'), { 'data-kit-tool': 'columns', 'aria-haspopup': 'dialog', 'aria-expanded': panelOpen ? 'true' : 'false' }, KIT_FACE_RAISED));
|
|
716
805
|
if (panelOpen) anchor.appendChild(columnPanel(doc));
|
|
717
806
|
group.appendChild(anchor);
|
|
718
807
|
} else if (it === 'export') {
|
|
719
|
-
group.appendChild(btn(doc, TOOL_BTN_CLASS, T('soma.kit.export'), { 'data-kit-tool': 'export' }));
|
|
808
|
+
group.appendChild(btn(doc, TOOL_BTN_CLASS, T('soma.kit.export'), { 'data-kit-tool': 'export', title: T('soma.kit.export_page_hint') }, KIT_FACE_RAISED));
|
|
720
809
|
}
|
|
721
810
|
}
|
|
722
811
|
return group;
|
|
@@ -728,6 +817,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
728
817
|
panel.setAttribute('aria-label', T('soma.kit.columns'));
|
|
729
818
|
panel.setAttribute('data-kit-cols-panel', '');
|
|
730
819
|
panel.className = PANEL_BASE;
|
|
820
|
+
colsPanelEl = panel;
|
|
731
821
|
for (const c of cols()) {
|
|
732
822
|
const locked = c.fixed !== '';
|
|
733
823
|
const box = createCheck(doc, 'checkbox', {
|
|
@@ -781,25 +871,69 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
781
871
|
q.setAttribute('role', 'alert');
|
|
782
872
|
q.textContent = confirmText(item.confirm, count);
|
|
783
873
|
bar.appendChild(q);
|
|
784
|
-
|
|
785
|
-
|
|
874
|
+
const busy = isKitActionBusy(batchBusyNames(item));
|
|
875
|
+
const yesAttrs: Record<string, string> = { 'data-kit-batch-yes': item.id };
|
|
876
|
+
if (busy) {
|
|
877
|
+
yesAttrs.disabled = '';
|
|
878
|
+
yesAttrs['aria-busy'] = 'true';
|
|
879
|
+
}
|
|
880
|
+
const yesButton = btn(doc, ACTION_BUTTON_CLASS[item.tone], T('soma.kit.confirm'), yesAttrs, faceOfTone(item.tone));
|
|
881
|
+
if (busy) yesButton.disabled = true;
|
|
882
|
+
bar.appendChild(yesButton);
|
|
883
|
+
bar.appendChild(btn(doc, ACTION_BUTTON_CLASS.neutral, T('soma.kit.cancel'), { 'data-kit-batch-no': item.id }, KIT_FACE_RAISED));
|
|
786
884
|
return bar;
|
|
787
885
|
}
|
|
788
886
|
}
|
|
789
887
|
for (const b of batch) {
|
|
790
888
|
if (b.permission !== '' && check !== null && !check(b.permission)) continue;
|
|
791
|
-
|
|
889
|
+
const busy = isKitActionBusy(batchBusyNames(b));
|
|
890
|
+
const attrs: Record<string, string> = { 'data-kit-batch': b.id };
|
|
891
|
+
if (busy) {
|
|
892
|
+
attrs.disabled = '';
|
|
893
|
+
attrs['aria-busy'] = 'true';
|
|
894
|
+
}
|
|
895
|
+
const button = btn(doc, ACTION_BUTTON_CLASS[b.tone], b.name, attrs, faceOfTone(b.tone));
|
|
896
|
+
if (busy) button.disabled = true;
|
|
897
|
+
bar.appendChild(button);
|
|
792
898
|
}
|
|
793
899
|
return bar;
|
|
794
900
|
};
|
|
795
901
|
|
|
796
902
|
const render = (root: HTMLElement, p: Rec): void => {
|
|
797
903
|
const doc = root.ownerDocument;
|
|
904
|
+
const nextQuerySig = tableQuerySignature(p, regionPort()?.slice('filter')?.get() ?? null, regionColFilterOf());
|
|
905
|
+
if (lastQuerySig !== '' && lastQuerySig !== nextQuerySig) {
|
|
906
|
+
allMode = false;
|
|
907
|
+
confirming = null;
|
|
908
|
+
}
|
|
909
|
+
lastQuerySig = nextQuerySig;
|
|
798
910
|
const items = (Array.isArray(p.items) ? p.items : []).filter((x): x is string => typeof x === 'string');
|
|
911
|
+
const busyNow = reading(p);
|
|
912
|
+
if (table) {
|
|
913
|
+
if (busyNow) table.setAttribute('aria-busy', 'true'); else table.removeAttribute('aria-busy');
|
|
914
|
+
for (const c of BUSY_TABLE_CLASS.split(' ')) table.classList.toggle(c, busyNow);
|
|
915
|
+
}
|
|
799
916
|
const batch = batchOf(p.batch);
|
|
800
917
|
const picked = selectedList();
|
|
801
918
|
const batching = batch.length > 0 && picked.length > 0;
|
|
802
919
|
const selectAll = batch.length > 0 && str(p.selectMode) === 'multi';
|
|
920
|
+
const activeBefore = doc.activeElement;
|
|
921
|
+
const onReload = activeBefore instanceof HTMLElement && root.contains(activeBefore) && activeBefore.matches('[data-kit-tool="reload"]');
|
|
922
|
+
const idleBefore = activeBefore === null || activeBefore === doc.body;
|
|
923
|
+
// 归还标记由键盘触发的刷新点击置位(见 click 处理);焦点在别处时清掉
|
|
924
|
+
if (!onReload && !idleBefore) reloadHadFocus = false;
|
|
925
|
+
// 通用焦点归还:重建前记下焦点所在控件的标识(属性 + 值),重建后焦点落到 body 时还回同一个控件
|
|
926
|
+
let focusMark: { attr: string; value: string } | null = null;
|
|
927
|
+
// 焦点在 root 内,或在列面板内(面板在浮层端口时不在 root 里)都要记
|
|
928
|
+
const panelBefore = colsPanelEl;
|
|
929
|
+
if (activeBefore instanceof HTMLElement && (root.contains(activeBefore) || (panelBefore !== null && panelBefore.contains(activeBefore)))) {
|
|
930
|
+
for (let el: HTMLElement | null = activeBefore; el !== null && el !== root && el !== panelBefore?.parentElement; el = el.parentElement) {
|
|
931
|
+
const found = FOCUS_ID_ATTRS.find((a) => el!.hasAttribute(a));
|
|
932
|
+
if (found !== undefined) { focusMark = { attr: found, value: el.getAttribute(found) ?? '' }; break; }
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
// 重建会销毁旧面板;开着时由 columnPanel 重新登记,关着就保持空
|
|
936
|
+
colsPanelEl = null;
|
|
803
937
|
releaseDropdownsIn(root);
|
|
804
938
|
root.replaceChildren();
|
|
805
939
|
if (!liveEl || liveEl.parentElement === null) {
|
|
@@ -823,7 +957,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
823
957
|
box.appendChild(text);
|
|
824
958
|
parts.push(box);
|
|
825
959
|
}
|
|
826
|
-
if (items.length > 0) parts.push(renderToolbar(doc, items));
|
|
960
|
+
if (items.length > 0) parts.push(renderToolbar(doc, items, busyNow));
|
|
827
961
|
}
|
|
828
962
|
if (notice !== null) {
|
|
829
963
|
const n = doc.createElement('span');
|
|
@@ -835,40 +969,195 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
835
969
|
// 批量条与全选在同一行:全选本页放在批量条之外时与工具栏分居两端
|
|
836
970
|
for (const part of parts) root.appendChild(part);
|
|
837
971
|
root.className = parts.length === 0 ? `${HIDDEN_CLASS}` : `${ROOT_CLASS} ${typeof p.class === 'string' ? p.class : ''}`.trim();
|
|
972
|
+
if (focusMark !== null) {
|
|
973
|
+
const now = doc.activeElement;
|
|
974
|
+
if (now === null || now === doc.body) {
|
|
975
|
+
const mark = focusMark;
|
|
976
|
+
// 在 root 与新列面板两处按同属性 + 值找(面板在浮层端口时不在 root 里)
|
|
977
|
+
const findIn = (scope: ParentNode | null, attr: string, accept: (v: string) => boolean): HTMLElement | undefined => (
|
|
978
|
+
scope === null ? undefined : Array.from(scope.querySelectorAll<HTMLElement>(`[${attr}]`)).find((e) => accept(e.getAttribute(attr) ?? ''))
|
|
979
|
+
);
|
|
980
|
+
const same = findIn(root, mark.attr, (v) => v === mark.value) ?? findIn(colsPanelEl, mark.attr, (v) => v === mark.value);
|
|
981
|
+
// 同标识的控件在就还给它(被禁用也不再找别的);不在时先按接力表找(批量二次确认的进出),再退到第一个可用控件
|
|
982
|
+
const relay = FOCUS_RELAY[mark.attr];
|
|
983
|
+
const relayed = same === undefined && relay !== undefined ? findIn(root, relay.attr, (v) => !relay.sameValue || v === mark.value) : undefined;
|
|
984
|
+
const target = same ?? relayed ?? root.querySelector<HTMLElement>('button:not([disabled]), [role="button"]:not([disabled]), input:not([disabled])');
|
|
985
|
+
// 勾选标记(「全选本页」、列显隐)是 label 包原生 input:label 自身不可聚焦,落到里面的 input
|
|
986
|
+
const focusEl = target !== undefined && target !== null && isMark(target) ? (markInput(target) ?? target) : target;
|
|
987
|
+
const panelNow = colsPanelEl as HTMLElement | null;
|
|
988
|
+
if (focusEl && panelNow !== null && panelNow.contains(focusEl)) {
|
|
989
|
+
// 新列面板在 columnPanel 排的微任务里才挂到浮层端口(挪节点会丢焦点):排在它之后再聚焦
|
|
990
|
+
queueMicrotask(() => {
|
|
991
|
+
const cur = doc.activeElement;
|
|
992
|
+
if (focusEl.isConnected && (cur === null || cur === doc.body)) focusEl.focus({ preventScroll: true });
|
|
993
|
+
});
|
|
994
|
+
} else {
|
|
995
|
+
focusEl?.focus({ preventScroll: true });
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
if (reloadHadFocus && !busyNow) {
|
|
1000
|
+
reloadHadFocus = false;
|
|
1001
|
+
const now = doc.activeElement;
|
|
1002
|
+
const again = root.querySelector<HTMLElement>('[data-kit-tool="reload"]');
|
|
1003
|
+
if (again && (now === null || now === doc.body)) again.focus({ preventScroll: true });
|
|
1004
|
+
}
|
|
838
1005
|
};
|
|
839
1006
|
|
|
840
|
-
return
|
|
841
|
-
attach(root
|
|
1007
|
+
return {
|
|
1008
|
+
attach(root) {
|
|
842
1009
|
rootEl = root;
|
|
843
1010
|
apiRef = api;
|
|
844
1011
|
const names = (): string[] => cols().map((c) => c.field);
|
|
1012
|
+
// 精确定位所属表格外壳:emitStatic 给工具条宿主(data-soma-id = 工具锚点)与表格外壳(data-kit-table-of)成对写同一个值;
|
|
1013
|
+
// 没有成对属性(手写页 / 旧产物)才认紧邻的、且没有标属于别人的表格外壳,再退到同父节点里「唯一一个」未标属主的表格;
|
|
1014
|
+
// 有多个候选时不猜(返回 null),不再取第一个
|
|
845
1015
|
table = (() => {
|
|
1016
|
+
const key = api.host.getAttribute('data-soma-id') ?? '';
|
|
1017
|
+
if (key !== '') {
|
|
1018
|
+
const paired = Array.from(api.host.parentElement?.querySelectorAll<HTMLElement>('[data-kit-table-of]') ?? []).find((e) => e.getAttribute('data-kit-table-of') === key);
|
|
1019
|
+
if (paired) return paired;
|
|
1020
|
+
}
|
|
846
1021
|
const next = api.host.nextElementSibling;
|
|
847
|
-
if (next instanceof HTMLElement && next.hasAttribute('data-kit-table')) return next;
|
|
848
|
-
|
|
1022
|
+
if (next instanceof HTMLElement && next.hasAttribute('data-kit-table') && !next.hasAttribute('data-kit-table-of')) return next;
|
|
1023
|
+
const free = Array.from(api.host.parentElement?.querySelectorAll<HTMLElement>('[data-kit-table]:not([data-kit-table-of])') ?? []);
|
|
1024
|
+
return free.length === 1 ? free[0]! : null;
|
|
849
1025
|
})();
|
|
850
1026
|
hidden = parseHidden(readStore(rememberKey(pathname(), object(), 'cols')), names());
|
|
851
1027
|
const savedDensity = readStore(rememberKey(pathname(), object(), 'density'));
|
|
852
|
-
density = savedDensity
|
|
853
|
-
|
|
1028
|
+
density = isDensity(savedDensity) ? savedDensity : null;
|
|
1029
|
+
// 工具栏是整体重建的:指针按下之后、click 派发之前换掉按钮节点,这次点击就丢了。
|
|
1030
|
+
// 两种来源共用一套挂起:① 外部点击检测(document 捕获阶段 pointerdown)同步提交编辑引起的重建(holdRebuild);
|
|
1031
|
+
// ② 指针按在本工具栏的按钮上之后(root 冒泡阶段 pointerdown 进入按下窗口)任何原因的重建 / 控制器重绘。
|
|
1032
|
+
// 结束时机:document click(冒泡,晚于 root 自己的 click 处理)/ pointercancel / pointerup 后一个任务 / window blur;结束时有待办则执行一次
|
|
1033
|
+
let holdRebuild = false;
|
|
1034
|
+
let pressing = false;
|
|
1035
|
+
let rebuildHeld = false;
|
|
1036
|
+
let renderHeld = false;
|
|
1037
|
+
let offHeld: (() => void) | null = null;
|
|
1038
|
+
const disarmHeld = (): void => { offHeld?.(); offHeld = null; };
|
|
1039
|
+
const endWindow = (): void => {
|
|
1040
|
+
pressing = false;
|
|
1041
|
+
disarmHeld();
|
|
1042
|
+
if (!rebuildHeld) return;
|
|
1043
|
+
const withRender = renderHeld;
|
|
1044
|
+
rebuildHeld = false;
|
|
1045
|
+
renderHeld = false;
|
|
1046
|
+
rebuild();
|
|
1047
|
+
if (withRender) applyAll();
|
|
1048
|
+
};
|
|
1049
|
+
const armHeldRebuild = (): void => {
|
|
1050
|
+
if (offHeld !== null) return;
|
|
1051
|
+
const doc = rootEl?.ownerDocument ?? document;
|
|
1052
|
+
const win = doc.defaultView;
|
|
1053
|
+
// pointerup 之后的兜底:触屏的 click 在手势结束后单独派发、可能晚于零延时定时器,所以等两帧再结束窗口;没有 rAF 的环境退回零延时定时器
|
|
1054
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
1055
|
+
let frame1: number | null = null;
|
|
1056
|
+
let frame2: number | null = null;
|
|
1057
|
+
const hasRaf = typeof win?.requestAnimationFrame === 'function';
|
|
1058
|
+
const onUp = (): void => {
|
|
1059
|
+
if (timer !== null || frame1 !== null || frame2 !== null) return;
|
|
1060
|
+
if (win && hasRaf) {
|
|
1061
|
+
frame1 = win.requestAnimationFrame(() => {
|
|
1062
|
+
frame1 = null;
|
|
1063
|
+
frame2 = win.requestAnimationFrame(() => { frame2 = null; endWindow(); });
|
|
1064
|
+
});
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
timer = setTimeout(() => { timer = null; endWindow(); }, 0);
|
|
1068
|
+
};
|
|
1069
|
+
doc.addEventListener('click', endWindow);
|
|
1070
|
+
doc.addEventListener('pointercancel', endWindow);
|
|
1071
|
+
doc.addEventListener('pointerup', onUp);
|
|
1072
|
+
win?.addEventListener('blur', endWindow);
|
|
1073
|
+
offHeld = () => {
|
|
1074
|
+
doc.removeEventListener('click', endWindow);
|
|
1075
|
+
doc.removeEventListener('pointercancel', endWindow);
|
|
1076
|
+
doc.removeEventListener('pointerup', onUp);
|
|
1077
|
+
win?.removeEventListener('blur', endWindow);
|
|
1078
|
+
if (timer !== null) clearTimeout(timer);
|
|
1079
|
+
timer = null;
|
|
1080
|
+
if (frame1 !== null) win?.cancelAnimationFrame(frame1);
|
|
1081
|
+
if (frame2 !== null) win?.cancelAnimationFrame(frame2);
|
|
1082
|
+
frame1 = null;
|
|
1083
|
+
frame2 = null;
|
|
1084
|
+
};
|
|
1085
|
+
};
|
|
1086
|
+
deferRender = () => {
|
|
1087
|
+
if (!pressing) return false;
|
|
1088
|
+
rebuildHeld = true;
|
|
1089
|
+
renderHeld = true;
|
|
1090
|
+
return true;
|
|
1091
|
+
};
|
|
1092
|
+
rebuild = () => {
|
|
1093
|
+
if (holdRebuild || pressing) {
|
|
1094
|
+
rebuildHeld = true;
|
|
1095
|
+
armHeldRebuild();
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (rootEl) {
|
|
1099
|
+
const prevScrollTop = table?.scrollTop;
|
|
1100
|
+
const prevScrollLeft = table?.scrollLeft;
|
|
1101
|
+
render(rootEl, api.props());
|
|
1102
|
+
if (table) {
|
|
1103
|
+
if (prevScrollTop !== undefined && table.scrollTop !== prevScrollTop) {
|
|
1104
|
+
table.scrollTop = prevScrollTop;
|
|
1105
|
+
}
|
|
1106
|
+
if (prevScrollLeft !== undefined && table.scrollLeft !== prevScrollLeft) {
|
|
1107
|
+
table.scrollLeft = prevScrollLeft;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
854
1112
|
|
|
855
1113
|
const offs: Array<() => void> = [];
|
|
1114
|
+
cancelHeldRebuild = () => { rebuildHeld = false; renderHeld = false; pressing = false; disarmHeld(); };
|
|
1115
|
+
offs.push(() => cancelHeldRebuild());
|
|
1116
|
+
offs.push(onKitActionBusy(() => rebuild()));
|
|
1117
|
+
for (const sliceName of ['filter', 'view'] as const) {
|
|
1118
|
+
const slice = regionPort()?.slice(sliceName);
|
|
1119
|
+
if (slice?.subscribe) {
|
|
1120
|
+
offs.push(slice.subscribe(() => { if (allMode) rebuild(); }));
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
856
1123
|
const on = (el: EventTarget | null | undefined, type: string, fn: (e: never) => void): void => {
|
|
857
1124
|
if (!el) return;
|
|
858
1125
|
el.addEventListener(type, fn as EventListener);
|
|
859
1126
|
offs.push(() => el.removeEventListener(type, fn as EventListener));
|
|
860
1127
|
};
|
|
861
1128
|
|
|
1129
|
+
// 指针按在工具栏按钮上:进入按下窗口(冒泡阶段,晚于 document 捕获阶段的外部点击检测,同步挂起的那次重建已在等待)。键盘触发没有 pointerdown,不进窗口
|
|
1130
|
+
on(root, 'pointerdown', (event: Event) => {
|
|
1131
|
+
// 只认主键:右键 / 中键按下时部分平台弹出上下文菜单,之后不一定派发 pointerup / click,按下窗口会一直挂着、重绘全被推迟
|
|
1132
|
+
const button = (event as { button?: unknown }).button;
|
|
1133
|
+
if (typeof button === 'number' && button !== 0) return;
|
|
1134
|
+
const t = event.target;
|
|
1135
|
+
if (!(t instanceof Element) || !root.contains(t) || t.closest('button, [role="button"], [data-kit-tool]') === null) return;
|
|
1136
|
+
pressing = true;
|
|
1137
|
+
armHeldRebuild();
|
|
1138
|
+
});
|
|
862
1139
|
// 工具栏 / 批量条 的点击与勾选
|
|
863
1140
|
on(root, 'click', (event: Event) => {
|
|
864
1141
|
const t = event.target as HTMLElement | null;
|
|
865
1142
|
if (!t) return;
|
|
1143
|
+
// 键盘在按钮上按 Enter / 空格没有 pointerdown,外部按下检测没机会结算:先结算进行中的行内编辑(鼠标路径已结算过,这里是空操作)。
|
|
1144
|
+
// 校验没过则留在编辑态,本次工具动作不执行
|
|
1145
|
+
const stillEditing = (): boolean => editing !== null;
|
|
1146
|
+
if (stillEditing()) {
|
|
1147
|
+
settleEdit();
|
|
1148
|
+
if (stillEditing()) return;
|
|
1149
|
+
}
|
|
866
1150
|
const tool = t.closest<HTMLElement>('[data-kit-tool]')?.getAttribute('data-kit-tool');
|
|
867
|
-
if (tool === 'reload') {
|
|
1151
|
+
if (tool === 'reload') {
|
|
1152
|
+
// 焦点归还只给键盘用户:键盘触发的 click 其 detail 为 0,鼠标 ≥ 1
|
|
1153
|
+
if ((event as MouseEvent).detail === 0) reloadHadFocus = true;
|
|
1154
|
+
api.emit('reload', {});
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
868
1157
|
if (tool === 'export') { exportCsv(); return; }
|
|
869
1158
|
if (tool === 'columns') { panelOpen = !panelOpen; rebuild(); return; }
|
|
870
|
-
const dens = t.closest<HTMLElement>('[data-kit-density]')?.getAttribute('data-kit-density');
|
|
871
|
-
if (dens
|
|
1159
|
+
const dens = t.closest<HTMLElement>('[data-kit-table-density]')?.getAttribute('data-kit-table-density');
|
|
1160
|
+
if (isDensity(dens)) {
|
|
872
1161
|
density = dens;
|
|
873
1162
|
writeStore(rememberKey(pathname(), object(), 'density'), dens);
|
|
874
1163
|
applyDensity();
|
|
@@ -896,24 +1185,49 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
896
1185
|
const item = batchOf(api.props().batch).find((b) => b.id === batchId);
|
|
897
1186
|
if (!item) return;
|
|
898
1187
|
if (item.confirm !== '') { confirming = item.id; rebuild(); return; }
|
|
899
|
-
|
|
1188
|
+
if (confirmingBatch || isKitActionBusy(batchBusyNames(item))) return;
|
|
1189
|
+
const batchBtn = t.closest<HTMLButtonElement>('[data-kit-batch]');
|
|
1190
|
+
if (batchBtn) batchBtn.disabled = true;
|
|
1191
|
+
confirmingBatch = true;
|
|
1192
|
+
try {
|
|
1193
|
+
fireBatch(item);
|
|
1194
|
+
} finally {
|
|
1195
|
+
queueMicrotask(() => {
|
|
1196
|
+
confirmingBatch = false;
|
|
1197
|
+
if (batchBtn && !isKitActionBusy(batchBusyNames(item))) batchBtn.disabled = false;
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
900
1200
|
return;
|
|
901
1201
|
}
|
|
902
1202
|
const yes = t.closest<HTMLElement>('[data-kit-batch-yes]')?.getAttribute('data-kit-batch-yes');
|
|
903
1203
|
if (yes) {
|
|
904
1204
|
const item = batchOf(api.props().batch).find((b) => b.id === yes);
|
|
905
|
-
|
|
906
|
-
if (
|
|
1205
|
+
if (!item) return;
|
|
1206
|
+
if (confirmingBatch || isKitActionBusy(batchBusyNames(item))) return;
|
|
1207
|
+
const yesBtn = t.closest<HTMLButtonElement>('[data-kit-batch-yes]');
|
|
1208
|
+
if (yesBtn) yesBtn.disabled = true;
|
|
1209
|
+
confirmingBatch = true;
|
|
1210
|
+
try {
|
|
1211
|
+
confirming = null;
|
|
1212
|
+
fireBatch(item);
|
|
1213
|
+
rebuild();
|
|
1214
|
+
} finally {
|
|
1215
|
+
queueMicrotask(() => {
|
|
1216
|
+
confirmingBatch = false;
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
907
1219
|
return;
|
|
908
1220
|
}
|
|
909
1221
|
if (t.closest('[data-kit-batch-no]')) { confirming = null; rebuild(); }
|
|
910
1222
|
});
|
|
911
1223
|
const fireBatch = (item: BatchItem): void => {
|
|
1224
|
+
const curProps = api.props();
|
|
912
1225
|
const picked = selectedList();
|
|
913
|
-
const total = num(
|
|
1226
|
+
const total = num(curProps.total) ?? 0;
|
|
914
1227
|
const all = allMode;
|
|
915
|
-
|
|
1228
|
+
emitActionSlot((n, p) => api.emit(n, p), KIT_ACTION_SLOT_BASE.batch, batchOf(curProps.batch).findIndex((b) => b.id === item.id), {
|
|
916
1229
|
kit_action: item.id, id: item.id, name: item.name, rows: picked, count: all ? Math.max(total, picked.length) : picked.length, all,
|
|
1230
|
+
...(all ? { selectAllPages: true, total: Math.max(total, picked.length), query: curProps.query, filters: curProps.filters } : {}),
|
|
917
1231
|
});
|
|
918
1232
|
allMode = false;
|
|
919
1233
|
};
|
|
@@ -992,7 +1306,11 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
992
1306
|
});
|
|
993
1307
|
// 编辑器自带的浮层(日期 / 日期范围 / 时间 / 下拉的面板挂在浮层端口,不在表格 DOM 内)算编辑区内部:
|
|
994
1308
|
// 面板的锚点在表格里即属本表;点击瞬间已被重画摘掉的节点(日历翻月、选中后重绘)也不算外部
|
|
995
|
-
offs.push(onOutsidePress(tb, () => editing !== null, () =>
|
|
1309
|
+
offs.push(onOutsidePress(tb, () => editing !== null, () => {
|
|
1310
|
+
// 提交后的工具栏重建延到本次点击结束之后:pointerdown 阶段换掉被按下的按钮会吞掉随后的 click
|
|
1311
|
+
holdRebuild = true;
|
|
1312
|
+
try { settleEdit(); } finally { holdRebuild = false; }
|
|
1313
|
+
}, (node) => {
|
|
996
1314
|
const v = overlayVerdict(node, tb);
|
|
997
1315
|
if (v === 'inside') return true;
|
|
998
1316
|
if (v === 'foreign-layer') return editing !== null && editing.cells.some((c) => c.handle !== null);
|
|
@@ -1005,7 +1323,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1005
1323
|
queued = true;
|
|
1006
1324
|
queueMicrotask(() => {
|
|
1007
1325
|
queued = false;
|
|
1008
|
-
//
|
|
1326
|
+
// 表体被整块重建(轮询 / 后台重取):正在编辑的单元格已脱离文档,释放上一轮挂进去的日期框 / 下拉(含已展开的浮层)。
|
|
1327
|
+
// 只取消、不提交:丢弃没敲完的输入比把半截值写给服务端安全
|
|
1009
1328
|
if (editing && editing.cells.some((c) => !c.cell.isConnected)) cancelEdit(false);
|
|
1010
1329
|
applyAll();
|
|
1011
1330
|
});
|
|
@@ -1033,6 +1352,13 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1033
1352
|
} else if (view.status === 'saved') {
|
|
1034
1353
|
notice = null;
|
|
1035
1354
|
rebuild();
|
|
1355
|
+
} else if (view.status === 'conflict') {
|
|
1356
|
+
notice = { text: view.message !== '' ? view.message : T('soma.kit.form_conflict'), error: true };
|
|
1357
|
+
rebuild();
|
|
1358
|
+
} else if (view.status === 'cancelled') {
|
|
1359
|
+
// 被取消:结束「正在保存」;结果自带消息就显示它
|
|
1360
|
+
notice = view.message !== '' ? { text: view.message, error: false } : null;
|
|
1361
|
+
rebuild();
|
|
1036
1362
|
}
|
|
1037
1363
|
}));
|
|
1038
1364
|
}
|
|
@@ -1044,6 +1370,11 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1044
1370
|
for (const h of resizeHandles.values()) h.destroy();
|
|
1045
1371
|
resizeHandles.clear();
|
|
1046
1372
|
cancelEdit(false);
|
|
1373
|
+
// 卸载:撤掉加在表格外壳上的加载态标记
|
|
1374
|
+
if (table) {
|
|
1375
|
+
table.removeAttribute('aria-busy');
|
|
1376
|
+
for (const c of BUSY_TABLE_CLASS.split(' ')) table.classList.remove(c);
|
|
1377
|
+
}
|
|
1047
1378
|
embeds.release(rootEl);
|
|
1048
1379
|
liveEl?.remove();
|
|
1049
1380
|
liveEl = null;
|
|
@@ -1052,6 +1383,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1052
1383
|
rootEl = null;
|
|
1053
1384
|
apiRef = null;
|
|
1054
1385
|
rebuild = () => undefined;
|
|
1386
|
+
cancelHeldRebuild = () => undefined;
|
|
1387
|
+
deferRender = () => false;
|
|
1055
1388
|
};
|
|
1056
1389
|
},
|
|
1057
1390
|
render(root, p) {
|
|
@@ -1063,10 +1396,12 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1063
1396
|
if (stale.length > 0) queueMicrotask(() => selectRows(stale, false));
|
|
1064
1397
|
}
|
|
1065
1398
|
if (allMode && (!Array.isArray(p.selected) || p.selected.length === 0)) allMode = false;
|
|
1399
|
+
if (deferRender()) return;
|
|
1400
|
+
cancelHeldRebuild();
|
|
1066
1401
|
render(root, p);
|
|
1067
1402
|
applyAll();
|
|
1068
1403
|
},
|
|
1069
|
-
}
|
|
1070
|
-
},
|
|
1404
|
+
};
|
|
1405
|
+
}),
|
|
1071
1406
|
};
|
|
1072
1407
|
}
|