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
|
@@ -5,20 +5,31 @@
|
|
|
5
5
|
// 响应里取不到行数组 -> loading;响应里 errorPath 有文案 -> error;行数组为空 -> empty;否则不显示。
|
|
6
6
|
// core 不暴露读失败状态,所以 error 态只在列表响应自带错误文案时出现。
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
import { CLASS_PROP, findRoot, joinClass, str } from '../base/shared';
|
|
8
|
+
import type { SomaComponentDefinition, SomaRegionPort } from 'soma-core';
|
|
9
|
+
import { CLASS_PROP, createKitController, findRoot, joinClass, str } from '../base/shared';
|
|
10
10
|
import { kitIcon } from '../base/icons';
|
|
11
|
+
import { releaseReasonTipsIn, KIT_APP_TOOLTIP_CLASS_CANDIDATES } from '../base/reason-tip';
|
|
12
|
+
import { KIT_TIPS_SCOPE_ATTR, kitHelpButton } from '../base/hint-tips';
|
|
13
|
+
import { KIT_FACE_FIELD, KIT_FACE_RAISED, KIT_PART_ATTRIBUTE, KIT_PART_TABLE_HEAD, kitFocusRingRecipe, kitTextActionRecipe, setKitFace } from '../recipes';
|
|
11
14
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, onOutsidePress, popPlaceClass, showDropdownFitted, type PopPlace } from '../base/popup';
|
|
15
|
+
import { releaseStickyEdge, syncStickyEdge } from '../base/sticky-edge';
|
|
16
|
+
import { leaveAnchored, unmarkAnchored } from '../base/anchored-layer';
|
|
17
|
+
import type { KitLeaveHandle } from '../base/overlay-runtime';
|
|
12
18
|
import { createPanelPortal, KIT_PANEL_PORTAL_CLASS_CANDIDATES, type PanelPortal } from '../data/overlay-portal';
|
|
13
19
|
import { trapTab } from '../data/d9-util';
|
|
14
|
-
import {
|
|
20
|
+
import { createReadRollback } from '../data/read-rollback';
|
|
21
|
+
import { KIT_CHECK_CLASS_CANDIDATES, attachMarkEvents, createCheck, isMark, markInput, paintCheck } from '../base/check-core';
|
|
15
22
|
import { KIT_TABLE_EXT } from './defaults';
|
|
16
23
|
import { kitText } from '../i18n/kit-text';
|
|
24
|
+
import { mergeClass } from './merge-class';
|
|
17
25
|
import { KIT_SKELETON_CLASS_CANDIDATES, buildSkeleton, skeletonConfigOf } from './skeleton';
|
|
26
|
+
import { KIT_ILLUSTRATION_CLASS_CANDIDATES } from '../base/illustrations';
|
|
27
|
+
import { KIT_STATE_PANEL_CLASS_CANDIDATES, paintKitStatePanel, splitHttpErrorPrefix } from '../base/state-panel';
|
|
18
28
|
|
|
19
29
|
// ---------------------------------------------------------------- KitTableHead
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
// px-0:样式引擎不带 preflight,button 吃浏览器默认的 1px 6px 内边距与 2px 按钮边框,可排序表头文字会比同列单元格内容右错 6px 且撑高紧凑表头;归零让表头与列内容左缘对齐、高度吃主题表头令牌
|
|
32
|
+
const HEAD_BUTTON_CLASS = 'inline-flex appearance-none items-center gap-1 rounded-md border-0 bg-transparent px-0 py-0 text-start font-semibold transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
22
33
|
const HEAD_SR_CLASS = 'sr-only';
|
|
23
34
|
const HEAD_MARK_CLASS = 'text-xs text-fg-subtle';
|
|
24
35
|
const HEAD_MARK_ACTIVE_CLASS = 'text-xs text-fg';
|
|
@@ -33,17 +44,17 @@ const FILTER_PANEL_BASE = 'absolute z-20 w-56 rounded-lg border border-border-su
|
|
|
33
44
|
const FILTER_PREF: PopPlace = { side: 'bottom', align: 'start' };
|
|
34
45
|
const filterClassFor = (place: PopPlace): string => `${FILTER_PANEL_BASE} ${popPlaceClass(place, 1)}`;
|
|
35
46
|
const FILTER_LIST_CLASS = 'flex max-h-48 flex-col gap-1 overflow-y-auto';
|
|
36
|
-
const FILTER_OPTION_CLASS = 'w-full px-1 py-1 hover:bg-
|
|
47
|
+
const FILTER_OPTION_CLASS = 'w-full px-1 py-1 hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
37
48
|
const FILTER_INPUT_CLASS = 'block h-8 w-full appearance-none autofill-clear rounded-md border border-border bg-surface px-3 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring';
|
|
38
49
|
const FILTER_FOOT_CLASS = 'mt-3 flex items-center justify-end gap-2';
|
|
39
50
|
const FILTER_APPLY_CLASS = 'inline-flex h-8 items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
40
|
-
const FILTER_CLEAR_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
51
|
+
const FILTER_CLEAR_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 state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
41
52
|
|
|
42
53
|
export const KIT_TABLE_HEAD_CLASS_CANDIDATES: readonly string[] = [
|
|
43
54
|
HEAD_BUTTON_CLASS, HEAD_MARK_CLASS, HEAD_MARK_ACTIVE_CLASS, HEAD_SR_CLASS,
|
|
44
55
|
HEAD_INNER_CLASS, HEAD_CELL_FILTER_CLASS, FILTER_BUTTON_CLASS, FILTER_BUTTON_ACTIVE_CLASS, FILTER_ICON_CLASS, FILTER_PANEL_BASE, FILTER_LIST_CLASS,
|
|
45
56
|
FILTER_OPTION_CLASS, ...KIT_CHECK_CLASS_CANDIDATES, FILTER_INPUT_CLASS, FILTER_FOOT_CLASS, FILTER_APPLY_CLASS, FILTER_CLEAR_CLASS,
|
|
46
|
-
...KIT_DROPDOWN_CLASS_CANDIDATES, ...KIT_PANEL_PORTAL_CLASS_CANDIDATES,
|
|
57
|
+
...KIT_DROPDOWN_CLASS_CANDIDATES, ...KIT_PANEL_PORTAL_CLASS_CANDIDATES, ...KIT_APP_TOOLTIP_CLASS_CANDIDATES,
|
|
47
58
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== ''));
|
|
48
59
|
|
|
49
60
|
type SortOrder = 'asc' | 'desc';
|
|
@@ -66,6 +77,8 @@ interface HeadCell {
|
|
|
66
77
|
group: number;
|
|
67
78
|
/** 叶子表头格右缘带列宽拖拽手柄(手柄由 KitTableTools 补,这里只标记) */
|
|
68
79
|
resizable: boolean;
|
|
80
|
+
/** 字段说明(fields[].help):非空时标签旁出一个「i」图标钮,悬停 / 聚焦显示(J9);空 = 不出任何节点 */
|
|
81
|
+
help: string;
|
|
69
82
|
}
|
|
70
83
|
|
|
71
84
|
/** 多级表头的列组(props.groups):组块 = flex 列(组标题格 + 叶子行) */
|
|
@@ -113,6 +126,7 @@ function cellsOf(raw: unknown): HeadCell[] {
|
|
|
113
126
|
out.push({
|
|
114
127
|
label: str(rec.label), class: str(rec.class), sort: str(rec.sort), col: str(rec.col), filter: filterOf(rec.filter), sr: str(rec.sr),
|
|
115
128
|
group: typeof rec.group === 'number' && Number.isInteger(rec.group) ? rec.group : -1, resizable: rec.resizable === true,
|
|
129
|
+
help: str(rec.help).trim(),
|
|
116
130
|
});
|
|
117
131
|
}
|
|
118
132
|
return out;
|
|
@@ -147,6 +161,9 @@ function sortHeld(raw: unknown): { sort: string; order: string } {
|
|
|
147
161
|
return { sort: str(rec.sort), order: str(rec.order) };
|
|
148
162
|
}
|
|
149
163
|
|
|
164
|
+
/** 区域语义事件:清除全部表头筛选(KitTableHead 是 cf_<字段> 的写者,所以清除由它做;集合的「清除筛选」提示经区域端口发这条) */
|
|
165
|
+
export const KIT_CLEAR_COLUMN_FILTERS_EVENT = 'kit_clear_column_filters';
|
|
166
|
+
|
|
150
167
|
export function createKitTableHead(): SomaComponentDefinition {
|
|
151
168
|
return {
|
|
152
169
|
contract: {
|
|
@@ -156,6 +173,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
156
173
|
cells: { type: 'array', default: [], desc: '表头格 [{ label, class, sort?, col?, filter?, group?, resizable? }];sort 非空即可排序列(值 = 排序键);col = 字段名(列显隐标记);filter = { kind: enum | text, param, options? } 时格内出漏斗钮;group = 所属列组下标(groups);resizable = 右缘留列宽拖拽手柄(KitTableTools 补)' },
|
|
157
174
|
groups: { type: 'array', default: [], desc: '列组(多级表头)[{ title, span, cols, blockClass, titleClass, leavesClass }];连续同组的 cells 收进一个组块(组标题格 + 叶子行)' },
|
|
158
175
|
scope: { type: 'string', default: '', desc: '区域作用域 id;给了就把 sort / order 写进 view 切片' },
|
|
176
|
+
readState: { type: 'string', default: '', desc: '列表对象的读状态,用于失败回滚' },
|
|
159
177
|
semantics: { type: 'enum', values: ['none', 'table'], default: 'none', desc: 'table = 表头行是 role=row、格是 columnheader(可排序列带 aria-sort),只在外壳是 role=table 的表格里用;none = 不写角色(树表等外壳没有表格角色的场合)' },
|
|
160
178
|
class: { ...CLASS_PROP, desc: '表头行容器类(栅格 + 底色)' },
|
|
161
179
|
},
|
|
@@ -173,8 +191,8 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
173
191
|
},
|
|
174
192
|
services: ['region'],
|
|
175
193
|
templateHtml: '<div data-soma-id="root"></div>',
|
|
176
|
-
controllerFactory: (
|
|
177
|
-
const P = (): Record<string, unknown> =>
|
|
194
|
+
controllerFactory: createKitController((api) => {
|
|
195
|
+
const P = (): Record<string, unknown> => api.props();
|
|
178
196
|
let root: HTMLElement | null = null;
|
|
179
197
|
let offs: Array<() => void> = [];
|
|
180
198
|
// 表头筛选面板状态(同一时刻至多开一个)
|
|
@@ -185,19 +203,69 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
185
203
|
let focusBack: string | null = null;
|
|
186
204
|
// 筛选面板的浮层挂载(onMount 建、onUnmount 销);壳上的委托监听由 onMount 里的处理函数登记
|
|
187
205
|
let panelPortal: PanelPortal | null = null;
|
|
206
|
+
// 筛选面板出场(隐藏前过渡,与其他锚定浮层同一机制):当前挂出的面板与进行中的退场句柄
|
|
207
|
+
let shownPanel: HTMLElement | null = null;
|
|
208
|
+
let filterLeave: KitLeaveHandle | null = null;
|
|
188
209
|
let shellBind: ((shell: HTMLElement) => () => void) | null = null;
|
|
189
210
|
|
|
190
211
|
const port =(): SomaRegionPort | null => {
|
|
191
212
|
const scope = str(P().scope);
|
|
192
|
-
const svc = (
|
|
213
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
193
214
|
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
194
215
|
};
|
|
195
216
|
|
|
217
|
+
// 重取失败回滚:点表头写了 sort / order(及回第 1 页)而重取失败时,写回最近一次读成功的值(只写切片,不抛 sort);
|
|
218
|
+
// 列筛选是用户输入,不回滚
|
|
219
|
+
const rollback = createReadRollback<{ sort: string; order: string; page: number | null }>({
|
|
220
|
+
readState: () => str(P().readState),
|
|
221
|
+
snapshot: () => {
|
|
222
|
+
const v = port()?.slice('view')?.get();
|
|
223
|
+
const rec = v !== null && typeof v === 'object' ? v as Record<string, unknown> : {};
|
|
224
|
+
const held = sortHeld(rec);
|
|
225
|
+
return { ...held, page: typeof rec.page === 'number' ? rec.page : null };
|
|
226
|
+
},
|
|
227
|
+
restore: (v) => {
|
|
228
|
+
const slice = port()?.slice('view');
|
|
229
|
+
if (!slice) return;
|
|
230
|
+
slice.set(v.sort === '' ? null : v.sort, 'sort');
|
|
231
|
+
slice.set(v.order === '' ? null : v.order, 'order');
|
|
232
|
+
const page = (slice.get() as { page?: unknown } | undefined)?.page;
|
|
233
|
+
if (v.page !== null && page !== v.page) {
|
|
234
|
+
try {
|
|
235
|
+
slice.set(v.page, 'page');
|
|
236
|
+
} catch (err) {
|
|
237
|
+
console.debug('[soma-kit] KitTableHead 无权写 page,页码回滚交给 page 写者', err);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
// 点表头写切片期间,切片订阅会同步触发重绘;这段重绘不是「读状态变了」,不喂给回滚状态机
|
|
243
|
+
let committing = false;
|
|
244
|
+
|
|
245
|
+
// 表头文字被列宽截断(truncate)时的悬停 / 聚焦全文提示、字段说明「i」图标钮的气泡,都由 base/hint-tips.ts 的事件委托按需挂载
|
|
246
|
+
// (悬停 / 聚焦到才量、才建;没截断不挂)。表头只负责标出作用范围(data-kit-tips)与画图标钮;重绘前摘掉旧气泡。
|
|
196
247
|
const paint = (): void => {
|
|
197
248
|
if (!root) return;
|
|
198
249
|
const p = P();
|
|
250
|
+
releaseReasonTipsIn(root);
|
|
199
251
|
const held = sortHeld(port()?.slice('view')?.get());
|
|
200
252
|
root.className = joinClass('', p.class);
|
|
253
|
+
root.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_TABLE_HEAD);
|
|
254
|
+
// 吸顶表头:吸住之后才出现下缘分隔(滚动驱动,不支持时 IntersectionObserver 回退);不吸顶的表头摘除标记
|
|
255
|
+
syncStickyEdge(root);
|
|
256
|
+
root.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
257
|
+
// 重绘会换掉全部节点:记下焦点所在的排序钮,重绘后还回去
|
|
258
|
+
const activeEl = root.ownerDocument.activeElement;
|
|
259
|
+
const focusedSort = activeEl && root.contains(activeEl) ? activeEl.closest('[data-kit-sort]')?.getAttribute('data-kit-sort') ?? null : null;
|
|
260
|
+
// 筛选面板内的焦点(文本框 / 枚举选项)同样记下:读取开始 / 完成的重绘不该把正在输入的人踢出面板
|
|
261
|
+
const activePanel = activeEl instanceof HTMLElement ? activeEl.closest('[data-kit-filter-panel]') : null;
|
|
262
|
+
const panelFocus = activePanel !== null && activeEl instanceof HTMLElement
|
|
263
|
+
? {
|
|
264
|
+
text: activeEl.hasAttribute('data-kit-filter-text'),
|
|
265
|
+
opt: activeEl.closest('[data-kit-filter-opt]')?.getAttribute('data-kit-filter-opt') ?? null,
|
|
266
|
+
caret: activeEl instanceof HTMLInputElement ? activeEl.selectionStart : null,
|
|
267
|
+
}
|
|
268
|
+
: null;
|
|
201
269
|
root.replaceChildren();
|
|
202
270
|
let pending: { panel: HTMLElement; anchor: HTMLElement; cell: HTMLElement } | null = null;
|
|
203
271
|
const doc = root.ownerDocument;
|
|
@@ -290,6 +358,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
290
358
|
fbtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
|
291
359
|
fbtn.setAttribute('aria-label', `${kitText('soma.kit.filter_of', { label: cell.label }, root)}${value !== '' ? kitText('soma.kit.filtered', undefined, root) : ''}`);
|
|
292
360
|
fbtn.className = value !== '' ? FILTER_BUTTON_ACTIVE_CLASS : FILTER_BUTTON_CLASS;
|
|
361
|
+
setKitFace(fbtn, value !== '' ? KIT_FACE_RAISED : null); // 仅「已筛选」态有底色(primary-soft),闲置态是幽灵钮不标
|
|
293
362
|
fbtn.appendChild(funnelIcon(doc));
|
|
294
363
|
inner.appendChild(fbtn);
|
|
295
364
|
el.appendChild(inner);
|
|
@@ -297,12 +366,18 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
297
366
|
} else if (content !== null) {
|
|
298
367
|
el.appendChild(content);
|
|
299
368
|
}
|
|
369
|
+
// 字段说明:标签旁一个「i」图标钮(列头各一个 Tab 停靠点,行内容里没有;没有 help 的列不出节点,不位移布局)
|
|
370
|
+
const helpBtn = cell.help !== '' ? kitHelpButton(doc, cell.help, cell.label, root) : null;
|
|
371
|
+
if (helpBtn !== null) el.appendChild(helpBtn);
|
|
300
372
|
parent.appendChild(el);
|
|
301
373
|
}
|
|
302
374
|
// 筛选面板挂到浮层根下(不被表格外层 overflow 裁切);挂不出去(无浮层端口)退回表头格内的绝对定位
|
|
303
375
|
let panelEl: HTMLElement | null = null;
|
|
304
376
|
if (pending !== null && panelPortal !== null) {
|
|
305
377
|
const { panel, anchor, cell: hostCell } = pending;
|
|
378
|
+
filterLeave?.cancel();
|
|
379
|
+
filterLeave = null;
|
|
380
|
+
shownPanel = panel;
|
|
306
381
|
const placed = panelPortal.show(panel, anchor, FILTER_PREF, filterClassFor, {
|
|
307
382
|
onEscape: () => closeFilter(true),
|
|
308
383
|
bind: (shell) => (shellBind ? shellBind(shell) : () => {}),
|
|
@@ -312,6 +387,17 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
312
387
|
showDropdownFitted(panel, hostCell, FILTER_PANEL_BASE, 'start');
|
|
313
388
|
}
|
|
314
389
|
panelEl = panel;
|
|
390
|
+
} else if (shownPanel !== null && panelPortal !== null) {
|
|
391
|
+
if (filterLeave === null) {
|
|
392
|
+
const leaving = shownPanel;
|
|
393
|
+
const portalNow = panelPortal;
|
|
394
|
+
filterLeave = leaveAnchored(leaving, () => {
|
|
395
|
+
filterLeave = null;
|
|
396
|
+
if (shownPanel === leaving) shownPanel = null;
|
|
397
|
+
portalNow.hide(false);
|
|
398
|
+
unmarkAnchored(leaving);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
315
401
|
} else {
|
|
316
402
|
panelPortal?.hide(false);
|
|
317
403
|
}
|
|
@@ -319,10 +405,23 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
319
405
|
if (focusPanel && openCol !== null) {
|
|
320
406
|
focusPanel = false;
|
|
321
407
|
panelEl?.querySelector<HTMLElement>('input')?.focus();
|
|
408
|
+
} else if (panelFocus !== null && openCol !== null && panelEl !== null) {
|
|
409
|
+
const target = panelFocus.text
|
|
410
|
+
? panelEl.querySelector<HTMLInputElement>('[data-kit-filter-text]')
|
|
411
|
+
: panelFocus.opt !== null
|
|
412
|
+
? Array.from(panelEl.querySelectorAll<HTMLElement>('[data-kit-filter-opt]')).find((o) => o.getAttribute('data-kit-filter-opt') === panelFocus.opt) ?? null
|
|
413
|
+
: null;
|
|
414
|
+
// 枚举选项的标记挂在 label 上,焦点要落到里面的原生 input
|
|
415
|
+
(target !== null && isMark(target) ? (markInput(target) ?? target) : target)?.focus();
|
|
416
|
+
if (target instanceof HTMLInputElement && panelFocus.caret !== null) target.setSelectionRange(panelFocus.caret, panelFocus.caret);
|
|
322
417
|
} else if (focusBack !== null) {
|
|
323
418
|
const back = root.querySelector<HTMLElement>(`[data-kit-filter="${focusBack}"]`);
|
|
324
419
|
focusBack = null;
|
|
325
420
|
back?.focus();
|
|
421
|
+
} else if (focusedSort !== null) {
|
|
422
|
+
// 排序后整头重绘:焦点还给同一列的排序钮
|
|
423
|
+
const again = Array.from(root.querySelectorAll<HTMLElement>('[data-kit-sort]')).find((b) => b.getAttribute('data-kit-sort') === focusedSort);
|
|
424
|
+
again?.focus();
|
|
326
425
|
}
|
|
327
426
|
};
|
|
328
427
|
|
|
@@ -331,7 +430,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
331
430
|
const f = cell.filter!;
|
|
332
431
|
const panel = doc.createElement('div');
|
|
333
432
|
panel.setAttribute('role', 'dialog');
|
|
334
|
-
panel.setAttribute('aria-label', kitText('soma.kit.filter_of', { label: cell.label },
|
|
433
|
+
panel.setAttribute('aria-label', kitText('soma.kit.filter_of', { label: cell.label }, api.host));
|
|
335
434
|
panel.setAttribute('data-kit-filter-panel', cell.col);
|
|
336
435
|
panel.className = FILTER_PANEL_BASE;
|
|
337
436
|
if (f.kind === 'enum') {
|
|
@@ -353,9 +452,10 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
353
452
|
input.setAttribute('type', 'text');
|
|
354
453
|
input.setAttribute('data-kit-filter-text', '');
|
|
355
454
|
input.setAttribute('maxlength', String(KIT_TABLE_EXT.columnFilter.textMaxLen));
|
|
356
|
-
input.setAttribute('aria-label', kitText('soma.kit.contains_of', { label: cell.label },
|
|
357
|
-
input.setAttribute('placeholder', kitText('soma.kit.contains_ph', undefined,
|
|
455
|
+
input.setAttribute('aria-label', kitText('soma.kit.contains_of', { label: cell.label }, api.host));
|
|
456
|
+
input.setAttribute('placeholder', kitText('soma.kit.contains_ph', undefined, api.host));
|
|
358
457
|
input.className = FILTER_INPUT_CLASS;
|
|
458
|
+
setKitFace(input, KIT_FACE_FIELD);
|
|
359
459
|
draftText ??= value;
|
|
360
460
|
input.value = draftText;
|
|
361
461
|
panel.appendChild(input);
|
|
@@ -366,12 +466,14 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
366
466
|
clear.setAttribute('type', 'button');
|
|
367
467
|
clear.setAttribute('data-kit-filter-clear', '');
|
|
368
468
|
clear.className = FILTER_CLEAR_CLASS;
|
|
369
|
-
|
|
469
|
+
setKitFace(clear, KIT_FACE_RAISED);
|
|
470
|
+
clear.textContent = kitText('soma.kit.clear', undefined, api.host);
|
|
370
471
|
const apply = doc.createElement('button');
|
|
371
472
|
apply.setAttribute('type', 'button');
|
|
372
473
|
apply.setAttribute('data-kit-filter-apply', '');
|
|
373
474
|
apply.className = FILTER_APPLY_CLASS;
|
|
374
|
-
|
|
475
|
+
setKitFace(apply, KIT_FACE_RAISED);
|
|
476
|
+
apply.textContent = kitText('soma.kit.apply', undefined, api.host);
|
|
375
477
|
foot.appendChild(clear);
|
|
376
478
|
foot.appendChild(apply);
|
|
377
479
|
panel.appendChild(foot);
|
|
@@ -404,14 +506,33 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
404
506
|
}
|
|
405
507
|
}
|
|
406
508
|
}
|
|
407
|
-
|
|
509
|
+
api.emit('column_filter', { field: col, value });
|
|
408
510
|
closeFilter(true);
|
|
409
511
|
};
|
|
410
512
|
|
|
513
|
+
// 清除全部表头筛选(集合的「已筛选 · N 项条件 / 清除筛选」经区域语义事件 KIT_CLEAR_COLUMN_FILTERS_EVENT 触发;本组件是 cf_<字段> 的写者):
|
|
514
|
+
// 逐列写空、回第 1 页,抛一次 column_filter(field 空串 = 全部清除),页面按既有接线重取
|
|
515
|
+
const clearAllColumnFilters = (): void => {
|
|
516
|
+
const slice = port()?.slice('view') ?? null;
|
|
517
|
+
const cols = cellsOf(P().cells).filter((c) => c.filter !== null);
|
|
518
|
+
if (slice === null || cols.length === 0) return;
|
|
519
|
+
for (const c of cols) slice.set(null, c.filter!.param);
|
|
520
|
+
const page = (slice.get() as { page?: unknown } | undefined)?.page;
|
|
521
|
+
if (typeof page === 'number' && page > 1) {
|
|
522
|
+
try {
|
|
523
|
+
slice.set(1, 'page');
|
|
524
|
+
} catch (err) {
|
|
525
|
+
console.debug('[soma-kit] KitTableHead 无权写 page,回第 1 页交给 page 写者', err);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
api.emit('column_filter', { field: '', value: '' });
|
|
529
|
+
closeFilter(false);
|
|
530
|
+
paint();
|
|
531
|
+
};
|
|
532
|
+
|
|
411
533
|
return {
|
|
412
|
-
|
|
413
|
-
root =
|
|
414
|
-
const r = root;
|
|
534
|
+
attach(r) {
|
|
535
|
+
root = r;
|
|
415
536
|
const onClick = (event: Event): void => {
|
|
416
537
|
const target = event.target as HTMLElement | null;
|
|
417
538
|
const fbtn = target?.closest<HTMLElement>('[data-kit-filter]');
|
|
@@ -443,20 +564,26 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
443
564
|
const slice = port()?.slice('view') ?? null;
|
|
444
565
|
const next = nextSort(sortHeld(slice?.get()), key);
|
|
445
566
|
if (slice) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
567
|
+
rollback.beforeCommit();
|
|
568
|
+
committing = true;
|
|
569
|
+
try {
|
|
570
|
+
slice.set(next.sort === '' ? null : next.sort, 'sort');
|
|
571
|
+
slice.set(next.order === '' ? null : next.order, 'order');
|
|
572
|
+
// 排序一变回第 1 页(本组件是 page 路径写者;没有分页器或写权被让出时忽略)
|
|
573
|
+
const page = (slice.get() as { page?: unknown } | undefined)?.page;
|
|
574
|
+
if (typeof page === 'number' && page > 1) {
|
|
575
|
+
try {
|
|
576
|
+
slice.set(1, 'page');
|
|
577
|
+
} catch (err) {
|
|
578
|
+
// 不是 page 写者(联动场景下由 KitLinkHub 订阅 sort 变化回第 1 页):不在这里回页,但留一条 debug 记录
|
|
579
|
+
console.debug('[soma-kit] KitTableHead 无权写 page,回第 1 页交给 page 写者', err);
|
|
580
|
+
}
|
|
456
581
|
}
|
|
582
|
+
} finally {
|
|
583
|
+
committing = false;
|
|
457
584
|
}
|
|
458
585
|
}
|
|
459
|
-
|
|
586
|
+
api.emit('sort', { sort: next.sort, order: next.order });
|
|
460
587
|
paint();
|
|
461
588
|
};
|
|
462
589
|
// 筛选面板内:勾选 / 输入只改草稿;Enter 应用;Esc 关闭并回漏斗钮
|
|
@@ -511,33 +638,57 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
511
638
|
() => r.removeEventListener('input', onInput),
|
|
512
639
|
() => r.removeEventListener('keydown', onKey),
|
|
513
640
|
onOutsidePress(r, () => openCol !== null, () => closeFilter(false), (node) => portal.contains(node)),
|
|
514
|
-
() => { portal.destroy(); panelPortal = null; shellBind = null; },
|
|
641
|
+
() => { filterLeave?.cancel(); filterLeave = null; shownPanel = null; portal.destroy(); panelPortal = null; shellBind = null; },
|
|
515
642
|
];
|
|
516
643
|
const slice = port()?.slice('view');
|
|
517
|
-
if (typeof slice?.subscribe === 'function') offs.push(slice.subscribe(() =>
|
|
518
|
-
|
|
644
|
+
if (typeof slice?.subscribe === 'function') offs.push(slice.subscribe(() => api.refresh()));
|
|
645
|
+
const semantic = port();
|
|
646
|
+
if (semantic !== null && typeof semantic.onSemantic === 'function') {
|
|
647
|
+
offs.push(semantic.onSemantic((name) => { if (name === KIT_CLEAR_COLUMN_FILTERS_EVENT) clearAllColumnFilters(); }));
|
|
648
|
+
}
|
|
649
|
+
// 列宽随容器变:不再常驻观察尺寸——截断与否在悬停 / 聚焦时现量(hint-tips 委托)
|
|
650
|
+
offs.push(() => releaseReasonTipsIn(r));
|
|
651
|
+
offs.push(() => releaseStickyEdge(r));
|
|
652
|
+
return () => {
|
|
653
|
+
for (const off of offs) off();
|
|
654
|
+
offs = [];
|
|
655
|
+
root = null;
|
|
656
|
+
};
|
|
519
657
|
},
|
|
520
|
-
|
|
658
|
+
render(r) {
|
|
659
|
+
root = r;
|
|
660
|
+
// 先让回滚状态机看读状态(失败时写回切片),再按最终切片画表头
|
|
661
|
+
if (!committing) rollback.onProps();
|
|
521
662
|
paint();
|
|
522
663
|
},
|
|
523
|
-
onUnmount(): void {
|
|
524
|
-
for (const off of offs) off();
|
|
525
|
-
offs = [];
|
|
526
|
-
root = null;
|
|
527
|
-
},
|
|
528
664
|
};
|
|
529
|
-
},
|
|
665
|
+
}),
|
|
530
666
|
};
|
|
531
667
|
}
|
|
532
668
|
|
|
533
669
|
// ---------------------------------------------------------------- KitCollectionState
|
|
534
670
|
|
|
535
|
-
|
|
536
|
-
|
|
671
|
+
// 三态面板的画法(类串、插画、role / aria、重试钮)全部来自 base/state-panel.ts:集合与写死形状数据组件共用同一份,这里只管「判哪一态」
|
|
672
|
+
|
|
673
|
+
/** 重取(只读重读,不是写入):优先用 core 挂在数据对象上的 retry(非枚举),退路是数据端口的 reload(对象名);无权限(forbidden)不给重试 */
|
|
674
|
+
function retryOf(data: unknown, object: string, services: unknown): (() => unknown) | null {
|
|
675
|
+
const d = data !== null && typeof data === 'object' ? data as { retry?: unknown; readState?: unknown } : null;
|
|
676
|
+
if (d?.readState === 'forbidden') return null;
|
|
677
|
+
if (d && typeof d.retry === 'function') return () => (d.retry as () => unknown).call(data);
|
|
678
|
+
const port = (services as { data?: { reload?: (names?: string[]) => unknown } } | undefined)?.data;
|
|
679
|
+
if (object !== '' && port && typeof port.reload === 'function') return () => port.reload!([object]);
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/** 标题旁(meta 形态)的根类:辅助文字,一行排下「共 N 条」与「已筛选 · N 项条件 清除」 */
|
|
684
|
+
const META_ROOT_CLASS = 'me-auto flex flex-wrap items-baseline gap-x-3 text-sm text-fg-muted';
|
|
685
|
+
const META_HINT_CLASS = 'inline-flex items-baseline gap-2';
|
|
686
|
+
const META_HINT_CLEAR_CLASS = kitTextActionRecipe('primary');
|
|
687
|
+
const FILTERED_EMPTY_CLEAR_CLASS = kitTextActionRecipe('primary');
|
|
537
688
|
|
|
538
|
-
export const KIT_COLLECTION_STATE_CLASS_CANDIDATES: readonly string[] = [
|
|
539
|
-
|
|
540
|
-
].flatMap((s) => s.split(/\s+/).filter((c) => c !== ''))
|
|
689
|
+
export const KIT_COLLECTION_STATE_CLASS_CANDIDATES: readonly string[] = ['hidden']
|
|
690
|
+
.concat(KIT_STATE_PANEL_CLASS_CANDIDATES, KIT_SKELETON_CLASS_CANDIDATES, KIT_ILLUSTRATION_CLASS_CANDIDATES,
|
|
691
|
+
[META_ROOT_CLASS, META_HINT_CLASS, META_HINT_CLEAR_CLASS, FILTERED_EMPTY_CLEAR_CLASS].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')));
|
|
541
692
|
|
|
542
693
|
function pick(data: unknown, path: string): unknown {
|
|
543
694
|
let cur: unknown = data;
|
|
@@ -568,6 +719,29 @@ export function singleStatus(data: unknown): KitCollectionStatus {
|
|
|
568
719
|
return 'ready';
|
|
569
720
|
}
|
|
570
721
|
|
|
722
|
+
// ---------------------------------------------------------------- 集合的「被筛选」状态(空态区分 / 标题旁提示)
|
|
723
|
+
|
|
724
|
+
/** 一个筛选值算不算「设了条件」:空串 / null / 空数组 / 全空的对象(日期区间)不算;数字与布尔(含 false)算 */
|
|
725
|
+
function isFilledCondition(v: unknown): boolean {
|
|
726
|
+
if (v === null || v === undefined) return false;
|
|
727
|
+
if (typeof v === 'string') return v.trim() !== '';
|
|
728
|
+
if (Array.isArray(v)) return v.some(isFilledCondition);
|
|
729
|
+
if (typeof v === 'object') return Object.values(v as Record<string, unknown>).some(isFilledCondition);
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* 当前生效的筛选条件数(纯函数):筛选栏的 filter 切片里有值的键(含默认筛选值)+ 表头筛选在 view 切片里有值的 cf_<字段> 键。
|
|
735
|
+
* 分页 / 排序等其它 view 键不算条件。
|
|
736
|
+
*/
|
|
737
|
+
export function activeFilterConditions(filter: unknown, view: unknown, columnParams: readonly string[]): { form: number; columns: number; total: number } {
|
|
738
|
+
const f = filter !== null && typeof filter === 'object' ? filter as Record<string, unknown> : {};
|
|
739
|
+
const v = view !== null && typeof view === 'object' ? view as Record<string, unknown> : {};
|
|
740
|
+
const form = Object.values(f).filter(isFilledCondition).length;
|
|
741
|
+
const columns = columnParams.filter((k) => isFilledCondition(v[k])).length;
|
|
742
|
+
return { form, columns, total: form + columns };
|
|
743
|
+
}
|
|
744
|
+
|
|
571
745
|
export function createKitCollectionState(): SomaComponentDefinition {
|
|
572
746
|
return {
|
|
573
747
|
contract: {
|
|
@@ -576,78 +750,201 @@ export function createKitCollectionState(): SomaComponentDefinition {
|
|
|
576
750
|
props: {
|
|
577
751
|
data: { type: 'object', default: {}, desc: '列表对象整体(page.data.<对象>);取不到行数组读作加载中' },
|
|
578
752
|
rows: { type: 'array', default: [], desc: '行数组(只用于触发重绘)' },
|
|
579
|
-
config: { type: 'object', default: {}, desc: '{ rowsPath, errorPath, loading, empty, error, skeleton?, mode? }:响应里行数组 / 错误文案的路径与三态文案;skeleton = { kind, cols?, listClass? } 时加载态画骨架屏;mode: single = 单对象视图(只判加载,并藏起紧随其后的 data-kit-skeleton-body
|
|
753
|
+
config: { type: 'object', default: {}, desc: '{ rowsPath, errorPath, loading, empty, error, skeleton?, mode?, scope?, filterId?, columnParams?, totalPath?, count?, hint? }:响应里行数组 / 错误文案的路径与三态文案;skeleton = { kind, cols?, listClass? } 时加载态画骨架屏;mode: single = 单对象视图(只判加载,并藏起紧随其后的 data-kit-skeleton-body);mode: errorOnly = 页面关闭了内置三态(state: false),只在读状态 error / forbidden 或错误路径有文案时显示失败面板(含重试),加载 / 空态 / 骨架一律隐藏;mode: meta = 标题旁的辅助文字(count: true 显示「共 N 条」,N 取 totalPath 的数字、没有就取行数;hint: true 在有生效筛选时显示「已筛选 · N 项条件」与「清除」);scope = 区域作用域 id(给了就按 filter / view 切片判断集合是否处于被筛选状态:空态改显示「没有符合条件的结果」+「清除筛选」);filterId = 筛选栏的宿主锚点(清除时优先点它的「重置」,表单输入同步清空);columnParams = 表头筛选写入 view 切片的键' },
|
|
580
754
|
class: CLASS_PROP,
|
|
581
755
|
},
|
|
582
|
-
emits: {
|
|
756
|
+
emits: {
|
|
757
|
+
clear_filter: {
|
|
758
|
+
payload: { values: { type: 'object', desc: '恒为空对象:清除筛选栏的全部条件(找不到筛选栏的「重置」钮时的兜底,页面接 SCOPE | set filter from:values,与筛选栏重置同一条管道)' } },
|
|
759
|
+
desc: '点「清除筛选」',
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
scope: { slices: ['filter', 'view'] },
|
|
583
763
|
},
|
|
764
|
+
services: ['data', 'region'],
|
|
584
765
|
templateHtml: '<div data-soma-id="root" class="hidden"><div data-soma-id="box" role="status"></div></div>',
|
|
585
|
-
controllerFactory: (
|
|
586
|
-
const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
587
|
-
let root: HTMLElement | null = null;
|
|
766
|
+
controllerFactory: createKitController((api) => {
|
|
588
767
|
let box: HTMLElement | null = null;
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
768
|
+
// 「重试」由键盘触发后置位:面板再次渲染出重试按钮时把焦点还给它
|
|
769
|
+
let retryByKeyboard = false;
|
|
770
|
+
const cfgOf = (): Record<string, unknown> => {
|
|
771
|
+
const c = api.props().config;
|
|
772
|
+
return c !== null && typeof c === 'object' ? c as Record<string, unknown> : {};
|
|
773
|
+
};
|
|
774
|
+
const regionPort = (): SomaRegionPort | null => {
|
|
775
|
+
const scope = str(cfgOf().scope);
|
|
776
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
777
|
+
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
778
|
+
};
|
|
779
|
+
const columnParamsOf = (): string[] => (Array.isArray(cfgOf().columnParams) ? (cfgOf().columnParams as unknown[]).filter((k): k is string => typeof k === 'string' && k !== '') : []);
|
|
780
|
+
/** 当前生效的筛选条件数(没有区域作用域 = 0) */
|
|
781
|
+
const activeNow = (): { form: number; columns: number; total: number } => {
|
|
782
|
+
const port = regionPort();
|
|
783
|
+
if (port === null) return { form: 0, columns: 0, total: 0 };
|
|
784
|
+
return activeFilterConditions(port.slice('filter')?.get(), port.slice('view')?.get(), columnParamsOf());
|
|
785
|
+
};
|
|
786
|
+
/** 找筛选栏里「重置」钮的原生按钮(Button 组件根或其内部按钮) */
|
|
787
|
+
const findFormReset = (doc: Document): HTMLElement | null => {
|
|
788
|
+
const id = str(cfgOf().filterId);
|
|
789
|
+
if (id === '') return null;
|
|
790
|
+
const formHost = [...doc.querySelectorAll<HTMLElement>('[data-soma-id], [data-soma-scoped-id]')]
|
|
791
|
+
.find((el) => el.getAttribute('data-soma-id') === id || el.getAttribute('data-soma-scoped-id') === id);
|
|
792
|
+
if (!formHost) return null;
|
|
793
|
+
return formHost.querySelector<HTMLElement>('button[data-soma-id="kit_reset"], button[data-soma-scoped-id="kit_reset"], [data-soma-id="kit_reset"] button, [data-soma-scoped-id="kit_reset"] button');
|
|
794
|
+
};
|
|
795
|
+
/** 清除筛选:筛选栏优先点它自己的「重置」(同一条事件通道,表单输入同步清空),找不到才抛 clear_filter;表头筛选经区域语义事件交 KitTableHead 清 */
|
|
796
|
+
const clearFilters = (doc: Document): void => {
|
|
797
|
+
const active = activeNow();
|
|
798
|
+
if (active.form > 0) {
|
|
799
|
+
const reset = findFormReset(doc);
|
|
800
|
+
if (reset !== null) reset.click();
|
|
801
|
+
else api.emit('clear_filter', { values: {} });
|
|
602
802
|
}
|
|
603
|
-
if (
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
803
|
+
if (active.columns > 0) regionPort()?.emit(KIT_CLEAR_COLUMN_FILTERS_EVENT, {});
|
|
804
|
+
};
|
|
805
|
+
/** meta 形态:标题旁的「共 N 条」与「已筛选 · N 项条件 清除」;没有可显示的就整体隐藏 */
|
|
806
|
+
const paintMeta = (root: HTMLElement, target: HTMLElement, p: Record<string, unknown>, cfg: Record<string, unknown>, status: KitCollectionStatus): void => {
|
|
807
|
+
const doc = target.ownerDocument;
|
|
808
|
+
target.removeAttribute('role');
|
|
809
|
+
target.removeAttribute('data-kit-state');
|
|
810
|
+
target.className = '';
|
|
811
|
+
target.replaceChildren();
|
|
812
|
+
let shown = 0;
|
|
813
|
+
if (cfg.count === true && status === 'ready') {
|
|
814
|
+
const rows = pick(p.data, str(cfg.rowsPath, 'result.rows'));
|
|
815
|
+
const total = cfg.totalPath === undefined ? undefined : pick(p.data, str(cfg.totalPath));
|
|
816
|
+
const n = typeof total === 'number' && Number.isFinite(total) && Array.isArray(rows) && total >= rows.length ? total : Array.isArray(rows) ? rows.length : 0;
|
|
817
|
+
const span = doc.createElement('span');
|
|
818
|
+
span.setAttribute('data-kit-count', '');
|
|
819
|
+
span.textContent = kitText('soma.kit.total', { n }, root);
|
|
820
|
+
target.appendChild(span);
|
|
821
|
+
shown += 1;
|
|
607
822
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
box.className = STATE_BOX_CLASS;
|
|
624
|
-
box.setAttribute('role', 'status');
|
|
625
|
-
box.removeAttribute('aria-busy');
|
|
626
|
-
box.removeAttribute('aria-label');
|
|
627
|
-
box.textContent = str(cfg.empty, kitText('soma.kit.empty', undefined, root));
|
|
628
|
-
} else {
|
|
629
|
-
box.className = STATE_ERROR_BOX_CLASS;
|
|
630
|
-
box.setAttribute('role', 'alert');
|
|
631
|
-
box.removeAttribute('aria-busy');
|
|
632
|
-
box.removeAttribute('aria-label');
|
|
633
|
-
box.textContent = str(cfg.error) !== '' ? str(cfg.error) : message !== '' ? message : kitText('soma.kit.load_failed', undefined, root);
|
|
823
|
+
const active = cfg.hint === true ? activeNow() : { form: 0, columns: 0, total: 0 };
|
|
824
|
+
if (active.total > 0) {
|
|
825
|
+
const hint = doc.createElement('span');
|
|
826
|
+
hint.setAttribute('data-kit-filter-hint', '');
|
|
827
|
+
hint.className = META_HINT_CLASS;
|
|
828
|
+
const text = doc.createElement('span');
|
|
829
|
+
text.textContent = kitText('soma.kit.filter_active', { n: active.total }, root);
|
|
830
|
+
const clear = doc.createElement('button');
|
|
831
|
+
clear.setAttribute('type', 'button');
|
|
832
|
+
clear.setAttribute('data-kit-filter-clear-all', '');
|
|
833
|
+
clear.className = META_HINT_CLEAR_CLASS;
|
|
834
|
+
clear.textContent = kitText('soma.kit.clear', undefined, root);
|
|
835
|
+
hint.append(text, clear);
|
|
836
|
+
target.appendChild(hint);
|
|
837
|
+
shown += 1;
|
|
634
838
|
}
|
|
839
|
+
root.className = shown === 0 ? joinClass('hidden', p.class) : joinClass(META_ROOT_CLASS, p.class);
|
|
635
840
|
};
|
|
636
|
-
|
|
637
841
|
return {
|
|
638
|
-
|
|
639
|
-
root = findRoot(ctx.host);
|
|
842
|
+
attach(root) {
|
|
640
843
|
box = root.querySelector<HTMLElement>('[data-soma-scoped-id="box"]') ?? root.querySelector<HTMLElement>('[data-soma-id="box"]');
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
844
|
+
const offs: Array<() => void> = [];
|
|
845
|
+
// 点「清除筛选」(空态面板里与标题旁提示里同一个入口):事件委托在根上,面板重画不丢
|
|
846
|
+
const onClick = (event: Event): void => {
|
|
847
|
+
const target = event.target as HTMLElement | null;
|
|
848
|
+
if (target?.closest('[data-kit-filter-clear-all]') && root.contains(target)) clearFilters(root.ownerDocument);
|
|
849
|
+
};
|
|
850
|
+
root.addEventListener('click', onClick);
|
|
851
|
+
offs.push(() => root.removeEventListener('click', onClick));
|
|
852
|
+
// 筛选 / 表头筛选切片一变,空态文案与标题旁提示随之重绘
|
|
853
|
+
const port = regionPort();
|
|
854
|
+
if (port !== null) {
|
|
855
|
+
for (const name of ['filter', 'view'] as const) {
|
|
856
|
+
const slice = port.slice(name);
|
|
857
|
+
if (typeof slice?.subscribe === 'function') offs.push(slice.subscribe(() => api.refresh()));
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return () => { for (const off of offs) off(); box = null; };
|
|
645
861
|
},
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
862
|
+
render(root, p) {
|
|
863
|
+
if (!box) return;
|
|
864
|
+
// 重试钮正持有焦点(Tab 停在上面、没点击):无关对象的重取也会让本组件重绘并重建钮,重建后把焦点还给新钮
|
|
865
|
+
const activeAtStart = box.ownerDocument.activeElement;
|
|
866
|
+
const hadRetryFocus = activeAtStart instanceof HTMLElement && box.contains(activeAtStart) && activeAtStart.hasAttribute('data-kit-state-retry');
|
|
867
|
+
const cfg = p.config !== null && typeof p.config === 'object' ? p.config as Record<string, unknown> : {};
|
|
868
|
+
const single = str(cfg.mode) === 'single';
|
|
869
|
+
let { status, message }: { status: KitCollectionStatus; message: string } = single
|
|
870
|
+
? { status: singleStatus(p.data), message: '' }
|
|
871
|
+
: collectionStatus(p.data, str(cfg.rowsPath, 'result.rows'), str(cfg.errorPath, 'result.error'));
|
|
872
|
+
// core 的读状态(不可枚举的 readState / errorMessage)与行数组、错误路径各自独立,按先后顺序合成:
|
|
873
|
+
const readMeta = !single && p.data !== null && typeof p.data === 'object' ? p.data as { readState?: unknown; errorMessage?: unknown } : null;
|
|
874
|
+
const readState = readMeta?.readState;
|
|
875
|
+
if (readState === 'error' || readState === 'forbidden') {
|
|
876
|
+
// ① 读状态失败:不论取没取到行数组(ready / empty / loading)一律判失败——重取失败但旧行还在、或取不到行数组都不再停在加载态;
|
|
877
|
+
// 每次重取失败 core 只更新 errorMessage / readState,错误路径上的占位文案停在第一次失败,所以以最新消息为准(config.error 仍最优先,见下)
|
|
878
|
+
const wasError = status === 'error';
|
|
879
|
+
status = 'error';
|
|
880
|
+
if (typeof readMeta?.errorMessage === 'string' && (!wasError || readMeta.errorMessage !== '')) message = readMeta.errorMessage;
|
|
881
|
+
else if (!wasError) message = '';
|
|
882
|
+
} else if (readState === 'loading') {
|
|
883
|
+
// ② 失败后点重试:错误路径上的失败标记不会清,重试进行中按加载态呈现,不再显示失败与重试按钮;
|
|
884
|
+
// 上一轮是空数组、这一轮显式重取,同样给加载反馈而不是停在「暂无数据」
|
|
885
|
+
if (status === 'error' || status === 'empty') { status = 'loading'; message = ''; }
|
|
886
|
+
}
|
|
887
|
+
// meta 形态(标题旁的辅助文字):只画「共 N 条」与「已筛选」提示,不画三态面板
|
|
888
|
+
if (str(cfg.mode) === 'meta') {
|
|
889
|
+
paintMeta(root, box, p, cfg, status);
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
// 单对象视图:加载态藏起紧随其后的内容体(空值内容在骨架下面没有意义)
|
|
893
|
+
if (single) {
|
|
894
|
+
const body = api.host.nextElementSibling;
|
|
895
|
+
if (body && body.hasAttribute('data-kit-skeleton-body')) body.classList.toggle('hidden', status === 'loading');
|
|
896
|
+
}
|
|
897
|
+
// 键盘重试的归还标记:旧行还在时重取期间 status 会回到 ready / empty,那是读取进行中、不能清;读完(读状态不是 loading)才清
|
|
898
|
+
if ((status === 'ready' || status === 'empty') && readState !== 'loading') retryByKeyboard = false;
|
|
899
|
+
// errorOnly(state: false):只有失败才画面板,加载 / 空态 / 就绪一律隐藏
|
|
900
|
+
const errorOnly = str(cfg.mode) === 'errorOnly';
|
|
901
|
+
if (status === 'ready' || (errorOnly && status !== 'error')) {
|
|
902
|
+
root.className = joinClass('hidden', p.class);
|
|
903
|
+
box.textContent = '';
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
root.className = joinClass('', p.class);
|
|
907
|
+
if (status === 'loading') {
|
|
908
|
+
const skeleton = skeletonConfigOf(cfg.skeleton);
|
|
909
|
+
paintKitStatePanel(box, 'loading', {
|
|
910
|
+
text: str(cfg.loading, kitText('soma.kit.loading', undefined, root)),
|
|
911
|
+
skeleton: skeleton !== null ? buildSkeleton(box.ownerDocument, skeleton) : null,
|
|
912
|
+
});
|
|
913
|
+
} else if (status === 'empty') {
|
|
914
|
+
// 空态区分「筛选无结果」与「无数据」:集合处于被筛选状态(筛选栏 / 表头筛选有生效条件)时,
|
|
915
|
+
// 显示「没有符合条件的结果」+「清除筛选」,不是「暂无数据」;页面自写的 empty 文案只用于没有筛选的空态
|
|
916
|
+
if (activeNow().total > 0) {
|
|
917
|
+
paintKitStatePanel(box, 'empty', { text: kitText('soma.kit.empty_filtered', undefined, root) });
|
|
918
|
+
const clear = box.ownerDocument.createElement('button');
|
|
919
|
+
clear.setAttribute('type', 'button');
|
|
920
|
+
clear.setAttribute('data-kit-filter-clear-all', '');
|
|
921
|
+
clear.className = FILTERED_EMPTY_CLEAR_CLASS;
|
|
922
|
+
clear.textContent = kitText('soma.kit.clear_filter', undefined, root);
|
|
923
|
+
box.appendChild(clear);
|
|
924
|
+
} else {
|
|
925
|
+
paintKitStatePanel(box, 'empty', { text: str(cfg.empty, kitText('soma.kit.empty', undefined, root)) });
|
|
926
|
+
}
|
|
927
|
+
} else {
|
|
928
|
+
const doc = box.ownerDocument;
|
|
929
|
+
// 内联错误只给人话:「HTTP 500:」这类协议前缀拆下来放悬停提示(data-kit-tip),可见文案只剩原因(拆完为空则回退通用文案)
|
|
930
|
+
const parsed = splitHttpErrorPrefix(message);
|
|
931
|
+
const btn = paintKitStatePanel(box, 'error', {
|
|
932
|
+
text: str(cfg.error) !== '' ? str(cfg.error) : parsed.text !== '' ? parsed.text : kitText('soma.kit.load_failed', undefined, root),
|
|
933
|
+
...(parsed.code !== '' ? { tip: parsed.code } : {}),
|
|
934
|
+
retry: retryOf(p.data, str(cfg.object), api.services),
|
|
935
|
+
// 键盘触发的 click(detail 为 0):面板随即切到加载态、按钮被销毁,焦点会丢;记下来,重试再次失败时还给新按钮
|
|
936
|
+
onKeyboardRetry: () => { retryByKeyboard = true; },
|
|
937
|
+
});
|
|
938
|
+
if (btn !== null && (retryByKeyboard || hadRetryFocus)) {
|
|
939
|
+
const active = doc.activeElement;
|
|
940
|
+
if (active === null || active === doc.body) {
|
|
941
|
+
btn.focus({ preventScroll: true });
|
|
942
|
+
retryByKeyboard = false;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
649
946
|
},
|
|
650
947
|
};
|
|
651
|
-
},
|
|
948
|
+
}),
|
|
652
949
|
};
|
|
653
950
|
}
|