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/card.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Card:通用卡片(基础组件,页面可写)。抄 shadcn/ui card(Card / CardHeader / CardTitle / CardDescription / CardAction / CardContent / CardFooter)的部件划分,
|
|
2
|
+
// 取值照 Ant / Arco / TDesign(取值表 02 §22):外缘 = 面板外缘配方(card 圆角、发丝边、随 shape / layering / 容器阴影,不在组件里写死);
|
|
3
|
+
// 内边距 = card 档(12 / 16 / 20,随 density B);标题 16 / 500,标题与说明 4,说明 14 / 次级色;脚与体之间一条节线。
|
|
4
|
+
// 数据:title / description / value(正文,纯文字)/ footer(脚文字)/ action_label(头部右上动作钮);全空的部件不占位。文字一律 textContent。
|
|
5
|
+
// 状态(组件卡 Card §6):interactive 可点(悬停状态层 + 聚焦环,Enter / Space 触发 click)、selected 选中(选中配方 + 右上对勾)、disabled 禁用、loading 加载(体内骨架 + aria-busy)。
|
|
6
|
+
// 语义:有标题且非可点时根是 region 地标(aria-labelledby 指标题,带 data-kit-container);可点时根是 button(selected 同步 aria-pressed)。
|
|
7
|
+
|
|
8
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
|
+
import { kitIcon } from '../shared/icons';
|
|
10
|
+
import { mergeClass } from '../shared/merge-class';
|
|
11
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
12
|
+
import { KIT_DIVIDER_FOOT_CLASS, KIT_DIVIDER_HEAD_CLASS } from '../recipes/divider';
|
|
13
|
+
import { kitActionRecipe } from '../recipes/emphasis';
|
|
14
|
+
import { KIT_SKELETON_BAR_LAST_TEXT, KIT_SKELETON_BAR_LINE } from '../recipes/placeholder';
|
|
15
|
+
import { kitDisabledRecipe, kitFocusRingRecipe, kitSelectedRecipe } from '../recipes/state';
|
|
16
|
+
import { kitLevelClassFor } from '../recipes/pipeline-runtime';
|
|
17
|
+
import {
|
|
18
|
+
CLASS_PROP, ID_PROPS,
|
|
19
|
+
bool, classCandidates, createKitController, joinClass, kitMarkDataState, kitMarkInteract, kitReadProps, kitSid, nextUid, setAttr, str,
|
|
20
|
+
} from './shared';
|
|
21
|
+
import { KIT_ATTR_CARD_SKEL, KIT_ATTR_CONTAINER, KIT_ATTR_SLOT } from '../shared/dom-attrs';
|
|
22
|
+
|
|
23
|
+
// 照组件卡 Card §7:根自画外缘;头 / 体 / 脚各自内边距(无 gap),头体之间与脚上各一条发丝线(有头 / 有脚时);头右上是动作位(card-action)
|
|
24
|
+
const ROOT = mergeClass('flex w-full min-w-0 flex-col overflow-hidden text-sm text-fg', kitShellRecipe());
|
|
25
|
+
const ROOT_INTERACTIVE = mergeClass(`${ROOT} cursor-pointer text-start transition-colors hover:bg-state-layer-hover active:bg-state-layer-press`, kitFocusRingRecipe('button'));
|
|
26
|
+
const ROOT_SELECTED = kitSelectedRecipe('primary');
|
|
27
|
+
const ROOT_DISABLED = kitDisabledRecipe('aria');
|
|
28
|
+
const HEAD = `flex min-w-0 items-start justify-between gap-3 px-card py-3 ${KIT_DIVIDER_HEAD_CLASS}`;
|
|
29
|
+
const HEAD_ALONE = 'flex min-w-0 items-start justify-between gap-3 px-card py-3';
|
|
30
|
+
const TITLES = 'flex min-w-0 flex-1 flex-col gap-1';
|
|
31
|
+
const TITLE = 'text-base font-medium text-fg';
|
|
32
|
+
const DESC = 'text-sm text-fg-muted';
|
|
33
|
+
const ACTION = kitActionRecipe('edit', { size: 'sm', tight: true });
|
|
34
|
+
const CHECK = 'shrink-0 text-primary-on-soft';
|
|
35
|
+
const BODY = 'p-card text-sm text-fg';
|
|
36
|
+
const BODY_LOADING = 'flex flex-col gap-2 p-card';
|
|
37
|
+
const FOOT = `flex items-center px-card py-3 text-sm text-fg-muted ${KIT_DIVIDER_FOOT_CLASS}`;
|
|
38
|
+
const HIDDEN = 'hidden';
|
|
39
|
+
/** 根上的 aria-label 由本组件(标题隐去时)写的那些卡:只撤回自己写的,不清应用写的 */
|
|
40
|
+
const CARD_OWN_LABEL = new WeakSet<Element>();
|
|
41
|
+
|
|
42
|
+
export const KIT_CARD_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
43
|
+
ROOT, ROOT_INTERACTIVE, ROOT_SELECTED, ROOT_DISABLED, HEAD, HEAD_ALONE, TITLES, TITLE, DESC, ACTION, CHECK, BODY, BODY_LOADING, FOOT, HIDDEN,
|
|
44
|
+
KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LAST_TEXT,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export function createCard(): SomaComponentDefinition {
|
|
48
|
+
return {
|
|
49
|
+
contract: {
|
|
50
|
+
name: 'Card',
|
|
51
|
+
layer: 'basic',
|
|
52
|
+
props: {
|
|
53
|
+
title: { type: 'string', default: '', desc: '标题' },
|
|
54
|
+
description: { type: 'string', default: '', desc: '标题下的说明(次级色)' },
|
|
55
|
+
value: { type: 'string', default: '', desc: '正文(纯文字)' },
|
|
56
|
+
footer: { type: 'string', default: '', desc: '脚文字;空则不出脚' },
|
|
57
|
+
action_label: { type: 'string', default: '', desc: '头部右上动作钮文字(按钮,有后果的操作);空则不出;点击抛 action' },
|
|
58
|
+
interactive: { type: 'boolean', default: false, desc: '可点卡:根变按钮,悬停状态层 + 聚焦环,点击 / Enter / Space 抛 click' },
|
|
59
|
+
selected: { type: 'boolean', default: false, desc: '选中:选中配方底 + 右上对勾(可点卡同步 aria-pressed)' },
|
|
60
|
+
disabled: { type: 'boolean', default: false, desc: '禁用:置灰,不抛 click / action' },
|
|
61
|
+
loading: { type: 'boolean', default: false, desc: '加载:体内骨架,根 aria-busy' },
|
|
62
|
+
id: ID_PROPS.id,
|
|
63
|
+
class: CLASS_PROP,
|
|
64
|
+
},
|
|
65
|
+
emits: {
|
|
66
|
+
click: { payload: {}, desc: '可点卡被点击;disabled / loading 时不抛' },
|
|
67
|
+
action: { payload: {}, desc: '头部右上动作钮被点击' },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
templateHtml: [
|
|
71
|
+
`<div data-soma-id="root" class="${ROOT}">`,
|
|
72
|
+
// 主题流水线自报(绘制时由骨架的 self / selfParts 写):标题行 = 面头、标题文字 = 块标题、头部右上钮 = 动作、脚 = 底栏、根 = 对象面
|
|
73
|
+
`<div data-soma-id="head" class="${HEAD}"><div data-soma-id="titles" class="${TITLES}"><span data-soma-id="title" class="${TITLE}"></span><span data-soma-id="desc" class="${DESC}"></span></div>`,
|
|
74
|
+
`<button data-soma-id="action" type="button" class="${HIDDEN}"></button><span data-soma-id="check" aria-hidden="true" class="${HIDDEN}"></span></div>`,
|
|
75
|
+
`<div data-soma-id="body" class="${BODY}"></div>`,
|
|
76
|
+
`<div data-soma-id="foot" class="${FOOT}"></div>`,
|
|
77
|
+
'</div>',
|
|
78
|
+
].join(''),
|
|
79
|
+
controllerFactory: createKitController((api) => {
|
|
80
|
+
const uid = nextUid('kit-card');
|
|
81
|
+
let slotsCollected = false;
|
|
82
|
+
const adoptedBody: Element[] = [];
|
|
83
|
+
const adoptedFoot: Element[] = [];
|
|
84
|
+
|
|
85
|
+
const collectSlots = (root: HTMLElement, body: HTMLElement, foot: HTMLElement): void => {
|
|
86
|
+
if (slotsCollected) return;
|
|
87
|
+
slotsCollected = true;
|
|
88
|
+
for (const el of Array.from(root.children)) {
|
|
89
|
+
if (el.hasAttribute('data-soma-id') || el.hasAttribute('data-soma-scoped-id')) continue;
|
|
90
|
+
if (el.getAttribute(KIT_ATTR_SLOT) === 'foot') adoptedFoot.push(el);
|
|
91
|
+
else adoptedBody.push(el);
|
|
92
|
+
}
|
|
93
|
+
for (const el of Array.from(body.children)) {
|
|
94
|
+
if (!el.hasAttribute(KIT_ATTR_CARD_SKEL) && !adoptedBody.includes(el)) adoptedBody.push(el);
|
|
95
|
+
}
|
|
96
|
+
for (const el of Array.from(foot.children)) {
|
|
97
|
+
if (!adoptedFoot.includes(el)) adoptedFoot.push(el);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
attach(root) {
|
|
103
|
+
const q = (id: string): HTMLElement | null => root.querySelector<HTMLElement>(`[data-soma-scoped-id="${id}"], [data-soma-id="${id}"]`);
|
|
104
|
+
const body = q('body');
|
|
105
|
+
const foot = q('foot');
|
|
106
|
+
if (body && foot) collectSlots(root, body, foot);
|
|
107
|
+
const act = q('action');
|
|
108
|
+
const titles = q('titles');
|
|
109
|
+
const onAction = (ev: Event): void => {
|
|
110
|
+
ev.stopPropagation();
|
|
111
|
+
const p = api.props();
|
|
112
|
+
if (bool(p.disabled) || bool(p.loading)) return;
|
|
113
|
+
api.emit('action', {});
|
|
114
|
+
};
|
|
115
|
+
const onActionKey = (ev: KeyboardEvent): void => {
|
|
116
|
+
if (ev.key === 'Enter' || ev.key === ' ') ev.stopPropagation();
|
|
117
|
+
};
|
|
118
|
+
const fire = (): void => {
|
|
119
|
+
const p = api.props();
|
|
120
|
+
if (!bool(p.interactive) || bool(p.disabled) || bool(p.loading)) return;
|
|
121
|
+
api.emit('click', {});
|
|
122
|
+
};
|
|
123
|
+
const onClick = (ev: Event): void => {
|
|
124
|
+
if (act !== null && ev.target instanceof Node && act.contains(ev.target)) return;
|
|
125
|
+
fire();
|
|
126
|
+
};
|
|
127
|
+
const onKey = (ev: KeyboardEvent): void => {
|
|
128
|
+
if (act !== null && ev.target instanceof Node && act.contains(ev.target)) return;
|
|
129
|
+
if (ev.target !== root && ev.target !== titles) return;
|
|
130
|
+
if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); fire(); }
|
|
131
|
+
};
|
|
132
|
+
act?.addEventListener('click', onAction);
|
|
133
|
+
act?.addEventListener('keydown', onActionKey);
|
|
134
|
+
root.addEventListener('click', onClick);
|
|
135
|
+
root.addEventListener('keydown', onKey);
|
|
136
|
+
return () => {
|
|
137
|
+
act?.removeEventListener('click', onAction);
|
|
138
|
+
act?.removeEventListener('keydown', onActionKey);
|
|
139
|
+
root.removeEventListener('click', onClick);
|
|
140
|
+
root.removeEventListener('keydown', onKey);
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
render(root, p) {
|
|
144
|
+
const q = (id: string): HTMLElement | null => root.querySelector<HTMLElement>(`[data-soma-scoped-id="${id}"], [data-soma-id="${id}"]`);
|
|
145
|
+
const head = q('head'); const titles = q('titles'); const title = q('title'); const desc = q('desc'); const body = q('body'); const foot = q('foot');
|
|
146
|
+
const action = q('action'); const check = q('check');
|
|
147
|
+
if (!head || !titles || !title || !desc || !body || !foot || !action || !check) return;
|
|
148
|
+
collectSlots(root, body, foot);
|
|
149
|
+
// 页面线判定隐去标题(kit.titleHidden)时只收起可见标题,名字仍给地标(aria-label),读屏不丢;没有 kit 时与原来相同
|
|
150
|
+
const titleHidden = kitReadProps(p).titleHidden === true;
|
|
151
|
+
const rawTitle = str(p.title);
|
|
152
|
+
const t = titleHidden ? '' : rawTitle; const d = str(p.description); const v = str(p.value); const f = str(p.footer); const a = str(p.action_label);
|
|
153
|
+
const interactive = bool(p.interactive);
|
|
154
|
+
const selected = bool(p.selected);
|
|
155
|
+
const disabled = bool(p.disabled);
|
|
156
|
+
const loading = bool(p.loading);
|
|
157
|
+
const hasBodySlot = adoptedBody.length > 0;
|
|
158
|
+
const hasFootSlot = adoptedFoot.length > 0;
|
|
159
|
+
title.textContent = t; title.className = t === '' ? HIDDEN : TITLE;
|
|
160
|
+
title.id = `${uid}-t`;
|
|
161
|
+
desc.textContent = d; desc.className = d === '' ? HIDDEN : DESC;
|
|
162
|
+
// 动作钮:有文字才出;加载 / 禁用时置灰
|
|
163
|
+
action.textContent = a;
|
|
164
|
+
action.className = a === '' ? HIDDEN : ACTION;
|
|
165
|
+
if (a !== '' && (disabled || loading)) action.setAttribute('disabled', ''); else action.removeAttribute('disabled');
|
|
166
|
+
// 选中对勾(右上)
|
|
167
|
+
if (selected) { check.replaceChildren(kitIcon('check', 'sm')); check.className = CHECK; } else { check.replaceChildren(); check.className = HIDDEN; }
|
|
168
|
+
const hasHead = t !== '' || d !== '' || a !== '' || selected;
|
|
169
|
+
const hasBody = loading || hasBodySlot || v !== '';
|
|
170
|
+
const hasFoot = hasFootSlot || f !== '';
|
|
171
|
+
head.className = !hasHead ? HIDDEN : kitLevelClassFor(head, !hasBody && !hasFoot ? HEAD_ALONE : HEAD);
|
|
172
|
+
// 体:加载时两条骨架(保活外部插槽);有外部插槽时迁入保活不被空 value 清空;否则写纯文字
|
|
173
|
+
if (loading) {
|
|
174
|
+
for (const el of adoptedBody) {
|
|
175
|
+
if (el.parentElement === body) el.remove();
|
|
176
|
+
}
|
|
177
|
+
body.className = BODY_LOADING;
|
|
178
|
+
const l1 = body.ownerDocument.createElement('div');
|
|
179
|
+
l1.className = KIT_SKELETON_BAR_LINE; l1.setAttribute('aria-hidden', 'true'); l1.setAttribute(KIT_ATTR_CARD_SKEL, '');
|
|
180
|
+
const l2 = body.ownerDocument.createElement('div');
|
|
181
|
+
l2.className = KIT_SKELETON_BAR_LAST_TEXT; l2.setAttribute('aria-hidden', 'true'); l2.setAttribute(KIT_ATTR_CARD_SKEL, '');
|
|
182
|
+
body.replaceChildren(l1, l2);
|
|
183
|
+
} else if (hasBodySlot) {
|
|
184
|
+
for (const skel of Array.from(body.querySelectorAll(`[${KIT_ATTR_CARD_SKEL}]`))) skel.remove();
|
|
185
|
+
for (const el of adoptedBody) {
|
|
186
|
+
if (el.parentElement !== body) body.appendChild(el);
|
|
187
|
+
}
|
|
188
|
+
body.className = BODY;
|
|
189
|
+
} else {
|
|
190
|
+
body.textContent = v; body.className = v === '' ? HIDDEN : BODY;
|
|
191
|
+
}
|
|
192
|
+
if (hasFootSlot) {
|
|
193
|
+
for (const el of adoptedFoot) {
|
|
194
|
+
if (el.parentElement !== foot) foot.appendChild(el);
|
|
195
|
+
}
|
|
196
|
+
foot.className = kitLevelClassFor(foot, FOOT);
|
|
197
|
+
} else {
|
|
198
|
+
foot.textContent = f; foot.className = f === '' ? HIDDEN : kitLevelClassFor(foot, FOOT);
|
|
199
|
+
}
|
|
200
|
+
// 根自报了对象面(骨架 self.level):基础外观经 kitLevelClassFor(新模式剥掉取值表负责的类),选中 / 禁用状态配方照旧追加
|
|
201
|
+
root.className = joinClass(mergeClass(mergeClass(kitLevelClassFor(root, interactive ? ROOT_INTERACTIVE : ROOT), selected ? ROOT_SELECTED : ''), disabled ? ROOT_DISABLED : ''), p.class);
|
|
202
|
+
setAttr(root, 'id', str(p.id));
|
|
203
|
+
// 语义:可点卡根为 button(同步 aria-pressed,内层 action 钮已阻断 click/keydown 冒泡);非交互有标题态标 region + data-kit-container="card"
|
|
204
|
+
root.removeAttribute('aria-labelledby');
|
|
205
|
+
titles.className = TITLES;
|
|
206
|
+
if (interactive) {
|
|
207
|
+
root.setAttribute('role', 'button');
|
|
208
|
+
root.setAttribute('tabindex', disabled ? '-1' : '0');
|
|
209
|
+
root.setAttribute('aria-pressed', selected ? 'true' : 'false');
|
|
210
|
+
root.removeAttribute(KIT_ATTR_CONTAINER);
|
|
211
|
+
} else {
|
|
212
|
+
root.removeAttribute('tabindex');
|
|
213
|
+
root.removeAttribute('aria-pressed');
|
|
214
|
+
if (t !== '') { root.setAttribute('role', 'region'); root.setAttribute('aria-labelledby', title.id); root.setAttribute(KIT_ATTR_CONTAINER, 'card'); }
|
|
215
|
+
else if (titleHidden && rawTitle !== '') { root.setAttribute('role', 'region'); root.setAttribute(KIT_ATTR_CONTAINER, 'card'); }
|
|
216
|
+
else { root.removeAttribute('role'); root.removeAttribute(KIT_ATTR_CONTAINER); }
|
|
217
|
+
}
|
|
218
|
+
// 只撤回本通道自己写过的 aria-label:旧版(没有 kit 判定)从不触碰根上的 aria-label,与改动前一致
|
|
219
|
+
if (titleHidden && rawTitle !== '') { root.setAttribute('aria-label', rawTitle); CARD_OWN_LABEL.add(root); }
|
|
220
|
+
else if (CARD_OWN_LABEL.has(root)) { root.removeAttribute('aria-label'); CARD_OWN_LABEL.delete(root); }
|
|
221
|
+
// 数据状态与交互状态自报(取值表据此给加载态、选中态的取值;视觉仍走原有配方)
|
|
222
|
+
kitMarkDataState(root, loading ? 'loading' : 'normal');
|
|
223
|
+
kitMarkInteract(root, 'selected', selected);
|
|
224
|
+
if (disabled) root.setAttribute('aria-disabled', 'true'); else root.removeAttribute('aria-disabled');
|
|
225
|
+
if (loading) root.setAttribute('aria-busy', 'true'); else root.removeAttribute('aria-busy');
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}, {
|
|
229
|
+
self: { level: 'face' },
|
|
230
|
+
selfParts: [[kitSid('head'), { level: 'head' }], [kitSid('title'), { part: 'block-title' }], [kitSid('action'), { part: 'action' }], [kitSid('foot'), { level: 'foot' }]],
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
}
|
package/src/base/cascader.ts
CHANGED
|
@@ -13,38 +13,49 @@
|
|
|
13
13
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
14
14
|
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
15
15
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
16
|
-
import { kitIcon } from '../shared/icons';
|
|
16
|
+
import { KIT_ICON_CLASS_CANDIDATES, kitIcon, setKitIconCached } from '../shared/icons';
|
|
17
17
|
import { mergeClass } from '../shared/merge-class';
|
|
18
18
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
19
19
|
import { kitDivideRecipe } from '../recipes/divider';
|
|
20
|
+
import { KIT_FOCUS_RING } from '../recipes/state';
|
|
20
21
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
21
22
|
import {
|
|
22
23
|
EMPTY_ROW_CLASS, KIT_POPUP_CLASS_CANDIDATES, KIT_DROPDOWN_CLASS_CANDIDATES, KIT_DROPDOWN_PANEL_MAX_CLASS, PANEL_BASE_CLASS,
|
|
23
24
|
syncDropdown, releaseDropdown, cssEscape, createListNav, onOutsidePress, optionClass, scrollIntoViewIfAny,
|
|
24
25
|
} from './popup';
|
|
25
26
|
import {
|
|
26
|
-
CLASS_PROP, FIELD_CLASS, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP, classCandidates,
|
|
27
|
-
applyCommon, applyDisabled, bool, createKitController, joinClass, nextUid, setAttr, setBoolAttr,
|
|
27
|
+
CLASS_PROP, FIELD_CLASS, FIELD_INVALID_CLASS, FIELD_TRIGGER_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP, classCandidates,
|
|
28
|
+
applyCommon, applyDisabled, bool, createKitController, joinClass, nextUid, setAttr, setBoolAttr, str, withInvalid,
|
|
29
|
+
kitControlSizeOf, kitMarkDataState, kitMarkInteract, kitReadProps,
|
|
28
30
|
type KitProps,
|
|
29
31
|
} from './shared';
|
|
32
|
+
import { KIT_ATTR_CLEAR, KIT_ATTR_FACE, KIT_ATTR_PATH, KIT_ATTR_VALUE } from '../shared/dom-attrs';
|
|
30
33
|
|
|
31
34
|
// ---- Tailwind 类常量与候选类清单 ----
|
|
32
35
|
|
|
33
|
-
const WRAP = 'relative block w-full';
|
|
36
|
+
const WRAP = 'relative block w-full min-w-0';
|
|
34
37
|
const STATUS = 'sr-only';
|
|
35
38
|
const PANEL_HIDDEN = 'hidden';
|
|
36
39
|
// 位置类(left-0 top-full mt-1 或翻转后的整串)由 popup.ts 的 syncDropdown 拼上,这里只写外观
|
|
37
|
-
// 多列面板 = 浮起表面(KT-B4);列与列之间的线由父出(kitDivideRecipe,KT-B5
|
|
38
|
-
const PANEL_COLUMNS = mergeClass('absolute z-10 flex max-w-
|
|
40
|
+
// 多列面板 = 浮起表面(KT-B4);列与列之间的线由父出(kitDivideRecipe,KT-B5);w-max 自然展开多列,预置安全上限防溢出视口
|
|
41
|
+
const PANEL_COLUMNS = mergeClass('absolute z-10 flex w-max max-w-4xl overflow-auto', `${kitSurfaceRecipe('raised')} ${kitDivideRecipe('x')}`);
|
|
39
42
|
const PANEL_FLAT = PANEL_BASE_CLASS;
|
|
40
|
-
const COLUMN = `${KIT_DROPDOWN_PANEL_MAX_CLASS} min-w-
|
|
41
|
-
const CHEVRON = 'ms-auto text-fg-subtle';
|
|
42
|
-
const LABEL = 'min-w-0 truncate';
|
|
43
|
+
const COLUMN = `${KIT_DROPDOWN_PANEL_MAX_CLASS} min-w-30 overflow-auto p-1`;
|
|
44
|
+
const CHEVRON = 'ms-auto inline-flex shrink-0 items-center justify-center text-fg-subtle';
|
|
45
|
+
const LABEL = 'min-w-0 flex-1 truncate';
|
|
46
|
+
const TRIGGER_IDLE_EXTRA = 'cursor-pointer select-none';
|
|
47
|
+
const PAD_CHEVRON = 'pe-8';
|
|
48
|
+
const PAD_CLEAR = 'pe-12';
|
|
49
|
+
const CARET_CLASS = 'pointer-events-none absolute end-2.5 top-0 inline-flex h-full items-center justify-center text-fg-subtle motion-safe:transition-transform';
|
|
50
|
+
const CLEAR_BTN_CLASS = 'absolute end-7 top-0 border-0 bg-transparent inline-flex h-full cursor-pointer items-center justify-center rounded-item px-1 text-fg-subtle transition-colors hover:text-fg ' + KIT_FOCUS_RING.item;
|
|
51
|
+
const HIDDEN_CLEAR_CLASS = 'hidden ' + KIT_FOCUS_RING.item;
|
|
43
52
|
|
|
44
53
|
export const KIT_CASCADER_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
45
54
|
WRAP, STATUS, PANEL_HIDDEN, PANEL_COLUMNS, PANEL_FLAT, COLUMN, CHEVRON, LABEL, EMPTY_ROW_CLASS,
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
TRIGGER_IDLE_EXTRA, PAD_CHEVRON, PAD_CLEAR, CARET_CLASS, CLEAR_BTN_CLASS, HIDDEN_CLEAR_CLASS,
|
|
56
|
+
Object.values(FIELD_CLASS), Object.values(FIELD_TRIGGER_CLASS), FIELD_INVALID_CLASS,
|
|
57
|
+
KIT_ICON_CLASS_CANDIDATES, KIT_POPUP_CLASS_CANDIDATES, KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
58
|
+
optionClass(false, false, false), optionClass(true, false, false), optionClass(false, true, false), optionClass(false, false, true), optionClass(true, true, false),
|
|
48
59
|
);
|
|
49
60
|
|
|
50
61
|
// ---- 选项树规整与搜索(纯函数) ----
|
|
@@ -137,6 +148,7 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
137
148
|
options: { type: 'array', default: [], desc: '选项树 [{ value, label, disabled?, lazy?, children? }],深度上限 8' },
|
|
138
149
|
placeholder: { type: 'string', default: '', desc: '占位文字' },
|
|
139
150
|
searchable: { type: 'boolean', default: false, desc: '可键入搜索路径' },
|
|
151
|
+
clearable: { type: 'boolean', default: false, desc: '有值时显示清除钮;点后清空并抛 change { value: [], labels: [] }' },
|
|
140
152
|
change_on_select: { type: 'boolean', default: false, desc: '允许选任意一级(点分支项即抛 change 并展开)' },
|
|
141
153
|
separator: { type: 'string', default: ' / ', desc: '路径文字分隔' },
|
|
142
154
|
empty_text: { type: 'string', default: '', desc: '搜索无结果提示;缺省取内置文案(按页面语言)' },
|
|
@@ -155,7 +167,7 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
155
167
|
},
|
|
156
168
|
templateHtml:
|
|
157
169
|
`<div data-soma-id="root" class="${WRAP}">` +
|
|
158
|
-
`<input data-soma-id="input" type="text" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-autocomplete="none" autocomplete="off"
|
|
170
|
+
`<input data-soma-id="input" type="text" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-autocomplete="none" autocomplete="off" ${KIT_ATTR_FACE}="field" class="${FIELD_TRIGGER_CLASS.md}" />` +
|
|
159
171
|
`<div data-soma-id="panel" role="listbox" class="${PANEL_HIDDEN}"></div>` +
|
|
160
172
|
`<div data-soma-id="status" role="status" class="${STATUS}"></div></div>`,
|
|
161
173
|
controllerFactory: createKitController((api) => {
|
|
@@ -165,6 +177,7 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
165
177
|
let composing = false;
|
|
166
178
|
let cursor: string[] = [];
|
|
167
179
|
let searchCursor: string | null = null;
|
|
180
|
+
let paintVersion = 0;
|
|
168
181
|
const requested = new Set<string>();
|
|
169
182
|
let paintFn: (() => void) | null = null;
|
|
170
183
|
|
|
@@ -173,6 +186,19 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
173
186
|
const input = root.querySelector<HTMLInputElement>('[data-soma-id="input"], [data-soma-scoped-id="input"]') as HTMLInputElement;
|
|
174
187
|
const panel = root.querySelector<HTMLElement>('[data-soma-id="panel"], [data-soma-scoped-id="panel"]') as HTMLElement;
|
|
175
188
|
const status = root.querySelector<HTMLElement>('[data-soma-id="status"], [data-soma-scoped-id="status"]') as HTMLElement;
|
|
189
|
+
const clear = document.createElement('button');
|
|
190
|
+
clear.type = 'button';
|
|
191
|
+
clear.tabIndex = -1;
|
|
192
|
+
clear.setAttribute(KIT_ATTR_CLEAR, '');
|
|
193
|
+
clear.className = HIDDEN_CLEAR_CLASS;
|
|
194
|
+
setKitIconCached(clear, 'close', 'sm');
|
|
195
|
+
const caret = document.createElement('span');
|
|
196
|
+
caret.setAttribute('aria-hidden', 'true');
|
|
197
|
+
caret.className = CARET_CLASS;
|
|
198
|
+
caret.appendChild(kitIcon('chevron-down', 'md'));
|
|
199
|
+
root.insertBefore(clear, panel);
|
|
200
|
+
root.insertBefore(caret, panel);
|
|
201
|
+
const hiddenEls: HTMLInputElement[] = [];
|
|
176
202
|
const listId = nextUid('kit-cascader');
|
|
177
203
|
panel.id = listId;
|
|
178
204
|
input.setAttribute('aria-controls', listId);
|
|
@@ -213,10 +239,13 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
213
239
|
const el = document.createElement('div');
|
|
214
240
|
el.id = id;
|
|
215
241
|
el.setAttribute('role', 'option');
|
|
216
|
-
el.setAttribute(
|
|
242
|
+
el.setAttribute(KIT_ATTR_PATH, pathAttr(keys));
|
|
217
243
|
el.setAttribute('aria-selected', selected ? 'true' : 'false');
|
|
218
244
|
if (disabled) el.setAttribute('aria-disabled', 'true');
|
|
219
245
|
el.className = optionClass(selected, active, disabled);
|
|
246
|
+
// 交互状态只自报选中与激活(键盘当前项);禁用走 aria-disabled
|
|
247
|
+
kitMarkInteract(el, 'selected', selected);
|
|
248
|
+
kitMarkInteract(el, 'current', active);
|
|
220
249
|
const label = document.createElement('span');
|
|
221
250
|
label.className = LABEL;
|
|
222
251
|
label.textContent = text;
|
|
@@ -289,11 +318,38 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
289
318
|
});
|
|
290
319
|
}
|
|
291
320
|
setAttr(input, 'aria-activedescendant', open ? activeId : '');
|
|
292
|
-
syncDropdown(panel, true, panelBase);
|
|
321
|
+
syncDropdown(panel, true, panelBase, root);
|
|
293
322
|
if (activeId !== '') scrollIntoViewIfAny(panel.querySelector(`#${cssEscape(activeId)}`));
|
|
294
323
|
};
|
|
295
324
|
|
|
325
|
+
const paintHidden = (props: KitProps): void => {
|
|
326
|
+
const name = str(props.name);
|
|
327
|
+
if (name === '') {
|
|
328
|
+
while (hiddenEls.length > 0) hiddenEls.pop()!.remove();
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const keys = valueKeys();
|
|
332
|
+
const vals = keys.length > 0 ? keys : [''];
|
|
333
|
+
while (hiddenEls.length > vals.length) hiddenEls.pop()!.remove();
|
|
334
|
+
while (hiddenEls.length < vals.length) {
|
|
335
|
+
const h = document.createElement('input');
|
|
336
|
+
h.type = 'hidden';
|
|
337
|
+
h.setAttribute(KIT_ATTR_VALUE, '');
|
|
338
|
+
root.appendChild(h);
|
|
339
|
+
hiddenEls.push(h);
|
|
340
|
+
}
|
|
341
|
+
const off = bool(props.disabled);
|
|
342
|
+
vals.forEach((v, i) => {
|
|
343
|
+
const h = hiddenEls[i]!;
|
|
344
|
+
if (h.value !== v) h.value = v;
|
|
345
|
+
setAttr(h, 'name', name);
|
|
346
|
+
setBoolAttr(h, 'disabled', off);
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
|
|
296
350
|
const paint = (): void => {
|
|
351
|
+
paintVersion += 1;
|
|
352
|
+
const props = p();
|
|
297
353
|
if (open) paintPanel();
|
|
298
354
|
else {
|
|
299
355
|
syncDropdown(panel, false);
|
|
@@ -302,10 +358,16 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
302
358
|
status.textContent = '';
|
|
303
359
|
}
|
|
304
360
|
input.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
361
|
+
caret.classList.toggle('rotate-180', open);
|
|
362
|
+
setKitIconCached(clear, 'close', 'sm');
|
|
363
|
+
clear.setAttribute('aria-label', kitText('soma.kit.clear', undefined, root));
|
|
364
|
+
const showClear = bool(props.clearable) && !locked() && valueKeys().length > 0;
|
|
365
|
+
clear.className = showClear ? CLEAR_BTN_CLASS : HIDDEN_CLEAR_CLASS;
|
|
305
366
|
if (!typing) {
|
|
306
367
|
const label = selectedText();
|
|
307
368
|
if (input.value !== label) input.value = label;
|
|
308
369
|
}
|
|
370
|
+
paintHidden(props);
|
|
309
371
|
};
|
|
310
372
|
paintFn = paint;
|
|
311
373
|
|
|
@@ -321,9 +383,9 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
321
383
|
cursor = first ? [first.value] : [];
|
|
322
384
|
}
|
|
323
385
|
searchCursor = null;
|
|
324
|
-
|
|
386
|
+
const v0 = paintVersion;
|
|
325
387
|
ensureLoaded();
|
|
326
|
-
paint();
|
|
388
|
+
if (paintVersion === v0) paint();
|
|
327
389
|
};
|
|
328
390
|
const closePanel = (): void => {
|
|
329
391
|
if (!open) return;
|
|
@@ -341,9 +403,9 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
341
403
|
};
|
|
342
404
|
const expand = (keys: string[]): void => {
|
|
343
405
|
cursor = keys;
|
|
344
|
-
|
|
406
|
+
const v0 = paintVersion;
|
|
345
407
|
ensureLoaded();
|
|
346
|
-
paint();
|
|
408
|
+
if (paintVersion === v0) paint();
|
|
347
409
|
};
|
|
348
410
|
// 激活一条路径:叶子选中;分支展开(change_on_select 时同时选中)
|
|
349
411
|
const activate = (keys: string[]): void => {
|
|
@@ -359,9 +421,8 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
359
421
|
return;
|
|
360
422
|
}
|
|
361
423
|
if (anyLevel()) commit(nodes, true);
|
|
362
|
-
expand(keys);
|
|
363
424
|
const child = firstEnabled(last.children ?? []);
|
|
364
|
-
|
|
425
|
+
expand(child ? [...keys, child.value] : keys);
|
|
365
426
|
};
|
|
366
427
|
|
|
367
428
|
const nav = createListNav({
|
|
@@ -401,12 +462,20 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
401
462
|
return;
|
|
402
463
|
}
|
|
403
464
|
if (!open) {
|
|
404
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
|
|
465
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter' || (!bool(p().searchable) && event.key === ' ')) {
|
|
405
466
|
event.preventDefault();
|
|
406
467
|
openPanel();
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (!bool(p().searchable) && !event.ctrlKey && !event.metaKey && !event.altKey && (event.key.length === 1 || event.key === 'Backspace' || event.key === 'Delete')) {
|
|
471
|
+
event.preventDefault();
|
|
407
472
|
}
|
|
408
473
|
return;
|
|
409
474
|
}
|
|
475
|
+
if (!bool(p().searchable) && !event.ctrlKey && !event.metaKey && !event.altKey && (event.key.length === 1 || event.key === 'Backspace' || event.key === 'Delete')) {
|
|
476
|
+
event.preventDefault();
|
|
477
|
+
if (event.key !== ' ') return;
|
|
478
|
+
}
|
|
410
479
|
if (!searching()) {
|
|
411
480
|
const arrow = kitKey(event.key, event.target as Element | null);
|
|
412
481
|
if (arrow === 'ArrowRight') {
|
|
@@ -445,8 +514,16 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
445
514
|
}
|
|
446
515
|
if (nav.handle(event)) event.preventDefault();
|
|
447
516
|
};
|
|
517
|
+
const onBeforeInput = (event: Event): void => {
|
|
518
|
+
if (!bool(p().searchable) || locked()) event.preventDefault();
|
|
519
|
+
};
|
|
448
520
|
const onInput = (): void => {
|
|
449
|
-
if (
|
|
521
|
+
if (!bool(p().searchable)) {
|
|
522
|
+
const label = selectedText();
|
|
523
|
+
if (input.value !== label) input.value = label;
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (composing || locked()) return;
|
|
450
527
|
if (!open) open = true;
|
|
451
528
|
typing = true;
|
|
452
529
|
query = input.value;
|
|
@@ -455,6 +532,15 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
455
532
|
searchCursor = first ? pathAttr(first.keys) : null;
|
|
456
533
|
paint();
|
|
457
534
|
};
|
|
535
|
+
const onClearMouseDown = (event: Event): void => { event.preventDefault(); };
|
|
536
|
+
const onClearClick = (): void => {
|
|
537
|
+
if (locked() || !bool(p().clearable)) return;
|
|
538
|
+
typing = false;
|
|
539
|
+
query = '';
|
|
540
|
+
api.emit('change', { value: [], labels: [] });
|
|
541
|
+
closePanel();
|
|
542
|
+
input.focus();
|
|
543
|
+
};
|
|
458
544
|
const onClick = (): void => {
|
|
459
545
|
if (open && !bool(p().searchable)) closePanel();
|
|
460
546
|
else openPanel();
|
|
@@ -468,34 +554,46 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
468
554
|
const onCompEnd = (): void => { composing = false; onInput(); };
|
|
469
555
|
const onPanelMouseDown = (event: Event): void => { event.preventDefault(); };
|
|
470
556
|
const onPanelClick = (event: Event): void => {
|
|
471
|
-
const row = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
472
|
-
const raw = row?.getAttribute(
|
|
557
|
+
const row = (event.target as HTMLElement | null)?.closest<HTMLElement>(`[${KIT_ATTR_PATH}]`);
|
|
558
|
+
const raw = row?.getAttribute(KIT_ATTR_PATH);
|
|
473
559
|
if (!row || raw === null || raw === undefined) return;
|
|
474
560
|
if (row.getAttribute('aria-disabled') === 'true') return;
|
|
475
561
|
activate(JSON.parse(raw) as string[]);
|
|
476
562
|
};
|
|
477
563
|
input.addEventListener('keydown', onKeydown);
|
|
564
|
+
input.addEventListener('beforeinput', onBeforeInput);
|
|
565
|
+
input.addEventListener('paste', onBeforeInput);
|
|
478
566
|
input.addEventListener('input', onInput);
|
|
479
567
|
input.addEventListener('click', onClick);
|
|
480
568
|
input.addEventListener('focus', onFocus);
|
|
481
569
|
input.addEventListener('blur', onBlur);
|
|
482
570
|
input.addEventListener('compositionstart', onCompStart);
|
|
483
571
|
input.addEventListener('compositionend', onCompEnd);
|
|
572
|
+
clear.addEventListener('mousedown', onClearMouseDown);
|
|
573
|
+
clear.addEventListener('click', onClearClick);
|
|
484
574
|
panel.addEventListener('mousedown', onPanelMouseDown);
|
|
485
575
|
panel.addEventListener('click', onPanelClick);
|
|
486
576
|
const offOutside = onOutsidePress(root, () => open, closePanel);
|
|
487
577
|
return () => {
|
|
488
578
|
input.removeEventListener('keydown', onKeydown);
|
|
579
|
+
input.removeEventListener('beforeinput', onBeforeInput);
|
|
580
|
+
input.removeEventListener('paste', onBeforeInput);
|
|
489
581
|
input.removeEventListener('input', onInput);
|
|
490
582
|
input.removeEventListener('click', onClick);
|
|
491
583
|
input.removeEventListener('focus', onFocus);
|
|
492
584
|
input.removeEventListener('blur', onBlur);
|
|
493
585
|
input.removeEventListener('compositionstart', onCompStart);
|
|
494
586
|
input.removeEventListener('compositionend', onCompEnd);
|
|
587
|
+
clear.removeEventListener('mousedown', onClearMouseDown);
|
|
588
|
+
clear.removeEventListener('click', onClearClick);
|
|
495
589
|
panel.removeEventListener('mousedown', onPanelMouseDown);
|
|
496
590
|
panel.removeEventListener('click', onPanelClick);
|
|
497
591
|
offOutside();
|
|
498
592
|
releaseDropdown(panel, false);
|
|
593
|
+
for (const h of hiddenEls) h.remove();
|
|
594
|
+
hiddenEls.length = 0;
|
|
595
|
+
clear.remove();
|
|
596
|
+
caret.remove();
|
|
499
597
|
paintFn = null;
|
|
500
598
|
open = false;
|
|
501
599
|
requested.clear();
|
|
@@ -503,14 +601,27 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
503
601
|
},
|
|
504
602
|
render(root, p) {
|
|
505
603
|
const input = root.querySelector<HTMLInputElement>('[data-soma-id="input"], [data-soma-scoped-id="input"]') as HTMLInputElement;
|
|
506
|
-
|
|
604
|
+
const disabled = bool(p.disabled);
|
|
605
|
+
const readonly = bool(p.readonly);
|
|
606
|
+
const searchable = bool(p.searchable);
|
|
607
|
+
const clearable = bool(p.clearable);
|
|
608
|
+
// 高度档:组件自己非缺省的 size 优先,否则取页面线的 kit.controlSize
|
|
609
|
+
const size = kitControlSizeOf(p, kitReadProps(p));
|
|
610
|
+
const fieldBase = readonly ? FIELD_CLASS[size] : FIELD_TRIGGER_CLASS[size];
|
|
611
|
+
kitMarkDataState(root, readonly ? 'readonly' : 'normal');
|
|
612
|
+
const triggerExtra = !searchable && !readonly && !disabled ? ` ${TRIGGER_IDLE_EXTRA}` : '';
|
|
613
|
+
const padExtra = ` ${clearable ? PAD_CLEAR : PAD_CHEVRON}`;
|
|
614
|
+
input.className = withInvalid(`${fieldBase}${triggerExtra}${padExtra}`, bool(p.invalid));
|
|
507
615
|
input.placeholder = str(p.placeholder);
|
|
508
|
-
applyDisabled(input,
|
|
509
|
-
//
|
|
510
|
-
setBoolAttr(input, 'readonly',
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
616
|
+
applyDisabled(input, disabled);
|
|
617
|
+
// 仅在 p.readonly === true 时挂原生 readonly(防非搜索常态命中只读底色变灰)
|
|
618
|
+
setBoolAttr(input, 'readonly', readonly);
|
|
619
|
+
if (readonly) input.setAttribute('aria-readonly', 'true');
|
|
620
|
+
else input.removeAttribute('aria-readonly');
|
|
621
|
+
setAttr(input, 'inputmode', !searchable && !readonly ? 'none' : '');
|
|
622
|
+
setAttr(input, 'aria-autocomplete', searchable ? 'list' : 'none');
|
|
623
|
+
applyCommon(input, { ...p, name: '' });
|
|
624
|
+
if (disabled || readonly) open = false;
|
|
514
625
|
root.className = joinClass(WRAP, p.class);
|
|
515
626
|
paintFn?.();
|
|
516
627
|
// 页面补进了懒加载的 children:该节点的子列自动补画;已加载的节点允许再次触发
|
|
@@ -521,6 +632,6 @@ export function createCascader(): SomaComponentDefinition {
|
|
|
521
632
|
}
|
|
522
633
|
},
|
|
523
634
|
};
|
|
524
|
-
}),
|
|
635
|
+
}, { self: { level: 'control' } }),
|
|
525
636
|
};
|
|
526
637
|
}
|