soma-kit 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +8 -5
- package/packs/ai/model-card.ts +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- 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 -338
- package/spec/generated/kit-page.schema.json +1152 -87
- package/spec/kit-grammar.json +1084 -136
- package/spec/kit-grammar.schema.json +167 -26
- package/src/app/app-config.ts +220 -187
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +200 -22
- package/src/app/define-kit-app.ts +54 -8
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +12 -7
- package/src/app/kit-view-context.ts +50 -3
- 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 +68 -24
- package/src/app/theme-runtime.ts +421 -87
- 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 +107 -59
- package/src/base/anchored-layer.ts +8 -7
- 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 +365 -53
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +147 -32
- package/src/base/check-core.ts +196 -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 +404 -28
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +155 -37
- package/src/base/context-menu.ts +26 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +115 -94
- package/src/base/date.ts +487 -76
- package/src/base/delta.ts +20 -11
- package/src/base/divider.ts +64 -97
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +64 -23
- package/src/base/gap-value.ts +35 -16
- package/src/base/hint-tips.ts +100 -30
- 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 +92 -24
- package/src/base/inline-error.ts +90 -0
- package/src/base/input.ts +174 -38
- package/src/base/kbd.ts +31 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +324 -95
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +58 -22
- package/src/base/menu-button.ts +129 -42
- package/src/base/menu-core.ts +210 -26
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +10 -5
- package/src/base/motion/hover-gallery.ts +19 -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 +143 -27
- package/src/base/overlay-runtime.ts +32 -24
- package/src/base/overlay-shell.ts +186 -0
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +625 -74
- package/src/base/popup.ts +219 -78
- 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 +145 -21
- 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 +60 -18
- package/src/base/relation-cells.ts +541 -0
- package/src/{frames → base}/resize-handle.ts +6 -4
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +99 -56
- package/src/base/select.ts +8 -2
- package/src/base/shared.ts +520 -73
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/status-tone.ts +1 -1
- 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 +129 -55
- package/src/base/tag.ts +203 -91
- package/src/base/text.ts +491 -77
- package/src/base/textarea.ts +89 -40
- package/src/base/time-picker.ts +341 -57
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +346 -89
- package/src/base/upload.ts +612 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +98 -6
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +53 -13
- package/src/biz/auth-panel/compile.ts +14 -4
- package/src/biz/auth-panel/shell.ts +28 -8
- package/src/biz/category-crud/compile.ts +64 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +30 -8
- package/src/biz/checkout-page/compile.ts +38 -4
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +28 -10
- package/src/biz/compose.ts +9 -4
- package/src/biz/data-components.ts +2 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +5 -2
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +36 -20
- package/src/biz/index.ts +5 -4
- package/src/biz/landing-page/compile.ts +4 -3
- package/src/biz/landing-page/shell.ts +25 -5
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +62 -16
- package/src/biz/master-sub/compile.ts +318 -38
- package/src/biz/master-sub/detail-head.ts +145 -21
- package/src/biz/master-sub/index.ts +6 -3
- package/src/biz/master-sub/shell.ts +232 -66
- package/src/biz/multi-board/compile.ts +89 -38
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +25 -9
- package/src/biz/multi-board/prose-fold.ts +17 -13
- package/src/biz/multi-board/shell.ts +153 -38
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +28 -7
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +51 -11
- package/src/biz/page-templates/domain-templates.ts +147 -20
- package/src/biz/page-templates/result-page/compile.ts +5 -2
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +20 -6
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +20 -9
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +30 -14
- package/src/biz/record-detail/compile.ts +43 -12
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +42 -11
- package/src/biz/settings-center/compile.ts +5 -2
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +33 -9
- package/src/biz/shared/action-host.ts +146 -48
- package/src/biz/shared/compile-helpers.ts +134 -32
- package/src/biz/shared/coordinator.ts +727 -163
- 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 +102 -24
- package/src/biz/shared/overlay-shell.ts +97 -116
- 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 +6 -4
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +22 -8
- package/src/biz/standard-crud/compile.ts +213 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +90 -13
- package/src/biz/standard-crud/summary.ts +2 -35
- package/src/biz/step-form/compile.ts +13 -4
- package/src/biz/step-form/hub.ts +168 -49
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +35 -17
- package/src/biz/types.ts +49 -6
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +179 -33
- package/src/cli/kit-init.ts +152 -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/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +461 -273
- package/src/compile/component-candidates.ts +58 -5
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +6 -59
- package/src/compile/index.ts +2 -2
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +44 -13
- 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 +405 -67
- 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/redirect.ts +1 -1
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +786 -0
- package/src/compile/styles.ts +286 -48
- package/src/compile/types.ts +63 -6
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +52 -23
- package/src/data/anchor-nav.ts +77 -16
- package/src/data/approval-flow.ts +217 -126
- package/src/data/assignment-picker.ts +182 -94
- package/src/data/async-result-panel.ts +114 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +150 -24
- package/src/data/calendar.ts +436 -97
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +81 -41
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +1053 -96
- package/src/data/checklist.ts +82 -38
- package/src/data/code-view.ts +296 -44
- package/src/data/comment-thread.ts +611 -86
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +250 -39
- 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 +109 -49
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +38 -18
- package/src/data/embed.ts +143 -8
- package/src/data/engine-ports.ts +135 -0
- package/src/data/field-mapper.ts +116 -54
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +695 -158
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +88 -26
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +640 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +40 -13
- package/src/data/image-viewer.ts +265 -62
- package/src/data/index.ts +75 -6
- package/src/data/item-list.ts +219 -58
- package/src/data/json-view.ts +909 -0
- package/src/data/kanban.ts +346 -91
- 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 +597 -0
- package/src/data/matrix.ts +234 -120
- package/src/data/media-grid.ts +165 -38
- package/src/data/mega-menu.ts +43 -26
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +55 -19
- package/src/data/menu.ts +138 -48
- package/src/data/mockup.ts +37 -25
- package/src/data/modal-dialog.ts +126 -98
- package/src/data/navbar.ts +152 -66
- package/src/data/notice-list.ts +101 -49
- package/src/data/notify-renderer.ts +80 -15
- package/src/data/object-form.ts +1504 -164
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +129 -45
- package/src/data/panel-head.ts +238 -76
- package/src/data/permission-matrix.ts +379 -120
- package/src/data/permission-tree.ts +146 -78
- package/src/data/pricing-table.ts +112 -43
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +67 -32
- package/src/data/record-card.ts +245 -72
- package/src/data/record-picker.ts +61 -28
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +141 -38
- package/src/data/resident.ts +11 -13
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +260 -127
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +384 -105
- package/src/data/rule-builder.ts +136 -81
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +90 -36
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +493 -100
- package/src/data/static-lazy.ts +21 -0
- package/src/data/static-registry.ts +46 -4
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +69 -36
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +134 -47
- package/src/data/system-switcher.ts +53 -24
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +731 -0
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +113 -47
- package/src/data/transfer.ts +204 -47
- package/src/data/tree-table.ts +228 -81
- package/src/data/tree.ts +193 -69
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +248 -98
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +28 -6
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +4 -4
- package/src/frames/inherited-shell.ts +219 -0
- package/src/frames/page-bar.ts +208 -28
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +18 -0
- package/src/frames/shared.ts +73 -26
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +27 -17
- package/src/frames/split-frame/wiring.ts +16 -12
- package/src/frames/tabs-frame/shell.ts +14 -7
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +5 -2
- package/src/frames/workspace-frame/extras.ts +23 -7
- 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 +24 -3
- package/src/frames/workspace-frame/state.ts +42 -8
- package/src/frames/workspace-frame/view.ts +773 -194
- package/src/generated/kit-grammar-runtime.ts +1061 -77
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +210 -5
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +204 -22
- package/src/object-renderer/action-more.ts +66 -19
- package/src/object-renderer/arrange.ts +270 -28
- 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 +459 -103
- package/src/object-renderer/collection-table.ts +406 -59
- package/src/object-renderer/collection.ts +333 -71
- package/src/object-renderer/compile-data.ts +13 -3
- package/src/object-renderer/defaults.ts +14 -5
- package/src/object-renderer/emit-events.ts +46 -20
- package/src/object-renderer/emit-object.ts +35 -6
- package/src/object-renderer/emit-static.ts +831 -153
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +190 -0
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +55 -7
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +124 -0
- 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 +72 -27
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +479 -111
- 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 +437 -130
- package/src/object-renderer/types.ts +100 -17
- 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/app-blocks.ts +66 -0
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +57 -0
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +32 -0
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +93 -26
- package/src/recipes/control.ts +85 -8
- package/src/recipes/desc-list.ts +108 -0
- package/src/recipes/divider.ts +74 -0
- package/src/recipes/emphasis.ts +102 -13
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +6 -5
- package/src/recipes/index.ts +39 -5
- package/src/recipes/inherited-shell.ts +43 -0
- package/src/recipes/json-view.ts +50 -0
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +96 -0
- package/src/recipes/overlay.ts +151 -37
- package/src/recipes/page-width.ts +51 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +38 -20
- 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 +6 -6
- package/src/recipes/state.ts +64 -11
- package/src/recipes/status.ts +21 -20
- package/src/recipes/strip.ts +114 -0
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +40 -7
- package/src/recipes/table-gap.ts +4 -3
- package/src/recipes/table-native-edit.ts +25 -12
- package/src/recipes/table-row.ts +56 -20
- package/src/recipes/tabs.ts +140 -31
- package/src/recipes/text-diff.ts +97 -0
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +72 -5
- package/src/recipes/typography.ts +2 -2
- 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/diagnostics.ts +16 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +292 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +40 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- 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/path-guard.ts +1 -1
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +181 -21
- 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 +563 -28
- package/src/theme/kit-theme.tpl +527 -28
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +538 -176
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +12 -3
- package/src/theme/theme-tokens.ts +1602 -90
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- package/src/frames/list-summary.ts +0 -100
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
- /package/src/{base → shared}/class-candidates.ts +0 -0
|
@@ -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,44 +12,67 @@
|
|
|
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';
|
|
18
19
|
import { kitText } from '../i18n/kit-text';
|
|
19
20
|
import { setKitFace } from '../recipes';
|
|
21
|
+
import { kitButtonEdgeRecipe, kitControlRecipe } from '../recipes/control';
|
|
22
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
23
|
+
import { kitSelectedVariantRecipe } from '../recipes/state';
|
|
24
|
+
import { kitClosedValueRecipe } from '../recipes/field-text';
|
|
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';
|
|
20
30
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
21
31
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, mk, mkProgressBar, PROGRESS_BAR_CLASS_TOKENS, recOf, setProgressBar, rowsOf, textOf } from './shape-util';
|
|
22
32
|
import { rowKey } from './d9-util';
|
|
23
33
|
import { markKitEdge } from '../recipes/surface-edge';
|
|
34
|
+
import { kitHasProps, kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
|
|
24
35
|
import { kitTypographyRecipe } from '../recipes/typography';
|
|
25
36
|
import { QUESTION_KINDS, QUESTION_MAX, QUESTION_MAX_OPTIONS, QUESTION_RATING_MAX, pickOf } from './d9-limits';
|
|
26
37
|
|
|
27
38
|
// ───────── 类串常量与 Tailwind 候选清单 ─────────
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
// 问卷外缘 = 壳配方(容器边,KT-B2);作答框 = 多行控件配方;评分钮 = 带文字中性按钮描边(KT-B1)
|
|
41
|
+
const ROOT_EDGE = kitShellRecipe({ tone: 'base', shadow: false });
|
|
42
|
+
const RATING_EDGE = kitButtonEdgeRecipe();
|
|
43
|
+
const ROOT_CLASS = mergeClass('flex flex-col gap-5 p-5 text-sm text-fg', ROOT_EDGE);
|
|
30
44
|
const TITLE_CLASS = kitTypographyRecipe('sectionTitle');
|
|
31
45
|
const DESC_CLASS = 'text-fg-muted';
|
|
32
46
|
const PROGRESS_ROW = 'flex items-center gap-3 text-xs text-fg-muted';
|
|
33
47
|
const PROGRESS_CLASS = 'block flex-1';
|
|
34
48
|
const QUESTION_CLASS = 'flex min-w-0 flex-col gap-2 border-0 p-0';
|
|
35
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';
|
|
36
51
|
const REQUIRED_CLASS = 'ms-1 text-danger-on-soft';
|
|
37
52
|
const OPTION_CLASS = 'w-full px-2 py-1.5 hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
38
|
-
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');
|
|
39
55
|
const RATING_ROW = 'flex flex-wrap gap-1';
|
|
40
56
|
const RATING_BOX = 'relative';
|
|
41
57
|
const RATING_INPUT = 'peer sr-only';
|
|
42
|
-
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
|
+
);
|
|
43
65
|
const ERROR_CLASS = 'text-xs text-danger-on-soft';
|
|
44
66
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
45
|
-
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';
|
|
46
68
|
const RESULT_HEAD = 'flex items-center justify-between gap-2';
|
|
47
|
-
const RESULT_MINE = '
|
|
69
|
+
const RESULT_MINE = mergeClass(kitClosedValueRecipe('primary'), 'ms-2');
|
|
48
70
|
const RESULT_NUM = 'text-xs text-fg-muted';
|
|
49
71
|
|
|
50
72
|
export const KIT_SURVEY_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
51
|
-
ROOT_CLASS, TITLE_CLASS, DESC_CLASS, PROGRESS_ROW, PROGRESS_CLASS, QUESTION_CLASS, LEGEND_CLASS,
|
|
52
|
-
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,
|
|
53
76
|
);
|
|
54
77
|
|
|
55
78
|
// ───────── 数据规整纯函数:题目、结果判定、占比、已答校验、答案过滤 ─────────
|
|
@@ -194,23 +217,47 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
194
217
|
let sig = '';
|
|
195
218
|
let lastValue = '\u0000';
|
|
196
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
|
+
]);
|
|
197
232
|
const kb = createKitBusy(P);
|
|
198
233
|
let uid = 0;
|
|
199
234
|
const inst = ++surveyInstances;
|
|
200
235
|
|
|
201
|
-
const questions =(): KitQuestion[] => questionsOf(P().data);
|
|
236
|
+
const questions = (): KitQuestion[] => questionsOf(P().data);
|
|
202
237
|
const status = (): ReturnType<typeof surveyStatus> => surveyStatus(questions(), answers);
|
|
203
238
|
const inResults = (q: KitQuestion): boolean => hasResults(q) && (q.closed || q.voted.length > 0 || submitted.has(q.id) || peek);
|
|
204
239
|
|
|
205
240
|
const refreshMeta = (): void => {
|
|
206
241
|
if (!root) return;
|
|
207
242
|
const st = status();
|
|
208
|
-
const bar = root.querySelector<HTMLElement>(
|
|
209
|
-
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));
|
|
210
245
|
if (bar) setProgressBar(bar, st.answered, st.total);
|
|
211
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));
|
|
212
|
-
root.querySelectorAll<HTMLElement>(
|
|
213
|
-
|
|
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
|
+
});
|
|
214
261
|
});
|
|
215
262
|
};
|
|
216
263
|
|
|
@@ -219,19 +266,28 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
219
266
|
if (value === undefined || !isAnswered(questions().find((q) => q.id === id) ?? { kind: 'text' }, value)) delete answers[id]; else answers[id] = value;
|
|
220
267
|
refreshMeta();
|
|
221
268
|
const st = status();
|
|
222
|
-
|
|
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 });
|
|
223
279
|
};
|
|
224
280
|
|
|
225
281
|
const resultNode = (q: KitQuestion, p: Record<string, unknown>): HTMLElement => {
|
|
226
282
|
const box = mk('div', 'flex flex-col gap-1');
|
|
227
|
-
box.setAttribute(
|
|
283
|
+
box.setAttribute(KIT_ATTR_RESULTS, q.id);
|
|
228
284
|
const mineSet = new Set<string>([...q.voted, ...(submitted.get(q.id) ?? [])]);
|
|
229
285
|
const bump = new Set(submitted.get(q.id) ?? []);
|
|
230
286
|
const votes = q.options.map((o) => (o.votes ?? 0) + (bump.has(o.value) && !q.voted.includes(o.value) ? 1 : 0));
|
|
231
287
|
const total = votes.reduce((s, v) => s + v, 0);
|
|
232
288
|
q.options.forEach((o, i) => {
|
|
233
289
|
const row = mk('div', RESULT_ROW);
|
|
234
|
-
row.setAttribute(
|
|
290
|
+
row.setAttribute(KIT_ATTR_RESULT, o.value);
|
|
235
291
|
const head = mk('div', RESULT_HEAD);
|
|
236
292
|
const name = mk('span', '', o.label);
|
|
237
293
|
if (mineSet.has(o.value)) name.appendChild(mk('span', RESULT_MINE, str(p.mine_text, kitText('soma.kit.sv_mine', undefined, root))));
|
|
@@ -250,14 +306,24 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
250
306
|
function paint(): void {
|
|
251
307
|
if (!root) return;
|
|
252
308
|
const p = P();
|
|
253
|
-
// 同样的 props 再下行(页面把 change 回写再下发的常见情形)不重画,保住输入焦点与光标
|
|
254
|
-
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()]]);
|
|
255
|
-
if (paintKey === lastPaintKey && root.childElementCount > 0) { paintBusy(); return; }
|
|
256
|
-
lastPaintKey = paintKey;
|
|
257
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;
|
|
258
321
|
const nextSig = JSON.stringify(p.data);
|
|
259
|
-
|
|
260
|
-
|
|
322
|
+
if (given !== lastValue) {
|
|
323
|
+
lastValue = given;
|
|
324
|
+
emittedValues.clear();
|
|
325
|
+
answers = answersFrom(p.value, qs);
|
|
326
|
+
}
|
|
261
327
|
if (nextSig !== sig) {
|
|
262
328
|
sig = nextSig;
|
|
263
329
|
// 题目 / 票数变了:以数据为准,清掉乐观结果,丢弃已不存在 / 题型不符的答案
|
|
@@ -266,28 +332,43 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
266
332
|
}
|
|
267
333
|
const ro = bool(p.readonly);
|
|
268
334
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
269
|
-
|
|
335
|
+
// 外框去留原先看祖先(surface-edge);页面线写了入参时由取值表按层级邻接给,不再自报 edge
|
|
336
|
+
if (!kitHasProps(p)) markKitEdge(root);
|
|
270
337
|
root.textContent = '';
|
|
271
338
|
const meta = recOf(p.data);
|
|
272
|
-
|
|
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
|
+
}
|
|
273
346
|
if (textOf(meta.description) !== '') root.appendChild(mk('p', DESC_CLASS, textOf(meta.description)));
|
|
274
347
|
if (qs.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.sv_empty', undefined, root)))); return; }
|
|
275
348
|
if (p.show_progress === undefined || bool(p.show_progress)) {
|
|
276
349
|
const row = mk('div', PROGRESS_ROW);
|
|
277
350
|
const bar = mkProgressBar(PROGRESS_CLASS);
|
|
278
|
-
bar.setAttribute(
|
|
351
|
+
bar.setAttribute(KIT_ATTR_PROGRESS, '');
|
|
279
352
|
row.appendChild(bar);
|
|
280
353
|
const t = mk('span', '');
|
|
281
|
-
t.setAttribute(
|
|
354
|
+
t.setAttribute(KIT_ATTR_PROGRESS_TEXT, '');
|
|
282
355
|
row.appendChild(t);
|
|
283
356
|
root.appendChild(row);
|
|
284
357
|
}
|
|
285
358
|
let allResults = true;
|
|
286
|
-
for (
|
|
359
|
+
for (let qi = 0; qi < qs.length; qi += 1) {
|
|
360
|
+
const q = qs[qi]!;
|
|
287
361
|
uid += 1;
|
|
288
362
|
const set = mk('fieldset', QUESTION_CLASS);
|
|
289
|
-
set.setAttribute(
|
|
290
|
-
|
|
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));
|
|
291
372
|
if (q.required) {
|
|
292
373
|
const star = mk('span', REQUIRED_CLASS, '*');
|
|
293
374
|
star.setAttribute('aria-hidden', 'true');
|
|
@@ -306,9 +387,9 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
306
387
|
// 自绘勾选标记(base/check-core.ts):透明原生 input 承载值与键盘,data-kit-opt 写在 input 上供 change 委托读取
|
|
307
388
|
const lab = createCheck(root.ownerDocument, q.kind === 'single' ? 'radio' : 'checkbox', {
|
|
308
389
|
checked: q.kind === 'single' ? cur === o.value : Array.isArray(cur) && cur.includes(o.value),
|
|
309
|
-
|
|
390
|
+
readonly: ro, name: `kit-q-${uid}`, value: o.value, extra: ro ? OPTION_RO_CLASS : OPTION_CLASS,
|
|
310
391
|
});
|
|
311
|
-
markInput(lab)?.setAttribute(
|
|
392
|
+
markInput(lab)?.setAttribute(KIT_ATTR_OPT, o.value);
|
|
312
393
|
lab.append(mk('span', '', o.label));
|
|
313
394
|
set.appendChild(lab);
|
|
314
395
|
}
|
|
@@ -317,10 +398,10 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
317
398
|
setKitFace(area, 'field');
|
|
318
399
|
area.rows = 3;
|
|
319
400
|
area.placeholder = q.placeholder;
|
|
320
|
-
area.
|
|
401
|
+
area.readOnly = ro;
|
|
321
402
|
area.value = typeof cur === 'string' ? cur : '';
|
|
322
403
|
area.setAttribute('aria-label', q.label);
|
|
323
|
-
area.setAttribute(
|
|
404
|
+
area.setAttribute(KIT_ATTR_SURVEY_TEXT, q.id);
|
|
324
405
|
set.appendChild(area);
|
|
325
406
|
} else {
|
|
326
407
|
const row = mk('div', RATING_ROW);
|
|
@@ -334,7 +415,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
334
415
|
input.id = `kit-q-${inst}-${uid}-${n}`;
|
|
335
416
|
input.disabled = ro;
|
|
336
417
|
input.checked = cur === n;
|
|
337
|
-
input.setAttribute(
|
|
418
|
+
input.setAttribute(KIT_ATTR_RATE, String(n));
|
|
338
419
|
const lab = mk('label', RATING_LABEL, String(n));
|
|
339
420
|
lab.htmlFor = input.id;
|
|
340
421
|
box.append(input, lab);
|
|
@@ -343,7 +424,8 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
343
424
|
set.appendChild(row);
|
|
344
425
|
}
|
|
345
426
|
const err = mk('p', `${ERROR_CLASS} hidden`, str(p.required_text, kitText('soma.kit.sv_required', undefined, root)));
|
|
346
|
-
err.
|
|
427
|
+
err.id = `kit-sv-err-${inst}-${uid}`;
|
|
428
|
+
err.setAttribute(KIT_ATTR_ERROR, q.id);
|
|
347
429
|
err.setAttribute('role', 'alert');
|
|
348
430
|
set.appendChild(err);
|
|
349
431
|
root.appendChild(set);
|
|
@@ -351,16 +433,17 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
351
433
|
const canPeek = bool(p.peekable) && qs.some(hasResults);
|
|
352
434
|
if (!ro && (!allResults || (peek && canPeek))) {
|
|
353
435
|
const foot = mk('div', FOOT_CLASS);
|
|
436
|
+
kitMarkLevel(foot, 'foot'); kitApplyLevelClass(foot);
|
|
354
437
|
if (canPeek) {
|
|
355
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: '' });
|
|
356
|
-
b.removeAttribute(
|
|
357
|
-
b.setAttribute(
|
|
439
|
+
b.removeAttribute(KIT_ATTR_ACTION);
|
|
440
|
+
b.setAttribute(KIT_ATTR_PEEK, '');
|
|
358
441
|
foot.appendChild(b);
|
|
359
442
|
}
|
|
360
443
|
if (!allResults) {
|
|
361
|
-
const submit = actionButton({ key: 'submit', label: str(p.submit_text, kitText('soma.kit.submit', undefined, root)),
|
|
362
|
-
submit.removeAttribute(
|
|
363
|
-
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, '');
|
|
364
447
|
foot.appendChild(submit);
|
|
365
448
|
}
|
|
366
449
|
root.appendChild(foot);
|
|
@@ -371,7 +454,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
371
454
|
|
|
372
455
|
/** 忙闲通道:提交所接动作在进行中时提交钮禁用并挂 aria-busy(只改这一个钮,不重建整表) */
|
|
373
456
|
function paintBusy(): void {
|
|
374
|
-
kb.paint(root?.querySelector<HTMLElement>(
|
|
457
|
+
kb.paint(root?.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_SUBMIT)) ?? null);
|
|
375
458
|
}
|
|
376
459
|
|
|
377
460
|
return {
|
|
@@ -379,7 +462,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
379
462
|
root = rootEl;
|
|
380
463
|
const r = root;
|
|
381
464
|
const esc = (s: string): string => s.replace(/["\\]/g, '\\$&');
|
|
382
|
-
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) ?? '';
|
|
383
466
|
const onChange = (event: Event): void => {
|
|
384
467
|
const el = event.target as HTMLInputElement | null;
|
|
385
468
|
const id = qOf(el);
|
|
@@ -387,13 +470,13 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
387
470
|
if (!el || !q) return;
|
|
388
471
|
if (q.kind === 'single') setAnswer(id, el.value);
|
|
389
472
|
else if (q.kind === 'multi') {
|
|
390
|
-
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);
|
|
391
474
|
setAnswer(id, checked);
|
|
392
475
|
} else if (q.kind === 'rating') setAnswer(id, Number(el.value));
|
|
393
476
|
};
|
|
394
477
|
const onInput = (event: Event): void => {
|
|
395
478
|
const el = event.target as HTMLTextAreaElement | null;
|
|
396
|
-
if (el?.hasAttribute(
|
|
479
|
+
if (el?.hasAttribute(KIT_ATTR_SURVEY_TEXT)) setAnswer(qOf(el), el.value);
|
|
397
480
|
};
|
|
398
481
|
const submit = (): void => {
|
|
399
482
|
if (bool(P().readonly) || kb.busy()) return;
|
|
@@ -402,7 +485,7 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
402
485
|
showErrors = true;
|
|
403
486
|
refreshMeta();
|
|
404
487
|
const sel = esc(st.missing[0]!);
|
|
405
|
-
r.querySelector<HTMLElement>(`[
|
|
488
|
+
r.querySelector<HTMLElement>(`[${KIT_ATTR_QUESTION}="${sel}"] input, [${KIT_ATTR_QUESTION}="${sel}"] textarea`)?.focus();
|
|
406
489
|
api.emit('invalid', { missing: st.missing });
|
|
407
490
|
return;
|
|
408
491
|
}
|
|
@@ -418,15 +501,19 @@ export function createQuestionnaire(): SomaComponentDefinition {
|
|
|
418
501
|
};
|
|
419
502
|
const onClick = (event: Event): void => {
|
|
420
503
|
const t = event.target as HTMLElement | null;
|
|
421
|
-
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))) {
|
|
422
509
|
event.preventDefault();
|
|
423
510
|
peek = !peek;
|
|
424
511
|
api.refresh();
|
|
425
512
|
// 整表重建后焦点回到「看结果 / 返回投票」钮
|
|
426
|
-
r.querySelector<HTMLElement>(
|
|
513
|
+
r.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_PEEK))?.focus();
|
|
427
514
|
return;
|
|
428
515
|
}
|
|
429
|
-
if (t?.closest(
|
|
516
|
+
if (t?.closest(kitAttrSel(KIT_ATTR_SUBMIT))) { event.preventDefault(); submit(); }
|
|
430
517
|
};
|
|
431
518
|
const onSubmit = (event: Event): void => { event.preventDefault(); submit(); };
|
|
432
519
|
r.addEventListener('change', onChange);
|