soma-kit 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -10,19 +10,27 @@
|
|
|
10
10
|
// 组件不改数据:写入只抛事件;勾选只抛 select_change(载荷 rows 批量,协调组件维护已选)。
|
|
11
11
|
// 记忆(列显隐、行高):localStorage,键含页面路径与对象名,读写全包 try/catch。
|
|
12
12
|
|
|
13
|
-
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
13
|
+
import type { SomaComponentDefinition, SomaDataPort, 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
|
|
|
@@ -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,29 +167,19 @@ 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`;
|
|
@@ -207,12 +223,17 @@ export function parseHidden(raw: string | null, known: readonly string[]): Set<s
|
|
|
207
223
|
}
|
|
208
224
|
}
|
|
209
225
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
226
|
+
// 行高三档就是九维 density 枚举(COMPACT_DENSE / STANDARD_BALANCED / SPACIOUS_AIRY),名字与真源同一份
|
|
227
|
+
type Density = KitTableDensity;
|
|
228
|
+
const DENSITY_LABEL: Readonly<Record<Density, KitTextKey>> = {
|
|
229
|
+
COMPACT_DENSE: 'soma.kit.density_compact_dense',
|
|
230
|
+
STANDARD_BALANCED: 'soma.kit.density_standard_balanced',
|
|
231
|
+
SPACIOUS_AIRY: 'soma.kit.density_spacious_airy',
|
|
232
|
+
};
|
|
233
|
+
const DENSITIES: ReadonlyArray<{ id: Density; label: KitTextKey }> = KIT_TABLE_DENSITIES.map((id) => ({ id, label: DENSITY_LABEL[id] }));
|
|
234
|
+
const isDensity = (v: unknown): v is Density => typeof v === 'string' && (KIT_TABLE_DENSITIES as readonly string[]).includes(v);
|
|
214
235
|
|
|
215
|
-
interface BatchItem { id: string; name: string; tone: 'primary' | 'danger' | 'neutral'; confirm: string; permission: string }
|
|
236
|
+
interface BatchItem { id: string; name: string; tone: 'primary' | 'danger' | 'neutral'; confirm: string; permission: string; busyAction: string }
|
|
216
237
|
|
|
217
238
|
function batchOf(raw: unknown): BatchItem[] {
|
|
218
239
|
if (!Array.isArray(raw)) return [];
|
|
@@ -220,9 +241,14 @@ function batchOf(raw: unknown): BatchItem[] {
|
|
|
220
241
|
id: str(b.id), name: str(b.name, str(b.id)),
|
|
221
242
|
tone: b.tone === 'primary' || b.tone === 'danger' ? b.tone : 'neutral',
|
|
222
243
|
confirm: str(b.confirm), permission: str(b.permission),
|
|
244
|
+
busyAction: str(b.busyAction),
|
|
223
245
|
})).filter((b) => b.id !== '');
|
|
224
246
|
}
|
|
225
247
|
|
|
248
|
+
function batchBusyNames(b: BatchItem): string {
|
|
249
|
+
return b.busyAction !== '' ? `${b.id},${b.busyAction}` : b.id;
|
|
250
|
+
}
|
|
251
|
+
|
|
226
252
|
// ---------------------------------------------------------------- 组件
|
|
227
253
|
|
|
228
254
|
export function createKitTableTools(): SomaComponentDefinition {
|
|
@@ -238,17 +264,29 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
238
264
|
keyField: { type: 'string', default: '', desc: '行主键字段名' },
|
|
239
265
|
columns: { type: 'array', default: [], desc: '列元信息 [{ field, label, fixed?, editable?, kind?, options?, format? }]' },
|
|
240
266
|
items: { type: 'array', default: [], desc: '工具栏项:reload / density / columns / export' },
|
|
241
|
-
density: { type: 'string', default: 'standard', desc: '表格默认行高档(记忆的行高优先)' },
|
|
242
267
|
scroll: { type: 'boolean', default: false, desc: '表格处于滚动模式(影响滚动边缘标记)' },
|
|
243
268
|
editMode: { type: 'string', default: '', desc: '就地编辑方式:cell / row;空 = 不编辑' },
|
|
244
269
|
selectMode: { type: 'string', default: 'none', desc: '勾选列模式 none / single / multi' },
|
|
245
270
|
selectScope: { type: 'string', default: 'all', desc: '勾选范围:all 跨页保留 / page 翻页丢弃不在本页的勾选' },
|
|
246
271
|
selected: { type: 'array', default: [], desc: '已选行数组(协调组件 focus 切片 sel 的镜像);配 batch 才有' },
|
|
247
272
|
batch: { type: 'array', default: [], desc: '批量动作 [{ id, name, tone, confirm, permission? }];confirm 里 {n} 换成已选个数' },
|
|
273
|
+
params: { type: 'object', default: {}, desc: '查询与筛选参数(变化时自动退出跨页全选全部模式)' },
|
|
274
|
+
query: { type: 'object', default: {}, desc: '查询条件参数(变化时自动退出跨页全选全部模式)' },
|
|
275
|
+
filters: { type: 'object', default: {}, desc: '筛选条件参数(变化时自动退出跨页全选全部模式)' },
|
|
276
|
+
readState: { type: 'string', default: '', desc: '列表对象的读状态(page.data.<对象>.readState);loading 且已有行 = 重新读取中:表格外壳 aria-busy + 降不透明度,刷新按钮置灰' },
|
|
248
277
|
class: CLASS_PROP,
|
|
249
278
|
},
|
|
250
279
|
emits: {
|
|
251
280
|
reload: { payload: {}, desc: '点工具栏「刷新」' },
|
|
281
|
+
export: {
|
|
282
|
+
payload: {
|
|
283
|
+
rows: { type: 'array', desc: '导出的当前页或已选行数组' },
|
|
284
|
+
csv: { type: 'string', desc: '导出的 CSV 文本' },
|
|
285
|
+
scope: { type: 'string', desc: '导出范围(固定为 page)' },
|
|
286
|
+
count: { type: 'number', desc: '导出的行数' },
|
|
287
|
+
},
|
|
288
|
+
desc: '点工具栏「导出」按钮(默认导出当前页数据)',
|
|
289
|
+
},
|
|
252
290
|
select_change: {
|
|
253
291
|
payload: {
|
|
254
292
|
rows: { type: 'array', desc: '被改变勾选的行(批量)' },
|
|
@@ -258,17 +296,14 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
258
296
|
},
|
|
259
297
|
desc: '批量条的「全选本页 / 清除」或翻页丢弃:与 row_select 同语义事件(载荷多了 rows)',
|
|
260
298
|
},
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
},
|
|
270
|
-
desc: '点批量动作(有 confirm 时已在批量条里确认过)',
|
|
271
|
-
},
|
|
299
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.batch, {
|
|
300
|
+
kit_action: { type: 'string', desc: '动作判别键' },
|
|
301
|
+
id: { type: 'string', desc: '动作 id' },
|
|
302
|
+
name: { type: 'string', desc: '动作显示名' },
|
|
303
|
+
rows: { type: 'array', desc: '已选行' },
|
|
304
|
+
count: { type: 'number', desc: '作用的行数(all 时为总数)' },
|
|
305
|
+
all: { type: 'boolean', desc: '用户选了「选择全部 N 项」:服务端按当前筛选条件处理' },
|
|
306
|
+
}, '点批量动作(有 confirm 时已在批量条里确认过),序号 = 动作在 batch 数组里的位置'),
|
|
272
307
|
cell_edit: {
|
|
273
308
|
payload: {
|
|
274
309
|
object: { type: 'string', desc: '对象名' },
|
|
@@ -281,15 +316,30 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
281
316
|
desc: '就地编辑保存:页面接 ACTION | data.submit',
|
|
282
317
|
},
|
|
283
318
|
},
|
|
319
|
+
scope: { slices: ['filter', 'view'] },
|
|
284
320
|
},
|
|
285
|
-
services: ['data', 'permission'],
|
|
321
|
+
services: ['data', 'permission', 'region'],
|
|
286
322
|
templateHtml: `<div data-soma-id="root" class="${HIDDEN_CLASS}"></div>`,
|
|
287
|
-
controllerFactory: (
|
|
288
|
-
const check = permissionCheckerOf(
|
|
323
|
+
controllerFactory: createKitController((api) => {
|
|
324
|
+
const check = permissionCheckerOf(api as unknown as any);
|
|
289
325
|
const dataPort = (): SomaDataPort | undefined => {
|
|
290
|
-
const port = (
|
|
326
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
291
327
|
return port && typeof port === 'object' ? port : undefined;
|
|
292
328
|
};
|
|
329
|
+
const regionPort = (): SomaRegionPort | null => {
|
|
330
|
+
const scope = str(P().scope);
|
|
331
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
332
|
+
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
333
|
+
};
|
|
334
|
+
const regionColFilterOf = (): Record<string, unknown> | null => {
|
|
335
|
+
const v = regionPort()?.slice('view')?.get();
|
|
336
|
+
if (!isRec(v)) return null;
|
|
337
|
+
const cf: Record<string, unknown> = {};
|
|
338
|
+
for (const [k, val] of Object.entries(v)) {
|
|
339
|
+
if (k.startsWith(KIT_TABLE_EXT.columnFilter.paramPrefix)) cf[k] = val;
|
|
340
|
+
}
|
|
341
|
+
return Object.keys(cf).length > 0 ? cf : null;
|
|
342
|
+
};
|
|
293
343
|
// ---- 状态
|
|
294
344
|
let hidden = new Set<string>();
|
|
295
345
|
// 列宽拖拽:字段 -> 档位下标(scroll.minSteps);touched = 有过改动、需要在新渲染的格上重放的列。宽度不持久化
|
|
@@ -298,20 +348,30 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
298
348
|
const resizeHandles = new Map<HTMLElement, ResizeHandle>();
|
|
299
349
|
let density: Density | null = null;
|
|
300
350
|
let panelOpen = false;
|
|
351
|
+
/** 当前列面板元素:面板经浮层端口挂在 root 之外,焦点归还要单独认它;面板关闭时为 null */
|
|
352
|
+
let colsPanelEl: HTMLElement | null = null;
|
|
301
353
|
// 列设置面板挂到浮层端口后不再是工具栏的后代,root 上的委托收不到它的事件:面板挂出后由 attach 里登记的函数直接绑在面板上
|
|
302
354
|
let panelBind: ((panel: HTMLElement) => void) | null = null;
|
|
303
355
|
let confirming: string | null = null;
|
|
356
|
+
let confirmingBatch = false;
|
|
304
357
|
let allMode = false;
|
|
358
|
+
let lastQuerySig = '';
|
|
305
359
|
let notice: { text: string; error: boolean } | null = null;
|
|
306
360
|
let table: HTMLElement | null = null;
|
|
307
361
|
let rootEl: HTMLElement | null = null;
|
|
308
362
|
let apiRef: { props: () => Rec } | null = null;
|
|
309
363
|
let rebuild: () => void = () => undefined;
|
|
364
|
+
// 组件正常重绘(新 props)已更新工具栏:取消挂起的那次重建
|
|
365
|
+
let cancelHeldRebuild: () => void = () => undefined;
|
|
366
|
+
// 指针按下窗口内的重绘入口:窗口开着则只记「待重绘(按最新 props)」并返回 true
|
|
367
|
+
let deferRender: () => boolean = () => false;
|
|
368
|
+
// 刷新由键盘触发(click.detail 为 0):读取期间按钮被禁用、焦点掉到 body,读取结束重建时还回去;鼠标触发不归还
|
|
369
|
+
let reloadHadFocus = false;
|
|
310
370
|
// 常驻播报区(sr-only,role=status):批量条每次重绘都会换新节点,节点内的 aria-live 播不出变化,所以播报走这一个不重建的节点
|
|
311
371
|
let liveEl: HTMLElement | null = null;
|
|
312
372
|
let liveLast = '';
|
|
313
373
|
// 内置文案:按宿主所在页面语言取词(运行期读法)
|
|
314
|
-
const T = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params,
|
|
374
|
+
const T = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params, api.host);
|
|
315
375
|
let selAnnounced = false;
|
|
316
376
|
const announce =(text: string): void => {
|
|
317
377
|
if (!liveEl || text === liveLast) return;
|
|
@@ -319,7 +379,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
319
379
|
liveEl.textContent = text;
|
|
320
380
|
};
|
|
321
381
|
|
|
322
|
-
const P =(): Rec => apiRef?.props() ??
|
|
382
|
+
const P =(): Rec => (apiRef?.props() ?? api.props()) as Rec;
|
|
323
383
|
const cols = (): ToolsColumn[] => columnsOf(P().columns);
|
|
324
384
|
const object = (): string => str(P().object);
|
|
325
385
|
const rowsList = (): unknown[] => (Array.isArray(P().rows) ? (P().rows as unknown[]) : []);
|
|
@@ -329,18 +389,16 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
329
389
|
const pathname = (): string => (typeof location === 'undefined' ? '' : location.pathname);
|
|
330
390
|
|
|
331
391
|
const effectiveDensity = (): Density => {
|
|
332
|
-
|
|
333
|
-
const d = str(P().density, 'standard');
|
|
334
|
-
return d === 'compact' || d === 'comfortable' ? d : 'standard';
|
|
392
|
+
return density ?? KIT_TABLE_DENSITY_DEFAULT;
|
|
335
393
|
};
|
|
336
394
|
|
|
337
395
|
// ---- 对表格外壳的作用
|
|
338
396
|
const applyDensity = (): void => {
|
|
339
397
|
if (!table) return;
|
|
340
398
|
const d = effectiveDensity();
|
|
341
|
-
if (d === '
|
|
399
|
+
if (d === 'COMPACT_DENSE') table.setAttribute('data-kit-dense', '');
|
|
342
400
|
else table.removeAttribute('data-kit-dense');
|
|
343
|
-
if (d === '
|
|
401
|
+
if (d === 'SPACIOUS_AIRY') table.setAttribute('data-kit-roomy', '');
|
|
344
402
|
else table.removeAttribute('data-kit-roomy');
|
|
345
403
|
};
|
|
346
404
|
|
|
@@ -490,7 +548,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
490
548
|
// ---- 勾选 / 批量
|
|
491
549
|
const selectRows = (rows: unknown[], checked: boolean): void => {
|
|
492
550
|
if (rows.length === 0) return;
|
|
493
|
-
|
|
551
|
+
api.emit('select_change', { rows, checked, mode: 'multi', keyField: keyField() });
|
|
494
552
|
};
|
|
495
553
|
/** 本页勾选状态:全未选 false / 部分选 'mixed' / 全选 true */
|
|
496
554
|
const pageState = (): boolean | 'mixed' => {
|
|
@@ -507,6 +565,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
507
565
|
const picked = selectedList();
|
|
508
566
|
const rows = picked.length > 0 ? picked : rowsList();
|
|
509
567
|
const text = buildCsv(visible, rows);
|
|
568
|
+
api.emit('export', { rows, csv: text, scope: 'page', count: rows.length });
|
|
510
569
|
const doc = rootEl?.ownerDocument;
|
|
511
570
|
if (!doc || typeof URL === 'undefined' || typeof URL.createObjectURL !== 'function') return;
|
|
512
571
|
const blob = new Blob([text], { type: 'text/csv;charset=utf-8' });
|
|
@@ -581,6 +640,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
581
640
|
input.setAttribute('type', 'text');
|
|
582
641
|
input.value = value === null || value === undefined ? '' : String(value);
|
|
583
642
|
input.className = EDIT_INPUT_CLASS;
|
|
643
|
+
setKitFace(input, KIT_FACE_FIELD);
|
|
584
644
|
// 数字列:自绘数字框(过滤非数字、↑↓ 调值),不用原生 type=number;随输入框一起卸载
|
|
585
645
|
if (col.kind === 'number') attachSpin(input, () => ({ step: 1 }));
|
|
586
646
|
return { control: input, valueEl: input, shell: input, handle: null };
|
|
@@ -591,7 +651,9 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
591
651
|
if (mode === '' || cell.getAttribute('data-kit-editable') === null) return;
|
|
592
652
|
const hit = rowOfCell(cell);
|
|
593
653
|
if (!hit) return;
|
|
594
|
-
|
|
654
|
+
// 点到同表另一格:旧编辑与「点到别处」同一套(有改动提交、无改动取消);校验没过则留在旧编辑
|
|
655
|
+
settleEdit();
|
|
656
|
+
if (editing) return;
|
|
595
657
|
const doc = cell.ownerDocument;
|
|
596
658
|
const targets = mode === 'row'
|
|
597
659
|
? Array.from(cell.parentElement?.querySelectorAll<HTMLElement>('[data-kit-editable]') ?? [cell])
|
|
@@ -631,9 +693,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
631
693
|
return raw;
|
|
632
694
|
};
|
|
633
695
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const e = editing;
|
|
696
|
+
/** 当前输入值相对编辑开始时的行值有哪些改动(Enter 提交与外部点击共用) */
|
|
697
|
+
const changesOf = (e: NonNullable<typeof editing>): Rec => {
|
|
637
698
|
const changes: Rec = {};
|
|
638
699
|
for (const c of e.cells) {
|
|
639
700
|
const next = valueOf(c);
|
|
@@ -641,8 +702,26 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
641
702
|
const same = (next === null || next === '') && (prev === null || prev === undefined || prev === '') ? true : String(next) === String(prev);
|
|
642
703
|
if (!same) changes[c.col.field] = next;
|
|
643
704
|
}
|
|
705
|
+
return changes;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
/** 点到别处 / 点另一个可编辑单元格:有未提交改动走与 Enter 相同的提交路径(不抢焦点),值没变才取消。
|
|
709
|
+
* 校验没过:留在编辑态并显示错误(不静默丢输入)。表体被后台重建时不走这里(见 MutationObserver:只取消,不提交半截输入) */
|
|
710
|
+
const settleEdit = (): void => {
|
|
711
|
+
if (!editing) return;
|
|
712
|
+
if (Object.keys(changesOf(editing)).length > 0) {
|
|
713
|
+
commitEdit(false);
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
cancelEdit(false);
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
const commitEdit = (refocus = true): void => {
|
|
720
|
+
if (!editing) return;
|
|
721
|
+
const e = editing;
|
|
722
|
+
const changes = changesOf(e);
|
|
644
723
|
if (Object.keys(changes).length === 0) {
|
|
645
|
-
cancelEdit(
|
|
724
|
+
cancelEdit(refocus);
|
|
646
725
|
return;
|
|
647
726
|
}
|
|
648
727
|
// 前端即时校验:沿用对象字典的 rules,只看被改的字段
|
|
@@ -671,33 +750,42 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
671
750
|
const key = keyField();
|
|
672
751
|
if (key === '' || e.row[key] === undefined) {
|
|
673
752
|
notice = { text: T('soma.kit.save_no_key'), error: true };
|
|
674
|
-
cancelEdit(
|
|
753
|
+
cancelEdit(refocus);
|
|
675
754
|
rebuild();
|
|
676
755
|
return;
|
|
677
756
|
}
|
|
678
757
|
const model: Rec = { [key]: e.row[key], ...changes };
|
|
679
|
-
cancelEdit(
|
|
758
|
+
cancelEdit(refocus);
|
|
680
759
|
notice = { text: T('soma.kit.saving'), error: false };
|
|
681
760
|
rebuild();
|
|
682
|
-
|
|
761
|
+
api.emit('cell_edit', { object: object(), scope: cellScope(), model, mode: 'update', field: Object.keys(changes).join(','), row: e.row });
|
|
683
762
|
};
|
|
684
763
|
|
|
685
764
|
// ---- 工具栏 / 批量条 渲染
|
|
686
|
-
|
|
765
|
+
/** 工具栏 / 批量条按钮;face 由调用方按创建处的样式决定(有实心 / 描边 / 浅底才标 raised,幽灵 / 链接钮传 null),不在运行时解析类串 */
|
|
766
|
+
const btn = (doc: Document, cls: string, text: string, attrs: Record<string, string> = {}, face: KitFaceKind | null = null): HTMLButtonElement => {
|
|
687
767
|
const b = doc.createElement('button');
|
|
688
768
|
b.setAttribute('type', 'button');
|
|
689
769
|
b.className = cls;
|
|
770
|
+
setKitFace(b, face);
|
|
690
771
|
b.textContent = text;
|
|
691
772
|
for (const [k, v] of Object.entries(attrs)) b.setAttribute(k, v);
|
|
692
773
|
return b;
|
|
693
774
|
};
|
|
694
775
|
|
|
695
|
-
|
|
776
|
+
/** 重新读取中:读状态 loading 且当前已有行(首次加载无行,走三态骨架,不叠加) */
|
|
777
|
+
const reading = (p: Rec): boolean => str(p.readState) === 'loading' && Array.isArray(p.rows) && p.rows.length > 0;
|
|
778
|
+
|
|
779
|
+
const renderToolbar = (doc: Document, items: string[], busy: boolean): HTMLElement => {
|
|
696
780
|
const group = doc.createElement('div');
|
|
697
781
|
group.className = GROUP_CLASS;
|
|
698
782
|
for (const it of items) {
|
|
699
783
|
if (it === 'reload') {
|
|
700
|
-
group.appendChild(btn(
|
|
784
|
+
group.appendChild(btn(
|
|
785
|
+
doc, busy ? `${TOOL_BTN_CLASS} ${BUSY_BTN_CLASS}` : TOOL_BTN_CLASS, T('soma.kit.refresh'),
|
|
786
|
+
busy ? { 'data-kit-tool': 'reload', disabled: '', 'aria-busy': 'true' } : { 'data-kit-tool': 'reload' },
|
|
787
|
+
KIT_FACE_RAISED,
|
|
788
|
+
));
|
|
701
789
|
} else if (it === 'density') {
|
|
702
790
|
const seg = doc.createElement('div');
|
|
703
791
|
seg.className = SEG_GROUP_CLASS;
|
|
@@ -705,18 +793,18 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
705
793
|
seg.setAttribute('aria-label', T('soma.kit.row_height'));
|
|
706
794
|
for (const d of DENSITIES) {
|
|
707
795
|
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' });
|
|
796
|
+
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
797
|
seg.appendChild(b);
|
|
710
798
|
}
|
|
711
799
|
group.appendChild(seg);
|
|
712
800
|
} else if (it === 'columns') {
|
|
713
801
|
const anchor = doc.createElement('div');
|
|
714
802
|
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' }));
|
|
803
|
+
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
804
|
if (panelOpen) anchor.appendChild(columnPanel(doc));
|
|
717
805
|
group.appendChild(anchor);
|
|
718
806
|
} else if (it === 'export') {
|
|
719
|
-
group.appendChild(btn(doc, TOOL_BTN_CLASS, T('soma.kit.export'), { 'data-kit-tool': 'export' }));
|
|
807
|
+
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
808
|
}
|
|
721
809
|
}
|
|
722
810
|
return group;
|
|
@@ -728,6 +816,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
728
816
|
panel.setAttribute('aria-label', T('soma.kit.columns'));
|
|
729
817
|
panel.setAttribute('data-kit-cols-panel', '');
|
|
730
818
|
panel.className = PANEL_BASE;
|
|
819
|
+
colsPanelEl = panel;
|
|
731
820
|
for (const c of cols()) {
|
|
732
821
|
const locked = c.fixed !== '';
|
|
733
822
|
const box = createCheck(doc, 'checkbox', {
|
|
@@ -781,25 +870,69 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
781
870
|
q.setAttribute('role', 'alert');
|
|
782
871
|
q.textContent = confirmText(item.confirm, count);
|
|
783
872
|
bar.appendChild(q);
|
|
784
|
-
|
|
785
|
-
|
|
873
|
+
const busy = isKitActionBusy(batchBusyNames(item));
|
|
874
|
+
const yesAttrs: Record<string, string> = { 'data-kit-batch-yes': item.id };
|
|
875
|
+
if (busy) {
|
|
876
|
+
yesAttrs.disabled = '';
|
|
877
|
+
yesAttrs['aria-busy'] = 'true';
|
|
878
|
+
}
|
|
879
|
+
const yesButton = btn(doc, ACTION_BUTTON_CLASS[item.tone], T('soma.kit.confirm'), yesAttrs, faceOfTone(item.tone));
|
|
880
|
+
if (busy) yesButton.disabled = true;
|
|
881
|
+
bar.appendChild(yesButton);
|
|
882
|
+
bar.appendChild(btn(doc, ACTION_BUTTON_CLASS.neutral, T('soma.kit.cancel'), { 'data-kit-batch-no': item.id }, KIT_FACE_RAISED));
|
|
786
883
|
return bar;
|
|
787
884
|
}
|
|
788
885
|
}
|
|
789
886
|
for (const b of batch) {
|
|
790
887
|
if (b.permission !== '' && check !== null && !check(b.permission)) continue;
|
|
791
|
-
|
|
888
|
+
const busy = isKitActionBusy(batchBusyNames(b));
|
|
889
|
+
const attrs: Record<string, string> = { 'data-kit-batch': b.id };
|
|
890
|
+
if (busy) {
|
|
891
|
+
attrs.disabled = '';
|
|
892
|
+
attrs['aria-busy'] = 'true';
|
|
893
|
+
}
|
|
894
|
+
const button = btn(doc, ACTION_BUTTON_CLASS[b.tone], b.name, attrs, faceOfTone(b.tone));
|
|
895
|
+
if (busy) button.disabled = true;
|
|
896
|
+
bar.appendChild(button);
|
|
792
897
|
}
|
|
793
898
|
return bar;
|
|
794
899
|
};
|
|
795
900
|
|
|
796
901
|
const render = (root: HTMLElement, p: Rec): void => {
|
|
797
902
|
const doc = root.ownerDocument;
|
|
903
|
+
const nextQuerySig = tableQuerySignature(p, regionPort()?.slice('filter')?.get() ?? null, regionColFilterOf());
|
|
904
|
+
if (lastQuerySig !== '' && lastQuerySig !== nextQuerySig) {
|
|
905
|
+
allMode = false;
|
|
906
|
+
confirming = null;
|
|
907
|
+
}
|
|
908
|
+
lastQuerySig = nextQuerySig;
|
|
798
909
|
const items = (Array.isArray(p.items) ? p.items : []).filter((x): x is string => typeof x === 'string');
|
|
910
|
+
const busyNow = reading(p);
|
|
911
|
+
if (table) {
|
|
912
|
+
if (busyNow) table.setAttribute('aria-busy', 'true'); else table.removeAttribute('aria-busy');
|
|
913
|
+
for (const c of BUSY_TABLE_CLASS.split(' ')) table.classList.toggle(c, busyNow);
|
|
914
|
+
}
|
|
799
915
|
const batch = batchOf(p.batch);
|
|
800
916
|
const picked = selectedList();
|
|
801
917
|
const batching = batch.length > 0 && picked.length > 0;
|
|
802
918
|
const selectAll = batch.length > 0 && str(p.selectMode) === 'multi';
|
|
919
|
+
const activeBefore = doc.activeElement;
|
|
920
|
+
const onReload = activeBefore instanceof HTMLElement && root.contains(activeBefore) && activeBefore.matches('[data-kit-tool="reload"]');
|
|
921
|
+
const idleBefore = activeBefore === null || activeBefore === doc.body;
|
|
922
|
+
// 归还标记由键盘触发的刷新点击置位(见 click 处理);焦点在别处时清掉
|
|
923
|
+
if (!onReload && !idleBefore) reloadHadFocus = false;
|
|
924
|
+
// 通用焦点归还:重建前记下焦点所在控件的标识(属性 + 值),重建后焦点落到 body 时还回同一个控件
|
|
925
|
+
let focusMark: { attr: string; value: string } | null = null;
|
|
926
|
+
// 焦点在 root 内,或在列面板内(面板在浮层端口时不在 root 里)都要记
|
|
927
|
+
const panelBefore = colsPanelEl;
|
|
928
|
+
if (activeBefore instanceof HTMLElement && (root.contains(activeBefore) || (panelBefore !== null && panelBefore.contains(activeBefore)))) {
|
|
929
|
+
for (let el: HTMLElement | null = activeBefore; el !== null && el !== root && el !== panelBefore?.parentElement; el = el.parentElement) {
|
|
930
|
+
const found = FOCUS_ID_ATTRS.find((a) => el!.hasAttribute(a));
|
|
931
|
+
if (found !== undefined) { focusMark = { attr: found, value: el.getAttribute(found) ?? '' }; break; }
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
// 重建会销毁旧面板;开着时由 columnPanel 重新登记,关着就保持空
|
|
935
|
+
colsPanelEl = null;
|
|
803
936
|
releaseDropdownsIn(root);
|
|
804
937
|
root.replaceChildren();
|
|
805
938
|
if (!liveEl || liveEl.parentElement === null) {
|
|
@@ -823,7 +956,7 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
823
956
|
box.appendChild(text);
|
|
824
957
|
parts.push(box);
|
|
825
958
|
}
|
|
826
|
-
if (items.length > 0) parts.push(renderToolbar(doc, items));
|
|
959
|
+
if (items.length > 0) parts.push(renderToolbar(doc, items, busyNow));
|
|
827
960
|
}
|
|
828
961
|
if (notice !== null) {
|
|
829
962
|
const n = doc.createElement('span');
|
|
@@ -835,40 +968,195 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
835
968
|
// 批量条与全选在同一行:全选本页放在批量条之外时与工具栏分居两端
|
|
836
969
|
for (const part of parts) root.appendChild(part);
|
|
837
970
|
root.className = parts.length === 0 ? `${HIDDEN_CLASS}` : `${ROOT_CLASS} ${typeof p.class === 'string' ? p.class : ''}`.trim();
|
|
971
|
+
if (focusMark !== null) {
|
|
972
|
+
const now = doc.activeElement;
|
|
973
|
+
if (now === null || now === doc.body) {
|
|
974
|
+
const mark = focusMark;
|
|
975
|
+
// 在 root 与新列面板两处按同属性 + 值找(面板在浮层端口时不在 root 里)
|
|
976
|
+
const findIn = (scope: ParentNode | null, attr: string, accept: (v: string) => boolean): HTMLElement | undefined => (
|
|
977
|
+
scope === null ? undefined : Array.from(scope.querySelectorAll<HTMLElement>(`[${attr}]`)).find((e) => accept(e.getAttribute(attr) ?? ''))
|
|
978
|
+
);
|
|
979
|
+
const same = findIn(root, mark.attr, (v) => v === mark.value) ?? findIn(colsPanelEl, mark.attr, (v) => v === mark.value);
|
|
980
|
+
// 同标识的控件在就还给它(被禁用也不再找别的);不在时先按接力表找(批量二次确认的进出),再退到第一个可用控件
|
|
981
|
+
const relay = FOCUS_RELAY[mark.attr];
|
|
982
|
+
const relayed = same === undefined && relay !== undefined ? findIn(root, relay.attr, (v) => !relay.sameValue || v === mark.value) : undefined;
|
|
983
|
+
const target = same ?? relayed ?? root.querySelector<HTMLElement>('button:not([disabled]), [role="button"]:not([disabled]), input:not([disabled])');
|
|
984
|
+
// 勾选标记(「全选本页」、列显隐)是 label 包原生 input:label 自身不可聚焦,落到里面的 input
|
|
985
|
+
const focusEl = target !== undefined && target !== null && isMark(target) ? (markInput(target) ?? target) : target;
|
|
986
|
+
const panelNow = colsPanelEl as HTMLElement | null;
|
|
987
|
+
if (focusEl && panelNow !== null && panelNow.contains(focusEl)) {
|
|
988
|
+
// 新列面板在 columnPanel 排的微任务里才挂到浮层端口(挪节点会丢焦点):排在它之后再聚焦
|
|
989
|
+
queueMicrotask(() => {
|
|
990
|
+
const cur = doc.activeElement;
|
|
991
|
+
if (focusEl.isConnected && (cur === null || cur === doc.body)) focusEl.focus({ preventScroll: true });
|
|
992
|
+
});
|
|
993
|
+
} else {
|
|
994
|
+
focusEl?.focus({ preventScroll: true });
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
if (reloadHadFocus && !busyNow) {
|
|
999
|
+
reloadHadFocus = false;
|
|
1000
|
+
const now = doc.activeElement;
|
|
1001
|
+
const again = root.querySelector<HTMLElement>('[data-kit-tool="reload"]');
|
|
1002
|
+
if (again && (now === null || now === doc.body)) again.focus({ preventScroll: true });
|
|
1003
|
+
}
|
|
838
1004
|
};
|
|
839
1005
|
|
|
840
|
-
return
|
|
841
|
-
attach(root
|
|
1006
|
+
return {
|
|
1007
|
+
attach(root) {
|
|
842
1008
|
rootEl = root;
|
|
843
1009
|
apiRef = api;
|
|
844
1010
|
const names = (): string[] => cols().map((c) => c.field);
|
|
1011
|
+
// 精确定位所属表格外壳:emitStatic 给工具条宿主(data-soma-id = 工具锚点)与表格外壳(data-kit-table-of)成对写同一个值;
|
|
1012
|
+
// 没有成对属性(手写页 / 旧产物)才认紧邻的、且没有标属于别人的表格外壳,再退到同父节点里「唯一一个」未标属主的表格;
|
|
1013
|
+
// 有多个候选时不猜(返回 null),不再取第一个
|
|
845
1014
|
table = (() => {
|
|
1015
|
+
const key = api.host.getAttribute('data-soma-id') ?? '';
|
|
1016
|
+
if (key !== '') {
|
|
1017
|
+
const paired = Array.from(api.host.parentElement?.querySelectorAll<HTMLElement>('[data-kit-table-of]') ?? []).find((e) => e.getAttribute('data-kit-table-of') === key);
|
|
1018
|
+
if (paired) return paired;
|
|
1019
|
+
}
|
|
846
1020
|
const next = api.host.nextElementSibling;
|
|
847
|
-
if (next instanceof HTMLElement && next.hasAttribute('data-kit-table')) return next;
|
|
848
|
-
|
|
1021
|
+
if (next instanceof HTMLElement && next.hasAttribute('data-kit-table') && !next.hasAttribute('data-kit-table-of')) return next;
|
|
1022
|
+
const free = Array.from(api.host.parentElement?.querySelectorAll<HTMLElement>('[data-kit-table]:not([data-kit-table-of])') ?? []);
|
|
1023
|
+
return free.length === 1 ? free[0]! : null;
|
|
849
1024
|
})();
|
|
850
1025
|
hidden = parseHidden(readStore(rememberKey(pathname(), object(), 'cols')), names());
|
|
851
1026
|
const savedDensity = readStore(rememberKey(pathname(), object(), 'density'));
|
|
852
|
-
density = savedDensity
|
|
853
|
-
|
|
1027
|
+
density = isDensity(savedDensity) ? savedDensity : null;
|
|
1028
|
+
// 工具栏是整体重建的:指针按下之后、click 派发之前换掉按钮节点,这次点击就丢了。
|
|
1029
|
+
// 两种来源共用一套挂起:① 外部点击检测(document 捕获阶段 pointerdown)同步提交编辑引起的重建(holdRebuild);
|
|
1030
|
+
// ② 指针按在本工具栏的按钮上之后(root 冒泡阶段 pointerdown 进入按下窗口)任何原因的重建 / 控制器重绘。
|
|
1031
|
+
// 结束时机:document click(冒泡,晚于 root 自己的 click 处理)/ pointercancel / pointerup 后一个任务 / window blur;结束时有待办则执行一次
|
|
1032
|
+
let holdRebuild = false;
|
|
1033
|
+
let pressing = false;
|
|
1034
|
+
let rebuildHeld = false;
|
|
1035
|
+
let renderHeld = false;
|
|
1036
|
+
let offHeld: (() => void) | null = null;
|
|
1037
|
+
const disarmHeld = (): void => { offHeld?.(); offHeld = null; };
|
|
1038
|
+
const endWindow = (): void => {
|
|
1039
|
+
pressing = false;
|
|
1040
|
+
disarmHeld();
|
|
1041
|
+
if (!rebuildHeld) return;
|
|
1042
|
+
const withRender = renderHeld;
|
|
1043
|
+
rebuildHeld = false;
|
|
1044
|
+
renderHeld = false;
|
|
1045
|
+
rebuild();
|
|
1046
|
+
if (withRender) applyAll();
|
|
1047
|
+
};
|
|
1048
|
+
const armHeldRebuild = (): void => {
|
|
1049
|
+
if (offHeld !== null) return;
|
|
1050
|
+
const doc = rootEl?.ownerDocument ?? document;
|
|
1051
|
+
const win = doc.defaultView;
|
|
1052
|
+
// pointerup 之后的兜底:触屏的 click 在手势结束后单独派发、可能晚于零延时定时器,所以等两帧再结束窗口;没有 rAF 的环境退回零延时定时器
|
|
1053
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
1054
|
+
let frame1: number | null = null;
|
|
1055
|
+
let frame2: number | null = null;
|
|
1056
|
+
const hasRaf = typeof win?.requestAnimationFrame === 'function';
|
|
1057
|
+
const onUp = (): void => {
|
|
1058
|
+
if (timer !== null || frame1 !== null || frame2 !== null) return;
|
|
1059
|
+
if (win && hasRaf) {
|
|
1060
|
+
frame1 = win.requestAnimationFrame(() => {
|
|
1061
|
+
frame1 = null;
|
|
1062
|
+
frame2 = win.requestAnimationFrame(() => { frame2 = null; endWindow(); });
|
|
1063
|
+
});
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
timer = setTimeout(() => { timer = null; endWindow(); }, 0);
|
|
1067
|
+
};
|
|
1068
|
+
doc.addEventListener('click', endWindow);
|
|
1069
|
+
doc.addEventListener('pointercancel', endWindow);
|
|
1070
|
+
doc.addEventListener('pointerup', onUp);
|
|
1071
|
+
win?.addEventListener('blur', endWindow);
|
|
1072
|
+
offHeld = () => {
|
|
1073
|
+
doc.removeEventListener('click', endWindow);
|
|
1074
|
+
doc.removeEventListener('pointercancel', endWindow);
|
|
1075
|
+
doc.removeEventListener('pointerup', onUp);
|
|
1076
|
+
win?.removeEventListener('blur', endWindow);
|
|
1077
|
+
if (timer !== null) clearTimeout(timer);
|
|
1078
|
+
timer = null;
|
|
1079
|
+
if (frame1 !== null) win?.cancelAnimationFrame(frame1);
|
|
1080
|
+
if (frame2 !== null) win?.cancelAnimationFrame(frame2);
|
|
1081
|
+
frame1 = null;
|
|
1082
|
+
frame2 = null;
|
|
1083
|
+
};
|
|
1084
|
+
};
|
|
1085
|
+
deferRender = () => {
|
|
1086
|
+
if (!pressing) return false;
|
|
1087
|
+
rebuildHeld = true;
|
|
1088
|
+
renderHeld = true;
|
|
1089
|
+
return true;
|
|
1090
|
+
};
|
|
1091
|
+
rebuild = () => {
|
|
1092
|
+
if (holdRebuild || pressing) {
|
|
1093
|
+
rebuildHeld = true;
|
|
1094
|
+
armHeldRebuild();
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (rootEl) {
|
|
1098
|
+
const prevScrollTop = table?.scrollTop;
|
|
1099
|
+
const prevScrollLeft = table?.scrollLeft;
|
|
1100
|
+
render(rootEl, api.props());
|
|
1101
|
+
if (table) {
|
|
1102
|
+
if (prevScrollTop !== undefined && table.scrollTop !== prevScrollTop) {
|
|
1103
|
+
table.scrollTop = prevScrollTop;
|
|
1104
|
+
}
|
|
1105
|
+
if (prevScrollLeft !== undefined && table.scrollLeft !== prevScrollLeft) {
|
|
1106
|
+
table.scrollLeft = prevScrollLeft;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
854
1111
|
|
|
855
1112
|
const offs: Array<() => void> = [];
|
|
1113
|
+
cancelHeldRebuild = () => { rebuildHeld = false; renderHeld = false; pressing = false; disarmHeld(); };
|
|
1114
|
+
offs.push(() => cancelHeldRebuild());
|
|
1115
|
+
offs.push(onKitActionBusy(() => rebuild()));
|
|
1116
|
+
for (const sliceName of ['filter', 'view'] as const) {
|
|
1117
|
+
const slice = regionPort()?.slice(sliceName);
|
|
1118
|
+
if (slice?.subscribe) {
|
|
1119
|
+
offs.push(slice.subscribe(() => { if (allMode) rebuild(); }));
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
856
1122
|
const on = (el: EventTarget | null | undefined, type: string, fn: (e: never) => void): void => {
|
|
857
1123
|
if (!el) return;
|
|
858
1124
|
el.addEventListener(type, fn as EventListener);
|
|
859
1125
|
offs.push(() => el.removeEventListener(type, fn as EventListener));
|
|
860
1126
|
};
|
|
861
1127
|
|
|
1128
|
+
// 指针按在工具栏按钮上:进入按下窗口(冒泡阶段,晚于 document 捕获阶段的外部点击检测,同步挂起的那次重建已在等待)。键盘触发没有 pointerdown,不进窗口
|
|
1129
|
+
on(root, 'pointerdown', (event: Event) => {
|
|
1130
|
+
// 只认主键:右键 / 中键按下时部分平台弹出上下文菜单,之后不一定派发 pointerup / click,按下窗口会一直挂着、重绘全被推迟
|
|
1131
|
+
const button = (event as { button?: unknown }).button;
|
|
1132
|
+
if (typeof button === 'number' && button !== 0) return;
|
|
1133
|
+
const t = event.target;
|
|
1134
|
+
if (!(t instanceof Element) || !root.contains(t) || t.closest('button, [role="button"], [data-kit-tool]') === null) return;
|
|
1135
|
+
pressing = true;
|
|
1136
|
+
armHeldRebuild();
|
|
1137
|
+
});
|
|
862
1138
|
// 工具栏 / 批量条 的点击与勾选
|
|
863
1139
|
on(root, 'click', (event: Event) => {
|
|
864
1140
|
const t = event.target as HTMLElement | null;
|
|
865
1141
|
if (!t) return;
|
|
1142
|
+
// 键盘在按钮上按 Enter / 空格没有 pointerdown,外部按下检测没机会结算:先结算进行中的行内编辑(鼠标路径已结算过,这里是空操作)。
|
|
1143
|
+
// 校验没过则留在编辑态,本次工具动作不执行
|
|
1144
|
+
const stillEditing = (): boolean => editing !== null;
|
|
1145
|
+
if (stillEditing()) {
|
|
1146
|
+
settleEdit();
|
|
1147
|
+
if (stillEditing()) return;
|
|
1148
|
+
}
|
|
866
1149
|
const tool = t.closest<HTMLElement>('[data-kit-tool]')?.getAttribute('data-kit-tool');
|
|
867
|
-
if (tool === 'reload') {
|
|
1150
|
+
if (tool === 'reload') {
|
|
1151
|
+
// 焦点归还只给键盘用户:键盘触发的 click 其 detail 为 0,鼠标 ≥ 1
|
|
1152
|
+
if ((event as MouseEvent).detail === 0) reloadHadFocus = true;
|
|
1153
|
+
api.emit('reload', {});
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
868
1156
|
if (tool === 'export') { exportCsv(); return; }
|
|
869
1157
|
if (tool === 'columns') { panelOpen = !panelOpen; rebuild(); return; }
|
|
870
|
-
const dens = t.closest<HTMLElement>('[data-kit-density]')?.getAttribute('data-kit-density');
|
|
871
|
-
if (dens
|
|
1158
|
+
const dens = t.closest<HTMLElement>('[data-kit-table-density]')?.getAttribute('data-kit-table-density');
|
|
1159
|
+
if (isDensity(dens)) {
|
|
872
1160
|
density = dens;
|
|
873
1161
|
writeStore(rememberKey(pathname(), object(), 'density'), dens);
|
|
874
1162
|
applyDensity();
|
|
@@ -896,24 +1184,49 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
896
1184
|
const item = batchOf(api.props().batch).find((b) => b.id === batchId);
|
|
897
1185
|
if (!item) return;
|
|
898
1186
|
if (item.confirm !== '') { confirming = item.id; rebuild(); return; }
|
|
899
|
-
|
|
1187
|
+
if (confirmingBatch || isKitActionBusy(batchBusyNames(item))) return;
|
|
1188
|
+
const batchBtn = t.closest<HTMLButtonElement>('[data-kit-batch]');
|
|
1189
|
+
if (batchBtn) batchBtn.disabled = true;
|
|
1190
|
+
confirmingBatch = true;
|
|
1191
|
+
try {
|
|
1192
|
+
fireBatch(item);
|
|
1193
|
+
} finally {
|
|
1194
|
+
queueMicrotask(() => {
|
|
1195
|
+
confirmingBatch = false;
|
|
1196
|
+
if (batchBtn && !isKitActionBusy(batchBusyNames(item))) batchBtn.disabled = false;
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
900
1199
|
return;
|
|
901
1200
|
}
|
|
902
1201
|
const yes = t.closest<HTMLElement>('[data-kit-batch-yes]')?.getAttribute('data-kit-batch-yes');
|
|
903
1202
|
if (yes) {
|
|
904
1203
|
const item = batchOf(api.props().batch).find((b) => b.id === yes);
|
|
905
|
-
|
|
906
|
-
if (
|
|
1204
|
+
if (!item) return;
|
|
1205
|
+
if (confirmingBatch || isKitActionBusy(batchBusyNames(item))) return;
|
|
1206
|
+
const yesBtn = t.closest<HTMLButtonElement>('[data-kit-batch-yes]');
|
|
1207
|
+
if (yesBtn) yesBtn.disabled = true;
|
|
1208
|
+
confirmingBatch = true;
|
|
1209
|
+
try {
|
|
1210
|
+
confirming = null;
|
|
1211
|
+
fireBatch(item);
|
|
1212
|
+
rebuild();
|
|
1213
|
+
} finally {
|
|
1214
|
+
queueMicrotask(() => {
|
|
1215
|
+
confirmingBatch = false;
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
907
1218
|
return;
|
|
908
1219
|
}
|
|
909
1220
|
if (t.closest('[data-kit-batch-no]')) { confirming = null; rebuild(); }
|
|
910
1221
|
});
|
|
911
1222
|
const fireBatch = (item: BatchItem): void => {
|
|
1223
|
+
const curProps = api.props();
|
|
912
1224
|
const picked = selectedList();
|
|
913
|
-
const total = num(
|
|
1225
|
+
const total = num(curProps.total) ?? 0;
|
|
914
1226
|
const all = allMode;
|
|
915
|
-
|
|
1227
|
+
emitActionSlot((n, p) => api.emit(n, p), KIT_ACTION_SLOT_BASE.batch, batchOf(curProps.batch).findIndex((b) => b.id === item.id), {
|
|
916
1228
|
kit_action: item.id, id: item.id, name: item.name, rows: picked, count: all ? Math.max(total, picked.length) : picked.length, all,
|
|
1229
|
+
...(all ? { selectAllPages: true, total: Math.max(total, picked.length), query: curProps.query, filters: curProps.filters } : {}),
|
|
917
1230
|
});
|
|
918
1231
|
allMode = false;
|
|
919
1232
|
};
|
|
@@ -992,7 +1305,11 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
992
1305
|
});
|
|
993
1306
|
// 编辑器自带的浮层(日期 / 日期范围 / 时间 / 下拉的面板挂在浮层端口,不在表格 DOM 内)算编辑区内部:
|
|
994
1307
|
// 面板的锚点在表格里即属本表;点击瞬间已被重画摘掉的节点(日历翻月、选中后重绘)也不算外部
|
|
995
|
-
offs.push(onOutsidePress(tb, () => editing !== null, () =>
|
|
1308
|
+
offs.push(onOutsidePress(tb, () => editing !== null, () => {
|
|
1309
|
+
// 提交后的工具栏重建延到本次点击结束之后:pointerdown 阶段换掉被按下的按钮会吞掉随后的 click
|
|
1310
|
+
holdRebuild = true;
|
|
1311
|
+
try { settleEdit(); } finally { holdRebuild = false; }
|
|
1312
|
+
}, (node) => {
|
|
996
1313
|
const v = overlayVerdict(node, tb);
|
|
997
1314
|
if (v === 'inside') return true;
|
|
998
1315
|
if (v === 'foreign-layer') return editing !== null && editing.cells.some((c) => c.handle !== null);
|
|
@@ -1005,7 +1322,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1005
1322
|
queued = true;
|
|
1006
1323
|
queueMicrotask(() => {
|
|
1007
1324
|
queued = false;
|
|
1008
|
-
//
|
|
1325
|
+
// 表体被整块重建(轮询 / 后台重取):正在编辑的单元格已脱离文档,释放上一轮挂进去的日期框 / 下拉(含已展开的浮层)。
|
|
1326
|
+
// 只取消、不提交:丢弃没敲完的输入比把半截值写给服务端安全
|
|
1009
1327
|
if (editing && editing.cells.some((c) => !c.cell.isConnected)) cancelEdit(false);
|
|
1010
1328
|
applyAll();
|
|
1011
1329
|
});
|
|
@@ -1033,6 +1351,13 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1033
1351
|
} else if (view.status === 'saved') {
|
|
1034
1352
|
notice = null;
|
|
1035
1353
|
rebuild();
|
|
1354
|
+
} else if (view.status === 'conflict') {
|
|
1355
|
+
notice = { text: view.message !== '' ? view.message : T('soma.kit.form_conflict'), error: true };
|
|
1356
|
+
rebuild();
|
|
1357
|
+
} else if (view.status === 'cancelled') {
|
|
1358
|
+
// 被取消:结束「正在保存」;结果自带消息就显示它
|
|
1359
|
+
notice = view.message !== '' ? { text: view.message, error: false } : null;
|
|
1360
|
+
rebuild();
|
|
1036
1361
|
}
|
|
1037
1362
|
}));
|
|
1038
1363
|
}
|
|
@@ -1044,6 +1369,11 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1044
1369
|
for (const h of resizeHandles.values()) h.destroy();
|
|
1045
1370
|
resizeHandles.clear();
|
|
1046
1371
|
cancelEdit(false);
|
|
1372
|
+
// 卸载:撤掉加在表格外壳上的加载态标记
|
|
1373
|
+
if (table) {
|
|
1374
|
+
table.removeAttribute('aria-busy');
|
|
1375
|
+
for (const c of BUSY_TABLE_CLASS.split(' ')) table.classList.remove(c);
|
|
1376
|
+
}
|
|
1047
1377
|
embeds.release(rootEl);
|
|
1048
1378
|
liveEl?.remove();
|
|
1049
1379
|
liveEl = null;
|
|
@@ -1052,6 +1382,8 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1052
1382
|
rootEl = null;
|
|
1053
1383
|
apiRef = null;
|
|
1054
1384
|
rebuild = () => undefined;
|
|
1385
|
+
cancelHeldRebuild = () => undefined;
|
|
1386
|
+
deferRender = () => false;
|
|
1055
1387
|
};
|
|
1056
1388
|
},
|
|
1057
1389
|
render(root, p) {
|
|
@@ -1063,10 +1395,12 @@ export function createKitTableTools(): SomaComponentDefinition {
|
|
|
1063
1395
|
if (stale.length > 0) queueMicrotask(() => selectRows(stale, false));
|
|
1064
1396
|
}
|
|
1065
1397
|
if (allMode && (!Array.isArray(p.selected) || p.selected.length === 0)) allMode = false;
|
|
1398
|
+
if (deferRender()) return;
|
|
1399
|
+
cancelHeldRebuild();
|
|
1066
1400
|
render(root, p);
|
|
1067
1401
|
applyAll();
|
|
1068
1402
|
},
|
|
1069
|
-
}
|
|
1070
|
-
},
|
|
1403
|
+
};
|
|
1404
|
+
}),
|
|
1071
1405
|
};
|
|
1072
1406
|
}
|