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/range.ts
CHANGED
|
@@ -16,27 +16,54 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
16
16
|
import { kitDirAt, kitKey, kitText } from '../i18n/kit-text';
|
|
17
17
|
import {
|
|
18
18
|
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
19
|
-
applyCompositeField, bool, classCandidates, createKitController, joinClass, num, setAttr,
|
|
19
|
+
applyCompositeField, bool, classCandidates, createKitController, joinClass, kitControlSizeOf, kitMarkDataState, kitOuterRoot, num, setAttr, str, syncKitTextValue,
|
|
20
20
|
type KitApi, type KitProps, type KitSize,
|
|
21
21
|
} from './shared';
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
import { KIT_RANGE_LIMITS } from 'soma-foundation/kit-limits';
|
|
24
|
+
import { setKitFace } from '../recipes';
|
|
25
|
+
import { KIT_CONTROL_THUMB_CLASS, KIT_CONTROL_TRACK_CLASS } from '../recipes/color-role';
|
|
26
|
+
import { kitControlRecipe } from '../recipes/control';
|
|
27
|
+
import { mergeClass } from '../shared/merge-class';
|
|
28
|
+
import { KIT_ATTR_MARK_DOT, KIT_ATTR_THUMB, KIT_ATTR_VALUE } from '../shared/dom-attrs';
|
|
29
|
+
|
|
30
|
+
const WRAP_CLASS ={ horizontal: 'block w-full px-2', vertical: 'inline-block px-2 py-2' } as const;
|
|
31
|
+
const WRAP_OFF_CLASS = { horizontal: 'block w-full cursor-not-allowed px-2', vertical: 'inline-block cursor-not-allowed px-2 py-2' } as const;
|
|
25
32
|
/** 竖向滑块的高度随 size 取档(sm h-32 / md h-40 / lg h-48),不再固定一档 */
|
|
26
|
-
const WRAP_VERTICAL_HEIGHT: Record<KitSize, string> = { sm: 'h-32', md: 'h-
|
|
33
|
+
const WRAP_VERTICAL_HEIGHT: Record<KitSize, string> = { sm: 'h-32', md: 'h-44', lg: 'h-48' };
|
|
34
|
+
// 带输入框(show_input,单值横向):滑块 + 数字输入并排,间距 16(gap-4),输入框宽 64(w-16,真源 range.inputWidthPx)
|
|
35
|
+
const WRAP_INPUT_CLASS = 'flex w-full items-center gap-4 px-2';
|
|
36
|
+
const WRAP_INPUT_OFF_CLASS = 'flex w-full cursor-not-allowed items-center gap-4 px-2';
|
|
37
|
+
const INPUT_CLASS: Record<KitSize, string> = {
|
|
38
|
+
sm: mergeClass(kitControlRecipe({ size: 'sm' }), 'w-16 shrink-0 tabular-nums'),
|
|
39
|
+
md: mergeClass(kitControlRecipe({ size: 'md' }), 'w-16 shrink-0 tabular-nums'),
|
|
40
|
+
lg: mergeClass(kitControlRecipe({ size: 'lg' }), 'w-16 shrink-0 tabular-nums'),
|
|
41
|
+
};
|
|
27
42
|
const SVG_CLASS = 'block cursor-pointer touch-none overflow-visible';
|
|
28
|
-
const TRACK_CLASS = 'fill-
|
|
43
|
+
const TRACK_CLASS = mergeClass('fill-control-track', KIT_CONTROL_TRACK_CLASS);
|
|
29
44
|
const FILL_CLASS = 'fill-primary';
|
|
30
|
-
const THUMB_CLASS =
|
|
31
|
-
|
|
45
|
+
const THUMB_CLASS = mergeClass(
|
|
46
|
+
'peer cursor-pointer fill-control-thumb stroke-primary stroke-2 focus-visible:outline-none focus-visible:stroke-ring',
|
|
47
|
+
KIT_CONTROL_THUMB_CLASS,
|
|
48
|
+
);
|
|
49
|
+
// 禁用态(KT-K0-4):不整体降透明度,填充段与滑块各取禁用令牌色
|
|
50
|
+
const FILL_OFF_CLASS = 'fill-fg-disabled';
|
|
51
|
+
const THUMB_OFF_CLASS = mergeClass(
|
|
52
|
+
'peer cursor-not-allowed fill-control-thumb stroke-fg-disabled stroke-2 focus-visible:outline-none',
|
|
53
|
+
KIT_CONTROL_THUMB_CLASS,
|
|
54
|
+
);
|
|
55
|
+
const HALO_CLASS ='pointer-events-none fill-none stroke-ring stroke-2 opacity-0 peer-focus-visible:opacity-100';
|
|
32
56
|
const TICK_CLASS = 'stroke-border stroke-1';
|
|
57
|
+
const MARK_DOT_ON_CLASS = 'fill-control-thumb stroke-primary stroke-2';
|
|
58
|
+
const MARK_DOT_OFF_CLASS = 'fill-control-thumb stroke-border stroke-2';
|
|
33
59
|
const MARK_TEXT_CLASS = 'fill-fg-subtle text-xs';
|
|
34
60
|
const BUBBLE_CLASS = 'fill-fg text-xs font-medium';
|
|
35
61
|
const HIDDEN_CLASS = 'hidden';
|
|
36
62
|
|
|
37
63
|
export const KIT_RANGE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
38
64
|
Object.values(WRAP_CLASS), Object.values(WRAP_OFF_CLASS), Object.values(WRAP_VERTICAL_HEIGHT), SVG_CLASS, TRACK_CLASS, FILL_CLASS,
|
|
39
|
-
THUMB_CLASS, HALO_CLASS, TICK_CLASS, MARK_TEXT_CLASS, BUBBLE_CLASS, HIDDEN_CLASS,
|
|
65
|
+
THUMB_CLASS, FILL_OFF_CLASS, THUMB_OFF_CLASS, HALO_CLASS, TICK_CLASS, MARK_DOT_ON_CLASS, MARK_DOT_OFF_CLASS, MARK_TEXT_CLASS, BUBBLE_CLASS, HIDDEN_CLASS,
|
|
66
|
+
WRAP_INPUT_CLASS, WRAP_INPUT_OFF_CLASS, Object.values(INPUT_CLASS), `${SVG_CLASS} min-w-0 flex-1`,
|
|
40
67
|
);
|
|
41
68
|
|
|
42
69
|
/** page:PageUp / PageDown 跨度,0 = 十分之一量程(至少一步);借鉴老 soma-ui slider 的 page_step */
|
|
@@ -123,10 +150,12 @@ export function marksOf(raw: unknown, spec: RangeSpec): RangeMark[] {
|
|
|
123
150
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
124
151
|
const svgEl = (tag: string): SVGElement => document.createElementNS(SVG_NS, tag);
|
|
125
152
|
|
|
126
|
-
|
|
127
|
-
const
|
|
153
|
+
// 轨粗与滑柄半径取真源 kit-limits#range(轨 4、md 柄外径 16 = 2 × 7 + 描边 2;组件卡 Slider §5;竖向 md 高 176 = h-44)
|
|
154
|
+
const TRACK_THICKNESS: Record<KitSize, number> = KIT_RANGE_LIMITS.trackPx;
|
|
155
|
+
const THUMB_RADIUS: Record<KitSize, number> = KIT_RANGE_LIMITS.thumbRadiusPx;
|
|
128
156
|
|
|
129
157
|
type Which = 'lo' | 'hi';
|
|
158
|
+
type DragState = Which | 'pending' | null;
|
|
130
159
|
|
|
131
160
|
interface Thumb { g: SVGElement; dot: SVGElement; halo: SVGElement; bubble: SVGElement }
|
|
132
161
|
|
|
@@ -139,7 +168,17 @@ interface CustomUi {
|
|
|
139
168
|
ticks: SVGElement;
|
|
140
169
|
lo: Thumb;
|
|
141
170
|
hi: Thumb;
|
|
142
|
-
dragging:
|
|
171
|
+
dragging: DragState;
|
|
172
|
+
pendingValue: number;
|
|
173
|
+
pendingClientX: number;
|
|
174
|
+
pendingClientY: number;
|
|
175
|
+
/** show_input 的数字输入框(单值横向时才有) */
|
|
176
|
+
input: HTMLInputElement | null;
|
|
177
|
+
lastSpec: RangeSpec | null;
|
|
178
|
+
lastHi: number;
|
|
179
|
+
lastSubmitted: number | null;
|
|
180
|
+
/** 把单值滑块的值提交为 next(吸附后的值),与拖动 / 键盘同一条 change 出口 */
|
|
181
|
+
commitHi(next: number): void;
|
|
143
182
|
dispose(): void;
|
|
144
183
|
}
|
|
145
184
|
|
|
@@ -150,7 +189,7 @@ function makeThumb(which: Which): Thumb {
|
|
|
150
189
|
const dot = svgEl('circle');
|
|
151
190
|
dot.setAttribute('class', THUMB_CLASS);
|
|
152
191
|
dot.setAttribute('role', 'slider');
|
|
153
|
-
dot.setAttribute(
|
|
192
|
+
dot.setAttribute(KIT_ATTR_THUMB, which);
|
|
154
193
|
const halo = svgEl('circle');
|
|
155
194
|
halo.setAttribute('class', HALO_CLASS);
|
|
156
195
|
halo.setAttribute('aria-hidden', 'true');
|
|
@@ -176,7 +215,8 @@ function currentPair(p: KitProps, spec: RangeSpec): { lo: number; hi: number } {
|
|
|
176
215
|
|
|
177
216
|
function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
|
|
178
217
|
const spec = rangeSpecOf(p);
|
|
179
|
-
|
|
218
|
+
// 档位(轨道粗细 / 滑块半径):自己的非缺省 size 优先,否则取页面线的 kit.controlSize(没有 kit 时与 sizeOf 相同)
|
|
219
|
+
const size = kitControlSizeOf(p);
|
|
180
220
|
const range = bool(p.range);
|
|
181
221
|
const vertical = p.orientation === 'vertical';
|
|
182
222
|
const showBubble = bool(p.value_label);
|
|
@@ -195,9 +235,67 @@ function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
|
|
|
195
235
|
const along = (v: number): number => (rtl ? 1 - frac(v) : frac(v));
|
|
196
236
|
const pct = (v: number): string => `${along(v) * 100}%`;
|
|
197
237
|
|
|
198
|
-
|
|
238
|
+
// 带输入框:仅单值横向;滑块吃余宽(flex-1),输入框宽 64(w-16 = kit-limits#range.inputWidthPx)、与滑块左距 16(gap-4)
|
|
239
|
+
const withInput = bool(p.show_input) && !range && !vertical;
|
|
240
|
+
const wrapBase = withInput ? (disabled ? WRAP_INPUT_OFF_CLASS : WRAP_INPUT_CLASS) : disabled ? WRAP_OFF_CLASS[dir] : WRAP_CLASS[dir];
|
|
241
|
+
ui.wrap.className = joinClass(`${wrapBase}${vertical ? ` ${WRAP_VERTICAL_HEIGHT[size]}` : ''}`, p.class);
|
|
199
242
|
setAttr(ui.wrap, 'id', str(p.id));
|
|
200
|
-
ui.svg.setAttribute('class', SVG_CLASS);
|
|
243
|
+
ui.svg.setAttribute('class', withInput ? `${SVG_CLASS} min-w-0 flex-1` : SVG_CLASS);
|
|
244
|
+
if (withInput) {
|
|
245
|
+
if (ui.input === null) {
|
|
246
|
+
const input = document.createElement('input');
|
|
247
|
+
input.type = 'text';
|
|
248
|
+
input.inputMode = 'decimal';
|
|
249
|
+
input.autocomplete = 'off';
|
|
250
|
+
input.spellcheck = false;
|
|
251
|
+
setKitFace(input, 'field');
|
|
252
|
+
const submitInput = (): void => {
|
|
253
|
+
const cur = ui.lastSpec;
|
|
254
|
+
if (cur === null || input.disabled || input.readOnly) {
|
|
255
|
+
input.value = String(ui.lastHi);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const trimmed = input.value.trim();
|
|
259
|
+
const next = trimmed === '' ? null : num(trimmed);
|
|
260
|
+
if (next === null) {
|
|
261
|
+
input.value = String(ui.lastHi);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const snapped = snapRange(next, cur);
|
|
265
|
+
input.value = String(snapped);
|
|
266
|
+
if (ui.lastSubmitted === snapped) return;
|
|
267
|
+
ui.lastSubmitted = snapped;
|
|
268
|
+
ui.commitHi(snapped);
|
|
269
|
+
};
|
|
270
|
+
input.addEventListener('input', () => { ui.lastSubmitted = null; });
|
|
271
|
+
input.addEventListener('change', submitInput);
|
|
272
|
+
input.addEventListener('blur', submitInput);
|
|
273
|
+
input.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
274
|
+
if (e.key === 'Enter') {
|
|
275
|
+
e.preventDefault();
|
|
276
|
+
submitInput();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
ui.wrap.appendChild(input);
|
|
280
|
+
ui.input = input;
|
|
281
|
+
}
|
|
282
|
+
const input = ui.input;
|
|
283
|
+
input.className = joinClass(INPUT_CLASS[size], '');
|
|
284
|
+
input.disabled = disabled;
|
|
285
|
+
input.readOnly = readonly;
|
|
286
|
+
const inputName = str(p.aria_label);
|
|
287
|
+
if (inputName !== '') input.setAttribute('aria-label', inputName); else input.removeAttribute('aria-label');
|
|
288
|
+
const propChanged = hi !== ui.lastHi;
|
|
289
|
+
if (propChanged || input.ownerDocument.activeElement !== input) {
|
|
290
|
+
syncKitTextValue(input, String(hi));
|
|
291
|
+
}
|
|
292
|
+
} else if (ui.input !== null) {
|
|
293
|
+
ui.input.remove();
|
|
294
|
+
ui.input = null;
|
|
295
|
+
}
|
|
296
|
+
ui.lastSpec = spec;
|
|
297
|
+
ui.lastHi = hi;
|
|
298
|
+
ui.lastSubmitted = null;
|
|
201
299
|
|
|
202
300
|
// 表单值载体:hidden input(单值一个;range 起、止各一个,同名)
|
|
203
301
|
const formVals = range ? [lo, hi] : [hi];
|
|
@@ -205,7 +303,7 @@ function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
|
|
|
205
303
|
while (ui.hiddens.length < formVals.length) {
|
|
206
304
|
const h = document.createElement('input');
|
|
207
305
|
h.type = 'hidden';
|
|
208
|
-
h.setAttribute(
|
|
306
|
+
h.setAttribute(KIT_ATTR_VALUE, '');
|
|
209
307
|
ui.wrap.appendChild(h);
|
|
210
308
|
ui.hiddens.push(h);
|
|
211
309
|
}
|
|
@@ -218,36 +316,42 @@ function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
|
|
|
218
316
|
// 布局常量(像素,写成 SVG 属性)
|
|
219
317
|
const bubbleRoom = showBubble ? (vertical ? 36 : 20) : 0;
|
|
220
318
|
const markRoom = marks.length > 0 ? (vertical ? 40 : 32) : 0;
|
|
221
|
-
|
|
319
|
+
// 命中区高 = 真源 range.hitPx(Ant 外层 12 + 轨 4 + 12 ≈ 32;轨居中,滑柄与轨都落在命中区内)
|
|
320
|
+
const hit = KIT_RANGE_LIMITS.hitPx;
|
|
321
|
+
const lane = bubbleRoom + hit / 2;
|
|
222
322
|
if (vertical) {
|
|
223
|
-
setAttrs(ui.svg, { width: bubbleRoom +
|
|
323
|
+
setAttrs(ui.svg, { width: bubbleRoom + hit + markRoom, height: '100%' });
|
|
224
324
|
setAttrs(ui.track, { x: lane - th / 2, y: 0, width: th, height: '100%', rx: th / 2 });
|
|
225
325
|
setAttrs(ui.fill, { x: lane - th / 2, y: pctRev(hi), width: th, height: `${((hi - lo) / span) * 100}%`, rx: th / 2 });
|
|
226
326
|
} else {
|
|
227
|
-
setAttrs(ui.svg, { width: '100%', height: bubbleRoom +
|
|
327
|
+
setAttrs(ui.svg, { width: '100%', height: bubbleRoom + hit + markRoom });
|
|
228
328
|
setAttrs(ui.track, { x: 0, y: lane - th / 2, width: '100%', height: th, rx: th / 2 });
|
|
229
329
|
setAttrs(ui.fill, { x: pct(rtl ? hi : lo), y: lane - th / 2, width: `${((hi - lo) / span) * 100}%`, height: th, rx: th / 2 });
|
|
230
330
|
}
|
|
231
331
|
ui.track.setAttribute('class', TRACK_CLASS);
|
|
232
|
-
ui.fill.setAttribute('class', FILL_CLASS);
|
|
332
|
+
ui.fill.setAttribute('class', disabled ? FILL_OFF_CLASS : FILL_CLASS);
|
|
233
333
|
|
|
234
334
|
// 刻度
|
|
235
335
|
ui.ticks.textContent = '';
|
|
236
336
|
for (const m of marks) {
|
|
237
|
-
|
|
337
|
+
// 刻度点画在轨上(Slider 卡):空心圆,落在已选段内(lo..hi,单值为 min..hi)的取主色描边,段外取线色描边;文字留在轨旁
|
|
338
|
+
const dot = svgEl('circle');
|
|
238
339
|
const text = svgEl('text');
|
|
239
|
-
|
|
340
|
+
const inFill = m.value <= hi && m.value >= (range ? lo : spec.min);
|
|
341
|
+
dot.setAttribute('class', inFill && !disabled ? MARK_DOT_ON_CLASS : MARK_DOT_OFF_CLASS);
|
|
342
|
+
dot.setAttribute(KIT_ATTR_MARK_DOT, inFill ? 'on' : 'off');
|
|
343
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
240
344
|
text.setAttribute('class', MARK_TEXT_CLASS);
|
|
241
345
|
text.setAttribute('aria-hidden', 'true');
|
|
242
346
|
text.textContent = m.label;
|
|
243
347
|
if (vertical) {
|
|
244
|
-
setAttrs(
|
|
348
|
+
setAttrs(dot, { cx: lane, cy: pctRev(m.value), r: th });
|
|
245
349
|
setAttrs(text, { x: lane + 18, y: pctRev(m.value), 'text-anchor': 'start', 'dominant-baseline': 'middle' });
|
|
246
350
|
} else {
|
|
247
|
-
setAttrs(
|
|
351
|
+
setAttrs(dot, { cx: pct(m.value), cy: lane, r: th });
|
|
248
352
|
setAttrs(text, { x: pct(m.value), y: lane + 28, 'text-anchor': 'middle' });
|
|
249
353
|
}
|
|
250
|
-
ui.ticks.appendChild(
|
|
354
|
+
ui.ticks.appendChild(dot);
|
|
251
355
|
ui.ticks.appendChild(text);
|
|
252
356
|
}
|
|
253
357
|
|
|
@@ -280,6 +384,7 @@ function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
|
|
|
280
384
|
const name = aria === '' ? side : side === '' ? aria : `${aria} ${side}`;
|
|
281
385
|
if (name === '') t.dot.removeAttribute('aria-label');
|
|
282
386
|
else t.dot.setAttribute('aria-label', name);
|
|
387
|
+
t.dot.setAttribute('class', disabled ? THUMB_OFF_CLASS : THUMB_CLASS);
|
|
283
388
|
if (disabled) t.dot.setAttribute('aria-disabled', 'true'); else t.dot.removeAttribute('aria-disabled');
|
|
284
389
|
if (readonly) t.dot.setAttribute('aria-readonly', 'true'); else t.dot.removeAttribute('aria-readonly');
|
|
285
390
|
};
|
|
@@ -320,7 +425,11 @@ function buildCustomUi(root: HTMLElement, api: KitApi): CustomUi {
|
|
|
320
425
|
svg.appendChild(lo.bubble);
|
|
321
426
|
svg.appendChild(hi.bubble);
|
|
322
427
|
wrap.appendChild(svg);
|
|
323
|
-
const ui: CustomUi = {
|
|
428
|
+
const ui: CustomUi = {
|
|
429
|
+
wrap, svg, hiddens: [], track, fill, ticks, lo, hi,
|
|
430
|
+
dragging: null, pendingValue: 0, pendingClientX: 0, pendingClientY: 0,
|
|
431
|
+
input: null, lastSpec: null, lastHi: 0, lastSubmitted: null, commitHi: () => {}, dispose: () => {},
|
|
432
|
+
};
|
|
324
433
|
|
|
325
434
|
const locked = (): boolean => bool(api.props().disabled) || bool(api.props().readonly);
|
|
326
435
|
const commit = (which: Which, next: number): void => {
|
|
@@ -337,6 +446,7 @@ function buildCustomUi(root: HTMLElement, api: KitApi): CustomUi {
|
|
|
337
446
|
api.emit('change', { value: next });
|
|
338
447
|
}
|
|
339
448
|
};
|
|
449
|
+
ui.commitHi = (next) => { if (!locked()) commit('hi', next); };
|
|
340
450
|
const valueAt = (event: PointerEvent): number => {
|
|
341
451
|
const p = api.props();
|
|
342
452
|
const spec = rangeSpecOf(p);
|
|
@@ -360,27 +470,68 @@ function buildCustomUi(root: HTMLElement, api: KitApi): CustomUi {
|
|
|
360
470
|
const onPointerDown = (event: PointerEvent): void => {
|
|
361
471
|
if (locked() || event.button > 0) return;
|
|
362
472
|
event.preventDefault();
|
|
473
|
+
const p = api.props();
|
|
474
|
+
const cur = currentPair(p, rangeSpecOf(p));
|
|
363
475
|
const value = valueAt(event);
|
|
364
|
-
const which = nearest(value);
|
|
365
|
-
ui.dragging = which;
|
|
366
|
-
const thumb = which === 'lo' ? lo : hi;
|
|
367
|
-
(thumb.dot as unknown as HTMLElement).focus?.();
|
|
368
476
|
const capture = (svg as unknown as { setPointerCapture?: (id: number) => void }).setPointerCapture;
|
|
369
477
|
if (typeof capture === 'function') {
|
|
370
478
|
try { capture.call(svg, event.pointerId); } catch { /* 合成事件没有活动指针,忽略 */ }
|
|
371
479
|
}
|
|
480
|
+
if (bool(p.range) && cur.lo === cur.hi) {
|
|
481
|
+
ui.dragging = 'pending';
|
|
482
|
+
ui.pendingValue = value;
|
|
483
|
+
ui.pendingClientX = event.clientX;
|
|
484
|
+
ui.pendingClientY = event.clientY;
|
|
485
|
+
(lo.dot as unknown as HTMLElement).focus?.();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const which = nearest(value);
|
|
489
|
+
ui.dragging = which;
|
|
490
|
+
const thumb = which === 'lo' ? lo : hi;
|
|
491
|
+
(thumb.dot as unknown as HTMLElement).focus?.();
|
|
372
492
|
commit(which, value);
|
|
373
493
|
};
|
|
374
494
|
const onPointerMove = (event: PointerEvent): void => {
|
|
375
495
|
if (ui.dragging === null || locked()) return;
|
|
376
|
-
|
|
496
|
+
const next = valueAt(event);
|
|
497
|
+
if (ui.dragging === 'pending') {
|
|
498
|
+
const moved = event.clientX !== ui.pendingClientX || event.clientY !== ui.pendingClientY || next !== ui.pendingValue;
|
|
499
|
+
if (!moved) return;
|
|
500
|
+
const p = api.props();
|
|
501
|
+
const cur = currentPair(p, rangeSpecOf(p));
|
|
502
|
+
if (next < cur.lo) {
|
|
503
|
+
ui.dragging = 'lo';
|
|
504
|
+
(lo.dot as unknown as HTMLElement).focus?.();
|
|
505
|
+
commit('lo', next);
|
|
506
|
+
} else if (next > cur.hi) {
|
|
507
|
+
ui.dragging = 'hi';
|
|
508
|
+
(hi.dot as unknown as HTMLElement).focus?.();
|
|
509
|
+
commit('hi', next);
|
|
510
|
+
}
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
commit(ui.dragging, next);
|
|
514
|
+
};
|
|
515
|
+
const onPointerUp = (): void => {
|
|
516
|
+
if (ui.dragging === 'pending' && !locked()) {
|
|
517
|
+
const p = api.props();
|
|
518
|
+
const cur = currentPair(p, rangeSpecOf(p));
|
|
519
|
+
if (ui.pendingValue < cur.lo) {
|
|
520
|
+
(lo.dot as unknown as HTMLElement).focus?.();
|
|
521
|
+
commit('lo', ui.pendingValue);
|
|
522
|
+
} else if (ui.pendingValue > cur.hi) {
|
|
523
|
+
(hi.dot as unknown as HTMLElement).focus?.();
|
|
524
|
+
commit('hi', ui.pendingValue);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
ui.dragging = null;
|
|
377
528
|
};
|
|
378
|
-
const
|
|
529
|
+
const onPointerCancel = (): void => { ui.dragging = null; };
|
|
379
530
|
const onKeydown = (event: KeyboardEvent): void => {
|
|
380
531
|
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
381
|
-
const dot = (event.target as Element | null)?.closest(
|
|
532
|
+
const dot = (event.target as Element | null)?.closest(`[${KIT_ATTR_THUMB}]`);
|
|
382
533
|
if (!dot) return;
|
|
383
|
-
const which = dot.getAttribute(
|
|
534
|
+
const which = dot.getAttribute(KIT_ATTR_THUMB) as Which;
|
|
384
535
|
const p = api.props();
|
|
385
536
|
const spec = rangeSpecOf(p);
|
|
386
537
|
const cur = currentPair(p, spec);
|
|
@@ -393,16 +544,18 @@ function buildCustomUi(root: HTMLElement, api: KitApi): CustomUi {
|
|
|
393
544
|
};
|
|
394
545
|
svg.addEventListener('pointerdown', onPointerDown as EventListener);
|
|
395
546
|
svg.addEventListener('pointermove', onPointerMove as EventListener);
|
|
396
|
-
svg.addEventListener('pointerup',
|
|
397
|
-
svg.addEventListener('pointercancel',
|
|
547
|
+
svg.addEventListener('pointerup', onPointerUp);
|
|
548
|
+
svg.addEventListener('pointercancel', onPointerCancel);
|
|
398
549
|
svg.addEventListener('keydown', onKeydown as EventListener);
|
|
399
550
|
ui.dispose = () => {
|
|
400
551
|
svg.removeEventListener('pointerdown', onPointerDown as EventListener);
|
|
401
552
|
svg.removeEventListener('pointermove', onPointerMove as EventListener);
|
|
402
|
-
svg.removeEventListener('pointerup',
|
|
403
|
-
svg.removeEventListener('pointercancel',
|
|
553
|
+
svg.removeEventListener('pointerup', onPointerUp);
|
|
554
|
+
svg.removeEventListener('pointercancel', onPointerCancel);
|
|
404
555
|
svg.removeEventListener('keydown', onKeydown as EventListener);
|
|
405
556
|
svg.remove();
|
|
557
|
+
ui.input?.remove();
|
|
558
|
+
ui.input = null;
|
|
406
559
|
for (const h of ui.hiddens) h.remove();
|
|
407
560
|
ui.hiddens.length = 0;
|
|
408
561
|
};
|
|
@@ -431,6 +584,7 @@ export function createRange(): SomaComponentDefinition {
|
|
|
431
584
|
range: { type: 'boolean', default: false, desc: '双滑块:value 是 { start, end },起点不越过终点(改画 SVG 滑块)' },
|
|
432
585
|
marks: { type: 'array', default: [], desc: '刻度 [数字 | { value, label? }],轨道下方(竖向时右侧)画刻度线与文字(改画 SVG 滑块)' },
|
|
433
586
|
value_label: { type: 'boolean', default: false, desc: '在滑块旁显示当前数值(改画 SVG 滑块)' },
|
|
587
|
+
show_input: { type: 'boolean', default: false, desc: '滑块右侧带数字输入框(宽 64、与滑块距 16),输入吸附到步长并夹进量程,与滑块同一条 change;仅单值横向(range / vertical 忽略)' },
|
|
434
588
|
orientation: { type: 'enum', values: ['horizontal', 'vertical'], default: 'horizontal', desc: '方向;vertical 竖向,上大下小(改画 SVG 滑块)' },
|
|
435
589
|
disabled: { type: 'boolean', default: false },
|
|
436
590
|
readonly: { type: 'boolean', default: false },
|
|
@@ -455,7 +609,8 @@ export function createRange(): SomaComponentDefinition {
|
|
|
455
609
|
customUis.set(root, ui);
|
|
456
610
|
}
|
|
457
611
|
paintCustom(root, p, ui);
|
|
612
|
+
kitMarkDataState(kitOuterRoot(api.host, root), bool(p.readonly) ? 'readonly' : 'normal');
|
|
458
613
|
},
|
|
459
|
-
})),
|
|
614
|
+
}), { self: { level: 'control' } }), // 滑块整体是一个输入控件
|
|
460
615
|
};
|
|
461
616
|
}
|
package/src/base/rating.ts
CHANGED
|
@@ -4,31 +4,35 @@
|
|
|
4
4
|
// 星形是 SVG(填充靠 fill 类 + clipPath 属性表达半星,不用内联样式)。受控:只抛 change { value: number }。
|
|
5
5
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
|
+
import { KIT_FOCUS_RING } from '../recipes/state';
|
|
7
8
|
import { kitKey } from '../i18n/kit-text';
|
|
8
9
|
import {
|
|
9
10
|
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
10
|
-
applyCommon, bool, classCandidates, createKitController, joinClass, nextUid, num, setAttr,
|
|
11
|
-
type KitSize, type KitView,
|
|
11
|
+
applyCommon, bool, classCandidates, createKitController, joinClass, kitControlSizeOf, kitMarkDataState, kitOuterRoot, nextUid, num, setAttr, str,
|
|
12
|
+
type KitProps, type KitSize, type KitView,
|
|
12
13
|
} from './shared';
|
|
13
14
|
|
|
14
15
|
// 排容器用 hit-gap-N(gap 同时写出 --kit-hit-gap),星的 hit-area-row 据此把沿排热区收到中心距,相邻热区相接不重叠
|
|
15
|
-
|
|
16
|
+
// 星大小 H·0.625(md 20)、星间距 8(取值表 03 §13:Ant 8 / Arco 8 / TDesign 8)
|
|
17
|
+
const GROUP_CLASS = 'inline-flex items-center hit-gap-2';
|
|
16
18
|
|
|
17
19
|
const STAR_CLASS: Record<KitSize, { edit: string; read: string }> = {
|
|
18
20
|
sm: {
|
|
19
|
-
edit: 'hit-area-row inline-flex h-
|
|
20
|
-
read: 'inline-flex h-
|
|
21
|
+
edit: 'hit-area-row inline-flex h-4 w-4 shrink-0 p-0 cursor-pointer items-center justify-center rounded-control transition-colors ' + KIT_FOCUS_RING.button,
|
|
22
|
+
read: 'inline-flex h-4 w-4 shrink-0 items-center justify-center',
|
|
21
23
|
},
|
|
22
24
|
md: {
|
|
23
|
-
edit: 'hit-area-row inline-flex h-
|
|
24
|
-
read: 'inline-flex h-
|
|
25
|
+
edit: 'hit-area-row inline-flex h-5 w-5 shrink-0 p-0 cursor-pointer items-center justify-center rounded-control transition-colors ' + KIT_FOCUS_RING.button,
|
|
26
|
+
read: 'inline-flex h-5 w-5 shrink-0 items-center justify-center',
|
|
25
27
|
},
|
|
26
28
|
lg: {
|
|
27
|
-
edit: 'hit-area-row inline-flex h-
|
|
28
|
-
read: 'inline-flex h-
|
|
29
|
+
edit: 'hit-area-row inline-flex h-6 w-6 shrink-0 p-0 cursor-pointer items-center justify-center rounded-control transition-colors ' + KIT_FOCUS_RING.button,
|
|
30
|
+
read: 'inline-flex h-6 w-6 shrink-0 items-center justify-center',
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
|
-
|
|
33
|
+
// 禁用态(KT-K0-4):不整体降透明度,已选部分改取禁用字色(fill-current 跟随 text-fg-disabled,高于未选底色)
|
|
34
|
+
const STAR_DISABLED = 'cursor-not-allowed';
|
|
35
|
+
const FILL_PATH_OFF_CLASS = 'fill-current text-fg-disabled';
|
|
32
36
|
const SVG_CLASS = 'h-full w-full';
|
|
33
37
|
const BASE_PATH_CLASS = 'fill-border';
|
|
34
38
|
const FILL_PATH_CLASS = 'fill-warning';
|
|
@@ -39,7 +43,7 @@ const HEART_PATH = 'M12 21s-8.5-5.3-8.5-11.2A4.8 4.8 0 0 1 12 7a4.8 4.8 0 0 1 8.
|
|
|
39
43
|
|
|
40
44
|
export const KIT_RATING_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
41
45
|
GROUP_CLASS, Object.values(STAR_CLASS).flatMap((c) => [c.edit, c.read]), STAR_DISABLED, SVG_CLASS,
|
|
42
|
-
BASE_PATH_CLASS, FILL_PATH_CLASS, HEART_FILL_CLASS, HIDDEN, 'cursor-not-allowed',
|
|
46
|
+
BASE_PATH_CLASS, FILL_PATH_CLASS, HEART_FILL_CLASS, HIDDEN, FILL_PATH_OFF_CLASS, 'cursor-not-allowed',
|
|
43
47
|
);
|
|
44
48
|
|
|
45
49
|
// 五角星(24 x 24 画布)
|
|
@@ -112,8 +116,28 @@ function buildStar(index: number): StarParts {
|
|
|
112
116
|
|
|
113
117
|
function makeView(): KitView {
|
|
114
118
|
let stars: StarParts[] = [];
|
|
119
|
+
let hiddenEl: HTMLInputElement | null = null;
|
|
120
|
+
let hoverValue: number | null = null;
|
|
115
121
|
let focusIndex = 0;
|
|
116
122
|
|
|
123
|
+
const paintVisualStars = (p: KitProps): void => {
|
|
124
|
+
const sp = ratingSpecOf(p);
|
|
125
|
+
const formalValue = ratingValue(p.value, sp);
|
|
126
|
+
const disabled = bool(p.disabled);
|
|
127
|
+
const readonly = bool(p.readonly);
|
|
128
|
+
const editable = !disabled && !readonly;
|
|
129
|
+
if (!editable) hoverValue = null;
|
|
130
|
+
const visualValue = editable && hoverValue !== null ? hoverValue : formalValue;
|
|
131
|
+
const heart = str(p.symbol) === 'heart';
|
|
132
|
+
stars.forEach((s, i) => {
|
|
133
|
+
const full = visualValue >= i + 1;
|
|
134
|
+
const half = !full && visualValue >= i + 0.5;
|
|
135
|
+
s.fill.setAttribute('class', full || half ? (disabled ? FILL_PATH_OFF_CLASS : heart ? HEART_FILL_CLASS : FILL_PATH_CLASS) : HIDDEN);
|
|
136
|
+
if (half) s.fill.setAttribute('clip-path', s.fill.dataset.clip ?? '');
|
|
137
|
+
else s.fill.removeAttribute('clip-path');
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
117
141
|
return {
|
|
118
142
|
attach(root, api) {
|
|
119
143
|
const spec = (): RatingSpec => ratingSpecOf(api.props());
|
|
@@ -122,6 +146,17 @@ function makeView(): KitView {
|
|
|
122
146
|
return bool(p.disabled) || bool(p.readonly);
|
|
123
147
|
};
|
|
124
148
|
const current = (): number => ratingValue(api.props().value, spec());
|
|
149
|
+
const pointerScore = (hit: HTMLElement, clientX: number): number => {
|
|
150
|
+
const index = Number(hit.dataset.index);
|
|
151
|
+
const sp = spec();
|
|
152
|
+
let next = index + 1;
|
|
153
|
+
if (sp.half) {
|
|
154
|
+
const rect = hit.getBoundingClientRect();
|
|
155
|
+
// 无布局(rect 宽 0)时按整星算
|
|
156
|
+
if (rect.width > 0 && clientX - rect.left < rect.width / 2) next = index + 0.5;
|
|
157
|
+
}
|
|
158
|
+
return next;
|
|
159
|
+
};
|
|
125
160
|
const choose = (next: number): void => {
|
|
126
161
|
if (locked()) return;
|
|
127
162
|
if (next !== current()) api.emit('change', { value: next });
|
|
@@ -131,21 +166,45 @@ function makeView(): KitView {
|
|
|
131
166
|
stars.forEach((s, i) => { s.btn.tabIndex = i === focusIndex ? 0 : -1; });
|
|
132
167
|
stars[focusIndex]?.btn.focus();
|
|
133
168
|
};
|
|
169
|
+
const onPointerMove = (event: PointerEvent): void => {
|
|
170
|
+
if (locked()) {
|
|
171
|
+
if (hoverValue !== null) {
|
|
172
|
+
hoverValue = null;
|
|
173
|
+
paintVisualStars(api.props());
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const hit = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-index]');
|
|
178
|
+
if (!hit || !root.contains(hit)) {
|
|
179
|
+
if (hoverValue !== null) {
|
|
180
|
+
hoverValue = null;
|
|
181
|
+
paintVisualStars(api.props());
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const next = pointerScore(hit, event.clientX);
|
|
186
|
+
if (hoverValue !== next) {
|
|
187
|
+
hoverValue = next;
|
|
188
|
+
paintVisualStars(api.props());
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const onPointerLeave = (): void => {
|
|
192
|
+
if (hoverValue !== null) {
|
|
193
|
+
hoverValue = null;
|
|
194
|
+
paintVisualStars(api.props());
|
|
195
|
+
}
|
|
196
|
+
};
|
|
134
197
|
const onClick = (event: Event): void => {
|
|
135
198
|
const hit = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-index]');
|
|
136
199
|
if (!hit || !root.contains(hit) || locked()) return;
|
|
137
200
|
const index = Number(hit.dataset.index);
|
|
138
|
-
const sp = spec();
|
|
139
|
-
let next = index + 1;
|
|
140
201
|
const e = event as MouseEvent;
|
|
141
|
-
|
|
142
|
-
const rect = hit.getBoundingClientRect();
|
|
143
|
-
// 无布局(rect 宽 0)时按整星算
|
|
144
|
-
if (rect.width > 0 && e.clientX - rect.left < rect.width / 2) next = index + 0.5;
|
|
145
|
-
}
|
|
202
|
+
let next = pointerScore(hit, e.clientX);
|
|
146
203
|
const clearable = api.props().clearable !== false && api.props().clearable !== 'false';
|
|
147
204
|
if (clearable && next === current()) next = 0;
|
|
205
|
+
hoverValue = null;
|
|
148
206
|
choose(next);
|
|
207
|
+
paintVisualStars(api.props());
|
|
149
208
|
focusStar(index);
|
|
150
209
|
};
|
|
151
210
|
const onKey = (event: KeyboardEvent): void => {
|
|
@@ -155,27 +214,42 @@ function makeView(): KitView {
|
|
|
155
214
|
if (target === null) return;
|
|
156
215
|
event.preventDefault();
|
|
157
216
|
if (locked()) return;
|
|
217
|
+
hoverValue = null;
|
|
158
218
|
choose(target);
|
|
159
219
|
focusStar(Math.max(0, Math.ceil(target) - 1));
|
|
160
220
|
};
|
|
221
|
+
root.addEventListener('pointermove', onPointerMove as EventListener);
|
|
222
|
+
root.addEventListener('pointerleave', onPointerLeave);
|
|
161
223
|
root.addEventListener('click', onClick);
|
|
162
224
|
root.addEventListener('keydown', onKey);
|
|
163
225
|
return () => {
|
|
226
|
+
root.removeEventListener('pointermove', onPointerMove as EventListener);
|
|
227
|
+
root.removeEventListener('pointerleave', onPointerLeave);
|
|
164
228
|
root.removeEventListener('click', onClick);
|
|
165
229
|
root.removeEventListener('keydown', onKey);
|
|
230
|
+
hiddenEl?.remove();
|
|
231
|
+
hiddenEl = null;
|
|
232
|
+
hoverValue = null;
|
|
166
233
|
stars = [];
|
|
167
234
|
};
|
|
168
235
|
},
|
|
169
|
-
render(root, p) {
|
|
236
|
+
render(root, p, api) {
|
|
170
237
|
const sp = ratingSpecOf(p);
|
|
171
238
|
const value = ratingValue(p.value, sp);
|
|
172
239
|
const readonly = bool(p.readonly);
|
|
173
240
|
const disabled = bool(p.disabled);
|
|
174
|
-
|
|
241
|
+
// 星的档位:自己的非缺省 size 优先,否则取页面线的 kit.controlSize(没有 kit 时与 sizeOf 相同)
|
|
242
|
+
const size = kitControlSizeOf(p);
|
|
243
|
+
// 只读展示是组件自己知道的数据状态
|
|
244
|
+
kitMarkDataState(kitOuterRoot(api.host, root), readonly ? 'readonly' : 'normal');
|
|
175
245
|
while (stars.length < sp.count) {
|
|
176
246
|
const star = buildStar(stars.length);
|
|
177
247
|
stars.push(star);
|
|
178
|
-
|
|
248
|
+
if (hiddenEl !== null && hiddenEl.parentElement === root) {
|
|
249
|
+
root.insertBefore(star.btn, hiddenEl);
|
|
250
|
+
} else {
|
|
251
|
+
root.appendChild(star.btn);
|
|
252
|
+
}
|
|
179
253
|
}
|
|
180
254
|
while (stars.length > sp.count) {
|
|
181
255
|
const star = stars.pop();
|
|
@@ -188,7 +262,7 @@ function makeView(): KitView {
|
|
|
188
262
|
root.removeAttribute('aria-disabled');
|
|
189
263
|
} else {
|
|
190
264
|
root.setAttribute('role', 'radiogroup');
|
|
191
|
-
applyCommon(root, p);
|
|
265
|
+
applyCommon(root, { ...p, name: '' });
|
|
192
266
|
if (disabled) root.setAttribute('aria-disabled', 'true');
|
|
193
267
|
else root.removeAttribute('aria-disabled');
|
|
194
268
|
}
|
|
@@ -197,12 +271,25 @@ function makeView(): KitView {
|
|
|
197
271
|
setAttr(root, 'id', str(p.id));
|
|
198
272
|
setAttr(root, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
|
|
199
273
|
}
|
|
274
|
+
const name = str(p.name);
|
|
275
|
+
if (name !== '') {
|
|
276
|
+
if (hiddenEl === null) {
|
|
277
|
+
hiddenEl = document.createElement('input');
|
|
278
|
+
hiddenEl.type = 'hidden';
|
|
279
|
+
root.appendChild(hiddenEl);
|
|
280
|
+
}
|
|
281
|
+
setAttr(hiddenEl, 'name', name);
|
|
282
|
+
hiddenEl.value = String(value);
|
|
283
|
+
hiddenEl.disabled = disabled;
|
|
284
|
+
} else if (hiddenEl !== null) {
|
|
285
|
+
hiddenEl.remove();
|
|
286
|
+
hiddenEl = null;
|
|
287
|
+
}
|
|
200
288
|
// roving:焦点星 = 当前值所在星,没有值时第一颗
|
|
201
289
|
if (focusIndex >= sp.count) focusIndex = 0;
|
|
202
290
|
const tabStop = value > 0 ? Math.ceil(value) - 1 : focusIndex;
|
|
291
|
+
const heart = str(p.symbol) === 'heart';
|
|
203
292
|
stars.forEach((s, i) => {
|
|
204
|
-
const full = value >= i + 1;
|
|
205
|
-
const half = !full && value >= i + 0.5;
|
|
206
293
|
s.btn.className = readonly ? STAR_CLASS[size].read : disabled ? `${STAR_CLASS[size].edit} ${STAR_DISABLED}` : STAR_CLASS[size].edit;
|
|
207
294
|
if (readonly) {
|
|
208
295
|
s.btn.removeAttribute('role');
|
|
@@ -210,17 +297,16 @@ function makeView(): KitView {
|
|
|
210
297
|
s.btn.removeAttribute('aria-label');
|
|
211
298
|
s.btn.removeAttribute('tabindex');
|
|
212
299
|
} else {
|
|
300
|
+
const isCheckedStar = Math.ceil(value) === i + 1;
|
|
301
|
+
const starScore = value === i + 0.5 ? value : i + 1;
|
|
213
302
|
s.btn.setAttribute('role', 'radio');
|
|
214
|
-
s.btn.setAttribute('aria-label',
|
|
215
|
-
s.btn.setAttribute('aria-checked',
|
|
303
|
+
s.btn.setAttribute('aria-label', String(starScore));
|
|
304
|
+
s.btn.setAttribute('aria-checked', isCheckedStar ? 'true' : 'false');
|
|
216
305
|
s.btn.tabIndex = disabled ? -1 : i === tabStop ? 0 : -1;
|
|
217
306
|
}
|
|
218
|
-
const heart = str(p.symbol) === 'heart';
|
|
219
307
|
for (const path of Array.from(s.btn.querySelectorAll('path'))) path.setAttribute('d', heart ? HEART_PATH : STAR_PATH);
|
|
220
|
-
s.fill.setAttribute('class', full || half ? (heart ? HEART_FILL_CLASS : FILL_PATH_CLASS) : HIDDEN);
|
|
221
|
-
if (half) s.fill.setAttribute('clip-path', s.fill.dataset.clip ?? '');
|
|
222
|
-
else s.fill.removeAttribute('clip-path');
|
|
223
308
|
});
|
|
309
|
+
paintVisualStars(p);
|
|
224
310
|
root.className = joinClass(GROUP_CLASS, p.class);
|
|
225
311
|
},
|
|
226
312
|
};
|
|
@@ -249,6 +335,6 @@ export function createRating(): SomaComponentDefinition {
|
|
|
249
335
|
},
|
|
250
336
|
},
|
|
251
337
|
templateHtml: `<span data-soma-id="root" role="radiogroup" class="${GROUP_CLASS}"></span>`,
|
|
252
|
-
controllerFactory: createKitController(() => makeView()),
|
|
338
|
+
controllerFactory: createKitController(() => makeView(), { self: { level: 'control' } }), // 评分整体是一个输入控件
|
|
253
339
|
};
|
|
254
340
|
}
|