soma-kit 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +8 -5
- package/packs/ai/model-card.ts +3 -3
- package/packs/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 +934 -92
- 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 +186 -57
- 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 +130 -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 +1015 -53
- 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 +424 -103
- 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,230 @@
|
|
|
1
|
+
// 数据组件与对象渲染共用的「组件契约」小件(Kit 主题流水线):在 shared/page-attrs-runtime 的读写帮手之上,
|
|
2
|
+
// 补三类 data / object-renderer 里反复要写的东西——
|
|
3
|
+
// 1. 元素部件自报时不覆盖节点上已有的、不是自报写的 data-kit-part(存量的样式 / 测试钩子,如 table-row、rule-builder 的 value);
|
|
4
|
+
// 2. 字段级、动作级判定的读取:生成事件把字段 / 动作节点的入参判定汇总进宿主条目(spatial/emit.ts#applyAttrsToArtifact,
|
|
5
|
+
// 宿主锚点见 biz/layout-contracts.ts#KIT_HOST_ANCHOR_PATTERN),形状 props.kit.fields[字段名]、props.kit.actions[动作键],这里按同一形状读;
|
|
6
|
+
// 没有时返回空对象,组件按原缺省画;
|
|
7
|
+
// 3. 选中 / 当前的自报与无障碍属性同写,免得各组件只写其一。
|
|
8
|
+
// 只依赖 shared/page-attrs*、recipes 的纯函数与 base/kit-contract 的自报入口(带新模式判断),不依赖任何组件模块。
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
KIT_COLLAPSES, KIT_FLOWS, KIT_LEVELS,
|
|
12
|
+
type KitAlign, type KitCollapse, type KitDataState, type KitElementPart, type KitFlow, type KitLevel,
|
|
13
|
+
} from '../shared/page-attrs';
|
|
14
|
+
import { KIT_SELF_ATTR, kitHasProps, kitReadProps, kitWriteSelfKey, type KitRuntimeProps } from '../shared/page-attrs-runtime';
|
|
15
|
+
// 数据状态 / 交互状态与溢出对齐合并取 base/kit-contract 的统一出口(旧版不写自报属性,见那里的说明)
|
|
16
|
+
import {
|
|
17
|
+
KIT_ALIGN_CLASS, KIT_INLINE_ROOT_ALIGN_CLASS_CANDIDATES, KIT_OVERFLOW_CLASS, kitHasOwnAlign, kitHasOwnOverflow, kitMarkDataState, kitMarkInteract,
|
|
18
|
+
kitMergeAlignOverflow,
|
|
19
|
+
} from '../base/kit-contract';
|
|
20
|
+
import { KIT_SINGLE_VALUE_CLASS_CANDIDATES, kitIsNextRuntime } from '../recipes/pipeline-runtime';
|
|
21
|
+
import { kitTextFit } from '../recipes/text-fit';
|
|
22
|
+
import { KIT_SELF_OWNED_CLASS_CANDIDATES } from '../recipes/self-owned';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
KIT_ALIGN_CLASS, KIT_OVERFLOW_CLASS, KIT_SELF_ATTR,
|
|
26
|
+
kitHasOwnAlign, kitHasOwnOverflow, kitHasProps, kitMarkDataState, kitMarkInteract, kitMergeAlignOverflow, kitReadProps,
|
|
27
|
+
type KitRuntimeProps,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const isRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 元素部件自报:节点上没有 data-kit-part 时写入;已有值时只有它是自报上一次写的才改写——模板、配方、组件私有钩子写的
|
|
34
|
+
* (存量钩子如 table-row、rule-builder 的 value,主题结构规则与测试按它选元素)一律保持原值,不论在不在 12 个元素部件之内。
|
|
35
|
+
* 返回本次是否由自报写下了这个值(调用方据此不必再判断)。
|
|
36
|
+
* 本文件的自报帮手在旧版(layout.pipeline 缺省)下一律不写:自报属性是本轮新增的写入,旧版 DOM 与产物保持改动前的样子。
|
|
37
|
+
*/
|
|
38
|
+
export function kitMarkPart(el: Element, part: KitElementPart): boolean {
|
|
39
|
+
if (!kitIsNextRuntime()) return false;
|
|
40
|
+
// 口径同 shared/page-attrs-runtime.ts#kitWriteSelfKey:已有值不覆盖,除非那个值是自报自己上一次写的
|
|
41
|
+
return kitWriteSelfKey(el, 'part', part) !== undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 层级角色自报(可带元素部件):层级角色与部件都按 kitWriteSelfKey 的同一口径写(已有值不是自报写的不覆盖) */
|
|
45
|
+
export function kitMarkLevel(el: Element, level: KitLevel, part?: KitElementPart): void {
|
|
46
|
+
if (!kitIsNextRuntime()) return;
|
|
47
|
+
kitWriteSelfKey(el, 'level', level);
|
|
48
|
+
if (part !== undefined) kitMarkPart(el, part);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 模板串里写的元素部件属性(带前导空格):给编译期 / 字符串模板用,存量部件值由调用方自己保留 */
|
|
52
|
+
// 这两个是纯函数、不看模式:调用方自己按模式决定拼不拼(object-renderer/emit-static 按显式的 ctx.next)。
|
|
53
|
+
// 组件定义里的静态模板不要直接用它们——模板在组件创建时求值,那时的模式不可靠(见 base/kit-contract 自报一节)
|
|
54
|
+
export function kitPartAttr(part: KitElementPart): string {
|
|
55
|
+
return ` ${KIT_SELF_ATTR.part}="${part}"`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 模板串里写的层级角色属性(带前导空格;纯函数,见上) */
|
|
59
|
+
export function kitLevelAttr(level: KitLevel): string {
|
|
60
|
+
return ` ${KIT_SELF_ATTR.level}="${level}"`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 数据状态的统一推法:出错压过加载(失败必须可见),加载压过空(重取时旧行还在也算加载中),只读最后。
|
|
65
|
+
* 组件只给自己知道的事实,不在各组件里各排一遍优先级。
|
|
66
|
+
*/
|
|
67
|
+
export function kitDataStateOf(facts: { readonly loading?: boolean; readonly error?: boolean; readonly empty?: boolean; readonly readonly?: boolean }): KitDataState {
|
|
68
|
+
if (facts.error === true) return 'error';
|
|
69
|
+
if (facts.loading === true) return 'loading';
|
|
70
|
+
if (facts.empty === true) return 'empty';
|
|
71
|
+
if (facts.readonly === true) return 'readonly';
|
|
72
|
+
return 'normal';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 一步写数据状态:推法同 kitDataStateOf */
|
|
76
|
+
export function kitMarkDataFacts(el: Element, facts: Parameters<typeof kitDataStateOf>[0]): void {
|
|
77
|
+
kitMarkDataState(el, kitDataStateOf(facts));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 选中 / 当前项自报,同时核写无障碍属性:aria 给 'selected'(列表框、网格行、页签)、'current'(导航、步骤)、
|
|
82
|
+
* 'pressed'(切换按钮)、'checked'(勾选项)或 null(节点角色不支持任何一个时只写自报)。
|
|
83
|
+
* current 用 aria-current="true",导航里需要 "page" 的由调用方自己写。
|
|
84
|
+
*/
|
|
85
|
+
export function kitMarkPicked(el: Element, state: 'selected' | 'current', on: boolean, aria: 'selected' | 'current' | 'pressed' | 'checked' | null = state): void {
|
|
86
|
+
kitMarkInteract(el, state, on);
|
|
87
|
+
if (aria === null) return;
|
|
88
|
+
if (aria === 'current') {
|
|
89
|
+
if (on) { if (el.getAttribute('aria-current') === null) el.setAttribute('aria-current', 'true'); } else el.removeAttribute('aria-current');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// 取消选中:新模式下只在角色支持该属性的节点上写 "false",不支持的去掉(aria-selected="false" 写在普通按钮上是无效属性);旧版照旧写 "false"
|
|
93
|
+
if (!on && kitIsNextRuntime() && !ariaRoleSupports(el, aria)) { el.removeAttribute(`aria-${aria}`); return; }
|
|
94
|
+
el.setAttribute(`aria-${aria}`, on ? 'true' : 'false');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 各状态属性被哪些角色支持(WAI-ARIA 1.2 的 supported states) */
|
|
98
|
+
const ARIA_STATE_ROLES: Readonly<Record<'selected' | 'pressed' | 'checked', ReadonlySet<string>>> = Object.freeze({
|
|
99
|
+
selected: new Set(['option', 'tab', 'gridcell', 'row', 'columnheader', 'rowheader', 'treeitem']),
|
|
100
|
+
pressed: new Set(['button']),
|
|
101
|
+
checked: new Set(['checkbox', 'radio', 'switch', 'menuitemcheckbox', 'menuitemradio', 'option', 'treeitem']),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/** 节点的角色:显式 role 取第一个词;没写时取常见的隐含角色(button / 勾选框 / 单选 / option / tr),其余为空串 */
|
|
105
|
+
function ariaRoleOf(el: Element): string {
|
|
106
|
+
const raw = (el.getAttribute('role') ?? '').trim();
|
|
107
|
+
const sp = raw.search(/\s/);
|
|
108
|
+
const explicit = sp < 0 ? raw : raw.slice(0, sp);
|
|
109
|
+
if (explicit !== '') return explicit;
|
|
110
|
+
switch (el.tagName) {
|
|
111
|
+
case 'BUTTON': return 'button';
|
|
112
|
+
case 'OPTION': return 'option';
|
|
113
|
+
case 'TR': return 'row';
|
|
114
|
+
case 'INPUT': {
|
|
115
|
+
const type = (el.getAttribute('type') ?? '').toLowerCase();
|
|
116
|
+
return type === 'checkbox' ? 'checkbox' : type === 'radio' ? 'radio' : type === 'button' || type === 'submit' || type === 'reset' ? 'button' : '';
|
|
117
|
+
}
|
|
118
|
+
default: return '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function ariaRoleSupports(el: Element, aria: 'selected' | 'pressed' | 'checked'): boolean {
|
|
123
|
+
return ARIA_STATE_ROLES[aria].has(ariaRoleOf(el));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 拖拽中自报(拖起时 on、放下或取消时 off) */
|
|
127
|
+
export function kitMarkDragging(el: Element, on: boolean): void {
|
|
128
|
+
kitMarkInteract(el, 'dragging', on);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── 字段级 / 动作级判定(汇总形状,与 spatial/emit.ts 写入的同形) ──────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 字段级判定:props.kit.fields[字段名] = { align, width, overflow, keep, valueForm, tone, categoryIndex }。
|
|
135
|
+
* 每一项按 kitReadProps 的闭集校验;没有这一层或这一字段时返回空对象。
|
|
136
|
+
*/
|
|
137
|
+
export function kitFieldPropsOf(props: unknown, field: string): KitRuntimeProps {
|
|
138
|
+
const kit = isRec(props) ? props.kit : undefined;
|
|
139
|
+
const fields = isRec(kit) ? kit.fields : undefined;
|
|
140
|
+
return isRec(fields) ? kitReadProps({ kit: fields[field] }) : {};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 动作级判定:props.kit.actions[动作键] = { variant, solid, tone, confirm, stowable };没有时返回空对象 */
|
|
144
|
+
export function kitActionPropsOf(props: unknown, action: string): KitRuntimeProps {
|
|
145
|
+
const kit = isRec(props) ? props.kit : undefined;
|
|
146
|
+
const actions = isRec(kit) ? kit.actions : undefined;
|
|
147
|
+
return isRec(actions) ? kitReadProps({ kit: actions[action] }) : {};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 入参里是否带了字段级 / 动作级 / 条带级汇总:集合 / 动作组 / 表单据此决定「按判定画」还是「按原缺省画」 */
|
|
151
|
+
export function kitHasFieldProps(props: unknown): boolean {
|
|
152
|
+
const kit = isRec(props) ? props.kit : undefined;
|
|
153
|
+
return isRec(kit) && isRec(kit.fields);
|
|
154
|
+
}
|
|
155
|
+
export function kitHasActionProps(props: unknown): boolean {
|
|
156
|
+
const kit = isRec(props) ? props.kit : undefined;
|
|
157
|
+
return isRec(kit) && isRec(kit.actions);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 运行期条带汇总判定(props.kit.strips[条带键],由 spatial/emit.ts 写入) */
|
|
161
|
+
export interface KitStripRuntimeProps {
|
|
162
|
+
readonly level?: KitLevel;
|
|
163
|
+
readonly flow?: KitFlow;
|
|
164
|
+
readonly collapse?: KitCollapse;
|
|
165
|
+
readonly stripHidden?: boolean;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const STRIP_LEVEL_SET: ReadonlySet<string> = new Set(KIT_LEVELS);
|
|
169
|
+
const STRIP_FLOW_SET: ReadonlySet<string> = new Set(KIT_FLOWS);
|
|
170
|
+
const STRIP_COLLAPSE_SET: ReadonlySet<string> = new Set(KIT_COLLAPSES);
|
|
171
|
+
const EMPTY_STRIP_PROPS: KitStripRuntimeProps = Object.freeze({});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 条带级判定:props.kit.strips[条带键] = { level, flow, collapse, stripHidden }(与 spatial/emit.ts 写入同形)。
|
|
175
|
+
* 每一项按闭集校验;没有这一层、这一条带或全为非法值时返回共享冻结空对象。
|
|
176
|
+
*/
|
|
177
|
+
export function kitStripPropsOf(props: unknown, stripKey: string): KitStripRuntimeProps {
|
|
178
|
+
const kit = isRec(props) ? props.kit : undefined;
|
|
179
|
+
const strips = isRec(kit) ? kit.strips : undefined;
|
|
180
|
+
const raw = isRec(strips) ? strips[stripKey] : undefined;
|
|
181
|
+
if (!isRec(raw)) return EMPTY_STRIP_PROPS;
|
|
182
|
+
const out: { -readonly [K in keyof KitStripRuntimeProps]: KitStripRuntimeProps[K] } = {};
|
|
183
|
+
let hasAny = false;
|
|
184
|
+
if (typeof raw.level === 'string' && STRIP_LEVEL_SET.has(raw.level)) { out.level = raw.level as KitLevel; hasAny = true; }
|
|
185
|
+
if (typeof raw.flow === 'string' && STRIP_FLOW_SET.has(raw.flow)) { out.flow = raw.flow as KitFlow; hasAny = true; }
|
|
186
|
+
if (typeof raw.collapse === 'string' && STRIP_COLLAPSE_SET.has(raw.collapse)) { out.collapse = raw.collapse as KitCollapse; hasAny = true; }
|
|
187
|
+
if (typeof raw.stripHidden === 'boolean') { out.stripHidden = raw.stripHidden; hasAny = true; }
|
|
188
|
+
return hasAny ? Object.freeze(out) : EMPTY_STRIP_PROPS;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ── 判定 → 类(只做一一映射,不判断) ──────────────────────────────────────────────
|
|
192
|
+
|
|
193
|
+
// 逻辑对齐 → 文字对齐类只有一张表:base/kit-contract.ts#KIT_ALIGN_CLASS(逻辑方向,RTL 下自动翻转),此处转出口不再另立一张。
|
|
194
|
+
/** 逻辑对齐 → 弹性盒主轴对齐类(单元格里值宿主是 flex 时用) */
|
|
195
|
+
export const KIT_ALIGN_JUSTIFY_CLASS: Readonly<Record<KitAlign, string>> = Object.freeze({ start: 'justify-start', center: 'justify-center', end: 'justify-end' });
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 组件按页面线判定(入参 kit)在运行期才换上的类:对齐类表(KIT_ALIGN_CLASS)与弹性盒对齐表、标题显隐用的 sr-only、表单列数换出的 12 栅格跨度档、
|
|
199
|
+
* 单一值输出改写出的单轴内边距类、文字型动作的链接色类。
|
|
200
|
+
* 不并进各组件自己的 *_CLASS_CANDIDATES——候选类会进页面样式,旧版(legacy)产物要逐字节不变;
|
|
201
|
+
* 只在新流水线模式下由页面编译在整页候选处统一并入(compile/styles.ts#collectPageCandidates,任何页面都有,不依赖是否经过对象渲染),
|
|
202
|
+
* legacy 下没有 kit 入参、也用不到这些类。
|
|
203
|
+
*/
|
|
204
|
+
export const KIT_CONTRACT_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
205
|
+
...new Set([
|
|
206
|
+
...Object.values(KIT_ALIGN_CLASS), ...Object.values(KIT_ALIGN_JUSTIFY_CLASS),
|
|
207
|
+
...Object.values(KIT_OVERFLOW_CLASS).flatMap((c) => c.split(' ')),
|
|
208
|
+
// Text / Tag 按溢出判定换上的文本角色类(base/kit-contract.ts#kitOverflowFit:wrap → prose、truncate / middle → name、clamp2 → clamp-2)
|
|
209
|
+
...(['prose', 'name', 'clamp-2'] as const).flatMap((r) => kitTextFit(r).class.split(' ')),
|
|
210
|
+
'sr-only',
|
|
211
|
+
// Tag / PriceText 按页面线对齐在格内真正移动时换上的块级根与自动外边距(base/kit-contract.ts#kitInlineRootAlign)
|
|
212
|
+
...KIT_INLINE_ROOT_ALIGN_CLASS_CANDIDATES,
|
|
213
|
+
...[1, 2, 3, 4, 6, 12].map((n) => `col-span-${n}`),
|
|
214
|
+
// 表单栅格按变量排(data/object-form.ts#withKitColumns,新模式)时整行格的跨度
|
|
215
|
+
'col-span-full',
|
|
216
|
+
// 单一值输出把 p-* 改写成单轴(recipes/pipeline-runtime.ts)后出现的 px-* / py-*;文字型动作新模式改引链接色(recipes/control.ts#kitLinkInkRecipe)
|
|
217
|
+
...KIT_SINGLE_VALUE_CLASS_CANDIDATES,
|
|
218
|
+
'text-link',
|
|
219
|
+
// 组件自己承担原先按组件名写的主题规则时带上的类(表格工具条轴内边距、分页条等宽数字,recipes/self-owned.ts)
|
|
220
|
+
...KIT_SELF_OWNED_CLASS_CANDIDATES,
|
|
221
|
+
]),
|
|
222
|
+
]);
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 窄容器下可收的列:字段级判定里 keep 为 optional 的字段名(保持声明顺序)。必留的不在其中——永不收。
|
|
226
|
+
* 没有字段级汇总时返回空数组,调用方按原来的收列逻辑走。
|
|
227
|
+
*/
|
|
228
|
+
export function kitOptionalFields(props: unknown, fields: readonly string[]): string[] {
|
|
229
|
+
return fields.filter((f) => kitFieldPropsOf(props, f).keep === 'optional');
|
|
230
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// Leaderboard:排行榜(layer: data,写死形状,accept: list)。通用「名次 + 名称 + 数值 + 占比条」,不含行业名词。
|
|
2
|
+
//
|
|
3
|
+
// 结构抄自 Tremor 的 BarList(名称在条内、数值在右)与 shadcn blocks 的排名卡片(名次圈 + 头像 + 名称 + 右对齐数值),
|
|
4
|
+
// 条沿用 kit 的迷你条(kitMiniBarNode,与指标卡同一图形),不写内联样式。
|
|
5
|
+
// 数据:`data` 是行 [{ id, name, value, share?, sub?, avatar?, unit?, tone? }];
|
|
6
|
+
// 名次 = 按 value 降序后的位次(相同数值并列同名次);`order: 'asc'` 升序(越小越靠前,如耗时)。
|
|
7
|
+
// 占比条 = share(0~100,行里给了就用);没给 share 时按「本行 value / 全部 value 之和」算;bar: 'max' 改成「相对第一名」。
|
|
8
|
+
// 前三名的名次圈走语气软底(金 / 银 / 铜不用颜色硬编码,取 warning / neutral / info 语气),其余中性。
|
|
9
|
+
// 点行抛 `select { id, item }`。
|
|
10
|
+
|
|
11
|
+
import { kitApplyLevelClass } from './level-class';
|
|
12
|
+
import { kitLevelParentClass } from '../recipes/pipeline-runtime';
|
|
13
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
14
|
+
import { KIT_PROGRESS_CLASS_CANDIDATES, kitMiniBarNode, clampPercent, type ProgressTone } from '../base/progress';
|
|
15
|
+
import {
|
|
16
|
+
KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
17
|
+
kitReadHostAutoSequence,
|
|
18
|
+
kitResolveStatusOrCategoryTone,
|
|
19
|
+
type KitSemanticOrCategoryTone,
|
|
20
|
+
} from '../recipes/color-role';
|
|
21
|
+
import { safeSrc, initialsOf } from '../base/avatar';
|
|
22
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
23
|
+
import { KIT_FOCUS_RING, kitSelectedRecipe } from '../recipes/state';
|
|
24
|
+
import { kitDivideRecipe } from '../recipes/divider';
|
|
25
|
+
import { kitWellRecipe } from '../recipes/surface';
|
|
26
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
27
|
+
import { mergeClass } from '../shared/merge-class';
|
|
28
|
+
import { KIT_SKELETON_BAR_BASE, KIT_STATE_RETRY_CLASS_CANDIDATES } from '../recipes/placeholder';
|
|
29
|
+
import { kitDecorFillRecipe, kitDecorToneOf } from '../recipes/field-text';
|
|
30
|
+
import { KIT_LOOK_TONE_ATTR } from '../recipes/look';
|
|
31
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
32
|
+
import { kitText } from '../i18n/kit-text';
|
|
33
|
+
import { TONE_SOFT, classTokens, emptyNode, keyMap, mk, retryButton, rowsOf, textOf } from './shape-util';
|
|
34
|
+
import { rowKey } from './d9-util';
|
|
35
|
+
import { kitMarkDataFacts, kitMarkLevel, kitMarkPart, kitMarkPicked } from './kit-contract';
|
|
36
|
+
import { KIT_ATTR_LOADING, KIT_ATTR_PART, KIT_ATTR_PICK, KIT_ATTR_RANK, KIT_ATTR_RETRY, KIT_ATTR_SELECTED, kitAttrSel } from '../shared/dom-attrs';
|
|
37
|
+
|
|
38
|
+
export const KIT_LEADERBOARD_DEFAULT_MAP = Object.freeze({
|
|
39
|
+
id: 'id', name: 'name', value: 'value', share: 'share', sub: 'sub', avatar: 'avatar', unit: 'unit', tone: 'tone',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const ROOT_CLASS = mergeClass('flex flex-col', kitTypographyRecipe('text'));
|
|
43
|
+
// 行线(divided):父出子项间发丝线(非末项),贯通到面板内缘
|
|
44
|
+
const ROOT_DIVIDED_CLASS = mergeClass(ROOT_CLASS, kitDivideRecipe('y'));
|
|
45
|
+
const ROW_CLASS = 'flex items-center gap-3 rounded-item px-4 py-3';
|
|
46
|
+
const ROW_PICK_CLASS = `${ROW_CLASS} w-full text-start transition-colors hover:bg-state-layer-hover ${KIT_FOCUS_RING.item}`;
|
|
47
|
+
// 选中行:主色淡底 + aria-current(选中配方自带选中悬停层)
|
|
48
|
+
const ROW_ON_CLASS = mergeClass(mergeClass(mergeClass(ROW_CLASS, 'w-full text-start transition-colors'), kitSelectedRecipe()), KIT_FOCUS_RING.item);
|
|
49
|
+
// 加载骨架:名次圈 + 名称条 + 占比条(条宽逐行递减,与真实排行的条形走势一致)
|
|
50
|
+
const SKELETON_ROW_CLASS = 'flex items-center gap-3 px-4 py-3';
|
|
51
|
+
const SKELETON_RANK_CLASS = mergeClass(mergeClass('size-6 shrink-0 rounded-full', kitWellRecipe()), 'motion-safe:animate-kit-pulse');
|
|
52
|
+
const SKELETON_BODY_CLASS = 'flex min-w-0 flex-1 flex-col gap-2';
|
|
53
|
+
const SKELETON_BAR_WIDTHS: readonly string[] = Object.freeze(['w-full', 'w-5/6', 'w-2/3', 'w-1/2', 'w-1/3']);
|
|
54
|
+
const STATE_ERR_CLASS = mergeClass(mergeClass('flex items-center justify-between gap-2 rounded-item bg-danger-soft px-3 py-2', kitTypographyRecipe('text')), 'text-danger-on-soft');
|
|
55
|
+
const RANK_BASE = mergeClass('flex size-6 shrink-0 items-center justify-center rounded-full', kitTypographyRecipe('deltaSm'));
|
|
56
|
+
/** 名次圈:前三名取语气软底,其余中性文字 */
|
|
57
|
+
const RANK_TOP: readonly string[] = Object.freeze([TONE_SOFT.warning, TONE_SOFT.neutral, TONE_SOFT.info]);
|
|
58
|
+
const RANK_REST = 'text-fg-subtle';
|
|
59
|
+
const AVATAR_CLASS = mergeClass(mergeClass('flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full', kitTypographyRecipe('captionPlain')), kitDecorFillRecipe());
|
|
60
|
+
const AVATAR_IMG_CLASS = 'size-full object-cover';
|
|
61
|
+
const BODY_CLASS = 'flex min-w-0 flex-1 flex-col gap-1';
|
|
62
|
+
const HEAD_CLASS = 'flex items-baseline justify-between gap-3';
|
|
63
|
+
const NAME_CLASS = mergeClass('min-w-0 truncate', kitTypographyRecipe('menuItem'));
|
|
64
|
+
const SUB_CLASS = mergeClass('truncate', kitTypographyRecipe('captionPlain'));
|
|
65
|
+
const VALUE_CLASS = mergeClass(mergeClass('shrink-0', kitTypographyRecipe('deltaMd')), 'text-fg');
|
|
66
|
+
const UNIT_CLASS = mergeClass(mergeClass('ms-1', kitTypographyRecipe('caption')), 'text-fg-muted');
|
|
67
|
+
const SHARE_CLASS = mergeClass(mergeClass('w-12 shrink-0 text-end tabular-nums', kitTypographyRecipe('captionPlain')), 'text-fg-muted');
|
|
68
|
+
const BAR_ROW_CLASS = 'flex items-center gap-2';
|
|
69
|
+
const BAR_BOX_CLASS = 'min-w-0 flex-1';
|
|
70
|
+
|
|
71
|
+
export const KIT_LEADERBOARD_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
72
|
+
ROOT_CLASS, ROW_CLASS, ROW_PICK_CLASS, RANK_BASE, RANK_TOP, RANK_REST, AVATAR_CLASS, AVATAR_IMG_CLASS, BODY_CLASS, HEAD_CLASS,
|
|
73
|
+
NAME_CLASS, SUB_CLASS, VALUE_CLASS, UNIT_CLASS, SHARE_CLASS, BAR_ROW_CLASS, BAR_BOX_CLASS,
|
|
74
|
+
ROOT_DIVIDED_CLASS, ROW_ON_CLASS, SKELETON_ROW_CLASS, SKELETON_RANK_CLASS, SKELETON_BODY_CLASS, SKELETON_BAR_WIDTHS, KIT_SKELETON_BAR_BASE,
|
|
75
|
+
STATE_ERR_CLASS, 'sr-only', 'h-4', KIT_STATE_RETRY_CLASS_CANDIDATES,
|
|
76
|
+
KIT_PROGRESS_CLASS_CANDIDATES, KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface KitLeaderEntry {
|
|
80
|
+
key: string;
|
|
81
|
+
rank: number;
|
|
82
|
+
name: string;
|
|
83
|
+
sub: string;
|
|
84
|
+
avatar: string;
|
|
85
|
+
unit: string;
|
|
86
|
+
value: number;
|
|
87
|
+
valueText: string;
|
|
88
|
+
percent: number;
|
|
89
|
+
tone: ProgressTone;
|
|
90
|
+
raw: unknown;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const EXPLICIT_BAR_TONES: ReadonlySet<string> = new Set<KitSemanticOrCategoryTone>([
|
|
94
|
+
'primary', 'info', 'success', 'warning', 'danger', 'neutral', 'tertiary', 'second',
|
|
95
|
+
'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8',
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
const BAR_TONES: readonly ProgressTone[] = ['primary', 'info', 'success', 'warning', 'danger'];
|
|
99
|
+
|
|
100
|
+
function barToneOf(raw: unknown): ProgressTone {
|
|
101
|
+
return BAR_TONES.find((t) => t === raw) ?? 'primary';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 源数据 -> 排行项(纯函数):value 非数字的行丢弃;并列同名次(竞赛排名 1,1,3) */
|
|
105
|
+
export function leaderEntriesOf(data: unknown, mapRaw: unknown, order: unknown = 'desc', bar: unknown = 'share'): KitLeaderEntry[] {
|
|
106
|
+
const m = keyMap(KIT_LEADERBOARD_DEFAULT_MAP, mapRaw);
|
|
107
|
+
const asc = order === 'asc';
|
|
108
|
+
const rows = rowsOf(data).map((raw, i) => ({ raw, i, value: num(raw[m.value]) })).filter((r): r is { raw: Record<string, unknown>; i: number; value: number } => r.value !== null);
|
|
109
|
+
rows.sort((a, b) => (asc ? a.value - b.value : b.value - a.value) || a.i - b.i);
|
|
110
|
+
const total = rows.reduce((s, r) => s + Math.abs(r.value), 0);
|
|
111
|
+
const lead = rows.length > 0 ? Math.abs(rows[0]!.value) : 0;
|
|
112
|
+
const nf = new Intl.NumberFormat();
|
|
113
|
+
let prevValue: number | null = null;
|
|
114
|
+
let prevRank = 0;
|
|
115
|
+
return rows.map((r, idx) => {
|
|
116
|
+
const rank = prevValue !== null && r.value === prevValue ? prevRank : idx + 1;
|
|
117
|
+
prevValue = r.value;
|
|
118
|
+
prevRank = rank;
|
|
119
|
+
const given = num(r.raw[m.share]);
|
|
120
|
+
const base = bar === 'max' ? lead : total;
|
|
121
|
+
const percent = given !== null ? clampPercent(given) : base > 0 ? clampPercent((Math.abs(r.value) / base) * 100) : 0;
|
|
122
|
+
const rawValue = r.raw[m.value];
|
|
123
|
+
return {
|
|
124
|
+
key: rowKey(r.raw[m.id], r.i, 'l'),
|
|
125
|
+
rank,
|
|
126
|
+
name: textOf(r.raw[m.name]),
|
|
127
|
+
sub: textOf(r.raw[m.sub]),
|
|
128
|
+
avatar: safeSrc(str(r.raw[m.avatar])),
|
|
129
|
+
unit: textOf(r.raw[m.unit]),
|
|
130
|
+
value: r.value,
|
|
131
|
+
valueText: typeof rawValue === 'string' ? rawValue : nf.format(r.value),
|
|
132
|
+
percent,
|
|
133
|
+
tone: barToneOf(r.raw[m.tone]),
|
|
134
|
+
raw: r.raw,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function createLeaderboard(): SomaComponentDefinition {
|
|
140
|
+
return {
|
|
141
|
+
contract: {
|
|
142
|
+
name: 'Leaderboard',
|
|
143
|
+
layer: 'data',
|
|
144
|
+
props: {
|
|
145
|
+
data: { type: 'array', default: [], desc: '排行行 [{ id, name, value, share?, sub?, avatar?, unit?, tone? }];value 非数字的行忽略' },
|
|
146
|
+
map: { type: 'object', default: {}, desc: '键名对照:id / name / value / share / sub / avatar / unit / tone -> 数据里的键' },
|
|
147
|
+
order: { type: 'string', default: 'desc', desc: '排序:desc(大者靠前,缺省)| asc(小者靠前);并列同名次' },
|
|
148
|
+
bar: { type: 'string', default: 'share', desc: '占比条口径:share = 本行占全部之和(缺省)| max = 相对第一名;行里有 share 字段时以它为准' },
|
|
149
|
+
show_share: { type: 'boolean', default: true, desc: '是否在条右侧显示百分比数字' },
|
|
150
|
+
limit: { type: 'number', default: 0, desc: '只显示前 N 名;0 = 不截断' },
|
|
151
|
+
empty_text: { type: 'string', default: '', desc: '无数据时的文案;缺省取内置文案(按页面语言)' },
|
|
152
|
+
selected: { type: 'string', default: '', desc: '选中行的 id:行画主色淡底并标 aria-current(外部变化时覆盖内部选中)' },
|
|
153
|
+
divided: { type: 'boolean', default: false, desc: '行间发丝线(子线,贯通到面板内缘);缺省无线、靠悬停底区分' },
|
|
154
|
+
loading: { type: 'boolean', default: false, desc: '加载中:没有数据时画骨架行(名次圈 + 条,条宽递减),有数据时保留并标 aria-busy' },
|
|
155
|
+
loading_text: { type: 'string', default: '', desc: '加载中文案(读屏用)' },
|
|
156
|
+
error: { type: 'string', default: '', desc: '错误文案,非空即错误态(role=alert);retry_text 非空时带重试钮' },
|
|
157
|
+
retry_text: { type: 'string', default: '', desc: '错误态重试钮文字,空则不显示' },
|
|
158
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
159
|
+
},
|
|
160
|
+
emits: {
|
|
161
|
+
select: { payload: { id: { type: 'string' }, item: { type: 'object' } }, desc: '点一行;item 是源数据行' },
|
|
162
|
+
retry: { payload: {}, desc: '错误态点重试' },
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
templateHtml: `<ol data-soma-id="root" class="${ROOT_CLASS}"></ol>`,
|
|
166
|
+
controllerFactory: createKitController((api) => {
|
|
167
|
+
const P = (): Record<string, unknown> => api.props();
|
|
168
|
+
let root: HTMLElement | null = null;
|
|
169
|
+
const listOf = (): KitLeaderEntry[] => {
|
|
170
|
+
const p = P();
|
|
171
|
+
const all = leaderEntriesOf(p.data, p.map, p.order, p.bar);
|
|
172
|
+
const limit = num(p.limit);
|
|
173
|
+
return limit !== null && limit > 0 ? all.slice(0, Math.floor(limit)) : all;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// 选中:外部 selected 只在它自己变化时覆盖内部选中
|
|
177
|
+
let selected = '';
|
|
178
|
+
let lastGiven = '';
|
|
179
|
+
const rowNode = (
|
|
180
|
+
e: KitLeaderEntry,
|
|
181
|
+
idx: number,
|
|
182
|
+
showShare: boolean,
|
|
183
|
+
toneKey: string,
|
|
184
|
+
autoSeq: readonly number[] | undefined,
|
|
185
|
+
): HTMLElement => {
|
|
186
|
+
const li = mk('li', '');
|
|
187
|
+
li.setAttribute(KIT_ATTR_RANK, String(e.rank));
|
|
188
|
+
// 榜单每一行是集合条目;选中自报落在 li(与 data-kit-selected 同一节点),无障碍语义沿用行按钮上的 aria-current
|
|
189
|
+
kitMarkLevel(li, 'item', 'line'); kitApplyLevelClass(li);
|
|
190
|
+
const on = e.key === selected;
|
|
191
|
+
kitMarkPicked(li, 'selected', on, null);
|
|
192
|
+
const row = mk('button', on ? ROW_ON_CLASS : ROW_PICK_CLASS);
|
|
193
|
+
row.type = 'button';
|
|
194
|
+
row.setAttribute(KIT_ATTR_PICK, e.key);
|
|
195
|
+
if (on) { row.setAttribute('aria-current', 'true'); li.setAttribute(KIT_ATTR_SELECTED, ''); }
|
|
196
|
+
const rank = mk('span', `${RANK_BASE} ${e.rank <= RANK_TOP.length ? RANK_TOP[e.rank - 1]! : RANK_REST}`, String(e.rank));
|
|
197
|
+
kitMarkPart(rank, 'mark');
|
|
198
|
+
row.appendChild(rank);
|
|
199
|
+
if (e.avatar !== '' || e.name !== '') {
|
|
200
|
+
const face = mk('span', AVATAR_CLASS);
|
|
201
|
+
face.setAttribute('aria-hidden', 'true');
|
|
202
|
+
const paintInitials = (): void => {
|
|
203
|
+
face.setAttribute(KIT_LOOK_TONE_ATTR, kitDecorToneOf(e.name));
|
|
204
|
+
face.textContent = initialsOf(e.name);
|
|
205
|
+
};
|
|
206
|
+
if (e.avatar !== '') {
|
|
207
|
+
const img = mk('img', AVATAR_IMG_CLASS);
|
|
208
|
+
img.src = e.avatar;
|
|
209
|
+
img.alt = '';
|
|
210
|
+
img.loading = 'lazy';
|
|
211
|
+
img.addEventListener('error', paintInitials, { once: true });
|
|
212
|
+
face.appendChild(img);
|
|
213
|
+
} else {
|
|
214
|
+
// 头像首字母底 = 装饰底:按名字散列取分类色(同名处处同色)
|
|
215
|
+
paintInitials();
|
|
216
|
+
}
|
|
217
|
+
row.appendChild(face);
|
|
218
|
+
}
|
|
219
|
+
const body = mk('span', BODY_CLASS);
|
|
220
|
+
const head = mk('span', HEAD_CLASS);
|
|
221
|
+
const name = mk('span', NAME_CLASS, e.name);
|
|
222
|
+
name.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
223
|
+
kitMarkPart(name, 'field-name');
|
|
224
|
+
const value = mk('span', VALUE_CLASS, e.valueText);
|
|
225
|
+
kitMarkPart(value, 'metric');
|
|
226
|
+
if (e.unit !== '') value.appendChild(mk('span', UNIT_CLASS, e.unit));
|
|
227
|
+
head.append(name, value);
|
|
228
|
+
body.appendChild(head);
|
|
229
|
+
if (e.sub !== '') body.appendChild(mk('span', SUB_CLASS, e.sub));
|
|
230
|
+
const barRow = mk('span', BAR_ROW_CLASS);
|
|
231
|
+
const box = mk('span', BAR_BOX_CLASS);
|
|
232
|
+
const rawTone = textOf((e.raw as Record<string, unknown> | null)?.[toneKey]).trim().toLowerCase();
|
|
233
|
+
const barTone: ProgressTone | KitSemanticOrCategoryTone = rawTone === ''
|
|
234
|
+
? kitResolveStatusOrCategoryTone(
|
|
235
|
+
e.name,
|
|
236
|
+
idx,
|
|
237
|
+
autoSeq !== undefined ? { autoSequence: autoSeq } : { host: root },
|
|
238
|
+
)
|
|
239
|
+
: EXPLICIT_BAR_TONES.has(rawTone)
|
|
240
|
+
? (rawTone as KitSemanticOrCategoryTone)
|
|
241
|
+
: e.tone;
|
|
242
|
+
box.appendChild(kitMiniBarNode(document, e.percent, barTone));
|
|
243
|
+
barRow.appendChild(box);
|
|
244
|
+
if (showShare) barRow.appendChild(mk('span', SHARE_CLASS, `${Math.round(e.percent)}%`));
|
|
245
|
+
body.appendChild(barRow);
|
|
246
|
+
row.appendChild(body);
|
|
247
|
+
li.appendChild(row);
|
|
248
|
+
return li;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const paint = (): void => {
|
|
252
|
+
if (!root) return;
|
|
253
|
+
const p = P();
|
|
254
|
+
root.className = joinClass(p.divided === true ? kitLevelParentClass('item', ROOT_DIVIDED_CLASS) : ROOT_CLASS, p.class);
|
|
255
|
+
root.textContent = '';
|
|
256
|
+
const given = str(p.selected);
|
|
257
|
+
if (given !== lastGiven) { lastGiven = given; selected = given; }
|
|
258
|
+
const list = listOf();
|
|
259
|
+
const failed = str(p.error) !== '';
|
|
260
|
+
kitMarkDataFacts(root, { error: failed, loading: p.loading === true, empty: list.length === 0 });
|
|
261
|
+
if (failed) {
|
|
262
|
+
const li = mk('li', '');
|
|
263
|
+
const box = mk('div', STATE_ERR_CLASS);
|
|
264
|
+
box.setAttribute('role', 'alert');
|
|
265
|
+
box.appendChild(mk('span', '', str(p.error)));
|
|
266
|
+
if (str(p.retry_text) !== '') {
|
|
267
|
+
const btn = retryButton('retry', str(p.retry_text), 'danger');
|
|
268
|
+
btn.setAttribute(KIT_ATTR_RETRY, '');
|
|
269
|
+
box.appendChild(btn);
|
|
270
|
+
}
|
|
271
|
+
li.appendChild(box);
|
|
272
|
+
root.appendChild(li);
|
|
273
|
+
if (list.length === 0) return;
|
|
274
|
+
} else if (p.loading === true && list.length === 0) {
|
|
275
|
+
// 加载骨架:名次圈 + 名称条 + 占比条,条宽递减
|
|
276
|
+
const li = mk('li', '');
|
|
277
|
+
const box = mk('div', '');
|
|
278
|
+
box.setAttribute('role', 'status');
|
|
279
|
+
box.setAttribute('aria-busy', 'true');
|
|
280
|
+
box.setAttribute(KIT_ATTR_LOADING, '');
|
|
281
|
+
box.appendChild(mk('span', 'sr-only', str(p.loading_text, kitText('soma.kit.processing', undefined, root))));
|
|
282
|
+
for (const w of SKELETON_BAR_WIDTHS) {
|
|
283
|
+
const row = mk('div', SKELETON_ROW_CLASS);
|
|
284
|
+
row.setAttribute('aria-hidden', 'true');
|
|
285
|
+
row.setAttribute(KIT_ATTR_PART, 'leaderboard-skeleton-row');
|
|
286
|
+
const body = mk('div', SKELETON_BODY_CLASS);
|
|
287
|
+
body.append(mk('div', `h-4 w-1/3 ${KIT_SKELETON_BAR_BASE}`), mk('div', `h-4 ${w} ${KIT_SKELETON_BAR_BASE}`));
|
|
288
|
+
row.append(mk('div', SKELETON_RANK_CLASS), body);
|
|
289
|
+
box.appendChild(row);
|
|
290
|
+
}
|
|
291
|
+
li.appendChild(box);
|
|
292
|
+
root.appendChild(li);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (p.loading === true && !failed) root.setAttribute('aria-busy', 'true'); else root.removeAttribute('aria-busy');
|
|
296
|
+
if (list.length === 0) {
|
|
297
|
+
const li = mk('li', '');
|
|
298
|
+
li.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
299
|
+
root.appendChild(li);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const showShare = p.show_share !== false;
|
|
303
|
+
const m = keyMap(KIT_LEADERBOARD_DEFAULT_MAP, p.map);
|
|
304
|
+
const autoSeq = kitReadHostAutoSequence(root);
|
|
305
|
+
list.forEach((e, idx) => root!.appendChild(rowNode(e, idx, showShare, m.tone, autoSeq)));
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
attach(rootEl) {
|
|
310
|
+
root = rootEl;
|
|
311
|
+
const r = root;
|
|
312
|
+
const onClick = (event: Event): void => {
|
|
313
|
+
const target = event.target as HTMLElement | null;
|
|
314
|
+
if (target?.closest(kitAttrSel(KIT_ATTR_RETRY))) { api.emit('retry', {}); return; }
|
|
315
|
+
const key = target?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_PICK))?.getAttribute(KIT_ATTR_PICK);
|
|
316
|
+
if (key === null || key === undefined) return;
|
|
317
|
+
const hit = listOf().find((e) => e.key === key);
|
|
318
|
+
if (!hit) return;
|
|
319
|
+
// 就地换选中态(焦点不丢),随后抛 select
|
|
320
|
+
selected = hit.key;
|
|
321
|
+
for (const b of Array.from(r.querySelectorAll<HTMLElement>(kitAttrSel(KIT_ATTR_PICK)))) {
|
|
322
|
+
const isOn = b.getAttribute(KIT_ATTR_PICK) === selected;
|
|
323
|
+
b.className = isOn ? ROW_ON_CLASS : ROW_PICK_CLASS;
|
|
324
|
+
if (isOn) b.setAttribute('aria-current', 'true'); else b.removeAttribute('aria-current');
|
|
325
|
+
if (isOn) b.parentElement?.setAttribute(KIT_ATTR_SELECTED, ''); else b.parentElement?.removeAttribute(KIT_ATTR_SELECTED);
|
|
326
|
+
if (b.parentElement) kitMarkPicked(b.parentElement, 'selected', isOn, null);
|
|
327
|
+
}
|
|
328
|
+
api.emit('select', { id: hit.key, item: hit.raw });
|
|
329
|
+
};
|
|
330
|
+
r.addEventListener('click', onClick);
|
|
331
|
+
return () => {
|
|
332
|
+
r.removeEventListener('click', onClick);
|
|
333
|
+
root = null;
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
render(rootEl) {
|
|
337
|
+
root = rootEl;
|
|
338
|
+
paint();
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// 数据组件里「落在层级角色节点上的类」的单一值输出出口(业务功能描述 §4.4、§5、§6.3;判据在 recipes/pipeline-runtime)。
|
|
2
|
+
//
|
|
3
|
+
// 新模式下,自报了层级角色的节点不再输出取值表对该角色负责的那几类(底色、边框与分隔线、圆角、阴影、内边距),否则无层工具类恒胜出、取值表不起作用。
|
|
4
|
+
// 数据组件的常见写法是「先 mk(tag, CLS) 赋类、后 kitMarkLevel(el, L) 自报」,所以这里在自报之后按节点**实际**的 data-kit-level 重算一次类。
|
|
5
|
+
//
|
|
6
|
+
// 旧版逐字节不变:kitLevelClassFor 在旧版原样返回,这里只有类串真的变了才写回——旧版不写 class 属性,
|
|
7
|
+
// 没有 class 属性的节点也不会被补上一个空的 class=""。
|
|
8
|
+
|
|
9
|
+
import { kitLevelClassFor, type KitLevelClassOptions } from '../recipes/pipeline-runtime';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 自报层级角色之后调用:按节点实际的层级角色剥掉取值表负责的类;旧版、或节点没有层级角色时不动节点。
|
|
13
|
+
* options 同 kitLevelClassFor(如气泡类面板声明内边距自理 KIT_SELF_PAD)。
|
|
14
|
+
*/
|
|
15
|
+
export function kitApplyLevelClass(el: Element | null | undefined, options?: KitLevelClassOptions): void {
|
|
16
|
+
if (el === null || el === undefined) return;
|
|
17
|
+
const cur = el.getAttribute('class');
|
|
18
|
+
if (cur === null) return;
|
|
19
|
+
const next = kitLevelClassFor(el, cur, options);
|
|
20
|
+
if (next !== cur) el.setAttribute('class', next);
|
|
21
|
+
}
|