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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// CardGrid:卡片网格(layer: data,写死形状,accept: list)。通用「一行一张卡」的网格容器,不含行业名词。
|
|
2
|
+
//
|
|
3
|
+
// 结构(组件卡 CardGrid §2 / §7):容器 div.@container > ul[role=list] > li > article(卡 = RecordCard 的同一份画法 paintRecordCard)。
|
|
4
|
+
// 列数随容器宽自适应(容器查询:窄 1 列、@md 2 列,columns 为 3 / 4 时 @xl 起 3 / 4 列),卡间留缝、同行等高(li 拉伸),卡脚沉底(卡脚 mt-auto)。
|
|
5
|
+
// 数据:`data` 是记录行数组,每行是一张 RecordCard 的 data({ title, subtitle?, status?, tone?, facts?, tags?, progress?, actions?, head_actions?, media?, avatar? … });
|
|
6
|
+
// `map` 键名对照与 `fields` 事实对来源同 RecordCard;`id` 键取 map.id(缺省 id)作选中与事件的标识。
|
|
7
|
+
// 状态:loading 无数据时画骨架卡(张数读 kit-limits#dataLimits.cardGrid.skeletonCards)、有数据时保留并标 aria-busy;error 就地提示条 + 重试;
|
|
8
|
+
// 没有数据整块换成空态(不画空卡);选中 = 卡主色边 + 淡底 + aria-pressed;行里 disabled: true 的卡字弱化、无悬停、aria-disabled。
|
|
9
|
+
// 事件:点卡抛 select { id, item }(selectable / clickable);卡内动作钮抛 action { key, id, item };错误态抛 retry。网格里的卡不带复制钮。
|
|
10
|
+
|
|
11
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
12
|
+
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
13
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
14
|
+
import { kitKey, kitText } from '../i18n/kit-text';
|
|
15
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
16
|
+
import { KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_TITLE_MAIN, KIT_SKELETON_BAR_TITLE_SUB, KIT_STATE_ERROR_BOX } from '../recipes/placeholder';
|
|
17
|
+
import { mergeClass } from '../shared/merge-class';
|
|
18
|
+
import { classTokens, emptyNode, keyMap, mk, retryButton, rowsOf } from './shape-util';
|
|
19
|
+
import { attrEsc, rowKey } from './d9-util';
|
|
20
|
+
import { KIT_RECORD_CARD_CLASS_CANDIDATES, KIT_RECORD_CARD_DEFAULT_MAP, paintRecordCard } from './record-card';
|
|
21
|
+
import { kitMarkDataFacts, kitMarkLevel, kitMarkPicked, kitReadProps } from './kit-contract';
|
|
22
|
+
import { kitApplyLevelClass } from './level-class';
|
|
23
|
+
import { kitApplyCols, kitColsGrid, kitStripGridCols } from '../base/kit-contract';
|
|
24
|
+
import { kitIsNextRuntime } from '../recipes/pipeline-runtime';
|
|
25
|
+
import {
|
|
26
|
+
KIT_ATTR_ACTION, KIT_ATTR_CARD_ID, KIT_ATTR_COLLAPSE, KIT_ATTR_CONTAINER, KIT_ATTR_RETRY, KIT_ATTR_SKELETON, kitAttrSel,
|
|
27
|
+
} from '../shared/dom-attrs';
|
|
28
|
+
import { KIT_VT_COLS_WIDE_VAR } from '../shared/value-table-contract';
|
|
29
|
+
|
|
30
|
+
const LIMITS = KIT_DATA_LIMITS.cardGrid;
|
|
31
|
+
export const KIT_CARD_GRID_COLUMNS: readonly number[] = LIMITS.columns;
|
|
32
|
+
|
|
33
|
+
export const KIT_CARD_GRID_DEFAULT_MAP = Object.freeze({ ...KIT_RECORD_CARD_DEFAULT_MAP, id: 'id', disabled: 'disabled' });
|
|
34
|
+
|
|
35
|
+
const ROOT_CLASS = '@container w-full text-sm text-fg';
|
|
36
|
+
const LIST_CLASS = 'block';
|
|
37
|
+
/** 列数 -> 完整类名(窄容器 1 列,@md 起 2 列,@xl 起设定列数;写死,不拼接)。卡间距取区块间距角色 gap-cluster */
|
|
38
|
+
const GRID_COLS: Readonly<Record<number, string>> = Object.freeze({
|
|
39
|
+
2: 'grid grid-cols-1 gap-cluster @md:grid-cols-2',
|
|
40
|
+
3: 'grid grid-cols-1 gap-cluster @md:grid-cols-2 @xl:grid-cols-3',
|
|
41
|
+
4: 'grid grid-cols-1 gap-cluster @md:grid-cols-2 @xl:grid-cols-4',
|
|
42
|
+
});
|
|
43
|
+
/** 网格项:撑满网格行高,卡在其内拉伸(同行等高) */
|
|
44
|
+
const ITEM_CLASS = 'flex min-w-0';
|
|
45
|
+
/** 卡根在 li 里:占满项宽,高度拉伸(卡脚的 mt-auto 才能沉底) */
|
|
46
|
+
const CARD_FIT_CLASS = 'min-w-0 flex-1';
|
|
47
|
+
const SKELETON_CARD_CLASS = mergeClass('flex min-w-0 flex-1 flex-col gap-3 p-card', kitShellRecipe({ tone: 'base', shadow: false }));
|
|
48
|
+
const SKELETON_BARS_CLASS = 'flex flex-col gap-2';
|
|
49
|
+
|
|
50
|
+
export const KIT_CARD_GRID_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
51
|
+
ROOT_CLASS, LIST_CLASS, Object.values(GRID_COLS), ITEM_CLASS, CARD_FIT_CLASS, SKELETON_CARD_CLASS, SKELETON_BARS_CLASS,
|
|
52
|
+
KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_TITLE_MAIN, KIT_SKELETON_BAR_TITLE_SUB, KIT_STATE_ERROR_BOX, KIT_RECORD_CARD_CLASS_CANDIDATES,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** 列数:只认闭集(kit-limits),其余取缺省 */
|
|
56
|
+
export function cardGridColumnsOf(raw: unknown): number {
|
|
57
|
+
const n = num(raw);
|
|
58
|
+
return n !== null && (LIMITS.columns as readonly number[]).includes(n) ? n : LIMITS.defaultColumns;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 卡的条目:标识 + 源行(纯函数,便于单测);超过 maxItems 的截掉 */
|
|
62
|
+
export function cardGridEntriesOf(data: unknown, mapRaw: unknown): Array<{ id: string; row: Record<string, unknown>; disabled: boolean }> {
|
|
63
|
+
const m = keyMap(KIT_CARD_GRID_DEFAULT_MAP, mapRaw);
|
|
64
|
+
return rowsOf(data).slice(0, LIMITS.maxItems).map((row, i) => ({ id: rowKey(row[m.id], i, 'c'), row, disabled: row[m.disabled] === true }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createCardGrid(): SomaComponentDefinition {
|
|
68
|
+
return {
|
|
69
|
+
contract: {
|
|
70
|
+
name: 'CardGrid',
|
|
71
|
+
layer: 'data',
|
|
72
|
+
props: {
|
|
73
|
+
data: { type: 'array', default: [], desc: '记录行数组:每行是一张卡的 data(title / subtitle? / status? / tone? / facts? / tags? / progress? / actions? / head_actions? / media? / avatar? …,同 RecordCard);行里 disabled: true 的卡置灰' },
|
|
74
|
+
map: { type: 'object', default: {}, desc: '键名对照:同 RecordCard 的 map,另有 id(选中与事件的标识,缺省 id)/ disabled' },
|
|
75
|
+
fields: { type: 'array', default: [], desc: '事实对来源 [{ key, label, format? }](按 key 从每行取值);空则读每行里的 facts 数组' },
|
|
76
|
+
columns: { type: 'number', default: LIMITS.defaultColumns, desc: `宽容器下的最大列数,取 ${LIMITS.columns.join(' / ')};窄容器自适应退到 2 列、1 列` },
|
|
77
|
+
preset: { type: 'enum', values: ['default', 'ticket', 'badge'], default: 'default', desc: '卡面预设(同 RecordCard)' },
|
|
78
|
+
variant: { type: 'enum', values: ['outlined', 'elevated', 'filled'], default: 'outlined', desc: '卡外观档(同 RecordCard)' },
|
|
79
|
+
rail: { type: 'boolean', default: false, desc: '每张卡左侧语气色细条' },
|
|
80
|
+
selectable: { type: 'boolean', default: false, desc: '整卡可聚焦可点,抛 select { id, item };选中卡 aria-pressed' },
|
|
81
|
+
clickable: { type: 'boolean', default: false, desc: '整卡点击(语义是「点进去」):行为同 selectable' },
|
|
82
|
+
selected: { type: 'string', default: '', desc: '选中卡的 id(selectable / clickable 时):主色边 + 淡底 + aria-pressed' },
|
|
83
|
+
empty_text: { type: 'string', default: '', desc: '无数据时整块替换为空态的文案;缺省取内置文案(按页面语言)' },
|
|
84
|
+
loading: { type: 'boolean', default: false, desc: '加载中:没有数据时画骨架卡,有数据时保留并标 aria-busy' },
|
|
85
|
+
loading_text: { type: 'string', default: '', desc: '加载中文案(读屏用)' },
|
|
86
|
+
error: { type: 'string', default: '', desc: '错误文案,非空即错误态(role=alert);retry_text 非空时带重试钮' },
|
|
87
|
+
error_text: { type: 'string', default: '', desc: '错误文案(兼容读状态自动绑定;优先于 error)' },
|
|
88
|
+
retry_text: { type: 'string', default: '', desc: '错误态重试钮文字,空则不显示' },
|
|
89
|
+
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
90
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
91
|
+
},
|
|
92
|
+
emits: {
|
|
93
|
+
select: { payload: { id: { type: 'string' }, item: { type: 'object' } }, desc: '点整卡(selectable / clickable 时);item 是源数据行' },
|
|
94
|
+
action: { payload: { key: { type: 'string' }, id: { type: 'string' }, item: { type: 'object' } }, desc: '点卡内动作钮(底部动作或右上动作);id 是该卡标识' },
|
|
95
|
+
retry: { payload: {}, desc: '错误态点重试' },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
99
|
+
controllerFactory: createKitController((api) => {
|
|
100
|
+
const P = (): Record<string, unknown> => api.props();
|
|
101
|
+
let root: HTMLElement | null = null;
|
|
102
|
+
let entries: Array<{ id: string; row: Record<string, unknown>; disabled: boolean }> = [];
|
|
103
|
+
|
|
104
|
+
const itemOf = (target: EventTarget | null): { id: string; row: Record<string, unknown>; disabled: boolean } | null => {
|
|
105
|
+
const li = (target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_CARD_ID));
|
|
106
|
+
if (!li || !root?.contains(li)) return null;
|
|
107
|
+
const id = li.getAttribute(KIT_ATTR_CARD_ID);
|
|
108
|
+
return entries.find((e) => e.id === id) ?? null;
|
|
109
|
+
};
|
|
110
|
+
const onClick = (event: Event): void => {
|
|
111
|
+
const target = event.target as HTMLElement | null;
|
|
112
|
+
if (target?.closest(kitAttrSel(KIT_ATTR_RETRY))) { api.emit('retry', {}); return; }
|
|
113
|
+
const entry = itemOf(target);
|
|
114
|
+
if (!entry) return;
|
|
115
|
+
const btn = target?.closest<HTMLButtonElement>(kitAttrSel(KIT_ATTR_ACTION));
|
|
116
|
+
if (btn) {
|
|
117
|
+
if (!btn.disabled) api.emit('action', { key: btn.getAttribute(KIT_ATTR_ACTION) ?? '', id: entry.id, item: entry.row });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const p = P();
|
|
121
|
+
if (entry.disabled || !(p.selectable === true || p.clickable === true)) return;
|
|
122
|
+
api.emit('select', { id: entry.id, item: entry.row });
|
|
123
|
+
};
|
|
124
|
+
const onKey = (event: KeyboardEvent): void => {
|
|
125
|
+
const target = event.target as HTMLElement | null;
|
|
126
|
+
if (target?.tagName !== 'ARTICLE') return;
|
|
127
|
+
const p = P();
|
|
128
|
+
if (!(p.selectable === true || p.clickable === true)) return;
|
|
129
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
130
|
+
const entry = itemOf(target);
|
|
131
|
+
if (!entry || entry.disabled) return;
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
api.emit('select', { id: entry.id, item: entry.row });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const cards = Array.from(root?.querySelectorAll<HTMLElement>(`li${kitAttrSel(KIT_ATTR_CARD_ID)} > article:not([aria-disabled="true"])`) ?? []);
|
|
137
|
+
const at = cards.indexOf(target);
|
|
138
|
+
if (at < 0 || cards.length === 0) return;
|
|
139
|
+
const arrow = kitKey(event.key, target);
|
|
140
|
+
const measureCols = (): number => {
|
|
141
|
+
if (cards.length <= 1) return 1;
|
|
142
|
+
const firstRect = cards[0]!.getBoundingClientRect();
|
|
143
|
+
let rowCount = 0;
|
|
144
|
+
for (const c of cards) {
|
|
145
|
+
if (Math.abs(c.getBoundingClientRect().top - firstRect.top) <= 2) rowCount += 1;
|
|
146
|
+
else break;
|
|
147
|
+
}
|
|
148
|
+
const configured = columnsOf(p);
|
|
149
|
+
if (rowCount === cards.length && firstRect.top === 0 && firstRect.width === 0) {
|
|
150
|
+
return Math.min(configured, cards.length);
|
|
151
|
+
}
|
|
152
|
+
return Math.max(1, rowCount);
|
|
153
|
+
};
|
|
154
|
+
let next = -1;
|
|
155
|
+
if (arrow === 'ArrowRight') next = Math.min(cards.length - 1, at + 1);
|
|
156
|
+
else if (arrow === 'ArrowLeft') next = Math.max(0, at - 1);
|
|
157
|
+
else if (event.key === 'ArrowDown') next = Math.min(cards.length - 1, at + measureCols());
|
|
158
|
+
else if (event.key === 'ArrowUp') next = Math.max(0, at - measureCols());
|
|
159
|
+
else if (event.key === 'Home') next = 0;
|
|
160
|
+
else if (event.key === 'End') next = cards.length - 1;
|
|
161
|
+
if (next >= 0 && next !== at) {
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
cards[next]?.focus();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const skeletonCard = (): HTMLElement => {
|
|
168
|
+
const li = mk('li', ITEM_CLASS);
|
|
169
|
+
li.setAttribute('aria-hidden', 'true');
|
|
170
|
+
li.setAttribute(KIT_ATTR_SKELETON, '');
|
|
171
|
+
const card = mk('div', SKELETON_CARD_CLASS);
|
|
172
|
+
const bars = mk('div', SKELETON_BARS_CLASS);
|
|
173
|
+
bars.append(mk('div', KIT_SKELETON_BAR_TITLE_MAIN), mk('div', KIT_SKELETON_BAR_TITLE_SUB));
|
|
174
|
+
card.append(bars, mk('div', KIT_SKELETON_BAR_LINE), mk('div', KIT_SKELETON_BAR_LINE));
|
|
175
|
+
li.appendChild(card);
|
|
176
|
+
return li;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/** 列数:页面线布局写了闭集内多列(2/3/4)时优先;页面线缺省 columns=1 不压过组件显式 columns / 缺省 3 列 */
|
|
180
|
+
const columnsOf = (p: Record<string, unknown>): number => {
|
|
181
|
+
const kitCols = kitReadProps(p).columns;
|
|
182
|
+
const validKitCols = kitCols !== undefined && (LIMITS.columns as readonly number[]).includes(kitCols) ? kitCols : undefined;
|
|
183
|
+
return cardGridColumnsOf(validKitCols ?? p.columns);
|
|
184
|
+
};
|
|
185
|
+
/** 卡片列表的栅格类:列数改由变量给时去掉 grid-cols-*(只留栅格与间距) */
|
|
186
|
+
const gridClassOf = (p: Record<string, unknown>, varTracks: boolean): string =>
|
|
187
|
+
varTracks ? kitStripGridCols(GRID_COLS[columnsOf(p)]!) : GRID_COLS[columnsOf(p)]!;
|
|
188
|
+
/** 窄容器退让协调:复用外部 data-kit-collapse(尊重外部 none),无外部声明时在 list(@container 根内)自落 to-single */
|
|
189
|
+
const applyCardGridCols = (list: HTMLElement, cols: number | null): boolean => {
|
|
190
|
+
const validCols = cols !== null && cols >= 2 ? cols : null;
|
|
191
|
+
let externalEl: HTMLElement | null = null;
|
|
192
|
+
let externalCollapse: string | null = null;
|
|
193
|
+
for (let el: HTMLElement | null = list.parentElement; el !== null; el = el.parentElement) {
|
|
194
|
+
const val = el.getAttribute(KIT_ATTR_COLLAPSE);
|
|
195
|
+
if (val !== null) {
|
|
196
|
+
externalEl = el;
|
|
197
|
+
externalCollapse = val;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (el.hasAttribute('data-soma-component')) break;
|
|
201
|
+
}
|
|
202
|
+
if (externalCollapse !== null) {
|
|
203
|
+
if (externalCollapse !== 'to-single') {
|
|
204
|
+
if (externalEl !== null && externalEl.style.getPropertyValue(KIT_VT_COLS_WIDE_VAR) !== '') {
|
|
205
|
+
externalEl.style.removeProperty(KIT_VT_COLS_WIDE_VAR);
|
|
206
|
+
if (externalEl.getAttribute('style') === '') externalEl.removeAttribute('style');
|
|
207
|
+
}
|
|
208
|
+
return kitApplyCols(list, null);
|
|
209
|
+
}
|
|
210
|
+
return kitApplyCols(list, validCols);
|
|
211
|
+
}
|
|
212
|
+
if (validCols !== null) {
|
|
213
|
+
list.setAttribute(KIT_ATTR_COLLAPSE, 'to-single');
|
|
214
|
+
return kitApplyCols(list, validCols);
|
|
215
|
+
}
|
|
216
|
+
return kitApplyCols(list, null);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const paint = (): void => {
|
|
220
|
+
if (!root) return;
|
|
221
|
+
const p = P();
|
|
222
|
+
const doc = root.ownerDocument;
|
|
223
|
+
const activeEl = root.contains(doc.activeElement) ? (doc.activeElement as HTMLElement | null) : null;
|
|
224
|
+
const focusedCardId = activeEl?.closest(kitAttrSel(KIT_ATTR_CARD_ID))?.getAttribute(KIT_ATTR_CARD_ID) ?? null;
|
|
225
|
+
const focusedActionKey = activeEl?.closest(kitAttrSel(KIT_ATTR_ACTION))?.getAttribute(KIT_ATTR_ACTION) ?? null;
|
|
226
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
227
|
+
root.textContent = '';
|
|
228
|
+
entries = cardGridEntriesOf(p.data, p.map);
|
|
229
|
+
const list = mk('ul', LIST_CLASS);
|
|
230
|
+
list.setAttribute('role', 'list');
|
|
231
|
+
root.appendChild(list);
|
|
232
|
+
/** 列表铺成卡片栅格(骨架与正文共用;出错与空态的列表是单项块,不铺且撤回退让变量) */
|
|
233
|
+
const asGrid = (): void => {
|
|
234
|
+
const varTracks = applyCardGridCols(list, kitIsNextRuntime() ? columnsOf(p) : null);
|
|
235
|
+
list.className = gridClassOf(p, varTracks);
|
|
236
|
+
kitColsGrid(list, varTracks);
|
|
237
|
+
};
|
|
238
|
+
const loading = p.loading === true || p.loading === 'true';
|
|
239
|
+
if (loading) root.setAttribute('aria-busy', 'true'); else root.removeAttribute('aria-busy');
|
|
240
|
+
const errMsg = str(p.error_text) !== '' ? str(p.error_text) : str(p.error);
|
|
241
|
+
const failed = errMsg !== '';
|
|
242
|
+
kitMarkDataFacts(root, { error: failed, loading, empty: entries.length === 0 });
|
|
243
|
+
const rowOf = (node: HTMLElement): HTMLElement => { const li = mk('li', ''); li.appendChild(node); return li; };
|
|
244
|
+
if (failed) {
|
|
245
|
+
const box = mk('div', KIT_STATE_ERROR_BOX);
|
|
246
|
+
box.setAttribute('role', 'alert');
|
|
247
|
+
box.appendChild(mk('span', '', errMsg));
|
|
248
|
+
if (str(p.retry_text) !== '') {
|
|
249
|
+
const btn = retryButton('retry', str(p.retry_text), 'danger');
|
|
250
|
+
btn.setAttribute(KIT_ATTR_RETRY, '');
|
|
251
|
+
box.appendChild(btn);
|
|
252
|
+
}
|
|
253
|
+
list.appendChild(rowOf(box));
|
|
254
|
+
if (entries.length === 0) { kitApplyCols(root, null); return; }
|
|
255
|
+
} else if (loading && entries.length === 0) {
|
|
256
|
+
asGrid();
|
|
257
|
+
for (let i = 0; i < LIMITS.skeletonCards; i += 1) list.appendChild(skeletonCard());
|
|
258
|
+
return;
|
|
259
|
+
} else if (entries.length === 0) {
|
|
260
|
+
// 没有数据:整块替换为空态,不画空卡(组件卡 CardGrid §4 空)
|
|
261
|
+
kitApplyCols(root, null);
|
|
262
|
+
list.appendChild(rowOf(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root)))));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
asGrid();
|
|
266
|
+
const pickable = p.selectable === true || p.clickable === true;
|
|
267
|
+
const given = str(p.selected);
|
|
268
|
+
for (const e of entries) {
|
|
269
|
+
const li = mk('li', ITEM_CLASS);
|
|
270
|
+
li.setAttribute(KIT_ATTR_CARD_ID, e.id);
|
|
271
|
+
const card = mk('article', '');
|
|
272
|
+
card.setAttribute(KIT_ATTR_CONTAINER, 'card');
|
|
273
|
+
paintRecordCard(card, {
|
|
274
|
+
data: e.row,
|
|
275
|
+
map: p.map,
|
|
276
|
+
fields: p.fields,
|
|
277
|
+
preset: p.preset,
|
|
278
|
+
variant: p.variant,
|
|
279
|
+
rail: p.rail,
|
|
280
|
+
selectable: pickable,
|
|
281
|
+
selected: pickable && given !== '' && e.id === given,
|
|
282
|
+
disabled: e.disabled,
|
|
283
|
+
locale: p.locale,
|
|
284
|
+
class: CARD_FIT_CLASS,
|
|
285
|
+
}, { secretOf: () => ({}), consumedOf: () => undefined, inGrid: true });
|
|
286
|
+
// 网格里每张卡 = 对象面;选中自报交互状态(aria-pressed 由卡画法写)
|
|
287
|
+
kitMarkLevel(card, 'face'); kitApplyLevelClass(card);
|
|
288
|
+
kitMarkPicked(card, 'selected', pickable && given !== '' && e.id === given, null);
|
|
289
|
+
li.appendChild(card);
|
|
290
|
+
list.appendChild(li);
|
|
291
|
+
}
|
|
292
|
+
if (focusedCardId !== null) {
|
|
293
|
+
const targetLi = list.querySelector<HTMLElement>(`[${KIT_ATTR_CARD_ID}="${attrEsc(focusedCardId)}"]`);
|
|
294
|
+
const focusTarget = focusedActionKey !== null
|
|
295
|
+
? targetLi?.querySelector<HTMLElement>(`[${KIT_ATTR_ACTION}="${attrEsc(focusedActionKey)}"]`)
|
|
296
|
+
: targetLi?.querySelector<HTMLElement>('article');
|
|
297
|
+
focusTarget?.focus({ preventScroll: true });
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
attach(rootEl) {
|
|
303
|
+
root = rootEl;
|
|
304
|
+
rootEl.addEventListener('click', onClick);
|
|
305
|
+
rootEl.addEventListener('keydown', onKey as EventListener);
|
|
306
|
+
return () => {
|
|
307
|
+
rootEl.removeEventListener('click', onClick);
|
|
308
|
+
rootEl.removeEventListener('keydown', onKey as EventListener);
|
|
309
|
+
root = null;
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
render(rootEl) {
|
|
313
|
+
root = rootEl;
|
|
314
|
+
paint();
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
}
|
package/src/data/carousel.ts
CHANGED
|
@@ -18,12 +18,18 @@ import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
|
18
18
|
import { kitIcon } from '../shared/icons';
|
|
19
19
|
import { kitText } from '../i18n/kit-text';
|
|
20
20
|
import { setKitFace } from '../recipes';
|
|
21
|
+
import { KIT_FOCUS_RING } from '../recipes/state';
|
|
21
22
|
import { kitButtonEdgeRecipe } from '../recipes/control';
|
|
22
23
|
import { kitShellRecipe } from '../recipes/container';
|
|
23
24
|
import { kitKey } from '../i18n/kit-text';
|
|
24
25
|
import { classTokens, emptyNode, mk, textOf, type Rec } from './shape-util';
|
|
25
|
-
import { clampInt, keyOfRow, listOf, prefersReducedMotion
|
|
26
|
+
import { clampInt, imageUrlOf, keyOfRow, listOf, prefersReducedMotion } from './display-util';
|
|
26
27
|
import { markKitEdge } from '../recipes/surface-edge';
|
|
28
|
+
import { kitHasProps, kitMarkPart, kitMarkPicked } from './kit-contract';
|
|
29
|
+
import {
|
|
30
|
+
KIT_ATTR_CONTAINER, KIT_ATTR_DOT, KIT_ATTR_MOTION, KIT_ATTR_NEXT, KIT_ATTR_PREV, KIT_ATTR_SELECTED, KIT_ATTR_SLIDE, KIT_ATTR_TOGGLE, KIT_ATTR_TOP,
|
|
31
|
+
kitAttrHtml, kitAttrSel,
|
|
32
|
+
} from '../shared/dom-attrs';
|
|
27
33
|
|
|
28
34
|
export const KIT_CAROUSEL_LAYOUTS = ['slide', 'stack'] as const;
|
|
29
35
|
export type KitCarouselLayout = (typeof KIT_CAROUSEL_LAYOUTS)[number];
|
|
@@ -39,17 +45,17 @@ const VIEWPORT_CLASS = `overflow-hidden ${VIEWPORT_EDGE}`;
|
|
|
39
45
|
const SLIDE_IMAGE_CLASS = 'flex flex-col';
|
|
40
46
|
const IMG_CLASS = 'aspect-16/9 w-full object-cover';
|
|
41
47
|
const CAPTION_CLASS = 'flex flex-col gap-1 px-4 py-3';
|
|
42
|
-
const CARD_CLASS = 'flex aspect-16/9 flex-col items-center justify-center gap-2
|
|
48
|
+
const CARD_CLASS = 'flex aspect-16/9 flex-col items-center justify-center gap-2 sub-block px-8 text-center text-fg';
|
|
43
49
|
const TITLE_CLASS = 'text-lg font-semibold';
|
|
44
50
|
const TEXT_CLASS = 'text-sm text-fg-muted';
|
|
45
51
|
const CARD_TEXT_CLASS = 'text-sm';
|
|
46
52
|
const BAR_CLASS = 'flex items-center justify-between gap-3';
|
|
47
|
-
const NAV_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-
|
|
53
|
+
const NAV_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-control ' + NAV_EDGE + ' bg-surface px-2 text-sm text-fg transition-colors state-layer ' + KIT_FOCUS_RING.button + ' disabled:cursor-not-allowed disabled:bg-control-disabled disabled:text-fg-disabled';
|
|
48
54
|
// 圆点尺寸与间距取 design 真源 kit-limits#carousel(间距步数,乘 --spacing);排容器 hit-gap-N 写 gap 与 --kit-hit-gap,
|
|
49
55
|
// 圆点用 hit-area-row(读 hitTarget;沿排热区 = min(命中边长, 中心距),相邻热区相接零重叠,垂直方向仍是完整命中边长),不手写外扩。
|
|
50
56
|
const DOTS_CLASS = `flex flex-1 items-center justify-center hit-gap-${KIT_CAROUSEL_LIMITS.dotGapStep}`;
|
|
51
|
-
const DOT_CLASS = `hit-area-row size-${KIT_CAROUSEL_LIMITS.dotSizeStep} p-0 rounded-full bg-border transition-colors hover:bg-fg-subtle
|
|
52
|
-
const TOGGLE_CLASS = 'inline-flex h-8 items-center justify-center rounded-
|
|
57
|
+
const DOT_CLASS = `hit-area-row size-${KIT_CAROUSEL_LIMITS.dotSizeStep} p-0 rounded-full bg-border transition-colors hover:bg-fg-subtle ${KIT_FOCUS_RING.button} data-kit-selected:bg-primary`;
|
|
58
|
+
const TOGGLE_CLASS = 'inline-flex h-8 items-center justify-center rounded-control px-2 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.button;
|
|
53
59
|
|
|
54
60
|
// stack 布局
|
|
55
61
|
const STACK_PAD: Readonly<Record<KitCarouselEdge, string>> = Object.freeze({
|
|
@@ -59,7 +65,7 @@ const STACK_PAD: Readonly<Record<KitCarouselEdge, string>> = Object.freeze({
|
|
|
59
65
|
end: 'grid pe-6',
|
|
60
66
|
});
|
|
61
67
|
const STACK_CARD_BASE = `col-start-1 row-start-1 flex min-h-32 flex-col gap-2 ${STACK_EDGE} p-4 text-start motion-safe:transition-transform`;
|
|
62
|
-
const STACK_TOP = 'z-30 cursor-pointer hover:bg-state-layer-hover active:bg-state-layer-press
|
|
68
|
+
const STACK_TOP = 'z-30 cursor-pointer hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.button;
|
|
63
69
|
/** 后面两张牌的位置:edge × 深度(1、2) */
|
|
64
70
|
const STACK_BEHIND: Readonly<Record<KitCarouselEdge, readonly [string, string]>> = Object.freeze({
|
|
65
71
|
top: ['z-20 -translate-y-3 scale-95 pointer-events-none', 'z-10 -translate-y-6 scale-90 pointer-events-none'],
|
|
@@ -67,11 +73,14 @@ const STACK_BEHIND: Readonly<Record<KitCarouselEdge, readonly [string, string]>>
|
|
|
67
73
|
start: ['z-20 -translate-x-3 rtl:translate-x-3 scale-95 pointer-events-none', 'z-10 -translate-x-6 rtl:translate-x-6 scale-90 pointer-events-none'],
|
|
68
74
|
end: ['z-20 translate-x-3 rtl:-translate-x-3 scale-95 pointer-events-none', 'z-10 translate-x-6 rtl:-translate-x-6 scale-90 pointer-events-none'],
|
|
69
75
|
});
|
|
70
|
-
const STACK_IMG_CLASS = 'aspect-16/9 w-full rounded-
|
|
76
|
+
const STACK_IMG_CLASS = 'aspect-16/9 w-full rounded-item object-cover';
|
|
77
|
+
const SLIDE_ACTIVE_CLASS = 'opacity-100 motion-safe:transition-opacity';
|
|
78
|
+
const SLIDE_IDLE_CLASS = 'opacity-0';
|
|
71
79
|
|
|
72
80
|
export const KIT_CAROUSEL_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
73
81
|
ROOT_CLASS, VIEWPORT_CLASS, SLIDE_IMAGE_CLASS, IMG_CLASS, CAPTION_CLASS, CARD_CLASS, TITLE_CLASS, TEXT_CLASS, CARD_TEXT_CLASS,
|
|
74
82
|
BAR_CLASS, NAV_CLASS, DOTS_CLASS, DOT_CLASS, TOGGLE_CLASS, 'hidden',
|
|
83
|
+
SLIDE_ACTIVE_CLASS, SLIDE_IDLE_CLASS,
|
|
75
84
|
Object.values(STACK_PAD), STACK_CARD_BASE, STACK_TOP, STACK_IMG_CLASS,
|
|
76
85
|
STACK_BEHIND.top, STACK_BEHIND.bottom, STACK_BEHIND.start, STACK_BEHIND.end,
|
|
77
86
|
);
|
|
@@ -101,7 +110,7 @@ export interface KitCarouselSlide {
|
|
|
101
110
|
export function carouselSlidesOf(data: unknown, itemsProp: unknown): KitCarouselSlide[] {
|
|
102
111
|
return listOf(data, itemsProp).map((raw, i) => ({
|
|
103
112
|
key: keyOfRow(raw, i, 's'),
|
|
104
|
-
image:
|
|
113
|
+
image: imageUrlOf(raw.image),
|
|
105
114
|
alt: textOf(raw.alt),
|
|
106
115
|
title: textOf(raw.title),
|
|
107
116
|
text: textOf(raw.text),
|
|
@@ -121,6 +130,7 @@ interface State {
|
|
|
121
130
|
index: number;
|
|
122
131
|
given: string;
|
|
123
132
|
sig: string;
|
|
133
|
+
timerSig: string;
|
|
124
134
|
hover: boolean;
|
|
125
135
|
focus: boolean;
|
|
126
136
|
userPaused: boolean;
|
|
@@ -132,46 +142,52 @@ const STATES = new WeakMap<HTMLElement, State>();
|
|
|
132
142
|
const stateOf = (root: HTMLElement): State => {
|
|
133
143
|
let s = STATES.get(root);
|
|
134
144
|
if (!s) {
|
|
135
|
-
s = { index: 0, given: '', sig: '', hover: false, focus: false, userPaused: false, timer: null, slides: [] };
|
|
145
|
+
s = { index: 0, given: '', sig: '', timerSig: '', hover: false, focus: false, userPaused: false, timer: null, slides: [] };
|
|
136
146
|
STATES.set(root, s);
|
|
137
147
|
}
|
|
138
148
|
return s;
|
|
139
149
|
};
|
|
140
150
|
|
|
141
151
|
function applyIndex(root: HTMLElement, s: State, loop: boolean, layout: KitCarouselLayout, edge: KitCarouselEdge): void {
|
|
142
|
-
const slides = Array.from(root.querySelectorAll<HTMLElement>(
|
|
152
|
+
const slides = Array.from(root.querySelectorAll<HTMLElement>(kitAttrSel(KIT_ATTR_SLIDE)));
|
|
143
153
|
const n = slides.length;
|
|
144
154
|
slides.forEach((el, i) => {
|
|
155
|
+
// 当前张自报「当前」(幻灯片是 group,没有可用的 aria 选中属性,只写自报)
|
|
156
|
+
kitMarkPicked(el, 'current', i === s.index, null);
|
|
145
157
|
if (layout === 'stack') {
|
|
146
158
|
const depth = (i - s.index + n) % n;
|
|
147
159
|
const behind = depth <= 2 ? STACK_BEHIND[edge][depth - 1] as string : 'hidden';
|
|
148
160
|
el.className = depth === 0 ? `${STACK_CARD_BASE} ${STACK_TOP}` : `${STACK_CARD_BASE} ${behind}`;
|
|
149
161
|
if (depth === 0) {
|
|
150
162
|
el.removeAttribute('aria-hidden');
|
|
151
|
-
el.setAttribute(
|
|
163
|
+
el.setAttribute(KIT_ATTR_TOP, '');
|
|
152
164
|
el.tabIndex = 0;
|
|
153
165
|
} else {
|
|
154
166
|
el.setAttribute('aria-hidden', 'true');
|
|
155
|
-
el.removeAttribute(
|
|
167
|
+
el.removeAttribute(KIT_ATTR_TOP);
|
|
156
168
|
el.removeAttribute('tabindex');
|
|
157
169
|
}
|
|
158
170
|
} else if (i === s.index) {
|
|
171
|
+
el.className = SLIDE_ACTIVE_CLASS;
|
|
159
172
|
el.removeAttribute('hidden');
|
|
160
173
|
} else {
|
|
174
|
+
el.className = SLIDE_IDLE_CLASS;
|
|
161
175
|
el.setAttribute('hidden', '');
|
|
162
176
|
}
|
|
163
177
|
});
|
|
164
|
-
Array.from(root.querySelectorAll<HTMLElement>(
|
|
178
|
+
Array.from(root.querySelectorAll<HTMLElement>(kitAttrSel(KIT_ATTR_DOT))).forEach((el, i) => {
|
|
179
|
+
// 指示点的当前项自报(aria-current 在下面同步写 / 摘)
|
|
180
|
+
kitMarkPicked(el, 'current', i === s.index, null);
|
|
165
181
|
if (i === s.index) {
|
|
166
|
-
el.setAttribute(
|
|
182
|
+
el.setAttribute(KIT_ATTR_SELECTED, '');
|
|
167
183
|
el.setAttribute('aria-current', 'true');
|
|
168
184
|
} else {
|
|
169
|
-
el.removeAttribute(
|
|
185
|
+
el.removeAttribute(KIT_ATTR_SELECTED);
|
|
170
186
|
el.removeAttribute('aria-current');
|
|
171
187
|
}
|
|
172
188
|
});
|
|
173
|
-
const prev = root.querySelector<HTMLButtonElement>(
|
|
174
|
-
const next = root.querySelector<HTMLButtonElement>(
|
|
189
|
+
const prev = root.querySelector<HTMLButtonElement>(kitAttrSel(KIT_ATTR_PREV));
|
|
190
|
+
const next = root.querySelector<HTMLButtonElement>(kitAttrSel(KIT_ATTR_NEXT));
|
|
175
191
|
if (prev) prev.disabled = !loop && s.index <= 0;
|
|
176
192
|
if (next) next.disabled = !loop && s.index >= n - 1;
|
|
177
193
|
}
|
|
@@ -181,6 +197,7 @@ function stopTimer(s: State): void {
|
|
|
181
197
|
clearInterval(s.timer);
|
|
182
198
|
s.timer = null;
|
|
183
199
|
}
|
|
200
|
+
s.timerSig = '';
|
|
184
201
|
}
|
|
185
202
|
|
|
186
203
|
type Api = { emit(n: string, p?: unknown): void; props(): Record<string, unknown> };
|
|
@@ -188,7 +205,7 @@ const loopOf = (p: Record<string, unknown>): boolean => (p.loop === undefined ?
|
|
|
188
205
|
|
|
189
206
|
function buildSlide(slide: KitCarouselSlide, i: number, n: number, layout: KitCarouselLayout): HTMLElement {
|
|
190
207
|
const el = mk('div', '');
|
|
191
|
-
el.setAttribute(
|
|
208
|
+
el.setAttribute(KIT_ATTR_SLIDE, slide.key);
|
|
192
209
|
el.setAttribute('role', 'group');
|
|
193
210
|
el.setAttribute('aria-roledescription', 'slide');
|
|
194
211
|
el.setAttribute('aria-label', `${i + 1} / ${n}`);
|
|
@@ -235,10 +252,10 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
235
252
|
const next = carouselStep(to, 0, s.slides.length, loop);
|
|
236
253
|
if (next === s.index) return;
|
|
237
254
|
const layout = carouselLayoutOf(p.layout);
|
|
238
|
-
const hadFocusOnCard = layout === 'stack' && (document.activeElement as HTMLElement | null)?.hasAttribute(
|
|
255
|
+
const hadFocusOnCard = layout === 'stack' && (document.activeElement as HTMLElement | null)?.hasAttribute(KIT_ATTR_SLIDE) === true;
|
|
239
256
|
s.index = next;
|
|
240
257
|
applyIndex(root, s, loop, layout, carouselEdgeOf(p.edge));
|
|
241
|
-
if (hadFocusOnCard) root.querySelector<HTMLElement>(
|
|
258
|
+
if (hadFocusOnCard) root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_TOP))?.focus();
|
|
242
259
|
const slide = s.slides[next];
|
|
243
260
|
if (slide) api.emit('change', { index: next, item: slide.raw });
|
|
244
261
|
};
|
|
@@ -247,10 +264,18 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
247
264
|
const s = stateOf(root);
|
|
248
265
|
const p = api.props();
|
|
249
266
|
const loop = loopOf(p);
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
267
|
+
const docHidden = typeof document !== 'undefined' && document.hidden === true;
|
|
268
|
+
const motionStill = root.closest(kitAttrSel(KIT_ATTR_MOTION, 'still')) !== null;
|
|
269
|
+
const want = bool(p.autoplay) && s.slides.length > 1 && !s.userPaused && !s.hover && !s.focus && !prefersReducedMotion() && !motionStill && !docHidden;
|
|
270
|
+
if (!want) {
|
|
271
|
+
stopTimer(s);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
253
274
|
const ms = clampInt(p.interval, KIT_CAROUSEL_INTERVAL.min, KIT_CAROUSEL_INTERVAL.max, KIT_CAROUSEL_INTERVAL.dflt);
|
|
275
|
+
const nextTimerSig = `${want}:${ms}:${loop}`;
|
|
276
|
+
if (s.timer !== null && s.timerSig === nextTimerSig) return;
|
|
277
|
+
stopTimer(s);
|
|
278
|
+
s.timerSig = nextTimerSig;
|
|
254
279
|
s.timer = setInterval(() => {
|
|
255
280
|
const last = s.index >= s.slides.length - 1;
|
|
256
281
|
if (last && !loop) { stopTimer(s); return; }
|
|
@@ -280,7 +305,7 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
280
305
|
select: { payload: { index: { type: 'number' }, item: { type: 'object' } }, desc: 'slide 布局下点当前张的内容' },
|
|
281
306
|
},
|
|
282
307
|
},
|
|
283
|
-
templateHtml: `<section
|
|
308
|
+
templateHtml: `<section${kitAttrHtml(KIT_ATTR_CONTAINER, 'card')} data-soma-id="root" role="region" aria-roledescription="carousel" class="${ROOT_CLASS}"></section>`,
|
|
284
309
|
controllerFactory: createKitController(() => ({
|
|
285
310
|
attach(root, api) {
|
|
286
311
|
const s = stateOf(root);
|
|
@@ -289,13 +314,13 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
289
314
|
if (!t) return;
|
|
290
315
|
const p = api.props();
|
|
291
316
|
const loop = loopOf(p);
|
|
292
|
-
if (t.closest(
|
|
293
|
-
if (t.closest(
|
|
294
|
-
const dot = t.closest<HTMLElement>(
|
|
295
|
-
if (dot) { go(root, api, Number(dot.getAttribute(
|
|
296
|
-
if (t.closest(
|
|
317
|
+
if (t.closest(kitAttrSel(KIT_ATTR_PREV))) { go(root, api, carouselStep(s.index, -1, s.slides.length, loop)); return; }
|
|
318
|
+
if (t.closest(kitAttrSel(KIT_ATTR_NEXT))) { go(root, api, carouselStep(s.index, 1, s.slides.length, loop)); return; }
|
|
319
|
+
const dot = t.closest<HTMLElement>(kitAttrSel(KIT_ATTR_DOT));
|
|
320
|
+
if (dot) { go(root, api, Number(dot.getAttribute(KIT_ATTR_DOT))); return; }
|
|
321
|
+
if (t.closest(kitAttrSel(KIT_ATTR_TOGGLE))) {
|
|
297
322
|
s.userPaused = !s.userPaused;
|
|
298
|
-
const btn = root.querySelector<HTMLElement>(
|
|
323
|
+
const btn = root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_TOGGLE));
|
|
299
324
|
if (btn) {
|
|
300
325
|
btn.textContent = kitText(s.userPaused ? 'soma.kit.car_play' : 'soma.kit.car_pause', undefined, root);
|
|
301
326
|
btn.setAttribute('aria-pressed', s.userPaused ? 'true' : 'false');
|
|
@@ -303,9 +328,9 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
303
328
|
syncTimer(root, api);
|
|
304
329
|
return;
|
|
305
330
|
}
|
|
306
|
-
if (t.closest(
|
|
331
|
+
if (t.closest(kitAttrSel(KIT_ATTR_SLIDE))) {
|
|
307
332
|
if (carouselLayoutOf(p.layout) === 'stack') {
|
|
308
|
-
if (t.closest(
|
|
333
|
+
if (t.closest(kitAttrSel(KIT_ATTR_TOP))) go(root, api, carouselStep(s.index, 1, s.slides.length, loop));
|
|
309
334
|
return;
|
|
310
335
|
}
|
|
311
336
|
const slide = s.slides[s.index];
|
|
@@ -320,7 +345,7 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
320
345
|
else if (arrow === 'ArrowRight') go(root, api, carouselStep(s.index, 1, n, loop));
|
|
321
346
|
else if (event.key === 'Home') go(root, api, 0);
|
|
322
347
|
else if (event.key === 'End') go(root, api, n - 1);
|
|
323
|
-
else if ((event.key === 'Enter' || event.key === ' ') && (event.target as HTMLElement | null)?.closest(
|
|
348
|
+
else if ((event.key === 'Enter' || event.key === ' ') && (event.target as HTMLElement | null)?.closest(kitAttrSel(KIT_ATTR_TOP))) go(root, api, carouselStep(s.index, 1, n, loop));
|
|
324
349
|
else return;
|
|
325
350
|
event.preventDefault();
|
|
326
351
|
};
|
|
@@ -333,12 +358,15 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
333
358
|
s.focus = false;
|
|
334
359
|
syncTimer(root, api);
|
|
335
360
|
};
|
|
361
|
+
const doc = root.ownerDocument;
|
|
362
|
+
const onVis = (): void => syncTimer(root, api);
|
|
336
363
|
root.addEventListener('click', onClick);
|
|
337
364
|
root.addEventListener('keydown', onKeydown);
|
|
338
365
|
root.addEventListener('mouseenter', enter);
|
|
339
366
|
root.addEventListener('mouseleave', leave);
|
|
340
367
|
root.addEventListener('focusin', focusIn);
|
|
341
368
|
root.addEventListener('focusout', focusOut);
|
|
369
|
+
doc.addEventListener('visibilitychange', onVis);
|
|
342
370
|
return () => {
|
|
343
371
|
root.removeEventListener('click', onClick);
|
|
344
372
|
root.removeEventListener('keydown', onKeydown);
|
|
@@ -346,6 +374,7 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
346
374
|
root.removeEventListener('mouseleave', leave);
|
|
347
375
|
root.removeEventListener('focusin', focusIn);
|
|
348
376
|
root.removeEventListener('focusout', focusOut);
|
|
377
|
+
doc.removeEventListener('visibilitychange', onVis);
|
|
349
378
|
stopTimer(s);
|
|
350
379
|
STATES.delete(root);
|
|
351
380
|
};
|
|
@@ -374,7 +403,8 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
374
403
|
root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
375
404
|
} else {
|
|
376
405
|
const viewport = mk('div', layout === 'stack' ? STACK_PAD[edge] : VIEWPORT_CLASS);
|
|
377
|
-
|
|
406
|
+
// C 项:外框去留原按祖先判断;新流水线下交取值表
|
|
407
|
+
if (layout !== 'stack' && !kitHasProps(p)) markKitEdge(viewport);
|
|
378
408
|
slides.forEach((slide, i) => viewport.appendChild(buildSlide(slide, i, slides.length, layout)));
|
|
379
409
|
root.appendChild(viewport);
|
|
380
410
|
}
|
|
@@ -384,19 +414,22 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
384
414
|
prev.appendChild(kitIcon('chevron-left', 'md', 'rtl:-scale-x-100'));
|
|
385
415
|
prev.type = 'button';
|
|
386
416
|
setKitFace(prev, 'raised');
|
|
387
|
-
prev.setAttribute(
|
|
417
|
+
prev.setAttribute(KIT_ATTR_PREV, '');
|
|
418
|
+
kitMarkPart(prev, 'action');
|
|
388
419
|
prev.setAttribute('aria-label', kitText('soma.kit.prev_item', undefined, root));
|
|
389
420
|
const next = mk('button', NAV_CLASS, '');
|
|
390
421
|
next.appendChild(kitIcon('chevron-right', 'md', 'rtl:-scale-x-100'));
|
|
391
422
|
next.type = 'button';
|
|
392
423
|
setKitFace(next, 'raised');
|
|
393
|
-
next.setAttribute(
|
|
424
|
+
next.setAttribute(KIT_ATTR_NEXT, '');
|
|
425
|
+
kitMarkPart(next, 'action');
|
|
394
426
|
next.setAttribute('aria-label', kitText('soma.kit.next_item', undefined, root));
|
|
395
427
|
const dots = mk('div', DOTS_CLASS);
|
|
396
428
|
slides.forEach((slide, i) => {
|
|
397
429
|
const dot = mk('button', DOT_CLASS);
|
|
398
430
|
dot.type = 'button';
|
|
399
|
-
dot.setAttribute(
|
|
431
|
+
dot.setAttribute(KIT_ATTR_DOT, String(i));
|
|
432
|
+
kitMarkPart(dot, 'control');
|
|
400
433
|
dot.setAttribute('aria-label', `${kitText('soma.kit.car_slide', { n: i + 1 }, root)}${slide.title !== '' ? `${kitText('soma.kit.colon', undefined, root)}${slide.title}` : ''}`);
|
|
401
434
|
dots.appendChild(dot);
|
|
402
435
|
});
|
|
@@ -405,7 +438,8 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
405
438
|
if (bool(p.autoplay)) {
|
|
406
439
|
const toggle = mk('button', TOGGLE_CLASS, kitText(s.userPaused ? 'soma.kit.car_play' : 'soma.kit.car_pause', undefined, root));
|
|
407
440
|
toggle.type = 'button';
|
|
408
|
-
toggle.setAttribute(
|
|
441
|
+
toggle.setAttribute(KIT_ATTR_TOGGLE, '');
|
|
442
|
+
kitMarkPart(toggle, 'action');
|
|
409
443
|
toggle.setAttribute('aria-pressed', s.userPaused ? 'true' : 'false');
|
|
410
444
|
bar.appendChild(toggle);
|
|
411
445
|
}
|