soma-kit 0.1.14 → 0.1.16
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/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- 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 -338
- package/spec/generated/kit-page.schema.json +1152 -87
- package/spec/kit-grammar.json +1084 -136
- package/spec/kit-grammar.schema.json +167 -26
- package/src/app/app-config.ts +220 -187
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +200 -22
- package/src/app/define-kit-app.ts +54 -8
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +12 -7
- package/src/app/kit-view-context.ts +50 -3
- 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 +68 -24
- package/src/app/theme-runtime.ts +421 -87
- 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 +107 -59
- package/src/base/anchored-layer.ts +8 -7
- 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 +365 -53
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +147 -32
- package/src/base/check-core.ts +196 -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 +404 -28
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +155 -37
- package/src/base/context-menu.ts +26 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +115 -94
- package/src/base/date.ts +487 -76
- package/src/base/delta.ts +20 -11
- package/src/base/divider.ts +64 -97
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +64 -23
- package/src/base/gap-value.ts +35 -16
- package/src/base/hint-tips.ts +100 -30
- 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 +92 -24
- package/src/base/inline-error.ts +90 -0
- package/src/base/input.ts +174 -38
- package/src/base/kbd.ts +31 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +324 -95
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +58 -22
- package/src/base/menu-button.ts +129 -42
- package/src/base/menu-core.ts +210 -26
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +10 -5
- package/src/base/motion/hover-gallery.ts +19 -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 +143 -27
- package/src/base/overlay-runtime.ts +32 -24
- package/src/base/overlay-shell.ts +186 -0
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +625 -74
- package/src/base/popup.ts +219 -78
- 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 +145 -21
- 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 +60 -18
- package/src/base/relation-cells.ts +541 -0
- package/src/{frames → base}/resize-handle.ts +6 -4
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +99 -56
- package/src/base/select.ts +8 -2
- package/src/base/shared.ts +520 -73
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/status-tone.ts +1 -1
- 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 +129 -55
- package/src/base/tag.ts +203 -91
- package/src/base/text.ts +491 -77
- package/src/base/textarea.ts +89 -40
- package/src/base/time-picker.ts +341 -57
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +346 -89
- package/src/base/upload.ts +612 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +98 -6
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +53 -13
- package/src/biz/auth-panel/compile.ts +14 -4
- package/src/biz/auth-panel/shell.ts +28 -8
- package/src/biz/category-crud/compile.ts +64 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +30 -8
- package/src/biz/checkout-page/compile.ts +38 -4
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +28 -10
- package/src/biz/compose.ts +9 -4
- package/src/biz/data-components.ts +2 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +5 -2
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +36 -20
- package/src/biz/index.ts +5 -4
- package/src/biz/landing-page/compile.ts +4 -3
- package/src/biz/landing-page/shell.ts +25 -5
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +62 -16
- package/src/biz/master-sub/compile.ts +318 -38
- package/src/biz/master-sub/detail-head.ts +145 -21
- package/src/biz/master-sub/index.ts +6 -3
- package/src/biz/master-sub/shell.ts +232 -66
- package/src/biz/multi-board/compile.ts +89 -38
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +25 -9
- package/src/biz/multi-board/prose-fold.ts +17 -13
- package/src/biz/multi-board/shell.ts +153 -38
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +28 -7
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +51 -11
- package/src/biz/page-templates/domain-templates.ts +147 -20
- package/src/biz/page-templates/result-page/compile.ts +5 -2
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +20 -6
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +20 -9
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +30 -14
- package/src/biz/record-detail/compile.ts +43 -12
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +42 -11
- package/src/biz/settings-center/compile.ts +5 -2
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +33 -9
- package/src/biz/shared/action-host.ts +146 -48
- package/src/biz/shared/compile-helpers.ts +134 -32
- package/src/biz/shared/coordinator.ts +727 -163
- 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 +102 -24
- package/src/biz/shared/overlay-shell.ts +97 -116
- 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 +6 -4
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +22 -8
- package/src/biz/standard-crud/compile.ts +213 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +90 -13
- package/src/biz/standard-crud/summary.ts +2 -35
- package/src/biz/step-form/compile.ts +13 -4
- package/src/biz/step-form/hub.ts +168 -49
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +35 -17
- package/src/biz/types.ts +49 -6
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +179 -33
- package/src/cli/kit-init.ts +152 -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/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +461 -273
- package/src/compile/component-candidates.ts +58 -5
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +6 -59
- package/src/compile/index.ts +2 -2
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +44 -13
- 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 +405 -67
- 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/redirect.ts +1 -1
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +786 -0
- package/src/compile/styles.ts +286 -48
- package/src/compile/types.ts +63 -6
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +52 -23
- package/src/data/anchor-nav.ts +77 -16
- package/src/data/approval-flow.ts +217 -126
- package/src/data/assignment-picker.ts +182 -94
- package/src/data/async-result-panel.ts +114 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +150 -24
- package/src/data/calendar.ts +436 -97
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +81 -41
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +1053 -96
- package/src/data/checklist.ts +82 -38
- package/src/data/code-view.ts +296 -44
- package/src/data/comment-thread.ts +611 -86
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +250 -39
- 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 +109 -49
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +38 -18
- package/src/data/embed.ts +143 -8
- package/src/data/engine-ports.ts +135 -0
- package/src/data/field-mapper.ts +116 -54
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +695 -158
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +88 -26
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +640 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +40 -13
- package/src/data/image-viewer.ts +265 -62
- package/src/data/index.ts +75 -6
- package/src/data/item-list.ts +219 -58
- package/src/data/json-view.ts +909 -0
- package/src/data/kanban.ts +346 -91
- 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 +597 -0
- package/src/data/matrix.ts +234 -120
- package/src/data/media-grid.ts +165 -38
- package/src/data/mega-menu.ts +43 -26
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +55 -19
- package/src/data/menu.ts +138 -48
- package/src/data/mockup.ts +37 -25
- package/src/data/modal-dialog.ts +126 -98
- package/src/data/navbar.ts +152 -66
- package/src/data/notice-list.ts +101 -49
- package/src/data/notify-renderer.ts +80 -15
- package/src/data/object-form.ts +1504 -164
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +129 -45
- package/src/data/panel-head.ts +238 -76
- package/src/data/permission-matrix.ts +379 -120
- package/src/data/permission-tree.ts +146 -78
- package/src/data/pricing-table.ts +112 -43
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +67 -32
- package/src/data/record-card.ts +245 -72
- package/src/data/record-picker.ts +61 -28
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +141 -38
- package/src/data/resident.ts +11 -13
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +260 -127
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +384 -105
- package/src/data/rule-builder.ts +136 -81
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +90 -36
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +493 -100
- package/src/data/static-lazy.ts +21 -0
- package/src/data/static-registry.ts +46 -4
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +69 -36
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +134 -47
- package/src/data/system-switcher.ts +53 -24
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +731 -0
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +113 -47
- package/src/data/transfer.ts +204 -47
- package/src/data/tree-table.ts +228 -81
- package/src/data/tree.ts +193 -69
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +248 -98
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +28 -6
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +4 -4
- package/src/frames/inherited-shell.ts +219 -0
- package/src/frames/page-bar.ts +208 -28
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +18 -0
- package/src/frames/shared.ts +73 -26
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +27 -17
- package/src/frames/split-frame/wiring.ts +16 -12
- package/src/frames/tabs-frame/shell.ts +14 -7
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +5 -2
- package/src/frames/workspace-frame/extras.ts +23 -7
- 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 +24 -3
- package/src/frames/workspace-frame/state.ts +42 -8
- package/src/frames/workspace-frame/view.ts +773 -194
- package/src/generated/kit-grammar-runtime.ts +1061 -77
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +210 -5
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +204 -22
- package/src/object-renderer/action-more.ts +66 -19
- package/src/object-renderer/arrange.ts +270 -28
- 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 +459 -103
- package/src/object-renderer/collection-table.ts +406 -59
- package/src/object-renderer/collection.ts +333 -71
- package/src/object-renderer/compile-data.ts +13 -3
- package/src/object-renderer/defaults.ts +14 -5
- package/src/object-renderer/emit-events.ts +46 -20
- package/src/object-renderer/emit-object.ts +35 -6
- package/src/object-renderer/emit-static.ts +831 -153
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +190 -0
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +55 -7
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +124 -0
- 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 +72 -27
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +479 -111
- 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 +437 -130
- package/src/object-renderer/types.ts +100 -17
- 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/app-blocks.ts +66 -0
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +57 -0
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +32 -0
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +93 -26
- package/src/recipes/control.ts +85 -8
- package/src/recipes/desc-list.ts +108 -0
- package/src/recipes/divider.ts +74 -0
- package/src/recipes/emphasis.ts +102 -13
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +6 -5
- package/src/recipes/index.ts +39 -5
- package/src/recipes/inherited-shell.ts +43 -0
- package/src/recipes/json-view.ts +50 -0
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +96 -0
- package/src/recipes/overlay.ts +151 -37
- package/src/recipes/page-width.ts +51 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +38 -20
- 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 +6 -6
- package/src/recipes/state.ts +64 -11
- package/src/recipes/status.ts +21 -20
- package/src/recipes/strip.ts +114 -0
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +40 -7
- package/src/recipes/table-gap.ts +4 -3
- package/src/recipes/table-native-edit.ts +25 -12
- package/src/recipes/table-row.ts +56 -20
- package/src/recipes/tabs.ts +140 -31
- package/src/recipes/text-diff.ts +97 -0
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +72 -5
- package/src/recipes/typography.ts +2 -2
- 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/diagnostics.ts +16 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +292 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +40 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- 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/path-guard.ts +1 -1
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +181 -21
- 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 +563 -28
- package/src/theme/kit-theme.tpl +527 -28
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +538 -176
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +12 -3
- package/src/theme/theme-tokens.ts +1602 -90
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- package/src/frames/list-summary.ts +0 -100
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/base/tree-select.ts
CHANGED
|
@@ -11,46 +11,89 @@
|
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
-
import { kitIcon } from '
|
|
14
|
+
import { KIT_ICON_CLASS_CANDIDATES, kitIcon } from '../shared/icons';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { kitControlEdgeRecipe, kitControlRecipe } from '../recipes/control';
|
|
17
|
+
import { KIT_DIVIDER_COLOR_CLASS } from '../recipes/divider';
|
|
18
|
+
import { mergeClass } from '../shared/merge-class';
|
|
19
|
+
import { kitSurfaceRecipe, kitWellRecipe } from '../recipes/surface';
|
|
20
|
+
import { kitClosedValueRecipe } from '../recipes/field-text';
|
|
21
|
+
import { KIT_FOCUS_RING, kitSelectedRecipe } from '../recipes/state';
|
|
18
22
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
19
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';
|
|
20
28
|
import {
|
|
21
29
|
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
22
|
-
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,
|
|
23
32
|
type KitApi, type KitProps, type KitSize,
|
|
24
33
|
} from './shared';
|
|
25
34
|
import {
|
|
26
|
-
EMPTY_ROW_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
35
|
+
EMPTY_ROW_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES, KIT_DROPDOWN_PANEL_MAX_CLASS, isImeComposing,
|
|
27
36
|
syncDropdown, releaseDropdown, cssEscape, createListNav, onOutsidePress, scrollIntoViewIfAny, type ListNav,
|
|
28
37
|
} from './popup';
|
|
29
38
|
|
|
30
39
|
// ---- Tailwind 类常量与候选类清单 ----
|
|
31
40
|
|
|
32
41
|
const ROOT_CLASS = 'relative block w-full';
|
|
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));
|
|
33
50
|
const TRIGGER_CLASS: Record<KitSize, string> = {
|
|
34
|
-
sm:
|
|
35
|
-
md:
|
|
36
|
-
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`,
|
|
37
54
|
};
|
|
38
|
-
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';
|
|
39
68
|
const VALUE_CLASS = 'flex min-w-0 flex-1 flex-wrap items-center gap-1 text-start';
|
|
40
|
-
const CHIP_CLASS = '
|
|
41
|
-
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
|
+
);
|
|
42
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);
|
|
43
84
|
const STATUS_CLASS = 'sr-only';
|
|
44
|
-
const PANEL_BASE = mergeClass(
|
|
45
|
-
const SEARCH_CLASS =
|
|
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'));
|
|
86
|
+
const SEARCH_CLASS = kitControlRecipe();
|
|
46
87
|
const TREE_CLASS = 'flex flex-col';
|
|
47
88
|
const TOGGLE_CLASS = 'w-4 shrink-0 text-fg-subtle';
|
|
48
89
|
const CHECK_CLASS = 'pointer-events-none';
|
|
49
|
-
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';
|
|
50
92
|
const ROW_STATE = {
|
|
51
93
|
idle: 'cursor-pointer text-fg hover:bg-state-layer-hover active:bg-state-layer-press',
|
|
52
|
-
selected: 'cursor-pointer
|
|
53
|
-
|
|
94
|
+
selected: mergeClass('cursor-pointer', kitSelectedRecipe()),
|
|
95
|
+
// 键盘当前项 = 悬停层(不是井)
|
|
96
|
+
cursor: 'cursor-pointer bg-state-layer-hover text-fg',
|
|
54
97
|
disabled: 'cursor-not-allowed text-fg-subtle',
|
|
55
98
|
} as const;
|
|
56
99
|
type RowState = keyof typeof ROW_STATE;
|
|
@@ -58,14 +101,13 @@ type RowState = keyof typeof ROW_STATE;
|
|
|
58
101
|
const PAD = ['ps-2', 'ps-6', 'ps-10', 'ps-14', 'ps-18', 'ps-22'] as const;
|
|
59
102
|
|
|
60
103
|
/** 本组件自带的类(并入基础组件候选类清单) */
|
|
61
|
-
export const KIT_TREE_SELECT_CLASS_CANDIDATES: readonly string[] =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
]);
|
|
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
|
+
);
|
|
69
111
|
|
|
70
112
|
|
|
71
113
|
// ---- 数据规整:树节点构建、展平、叶子、选中键与勾选态(纯函数) ----
|
|
@@ -137,8 +179,16 @@ function flatten(nodes: readonly TNode[]): TNode[] {
|
|
|
137
179
|
}
|
|
138
180
|
|
|
139
181
|
function leavesOf(node: TNode): TNode[] {
|
|
140
|
-
|
|
141
|
-
|
|
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;
|
|
142
192
|
}
|
|
143
193
|
|
|
144
194
|
function canEdit(p: KitProps): boolean {
|
|
@@ -160,34 +210,56 @@ function refId(v: unknown): number {
|
|
|
160
210
|
return id;
|
|
161
211
|
}
|
|
162
212
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
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;
|
|
169
236
|
}
|
|
170
237
|
|
|
171
238
|
// ---- 组件 ----
|
|
172
239
|
|
|
173
240
|
interface Ui {
|
|
174
|
-
trigger:
|
|
241
|
+
trigger: HTMLElement;
|
|
175
242
|
valueEl: HTMLElement;
|
|
243
|
+
caret: HTMLElement;
|
|
176
244
|
clear: HTMLElement;
|
|
177
245
|
panel: HTMLElement;
|
|
178
246
|
search: HTMLInputElement;
|
|
179
247
|
tree: HTMLElement;
|
|
180
248
|
/** 常驻的 live region(视觉隐藏),过滤无结果时写入提示 */
|
|
181
249
|
status: HTMLElement;
|
|
250
|
+
hiddenEls: HTMLInputElement[];
|
|
182
251
|
listId: string;
|
|
183
252
|
open: boolean;
|
|
253
|
+
immediateClose: boolean;
|
|
184
254
|
query: string;
|
|
185
255
|
composing: boolean;
|
|
186
256
|
cursor: string | null;
|
|
187
257
|
expanded: Set<string>;
|
|
188
258
|
dataSig: string;
|
|
189
259
|
nodes: TNode[];
|
|
260
|
+
flat: TNode[];
|
|
190
261
|
byKey: Map<string, TNode>;
|
|
262
|
+
rowByKey: Map<string, HTMLElement>;
|
|
191
263
|
api: KitApi;
|
|
192
264
|
nav: ListNav;
|
|
193
265
|
dispose(): void;
|
|
@@ -207,7 +279,8 @@ function sync(ui: Ui, p: KitProps): void {
|
|
|
207
279
|
if (sig === ui.dataSig) return;
|
|
208
280
|
ui.dataSig = sig;
|
|
209
281
|
ui.nodes = buildNodes(p.options, map);
|
|
210
|
-
ui.
|
|
282
|
+
ui.flat = flatten(ui.nodes);
|
|
283
|
+
ui.byKey = new Map(ui.flat.map((n) => [n.key, n]));
|
|
211
284
|
if (p.expand_all !== false) for (const n of ui.byKey.values()) if (n.children.length > 0) ui.expanded.add(n.key);
|
|
212
285
|
for (const k of [...ui.expanded]) if (!ui.byKey.has(k)) ui.expanded.delete(k);
|
|
213
286
|
if (ui.cursor !== null && !ui.byKey.has(ui.cursor)) ui.cursor = null;
|
|
@@ -239,47 +312,100 @@ function visibleRows(ui: Ui): TNode[] {
|
|
|
239
312
|
|
|
240
313
|
function paintValue(ui: Ui, p: KitProps): void {
|
|
241
314
|
const multiple = bool(p.multiple);
|
|
315
|
+
const editable = canEdit(p);
|
|
316
|
+
const disabled = bool(p.disabled);
|
|
242
317
|
const keys = selectedKeys(p, multiple).filter((k) => ui.byKey.has(k));
|
|
243
318
|
ui.valueEl.textContent = '';
|
|
244
319
|
if (keys.length === 0) {
|
|
245
|
-
ui.valueEl.className = PLACEHOLDER_CLASS;
|
|
320
|
+
ui.valueEl.className = disabled ? PLACEHOLDER_OFF_CLASS : PLACEHOLDER_CLASS;
|
|
246
321
|
ui.valueEl.textContent = str(p.placeholder, kitText('soma.kit.please_select', undefined, ui.valueEl));
|
|
247
322
|
return;
|
|
248
323
|
}
|
|
249
324
|
if (!multiple) {
|
|
250
|
-
ui.valueEl.className =
|
|
325
|
+
ui.valueEl.className = SINGLE_VALUE_CLASS;
|
|
251
326
|
ui.valueEl.textContent = ui.byKey.get(keys[0] as string)?.label ?? '';
|
|
252
327
|
return;
|
|
253
328
|
}
|
|
254
329
|
ui.valueEl.className = VALUE_CLASS;
|
|
255
|
-
const max = num(p.max_tags);
|
|
330
|
+
const max = num(p.limit_tags) || num(p.max_tags);
|
|
256
331
|
const shown = max !== null && max > 0 ? keys.slice(0, Math.floor(max)) : keys;
|
|
257
332
|
for (const k of shown) {
|
|
258
333
|
const chip = document.createElement('span');
|
|
259
334
|
chip.className = CHIP_CLASS;
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
}
|
|
262
351
|
ui.valueEl.appendChild(chip);
|
|
263
352
|
}
|
|
264
353
|
if (shown.length < keys.length) {
|
|
354
|
+
const hiddenCount = keys.length - shown.length;
|
|
265
355
|
const more = document.createElement('span');
|
|
266
|
-
more.className = CHIP_CLASS;
|
|
267
|
-
|
|
268
|
-
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);
|
|
269
363
|
ui.valueEl.appendChild(more);
|
|
270
364
|
}
|
|
271
365
|
}
|
|
272
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
|
+
|
|
273
397
|
function paintTree(ui: Ui, p: KitProps): void {
|
|
274
398
|
const multiple = bool(p.multiple);
|
|
275
399
|
const cascade = multiple && bool(p.cascade);
|
|
276
400
|
const selected = new Set(selectedKeys(p, multiple));
|
|
401
|
+
const cascadeStates = cascade ? computeCascadeStates(ui.nodes, selected) : null;
|
|
277
402
|
const rows = visibleRows(ui);
|
|
278
403
|
const inputFocus = p.searchable === true && document.activeElement === ui.search;
|
|
279
404
|
const hadFocus = ui.tree.contains(document.activeElement);
|
|
280
405
|
const live = ui.cursor !== null && rows.some((n) => n.key === ui.cursor);
|
|
281
406
|
const tabbable = live ? ui.cursor : (rows.find((n) => !n.disabled)?.key ?? null);
|
|
282
407
|
ui.tree.textContent = '';
|
|
408
|
+
ui.rowByKey.clear();
|
|
283
409
|
let activeId = '';
|
|
284
410
|
if (rows.length === 0) {
|
|
285
411
|
const empty = document.createElement('div');
|
|
@@ -296,7 +422,7 @@ function paintTree(ui: Ui, p: KitProps): void {
|
|
|
296
422
|
const id = `${ui.listId}-${index}`;
|
|
297
423
|
const branch = n.children.length > 0;
|
|
298
424
|
const isOpen = branch && (ui.query.trim() !== '' || ui.expanded.has(n.key));
|
|
299
|
-
const state =
|
|
425
|
+
const state: 'on' | 'off' | 'mixed' = cascadeStates ? (cascadeStates.get(n.key) ?? 'off') : (selected.has(n.key) ? 'on' : 'off');
|
|
300
426
|
const rowState: RowState = n.disabled ? 'disabled' : !multiple && state === 'on' ? 'selected' : (inputFocus && n.key === ui.cursor ? 'cursor' : 'idle');
|
|
301
427
|
li.id = id;
|
|
302
428
|
li.setAttribute('role', 'treeitem');
|
|
@@ -305,66 +431,140 @@ function paintTree(ui: Ui, p: KitProps): void {
|
|
|
305
431
|
if (multiple) li.setAttribute('aria-checked', state === 'mixed' ? 'mixed' : state === 'on' ? 'true' : 'false');
|
|
306
432
|
else li.setAttribute('aria-selected', state === 'on' ? 'true' : 'false');
|
|
307
433
|
if (n.disabled) li.setAttribute('aria-disabled', 'true');
|
|
308
|
-
li.setAttribute(
|
|
434
|
+
li.setAttribute(KIT_ATTR_KEY, n.key);
|
|
309
435
|
li.tabIndex = !inputFocus && n.key === tabbable ? 0 : -1;
|
|
310
|
-
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);
|
|
311
440
|
const toggle = document.createElement('span');
|
|
312
441
|
toggle.className = TOGGLE_CLASS;
|
|
313
442
|
toggle.setAttribute('aria-hidden', 'true');
|
|
314
|
-
toggle.setAttribute(
|
|
443
|
+
toggle.setAttribute(KIT_ATTR_TOGGLE, '');
|
|
315
444
|
if (branch) toggle.appendChild(kitIcon(isOpen ? 'chevron-down' : 'chevron-right', 'sm', 'rtl:-scale-x-100'));
|
|
316
445
|
li.appendChild(toggle);
|
|
317
446
|
if (multiple) {
|
|
318
|
-
// 仅展示:自绘勾选标记(check-core,半选 = indeterminate
|
|
447
|
+
// 仅展示:自绘勾选标记(check-core,半选 = indeterminate),显式补齐 data-kit-check-box 防 Portal 下胶囊主题变圆
|
|
319
448
|
const box = createCheck(document, 'checkbox', { checked: state === 'mixed' ? 'mixed' : state === 'on', disabled: n.disabled, extra: CHECK_CLASS });
|
|
320
449
|
const boxInput = markInput(box);
|
|
321
450
|
if (boxInput) {
|
|
322
451
|
boxInput.tabIndex = -1;
|
|
323
452
|
boxInput.setAttribute('aria-hidden', 'true');
|
|
324
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
|
+
}
|
|
325
458
|
li.appendChild(box);
|
|
326
459
|
}
|
|
327
460
|
const label = document.createElement('span');
|
|
461
|
+
label.className = ROW_TEXT_CLASS;
|
|
328
462
|
label.textContent = n.label;
|
|
329
463
|
li.appendChild(label);
|
|
464
|
+
ui.rowByKey.set(n.key, li);
|
|
330
465
|
if (inputFocus && n.key === ui.cursor) activeId = id;
|
|
331
466
|
ui.tree.appendChild(li);
|
|
332
467
|
});
|
|
333
468
|
setAttr(ui.search, 'aria-activedescendant', activeId);
|
|
334
469
|
if (activeId !== '') scrollIntoViewIfAny(ui.tree.querySelector(`#${cssEscape(activeId)}`));
|
|
335
470
|
if (hadFocus && !inputFocus && ui.cursor !== null) {
|
|
336
|
-
const el = ui.
|
|
471
|
+
const el = ui.rowByKey.get(ui.cursor);
|
|
337
472
|
el?.focus();
|
|
338
473
|
}
|
|
339
474
|
}
|
|
340
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
|
+
|
|
341
517
|
function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
|
|
342
518
|
sync(ui, p);
|
|
519
|
+
const disabled = bool(p.disabled);
|
|
520
|
+
const readonly = bool(p.readonly);
|
|
343
521
|
const editable = canEdit(p);
|
|
344
522
|
const multiple = bool(p.multiple);
|
|
345
|
-
|
|
346
|
-
|
|
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');
|
|
347
530
|
// 质感标记:触发器是带边框的输入外观(field)
|
|
348
531
|
setKitFace(ui.trigger, 'field');
|
|
349
|
-
applyDisabled(ui.trigger,
|
|
350
|
-
if (
|
|
532
|
+
applyDisabled(ui.trigger, disabled);
|
|
533
|
+
if (readonly) ui.trigger.setAttribute('aria-readonly', 'true'); else ui.trigger.removeAttribute('aria-readonly');
|
|
351
534
|
applyCommon(ui.trigger, { ...p, name: '' });
|
|
352
535
|
paintValue(ui, p);
|
|
536
|
+
paintHidden(root, ui, p);
|
|
353
537
|
const hasValue = selectedKeys(p, multiple).length > 0;
|
|
354
|
-
ui.clear.className = editable && hasValue && bool(p.clearable) ? CLEAR_CLASS :
|
|
355
|
-
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
|
+
}
|
|
356
543
|
ui.trigger.setAttribute('aria-expanded', ui.open ? 'true' : 'false');
|
|
357
|
-
ui.
|
|
358
|
-
|
|
359
|
-
|
|
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;
|
|
360
552
|
// 面板内搜索框带边框(field);隐藏时 display:none,标记无害
|
|
361
553
|
setKitFace(ui.search, 'field');
|
|
362
554
|
ui.search.placeholder = str(p.search_placeholder, kitText('soma.kit.search', undefined, root));
|
|
363
555
|
ui.tree.setAttribute('aria-multiselectable', multiple ? 'true' : 'false');
|
|
364
556
|
if (ui.open) {
|
|
365
557
|
paintTree(ui, p);
|
|
366
|
-
syncDropdown(ui.panel, true, PANEL_BASE
|
|
367
|
-
|
|
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
|
+
}
|
|
368
568
|
}
|
|
369
569
|
|
|
370
570
|
function emitValue(ui: Ui, value: unknown): void {
|
|
@@ -381,7 +581,7 @@ function activate(ui: Ui, key: string): void {
|
|
|
381
581
|
const multiple = bool(p.multiple);
|
|
382
582
|
if (!multiple) {
|
|
383
583
|
emitValue(ui, node.value);
|
|
384
|
-
closePanel(ui, true);
|
|
584
|
+
closePanel(ui, true, true);
|
|
385
585
|
return;
|
|
386
586
|
}
|
|
387
587
|
const cascade = bool(p.cascade);
|
|
@@ -393,12 +593,23 @@ function activate(ui: Ui, key: string): void {
|
|
|
393
593
|
} else if (current.has(key)) current.delete(key);
|
|
394
594
|
else current.add(key);
|
|
395
595
|
// 树序输出;树里没有的旧值原样保留在前面
|
|
396
|
-
const known =
|
|
596
|
+
const known = ui.flat;
|
|
397
597
|
const unknown = selectedKeys(p, true).filter((k) => !ui.byKey.has(k));
|
|
398
598
|
emitValue(ui, [...unknown, ...known.filter((n) => current.has(n.key)).map((n) => n.value)]);
|
|
399
599
|
paint(ui.trigger.parentElement as HTMLElement, p, ui);
|
|
400
600
|
}
|
|
401
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
|
+
|
|
402
613
|
function setExpanded(ui: Ui, key: string, on: boolean): void {
|
|
403
614
|
const node = ui.byKey.get(key);
|
|
404
615
|
if (!node || node.children.length === 0) return;
|
|
@@ -424,14 +635,15 @@ function openPanel(ui: Ui): void {
|
|
|
424
635
|
paint(ui.trigger.parentElement as HTMLElement, p, ui);
|
|
425
636
|
if (bool(p.searchable)) ui.search.focus();
|
|
426
637
|
else if (ui.cursor !== null) {
|
|
427
|
-
const el = ui.tree.querySelector<HTMLElement>(`[
|
|
638
|
+
const el = ui.tree.querySelector<HTMLElement>(`[${KIT_ATTR_KEY}="${cssEscape(ui.cursor)}"]`);
|
|
428
639
|
el?.focus();
|
|
429
640
|
}
|
|
430
641
|
}
|
|
431
642
|
|
|
432
|
-
function closePanel(ui: Ui, refocus: boolean): void {
|
|
643
|
+
function closePanel(ui: Ui, refocus: boolean, immediate = false): void {
|
|
433
644
|
if (!ui.open) return;
|
|
434
645
|
ui.open = false;
|
|
646
|
+
ui.immediateClose = immediate;
|
|
435
647
|
ui.query = '';
|
|
436
648
|
ui.search.value = '';
|
|
437
649
|
paint(ui.trigger.parentElement as HTMLElement, ui.api.props(), ui);
|
|
@@ -455,6 +667,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
455
667
|
placeholder: { type: 'string', default: '', desc: '未选时的提示;缺省取内置文案(按页面语言)' },
|
|
456
668
|
clearable: { type: 'boolean', default: false, desc: '有值时显示清除钮:单选抛 change { value: "" },多选抛 change { value: [] }' },
|
|
457
669
|
expand_all: { type: 'boolean', default: true, desc: '数据载入时全部分支展开' },
|
|
670
|
+
limit_tags: { type: 'number', default: 0, desc: '多选触发按钮最多显示几个标签(与 max_tags 同义),其余折成 "+N";0 = 全显示' },
|
|
458
671
|
max_tags: { type: 'number', default: 0, desc: '多选触发按钮最多显示几个标签,其余折成 "+N";0 = 全显示' },
|
|
459
672
|
disabled: { type: 'boolean', default: false },
|
|
460
673
|
readonly: { type: 'boolean', default: false },
|
|
@@ -471,20 +684,28 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
471
684
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
472
685
|
controllerFactory: createKitController(() => ({
|
|
473
686
|
attach(root, api) {
|
|
474
|
-
|
|
475
|
-
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;
|
|
476
691
|
trigger.setAttribute('aria-haspopup', 'tree');
|
|
477
692
|
const valueEl = document.createElement('span');
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
caret.className = 'inline-flex motion-safe:transition-transform';
|
|
481
|
-
caret.appendChild(kitIcon('chevron-down', 'md'));
|
|
482
|
-
trigger.appendChild(valueEl);
|
|
483
|
-
trigger.appendChild(caret);
|
|
693
|
+
// 触发器里显示当前值的文字节点
|
|
694
|
+
kitReportSelf(valueEl, { part: 'value' });
|
|
484
695
|
const clear = document.createElement('button');
|
|
485
696
|
clear.type = 'button';
|
|
486
697
|
clear.appendChild(kitIcon('close', 'sm'));
|
|
487
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);
|
|
488
709
|
const panel = document.createElement('div');
|
|
489
710
|
const listId = nextUid('kit-treeselect');
|
|
490
711
|
panel.id = listId;
|
|
@@ -505,13 +726,12 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
505
726
|
panel.appendChild(tree);
|
|
506
727
|
panel.appendChild(status);
|
|
507
728
|
root.appendChild(trigger);
|
|
508
|
-
root.appendChild(clear);
|
|
509
729
|
root.appendChild(panel);
|
|
510
730
|
trigger.setAttribute('aria-controls', tree.id);
|
|
511
731
|
|
|
512
732
|
const ui: Ui = {
|
|
513
|
-
trigger, valueEl, clear, panel, search, tree, status, listId, open: false, query: '', composing: false, cursor: null,
|
|
514
|
-
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: () => {},
|
|
515
735
|
nav: createListNav({
|
|
516
736
|
layout: 'tree',
|
|
517
737
|
host: () => tree,
|
|
@@ -524,10 +744,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
524
744
|
})),
|
|
525
745
|
getCursor: () => ui.cursor,
|
|
526
746
|
setCursor: (key) => {
|
|
527
|
-
ui
|
|
528
|
-
paintTree(ui, api.props());
|
|
529
|
-
const el = ui.tree.querySelector<HTMLElement>(`[data-kit-key="${cssEscape(key)}"]`);
|
|
530
|
-
if (document.activeElement !== ui.search) el?.focus();
|
|
747
|
+
syncTreeCursor(ui, key);
|
|
531
748
|
},
|
|
532
749
|
onActivate: (key) => activate(ui, key),
|
|
533
750
|
onExpand: (key) => setExpanded(ui, key, true),
|
|
@@ -536,21 +753,56 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
536
753
|
};
|
|
537
754
|
uis.set(root, ui);
|
|
538
755
|
|
|
539
|
-
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
|
+
};
|
|
540
775
|
const onTriggerKeydown = (event: KeyboardEvent): void => {
|
|
541
|
-
|
|
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) {
|
|
542
781
|
event.preventDefault();
|
|
543
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);
|
|
544
795
|
}
|
|
545
796
|
};
|
|
546
|
-
const onClear = (): void => {
|
|
797
|
+
const onClear = (event: Event): void => {
|
|
798
|
+
event.stopPropagation();
|
|
547
799
|
const p = api.props();
|
|
548
800
|
emitValue(ui, bool(p.multiple) ? [] : '');
|
|
549
801
|
// 清除钮随即隐藏,焦点交还触发按钮
|
|
550
802
|
if (canEdit(p)) trigger.focus();
|
|
551
803
|
};
|
|
552
|
-
const onSearchInput = (): void => {
|
|
553
|
-
if (ui.composing) return;
|
|
804
|
+
const onSearchInput = (event?: Event): void => {
|
|
805
|
+
if (ui.composing || (event !== undefined && (event as InputEvent).isComposing)) return;
|
|
554
806
|
ui.query = search.value;
|
|
555
807
|
const rows = visibleRows(ui);
|
|
556
808
|
ui.cursor = rows.find((n) => !n.disabled)?.key ?? null;
|
|
@@ -560,20 +812,21 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
560
812
|
const onCompositionEnd = (): void => { ui.composing = false; onSearchInput(); };
|
|
561
813
|
const onPanelClick = (event: Event): void => {
|
|
562
814
|
const target = event.target as HTMLElement | null;
|
|
563
|
-
const row = target?.closest<HTMLElement>(
|
|
564
|
-
const key = row?.getAttribute(
|
|
815
|
+
const row = target?.closest<HTMLElement>(`[${KIT_ATTR_KEY}]`);
|
|
816
|
+
const key = row?.getAttribute(KIT_ATTR_KEY);
|
|
565
817
|
if (!row || key === null || key === undefined) return;
|
|
566
|
-
if (target?.closest(
|
|
818
|
+
if (target?.closest(`[${KIT_ATTR_TOGGLE}]`)) {
|
|
567
819
|
setExpanded(ui, key, !ui.expanded.has(key));
|
|
568
820
|
return;
|
|
569
821
|
}
|
|
570
822
|
activate(ui, key);
|
|
571
823
|
};
|
|
572
824
|
const onPanelKeydown = (event: KeyboardEvent): void => {
|
|
825
|
+
if (ui.composing || isImeComposing(event)) return;
|
|
573
826
|
if (event.key === 'Escape') {
|
|
574
827
|
event.preventDefault();
|
|
575
828
|
event.stopPropagation();
|
|
576
|
-
closePanel(ui, true);
|
|
829
|
+
closePanel(ui, true, true);
|
|
577
830
|
return;
|
|
578
831
|
}
|
|
579
832
|
if (event.key === 'Tab') {
|
|
@@ -589,7 +842,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
589
842
|
if (ui.nav.handle(event)) event.preventDefault();
|
|
590
843
|
return;
|
|
591
844
|
}
|
|
592
|
-
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);
|
|
593
846
|
if (ui.cursor === null && key) ui.cursor = key;
|
|
594
847
|
if (ui.nav.handle(event)) event.preventDefault();
|
|
595
848
|
};
|
|
@@ -599,6 +852,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
599
852
|
};
|
|
600
853
|
const offOutside = onOutsidePress(root, () => ui.open, () => closePanel(ui, false));
|
|
601
854
|
|
|
855
|
+
trigger.addEventListener('mousedown', onTriggerMouseDown);
|
|
602
856
|
trigger.addEventListener('click', onTriggerClick);
|
|
603
857
|
trigger.addEventListener('keydown', onTriggerKeydown);
|
|
604
858
|
clear.addEventListener('click', onClear);
|
|
@@ -609,6 +863,7 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
609
863
|
panel.addEventListener('keydown', onPanelKeydown);
|
|
610
864
|
panel.addEventListener('mousedown', onPanelMouseDown);
|
|
611
865
|
ui.dispose = () => {
|
|
866
|
+
trigger.removeEventListener('mousedown', onTriggerMouseDown);
|
|
612
867
|
trigger.removeEventListener('click', onTriggerClick);
|
|
613
868
|
trigger.removeEventListener('keydown', onTriggerKeydown);
|
|
614
869
|
clear.removeEventListener('click', onClear);
|
|
@@ -623,6 +878,8 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
623
878
|
return () => {
|
|
624
879
|
ui.dispose();
|
|
625
880
|
uis.delete(root);
|
|
881
|
+
for (const h of ui.hiddenEls) h.remove();
|
|
882
|
+
ui.hiddenEls.length = 0;
|
|
626
883
|
trigger.remove();
|
|
627
884
|
clear.remove();
|
|
628
885
|
releaseDropdown(panel, false);
|
|
@@ -633,6 +890,6 @@ export function createTreeSelect(): SomaComponentDefinition {
|
|
|
633
890
|
const ui = uis.get(root);
|
|
634
891
|
if (ui) paint(root, p, ui);
|
|
635
892
|
},
|
|
636
|
-
})),
|
|
893
|
+
}), { self: { level: 'control' } }),
|
|
637
894
|
};
|
|
638
895
|
}
|