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,136 @@
|
|
|
1
|
+
// SummaryStrip:摘要条(layer: data,写死形状,accept: single)。一个对象的关键事实排成一行:「标签 值」成对紧排,可带状态、可带分隔线。
|
|
2
|
+
//
|
|
3
|
+
// 数据:`data` 是一个对象;展示哪几项由 `fields` 给 [{ key, label, format?, tone?, tone_key?, status? }],值取 data[key],format 取 soma-foundation/values 写法。
|
|
4
|
+
// status: true(或写了 tone / tone_key)的项画成状态标签(淡底 + 圆点 + 文字,与详情头、记录卡同一壳);其余是「弱化标签 + 正文值」。值缺失画「—」弱化占位。
|
|
5
|
+
// 排布:flex-wrap 横排,项间距 24(横)/ 8(竖);divider 为真时第二项起带左分隔线(border-s + ps)。
|
|
6
|
+
// 结构抄 Ant Descriptions 横排(layout: horizontal)与 Primer PageHeader.Description;语义是 dl / dt / dd。
|
|
7
|
+
|
|
8
|
+
import { kitApplyLevelClass } from './level-class';
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
|
+
import { kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
|
|
11
|
+
import { createKitController, formatValue, joinClass, str, type KitProps } from '../base/shared';
|
|
12
|
+
import {
|
|
13
|
+
KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
14
|
+
kitMatchSemanticStatusTone,
|
|
15
|
+
kitReadHostAutoSequence,
|
|
16
|
+
kitResolveStatusOrCategoryTone,
|
|
17
|
+
kitToneDotClass,
|
|
18
|
+
kitToneSoftBadgeClass,
|
|
19
|
+
type KitSemanticOrCategoryTone,
|
|
20
|
+
} from '../recipes/color-role';
|
|
21
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
22
|
+
import { kitFieldNameRecipe } from '../recipes/field-text';
|
|
23
|
+
import { KIT_STATUS_BADGE_CLASS, KIT_STATUS_DOT_CLASS } from '../recipes/status';
|
|
24
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
25
|
+
import { mergeClass } from '../shared/merge-class';
|
|
26
|
+
import { classTokens, emptyNode, mk, recOf, rowsOf, shapeToneOf, textOf } from './shape-util';
|
|
27
|
+
|
|
28
|
+
const ROOT_CLASS = mergeClass('m-0 flex w-full min-w-0 flex-wrap items-center gap-x-6 gap-y-2', kitTypographyRecipe('text'));
|
|
29
|
+
const ITEM_CLASS = 'flex min-w-0 items-baseline gap-1.5';
|
|
30
|
+
const ITEM_DIVIDED_CLASS = mergeClass('flex min-w-0 items-baseline gap-1.5 ps-6', kitDividerRecipe('start'));
|
|
31
|
+
// 项的键 = 字段名:唯一出口(弱化墨 / 正文字号 / 500 / 无底)
|
|
32
|
+
const LABEL_CLASS = mergeClass('shrink-0', kitFieldNameRecipe());
|
|
33
|
+
const VALUE_CLASS = 'm-0 min-w-0 break-words tabular-nums text-fg';
|
|
34
|
+
const MISSING_CLASS = 'm-0 text-fg-subtle';
|
|
35
|
+
const BADGE_ITEM_CLASS = 'm-0 flex items-center';
|
|
36
|
+
|
|
37
|
+
export const KIT_SUMMARY_STRIP_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
38
|
+
ROOT_CLASS, ITEM_CLASS, ITEM_DIVIDED_CLASS, LABEL_CLASS, VALUE_CLASS, MISSING_CLASS, BADGE_ITEM_CLASS,
|
|
39
|
+
KIT_STATUS_BADGE_CLASS, KIT_STATUS_DOT_CLASS, KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export interface KitSummaryItem { label: string; text: string; status: boolean; tone: KitSemanticOrCategoryTone }
|
|
43
|
+
|
|
44
|
+
const EXPLICIT_SUMMARY_TONES: ReadonlySet<string> = new Set<KitSemanticOrCategoryTone>([
|
|
45
|
+
'primary', 'info', 'success', 'warning', 'danger', 'neutral', 'tertiary', 'second',
|
|
46
|
+
'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/** 源数据 + 字段表 -> 项(纯函数):缺 key 或 label 的字段丢弃;tone_key 取数据里的语气值,优先于字面 tone */
|
|
50
|
+
export function summaryItemsOf(data: unknown, fields: unknown, locale: string, host?: Element | null): KitSummaryItem[] {
|
|
51
|
+
const rec = recOf(data);
|
|
52
|
+
const autoSeq = host !== undefined ? kitReadHostAutoSequence(host) : undefined;
|
|
53
|
+
const out: KitSummaryItem[] = [];
|
|
54
|
+
for (const f of rowsOf(fields)) {
|
|
55
|
+
const key = textOf(f.key);
|
|
56
|
+
const label = textOf(f.label);
|
|
57
|
+
if (key === '' || label === '') continue;
|
|
58
|
+
const raw = rec[key];
|
|
59
|
+
const missing = raw === null || raw === undefined || raw === '';
|
|
60
|
+
const format = textOf(f.format);
|
|
61
|
+
const displayText = missing ? '' : format !== '' ? formatValue(raw, format, locale) : textOf(raw);
|
|
62
|
+
const toneKey = textOf(f.tone_key);
|
|
63
|
+
const toneRaw = toneKey !== '' ? rec[toneKey] : f.tone;
|
|
64
|
+
const explicitStr = textOf(toneRaw).trim();
|
|
65
|
+
const explicitLower = explicitStr.toLowerCase();
|
|
66
|
+
const status = f.status === true || f.tone !== undefined || toneKey !== '';
|
|
67
|
+
let tone: KitSemanticOrCategoryTone;
|
|
68
|
+
if (EXPLICIT_SUMMARY_TONES.has(explicitLower)) {
|
|
69
|
+
tone = explicitLower as KitSemanticOrCategoryTone;
|
|
70
|
+
} else if (f.status === true || toneKey !== '') {
|
|
71
|
+
tone = kitMatchSemanticStatusTone(explicitStr)
|
|
72
|
+
?? kitResolveStatusOrCategoryTone(displayText || explicitStr, undefined, {
|
|
73
|
+
explicitTone: explicitStr,
|
|
74
|
+
preferHash: true,
|
|
75
|
+
...(autoSeq !== undefined ? { autoSequence: autoSeq } : host !== undefined ? { host } : {}),
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
tone = shapeToneOf(toneRaw, 'neutral');
|
|
79
|
+
}
|
|
80
|
+
out.push({ label, text: displayText, status, tone });
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function createSummaryStrip(): SomaComponentDefinition {
|
|
86
|
+
return {
|
|
87
|
+
contract: {
|
|
88
|
+
name: 'SummaryStrip',
|
|
89
|
+
layer: 'data',
|
|
90
|
+
props: {
|
|
91
|
+
data: { type: 'object', default: {}, desc: '一个对象(如详情接口返回);fields 按 key 取值' },
|
|
92
|
+
fields: { type: 'array', default: [], desc: '关键事实 [{ key, label, format?, status?, tone?, tone_key? }];status / tone / tone_key 的项画成状态标签(语气取 tone 或数据里 tone_key 的值)' },
|
|
93
|
+
divider: { type: 'boolean', default: false, desc: '第二项起带左分隔线' },
|
|
94
|
+
label: { type: 'string', default: '', desc: '无障碍名称' },
|
|
95
|
+
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
96
|
+
empty_text: { type: 'string', default: '—', desc: '没有字段时的文案' },
|
|
97
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
98
|
+
},
|
|
99
|
+
emits: {},
|
|
100
|
+
},
|
|
101
|
+
templateHtml: `<dl data-soma-id="root" class="${ROOT_CLASS}"></dl>`,
|
|
102
|
+
controllerFactory: createKitController((_api) => ({
|
|
103
|
+
render(root: HTMLElement, p: KitProps): void {
|
|
104
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
105
|
+
root.textContent = '';
|
|
106
|
+
const label = str(p.label);
|
|
107
|
+
if (label === '') root.removeAttribute('aria-label');
|
|
108
|
+
else root.setAttribute('aria-label', label);
|
|
109
|
+
const items = summaryItemsOf(p.data, p.fields, str(p.locale, 'zh-CN'), root);
|
|
110
|
+
// 数据状态自报:本组件没有加载 / 出错入参,只有空与常态
|
|
111
|
+
kitMarkDataFacts(root, { empty: items.length === 0 });
|
|
112
|
+
if (items.length === 0) { root.appendChild(emptyNode(str(p.empty_text, '—'))); return; }
|
|
113
|
+
const divided = p.divider === true || p.divider === 'true';
|
|
114
|
+
items.forEach((it, i) => {
|
|
115
|
+
const wrap = mk('div', divided && i > 0 ? ITEM_DIVIDED_CLASS : ITEM_CLASS);
|
|
116
|
+
// 键值概况的每一项是一个描述项(条目):键 = 字段名,值 = 值 / 状态
|
|
117
|
+
kitMarkLevel(wrap, 'item'); kitApplyLevelClass(wrap);
|
|
118
|
+
const dt = mk('dt', LABEL_CLASS, it.label);
|
|
119
|
+
kitMarkPart(dt, 'field-name');
|
|
120
|
+
wrap.appendChild(dt);
|
|
121
|
+
if (it.text === '') { const dd = mk('dd', MISSING_CLASS, '—'); kitMarkPart(dd, 'value'); wrap.appendChild(dd); }
|
|
122
|
+
else if (it.status) {
|
|
123
|
+
const dd = mk('dd', BADGE_ITEM_CLASS);
|
|
124
|
+
const badge = mk('span', `${KIT_STATUS_BADGE_CLASS} ${kitToneSoftBadgeClass(it.tone)}`);
|
|
125
|
+
badge.appendChild(mk('span', `${KIT_STATUS_DOT_CLASS} ${kitToneDotClass(it.tone, { solid: true })}`));
|
|
126
|
+
badge.appendChild(mk('span', '', it.text));
|
|
127
|
+
kitMarkPart(badge, 'status');
|
|
128
|
+
dd.appendChild(badge);
|
|
129
|
+
wrap.appendChild(dd);
|
|
130
|
+
} else { const dd = mk('dd', VALUE_CLASS, it.text); kitMarkPart(dd, 'value'); wrap.appendChild(dd); }
|
|
131
|
+
root.appendChild(wrap);
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// 汇总与比较类数据组件(SegmentBar / TargetProgress / CompareView / TileGrid / StatusStrip / Waterfall)共用小件。
|
|
2
|
+
//
|
|
3
|
+
// - 系列色:--soma-chart-1…8(经 theme 头的 --color-chart-N),类串写死成表,不拼接类名片段;
|
|
4
|
+
// - 语气(success / warning / danger / info / primary / neutral)与系列色二选一:声明了语气走语义色,没声明按序取系列色;
|
|
5
|
+
// - SVG 小工具:宽度 / 位置一律写成 SVG 百分比属性,不用内联样式;
|
|
6
|
+
// - 限值读 design kit-limits#dataLimits.summaryShapes(经 foundation),代码里不写数字。
|
|
7
|
+
// 抄自 Tremor(Apache-2.0)CategoryBar / ProgressBar / Tracker 的结构:轨道 + 分段 + 图例,圆点 + 名 + 值。
|
|
8
|
+
|
|
9
|
+
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
10
|
+
import { num } from '../base/shared';
|
|
11
|
+
import { kitMatchSemanticStatusTone } from '../recipes/color-role';
|
|
12
|
+
import { type ShapeTone, shapeToneOf } from './shape-util';
|
|
13
|
+
|
|
14
|
+
type Json = Record<string, any>;
|
|
15
|
+
const L = (KIT_DATA_LIMITS as unknown as Json).summaryShapes as Json;
|
|
16
|
+
|
|
17
|
+
export const SEGMENT_MAX: number = L.segmentBar.maxSegments;
|
|
18
|
+
export const SEGMENT_GAP_PCT: number = L.segmentBar.gapPct;
|
|
19
|
+
export const STRIP_MAX_CELLS: number = L.statusStrip.maxCells;
|
|
20
|
+
export const TILE_MAX: number = L.tileGrid.maxTiles;
|
|
21
|
+
export const COMPARE_MAX_COLUMNS: number = L.compareView.maxColumns;
|
|
22
|
+
export const COMPARE_MAX_ROWS: number = L.compareView.maxRows;
|
|
23
|
+
export const WATERFALL_MAX_STEPS: number = L.waterfall.maxSteps;
|
|
24
|
+
export const WATERFALL_BAR_RATIO_PCT: number = L.waterfall.barRatioPct;
|
|
25
|
+
export const WATERFALL_PLOT_HEIGHT: number = L.waterfall.plotHeight;
|
|
26
|
+
export const WATERFALL_PLOT_WIDTH: number = L.waterfall.plotWidth;
|
|
27
|
+
|
|
28
|
+
export const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
29
|
+
|
|
30
|
+
const SERIES_IDS = ['chart-1', 'chart-2', 'chart-3', 'chart-4', 'chart-5', 'chart-6', 'chart-7', 'chart-8'] as const;
|
|
31
|
+
/** 系列色(块 / 圆点底色、SVG 填充):按序循环 */
|
|
32
|
+
export const SERIES_BG: readonly string[] = Object.freeze(SERIES_IDS.map((s) => `bg-${s}`));
|
|
33
|
+
export const SERIES_FILL: readonly string[] = Object.freeze(SERIES_IDS.map((s) => `fill-${s}`));
|
|
34
|
+
|
|
35
|
+
const TONE_FILL: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
36
|
+
neutral: 'fill-fg-subtle', primary: 'fill-primary', info: 'fill-info', success: 'fill-success', warning: 'fill-warning', danger: 'fill-danger',
|
|
37
|
+
});
|
|
38
|
+
export const TONE_BG: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
39
|
+
neutral: 'bg-fg-subtle', primary: 'bg-primary', info: 'bg-info', success: 'bg-success', warning: 'bg-warning', danger: 'bg-danger',
|
|
40
|
+
});
|
|
41
|
+
/** 语气的浅一档填充(预测段、缓冲段:同色淡一档,抄 KitProgress 缓冲 opacity-30) */
|
|
42
|
+
const TONE_FILL_SOFT: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
43
|
+
neutral: 'fill-fg-subtle opacity-30', primary: 'fill-primary opacity-30', info: 'fill-info opacity-30',
|
|
44
|
+
success: 'fill-success opacity-30', warning: 'fill-warning opacity-30', danger: 'fill-danger opacity-30',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const SUMMARY_COLOR_CLASSES: readonly string[] = Object.freeze([
|
|
48
|
+
...SERIES_BG, ...SERIES_FILL, ...Object.values(TONE_FILL), ...Object.values(TONE_BG), ...Object.values(TONE_FILL_SOFT),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
/** 汇总与图表读数的统一空值占位 */
|
|
52
|
+
export const SUMMARY_EMPTY_TEXT = '—';
|
|
53
|
+
|
|
54
|
+
/** 消除 IEEE-754 双精度浮点运算尾差(如 0.1 + 0.2 -> 0.3、-0 -> 0) */
|
|
55
|
+
export function cleanSummaryFloat(v: number): number {
|
|
56
|
+
if (!Number.isFinite(v)) return 0;
|
|
57
|
+
const cleaned = Number(v.toPrecision(15));
|
|
58
|
+
return Object.is(cleaned, -0) ? 0 : cleaned;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function roundTwoDecimals(v: number): number {
|
|
62
|
+
const cleaned = cleanSummaryFloat(v);
|
|
63
|
+
const shifted = Math.round((cleaned + Math.sign(cleaned) * Number.EPSILON) * 100) / 100;
|
|
64
|
+
const normalized = Number(shifted.toFixed(2));
|
|
65
|
+
return Object.is(normalized, -0) ? 0 : normalized;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface Swatch { bg: string; fill: string }
|
|
69
|
+
|
|
70
|
+
/** 色:声明了合法语气用语义色;未传 tone 且 label 命中四档状态词时取对应语义色;否则按下标取系列色(循环) */
|
|
71
|
+
export function swatchOf(rawTone: unknown, index: number, label?: string): Swatch {
|
|
72
|
+
const tone = typeof rawTone === 'string' ? rawTone.trim() : '';
|
|
73
|
+
if (tone === 'neutral' || tone === 'primary' || tone === 'info' || tone === 'success' || tone === 'warning' || tone === 'danger') {
|
|
74
|
+
const t = shapeToneOf(tone);
|
|
75
|
+
return { bg: TONE_BG[t], fill: TONE_FILL[t] };
|
|
76
|
+
}
|
|
77
|
+
if (tone === '' && typeof label === 'string' && label.trim() !== '') {
|
|
78
|
+
const matched = kitMatchSemanticStatusTone(label);
|
|
79
|
+
if (matched === 'success' || matched === 'info' || matched === 'warning' || matched === 'danger') {
|
|
80
|
+
return { bg: TONE_BG[matched], fill: TONE_FILL[matched] };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const safeIdx = Number.isFinite(index) ? Math.trunc(index) : 0;
|
|
84
|
+
const i = ((safeIdx % SERIES_IDS.length) + SERIES_IDS.length) % SERIES_IDS.length;
|
|
85
|
+
return { bg: SERIES_BG[i]!, fill: SERIES_FILL[i]! };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function toneFill(tone: ShapeTone): string { return TONE_FILL[tone]; }
|
|
89
|
+
export function toneFillSoft(tone: ShapeTone): string { return TONE_FILL_SOFT[tone]; }
|
|
90
|
+
|
|
91
|
+
/** 取非负数(缺失 / 非数 / 负数 -> 0,消除浮点尾差) */
|
|
92
|
+
export function nonNeg(raw: unknown): number {
|
|
93
|
+
const n = num(raw);
|
|
94
|
+
return n === null || !Number.isFinite(n) || n <= 0 ? 0 : cleanSummaryFloat(n);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 百分数保留两位小数(SVG 属性用,非有限数安全归零,零浮点尾差) */
|
|
98
|
+
export function pctText(v: number): string {
|
|
99
|
+
if (typeof v !== 'number' || !Number.isFinite(v)) return '0%';
|
|
100
|
+
return `${roundTwoDecimals(v)}%`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 建 SVG 元素并一次设属性(忽略空属性,防写入 undefined/null) */
|
|
104
|
+
export function svgEl<K extends keyof SVGElementTagNameMap>(tag: K, attrs: Readonly<Record<string, string>>): SVGElementTagNameMap[K] {
|
|
105
|
+
const el = document.createElementNS(SVG_NS, tag);
|
|
106
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
107
|
+
if (v !== undefined && v !== null) el.setAttribute(k, String(v));
|
|
108
|
+
}
|
|
109
|
+
return el;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 数值格式化:空值 / NaN / Infinity 统一返回 '—',有限数保留至多两位小数且零浮点尾差 */
|
|
113
|
+
export function plainNumber(n: number | null | undefined): string {
|
|
114
|
+
if (n === null || n === undefined || typeof n !== 'number' || !Number.isFinite(n)) return SUMMARY_EMPTY_TEXT;
|
|
115
|
+
return String(roundTwoDecimals(n));
|
|
116
|
+
}
|
package/src/data/survey.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// 这道题显示结果:每项 票数 · 占比 + progress 条,我的选择带标记;提交时乐观计入我的选择,数据再次下行(内容变)即以数据为准。
|
|
13
13
|
// 所有题都进入结果视图后不再出提交钮。投票用法的写法:一道 single 题,`submit_text: 投票`,`show_progress: false`,`peekable: true`,页面接 `submit`。
|
|
14
14
|
|
|
15
|
+
import { kitApplyLevelClass } from './level-class';
|
|
15
16
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
17
|
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
17
18
|
import { createCheck, markInput } from '../base/check-core';
|
|
@@ -19,11 +20,18 @@ import { kitText } from '../i18n/kit-text';
|
|
|
19
20
|
import { setKitFace } from '../recipes';
|
|
20
21
|
import { kitButtonEdgeRecipe, kitControlRecipe } from '../recipes/control';
|
|
21
22
|
import { kitShellRecipe } from '../recipes/container';
|
|
23
|
+
import { kitSelectedVariantRecipe } from '../recipes/state';
|
|
24
|
+
import { kitClosedValueRecipe } from '../recipes/field-text';
|
|
22
25
|
import { mergeClass } from '../shared/merge-class';
|
|
26
|
+
import {
|
|
27
|
+
KIT_ATTR_ACTION, KIT_ATTR_ERROR, KIT_ATTR_OPT, KIT_ATTR_PEEK, KIT_ATTR_PROGRESS, KIT_ATTR_PROGRESS_TEXT, KIT_ATTR_QUESTION, KIT_ATTR_RATE,
|
|
28
|
+
KIT_ATTR_READONLY, KIT_ATTR_RESULT, KIT_ATTR_RESULTS, KIT_ATTR_SUBMIT, KIT_ATTR_SURVEY_TEXT, kitAttrSel,
|
|
29
|
+
} from '../shared/dom-attrs';
|
|
23
30
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
24
31
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, mkProgressBar, PROGRESS_BAR_CLASS_TOKENS, recOf, setProgressBar, rowsOf, textOf } from './shape-util';
|
|
25
32
|
import { rowKey } from './d9-util';
|
|
26
33
|
import { markKitEdge } from '../recipes/surface-edge';
|
|
34
|
+
import { kitHasProps, kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
|
|
27
35
|
import { kitTypographyRecipe } from '../recipes/typography';
|
|
28
36
|
import { QUESTION_KINDS, QUESTION_MAX, QUESTION_MAX_OPTIONS, QUESTION_RATING_MAX, pickOf } from './d9-limits';
|
|
29
37
|
|
|
@@ -32,30 +40,39 @@ import { QUESTION_KINDS, QUESTION_MAX, QUESTION_MAX_OPTIONS, QUESTION_RATING_MAX
|
|
|
32
40
|
// 问卷外缘 = 壳配方(容器边,KT-B2);作答框 = 多行控件配方;评分钮 = 带文字中性按钮描边(KT-B1)
|
|
33
41
|
const ROOT_EDGE = kitShellRecipe({ tone: 'base', shadow: false });
|
|
34
42
|
const RATING_EDGE = kitButtonEdgeRecipe();
|
|
35
|
-
const ROOT_CLASS =
|
|
43
|
+
const ROOT_CLASS = mergeClass('flex flex-col gap-5 p-5 text-sm text-fg', ROOT_EDGE);
|
|
36
44
|
const TITLE_CLASS = kitTypographyRecipe('sectionTitle');
|
|
37
45
|
const DESC_CLASS = 'text-fg-muted';
|
|
38
46
|
const PROGRESS_ROW = 'flex items-center gap-3 text-xs text-fg-muted';
|
|
39
47
|
const PROGRESS_CLASS = 'block flex-1';
|
|
40
48
|
const QUESTION_CLASS = 'flex min-w-0 flex-col gap-2 border-0 p-0';
|
|
41
49
|
const LEGEND_CLASS = 'mb-1 font-medium text-fg';
|
|
50
|
+
const QUESTION_NO_CLASS = 'me-1.5 font-mono tabular-nums text-fg-muted';
|
|
42
51
|
const REQUIRED_CLASS = 'ms-1 text-danger-on-soft';
|
|
43
52
|
const OPTION_CLASS = 'w-full px-2 py-1.5 hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
44
|
-
const
|
|
53
|
+
const OPTION_RO_CLASS = 'w-full cursor-default px-2 py-1.5';
|
|
54
|
+
const AREA_CLASS = mergeClass(kitControlRecipe({ multiline: true }), 'resize-none aria-invalid:border-danger');
|
|
45
55
|
const RATING_ROW = 'flex flex-wrap gap-1';
|
|
46
56
|
const RATING_BOX = 'relative';
|
|
47
57
|
const RATING_INPUT = 'peer sr-only';
|
|
48
|
-
const RATING_LABEL =
|
|
58
|
+
const RATING_LABEL = mergeClass(
|
|
59
|
+
mergeClass(
|
|
60
|
+
'inline-flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-control bg-surface px-2 text-sm text-fg transition-colors state-layer peer-checked:border-primary peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-disabled:cursor-not-allowed peer-disabled:bg-control-disabled peer-disabled:text-fg-disabled peer-aria-invalid:border-danger',
|
|
61
|
+
RATING_EDGE,
|
|
62
|
+
),
|
|
63
|
+
kitSelectedVariantRecipe('peer-checked'),
|
|
64
|
+
);
|
|
49
65
|
const ERROR_CLASS = 'text-xs text-danger-on-soft';
|
|
50
66
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
51
|
-
const RESULT_ROW = 'flex flex-col gap-1 rounded-
|
|
67
|
+
const RESULT_ROW = 'flex flex-col gap-1 rounded-item px-2 py-1.5';
|
|
52
68
|
const RESULT_HEAD = 'flex items-center justify-between gap-2';
|
|
53
|
-
const RESULT_MINE = '
|
|
69
|
+
const RESULT_MINE = mergeClass(kitClosedValueRecipe('primary'), 'ms-2');
|
|
54
70
|
const RESULT_NUM = 'text-xs text-fg-muted';
|
|
55
71
|
|
|
56
72
|
export const KIT_SURVEY_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
57
|
-
ROOT_CLASS, TITLE_CLASS, DESC_CLASS, PROGRESS_ROW, PROGRESS_CLASS, QUESTION_CLASS, LEGEND_CLASS,
|
|
58
|
-
RATING_ROW, RATING_BOX, RATING_INPUT, RATING_LABEL, ERROR_CLASS, FOOT_CLASS,
|
|
73
|
+
ROOT_CLASS, TITLE_CLASS, DESC_CLASS, PROGRESS_ROW, PROGRESS_CLASS, QUESTION_CLASS, LEGEND_CLASS, QUESTION_NO_CLASS, REQUIRED_CLASS,
|
|
74
|
+
OPTION_CLASS, OPTION_RO_CLASS, AREA_CLASS, RATING_ROW, RATING_BOX, RATING_INPUT, RATING_LABEL, ERROR_CLASS, FOOT_CLASS,
|
|
75
|
+
RESULT_ROW, RESULT_HEAD, RESULT_MINE, RESULT_NUM, BUTTON_CLASS_TOKENS, 'hidden', PROGRESS_BAR_CLASS_TOKENS,
|
|
59
76
|
);
|
|
60
77
|
|
|
61
78
|
// ───────── 数据规整纯函数:题目、结果判定、占比、已答校验、答案过滤 ─────────
|
|
@@ -200,23 +217,47 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
200
217
|
let sig = '';
|
|
201
218
|
let lastValue = '\u0000';
|
|
202
219
|
let lastPaintKey = '';
|
|
220
|
+
const emittedValues = new Set<string>();
|
|
221
|
+
const canonValue = (raw: unknown): string => {
|
|
222
|
+
const r = recOf(raw);
|
|
223
|
+
const sorted: Record<string, unknown> = {};
|
|
224
|
+
for (const k of Object.keys(r).sort()) sorted[k] = r[k];
|
|
225
|
+
return JSON.stringify(sorted);
|
|
226
|
+
};
|
|
227
|
+
const makePaintKey = (p: Record<string, unknown>, valSig: string): string => JSON.stringify([
|
|
228
|
+
p.data, valSig, p.readonly, p.show_progress, p.peekable, p.results_after_submit,
|
|
229
|
+
p.submit_text, p.peek_text, p.back_text, p.mine_text, p.total_text, p.closed_text,
|
|
230
|
+
p.progress_text, p.required_text, p.empty_text, p.class, peek, [...submitted.keys()],
|
|
231
|
+
]);
|
|
203
232
|
const kb = createKitBusy(P);
|
|
204
233
|
let uid = 0;
|
|
205
234
|
const inst = ++surveyInstances;
|
|
206
235
|
|
|
207
|
-
const questions =(): KitQuestion[] => questionsOf(P().data);
|
|
236
|
+
const questions = (): KitQuestion[] => questionsOf(P().data);
|
|
208
237
|
const status = (): ReturnType<typeof surveyStatus> => surveyStatus(questions(), answers);
|
|
209
238
|
const inResults = (q: KitQuestion): boolean => hasResults(q) && (q.closed || q.voted.length > 0 || submitted.has(q.id) || peek);
|
|
210
239
|
|
|
211
240
|
const refreshMeta = (): void => {
|
|
212
241
|
if (!root) return;
|
|
213
242
|
const st = status();
|
|
214
|
-
const bar = root.querySelector<HTMLElement>(
|
|
215
|
-
const txt = root.querySelector<HTMLElement>(
|
|
243
|
+
const bar = root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_PROGRESS));
|
|
244
|
+
const txt = root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_PROGRESS_TEXT));
|
|
216
245
|
if (bar) setProgressBar(bar, st.answered, st.total);
|
|
217
246
|
if (txt) txt.textContent = str(P().progress_text, kitText('soma.kit.sv_progress', undefined, root)).replace('{a}', String(st.answered)).replace('{t}', String(st.total));
|
|
218
|
-
root.querySelectorAll<HTMLElement>(
|
|
219
|
-
|
|
247
|
+
root.querySelectorAll<HTMLElement>(kitAttrSel(KIT_ATTR_ERROR)).forEach((errEl) => {
|
|
248
|
+
const qid = errEl.getAttribute(KIT_ATTR_ERROR) ?? '';
|
|
249
|
+
const bad = showErrors && st.missing.includes(qid);
|
|
250
|
+
errEl.classList.toggle('hidden', !bad);
|
|
251
|
+
const qSet = errEl.closest<HTMLElement>(kitAttrSel(KIT_ATTR_QUESTION));
|
|
252
|
+
qSet?.querySelectorAll<HTMLElement>('input, textarea').forEach((ctl) => {
|
|
253
|
+
if (bad) {
|
|
254
|
+
ctl.setAttribute('aria-invalid', 'true');
|
|
255
|
+
if (errEl.id !== '') ctl.setAttribute('aria-describedby', errEl.id);
|
|
256
|
+
} else {
|
|
257
|
+
ctl.removeAttribute('aria-invalid');
|
|
258
|
+
if (ctl.getAttribute('aria-describedby') === errEl.id) ctl.removeAttribute('aria-describedby');
|
|
259
|
+
}
|
|
260
|
+
});
|
|
220
261
|
});
|
|
221
262
|
};
|
|
222
263
|
|
|
@@ -225,19 +266,28 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
225
266
|
if (value === undefined || !isAnswered(questions().find((q) => q.id === id) ?? { kind: 'text' }, value)) delete answers[id]; else answers[id] = value;
|
|
226
267
|
refreshMeta();
|
|
227
268
|
const st = status();
|
|
228
|
-
|
|
269
|
+
const outValue = { ...answers };
|
|
270
|
+
const emittedSig = canonValue(outValue);
|
|
271
|
+
lastValue = emittedSig;
|
|
272
|
+
if (emittedValues.size >= 50) {
|
|
273
|
+
const first = emittedValues.values().next().value;
|
|
274
|
+
if (first !== undefined) emittedValues.delete(first);
|
|
275
|
+
}
|
|
276
|
+
emittedValues.add(emittedSig);
|
|
277
|
+
lastPaintKey = makePaintKey(P(), emittedSig);
|
|
278
|
+
api.emit('change', { value: outValue, answered: st.answered, total: st.total, valid: st.missing.length === 0 });
|
|
229
279
|
};
|
|
230
280
|
|
|
231
281
|
const resultNode = (q: KitQuestion, p: Record<string, unknown>): HTMLElement => {
|
|
232
282
|
const box = mk('div', 'flex flex-col gap-1');
|
|
233
|
-
box.setAttribute(
|
|
283
|
+
box.setAttribute(KIT_ATTR_RESULTS, q.id);
|
|
234
284
|
const mineSet = new Set<string>([...q.voted, ...(submitted.get(q.id) ?? [])]);
|
|
235
285
|
const bump = new Set(submitted.get(q.id) ?? []);
|
|
236
286
|
const votes = q.options.map((o) => (o.votes ?? 0) + (bump.has(o.value) && !q.voted.includes(o.value) ? 1 : 0));
|
|
237
287
|
const total = votes.reduce((s, v) => s + v, 0);
|
|
238
288
|
q.options.forEach((o, i) => {
|
|
239
289
|
const row = mk('div', RESULT_ROW);
|
|
240
|
-
row.setAttribute(
|
|
290
|
+
row.setAttribute(KIT_ATTR_RESULT, o.value);
|
|
241
291
|
const head = mk('div', RESULT_HEAD);
|
|
242
292
|
const name = mk('span', '', o.label);
|
|
243
293
|
if (mineSet.has(o.value)) name.appendChild(mk('span', RESULT_MINE, str(p.mine_text, kitText('soma.kit.sv_mine', undefined, root))));
|
|
@@ -256,14 +306,24 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
256
306
|
function paint(): void {
|
|
257
307
|
if (!root) return;
|
|
258
308
|
const p = P();
|
|
259
|
-
// 同样的 props 再下行(页面把 change 回写再下发的常见情形)不重画,保住输入焦点与光标
|
|
260
|
-
const paintKey = JSON.stringify([p.data, p.value, p.readonly, p.show_progress, p.peekable, p.results_after_submit, p.submit_text, p.peek_text, p.back_text, p.mine_text, p.total_text, p.closed_text, p.progress_text, p.required_text, p.empty_text, p.class, peek, [...submitted.keys()]]);
|
|
261
|
-
if (paintKey === lastPaintKey && root.childElementCount > 0) { paintBusy(); return; }
|
|
262
|
-
lastPaintKey = paintKey;
|
|
263
309
|
const qs = questions();
|
|
310
|
+
const given = canonValue(answersFrom(p.value, qs));
|
|
311
|
+
// 同样的 props 再下行(页面把 change 回写再下发的受控情形,含滞后快照回声)不重画,保住输入焦点与中文输入法组合态
|
|
312
|
+
const isEchoWhileTyping = root.childElementCount > 0
|
|
313
|
+
&& typeof document !== 'undefined'
|
|
314
|
+
&& document.activeElement instanceof HTMLTextAreaElement
|
|
315
|
+
&& root.contains(document.activeElement)
|
|
316
|
+
&& emittedValues.has(given)
|
|
317
|
+
&& makePaintKey(p, lastValue) === lastPaintKey;
|
|
318
|
+
const paintKey = makePaintKey(p, given);
|
|
319
|
+
if ((paintKey === lastPaintKey && root.childElementCount > 0) || isEchoWhileTyping) { paintBusy(); return; }
|
|
320
|
+
lastPaintKey = paintKey;
|
|
264
321
|
const nextSig = JSON.stringify(p.data);
|
|
265
|
-
|
|
266
|
-
|
|
322
|
+
if (given !== lastValue) {
|
|
323
|
+
lastValue = given;
|
|
324
|
+
emittedValues.clear();
|
|
325
|
+
answers = answersFrom(p.value, qs);
|
|
326
|
+
}
|
|
267
327
|
if (nextSig !== sig) {
|
|
268
328
|
sig = nextSig;
|
|
269
329
|
// 题目 / 票数变了:以数据为准,清掉乐观结果,丢弃已不存在 / 题型不符的答案
|
|
@@ -272,28 +332,43 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
272
332
|
}
|
|
273
333
|
const ro = bool(p.readonly);
|
|
274
334
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
275
|
-
|
|
335
|
+
// 外框去留原先看祖先(surface-edge);页面线写了入参时由取值表按层级邻接给,不再自报 edge
|
|
336
|
+
if (!kitHasProps(p)) markKitEdge(root);
|
|
276
337
|
root.textContent = '';
|
|
277
338
|
const meta = recOf(p.data);
|
|
278
|
-
|
|
339
|
+
// 数据状态:只读、没有题目
|
|
340
|
+
kitMarkDataFacts(root, { empty: qs.length === 0, readonly: ro });
|
|
341
|
+
if (textOf(meta.title) !== '') {
|
|
342
|
+
const h = mk('h3', TITLE_CLASS, textOf(meta.title));
|
|
343
|
+
kitMarkPart(h, 'block-title');
|
|
344
|
+
root.appendChild(h);
|
|
345
|
+
}
|
|
279
346
|
if (textOf(meta.description) !== '') root.appendChild(mk('p', DESC_CLASS, textOf(meta.description)));
|
|
280
347
|
if (qs.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.sv_empty', undefined, root)))); return; }
|
|
281
348
|
if (p.show_progress === undefined || bool(p.show_progress)) {
|
|
282
349
|
const row = mk('div', PROGRESS_ROW);
|
|
283
350
|
const bar = mkProgressBar(PROGRESS_CLASS);
|
|
284
|
-
bar.setAttribute(
|
|
351
|
+
bar.setAttribute(KIT_ATTR_PROGRESS, '');
|
|
285
352
|
row.appendChild(bar);
|
|
286
353
|
const t = mk('span', '');
|
|
287
|
-
t.setAttribute(
|
|
354
|
+
t.setAttribute(KIT_ATTR_PROGRESS_TEXT, '');
|
|
288
355
|
row.appendChild(t);
|
|
289
356
|
root.appendChild(row);
|
|
290
357
|
}
|
|
291
358
|
let allResults = true;
|
|
292
|
-
for (
|
|
359
|
+
for (let qi = 0; qi < qs.length; qi += 1) {
|
|
360
|
+
const q = qs[qi]!;
|
|
293
361
|
uid += 1;
|
|
294
362
|
const set = mk('fieldset', QUESTION_CLASS);
|
|
295
|
-
set.setAttribute(
|
|
296
|
-
|
|
363
|
+
set.setAttribute(KIT_ATTR_QUESTION, q.id);
|
|
364
|
+
// 每道题 = 问卷里的一节,题干 = 字段名
|
|
365
|
+
kitMarkLevel(set, 'section'); kitApplyLevelClass(set);
|
|
366
|
+
const legend = mk('legend', LEGEND_CLASS);
|
|
367
|
+
kitMarkPart(legend, 'field-name');
|
|
368
|
+
if (qs.length > 1) {
|
|
369
|
+
legend.appendChild(mk('span', QUESTION_NO_CLASS, `${qi + 1}.`));
|
|
370
|
+
}
|
|
371
|
+
legend.appendChild(root.ownerDocument.createTextNode(q.label));
|
|
297
372
|
if (q.required) {
|
|
298
373
|
const star = mk('span', REQUIRED_CLASS, '*');
|
|
299
374
|
star.setAttribute('aria-hidden', 'true');
|
|
@@ -312,9 +387,9 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
312
387
|
// 自绘勾选标记(base/check-core.ts):透明原生 input 承载值与键盘,data-kit-opt 写在 input 上供 change 委托读取
|
|
313
388
|
const lab = createCheck(root.ownerDocument, q.kind === 'single' ? 'radio' : 'checkbox', {
|
|
314
389
|
checked: q.kind === 'single' ? cur === o.value : Array.isArray(cur) && cur.includes(o.value),
|
|
315
|
-
|
|
390
|
+
readonly: ro, name: `kit-q-${uid}`, value: o.value, extra: ro ? OPTION_RO_CLASS : OPTION_CLASS,
|
|
316
391
|
});
|
|
317
|
-
markInput(lab)?.setAttribute(
|
|
392
|
+
markInput(lab)?.setAttribute(KIT_ATTR_OPT, o.value);
|
|
318
393
|
lab.append(mk('span', '', o.label));
|
|
319
394
|
set.appendChild(lab);
|
|
320
395
|
}
|
|
@@ -323,10 +398,10 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
323
398
|
setKitFace(area, 'field');
|
|
324
399
|
area.rows = 3;
|
|
325
400
|
area.placeholder = q.placeholder;
|
|
326
|
-
area.
|
|
401
|
+
area.readOnly = ro;
|
|
327
402
|
area.value = typeof cur === 'string' ? cur : '';
|
|
328
403
|
area.setAttribute('aria-label', q.label);
|
|
329
|
-
area.setAttribute(
|
|
404
|
+
area.setAttribute(KIT_ATTR_SURVEY_TEXT, q.id);
|
|
330
405
|
set.appendChild(area);
|
|
331
406
|
} else {
|
|
332
407
|
const row = mk('div', RATING_ROW);
|
|
@@ -340,7 +415,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
340
415
|
input.id = `kit-q-${inst}-${uid}-${n}`;
|
|
341
416
|
input.disabled = ro;
|
|
342
417
|
input.checked = cur === n;
|
|
343
|
-
input.setAttribute(
|
|
418
|
+
input.setAttribute(KIT_ATTR_RATE, String(n));
|
|
344
419
|
const lab = mk('label', RATING_LABEL, String(n));
|
|
345
420
|
lab.htmlFor = input.id;
|
|
346
421
|
box.append(input, lab);
|
|
@@ -349,7 +424,8 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
349
424
|
set.appendChild(row);
|
|
350
425
|
}
|
|
351
426
|
const err = mk('p', `${ERROR_CLASS} hidden`, str(p.required_text, kitText('soma.kit.sv_required', undefined, root)));
|
|
352
|
-
err.
|
|
427
|
+
err.id = `kit-sv-err-${inst}-${uid}`;
|
|
428
|
+
err.setAttribute(KIT_ATTR_ERROR, q.id);
|
|
353
429
|
err.setAttribute('role', 'alert');
|
|
354
430
|
set.appendChild(err);
|
|
355
431
|
root.appendChild(set);
|
|
@@ -357,16 +433,17 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
357
433
|
const canPeek = bool(p.peekable) && qs.some(hasResults);
|
|
358
434
|
if (!ro && (!allResults || (peek && canPeek))) {
|
|
359
435
|
const foot = mk('div', FOOT_CLASS);
|
|
436
|
+
kitMarkLevel(foot, 'foot'); kitApplyLevelClass(foot);
|
|
360
437
|
if (canPeek) {
|
|
361
438
|
const b = actionButton({ key: 'peek', label: peek ? str(p.back_text, kitText('soma.kit.sv_back', undefined, root)) : str(p.peek_text, kitText('soma.kit.sv_peek', undefined, root)), tone: 'neutral', disabled: false, reason: '' });
|
|
362
|
-
b.removeAttribute(
|
|
363
|
-
b.setAttribute(
|
|
439
|
+
b.removeAttribute(KIT_ATTR_ACTION);
|
|
440
|
+
b.setAttribute(KIT_ATTR_PEEK, '');
|
|
364
441
|
foot.appendChild(b);
|
|
365
442
|
}
|
|
366
443
|
if (!allResults) {
|
|
367
|
-
const submit = actionButton({ key: 'submit', label: str(p.submit_text, kitText('soma.kit.submit', undefined, root)),
|
|
368
|
-
submit.removeAttribute(
|
|
369
|
-
submit.setAttribute(
|
|
444
|
+
const submit = actionButton({ key: 'submit', label: str(p.submit_text, kitText('soma.kit.submit', undefined, root)), fn: 'submit', disabled: false, reason: '' });
|
|
445
|
+
submit.removeAttribute(KIT_ATTR_ACTION);
|
|
446
|
+
submit.setAttribute(KIT_ATTR_SUBMIT, '');
|
|
370
447
|
foot.appendChild(submit);
|
|
371
448
|
}
|
|
372
449
|
root.appendChild(foot);
|
|
@@ -377,7 +454,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
377
454
|
|
|
378
455
|
/** 忙闲通道:提交所接动作在进行中时提交钮禁用并挂 aria-busy(只改这一个钮,不重建整表) */
|
|
379
456
|
function paintBusy(): void {
|
|
380
|
-
kb.paint(root?.querySelector<HTMLElement>(
|
|
457
|
+
kb.paint(root?.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_SUBMIT)) ?? null);
|
|
381
458
|
}
|
|
382
459
|
|
|
383
460
|
return {
|
|
@@ -385,7 +462,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
385
462
|
root = rootEl;
|
|
386
463
|
const r = root;
|
|
387
464
|
const esc = (s: string): string => s.replace(/["\\]/g, '\\$&');
|
|
388
|
-
const qOf = (el: HTMLElement | null): string => el?.closest<HTMLElement>(
|
|
465
|
+
const qOf = (el: HTMLElement | null): string => el?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_QUESTION))?.getAttribute(KIT_ATTR_QUESTION) ?? '';
|
|
389
466
|
const onChange = (event: Event): void => {
|
|
390
467
|
const el = event.target as HTMLInputElement | null;
|
|
391
468
|
const id = qOf(el);
|
|
@@ -393,13 +470,13 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
393
470
|
if (!el || !q) return;
|
|
394
471
|
if (q.kind === 'single') setAnswer(id, el.value);
|
|
395
472
|
else if (q.kind === 'multi') {
|
|
396
|
-
const checked = [...r.querySelectorAll<HTMLInputElement>(`[
|
|
473
|
+
const checked = [...r.querySelectorAll<HTMLInputElement>(`[${KIT_ATTR_QUESTION}="${esc(id)}"] ${kitAttrSel(KIT_ATTR_OPT)}`)].filter((i) => i.checked).map((i) => i.value);
|
|
397
474
|
setAnswer(id, checked);
|
|
398
475
|
} else if (q.kind === 'rating') setAnswer(id, Number(el.value));
|
|
399
476
|
};
|
|
400
477
|
const onInput = (event: Event): void => {
|
|
401
478
|
const el = event.target as HTMLTextAreaElement | null;
|
|
402
|
-
if (el?.hasAttribute(
|
|
479
|
+
if (el?.hasAttribute(KIT_ATTR_SURVEY_TEXT)) setAnswer(qOf(el), el.value);
|
|
403
480
|
};
|
|
404
481
|
const submit = (): void => {
|
|
405
482
|
if (bool(P().readonly) || kb.busy()) return;
|
|
@@ -408,7 +485,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
408
485
|
showErrors = true;
|
|
409
486
|
refreshMeta();
|
|
410
487
|
const sel = esc(st.missing[0]!);
|
|
411
|
-
r.querySelector<HTMLElement>(`[
|
|
488
|
+
r.querySelector<HTMLElement>(`[${KIT_ATTR_QUESTION}="${sel}"] input, [${KIT_ATTR_QUESTION}="${sel}"] textarea`)?.focus();
|
|
412
489
|
api.emit('invalid', { missing: st.missing });
|
|
413
490
|
return;
|
|
414
491
|
}
|
|
@@ -424,15 +501,19 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
424
501
|
};
|
|
425
502
|
const onClick = (event: Event): void => {
|
|
426
503
|
const t = event.target as HTMLElement | null;
|
|
427
|
-
if (t
|
|
504
|
+
if (t instanceof HTMLInputElement && (t.hasAttribute(KIT_ATTR_READONLY) || bool(P().readonly))) {
|
|
505
|
+
event.preventDefault();
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (t?.closest(kitAttrSel(KIT_ATTR_PEEK))) {
|
|
428
509
|
event.preventDefault();
|
|
429
510
|
peek = !peek;
|
|
430
511
|
api.refresh();
|
|
431
512
|
// 整表重建后焦点回到「看结果 / 返回投票」钮
|
|
432
|
-
r.querySelector<HTMLElement>(
|
|
513
|
+
r.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_PEEK))?.focus();
|
|
433
514
|
return;
|
|
434
515
|
}
|
|
435
|
-
if (t?.closest(
|
|
516
|
+
if (t?.closest(kitAttrSel(KIT_ATTR_SUBMIT))) { event.preventDefault(); submit(); }
|
|
436
517
|
};
|
|
437
518
|
const onSubmit = (event: Event): void => { event.preventDefault(); submit(); };
|
|
438
519
|
r.addEventListener('change', onChange);
|