soma-kit 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/data/tree-table.ts
CHANGED
|
@@ -15,40 +15,48 @@
|
|
|
15
15
|
// 大数据:可见行数超过 `tree.windowThreshold` 时先画前 N 行,余下由「显示更多」每次追加 windowBatch 行(阈值与批量读设计真源)。
|
|
16
16
|
// 参考老 soma-ui:data-table 的树表(缩进、整体展开 / 收起、接口子项默认折叠的初态规则)、virtual-list 的窗口思路。
|
|
17
17
|
|
|
18
|
-
import type {
|
|
18
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
19
19
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
20
20
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
21
21
|
import { TAG_CLASS } from '../base/tag';
|
|
22
22
|
import { permissionCheckerOf } from '../base/permission-gate';
|
|
23
23
|
import { KIT_CHECK_CLASS_CANDIDATES, attachMarkEvents, createCheck, setMarkLabel } from '../base/check-core';
|
|
24
|
-
import { CLASS_PROP, bool, displayOf, joinClass, optionsOf, str, toneOf } from '../base/shared';
|
|
24
|
+
import { CLASS_PROP, bool, createKitController, displayOf, joinClass, optionsOf, str, toneOf } from '../base/shared';
|
|
25
25
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
26
|
+
import { setKitFace } from '../recipes';
|
|
26
27
|
import { kitIcon } from '../base/icons';
|
|
27
28
|
import { KIT_TREE_TABLE } from '../object-renderer/defaults';
|
|
28
|
-
import {
|
|
29
|
+
import { KIT_PART_TABLE_ROW } from '../recipes/table-row';
|
|
30
|
+
import { ROW_ACTION_BUTTON_CLASS, rowBusyName, removeKeyOf } from '../object-renderer/table-actions';
|
|
31
|
+
import { KIT_ROW_TONE_CLASS, rowToneClass } from '../object-renderer/view-binding';
|
|
32
|
+
import { isKitActionBusy, onKitActionBusy } from '../base/action-busy';
|
|
29
33
|
import { provideCtxRows } from './context-menu';
|
|
30
|
-
import {
|
|
34
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
35
|
+
import { unwrapEnvelope, envelopeMessage, getKitAppEnvelope } from '../shared/envelope';
|
|
31
36
|
|
|
32
37
|
// ── 类串表(整串字面量;候选类汇总在底部) ──
|
|
33
38
|
|
|
34
39
|
const ROOT_CLASS = 'flex flex-col';
|
|
35
|
-
const TOOLBAR_CLASS = 'flex items-center gap-3 px-4 py-2 border-b border-border-subtle';
|
|
36
|
-
const TOOLBAR_BUTTON_CLASS = 'inline-flex items-center rounded-md px-1 text-xs text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
37
40
|
const GRID_CLASS = 'flex flex-col';
|
|
38
41
|
const INDENT_CELL_CLASS = 'flex min-w-0 items-center gap-1';
|
|
39
42
|
const SPACER_CLASS = 'inline-block h-5 w-5 shrink-0';
|
|
40
|
-
const TOGGLE_CLASS = 'inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
+
const TOGGLE_CLASS = 'hit-area inline-flex h-5 w-5 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
44
|
+
// 单元格文字:块级 + min-w-0 + 单行省略(长 ID 不再压到相邻列);被截断时悬停出全文提示(表壳带 data-kit-tips,由 base/hint-tips 按需挂)
|
|
45
|
+
const TEXT_CLASS = 'block min-w-0 truncate text-sm text-fg';
|
|
46
|
+
const ACTIONS_CELL_CLASS = 'flex flex-nowrap items-center gap-x-4 whitespace-nowrap';
|
|
43
47
|
const MORE_WRAP_CLASS = 'flex items-center justify-center px-4 py-3';
|
|
44
|
-
const MORE_BUTTON_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
48
|
+
const MORE_BUTTON_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
45
49
|
const ROW_FOCUS_CLASS = 'cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
46
50
|
|
|
51
|
+
/** 工具位链接的原始类串(显隐切类名时据此还原) */
|
|
52
|
+
const CONTROL_CLASS = new WeakMap<HTMLElement, string>();
|
|
53
|
+
|
|
47
54
|
export const KIT_TREE_TABLE_CLASS_CANDIDATES: readonly string[] = Object.freeze([...new Set([
|
|
48
|
-
ROOT_CLASS,
|
|
55
|
+
ROOT_CLASS, GRID_CLASS, INDENT_CELL_CLASS, SPACER_CLASS, TOGGLE_CLASS, TEXT_CLASS,
|
|
49
56
|
...KIT_CHECK_CLASS_CANDIDATES, ACTIONS_CELL_CLASS, MORE_WRAP_CLASS, MORE_BUTTON_CLASS, ROW_FOCUS_CLASS,
|
|
50
|
-
...Object.values(
|
|
57
|
+
...Object.values(ROW_ACTION_BUTTON_CLASS),
|
|
51
58
|
...Object.values(TAG_CLASS.md),
|
|
59
|
+
...Object.values(KIT_ROW_TONE_CLASS),
|
|
52
60
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')))].sort());
|
|
53
61
|
|
|
54
62
|
// ── 数据规整纯函数:建树 / 可见行 / 初态 / 列与行操作解析 ──
|
|
@@ -285,13 +293,17 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
285
293
|
tree: { type: 'object', default: {}, desc: '层级配置(KitTreeIR):idField / parentField / childrenField / orderField / indentField / defaultExpand / childrenFrom / hasChildrenField / expandAll / windowThreshold' },
|
|
286
294
|
rowClass: { type: 'string', default: '', desc: '行容器类(栅格 + 内边距 + 悬停 / 选中高亮)' },
|
|
287
295
|
stripeClass: { type: 'string', default: '', desc: '斑马纹类(偶数行)' },
|
|
296
|
+
rowToneField: { type: 'string', default: '', desc: '行样式档位取自的行字段名(view.list.rowTone: row.<字段>):该字段取值属于语法真源 viewObject.rowState.toneTiers 闭集时,行容器加该档位的类串;空 / 不在闭集不加类;每次重绘整行重建,不残留旧档位' },
|
|
288
297
|
select: { type: 'string', default: 'none', desc: '勾选列 none / single / multi' },
|
|
289
298
|
selectClass: { type: 'string', default: '', desc: '勾选列跨度类' },
|
|
290
299
|
selected: { type: 'array', default: [], desc: '已选行数组(协调组件 focus 切片镜像)' },
|
|
291
300
|
keyField: { type: 'string', default: '', desc: '行主键字段名(比对已选行)' },
|
|
301
|
+
removeScope: { type: 'string', default: '', desc: '行在途判断用(内置删除与具名行动作共用):协调组件的作用域 id;本行在途(经忙闲通道登记)时,本行全部操作置灰、行挂 aria-busy、不抛行点击 / 勾选 / 行操作;空 = 不读' },
|
|
302
|
+
removeObject: { type: 'string', default: '', desc: '行在途判断用(内置删除与具名行动作共用):对象名,须与协调组件的主对象同名,空 = 不读;非空时行操作载荷附带 kit_object' },
|
|
303
|
+
removeKeyField: { type: 'string', default: '', desc: '行在途判断用(内置删除与具名行动作共用):行主键字段名(与协调组件登记忙态的键同一规则:显式主键 → id → 空串;独立于 keyField,不受选择影响)' },
|
|
292
304
|
actions: { type: 'array', default: [], desc: '行操作 [{ id, name, tone?, builtin?, target?, permission? }]' },
|
|
293
305
|
actionsClass: { type: 'string', default: '', desc: '操作列跨度类' },
|
|
294
|
-
pickOnRow: { type: 'boolean', default: false, desc: '点击行抛
|
|
306
|
+
pickOnRow: { type: 'boolean', default: false, desc: '点击行抛 row_pick(builtin: select)' },
|
|
295
307
|
bordered: { type: 'boolean', default: true, desc: '是否显示边框(collection.bordered: false 时移除边框类)' },
|
|
296
308
|
expandAllLabel: { type: 'string', default: '', desc: '工具条按钮文案' },
|
|
297
309
|
collapseAllLabel: { type: 'string', default: '', desc: '工具条按钮文案' },
|
|
@@ -309,25 +321,28 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
309
321
|
},
|
|
310
322
|
desc: '勾选列变化(同 KitTableActions.row_select)',
|
|
311
323
|
},
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
},
|
|
321
|
-
|
|
324
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.row, {
|
|
325
|
+
kit_action: { type: 'string', desc: '动作判别键' },
|
|
326
|
+
id: { type: 'string', desc: '动作 id' },
|
|
327
|
+
name: { type: 'string', desc: '动作显示名' },
|
|
328
|
+
builtin: { type: 'string', desc: '内置动作名' },
|
|
329
|
+
target: { type: 'string', desc: '目标浮层' },
|
|
330
|
+
row: { type: 'object', desc: '当前行' },
|
|
331
|
+
kit_object: { type: 'string', desc: '对象名(removeObject 非空时附带,协调组件据此认出本表所属对象)' },
|
|
332
|
+
kit_row_busy: { type: 'string', desc: '本行在途通道名(removeScope 与 removeObject 都非空时附带;动作执行器在具名行动作执行期间登记)' },
|
|
333
|
+
}, '点击行操作;载荷自带整行(同 KitTableActions.row_action_<序号>)'),
|
|
334
|
+
row_pick: {
|
|
335
|
+
payload: { kit_action: { type: 'string' }, id: { type: 'string' }, builtin: { type: 'string' }, row: { type: 'object', desc: '当前行' }, kit_object: { type: 'string', desc: '对象名(removeObject 非空时附带)' } },
|
|
336
|
+
desc: '点击行(pickOnRow);载荷自带整行(同 KitTableActions.row_pick)',
|
|
322
337
|
},
|
|
323
338
|
},
|
|
324
339
|
keyboard: { layout: 'tree', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
325
340
|
},
|
|
326
341
|
services: ['permission', 'http'],
|
|
327
342
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
328
|
-
controllerFactory: (
|
|
329
|
-
const P = (): Rec =>
|
|
330
|
-
const check = permissionCheckerOf(
|
|
343
|
+
controllerFactory: createKitController((api) => {
|
|
344
|
+
const P = (): Rec => api.props();
|
|
345
|
+
const check = permissionCheckerOf(api as unknown as any);
|
|
331
346
|
let root: HTMLElement | null = null;
|
|
332
347
|
let alive = false;
|
|
333
348
|
let forest: TreeNode[] = [];
|
|
@@ -378,7 +393,7 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
378
393
|
...(n.children.length > 0 || n.lazy ? { expanded: open.has(n.key) } : {}),
|
|
379
394
|
}));
|
|
380
395
|
|
|
381
|
-
const doc = (): Document => (root ??
|
|
396
|
+
const doc = (): Document => (root ?? api.host).ownerDocument;
|
|
382
397
|
const mk = (tag: string, cls: string, text?: string): HTMLElement => {
|
|
383
398
|
const el = doc().createElement(tag);
|
|
384
399
|
if (cls !== '') el.className = cls;
|
|
@@ -394,7 +409,7 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
394
409
|
|
|
395
410
|
const loadChildren = async (node: TreeNode): Promise<void> => {
|
|
396
411
|
const from = cfg().childrenFrom;
|
|
397
|
-
const http = (
|
|
412
|
+
const http = (api.services as { http?: HttpPort } | undefined)?.http;
|
|
398
413
|
if (!from || !http || loading.has(node.key)) return;
|
|
399
414
|
loading.add(node.key);
|
|
400
415
|
failed.delete(node.key);
|
|
@@ -404,8 +419,9 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
404
419
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
405
420
|
const apiPath = baseURL && baseURL !== '/' && from.api.startsWith(`${baseURL}/`) ? from.api.slice(baseURL.length) : from.api;
|
|
406
421
|
const res = await http.get<unknown>(apiPath, { params: { [from.param]: node.key } });
|
|
407
|
-
const
|
|
408
|
-
|
|
422
|
+
const env = getKitAppEnvelope(api.host);
|
|
423
|
+
const unwrapped = unwrapEnvelope(res, env);
|
|
424
|
+
if (!unwrapped.ok) throw new Error(envelopeMessage(res, env) || kitText('soma.kit.tt_children_failed', undefined, api.host));
|
|
409
425
|
const payload = unwrapped.data;
|
|
410
426
|
let list: unknown;
|
|
411
427
|
if (Array.isArray(payload)) {
|
|
@@ -445,13 +461,34 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
445
461
|
paint();
|
|
446
462
|
};
|
|
447
463
|
|
|
464
|
+
/** 本行删除在途:协调组件经忙闲通道登记(作用域 + 对象 + 行主键三段),与 KitTableActions 同一条规则 */
|
|
465
|
+
const rowBusy = (row: Rec): boolean => {
|
|
466
|
+
const p = P();
|
|
467
|
+
const scope = str(p.removeScope);
|
|
468
|
+
const object = str(p.removeObject);
|
|
469
|
+
return scope !== '' && object !== '' && isKitActionBusy(rowBusyName(scope, object, removeKeyOf(row, str(p.removeKeyField))));
|
|
470
|
+
};
|
|
471
|
+
/** 行动作载荷附带的对象名(removeObject 非空才有) */
|
|
472
|
+
const objectPayload = (): Rec => {
|
|
473
|
+
const object = str(P().removeObject);
|
|
474
|
+
return object !== '' ? { kit_object: object } : {};
|
|
475
|
+
};
|
|
476
|
+
/** 行动作载荷附带的本行在途通道名(removeScope 与 removeObject 都非空才有;动作执行器在具名行动作执行期间登记) */
|
|
477
|
+
const rowBusyPayload = (row: Rec): Rec => {
|
|
478
|
+
const p = P();
|
|
479
|
+
const scope = str(p.removeScope);
|
|
480
|
+
const object = str(p.removeObject);
|
|
481
|
+
return scope !== '' && object !== '' ? { kit_row_busy: rowBusyName(scope, object, removeKeyOf(row, str(p.removeKeyField))) } : {};
|
|
482
|
+
};
|
|
448
483
|
const emitSelect = (row: Rec, checked: boolean): void => {
|
|
449
484
|
const mode = str(P().select, 'none');
|
|
450
485
|
if (mode !== 'single' && mode !== 'multi') return;
|
|
451
|
-
|
|
486
|
+
if (rowBusy(row)) return; // 删除在途:不抛勾选
|
|
487
|
+
api.emit('row_select', { row, checked, mode, keyField: str(P().keyField) });
|
|
452
488
|
};
|
|
453
489
|
const emitPick = (row: Rec): void => {
|
|
454
|
-
|
|
490
|
+
if (rowBusy(row)) return; // 删除在途:不抛行点击
|
|
491
|
+
api.emit('row_pick', { kit_action: 'select', id: 'select', name: '', builtin: 'select', target: '', row, ...objectPayload() });
|
|
455
492
|
};
|
|
456
493
|
const isPicked = (row: Rec): boolean => {
|
|
457
494
|
const sel = P().selected;
|
|
@@ -485,7 +522,7 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
485
522
|
/** 单元格内容:Tag(选项自带 tone)或 Text */
|
|
486
523
|
const cellContent = (cell: CellDef, row: Rec): HTMLElement => {
|
|
487
524
|
const placeholder = str(cell.props.placeholder);
|
|
488
|
-
const { text, option } = displayOf(row[cell.field], optionsOf(cell.props.options), str(cell.props.format), str(cell.props.locale, kitLocaleAt(
|
|
525
|
+
const { text, option } = displayOf(row[cell.field], optionsOf(cell.props.options), str(cell.props.format), str(cell.props.locale, kitLocaleAt(api.host) || 'zh-CN'), placeholder);
|
|
489
526
|
if (cell.component === 'Tag' && text !== '') {
|
|
490
527
|
const tone = option?.tone ?? toneOf(cell.props.tone, 'neutral');
|
|
491
528
|
return mk('span', TAG_CLASS.md[tone], text);
|
|
@@ -493,6 +530,30 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
493
530
|
return mk('span', TEXT_CLASS, text);
|
|
494
531
|
};
|
|
495
532
|
|
|
533
|
+
// ── 表格工具位里的「全部展开 / 全部收起」(页面编译放的静态链接,按对象名认领;本组件只接线与显隐)
|
|
534
|
+
const treeName = (): string => root?.closest<HTMLElement>('[data-kit-tree-of]')?.getAttribute('data-kit-tree-of') ?? '';
|
|
535
|
+
const controls = (): HTMLElement[] => {
|
|
536
|
+
const name = treeName();
|
|
537
|
+
const d = root?.ownerDocument;
|
|
538
|
+
if (d === undefined || name === '') return [];
|
|
539
|
+
return Array.from(d.querySelectorAll<HTMLElement>('[data-kit-tree-ctl]')).filter((el) => el.getAttribute('data-kit-tree-for') === name);
|
|
540
|
+
};
|
|
541
|
+
function syncTreeControls(anyBranch: boolean): void {
|
|
542
|
+
for (const el of controls()) {
|
|
543
|
+
// 显隐落在类名上(链接自带 inline-flex,会盖住 [hidden])
|
|
544
|
+
if (!CONTROL_CLASS.has(el)) CONTROL_CLASS.set(el, el.className);
|
|
545
|
+
el.className = anyBranch ? CONTROL_CLASS.get(el)! : 'hidden';
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const onControl = (event: Event): void => {
|
|
549
|
+
const t = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-tree-ctl]') ?? null;
|
|
550
|
+
if (t === null || t.getAttribute('data-kit-tree-for') !== treeName()) return;
|
|
551
|
+
if (t.getAttribute('data-kit-tree-ctl') === 'expand') {
|
|
552
|
+
for (const n of byKey.values()) if (n.children.length > 0) open.add(n.key);
|
|
553
|
+
} else open.clear();
|
|
554
|
+
paint();
|
|
555
|
+
};
|
|
556
|
+
|
|
496
557
|
function paint(): void {
|
|
497
558
|
if (!root) return;
|
|
498
559
|
const p = P();
|
|
@@ -503,34 +564,39 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
503
564
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
504
565
|
root.replaceChildren();
|
|
505
566
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const barClass = p.bordered === false ? stripBorderClasses(TOOLBAR_CLASS) : TOOLBAR_CLASS;
|
|
509
|
-
const bar = mk('div', barClass);
|
|
510
|
-
const expandBtn = mk('button', TOOLBAR_BUTTON_CLASS, str(p.expandAllLabel, kitText('soma.kit.expand_all', undefined, ctx.host)));
|
|
511
|
-
expandBtn.setAttribute('type', 'button');
|
|
512
|
-
expandBtn.setAttribute('data-kit-expand-all', '');
|
|
513
|
-
const collapseBtn = mk('button', TOOLBAR_BUTTON_CLASS, str(p.collapseAllLabel, kitText('soma.kit.collapse_all', undefined, ctx.host)));
|
|
514
|
-
collapseBtn.setAttribute('type', 'button');
|
|
515
|
-
collapseBtn.setAttribute('data-kit-collapse-all', '');
|
|
516
|
-
bar.append(expandBtn, collapseBtn);
|
|
517
|
-
root.appendChild(bar);
|
|
518
|
-
}
|
|
567
|
+
// 「全部展开 / 全部收起」不在表体里:由页面编译放进表格工具位(与刷新同一行),这里只按有没有可展开的节点显隐那两个链接
|
|
568
|
+
syncTreeControls(flattenTree(forest).some((n) => n.children.length > 0 || n.lazy));
|
|
519
569
|
|
|
520
570
|
const grid = mk('div', GRID_CLASS);
|
|
521
571
|
grid.setAttribute('role', 'treegrid');
|
|
522
572
|
grid.setAttribute('aria-multiselectable', str(p.select) === 'multi' ? 'true' : 'false');
|
|
523
573
|
const tabbable = cursor !== null && list.some((n) => n.key === cursor) ? cursor : (list[0]?.key ?? null);
|
|
524
574
|
const cols = cells();
|
|
575
|
+
// 显式 bordered: true 的完整网格表(页面编译给每列单元格写了列间竖分隔线 not-last:border-e):外壳与本组件宿主都标 data-kit-grid,
|
|
576
|
+
// 主题结构 CSS 不对它去卡片外观;契约里 bordered 缺省是 true,不能拿它判「显式」,所以看编译产出的列类
|
|
577
|
+
const gridTable = p.bordered !== false && cols.some((col) => /(?:^|\s)not-last:border-e(?:\s|$)/.test(col.cellClass));
|
|
578
|
+
const gridHost = root.closest('[data-soma-component]');
|
|
579
|
+
if (gridTable) {
|
|
580
|
+
root.setAttribute('data-kit-grid', '');
|
|
581
|
+
gridHost?.setAttribute('data-kit-grid', '');
|
|
582
|
+
} else {
|
|
583
|
+
root.removeAttribute('data-kit-grid');
|
|
584
|
+
gridHost?.removeAttribute('data-kit-grid');
|
|
585
|
+
}
|
|
525
586
|
const mode = str(p.select, 'none');
|
|
526
587
|
const actions = actionsOf(p.actions).filter((a) => a.permission === '' || check === null || check(a.permission));
|
|
527
588
|
const rowCls = [str(p.rowClass), str(p.stripeClass), bool(p.pickOnRow) ? ROW_FOCUS_CLASS : 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring']
|
|
528
589
|
.filter((s) => s !== '').join(' ');
|
|
590
|
+
const toneField = str(p.rowToneField);
|
|
529
591
|
for (const n of list) {
|
|
530
592
|
const branch = n.children.length > 0 || n.lazy;
|
|
531
593
|
const isOpen = n.children.length > 0 && open.has(n.key);
|
|
532
|
-
|
|
594
|
+
// 行样式档位:每次 paint 都 replaceChildren 重建行元素,类串每行现算,无旧档位残留
|
|
595
|
+
const toneCls = toneField === '' ? '' : rowToneClass(n.row[toneField]);
|
|
596
|
+
const row = mk('div', toneCls === '' ? rowCls : `${rowCls} ${toneCls}`);
|
|
533
597
|
row.setAttribute('role', 'row');
|
|
598
|
+
// 与普通表格行同一部件标记:主题的最小行高令牌(含边线正好 44,随密度档)、行分隔线、斑马纹规则都靠它命中
|
|
599
|
+
row.setAttribute('data-kit-part', KIT_PART_TABLE_ROW);
|
|
534
600
|
row.setAttribute('data-kit-row', '');
|
|
535
601
|
row.setAttribute('data-kit-key', n.key);
|
|
536
602
|
row.setAttribute('aria-level', String(n.level + 1));
|
|
@@ -539,16 +605,18 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
539
605
|
if (branch) row.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
|
540
606
|
row.tabIndex = n.key === tabbable ? 0 : -1;
|
|
541
607
|
const picked = isPicked(n.row);
|
|
608
|
+
const busy = rowBusy(n.row);
|
|
542
609
|
if (mode !== 'none') row.setAttribute('aria-selected', picked ? 'true' : 'false');
|
|
543
610
|
if (picked) row.setAttribute('data-kit-selected', '');
|
|
611
|
+
if (busy) row.setAttribute('aria-busy', 'true');
|
|
544
612
|
|
|
545
613
|
if (mode === 'single' || mode === 'multi') {
|
|
546
614
|
const selectClass = p.bordered === false ? stripBorderClasses(str(p.selectClass)) : str(p.selectClass);
|
|
547
615
|
const cell = mk('div', selectClass);
|
|
548
616
|
cell.setAttribute('role', 'gridcell');
|
|
549
|
-
const box = createCheck(doc(), mode === 'single' ? 'radio' : 'checkbox', { checked: picked });
|
|
617
|
+
const box = createCheck(doc(), mode === 'single' ? 'radio' : 'checkbox', { checked: picked, ...(busy ? { disabled: true } : {}) });
|
|
550
618
|
box.setAttribute('data-kit-sel', '');
|
|
551
|
-
setMarkLabel(box, kitText('soma.kit.select_row_of', { key: n.key },
|
|
619
|
+
setMarkLabel(box, kitText('soma.kit.select_row_of', { key: n.key }, api.host));
|
|
552
620
|
cell.appendChild(box);
|
|
553
621
|
row.appendChild(cell);
|
|
554
622
|
}
|
|
@@ -570,7 +638,7 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
570
638
|
tg.setAttribute('type', 'button');
|
|
571
639
|
tg.setAttribute('data-kit-toggle', '');
|
|
572
640
|
tg.tabIndex = -1;
|
|
573
|
-
tg.setAttribute('aria-label', failed.has(n.key) ? str(p.retryLabel, kitText('soma.kit.retry_load', undefined,
|
|
641
|
+
tg.setAttribute('aria-label', failed.has(n.key) ? str(p.retryLabel, kitText('soma.kit.retry_load', undefined, api.host)) : isOpen ? kitText('soma.kit.collapse', undefined, api.host) : kitText('soma.kit.expand', undefined, api.host));
|
|
574
642
|
wrap.appendChild(tg);
|
|
575
643
|
} else {
|
|
576
644
|
const sp = mk('span', SPACER_CLASS);
|
|
@@ -589,9 +657,14 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
589
657
|
cell.setAttribute('role', 'gridcell');
|
|
590
658
|
const box = mk('div', ACTIONS_CELL_CLASS);
|
|
591
659
|
for (const a of actions) {
|
|
592
|
-
const btn = mk('button',
|
|
660
|
+
const btn = mk('button', ROW_ACTION_BUTTON_CLASS[a.tone], a.name) as HTMLButtonElement;
|
|
593
661
|
btn.setAttribute('type', 'button');
|
|
662
|
+
// 行动作:文字链接形态(无面,不标 raised)
|
|
594
663
|
btn.setAttribute('data-kit-act', a.id);
|
|
664
|
+
if (busy) {
|
|
665
|
+
btn.disabled = true;
|
|
666
|
+
btn.setAttribute('aria-disabled', 'true');
|
|
667
|
+
}
|
|
595
668
|
box.appendChild(btn);
|
|
596
669
|
}
|
|
597
670
|
cell.appendChild(box);
|
|
@@ -603,8 +676,9 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
603
676
|
|
|
604
677
|
if (all.length > list.length) {
|
|
605
678
|
const wrap = mk('div', MORE_WRAP_CLASS);
|
|
606
|
-
const more = mk('button', MORE_BUTTON_CLASS, kitText('soma.kit.more_rows', { label: str(p.moreLabel, kitText('soma.kit.show_more', undefined,
|
|
679
|
+
const more = mk('button', MORE_BUTTON_CLASS, kitText('soma.kit.more_rows', { label: str(p.moreLabel, kitText('soma.kit.show_more', undefined, api.host)), n: all.length - list.length }, api.host));
|
|
607
680
|
more.setAttribute('type', 'button');
|
|
681
|
+
setKitFace(more, 'raised');
|
|
608
682
|
more.setAttribute('data-kit-more', '');
|
|
609
683
|
wrap.appendChild(more);
|
|
610
684
|
root.appendChild(wrap);
|
|
@@ -613,26 +687,13 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
613
687
|
}
|
|
614
688
|
|
|
615
689
|
return {
|
|
616
|
-
|
|
617
|
-
root =
|
|
618
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
619
|
-
?? ctx.host;
|
|
690
|
+
attach(rootEl) {
|
|
691
|
+
root = rootEl;
|
|
620
692
|
alive = true;
|
|
621
|
-
sync();
|
|
622
693
|
const r = root;
|
|
623
694
|
const onClick = (event: Event): void => {
|
|
624
695
|
const t = event.target as HTMLElement | null;
|
|
625
696
|
if (!t) return;
|
|
626
|
-
if (t.closest('[data-kit-expand-all]')) {
|
|
627
|
-
for (const n of byKey.values()) if (n.children.length > 0) open.add(n.key);
|
|
628
|
-
paint();
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
if (t.closest('[data-kit-collapse-all]')) {
|
|
632
|
-
open.clear();
|
|
633
|
-
paint();
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
697
|
if (t.closest('[data-kit-more]')) {
|
|
637
698
|
limit = (limit > 0 ? limit : cfg().windowThreshold) + KIT_TREE_TABLE.windowBatch;
|
|
638
699
|
paint();
|
|
@@ -646,8 +707,10 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
646
707
|
cursor = key;
|
|
647
708
|
const act = t.closest<HTMLElement>('[data-kit-act]');
|
|
648
709
|
if (act) {
|
|
649
|
-
const
|
|
650
|
-
|
|
710
|
+
const list = actionsOf(P().actions);
|
|
711
|
+
const idx = list.findIndex((x) => x.id === act.getAttribute('data-kit-act'));
|
|
712
|
+
const a = list[idx];
|
|
713
|
+
if (a && !rowBusy(node.row)) emitActionSlot((n, p) => api.emit(n, p), KIT_ACTION_SLOT_BASE.row, idx, { kit_action: a.id, id: a.id, name: a.name, builtin: a.builtin, target: a.target, row: node.row, ...objectPayload(), ...rowBusyPayload(node.row) });
|
|
651
714
|
return;
|
|
652
715
|
}
|
|
653
716
|
if (t.closest('[data-kit-toggle]')) {
|
|
@@ -676,27 +739,38 @@ export function createKitTreeTable(): SomaComponentDefinition {
|
|
|
676
739
|
if (wiring.onKeydown(event)) event.preventDefault();
|
|
677
740
|
};
|
|
678
741
|
r.addEventListener('click', onClick);
|
|
742
|
+
r.ownerDocument.addEventListener('click', onControl);
|
|
679
743
|
r.addEventListener('keydown', onKeydown as EventListener);
|
|
744
|
+
// 删除在途的忙闲通道:可见行里有在途状态与现状不一致才重绘
|
|
745
|
+
const offBusy = onKitActionBusy(() => {
|
|
746
|
+
if (!alive) return;
|
|
747
|
+
for (const el of rowEls()) {
|
|
748
|
+
const node = byKey.get(el.getAttribute('data-kit-key') ?? '');
|
|
749
|
+
if (node && (el.getAttribute('aria-busy') === 'true') !== rowBusy(node.row)) { api.refresh(); return; }
|
|
750
|
+
}
|
|
751
|
+
});
|
|
680
752
|
offs = [
|
|
753
|
+
offBusy,
|
|
681
754
|
() => r.removeEventListener('click', onClick),
|
|
755
|
+
() => r.ownerDocument.removeEventListener('click', onControl),
|
|
682
756
|
offMark,
|
|
683
757
|
() => r.removeEventListener('keydown', onKeydown as EventListener),
|
|
684
758
|
// 右键菜单(页面声明了 contextMenu 才有宿主壳):按行主键取整行
|
|
685
759
|
provideCtxRows(r, (key) => byKey.get(key)?.row),
|
|
686
760
|
];
|
|
687
|
-
|
|
761
|
+
return () => {
|
|
762
|
+
alive = false;
|
|
763
|
+
for (const off of offs) off();
|
|
764
|
+
offs = [];
|
|
765
|
+
root = null;
|
|
766
|
+
};
|
|
688
767
|
},
|
|
689
|
-
|
|
768
|
+
render(rootEl) {
|
|
769
|
+
root = rootEl;
|
|
690
770
|
sync();
|
|
691
771
|
paint();
|
|
692
772
|
},
|
|
693
|
-
onUnmount(): void {
|
|
694
|
-
alive = false;
|
|
695
|
-
for (const off of offs) off();
|
|
696
|
-
offs = [];
|
|
697
|
-
root = null;
|
|
698
|
-
},
|
|
699
773
|
};
|
|
700
|
-
},
|
|
774
|
+
}),
|
|
701
775
|
};
|
|
702
776
|
}
|
package/src/data/tree.ts
CHANGED
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
// 页面重取数据把 children 补进该节点后自动结束加载态;已有的勾选会顺着级联落到新子项上。
|
|
14
14
|
// - `filter`:关键字(页面绑一个输入框的值),只留命中项 + 祖先 + 命中项的后代,祖先自动展开,命中文字高亮;无命中显示 filter_empty_text。
|
|
15
15
|
|
|
16
|
-
import type {
|
|
16
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
17
17
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
18
18
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
19
|
-
import { bool, joinClass, str } from '../base/shared';
|
|
19
|
+
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
20
20
|
import { kitIcon } from '../base/icons';
|
|
21
|
+
import { markCheckBox } from '../base/check-core';
|
|
21
22
|
import { kitText } from '../i18n/kit-text';
|
|
23
|
+
import { applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES, kitEmptyPanel } from '../base/state-panel';
|
|
22
24
|
import {
|
|
23
|
-
KIT_VIRTUAL_CLASS_CANDIDATES, KIT_VIRTUAL_OPTION_ROW_CLASS,
|
|
25
|
+
KIT_VIRTUAL_CLASS_CANDIDATES, KIT_VIRTUAL_OPTION_ROW_CLASS, virtualRowPx, KIT_VIRTUAL_VIEWPORT_BASE, KIT_VIRTUAL_VIEWPORT_CLASS, KIT_VIRTUAL_VIEWPORT_DEFAULT,
|
|
24
26
|
createVirtualWindow, paintVirtualRows, rowTierOf, withoutPy, type VirtualWindow,
|
|
25
27
|
} from '../base/virtual-list';
|
|
26
28
|
import { classTokens } from './shape-util';
|
|
@@ -43,7 +45,7 @@ export const KIT_TREE_DEFAULT_MAP: Readonly<KitTreeMap> = Object.freeze({
|
|
|
43
45
|
const ROOT_CLASS = 'flex flex-col gap-0.5 text-sm text-fg';
|
|
44
46
|
const GROUP_CLASS = 'ms-4 flex flex-col gap-0.5';
|
|
45
47
|
const ITEM_CLASS = 'flex flex-col gap-0.5 rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
46
|
-
const ROW_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-fg transition-colors hover:bg-
|
|
48
|
+
const ROW_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
47
49
|
const ROW_SELECTED_CLASS = 'flex cursor-pointer items-center gap-2 rounded-md bg-primary-soft px-2 py-1.5 text-primary-on-soft';
|
|
48
50
|
const ROW_DISABLED_CLASS = 'flex cursor-not-allowed items-center gap-2 rounded-md px-2 py-1.5 text-fg-subtle opacity-60';
|
|
49
51
|
const TOGGLE_CLASS = 'w-4 shrink-0 text-fg-subtle';
|
|
@@ -64,7 +66,7 @@ const VIRTUAL_ROOT_CLASS = 'flex flex-col text-sm text-fg';
|
|
|
64
66
|
export const KIT_TREE_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
65
67
|
...FLAT_INDENT, FLAT_ROW_FILL, VIRTUAL_ROOT_CLASS, KIT_VIRTUAL_VIEWPORT_BASE, ...Object.values(KIT_VIRTUAL_VIEWPORT_CLASS), ...KIT_VIRTUAL_CLASS_CANDIDATES,
|
|
66
68
|
ROOT_CLASS, GROUP_CLASS, ITEM_CLASS, ROW_CLASS, ROW_SELECTED_CLASS, ROW_DISABLED_CLASS, TOGGLE_CLASS, CHECK_CLASS, CHECK_ON_CLASS, HIT_CLASS, EMPTY_CLASS,
|
|
67
|
-
'py-1',
|
|
69
|
+
'py-1', KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
68
70
|
);
|
|
69
71
|
|
|
70
72
|
/** 层级上限:超深的数据截断,不递归到栈溢出 */
|
|
@@ -207,6 +209,8 @@ export function createTree(): SomaComponentDefinition {
|
|
|
207
209
|
lazy: { type: 'boolean', default: false, desc: '懒加载:has_children 为真且无子项的节点首次展开抛 load { item }' },
|
|
208
210
|
filter: { type: 'string', default: '', desc: '过滤关键字:命中项 + 祖先 + 命中项的后代,祖先自动展开,命中文字高亮' },
|
|
209
211
|
filter_empty_text: { type: 'string', default: '', desc: '过滤无命中时的文案' },
|
|
212
|
+
empty_text: { type: 'string', default: '', desc: '没有节点时的文案;缺省取内置文案(按页面语言)' },
|
|
213
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
210
214
|
virtual: { type: 'boolean', default: false, desc: '大量节点虚拟滚动:可见节点拍平成一列,只画窗口内的行(走 core 虚拟滚动端口,固定行高 row_height;缩进改用扁平缩进,最多 11 层);引擎不可用时回退为普通渲染并在控制台提示一次' },
|
|
211
215
|
row_height: { type: 'enum', values: ['sm', 'md', 'lg'], default: 'md', desc: 'virtual 时节点行的固定行高档位(档位名,不接受像素)' },
|
|
212
216
|
height: { type: 'enum', values: ['sm', 'md', 'lg'], default: 'md', desc: 'virtual 时滚动视口的最大高度档位' },
|
|
@@ -216,13 +220,14 @@ export function createTree(): SomaComponentDefinition {
|
|
|
216
220
|
select: { payload: { item: { type: 'object' } }, desc: '选中某项(点击、Enter、Space);item 是源数据里的原对象' },
|
|
217
221
|
check: { payload: { checked: { type: 'array' }, half: { type: 'array' }, item: { type: 'object' }, on: { type: 'boolean' } }, desc: 'checkable 下勾选变化;checked 全勾节点 id,half 半选节点 id,item 是被点的节点' },
|
|
218
222
|
load: { payload: { item: { type: 'object' } }, desc: 'lazy 下首次展开待加载节点;页面重取并把 children 补进该节点' },
|
|
223
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
219
224
|
},
|
|
220
225
|
keyboard: { layout: 'tree', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
221
226
|
},
|
|
222
227
|
services: ['engines'],
|
|
223
228
|
templateHtml: `<ul data-soma-id="root" role="tree" class="${ROOT_CLASS}"></ul>`,
|
|
224
|
-
controllerFactory: (
|
|
225
|
-
const P = (): Record<string, unknown> =>
|
|
229
|
+
controllerFactory: createKitController((api) => {
|
|
230
|
+
const P = (): Record<string, unknown> => api.props();
|
|
226
231
|
let root: HTMLElement | null = null;
|
|
227
232
|
let nodes: FlatNode[] = [];
|
|
228
233
|
let order: FlatNode[] = [];
|
|
@@ -303,7 +308,7 @@ export function createTree(): SomaComponentDefinition {
|
|
|
303
308
|
if (!wasOpen && node.children.length === 0 && node.pending && !loading.has(key)) {
|
|
304
309
|
loading.add(key);
|
|
305
310
|
paint();
|
|
306
|
-
|
|
311
|
+
api.emit('load', { item: node.raw });
|
|
307
312
|
return;
|
|
308
313
|
}
|
|
309
314
|
} else {
|
|
@@ -318,7 +323,7 @@ export function createTree(): SomaComponentDefinition {
|
|
|
318
323
|
selected = key;
|
|
319
324
|
cursor = key;
|
|
320
325
|
paint();
|
|
321
|
-
|
|
326
|
+
api.emit('select', { item: node.raw });
|
|
322
327
|
};
|
|
323
328
|
|
|
324
329
|
// ── 勾选 ──
|
|
@@ -382,7 +387,7 @@ export function createTree(): SomaComponentDefinition {
|
|
|
382
387
|
else if (target === 1) on.add(key); else on.delete(key);
|
|
383
388
|
recompute();
|
|
384
389
|
paint();
|
|
385
|
-
|
|
390
|
+
api.emit('check', { ...outputChecked(), item: node.raw, on: target === 1 });
|
|
386
391
|
};
|
|
387
392
|
|
|
388
393
|
const sync = (): void => {
|
|
@@ -486,6 +491,7 @@ export function createTree(): SomaComponentDefinition {
|
|
|
486
491
|
const cb = document.createElement('span');
|
|
487
492
|
cb.className = s === 0 ? CHECK_CLASS : CHECK_ON_CLASS;
|
|
488
493
|
cb.setAttribute('aria-hidden', 'true');
|
|
494
|
+
markCheckBox(cb);
|
|
489
495
|
cb.setAttribute('data-kit-check', '');
|
|
490
496
|
if (s !== 0) cb.appendChild(kitIcon(s === 1 ? 'check' : 'minus', 'xs'));
|
|
491
497
|
row.appendChild(cb);
|
|
@@ -518,10 +524,10 @@ export function createTree(): SomaComponentDefinition {
|
|
|
518
524
|
const viewport = rowTierOf(p.height, KIT_VIRTUAL_VIEWPORT_DEFAULT);
|
|
519
525
|
if (virt === null) {
|
|
520
526
|
virt = createVirtualWindow({
|
|
521
|
-
services:
|
|
527
|
+
services: api.services,
|
|
522
528
|
scroller: () => root,
|
|
523
529
|
count: visible.length,
|
|
524
|
-
rowPx:
|
|
530
|
+
rowPx: virtualRowPx(tier, r),
|
|
525
531
|
onChange: () => paint(),
|
|
526
532
|
});
|
|
527
533
|
} else {
|
|
@@ -560,6 +566,18 @@ export function createTree(): SomaComponentDefinition {
|
|
|
560
566
|
function paint(): void {
|
|
561
567
|
if (!root) return;
|
|
562
568
|
const p = P();
|
|
569
|
+
// 没有节点:读取中 / 读取失败 + 重试 / 空态,与集合三态同一画法(base/state-panel.ts;有读接口时编译器自动绑 loading / error_text)
|
|
570
|
+
if (nodes.length === 0) {
|
|
571
|
+
if (virt !== null) root.tabIndex = -1;
|
|
572
|
+
disposeVirt();
|
|
573
|
+
root.textContent = '';
|
|
574
|
+
root.removeAttribute('aria-multiselectable');
|
|
575
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
576
|
+
if (!applyKitReadState(root, p, { hasContent: false, onRetry: () => api.emit('retry', {}), repaint: () => api.refresh() })) {
|
|
577
|
+
root.appendChild(kitEmptyPanel(document, str(p.empty_text, kitText('soma.kit.empty', undefined, api.host)), true));
|
|
578
|
+
}
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
563
581
|
const flt = filterOf();
|
|
564
582
|
const keyword = str(p.filter).trim().toLowerCase();
|
|
565
583
|
const visible = visibleOf(nodes, open, flt);
|
|
@@ -575,11 +593,13 @@ export function createTree(): SomaComponentDefinition {
|
|
|
575
593
|
disposeVirt();
|
|
576
594
|
root.textContent = '';
|
|
577
595
|
if (box) root.setAttribute('aria-multiselectable', 'true'); else root.removeAttribute('aria-multiselectable');
|
|
596
|
+
// 已有内容时的读状态:重取中根 aria-busy(内容保留);读取失败不往 role=tree 里塞面板(树结构不被破坏)
|
|
597
|
+
if (p.loading === true || p.loading === 'true') root.setAttribute('aria-busy', 'true'); else root.removeAttribute('aria-busy');
|
|
578
598
|
if (flt !== null && visible.length === 0) {
|
|
579
599
|
const empty = document.createElement('li');
|
|
580
600
|
empty.setAttribute('role', 'none');
|
|
581
601
|
empty.className = EMPTY_CLASS;
|
|
582
|
-
empty.textContent = str(p.filter_empty_text, kitText('soma.kit.empty_node', undefined,
|
|
602
|
+
empty.textContent = str(p.filter_empty_text, kitText('soma.kit.empty_node', undefined, api.host));
|
|
583
603
|
root.appendChild(empty);
|
|
584
604
|
} else {
|
|
585
605
|
for (const n of nodes) {
|
|
@@ -592,11 +612,8 @@ export function createTree(): SomaComponentDefinition {
|
|
|
592
612
|
}
|
|
593
613
|
|
|
594
614
|
return {
|
|
595
|
-
|
|
596
|
-
root =
|
|
597
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
598
|
-
?? ctx.host;
|
|
599
|
-
sync();
|
|
615
|
+
attach(rootEl) {
|
|
616
|
+
root = rootEl;
|
|
600
617
|
const onClick = (event: Event): void => {
|
|
601
618
|
const target = event.target as HTMLElement | null;
|
|
602
619
|
const li = target?.closest<HTMLElement>('[data-kit-key]');
|
|
@@ -625,29 +642,25 @@ export function createTree(): SomaComponentDefinition {
|
|
|
625
642
|
root.addEventListener('click', onClick);
|
|
626
643
|
root.addEventListener('keydown', onKeydown as EventListener);
|
|
627
644
|
const r = root;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
645
|
+
const offCtx = provideCtxRows(r, (key) => {
|
|
646
|
+
const raw = byKey.get(key)?.raw;
|
|
647
|
+
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : undefined;
|
|
648
|
+
});
|
|
649
|
+
return () => {
|
|
650
|
+
r.removeEventListener('click', onClick);
|
|
651
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
652
|
+
offCtx();
|
|
653
|
+
disposeVirt();
|
|
654
|
+
root = null;
|
|
655
|
+
};
|
|
638
656
|
},
|
|
639
|
-
|
|
657
|
+
render(rootEl) {
|
|
658
|
+
root = rootEl;
|
|
640
659
|
sync();
|
|
641
660
|
paint();
|
|
642
661
|
},
|
|
643
|
-
onUnmount(): void {
|
|
644
|
-
for (const fn of removeListeners) fn();
|
|
645
|
-
removeListeners = [];
|
|
646
|
-
disposeVirt();
|
|
647
|
-
root = null;
|
|
648
|
-
},
|
|
649
662
|
};
|
|
650
|
-
},
|
|
663
|
+
}),
|
|
651
664
|
};
|
|
652
665
|
}
|
|
653
666
|
|