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,227 @@
|
|
|
1
|
+
// CompareView:对比视图(layer: data,写死形状,accept: single)。
|
|
2
|
+
//
|
|
3
|
+
// 数据:`data` 是 { columns, rows }:
|
|
4
|
+
// columns [{ key, label, note? }] 列 = 被比较的对象(左起第一列是基准)
|
|
5
|
+
// rows [{ key, label, group?, better?, values: { <列 key>: 值 } }] 行 = 属性;better = high / low 时该行数值型最优列高亮
|
|
6
|
+
// `highlight`:diff(缺省:与基准列不同的格浅底标出)| best(只标 better 行的最优格)| both | none。
|
|
7
|
+
// 颜色之外有读屏文字(差异 / 最优),不靠颜色单独表达;相同值不标,缺失值显示「—」且不参与比较。
|
|
8
|
+
// 结构抄 Ant Design Table / shadcn Table 的真 <table>:表头吸顶、首列(属性名)吸左,行间发丝线;行 group 变化时插一条组标题行。
|
|
9
|
+
// 事件:点列头抛 `column_pick { column }`。
|
|
10
|
+
|
|
11
|
+
import { kitApplyLevelClass } from './level-class';
|
|
12
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
+
import { kitHasProps, kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
|
|
14
|
+
import { createKitController, formatValue, joinClass, num, preserveKitScroll, str, type KitProps } from '../base/shared';
|
|
15
|
+
import { applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS } from '../base/state-panel';
|
|
16
|
+
import { KIT_FACE_HEAD_CLASS } from '../recipes/container';
|
|
17
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
18
|
+
import { kitClosedValueRecipe, kitFieldNameRecipe } from '../recipes/field-text';
|
|
19
|
+
import { kitFocusRingRecipe } from '../recipes/state';
|
|
20
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
21
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
22
|
+
import { mergeClass } from '../shared/merge-class';
|
|
23
|
+
import { classTokens, emptyNode, mk, recOf, rowsOf, textOf } from './shape-util';
|
|
24
|
+
import { COMPARE_MAX_COLUMNS, COMPARE_MAX_ROWS } from './summary-util';
|
|
25
|
+
import { KIT_ATTR_COLUMN, KIT_ATTR_DIFF_MARK, kitAttrSel } from '../shared/dom-attrs';
|
|
26
|
+
|
|
27
|
+
const ROOT_CLASS = 'relative isolate w-full overflow-auto';
|
|
28
|
+
const TABLE_CLASS = mergeClass('w-full', kitTypographyRecipe('text'));
|
|
29
|
+
// 照组件卡 Table.md §6 / §7(对比视图无源码,复用表格卡):表头 = 层级表头带(KIT_FACE_HEAD_CLASS,不加底线)、字段名 = tableHead 字阶(500 / 弱化墨)、
|
|
30
|
+
// 行定高 h-table-row、行间发丝线、悬停 = 状态层;shadcn table.tsx 的 h-10 表头改为同一行高令牌
|
|
31
|
+
const HEAD_CLASS = mergeClass('h-table-row whitespace-nowrap px-3 text-start align-middle', kitFieldNameRecipe());
|
|
32
|
+
const HEAD_STICKY = `sticky top-0 z-10 ${KIT_FACE_HEAD_CLASS}`;
|
|
33
|
+
const HEAD_CORNER = `sticky start-0 top-0 z-20 ${KIT_FACE_HEAD_CLASS}`;
|
|
34
|
+
const HEAD_BTN = mergeClass('max-w-full cursor-pointer truncate rounded-item text-start', kitFocusRingRecipe('item'));
|
|
35
|
+
const NOTE_CLASS = 'block font-normal text-fg-subtle';
|
|
36
|
+
const GROUP_CLASS = mergeClass('px-3 pb-1 pt-4 text-start', kitTypographyRecipe('tableGroup'));
|
|
37
|
+
const ROW_HEAD_CLASS = mergeClass('sticky start-0 z-10 h-table-row whitespace-nowrap bg-surface p-0 text-start align-middle', kitFieldNameRecipe());
|
|
38
|
+
const ROW_HEAD_INNER_CLASS = 'flex h-full w-full items-center px-3 transition-colors group-hover/row:bg-state-layer-hover';
|
|
39
|
+
const CELL_CLASS = 'h-table-row whitespace-nowrap px-3 align-middle tabular-nums text-fg';
|
|
40
|
+
const LINE_CLASS = kitDividerRecipe('top');
|
|
41
|
+
const DIFF_CHIP = kitClosedValueRecipe('primary');
|
|
42
|
+
const BEST_CHIP = mergeClass(kitClosedValueRecipe('success'), 'font-medium');
|
|
43
|
+
const MISSING_CLASS = 'text-fg-subtle';
|
|
44
|
+
const SR_CLASS = 'sr-only';
|
|
45
|
+
// 悬停 = 状态层出口(KT-HB-F1:悬停 / 按下走 state-layer,不用凹槽色;group/row 联动吸左首列)
|
|
46
|
+
const ROW_HOVER = 'group/row hover:bg-state-layer-hover';
|
|
47
|
+
|
|
48
|
+
export const KIT_COMPARE_VIEW_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
49
|
+
ROW_HOVER, ROW_HEAD_INNER_CLASS, DIFF_CHIP, BEST_CHIP,
|
|
50
|
+
ROOT_CLASS, TABLE_CLASS, HEAD_CLASS, HEAD_STICKY, HEAD_CORNER, HEAD_BTN, NOTE_CLASS, GROUP_CLASS, ROW_HEAD_CLASS, CELL_CLASS, LINE_CLASS,
|
|
51
|
+
MISSING_CLASS, SR_CLASS,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export type KitCompareHighlight = 'diff' | 'best' | 'both' | 'none';
|
|
55
|
+
export const KIT_COMPARE_HIGHLIGHTS: readonly KitCompareHighlight[] = Object.freeze(['diff', 'best', 'both', 'none']);
|
|
56
|
+
|
|
57
|
+
export type KitCellMark = 'none' | 'diff' | 'best';
|
|
58
|
+
|
|
59
|
+
function sameCompareValue(a: unknown, b: unknown, formatText?: (v: unknown) => string): boolean {
|
|
60
|
+
if (String(a).trim() === String(b).trim()) return true;
|
|
61
|
+
const na = num(a);
|
|
62
|
+
const nb = num(b);
|
|
63
|
+
if (na !== null && nb !== null && na === nb) return true;
|
|
64
|
+
if (formatText !== undefined && formatText(a) === formatText(b)) return true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 一行里各列的标记(纯函数):缺失值 none;diff = 与基准列(第一列)不等价(如 10 与 '10.00' 或格式化一致时不误标);best = better 行数值型最优(并列都标) */
|
|
69
|
+
export function compareMarksOf(
|
|
70
|
+
values: readonly unknown[],
|
|
71
|
+
better: unknown,
|
|
72
|
+
highlight: KitCompareHighlight,
|
|
73
|
+
formatText?: (v: unknown) => string,
|
|
74
|
+
): KitCellMark[] {
|
|
75
|
+
const present = (v: unknown): boolean => v !== undefined && v !== null && v !== '';
|
|
76
|
+
const marks: KitCellMark[] = values.map(() => 'none');
|
|
77
|
+
if (highlight === 'diff' || highlight === 'both') {
|
|
78
|
+
const base = values[0];
|
|
79
|
+
if (present(base)) {
|
|
80
|
+
values.forEach((v, i) => {
|
|
81
|
+
if (i > 0 && present(v) && !sameCompareValue(v, base, formatText)) marks[i] = 'diff';
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if ((highlight === 'best' || highlight === 'both') && (better === 'high' || better === 'low')) {
|
|
86
|
+
const nums = values.map((v) => (present(v) ? num(v) : null));
|
|
87
|
+
const found = nums.filter((n): n is number => n !== null);
|
|
88
|
+
if (found.length > 1) {
|
|
89
|
+
const pickN = better === 'high' ? Math.max(...found) : Math.min(...found);
|
|
90
|
+
if (found.some((n) => n !== pickN)) nums.forEach((n, i) => { if (n === pickN) marks[i] = 'best'; });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return marks;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function createCompareView(): SomaComponentDefinition {
|
|
97
|
+
return {
|
|
98
|
+
contract: {
|
|
99
|
+
name: 'CompareView',
|
|
100
|
+
layer: 'data',
|
|
101
|
+
props: {
|
|
102
|
+
data: { type: 'object', default: {}, desc: '{ columns: [{ key, label, note? }], rows: [{ key, label, group?, better?, format?, values: { 列key: 值 } }] }' },
|
|
103
|
+
highlight: { type: 'string', default: 'diff', desc: '高亮:diff(与基准列不同)| best(better 行最优)| both | none' },
|
|
104
|
+
format: { type: 'string', default: '', desc: '全表值格式(行上的 format 优先)' },
|
|
105
|
+
locale: { type: 'string', default: '', desc: '格式化语言' },
|
|
106
|
+
diff_label: { type: 'string', default: '有差异', desc: '差异格的读屏文字' },
|
|
107
|
+
best_label: { type: 'string', default: '最优', desc: '最优格的读屏文字' },
|
|
108
|
+
label: { type: 'string', default: '', desc: '表的无障碍名称' },
|
|
109
|
+
empty_text: { type: 'string', default: '—', desc: '无数据时的文案' },
|
|
110
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
111
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
112
|
+
},
|
|
113
|
+
emits: {
|
|
114
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
115
|
+
column_pick: { payload: { column: { type: 'string' } }, desc: '点列头:column 是列键' },
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
119
|
+
controllerFactory: createKitController((api) => ({
|
|
120
|
+
attach(root: HTMLElement): () => void {
|
|
121
|
+
const onClick = (event: Event): void => {
|
|
122
|
+
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_COLUMN));
|
|
123
|
+
if (btn && root.contains(btn)) api.emit('column_pick', { column: btn.getAttribute(KIT_ATTR_COLUMN) ?? '' });
|
|
124
|
+
};
|
|
125
|
+
root.addEventListener('click', onClick);
|
|
126
|
+
return () => root.removeEventListener('click', onClick);
|
|
127
|
+
},
|
|
128
|
+
render(root: HTMLElement, p: KitProps): void {
|
|
129
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
130
|
+
// 旧版:按祖先是不是面板决定画不画外框(data-kit-edge 由祖先样式去框);新流水线下外观由取值表按层级角色给,组件不再看祖先
|
|
131
|
+
if (!kitHasProps(p)) markKitEdge(root);
|
|
132
|
+
const active = root.ownerDocument.activeElement;
|
|
133
|
+
const focusedCol = active instanceof HTMLElement && root.contains(active)
|
|
134
|
+
? active.closest<HTMLElement>(kitAttrSel(KIT_ATTR_COLUMN))?.getAttribute(KIT_ATTR_COLUMN) ?? null
|
|
135
|
+
: null;
|
|
136
|
+
preserveKitScroll(root, () => {
|
|
137
|
+
root.textContent = '';
|
|
138
|
+
const d = recOf(p.data);
|
|
139
|
+
const cols = rowsOf(d.columns).slice(0, COMPARE_MAX_COLUMNS).map((c, i) => ({ key: textOf(c.key) || String(i), label: textOf(c.label) || textOf(c.key), note: textOf(c.note) }));
|
|
140
|
+
const rows = rowsOf(d.rows).slice(0, COMPARE_MAX_ROWS);
|
|
141
|
+
const hasContent = cols.length > 0 && rows.length > 0;
|
|
142
|
+
// 数据状态自报(每次渲染都写):与读状态面板同一判据,出错 > 加载 > 空;data-kit-state 面板标记照旧
|
|
143
|
+
kitMarkDataFacts(root, { error: str(p.error_text) !== '', loading: p.loading === true || p.loading === 'true', empty: !(hasContent) });
|
|
144
|
+
if (applyKitReadState(root, p, { hasContent, onRetry: () => api.emit('retry', {}), repaint: () => api.refresh() })) return;
|
|
145
|
+
if (!hasContent) { root.appendChild(emptyNode(str(p.empty_text, '—'))); return; }
|
|
146
|
+
const rawHighlight = str(p.highlight, 'diff');
|
|
147
|
+
const highlight = (KIT_COMPARE_HIGHLIGHTS as readonly string[]).includes(rawHighlight) ? rawHighlight as KitCompareHighlight : 'diff';
|
|
148
|
+
const locale = str(p.locale);
|
|
149
|
+
|
|
150
|
+
const table = mk('table', TABLE_CLASS);
|
|
151
|
+
if (str(p.label) !== '') table.setAttribute('aria-label', str(p.label));
|
|
152
|
+
const thead = mk('thead', '');
|
|
153
|
+
const hr = mk('tr', '');
|
|
154
|
+
// 表头带 = 面头(§8.2)
|
|
155
|
+
kitMarkLevel(hr, 'head'); kitApplyLevelClass(hr);
|
|
156
|
+
hr.appendChild(mk('th', HEAD_CORNER + ' ' + HEAD_CLASS)).setAttribute('scope', 'col');
|
|
157
|
+
for (const c of cols) {
|
|
158
|
+
const th = mk('th', `${HEAD_STICKY} ${HEAD_CLASS}`);
|
|
159
|
+
th.setAttribute('scope', 'col');
|
|
160
|
+
const btn = mk('button', HEAD_BTN, c.label);
|
|
161
|
+
btn.type = 'button';
|
|
162
|
+
btn.setAttribute(KIT_ATTR_COLUMN, c.key);
|
|
163
|
+
th.appendChild(btn);
|
|
164
|
+
if (c.note !== '') th.appendChild(mk('span', NOTE_CLASS, c.note));
|
|
165
|
+
hr.appendChild(th);
|
|
166
|
+
}
|
|
167
|
+
thead.appendChild(hr);
|
|
168
|
+
table.appendChild(thead);
|
|
169
|
+
|
|
170
|
+
const tbody = mk('tbody', '');
|
|
171
|
+
let lastGroup = '';
|
|
172
|
+
for (const r of rows) {
|
|
173
|
+
const group = textOf(r.group);
|
|
174
|
+
if (group !== '' && group !== lastGroup) {
|
|
175
|
+
const gr = mk('tr', '');
|
|
176
|
+
// 分组行 = 淡底带
|
|
177
|
+
kitMarkLevel(gr, 'band'); kitApplyLevelClass(gr);
|
|
178
|
+
const gh = mk('th', GROUP_CLASS, group);
|
|
179
|
+
gh.setAttribute('scope', 'rowgroup');
|
|
180
|
+
gh.setAttribute('colspan', String(cols.length + 1));
|
|
181
|
+
gr.appendChild(gh);
|
|
182
|
+
tbody.appendChild(gr);
|
|
183
|
+
}
|
|
184
|
+
lastGroup = group;
|
|
185
|
+
const vals = recOf(r.values);
|
|
186
|
+
const format = textOf(r.format) || str(p.format);
|
|
187
|
+
const fmtCell = (v: unknown): string => (format === '' ? String(v) : formatValue(v, format, locale));
|
|
188
|
+
const marks = compareMarksOf(cols.map((c) => vals[c.key]), r.better, highlight, fmtCell);
|
|
189
|
+
const tr = mk('tr', ROW_HOVER);
|
|
190
|
+
kitMarkLevel(tr, 'item', 'line'); kitApplyLevelClass(tr);
|
|
191
|
+
const rh = mk('th', `${ROW_HEAD_CLASS} ${LINE_CLASS}`);
|
|
192
|
+
rh.setAttribute('scope', 'row');
|
|
193
|
+
kitMarkPart(rh, 'field-name');
|
|
194
|
+
rh.appendChild(mk('span', ROW_HEAD_INNER_CLASS, textOf(r.label)));
|
|
195
|
+
tr.appendChild(rh);
|
|
196
|
+
cols.forEach((c, i) => {
|
|
197
|
+
const v = vals[c.key];
|
|
198
|
+
const missing = v === undefined || v === null || v === '';
|
|
199
|
+
const mark = marks[i]!;
|
|
200
|
+
const td = mk('td', `${CELL_CLASS} ${LINE_CLASS} ${missing ? MISSING_CLASS : ''}`.trim());
|
|
201
|
+
kitMarkPart(td, 'cell');
|
|
202
|
+
const text = missing ? '—' : fmtCell(v);
|
|
203
|
+
if (mark === 'none') td.textContent = text;
|
|
204
|
+
else {
|
|
205
|
+
// 差异 / 最优 = 闭集语义标记:值包进标记出口的语气淡底块(不在组件里直写 -soft 底,KT-HB-F2)
|
|
206
|
+
td.setAttribute(KIT_ATTR_DIFF_MARK, mark);
|
|
207
|
+
const chip = mk('span', mark === 'best' ? BEST_CHIP : DIFF_CHIP, text);
|
|
208
|
+
kitMarkPart(chip, 'mark');
|
|
209
|
+
chip.appendChild(mk('span', SR_CLASS, ` ${mark === 'best' ? str(p.best_label, '最优') : str(p.diff_label, '有差异')}`));
|
|
210
|
+
td.appendChild(chip);
|
|
211
|
+
}
|
|
212
|
+
tr.appendChild(td);
|
|
213
|
+
});
|
|
214
|
+
tbody.appendChild(tr);
|
|
215
|
+
}
|
|
216
|
+
table.appendChild(tbody);
|
|
217
|
+
root.appendChild(table);
|
|
218
|
+
if (focusedCol !== null) {
|
|
219
|
+
Array.from(table.querySelectorAll<HTMLButtonElement>(`button${kitAttrSel(KIT_ATTR_COLUMN)}`))
|
|
220
|
+
.find((b) => b.getAttribute(KIT_ATTR_COLUMN) === focusedCol)
|
|
221
|
+
?.focus({ preventScroll: true });
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
})),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
@@ -10,24 +10,38 @@
|
|
|
10
10
|
// 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 false)。
|
|
11
11
|
|
|
12
12
|
import type { SomaConfirmSpec } from 'soma-core';
|
|
13
|
+
import { OVERLAY_SCOPE_ATTRIBUTES } from 'soma-core/behavior';
|
|
13
14
|
import { confirmKeyAccepts, confirmSatisfied } from 'soma-core/render-ports';
|
|
14
15
|
import { KIT_CHECK_CLASS_CANDIDATES, createCheck, markInput, setMarkLabel } from '../base/check-core';
|
|
15
16
|
import { nextUid } from '../base/shared';
|
|
16
17
|
import { kitText } from '../i18n/kit-text';
|
|
17
|
-
import { kitControlRecipe, setKitFace } from '../recipes';
|
|
18
|
-
import {
|
|
18
|
+
import { kitControlRecipe, kitTypographyRecipe, setKitFace } from '../recipes';
|
|
19
|
+
import { KIT_PROSE_ATTR, kitProseFit, kitProseParagraphs } from '../recipes/text-fit';
|
|
20
|
+
import { mergeClass } from '../shared/merge-class';
|
|
21
|
+
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal, watchKitModalDetached, type KitModalHandle } from './modal-dialog';
|
|
22
|
+
import { kitMarkPart } from './kit-contract';
|
|
23
|
+
import { hasKitConfirmAsk, setKitConfirmAsk, type KitConfirmRequest } from '../base/kit-contract';
|
|
24
|
+
import { kitAskInlineConfirm } from '../base/popover';
|
|
19
25
|
import { ACTION_BUTTON_CONFIRM_DANGER, ACTION_BUTTON_TONE, BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
26
|
+
import { KIT_ATTR_LEAVING, KIT_ATTR_SCOPE } from '../shared/dom-attrs';
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
28
|
+
// 禁用态(KT-K0-4):原生 disabled 已置位,用 disabled: 变体换专用令牌,压过语气配方的实心底
|
|
29
|
+
const BUTTON_DISABLED = 'disabled:bg-control-disabled disabled:text-fg-disabled cursor-not-allowed';
|
|
30
|
+
const MESSAGE_CLASS = mergeClass('m-0 min-w-0 whitespace-pre-line break-words', kitTypographyRecipe('text'));
|
|
31
|
+
const IMPACT_CLASS = mergeClass(mergeClass('m-0 min-w-0 whitespace-pre-line break-words', kitTypographyRecipe('captionPlain')), 'text-fg-muted');
|
|
32
|
+
const PROMPT_CLASS = mergeClass(mergeClass('m-0 min-w-0 break-words', kitTypographyRecipe('captionPlain')), 'text-fg-muted');
|
|
25
33
|
// 键入短语的输入框 = 标准输入(控件配方,KT-B1 控件轮廓、§4 C6、§8 G-B5)
|
|
26
|
-
const INPUT_CLASS = kitControlRecipe();
|
|
34
|
+
const INPUT_CLASS = mergeClass(kitControlRecipe(), 'w-full min-w-0');
|
|
35
|
+
const DIALOG_TITLE_TIGHT = 'tracking-tight';
|
|
36
|
+
const LEAD_HEADER_PAD = 'p-card';
|
|
37
|
+
const LEAD_BODY_PAD = 'p-card pt-0';
|
|
38
|
+
const LEAD_GAP_CLASS = 'gap-1.5';
|
|
39
|
+
const CONSENT_WRAP_CLASS = 'min-w-0';
|
|
27
40
|
|
|
28
41
|
export const KIT_CONFIRM_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
29
|
-
BUTTON_DISABLED, MESSAGE_CLASS, IMPACT_CLASS, PROMPT_CLASS, INPUT_CLASS,
|
|
30
|
-
|
|
42
|
+
BUTTON_DISABLED, MESSAGE_CLASS, IMPACT_CLASS, PROMPT_CLASS, INPUT_CLASS,
|
|
43
|
+
DIALOG_TITLE_TIGHT, LEAD_HEADER_PAD, LEAD_BODY_PAD, LEAD_GAP_CLASS, CONSENT_WRAP_CLASS,
|
|
44
|
+
BUTTON_CLASS_TOKENS, KIT_MODAL_CLASS_CANDIDATES, KIT_CHECK_CLASS_CANDIDATES,
|
|
31
45
|
);
|
|
32
46
|
|
|
33
47
|
export interface KitConfirmOptions {
|
|
@@ -62,6 +76,8 @@ function btn(doc: Document, tone: ActionTone, label: string): HTMLButtonElement
|
|
|
62
76
|
b.className = tone === 'danger' ? ACTION_BUTTON_CONFIRM_DANGER : ACTION_BUTTON_TONE[tone];
|
|
63
77
|
setKitFace(b, 'raised');
|
|
64
78
|
b.textContent = label;
|
|
79
|
+
// 窗口底栏的按钮:元素部件「动作」(askKitPrompt 经 kitDialogButton 复用,同一处自报);窗口壳的浮层 / 面头 / 底栏由 base/overlay-shell 自报
|
|
80
|
+
kitMarkPart(b, 'action');
|
|
65
81
|
return b;
|
|
66
82
|
}
|
|
67
83
|
|
|
@@ -71,6 +87,56 @@ export const KIT_DIALOG_INPUT_CLASS = INPUT_CLASS;
|
|
|
71
87
|
export const KIT_DIALOG_MESSAGE_CLASS = MESSAGE_CLASS;
|
|
72
88
|
export const KIT_DIALOG_HINT_CLASS = PROMPT_CLASS;
|
|
73
89
|
|
|
90
|
+
/**
|
|
91
|
+
* 关闭并销毁命令式模态弹层:先调 close() 触发退场动画;
|
|
92
|
+
* 无退场动画(jsdom / 无关键帧,scrim 已同步脱离或未进入 data-kit-leaving)时立即同步 destroy(),兼容同步 DOM 断言;
|
|
93
|
+
* 有退场动画在播时等退场结束(getAnimations().finished / animationend / scrim 脱离 / 超时兜底)后再 destroy(),不掐死退场过渡。
|
|
94
|
+
*/
|
|
95
|
+
export function closeAndDestroyKitModal(modal: KitModalHandle, doc: Document): void {
|
|
96
|
+
modal.close();
|
|
97
|
+
if (!modal.scrim.isConnected || !modal.scrim.hasAttribute(KIT_ATTR_LEAVING)) {
|
|
98
|
+
modal.destroy();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let done = false;
|
|
102
|
+
let attrObs: MutationObserver | null = null;
|
|
103
|
+
let stopDetached: () => void = () => {};
|
|
104
|
+
const finalize = (): void => {
|
|
105
|
+
if (done) return;
|
|
106
|
+
done = true;
|
|
107
|
+
clearTimeout(fallback);
|
|
108
|
+
attrObs?.disconnect();
|
|
109
|
+
stopDetached();
|
|
110
|
+
modal.scrim.removeEventListener('animationend', check);
|
|
111
|
+
modal.scrim.removeEventListener('animationcancel', check);
|
|
112
|
+
modal.destroy();
|
|
113
|
+
};
|
|
114
|
+
const check = (): void => {
|
|
115
|
+
if (!modal.scrim.isConnected || !modal.scrim.hasAttribute(KIT_ATTR_LEAVING)) finalize();
|
|
116
|
+
};
|
|
117
|
+
const fallback = setTimeout(finalize, 1100);
|
|
118
|
+
modal.scrim.addEventListener('animationend', check);
|
|
119
|
+
modal.scrim.addEventListener('animationcancel', check);
|
|
120
|
+
if (typeof modal.scrim.getAnimations === 'function') {
|
|
121
|
+
try {
|
|
122
|
+
const anims = modal.scrim.getAnimations({ subtree: true }).filter((a) => a.effect?.getComputedTiming().iterations !== Infinity);
|
|
123
|
+
if (anims.length > 0) void Promise.allSettled(anims.map((a) => a.finished)).then(() => queueMicrotask(finalize));
|
|
124
|
+
} catch {
|
|
125
|
+
// 部分运行环境不支持 subtree 参数:交由事件 / MutationObserver / 超时兜底收尾
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const View = doc.defaultView;
|
|
129
|
+
const MO = View !== null && typeof View.MutationObserver === 'function'
|
|
130
|
+
? View.MutationObserver
|
|
131
|
+
: typeof MutationObserver !== 'undefined' ? MutationObserver : null;
|
|
132
|
+
if (MO !== null) {
|
|
133
|
+
// 仅观察 modal.scrim 自身的 data-kit-leaving 属性 + 祖先链 childList,禁用 document.body subtree: true
|
|
134
|
+
attrObs = new MO(check);
|
|
135
|
+
attrObs.observe(modal.scrim, { attributes: true, attributeFilter: [KIT_ATTR_LEAVING] });
|
|
136
|
+
stopDetached = watchKitModalDetached(modal.scrim, doc, check);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
74
140
|
/**
|
|
75
141
|
* 确认窗口的文案派生(工序 4:没有「确认」这个空标题;标题 = 具体问句,正文 = 后果说明,主钮 = 具体动词)。唯一出口,页面不逐个手写:
|
|
76
142
|
* - 调用方给了标题(且不是空泛的「确认」)就用它,正文 = message;
|
|
@@ -105,6 +171,30 @@ export function kitConfirmCopy(message: string, title: string | undefined, at?:
|
|
|
105
171
|
return { title: head, body, verb };
|
|
106
172
|
}
|
|
107
173
|
|
|
174
|
+
/** 把锚点祖先上的宿主 / 亮暗 / 作用域与主题属性镜像到独立挂在 body 的层锚点,避免侵入 opts.at.parentNode 破坏 ButtonGroup / flex 布局 */
|
|
175
|
+
function mirrorAnchorScopeToLayer(at: Element, layer: HTMLElement, doc: Document): void {
|
|
176
|
+
const hostAncestor = at.closest('[data-soma-host]');
|
|
177
|
+
if (hostAncestor !== null) {
|
|
178
|
+
layer.setAttribute('data-soma-host', hostAncestor.getAttribute('data-soma-host') ?? '');
|
|
179
|
+
}
|
|
180
|
+
const schemeAncestor = at.closest('.soma-scheme-dark, .soma-scheme-light');
|
|
181
|
+
if (schemeAncestor !== null && schemeAncestor !== doc.documentElement && schemeAncestor !== doc.body) {
|
|
182
|
+
const dark = schemeAncestor.classList.contains('soma-scheme-dark');
|
|
183
|
+
layer.classList.toggle('soma-scheme-dark', dark);
|
|
184
|
+
layer.classList.toggle('soma-scheme-light', !dark);
|
|
185
|
+
}
|
|
186
|
+
const scopeAncestor = at.closest(`[${KIT_ATTR_SCOPE}]`);
|
|
187
|
+
if (scopeAncestor !== null) {
|
|
188
|
+
layer.setAttribute(KIT_ATTR_SCOPE, scopeAncestor.getAttribute(KIT_ATTR_SCOPE) ?? '');
|
|
189
|
+
}
|
|
190
|
+
for (const attr of OVERLAY_SCOPE_ATTRIBUTES) {
|
|
191
|
+
const ancestor = at.closest(`[${attr}]`);
|
|
192
|
+
if (ancestor !== null) {
|
|
193
|
+
layer.setAttribute(attr, ancestor.getAttribute(attr) ?? '');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
108
198
|
export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
109
199
|
if (opts.signal?.aborted === true) return Promise.resolve(false);
|
|
110
200
|
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom === true);
|
|
@@ -128,30 +218,44 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
128
218
|
onClose: () => finish(opts.alertOnly === true),
|
|
129
219
|
}, doc);
|
|
130
220
|
// 兜底:打开期间宿主区域被卸载(层锚点脱离文档)时按取消收口,调用方的 await 不会永久挂起
|
|
131
|
-
let
|
|
221
|
+
let stopWatch: () => void = () => {};
|
|
132
222
|
const finish = (ok: boolean): void => {
|
|
133
223
|
if (settled) return;
|
|
134
224
|
settled = true;
|
|
135
|
-
|
|
136
|
-
|
|
225
|
+
stopWatch();
|
|
226
|
+
stopWatch = () => {};
|
|
137
227
|
opts.signal?.removeEventListener('abort', onAbort);
|
|
138
|
-
modal
|
|
139
|
-
modal.destroy();
|
|
228
|
+
closeAndDestroyKitModal(modal, doc);
|
|
140
229
|
resolve(ok);
|
|
141
230
|
};
|
|
142
231
|
const onAbort = (): void => finish(false);
|
|
143
232
|
|
|
144
|
-
|
|
233
|
+
// 标题紧字距 + 卡片级密度内边距节奏(p-card),标题与正文/输入区之间保持呼吸感
|
|
234
|
+
const heading = modal.lead.querySelector('h2');
|
|
235
|
+
if (heading !== null) heading.className = mergeClass(heading.className, DIALOG_TITLE_TIGHT);
|
|
236
|
+
modal.lead.className = mergeClass(modal.lead.className, LEAD_GAP_CLASS);
|
|
237
|
+
const leadHeader = modal.lead.parentElement;
|
|
238
|
+
if (leadHeader !== null && leadHeader !== modal.body.parentElement) {
|
|
239
|
+
leadHeader.className = mergeClass(leadHeader.className, LEAD_HEADER_PAD);
|
|
240
|
+
}
|
|
241
|
+
modal.body.className = mergeClass(modal.body.className, LEAD_BODY_PAD);
|
|
242
|
+
|
|
243
|
+
// 正文:一两句 = 一个段落、不缩进;成段说明(多段,或单段够长够多句)走成段正文出口(text-fit#kitProseFit,KT-T-prose)
|
|
244
|
+
const paras = kitProseParagraphs(copy.body);
|
|
245
|
+
const fit = kitProseFit(paras);
|
|
246
|
+
const msg = doc.createElement(paras.length > 1 ? 'div' : 'p');
|
|
145
247
|
msg.className = MESSAGE_CLASS;
|
|
146
|
-
|
|
248
|
+
if (paras.length > 1 || fit.indent) {
|
|
249
|
+
msg.replaceChildren(...paras.map((para) => {
|
|
250
|
+
const el = doc.createElement('p');
|
|
251
|
+
el.className = fit.classOf(para);
|
|
252
|
+
el.setAttribute(KIT_PROSE_ATTR, fit.indent ? 'indent' : 'flat');
|
|
253
|
+
el.textContent = para;
|
|
254
|
+
return el;
|
|
255
|
+
}));
|
|
256
|
+
} else msg.textContent = copy.body;
|
|
147
257
|
msg.id = nextUid('kit-confirm-msg');
|
|
148
258
|
if (copy.body !== '') modal.lead.appendChild(msg);
|
|
149
|
-
// 无障碍:确认框是 alertdialog(要求用户回应),可访问名 = 标题,描述 = 正文;壳由 mountKitModal 画成 dialog,这里改角色
|
|
150
|
-
const panel = modal.body.parentElement;
|
|
151
|
-
if (panel !== null) {
|
|
152
|
-
panel.setAttribute('role', 'alertdialog');
|
|
153
|
-
if (copy.body !== '') panel.setAttribute('aria-describedby', msg.id);
|
|
154
|
-
}
|
|
155
259
|
let impactId = '';
|
|
156
260
|
if (opts.impact !== undefined && opts.impact !== '') {
|
|
157
261
|
const impact = doc.createElement('p');
|
|
@@ -161,6 +265,13 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
161
265
|
impactId = impact.id;
|
|
162
266
|
modal.body.appendChild(impact);
|
|
163
267
|
}
|
|
268
|
+
// 无障碍:确认框是 alertdialog(要求用户回应),可访问名 = 标题,描述 = 正文 + 影响说明;壳由 mountKitModal 画成 dialog,这里改角色
|
|
269
|
+
const panel = modal.body.parentElement;
|
|
270
|
+
if (panel !== null) {
|
|
271
|
+
panel.setAttribute('role', 'alertdialog');
|
|
272
|
+
const descIds = [copy.body !== '' ? msg.id : '', impactId].filter((id) => id !== '');
|
|
273
|
+
if (descIds.length > 0) panel.setAttribute('aria-describedby', descIds.join(' '));
|
|
274
|
+
}
|
|
164
275
|
|
|
165
276
|
const tone = opts.tone ?? 'primary';
|
|
166
277
|
const okLabel = opts.confirmLabel ?? copy.verb;
|
|
@@ -206,6 +317,7 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
206
317
|
} else if (gate?.level === 'consent') {
|
|
207
318
|
// 勾选框用 kit 的 check-core(原生 input 作行为载体:Space 切换、读屏语义);文案是固定词条,影响说明在上面的段落里
|
|
208
319
|
const mark = createCheck(doc, 'checkbox', { checked: false });
|
|
320
|
+
mark.className = mergeClass(mark.className, CONSENT_WRAP_CLASS);
|
|
209
321
|
consentBox = markInput(mark);
|
|
210
322
|
const ack = doc.createElement('span');
|
|
211
323
|
ack.className = MESSAGE_CLASS;
|
|
@@ -229,16 +341,72 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
229
341
|
ok.addEventListener('click', () => finish(true));
|
|
230
342
|
modal.footer.appendChild(ok);
|
|
231
343
|
|
|
232
|
-
//
|
|
233
|
-
|
|
344
|
+
// 层锚点挂入 doc.body(绝不侵入 opts.at.parentNode 破坏 ButtonGroup :last-child 或 flex gap),
|
|
345
|
+
// 并把 opts.at 祖先的 data-soma-host / .soma-scheme-dark / data-kit-scope / 主题属性镜像到层锚点,供浮层端口继承;destroy 时一并移除
|
|
346
|
+
const atConnected = opts.at?.isConnected === true;
|
|
347
|
+
if (atConnected) mirrorAnchorScopeToLayer(opts.at!, modal.layer, doc);
|
|
348
|
+
doc.body.appendChild(modal.layer);
|
|
234
349
|
modal.open();
|
|
235
|
-
|
|
236
|
-
watch = new MutationObserver(() => { if (!modal.layer.isConnected) finish(false); });
|
|
237
|
-
watch.observe(doc.body, { childList: true, subtree: true });
|
|
238
|
-
}
|
|
350
|
+
stopWatch = watchKitModalDetached(modal.layer, doc, () => finish(false), atConnected ? [opts.at] : undefined);
|
|
239
351
|
// 调用方中止(如协调组件卸载):按取消收口,对话框随之关闭
|
|
240
352
|
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
241
|
-
//
|
|
242
|
-
(input ?? (
|
|
353
|
+
// 焦点(F-1 & 文件头契约):键入式 → 输入框;danger 确认 → 取消钮(误按回车不会执行危险操作);普通确认 / alertOnly → 确定钮
|
|
354
|
+
(input ?? (tone === 'danger' ? cancel : ok) ?? ok).focus();
|
|
243
355
|
});
|
|
244
356
|
}
|
|
357
|
+
|
|
358
|
+
// ── 基础组件二次确认端口的注册(base/kit-contract#setKitConfirmAsk) ─────────────────
|
|
359
|
+
//
|
|
360
|
+
// 基础组件(Button 等)拿到页面线判定的确认方式(kit.confirm)时经端口发起确认;端口的实现在这里注册,
|
|
361
|
+
// 本模块经 data/resident(浏览器面)与 data/index(全量入口)的加载链必然执行,所以在模块加载时注册一次。
|
|
362
|
+
// - dialog → 确认窗口(askKitConfirm);
|
|
363
|
+
// - popconfirm → 行内气泡确认(base/popover 的 kitAskInlineConfirm:贴着被点的按钮、与 Popconfirm 同一外观);
|
|
364
|
+
// 锚点已不在文档里(按钮刚被卸载)时气泡无处可贴,退到确认窗口——判定为要确认的动作不能因此被放行。
|
|
365
|
+
// - 文案:标题 / 正文 / 主钮由 kitConfirmCopy 从动作的可见文字(req.label)派生(命中 soma.kit.confirm_prefixes 去前缀、
|
|
366
|
+
// soma.kit.confirm_verbs 取具体动词);可见文字为空时用 soma.kit.confirm;取消钮 soma.kit.cancel。不另立文案键。
|
|
367
|
+
// - tone = danger 透传(确认钮危险色、焦点落取消钮、点遮罩不关);signal 透传(调用方卸载时按取消收口)。
|
|
368
|
+
|
|
369
|
+
/** 端口实现:按确认方式分派(见上) */
|
|
370
|
+
export function kitConfirmAskImpl(req: KitConfirmRequest): Promise<boolean> {
|
|
371
|
+
const label = req.label.trim();
|
|
372
|
+
const message = label !== '' ? label : kitText('soma.kit.confirm', undefined, req.at);
|
|
373
|
+
if (req.kind === 'popconfirm' && req.at.isConnected) {
|
|
374
|
+
const copy = kitConfirmCopy(message, undefined, req.at);
|
|
375
|
+
return kitAskInlineConfirm({
|
|
376
|
+
at: req.at,
|
|
377
|
+
title: copy.title,
|
|
378
|
+
body: copy.body,
|
|
379
|
+
okText: copy.verb,
|
|
380
|
+
cancelText: kitText('soma.kit.cancel', undefined, req.at),
|
|
381
|
+
...(req.tone === 'danger' ? { tone: 'danger' as const } : {}),
|
|
382
|
+
...(req.signal !== undefined ? { signal: req.signal } : {}),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return askKitConfirm({
|
|
386
|
+
message,
|
|
387
|
+
at: req.at,
|
|
388
|
+
...(req.tone === 'danger' ? { tone: 'danger' as const } : {}),
|
|
389
|
+
...(req.signal !== undefined ? { signal: req.signal } : {}),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
let undoInstall: (() => void) | null = null;
|
|
394
|
+
const NOOP = (): void => {};
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* 把确认实现注册到基础组件的确认端口。幂等:本层已注册且仍在位时直接返回同一个撤销函数,不重复注册;
|
|
398
|
+
* 应用先行注册了自己的实现时不覆盖(返回空撤销函数);端口被清掉(setKitConfirmAsk(null))后再调用会重新注册。
|
|
399
|
+
* 返回撤销函数:只撤销本层这一次注册(端口已被别处换掉时不动)。
|
|
400
|
+
*/
|
|
401
|
+
export function installKitConfirmAsk(): () => void {
|
|
402
|
+
if (hasKitConfirmAsk()) return undoInstall ?? NOOP;
|
|
403
|
+
const undo = setKitConfirmAsk(kitConfirmAskImpl);
|
|
404
|
+
const mine = (): void => {
|
|
405
|
+
undo();
|
|
406
|
+
if (undoInstall === mine) undoInstall = null;
|
|
407
|
+
};
|
|
408
|
+
undoInstall = mine;
|
|
409
|
+
return mine;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
installKitConfirmAsk();
|