soma-kit 0.1.15 → 0.1.17
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 +1 -1
- package/package.json +8 -5
- package/packs/ai/model-card.ts +3 -3
- package/packs/ops/error-budget-card.ts +3 -3
- package/packs/ops/release-readiness-card.ts +3 -3
- package/packs/security/control-evidence-card.ts +3 -3
- package/packs/security/finding-card.ts +3 -2
- package/packs/shared/card-util.ts +17 -0
- package/spec/generated/kit-app.schema.json +2148 -340
- package/spec/generated/kit-page.schema.json +1134 -139
- package/spec/kit-grammar.json +935 -93
- package/spec/kit-grammar.schema.json +167 -2
- package/src/app/app-config.ts +219 -186
- package/src/app/define-kit-actions.ts +126 -20
- package/src/app/define-kit-app.ts +49 -4
- package/src/app/index.ts +5 -0
- package/src/app/kit-view-context.ts +39 -1
- package/src/app/list-page-defaults.ts +14 -0
- package/src/app/server-pages.ts +239 -7
- package/src/app/server.ts +466 -25
- package/src/app/theme-endpoint.ts +67 -23
- package/src/app/theme-runtime.ts +414 -85
- package/src/app/theme-shards.ts +69 -0
- package/src/app/tier-compat.ts +107 -0
- package/src/base/action-busy.ts +215 -38
- package/src/base/affix.ts +137 -0
- package/src/base/alert.ts +104 -59
- package/src/base/anchored-layer.ts +7 -6
- package/src/base/avatar.ts +147 -61
- package/src/base/badge.ts +186 -0
- package/src/base/button-group.ts +227 -0
- package/src/base/button.ts +347 -50
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +143 -32
- package/src/base/check-core.ts +193 -33
- package/src/base/checkbox.ts +67 -2
- package/src/base/choice.ts +132 -31
- package/src/base/collapse.ts +249 -0
- package/src/base/color-picker.ts +399 -27
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +148 -36
- package/src/base/context-menu.ts +23 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +114 -96
- package/src/base/date.ts +481 -74
- package/src/base/delta.ts +16 -9
- package/src/base/divider.ts +51 -33
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +57 -21
- package/src/base/gap-value.ts +34 -15
- package/src/base/hint-tips.ts +99 -29
- package/src/base/identity-cells.ts +839 -0
- package/src/base/illustrations.ts +6 -4
- package/src/base/image.ts +40 -19
- package/src/base/index.ts +79 -22
- package/src/base/inline-error.ts +13 -7
- package/src/base/input.ts +135 -35
- package/src/base/kbd.ts +30 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +282 -101
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +55 -22
- package/src/base/menu-button.ts +73 -22
- package/src/base/menu-core.ts +201 -24
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +7 -5
- package/src/base/motion/hover-gallery.ts +16 -12
- package/src/base/motion/limits.ts +10 -0
- package/src/base/motion/marquee.ts +18 -11
- package/src/base/motion/text-rotate.ts +34 -16
- package/src/base/notification.ts +292 -0
- package/src/base/number.ts +93 -12
- package/src/base/otp.ts +139 -27
- package/src/base/overlay-runtime.ts +30 -23
- package/src/base/overlay-shell.ts +59 -14
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +624 -73
- package/src/base/popup.ts +187 -52
- package/src/base/portal-core.ts +99 -2
- package/src/base/price-text.ts +51 -17
- package/src/base/progress.ts +100 -18
- package/src/base/qr-code.ts +64 -17
- package/src/base/qty-stepper.ts +141 -22
- package/src/base/radio.ts +43 -2
- package/src/base/range.ts +194 -39
- package/src/base/rating.ts +117 -31
- package/src/base/reason-tip.ts +58 -16
- package/src/base/relation-cells.ts +541 -0
- package/src/base/resize-handle.ts +5 -3
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +70 -26
- package/src/base/select.ts +8 -3
- package/src/base/shared.ts +482 -71
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/sticky-edge.ts +96 -29
- package/src/base/swap.ts +39 -21
- package/src/base/switch.ts +158 -38
- package/src/base/tabs.ts +292 -0
- package/src/base/tag-input.ts +123 -54
- package/src/base/tag.ts +184 -66
- package/src/base/text.ts +461 -71
- package/src/base/textarea.ts +88 -39
- package/src/base/time-picker.ts +335 -55
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +342 -88
- package/src/base/upload.ts +604 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +70 -5
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +52 -12
- package/src/biz/auth-panel/compile.ts +13 -3
- package/src/biz/auth-panel/shell.ts +27 -7
- package/src/biz/category-crud/compile.ts +51 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +29 -9
- package/src/biz/checkout-page/compile.ts +37 -3
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +26 -9
- package/src/biz/compose.ts +6 -1
- package/src/biz/data-components.ts +2 -0
- package/src/biz/import-wizard/compile.ts +4 -1
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +32 -18
- package/src/biz/index.ts +1 -1
- package/src/biz/landing-page/compile.ts +3 -2
- package/src/biz/landing-page/shell.ts +22 -3
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +54 -15
- package/src/biz/master-sub/compile.ts +194 -57
- package/src/biz/master-sub/detail-head.ts +141 -18
- package/src/biz/master-sub/index.ts +3 -0
- package/src/biz/master-sub/shell.ts +188 -62
- package/src/biz/multi-board/compile.ts +87 -36
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +3 -2
- package/src/biz/multi-board/prose-fold.ts +15 -11
- package/src/biz/multi-board/shell.ts +148 -37
- package/src/biz/notification-center/compile.ts +20 -6
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +43 -10
- package/src/biz/page-templates/domain-templates.ts +145 -22
- package/src/biz/page-templates/result-page/compile.ts +4 -1
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +17 -4
- package/src/biz/page-templates/sign-in-page/compile.ts +19 -8
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +28 -12
- package/src/biz/record-detail/compile.ts +39 -11
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +41 -10
- package/src/biz/settings-center/compile.ts +4 -1
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +30 -9
- package/src/biz/shared/action-host.ts +137 -46
- package/src/biz/shared/compile-helpers.ts +152 -28
- package/src/biz/shared/coordinator.ts +628 -147
- package/src/biz/shared/focus-return.ts +180 -0
- package/src/biz/shared/object-aliases.ts +7 -1
- package/src/biz/shared/overlay-compile.ts +58 -10
- package/src/biz/shared/overlay-shell.ts +40 -10
- package/src/biz/shared/page-form-actions.ts +151 -0
- package/src/biz/shared/page-form.ts +255 -0
- package/src/biz/shared/pipeline.ts +74 -0
- package/src/biz/shared/runtime-hub.ts +101 -8
- package/src/biz/shared/verbs.ts +129 -0
- package/src/biz/single-form/compile.ts +4 -2
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +21 -11
- package/src/biz/standard-crud/compile.ts +206 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +82 -22
- package/src/biz/standard-crud/summary.ts +2 -37
- package/src/biz/step-form/compile.ts +12 -3
- package/src/biz/step-form/hub.ts +165 -50
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +31 -15
- package/src/biz/types.ts +40 -4
- package/src/cli/kit-cli.ts +145 -26
- package/src/cli/kit-init.ts +3 -3
- package/src/cli/migrate/theme-map.ts +35 -28
- package/src/cli/migrate/ts-rules.ts +2 -2
- package/src/cli/migrate/types.ts +3 -3
- package/src/cli/migrate/yaml-rules.ts +11 -9
- package/src/cli/view-writes.ts +13 -0
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +446 -53
- package/src/compile/component-candidates.ts +56 -4
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +1 -1
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/rules-composition.ts +2 -1
- package/src/compile/layout-lint/rules-table.ts +4 -19
- package/src/compile/look-page.ts +551 -0
- package/src/compile/look.ts +376 -0
- package/src/compile/page-composition.ts +382 -46
- package/src/compile/page-hierarchy.ts +131 -0
- package/src/compile/page-pipeline-look.ts +156 -0
- package/src/compile/page-pipeline.ts +200 -0
- package/src/compile/parse.ts +12 -11
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +645 -28
- package/src/compile/styles.ts +226 -26
- package/src/compile/types.ts +62 -5
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +49 -22
- package/src/data/anchor-nav.ts +73 -15
- package/src/data/approval-flow.ts +210 -124
- package/src/data/assignment-picker.ts +163 -85
- package/src/data/async-result-panel.ts +110 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +141 -19
- package/src/data/calendar.ts +434 -96
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +72 -38
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +904 -77
- package/src/data/checklist.ts +78 -35
- package/src/data/code-view.ts +106 -48
- package/src/data/comment-thread.ts +607 -87
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +198 -30
- package/src/data/context-menu.ts +95 -21
- package/src/data/d9-limits.ts +2 -0
- package/src/data/d9-util.ts +13 -5
- package/src/data/diff.ts +107 -50
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +33 -17
- package/src/data/embed.ts +142 -7
- package/src/data/engine-ports.ts +13 -4
- package/src/data/field-mapper.ts +104 -48
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +603 -142
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +85 -27
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +637 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +38 -15
- package/src/data/image-viewer.ts +261 -62
- package/src/data/index.ts +63 -1
- package/src/data/item-list.ts +217 -57
- package/src/data/json-view.ts +165 -100
- package/src/data/kanban.ts +339 -87
- package/src/data/kit-contract.ts +230 -0
- package/src/data/leaderboard.ts +343 -0
- package/src/data/level-class.ts +21 -0
- package/src/data/log-stream.ts +347 -0
- package/src/data/markdown-view.ts +155 -45
- package/src/data/matrix.ts +217 -112
- package/src/data/media-grid.ts +162 -38
- package/src/data/mega-menu.ts +39 -23
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +50 -15
- package/src/data/menu.ts +131 -47
- package/src/data/mockup.ts +30 -22
- package/src/data/modal-dialog.ts +90 -13
- package/src/data/navbar.ts +143 -61
- package/src/data/notice-list.ts +100 -48
- package/src/data/notify-renderer.ts +61 -7
- package/src/data/object-form.ts +1389 -130
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +122 -42
- package/src/data/panel-head.ts +237 -75
- package/src/data/permission-matrix.ts +371 -119
- package/src/data/permission-tree.ts +135 -80
- package/src/data/pricing-table.ts +106 -42
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +63 -31
- package/src/data/record-card.ts +239 -70
- package/src/data/record-picker.ts +56 -27
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +131 -41
- package/src/data/resident.ts +11 -1
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +206 -35
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +376 -102
- package/src/data/rule-builder.ts +129 -80
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +86 -43
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +438 -86
- package/src/data/static-lazy.ts +18 -0
- package/src/data/static-registry.ts +38 -2
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +63 -34
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +128 -47
- package/src/data/system-switcher.ts +40 -20
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +99 -31
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +110 -47
- package/src/data/transfer.ts +195 -47
- package/src/data/tree-table.ts +194 -112
- package/src/data/tree.ts +191 -70
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +242 -102
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +26 -4
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +1 -2
- package/src/frames/inherited-shell.ts +54 -13
- package/src/frames/page-bar.ts +205 -27
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +0 -2
- package/src/frames/shared.ts +64 -21
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +11 -7
- package/src/frames/split-frame/wiring.ts +14 -10
- package/src/frames/tabs-frame/shell.ts +3 -2
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +2 -0
- package/src/frames/workspace-frame/extras.ts +5 -3
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/pipeline-key.ts +6 -0
- package/src/frames/workspace-frame/shell.ts +22 -2
- package/src/frames/workspace-frame/state.ts +42 -14
- package/src/frames/workspace-frame/view.ts +697 -167
- package/src/generated/kit-grammar-runtime.ts +1016 -54
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +96 -3
- package/src/object-renderer/action-group.ts +175 -23
- package/src/object-renderer/action-more.ts +48 -17
- package/src/object-renderer/arrange.ts +241 -29
- package/src/object-renderer/category-tone.ts +96 -0
- package/src/object-renderer/collapse-wiring.ts +19 -9
- package/src/object-renderer/collection-expand.ts +3 -3
- package/src/object-renderer/collection-parts.ts +432 -107
- package/src/object-renderer/collection-table.ts +347 -45
- package/src/object-renderer/collection.ts +291 -62
- package/src/object-renderer/compile-data.ts +12 -2
- package/src/object-renderer/defaults.ts +6 -5
- package/src/object-renderer/emit-events.ts +45 -19
- package/src/object-renderer/emit-object.ts +35 -9
- package/src/object-renderer/emit-static.ts +734 -159
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +105 -18
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +18 -2
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +44 -2
- package/src/object-renderer/pick-component.ts +8 -2
- package/src/object-renderer/pipeline-mode.ts +6 -0
- package/src/object-renderer/relation-field.ts +79 -0
- package/src/object-renderer/render-object.ts +71 -26
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +423 -104
- package/src/object-renderer/table-gap.ts +2 -1
- package/src/object-renderer/table-reorder.ts +237 -0
- package/src/object-renderer/table-summary.ts +26 -12
- package/src/object-renderer/table-tools.ts +428 -128
- package/src/object-renderer/types.ts +91 -2
- package/src/object-renderer/value-present.ts +49 -0
- package/src/page-target/ai-surface.ts +15 -22
- package/src/page-target/compile.ts +5 -6
- package/src/page-target/drift.ts +0 -7
- package/src/page-target/intent-schema.ts +46 -43
- package/src/page-target/target.ts +4 -5
- package/src/page-target/writer-policy.ts +4 -5
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +15 -14
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +3 -2
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +76 -19
- package/src/recipes/control.ts +64 -5
- package/src/recipes/desc-list.ts +101 -7
- package/src/recipes/divider.ts +30 -9
- package/src/recipes/emphasis.ts +90 -5
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +3 -2
- package/src/recipes/index.ts +28 -4
- package/src/recipes/inherited-shell.ts +21 -15
- package/src/recipes/json-view.ts +6 -5
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +16 -6
- package/src/recipes/overlay.ts +47 -19
- package/src/recipes/page-width.ts +31 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +37 -19
- package/src/recipes/rail-grid.ts +6 -3
- package/src/recipes/self-owned.ts +59 -0
- package/src/recipes/slot-align.ts +5 -3
- package/src/recipes/stat-state.ts +5 -5
- package/src/recipes/state.ts +54 -3
- package/src/recipes/status.ts +14 -14
- package/src/recipes/strip.ts +47 -5
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +33 -4
- package/src/recipes/table-gap.ts +3 -2
- package/src/recipes/table-native-edit.ts +22 -9
- package/src/recipes/table-row.ts +45 -12
- package/src/recipes/tabs.ts +54 -22
- package/src/recipes/text-diff.ts +15 -8
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +68 -3
- package/src/shared/action-func.ts +106 -0
- package/src/shared/color-scheme.ts +127 -0
- package/src/shared/confirm-decl.ts +5 -2
- package/src/shared/danger-facts.ts +55 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +58 -12
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/icons.ts +28 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/shared/order-value.ts +15 -0
- package/src/shared/page-attrs-runtime.ts +327 -0
- package/src/shared/page-attrs.ts +262 -0
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +165 -24
- package/src/shared/theme-usage.ts +16 -0
- package/src/shared/value-table-contract.ts +68 -0
- package/src/spatial/action-func.ts +4 -0
- package/src/spatial/declared-actions.ts +116 -0
- package/src/spatial/emit.ts +660 -0
- package/src/spatial/expand.ts +1482 -0
- package/src/spatial/field-types.ts +48 -0
- package/src/spatial/index.ts +82 -0
- package/src/spatial/layout.ts +697 -0
- package/src/spatial/look-apply.ts +206 -0
- package/src/spatial/page-decl.ts +44 -0
- package/src/spatial/page-object.ts +349 -0
- package/src/spatial/recognize.ts +491 -0
- package/src/spatial/self-report.ts +571 -0
- package/src/spatial/shape.ts +205 -0
- package/src/spatial/spatial-map.ts +136 -0
- package/src/spatial/tone.ts +145 -0
- package/src/theme/index.ts +11 -2
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +527 -16
- package/src/theme/kit-theme.tpl +491 -16
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +522 -185
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +3 -2
- package/src/theme/theme-tokens.ts +1601 -93
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/frames/list-summary.ts +0 -123
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
package/src/base/tree-select.ts
CHANGED
|
@@ -11,49 +11,89 @@
|
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
-
import { kitIcon } from '../shared/icons';
|
|
14
|
+
import { KIT_ICON_CLASS_CANDIDATES, kitIcon } from '../shared/icons';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
16
|
import { kitControlEdgeRecipe, kitControlRecipe } from '../recipes/control';
|
|
17
|
+
import { KIT_DIVIDER_COLOR_CLASS } from '../recipes/divider';
|
|
17
18
|
import { mergeClass } from '../shared/merge-class';
|
|
18
|
-
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
19
|
+
import { kitSurfaceRecipe, kitWellRecipe } from '../recipes/surface';
|
|
20
|
+
import { kitClosedValueRecipe } from '../recipes/field-text';
|
|
21
|
+
import { KIT_FOCUS_RING, kitSelectedRecipe } from '../recipes/state';
|
|
19
22
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
20
23
|
import { createCheck, markInput } from './check-core';
|
|
24
|
+
import { CHIP_REMOVE_CLASS } from './listbox-core';
|
|
25
|
+
// 仅为副作用保留:hint-tips 模块加载时注册提示委托(原先随常量导入一并加载,加载顺序不变)
|
|
26
|
+
import './hint-tips';
|
|
27
|
+
import { KIT_ATTR_CHECK_BOX, KIT_ATTR_CHIP, KIT_ATTR_CHIP_REMOVE, KIT_ATTR_KEY, KIT_ATTR_TIP, KIT_ATTR_TOGGLE, KIT_ATTR_VALUE } from '../shared/dom-attrs';
|
|
21
28
|
import {
|
|
22
29
|
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
23
|
-
applyCommon, applyDisabled, bool, createKitController, joinClass, nextUid, num, setAttr,
|
|
30
|
+
applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, nextUid, num, setAttr, setBoolAttr, str, withInvalid,
|
|
31
|
+
kitControlSizeOf, kitMarkDataState, kitMarkInteract, kitReadProps, kitReportSelf,
|
|
24
32
|
type KitApi, type KitProps, type KitSize,
|
|
25
33
|
} from './shared';
|
|
26
34
|
import {
|
|
27
|
-
EMPTY_ROW_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES, KIT_DROPDOWN_PANEL_MAX_CLASS,
|
|
35
|
+
EMPTY_ROW_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES, KIT_DROPDOWN_PANEL_MAX_CLASS, isImeComposing,
|
|
28
36
|
syncDropdown, releaseDropdown, cssEscape, createListNav, onOutsidePress, scrollIntoViewIfAny, type ListNav,
|
|
29
37
|
} from './popup';
|
|
30
38
|
|
|
31
39
|
// ---- Tailwind 类常量与候选类清单 ----
|
|
32
40
|
|
|
33
41
|
const ROOT_CLASS = 'relative block w-full';
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
const ROOT_OFF_CLASS = 'relative block w-full cursor-not-allowed';
|
|
43
|
+
// 触发框 / 搜索框的边 = 控件轮廓出口(KT-B1 / §4 C6,外框为 div[role=combobox] 走 wrapper: true 避免非法 <button> 嵌套 <button>);已选芯片浅底无描边
|
|
44
|
+
const EDGE = kitControlEdgeRecipe({ wrapper: true });
|
|
45
|
+
const EDGE_STILL = kitControlEdgeRecipe({ wrapper: true, hover: false });
|
|
46
|
+
const EDGE_DISABLED = mergeClass(EDGE_STILL, KIT_DIVIDER_COLOR_CLASS);
|
|
47
|
+
const TRIGGER_BASE = mergeClass(mergeClass('flex w-full cursor-pointer items-center justify-between gap-2 rounded-control bg-surface text-fg transition-colors', EDGE), KIT_FOCUS_RING.control);
|
|
48
|
+
const TRIGGER_OFF_BASE = mergeClass('flex w-full cursor-not-allowed items-center justify-between gap-2 rounded-control bg-control-disabled text-fg-disabled', EDGE_DISABLED);
|
|
49
|
+
const TRIGGER_RO_BASE = mergeClass(mergeClass('flex w-full cursor-default items-center justify-between gap-2 rounded-control text-fg transition-colors', EDGE_STILL), mergeClass(kitWellRecipe(), KIT_FOCUS_RING.control));
|
|
36
50
|
const TRIGGER_CLASS: Record<KitSize, string> = {
|
|
37
|
-
sm:
|
|
38
|
-
md:
|
|
39
|
-
lg:
|
|
51
|
+
sm: `${TRIGGER_BASE} min-h-control-sm px-2.5 text-xs`,
|
|
52
|
+
md: `${TRIGGER_BASE} min-h-8 px-3 text-sm`,
|
|
53
|
+
lg: `${TRIGGER_BASE} min-h-10 px-4 text-base`,
|
|
40
54
|
};
|
|
41
|
-
const
|
|
55
|
+
const TRIGGER_OFF_CLASS: Record<KitSize, string> = {
|
|
56
|
+
sm: `${TRIGGER_OFF_BASE} min-h-control-sm px-2.5 text-xs`,
|
|
57
|
+
md: `${TRIGGER_OFF_BASE} min-h-8 px-3 text-sm`,
|
|
58
|
+
lg: `${TRIGGER_OFF_BASE} min-h-10 px-4 text-base`,
|
|
59
|
+
};
|
|
60
|
+
const TRIGGER_RO_CLASS: Record<KitSize, string> = {
|
|
61
|
+
sm: `${TRIGGER_RO_BASE} min-h-control-sm px-2.5 text-xs`,
|
|
62
|
+
md: `${TRIGGER_RO_BASE} min-h-8 px-3 text-sm`,
|
|
63
|
+
lg: `${TRIGGER_RO_BASE} min-h-10 px-4 text-base`,
|
|
64
|
+
};
|
|
65
|
+
const PLACEHOLDER_CLASS = 'min-w-0 flex-1 truncate text-start text-fg-subtle';
|
|
66
|
+
const PLACEHOLDER_OFF_CLASS = 'min-w-0 flex-1 truncate text-start text-fg-disabled';
|
|
67
|
+
const SINGLE_VALUE_CLASS = 'min-w-0 flex-1 truncate text-start';
|
|
42
68
|
const VALUE_CLASS = 'flex min-w-0 flex-1 flex-wrap items-center gap-1 text-start';
|
|
43
|
-
const CHIP_CLASS = '
|
|
44
|
-
const
|
|
69
|
+
const CHIP_CLASS = mergeClass(kitClosedValueRecipe('neutral'), 'max-w-full gap-1');
|
|
70
|
+
const CHIP_TEXT_CLASS = 'truncate';
|
|
71
|
+
const MORE_CHIP_CLASS = 'cursor-default';
|
|
72
|
+
const TAIL_CLASS = 'inline-flex shrink-0 items-center gap-1';
|
|
73
|
+
const CARET_CLASS = 'inline-flex shrink-0 text-fg-subtle motion-safe:transition-transform';
|
|
74
|
+
const CARET_OFF_CLASS = 'inline-flex shrink-0 text-fg-disabled motion-safe:transition-transform';
|
|
75
|
+
// 清除钮随下拉箭头一起位于触发框右侧弹性尾槽内,避免绝对定位压住最右多选芯片(PW-1 R1-P1-01)
|
|
76
|
+
const CLEAR_CLASS = mergeClass(
|
|
77
|
+
'inline-flex shrink-0 border-0 bg-transparent cursor-pointer items-center justify-center rounded-item p-0.5 text-fg-subtle transition-colors hover:text-fg',
|
|
78
|
+
KIT_FOCUS_RING.item,
|
|
79
|
+
);
|
|
45
80
|
const HIDDEN_CLASS = 'hidden';
|
|
81
|
+
// 隐藏的可交互节点也带焦点环出口(清除钮 = 集合项宿主,搜索框 = 输入类宿主),G121 ⑥
|
|
82
|
+
const HIDDEN_CLEAR_CLASS = mergeClass('hidden', KIT_FOCUS_RING.item);
|
|
83
|
+
const HIDDEN_SEARCH_CLASS = mergeClass('hidden', KIT_FOCUS_RING.control);
|
|
46
84
|
const STATUS_CLASS = 'sr-only';
|
|
47
85
|
const PANEL_BASE = mergeClass(`absolute z-10 flex ${KIT_DROPDOWN_PANEL_MAX_CLASS} w-full flex-col gap-1 overflow-auto p-1`, kitSurfaceRecipe('raised'));
|
|
48
86
|
const SEARCH_CLASS = kitControlRecipe();
|
|
49
87
|
const TREE_CLASS = 'flex flex-col';
|
|
50
88
|
const TOGGLE_CLASS = 'w-4 shrink-0 text-fg-subtle';
|
|
51
89
|
const CHECK_CLASS = 'pointer-events-none';
|
|
52
|
-
const ROW_BASE = 'flex items-center gap-2 py-1 pe-2 text-sm
|
|
90
|
+
const ROW_BASE = mergeClass('flex items-center gap-2 rounded-item py-1 pe-2 text-sm', KIT_FOCUS_RING.item);
|
|
91
|
+
const ROW_TEXT_CLASS = 'min-w-0 flex-1 truncate';
|
|
53
92
|
const ROW_STATE = {
|
|
54
93
|
idle: 'cursor-pointer text-fg hover:bg-state-layer-hover active:bg-state-layer-press',
|
|
55
|
-
selected: 'cursor-pointer
|
|
56
|
-
|
|
94
|
+
selected: mergeClass('cursor-pointer', kitSelectedRecipe()),
|
|
95
|
+
// 键盘当前项 = 悬停层(不是井)
|
|
96
|
+
cursor: 'cursor-pointer bg-state-layer-hover text-fg',
|
|
57
97
|
disabled: 'cursor-not-allowed text-fg-subtle',
|
|
58
98
|
} as const;
|
|
59
99
|
type RowState = keyof typeof ROW_STATE;
|
|
@@ -61,14 +101,13 @@ type RowState = keyof typeof ROW_STATE;
|
|
|
61
101
|
const PAD = ['ps-2', 'ps-6', 'ps-10', 'ps-14', 'ps-18', 'ps-22'] as const;
|
|
62
102
|
|
|
63
103
|
/** 本组件自带的类(并入基础组件候选类清单) */
|
|
64
|
-
export const KIT_TREE_SELECT_CLASS_CANDIDATES: readonly string[] =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
]);
|
|
104
|
+
export const KIT_TREE_SELECT_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
105
|
+
ROOT_CLASS, ROOT_OFF_CLASS, PLACEHOLDER_CLASS, PLACEHOLDER_OFF_CLASS, SINGLE_VALUE_CLASS, VALUE_CLASS, CHIP_CLASS, CHIP_TEXT_CLASS, CHIP_REMOVE_CLASS, MORE_CHIP_CLASS,
|
|
106
|
+
TAIL_CLASS, CARET_CLASS, CARET_OFF_CLASS, CLEAR_CLASS, HIDDEN_CLASS, HIDDEN_CLEAR_CLASS, HIDDEN_SEARCH_CLASS, PANEL_BASE, SEARCH_CLASS, TREE_CLASS,
|
|
107
|
+
TOGGLE_CLASS, CHECK_CLASS, ROW_BASE, ROW_TEXT_CLASS, EMPTY_ROW_CLASS, STATUS_CLASS,
|
|
108
|
+
Object.values(TRIGGER_CLASS), Object.values(TRIGGER_OFF_CLASS), Object.values(TRIGGER_RO_CLASS), Object.values(ROW_STATE), PAD, FIELD_INVALID_CLASS,
|
|
109
|
+
KIT_ICON_CLASS_CANDIDATES, KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
110
|
+
);
|
|
72
111
|
|
|
73
112
|
|
|
74
113
|
// ---- 数据规整:树节点构建、展平、叶子、选中键与勾选态(纯函数) ----
|
|
@@ -140,8 +179,16 @@ function flatten(nodes: readonly TNode[]): TNode[] {
|
|
|
140
179
|
}
|
|
141
180
|
|
|
142
181
|
function leavesOf(node: TNode): TNode[] {
|
|
143
|
-
|
|
144
|
-
|
|
182
|
+
const out: TNode[] = [];
|
|
183
|
+
const walk = (n: TNode): void => {
|
|
184
|
+
if (n.children.length === 0) {
|
|
185
|
+
if (!n.disabled) out.push(n);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
for (const c of n.children) walk(c);
|
|
189
|
+
};
|
|
190
|
+
walk(node);
|
|
191
|
+
return out;
|
|
145
192
|
}
|
|
146
193
|
|
|
147
194
|
function canEdit(p: KitProps): boolean {
|
|
@@ -163,34 +210,56 @@ function refId(v: unknown): number {
|
|
|
163
210
|
return id;
|
|
164
211
|
}
|
|
165
212
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
213
|
+
/** 线性 O(N) 自底向上计算 cascade 勾选态,消除逐行递归 flatMap 的 O(N^2) 开销 */
|
|
214
|
+
function computeCascadeStates(nodes: readonly TNode[], selected: ReadonlySet<string>): Map<string, 'on' | 'off' | 'mixed'> {
|
|
215
|
+
const states = new Map<string, 'on' | 'off' | 'mixed'>();
|
|
216
|
+
const visit = (node: TNode): { total: number; picked: number } => {
|
|
217
|
+
if (node.children.length === 0) {
|
|
218
|
+
const on = selected.has(node.key);
|
|
219
|
+
states.set(node.key, on ? 'on' : 'off');
|
|
220
|
+
if (node.disabled) return { total: 0, picked: 0 };
|
|
221
|
+
return { total: 1, picked: on ? 1 : 0 };
|
|
222
|
+
}
|
|
223
|
+
let total = 0;
|
|
224
|
+
let picked = 0;
|
|
225
|
+
for (const child of node.children) {
|
|
226
|
+
const sub = visit(child);
|
|
227
|
+
total += sub.total;
|
|
228
|
+
picked += sub.picked;
|
|
229
|
+
}
|
|
230
|
+
const state: 'on' | 'off' | 'mixed' = total > 0 && picked === total ? 'on' : picked > 0 ? 'mixed' : 'off';
|
|
231
|
+
states.set(node.key, state);
|
|
232
|
+
return { total, picked };
|
|
233
|
+
};
|
|
234
|
+
for (const rootNode of nodes) visit(rootNode);
|
|
235
|
+
return states;
|
|
172
236
|
}
|
|
173
237
|
|
|
174
238
|
// ---- 组件 ----
|
|
175
239
|
|
|
176
240
|
interface Ui {
|
|
177
|
-
trigger:
|
|
241
|
+
trigger: HTMLElement;
|
|
178
242
|
valueEl: HTMLElement;
|
|
243
|
+
caret: HTMLElement;
|
|
179
244
|
clear: HTMLElement;
|
|
180
245
|
panel: HTMLElement;
|
|
181
246
|
search: HTMLInputElement;
|
|
182
247
|
tree: HTMLElement;
|
|
183
248
|
/** 常驻的 live region(视觉隐藏),过滤无结果时写入提示 */
|
|
184
249
|
status: HTMLElement;
|
|
250
|
+
hiddenEls: HTMLInputElement[];
|
|
185
251
|
listId: string;
|
|
186
252
|
open: boolean;
|
|
253
|
+
immediateClose: boolean;
|
|
187
254
|
query: string;
|
|
188
255
|
composing: boolean;
|
|
189
256
|
cursor: string | null;
|
|
190
257
|
expanded: Set<string>;
|
|
191
258
|
dataSig: string;
|
|
192
259
|
nodes: TNode[];
|
|
260
|
+
flat: TNode[];
|
|
193
261
|
byKey: Map<string, TNode>;
|
|
262
|
+
rowByKey: Map<string, HTMLElement>;
|
|
194
263
|
api: KitApi;
|
|
195
264
|
nav: ListNav;
|
|
196
265
|
dispose(): void;
|
|
@@ -210,7 +279,8 @@ function sync(ui: Ui, p: KitProps): void {
|
|
|
210
279
|
if (sig === ui.dataSig) return;
|
|
211
280
|
ui.dataSig = sig;
|
|
212
281
|
ui.nodes = buildNodes(p.options, map);
|
|
213
|
-
ui.
|
|
282
|
+
ui.flat = flatten(ui.nodes);
|
|
283
|
+
ui.byKey = new Map(ui.flat.map((n) => [n.key, n]));
|
|
214
284
|
if (p.expand_all !== false) for (const n of ui.byKey.values()) if (n.children.length > 0) ui.expanded.add(n.key);
|
|
215
285
|
for (const k of [...ui.expanded]) if (!ui.byKey.has(k)) ui.expanded.delete(k);
|
|
216
286
|
if (ui.cursor !== null && !ui.byKey.has(ui.cursor)) ui.cursor = null;
|
|
@@ -242,47 +312,100 @@ function visibleRows(ui: Ui): TNode[] {
|
|
|
242
312
|
|
|
243
313
|
function paintValue(ui: Ui, p: KitProps): void {
|
|
244
314
|
const multiple = bool(p.multiple);
|
|
315
|
+
const editable = canEdit(p);
|
|
316
|
+
const disabled = bool(p.disabled);
|
|
245
317
|
const keys = selectedKeys(p, multiple).filter((k) => ui.byKey.has(k));
|
|
246
318
|
ui.valueEl.textContent = '';
|
|
247
319
|
if (keys.length === 0) {
|
|
248
|
-
ui.valueEl.className = PLACEHOLDER_CLASS;
|
|
320
|
+
ui.valueEl.className = disabled ? PLACEHOLDER_OFF_CLASS : PLACEHOLDER_CLASS;
|
|
249
321
|
ui.valueEl.textContent = str(p.placeholder, kitText('soma.kit.please_select', undefined, ui.valueEl));
|
|
250
322
|
return;
|
|
251
323
|
}
|
|
252
324
|
if (!multiple) {
|
|
253
|
-
ui.valueEl.className =
|
|
325
|
+
ui.valueEl.className = SINGLE_VALUE_CLASS;
|
|
254
326
|
ui.valueEl.textContent = ui.byKey.get(keys[0] as string)?.label ?? '';
|
|
255
327
|
return;
|
|
256
328
|
}
|
|
257
329
|
ui.valueEl.className = VALUE_CLASS;
|
|
258
|
-
const max = num(p.max_tags);
|
|
330
|
+
const max = num(p.limit_tags) || num(p.max_tags);
|
|
259
331
|
const shown = max !== null && max > 0 ? keys.slice(0, Math.floor(max)) : keys;
|
|
260
332
|
for (const k of shown) {
|
|
261
333
|
const chip = document.createElement('span');
|
|
262
334
|
chip.className = CHIP_CLASS;
|
|
263
|
-
|
|
264
|
-
|
|
335
|
+
chip.setAttribute(KIT_ATTR_CHIP, k);
|
|
336
|
+
const labelText = ui.byKey.get(k)?.label ?? k;
|
|
337
|
+
const text = document.createElement('span');
|
|
338
|
+
text.className = CHIP_TEXT_CLASS;
|
|
339
|
+
text.textContent = labelText;
|
|
340
|
+
chip.appendChild(text);
|
|
341
|
+
if (editable) {
|
|
342
|
+
const rm = document.createElement('button');
|
|
343
|
+
rm.type = 'button';
|
|
344
|
+
rm.className = CHIP_REMOVE_CLASS;
|
|
345
|
+
rm.tabIndex = -1;
|
|
346
|
+
rm.setAttribute(KIT_ATTR_CHIP_REMOVE, k);
|
|
347
|
+
rm.setAttribute('aria-label', kitText('soma.kit.remove_named', { name: labelText }, ui.valueEl));
|
|
348
|
+
rm.appendChild(kitIcon('close', 'xs'));
|
|
349
|
+
chip.appendChild(rm);
|
|
350
|
+
}
|
|
265
351
|
ui.valueEl.appendChild(chip);
|
|
266
352
|
}
|
|
267
353
|
if (shown.length < keys.length) {
|
|
354
|
+
const hiddenCount = keys.length - shown.length;
|
|
268
355
|
const more = document.createElement('span');
|
|
269
|
-
more.className = CHIP_CLASS;
|
|
270
|
-
|
|
271
|
-
more.textContent = `+${
|
|
356
|
+
more.className = mergeClass(CHIP_CLASS, MORE_CHIP_CLASS);
|
|
357
|
+
more.setAttribute(KIT_ATTR_CHIP, '');
|
|
358
|
+
more.textContent = `+${hiddenCount}`;
|
|
359
|
+
const rest = keys.slice(shown.length).map((k) => ui.byKey.get(k)?.label ?? k).join(kitText('soma.kit.list_sep', undefined, ui.valueEl));
|
|
360
|
+
more.tabIndex = 0;
|
|
361
|
+
more.setAttribute('aria-label', `+${hiddenCount}: ${rest}`);
|
|
362
|
+
more.setAttribute(KIT_ATTR_TIP, rest);
|
|
272
363
|
ui.valueEl.appendChild(more);
|
|
273
364
|
}
|
|
274
365
|
}
|
|
275
366
|
|
|
367
|
+
function paintHidden(root: HTMLElement, ui: Ui, p: KitProps): void {
|
|
368
|
+
const name = str(p.name);
|
|
369
|
+
if (name === '') {
|
|
370
|
+
while (ui.hiddenEls.length > 0) ui.hiddenEls.pop()!.remove();
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const multiple = bool(p.multiple);
|
|
374
|
+
const keys = selectedKeys(p, multiple);
|
|
375
|
+
const vals = multiple ? (keys.length > 0 ? keys : ['']) : [keys[0] ?? ''];
|
|
376
|
+
while (ui.hiddenEls.length > vals.length) ui.hiddenEls.pop()!.remove();
|
|
377
|
+
while (ui.hiddenEls.length < vals.length) {
|
|
378
|
+
const h = document.createElement('input');
|
|
379
|
+
h.type = 'hidden';
|
|
380
|
+
h.setAttribute(KIT_ATTR_VALUE, '');
|
|
381
|
+
root.appendChild(h);
|
|
382
|
+
ui.hiddenEls.push(h);
|
|
383
|
+
}
|
|
384
|
+
const off = bool(p.disabled);
|
|
385
|
+
vals.forEach((v, i) => {
|
|
386
|
+
const h = ui.hiddenEls[i]!;
|
|
387
|
+
if (h.value !== v) h.value = v;
|
|
388
|
+
setAttr(h, 'name', name);
|
|
389
|
+
setBoolAttr(h, 'disabled', off);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function rowClassOf(level: number, rowState: RowState): string {
|
|
394
|
+
return `${PAD[Math.min(level, PAD.length) - 1]} ${ROW_BASE} ${ROW_STATE[rowState]}`;
|
|
395
|
+
}
|
|
396
|
+
|
|
276
397
|
function paintTree(ui: Ui, p: KitProps): void {
|
|
277
398
|
const multiple = bool(p.multiple);
|
|
278
399
|
const cascade = multiple && bool(p.cascade);
|
|
279
400
|
const selected = new Set(selectedKeys(p, multiple));
|
|
401
|
+
const cascadeStates = cascade ? computeCascadeStates(ui.nodes, selected) : null;
|
|
280
402
|
const rows = visibleRows(ui);
|
|
281
403
|
const inputFocus = p.searchable === true && document.activeElement === ui.search;
|
|
282
404
|
const hadFocus = ui.tree.contains(document.activeElement);
|
|
283
405
|
const live = ui.cursor !== null && rows.some((n) => n.key === ui.cursor);
|
|
284
406
|
const tabbable = live ? ui.cursor : (rows.find((n) => !n.disabled)?.key ?? null);
|
|
285
407
|
ui.tree.textContent = '';
|
|
408
|
+
ui.rowByKey.clear();
|
|
286
409
|
let activeId = '';
|
|
287
410
|
if (rows.length === 0) {
|
|
288
411
|
const empty = document.createElement('div');
|
|
@@ -299,7 +422,7 @@ function paintTree(ui: Ui, p: KitProps): void {
|
|
|
299
422
|
const id = `${ui.listId}-${index}`;
|
|
300
423
|
const branch = n.children.length > 0;
|
|
301
424
|
const isOpen = branch && (ui.query.trim() !== '' || ui.expanded.has(n.key));
|
|
302
|
-
const state =
|
|
425
|
+
const state: 'on' | 'off' | 'mixed' = cascadeStates ? (cascadeStates.get(n.key) ?? 'off') : (selected.has(n.key) ? 'on' : 'off');
|
|
303
426
|
const rowState: RowState = n.disabled ? 'disabled' : !multiple && state === 'on' ? 'selected' : (inputFocus && n.key === ui.cursor ? 'cursor' : 'idle');
|
|
304
427
|
li.id = id;
|
|
305
428
|
li.setAttribute('role', 'treeitem');
|
|
@@ -308,66 +431,140 @@ function paintTree(ui: Ui, p: KitProps): void {
|
|
|
308
431
|
if (multiple) li.setAttribute('aria-checked', state === 'mixed' ? 'mixed' : state === 'on' ? 'true' : 'false');
|
|
309
432
|
else li.setAttribute('aria-selected', state === 'on' ? 'true' : 'false');
|
|
310
433
|
if (n.disabled) li.setAttribute('aria-disabled', 'true');
|
|
311
|
-
li.setAttribute(
|
|
434
|
+
li.setAttribute(KIT_ATTR_KEY, n.key);
|
|
312
435
|
li.tabIndex = !inputFocus && n.key === tabbable ? 0 : -1;
|
|
313
|
-
li.className =
|
|
436
|
+
li.className = rowClassOf(n.level, rowState);
|
|
437
|
+
// 交互状态只自报选中(含多选勾上)与激活(键盘当前项);半选、禁用走 aria-checked / aria-disabled
|
|
438
|
+
kitMarkInteract(li, 'selected', state === 'on');
|
|
439
|
+
kitMarkInteract(li, 'current', n.key === ui.cursor);
|
|
314
440
|
const toggle = document.createElement('span');
|
|
315
441
|
toggle.className = TOGGLE_CLASS;
|
|
316
442
|
toggle.setAttribute('aria-hidden', 'true');
|
|
317
|
-
toggle.setAttribute(
|
|
443
|
+
toggle.setAttribute(KIT_ATTR_TOGGLE, '');
|
|
318
444
|
if (branch) toggle.appendChild(kitIcon(isOpen ? 'chevron-down' : 'chevron-right', 'sm', 'rtl:-scale-x-100'));
|
|
319
445
|
li.appendChild(toggle);
|
|
320
446
|
if (multiple) {
|
|
321
|
-
// 仅展示:自绘勾选标记(check-core,半选 = indeterminate
|
|
447
|
+
// 仅展示:自绘勾选标记(check-core,半选 = indeterminate),显式补齐 data-kit-check-box 防 Portal 下胶囊主题变圆
|
|
322
448
|
const box = createCheck(document, 'checkbox', { checked: state === 'mixed' ? 'mixed' : state === 'on', disabled: n.disabled, extra: CHECK_CLASS });
|
|
323
449
|
const boxInput = markInput(box);
|
|
324
450
|
if (boxInput) {
|
|
325
451
|
boxInput.tabIndex = -1;
|
|
326
452
|
boxInput.setAttribute('aria-hidden', 'true');
|
|
327
453
|
}
|
|
454
|
+
const checkVisual = (boxInput?.nextElementSibling ?? box.querySelector('span')) as HTMLElement | null;
|
|
455
|
+
if (checkVisual && !checkVisual.hasAttribute(KIT_ATTR_CHECK_BOX)) {
|
|
456
|
+
checkVisual.setAttribute(KIT_ATTR_CHECK_BOX, '');
|
|
457
|
+
}
|
|
328
458
|
li.appendChild(box);
|
|
329
459
|
}
|
|
330
460
|
const label = document.createElement('span');
|
|
461
|
+
label.className = ROW_TEXT_CLASS;
|
|
331
462
|
label.textContent = n.label;
|
|
332
463
|
li.appendChild(label);
|
|
464
|
+
ui.rowByKey.set(n.key, li);
|
|
333
465
|
if (inputFocus && n.key === ui.cursor) activeId = id;
|
|
334
466
|
ui.tree.appendChild(li);
|
|
335
467
|
});
|
|
336
468
|
setAttr(ui.search, 'aria-activedescendant', activeId);
|
|
337
469
|
if (activeId !== '') scrollIntoViewIfAny(ui.tree.querySelector(`#${cssEscape(activeId)}`));
|
|
338
470
|
if (hadFocus && !inputFocus && ui.cursor !== null) {
|
|
339
|
-
const el = ui.
|
|
471
|
+
const el = ui.rowByKey.get(ui.cursor);
|
|
340
472
|
el?.focus();
|
|
341
473
|
}
|
|
342
474
|
}
|
|
343
475
|
|
|
476
|
+
/** 方向键上下移动游标时:仅原地更新旧/新行类名、tabIndex 与 aria-activedescendant,零整树重建 */
|
|
477
|
+
function syncTreeCursor(ui: Ui, nextKey: string | null): void {
|
|
478
|
+
const p = ui.api.props();
|
|
479
|
+
if (!ui.open || ui.rowByKey.size === 0 || (nextKey !== null && !ui.rowByKey.has(nextKey))) {
|
|
480
|
+
ui.cursor = nextKey;
|
|
481
|
+
paintTree(ui, p);
|
|
482
|
+
const el = nextKey !== null ? ui.rowByKey.get(nextKey) : undefined;
|
|
483
|
+
if (document.activeElement !== ui.search) el?.focus();
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const multiple = bool(p.multiple);
|
|
487
|
+
const inputFocus = p.searchable === true && document.activeElement === ui.search;
|
|
488
|
+
const prevKey = ui.cursor;
|
|
489
|
+
ui.cursor = nextKey;
|
|
490
|
+
if (prevKey === null && !inputFocus) {
|
|
491
|
+
for (const prevTab of Array.from(ui.tree.querySelectorAll<HTMLElement>('[role="treeitem"][tabindex="0"]'))) {
|
|
492
|
+
prevTab.tabIndex = -1;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const patchRow = (key: string | null): void => {
|
|
496
|
+
if (key === null) return;
|
|
497
|
+
const li = ui.rowByKey.get(key);
|
|
498
|
+
const n = ui.byKey.get(key);
|
|
499
|
+
if (!li || !n) return;
|
|
500
|
+
const isSel = !multiple && li.getAttribute('aria-selected') === 'true';
|
|
501
|
+
const isActive = key === ui.cursor;
|
|
502
|
+
const rowState: RowState = n.disabled ? 'disabled' : isSel ? 'selected' : (inputFocus && isActive ? 'cursor' : 'idle');
|
|
503
|
+
li.className = rowClassOf(n.level, rowState);
|
|
504
|
+
kitMarkInteract(li, 'current', isActive);
|
|
505
|
+
li.tabIndex = !inputFocus && isActive && !n.disabled ? 0 : -1;
|
|
506
|
+
};
|
|
507
|
+
if (prevKey !== nextKey) patchRow(prevKey);
|
|
508
|
+
patchRow(nextKey);
|
|
509
|
+
const nextEl = nextKey !== null ? ui.rowByKey.get(nextKey) : undefined;
|
|
510
|
+
setAttr(ui.search, 'aria-activedescendant', inputFocus && nextEl ? nextEl.id : '');
|
|
511
|
+
if (nextEl) {
|
|
512
|
+
if (typeof nextEl.scrollIntoView === 'function') nextEl.scrollIntoView({ block: 'nearest' });
|
|
513
|
+
if (!inputFocus) nextEl.focus();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
344
517
|
function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
|
|
345
518
|
sync(ui, p);
|
|
519
|
+
const disabled = bool(p.disabled);
|
|
520
|
+
const readonly = bool(p.readonly);
|
|
346
521
|
const editable = canEdit(p);
|
|
347
522
|
const multiple = bool(p.multiple);
|
|
348
|
-
|
|
349
|
-
|
|
523
|
+
const size = kitControlSizeOf(p, kitReadProps(p));
|
|
524
|
+
root.className = joinClass(disabled ? ROOT_OFF_CLASS : ROOT_CLASS, p.class);
|
|
525
|
+
// 高度档:组件自己非缺省的 size 优先,否则取页面线的 kit.controlSize
|
|
526
|
+
const triggerBase = disabled ? TRIGGER_OFF_CLASS[size] : readonly ? TRIGGER_RO_CLASS[size] : TRIGGER_CLASS[size];
|
|
527
|
+
ui.trigger.className = withInvalid(triggerBase, bool(p.invalid) && !disabled);
|
|
528
|
+
ui.trigger.tabIndex = disabled ? -1 : 0;
|
|
529
|
+
kitMarkDataState(root, readonly ? 'readonly' : 'normal');
|
|
350
530
|
// 质感标记:触发器是带边框的输入外观(field)
|
|
351
531
|
setKitFace(ui.trigger, 'field');
|
|
352
|
-
applyDisabled(ui.trigger,
|
|
353
|
-
if (
|
|
532
|
+
applyDisabled(ui.trigger, disabled);
|
|
533
|
+
if (readonly) ui.trigger.setAttribute('aria-readonly', 'true'); else ui.trigger.removeAttribute('aria-readonly');
|
|
354
534
|
applyCommon(ui.trigger, { ...p, name: '' });
|
|
355
535
|
paintValue(ui, p);
|
|
536
|
+
paintHidden(root, ui, p);
|
|
356
537
|
const hasValue = selectedKeys(p, multiple).length > 0;
|
|
357
|
-
ui.clear.className = editable && hasValue && bool(p.clearable) ? CLEAR_CLASS :
|
|
358
|
-
if (!editable)
|
|
538
|
+
ui.clear.className = editable && hasValue && bool(p.clearable) ? CLEAR_CLASS : HIDDEN_CLEAR_CLASS;
|
|
539
|
+
if (!editable) {
|
|
540
|
+
ui.open = false;
|
|
541
|
+
ui.immediateClose = true;
|
|
542
|
+
}
|
|
359
543
|
ui.trigger.setAttribute('aria-expanded', ui.open ? 'true' : 'false');
|
|
360
|
-
ui.
|
|
361
|
-
|
|
362
|
-
|
|
544
|
+
ui.caret.className = disabled ? CARET_OFF_CLASS : CARET_CLASS;
|
|
545
|
+
ui.caret.classList.toggle('rotate-180', ui.open);
|
|
546
|
+
if (!ui.open) {
|
|
547
|
+
const immediate = ui.immediateClose;
|
|
548
|
+
ui.immediateClose = false;
|
|
549
|
+
syncDropdown(ui.panel, false, PANEL_BASE, undefined, 'start', immediate ? { immediate: true } : undefined);
|
|
550
|
+
}
|
|
551
|
+
ui.search.className = ui.open && bool(p.searchable) ? SEARCH_CLASS : HIDDEN_SEARCH_CLASS;
|
|
363
552
|
// 面板内搜索框带边框(field);隐藏时 display:none,标记无害
|
|
364
553
|
setKitFace(ui.search, 'field');
|
|
365
554
|
ui.search.placeholder = str(p.search_placeholder, kitText('soma.kit.search', undefined, root));
|
|
366
555
|
ui.tree.setAttribute('aria-multiselectable', multiple ? 'true' : 'false');
|
|
367
556
|
if (ui.open) {
|
|
368
557
|
paintTree(ui, p);
|
|
369
|
-
syncDropdown(ui.panel, true, PANEL_BASE
|
|
370
|
-
|
|
558
|
+
syncDropdown(ui.panel, true, PANEL_BASE, root, 'start', {
|
|
559
|
+
onEscape: () => {
|
|
560
|
+
if (ui.composing) return;
|
|
561
|
+
closePanel(ui, true, true);
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
} else {
|
|
565
|
+
ui.rowByKey.clear();
|
|
566
|
+
ui.status.textContent = '';
|
|
567
|
+
}
|
|
371
568
|
}
|
|
372
569
|
|
|
373
570
|
function emitValue(ui: Ui, value: unknown): void {
|
|
@@ -384,7 +581,7 @@ function activate(ui: Ui, key: string): void {
|
|
|
384
581
|
const multiple = bool(p.multiple);
|
|
385
582
|
if (!multiple) {
|
|
386
583
|
emitValue(ui, node.value);
|
|
387
|
-
closePanel(ui, true);
|
|
584
|
+
closePanel(ui, true, true);
|
|
388
585
|
return;
|
|
389
586
|
}
|
|
390
587
|
const cascade = bool(p.cascade);
|
|
@@ -396,12 +593,23 @@ function activate(ui: Ui, key: string): void {
|
|
|
396
593
|
} else if (current.has(key)) current.delete(key);
|
|
397
594
|
else current.add(key);
|
|
398
595
|
// 树序输出;树里没有的旧值原样保留在前面
|
|
399
|
-
const known =
|
|
596
|
+
const known = ui.flat;
|
|
400
597
|
const unknown = selectedKeys(p, true).filter((k) => !ui.byKey.has(k));
|
|
401
598
|
emitValue(ui, [...unknown, ...known.filter((n) => current.has(n.key)).map((n) => n.value)]);
|
|
402
599
|
paint(ui.trigger.parentElement as HTMLElement, p, ui);
|
|
403
600
|
}
|
|
404
601
|
|
|
602
|
+
function removeChipKey(ui: Ui, key: string): void {
|
|
603
|
+
const p = ui.api.props();
|
|
604
|
+
if (!canEdit(p) || !bool(p.multiple)) return;
|
|
605
|
+
const current = new Set(selectedKeys(p, true));
|
|
606
|
+
if (!current.has(key)) return;
|
|
607
|
+
current.delete(key);
|
|
608
|
+
const unknown = selectedKeys(p, true).filter((k) => !ui.byKey.has(k) && current.has(k));
|
|
609
|
+
emitValue(ui, [...unknown, ...ui.flat.filter((n) => current.has(n.key)).map((n) => n.value)]);
|
|
610
|
+
paint(ui.trigger.parentElement as HTMLElement, p, ui);
|
|
611
|
+
}
|
|
612
|
+
|
|
405
613
|
function setExpanded(ui: Ui, key: string, on: boolean): void {
|
|
406
614
|
const node = ui.byKey.get(key);
|
|
407
615
|
if (!node || node.children.length === 0) return;
|
|
@@ -427,14 +635,15 @@ function openPanel(ui: Ui): void {
|
|
|
427
635
|
paint(ui.trigger.parentElement as HTMLElement, p, ui);
|
|
428
636
|
if (bool(p.searchable)) ui.search.focus();
|
|
429
637
|
else if (ui.cursor !== null) {
|
|
430
|
-
const el = ui.tree.querySelector<HTMLElement>(`[
|
|
638
|
+
const el = ui.tree.querySelector<HTMLElement>(`[${KIT_ATTR_KEY}="${cssEscape(ui.cursor)}"]`);
|
|
431
639
|
el?.focus();
|
|
432
640
|
}
|
|
433
641
|
}
|
|
434
642
|
|
|
435
|
-
function closePanel(ui: Ui, refocus: boolean): void {
|
|
643
|
+
function closePanel(ui: Ui, refocus: boolean, immediate = false): void {
|
|
436
644
|
if (!ui.open) return;
|
|
437
645
|
ui.open = false;
|
|
646
|
+
ui.immediateClose = immediate;
|
|
438
647
|
ui.query = '';
|
|
439
648
|
ui.search.value = '';
|
|
440
649
|
paint(ui.trigger.parentElement as HTMLElement, ui.api.props(), ui);
|
|
@@ -458,6 +667,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
458
667
|
placeholder: { type: 'string', default: '', desc: '未选时的提示;缺省取内置文案(按页面语言)' },
|
|
459
668
|
clearable: { type: 'boolean', default: false, desc: '有值时显示清除钮:单选抛 change { value: "" },多选抛 change { value: [] }' },
|
|
460
669
|
expand_all: { type: 'boolean', default: true, desc: '数据载入时全部分支展开' },
|
|
670
|
+
limit_tags: { type: 'number', default: 0, desc: '多选触发按钮最多显示几个标签(与 max_tags 同义),其余折成 "+N";0 = 全显示' },
|
|
461
671
|
max_tags: { type: 'number', default: 0, desc: '多选触发按钮最多显示几个标签,其余折成 "+N";0 = 全显示' },
|
|
462
672
|
disabled: { type: 'boolean', default: false },
|
|
463
673
|
readonly: { type: 'boolean', default: false },
|
|
@@ -474,20 +684,28 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
474
684
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
475
685
|
controllerFactory: createKitController(() => ({
|
|
476
686
|
attach(root, api) {
|
|
477
|
-
|
|
478
|
-
trigger
|
|
687
|
+
// 外框使用 div[role=combobox] 而非 <button>,避免多选芯片删除钮造成 HTML5 非法 <button> 嵌套 <button>(DSF-NEW-01)
|
|
688
|
+
const trigger = document.createElement('div');
|
|
689
|
+
trigger.setAttribute('role', 'combobox');
|
|
690
|
+
trigger.tabIndex = 0;
|
|
479
691
|
trigger.setAttribute('aria-haspopup', 'tree');
|
|
480
692
|
const valueEl = document.createElement('span');
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
caret.className = 'inline-flex motion-safe:transition-transform';
|
|
484
|
-
caret.appendChild(kitIcon('chevron-down', 'md'));
|
|
485
|
-
trigger.appendChild(valueEl);
|
|
486
|
-
trigger.appendChild(caret);
|
|
693
|
+
// 触发器里显示当前值的文字节点
|
|
694
|
+
kitReportSelf(valueEl, { part: 'value' });
|
|
487
695
|
const clear = document.createElement('button');
|
|
488
696
|
clear.type = 'button';
|
|
489
697
|
clear.appendChild(kitIcon('close', 'sm'));
|
|
490
698
|
clear.setAttribute('aria-label', kitText('soma.kit.clear', undefined, root));
|
|
699
|
+
const caret = document.createElement('span');
|
|
700
|
+
caret.setAttribute('aria-hidden', 'true');
|
|
701
|
+
caret.className = CARET_CLASS;
|
|
702
|
+
caret.appendChild(kitIcon('chevron-down', 'md'));
|
|
703
|
+
const tail = document.createElement('span');
|
|
704
|
+
tail.className = TAIL_CLASS;
|
|
705
|
+
tail.appendChild(clear);
|
|
706
|
+
tail.appendChild(caret);
|
|
707
|
+
trigger.appendChild(valueEl);
|
|
708
|
+
trigger.appendChild(tail);
|
|
491
709
|
const panel = document.createElement('div');
|
|
492
710
|
const listId = nextUid('kit-treeselect');
|
|
493
711
|
panel.id = listId;
|
|
@@ -508,13 +726,12 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
508
726
|
panel.appendChild(tree);
|
|
509
727
|
panel.appendChild(status);
|
|
510
728
|
root.appendChild(trigger);
|
|
511
|
-
root.appendChild(clear);
|
|
512
729
|
root.appendChild(panel);
|
|
513
730
|
trigger.setAttribute('aria-controls', tree.id);
|
|
514
731
|
|
|
515
732
|
const ui: Ui = {
|
|
516
|
-
trigger, valueEl, clear, panel, search, tree, status, listId, open: false, query: '', composing: false, cursor: null,
|
|
517
|
-
expanded: new Set(), dataSig: '', nodes: [], byKey: new Map(), api, dispose: () => {},
|
|
733
|
+
trigger, valueEl, caret, clear, panel, search, tree, status, hiddenEls: [], listId, open: false, immediateClose: false, query: '', composing: false, cursor: null,
|
|
734
|
+
expanded: new Set(), dataSig: '', nodes: [], flat: [], byKey: new Map(), rowByKey: new Map(), api, dispose: () => {},
|
|
518
735
|
nav: createListNav({
|
|
519
736
|
layout: 'tree',
|
|
520
737
|
host: () => tree,
|
|
@@ -527,10 +744,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
527
744
|
})),
|
|
528
745
|
getCursor: () => ui.cursor,
|
|
529
746
|
setCursor: (key) => {
|
|
530
|
-
ui
|
|
531
|
-
paintTree(ui, api.props());
|
|
532
|
-
const el = ui.tree.querySelector<HTMLElement>(`[data-kit-key="${cssEscape(key)}"]`);
|
|
533
|
-
if (document.activeElement !== ui.search) el?.focus();
|
|
747
|
+
syncTreeCursor(ui, key);
|
|
534
748
|
},
|
|
535
749
|
onActivate: (key) => activate(ui, key),
|
|
536
750
|
onExpand: (key) => setExpanded(ui, key, true),
|
|
@@ -539,21 +753,56 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
539
753
|
};
|
|
540
754
|
uis.set(root, ui);
|
|
541
755
|
|
|
542
|
-
const
|
|
756
|
+
const onTriggerMouseDown = (event: Event): void => {
|
|
757
|
+
const target = event.target as HTMLElement | null;
|
|
758
|
+
if (target?.closest(`[${KIT_ATTR_CHIP_REMOVE}]`)) event.preventDefault();
|
|
759
|
+
};
|
|
760
|
+
const onTriggerClick = (event: Event): void => {
|
|
761
|
+
const target = event.target as HTMLElement | null;
|
|
762
|
+
if (target !== null && (target === clear || clear.contains(target))) return;
|
|
763
|
+
const rm = target?.closest<HTMLElement>(`[${KIT_ATTR_CHIP_REMOVE}]`);
|
|
764
|
+
if (rm) {
|
|
765
|
+
event.preventDefault();
|
|
766
|
+
event.stopPropagation();
|
|
767
|
+
removeChipKey(ui, rm.getAttribute(KIT_ATTR_CHIP_REMOVE) ?? '');
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (target?.closest(`[${KIT_ATTR_TIP}]`)) return;
|
|
771
|
+
if (!canEdit(api.props())) return;
|
|
772
|
+
if (ui.open) closePanel(ui, true);
|
|
773
|
+
else openPanel(ui);
|
|
774
|
+
};
|
|
543
775
|
const onTriggerKeydown = (event: KeyboardEvent): void => {
|
|
544
|
-
|
|
776
|
+
const target = event.target as HTMLElement | null;
|
|
777
|
+
if (target !== null && (target === clear || clear.contains(target))) return;
|
|
778
|
+
if (target?.closest(`[${KIT_ATTR_CHIP_REMOVE}]`)) return;
|
|
779
|
+
if (!canEdit(api.props())) return;
|
|
780
|
+
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && !ui.open) {
|
|
545
781
|
event.preventDefault();
|
|
546
782
|
openPanel(ui);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
786
|
+
event.preventDefault();
|
|
787
|
+
if (ui.open) closePanel(ui, true);
|
|
788
|
+
else openPanel(ui);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (event.key === 'Escape' && ui.open) {
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
event.stopPropagation();
|
|
794
|
+
closePanel(ui, true, true);
|
|
547
795
|
}
|
|
548
796
|
};
|
|
549
|
-
const onClear = (): void => {
|
|
797
|
+
const onClear = (event: Event): void => {
|
|
798
|
+
event.stopPropagation();
|
|
550
799
|
const p = api.props();
|
|
551
800
|
emitValue(ui, bool(p.multiple) ? [] : '');
|
|
552
801
|
// 清除钮随即隐藏,焦点交还触发按钮
|
|
553
802
|
if (canEdit(p)) trigger.focus();
|
|
554
803
|
};
|
|
555
|
-
const onSearchInput = (): void => {
|
|
556
|
-
if (ui.composing) return;
|
|
804
|
+
const onSearchInput = (event?: Event): void => {
|
|
805
|
+
if (ui.composing || (event !== undefined && (event as InputEvent).isComposing)) return;
|
|
557
806
|
ui.query = search.value;
|
|
558
807
|
const rows = visibleRows(ui);
|
|
559
808
|
ui.cursor = rows.find((n) => !n.disabled)?.key ?? null;
|
|
@@ -563,20 +812,21 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
563
812
|
const onCompositionEnd = (): void => { ui.composing = false; onSearchInput(); };
|
|
564
813
|
const onPanelClick = (event: Event): void => {
|
|
565
814
|
const target = event.target as HTMLElement | null;
|
|
566
|
-
const row = target?.closest<HTMLElement>(
|
|
567
|
-
const key = row?.getAttribute(
|
|
815
|
+
const row = target?.closest<HTMLElement>(`[${KIT_ATTR_KEY}]`);
|
|
816
|
+
const key = row?.getAttribute(KIT_ATTR_KEY);
|
|
568
817
|
if (!row || key === null || key === undefined) return;
|
|
569
|
-
if (target?.closest(
|
|
818
|
+
if (target?.closest(`[${KIT_ATTR_TOGGLE}]`)) {
|
|
570
819
|
setExpanded(ui, key, !ui.expanded.has(key));
|
|
571
820
|
return;
|
|
572
821
|
}
|
|
573
822
|
activate(ui, key);
|
|
574
823
|
};
|
|
575
824
|
const onPanelKeydown = (event: KeyboardEvent): void => {
|
|
825
|
+
if (ui.composing || isImeComposing(event)) return;
|
|
576
826
|
if (event.key === 'Escape') {
|
|
577
827
|
event.preventDefault();
|
|
578
828
|
event.stopPropagation();
|
|
579
|
-
closePanel(ui, true);
|
|
829
|
+
closePanel(ui, true, true);
|
|
580
830
|
return;
|
|
581
831
|
}
|
|
582
832
|
if (event.key === 'Tab') {
|
|
@@ -592,7 +842,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
592
842
|
if (ui.nav.handle(event)) event.preventDefault();
|
|
593
843
|
return;
|
|
594
844
|
}
|
|
595
|
-
const key = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
845
|
+
const key = (event.target as HTMLElement | null)?.closest<HTMLElement>(`[${KIT_ATTR_KEY}]`)?.getAttribute(KIT_ATTR_KEY);
|
|
596
846
|
if (ui.cursor === null && key) ui.cursor = key;
|
|
597
847
|
if (ui.nav.handle(event)) event.preventDefault();
|
|
598
848
|
};
|
|
@@ -602,6 +852,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
602
852
|
};
|
|
603
853
|
const offOutside = onOutsidePress(root, () => ui.open, () => closePanel(ui, false));
|
|
604
854
|
|
|
855
|
+
trigger.addEventListener('mousedown', onTriggerMouseDown);
|
|
605
856
|
trigger.addEventListener('click', onTriggerClick);
|
|
606
857
|
trigger.addEventListener('keydown', onTriggerKeydown);
|
|
607
858
|
clear.addEventListener('click', onClear);
|
|
@@ -612,6 +863,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
612
863
|
panel.addEventListener('keydown', onPanelKeydown);
|
|
613
864
|
panel.addEventListener('mousedown', onPanelMouseDown);
|
|
614
865
|
ui.dispose = () => {
|
|
866
|
+
trigger.removeEventListener('mousedown', onTriggerMouseDown);
|
|
615
867
|
trigger.removeEventListener('click', onTriggerClick);
|
|
616
868
|
trigger.removeEventListener('keydown', onTriggerKeydown);
|
|
617
869
|
clear.removeEventListener('click', onClear);
|
|
@@ -626,6 +878,8 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
626
878
|
return () => {
|
|
627
879
|
ui.dispose();
|
|
628
880
|
uis.delete(root);
|
|
881
|
+
for (const h of ui.hiddenEls) h.remove();
|
|
882
|
+
ui.hiddenEls.length = 0;
|
|
629
883
|
trigger.remove();
|
|
630
884
|
clear.remove();
|
|
631
885
|
releaseDropdown(panel, false);
|
|
@@ -636,6 +890,6 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
636
890
|
const ui = uis.get(root);
|
|
637
891
|
if (ui) paint(root, p, ui);
|
|
638
892
|
},
|
|
639
|
-
})),
|
|
893
|
+
}), { self: { level: 'control' } }),
|
|
640
894
|
};
|
|
641
895
|
}
|