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
package/src/base/shared.ts
CHANGED
|
@@ -13,19 +13,27 @@ import type {
|
|
|
13
13
|
} from 'soma-core';
|
|
14
14
|
import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
15
15
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
16
|
+
import { KIT_ICON_LIMITS, KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
|
|
16
17
|
import { createFormatter, type SomaFormatter } from 'soma-foundation/values';
|
|
17
18
|
import {
|
|
18
19
|
KIT_POPUP_PLACE_CLASS_CANDIDATES, POPUP_TIP_BASE, POPUP_TIP_HIDDEN_CLASS, POPUP_TIP_PREF, POPUP_TIP_SHOWN_CLASS,
|
|
19
|
-
popupTipClass, showPopupFitted,
|
|
20
|
+
onKitPanelMounted, popupTipClass, queryAllWithDropdowns, showPopupFitted,
|
|
20
21
|
} from './popup';
|
|
21
|
-
import { classCandidates } from '
|
|
22
|
+
import { classCandidates } from '../shared/class-candidates';
|
|
23
|
+
import type { KitSize } from '../shared/primitives-types';
|
|
22
24
|
import { leaveAnchored, unmarkAnchored } from './anchored-layer';
|
|
23
25
|
import type { KitLeaveHandle } from './overlay-runtime';
|
|
24
26
|
import { withKitViewTransition } from './view-transition';
|
|
25
27
|
import { kitBusyOf, onKitActionBusy } from './action-busy';
|
|
26
28
|
import { deniedBy, registerLivePermissionGate } from './permission-gate';
|
|
27
29
|
import { kitText } from '../i18n/kit-text';
|
|
28
|
-
import {
|
|
30
|
+
import { kitOuterRoot, kitReportSelf, kitReportSelfTracked, type KitSelfReportAttrs } from './kit-contract';
|
|
31
|
+
import { kitFileSizeText } from '../shared/field-value-format';
|
|
32
|
+
import { mergeClass } from '../shared/merge-class';
|
|
33
|
+
import {
|
|
34
|
+
KIT_ATTR_BADGE, KIT_ATTR_BOARD_PANEL, KIT_ATTR_HERO_SOLO, KIT_ATTR_HERO_STATS, KIT_ATTR_INVALID, KIT_ATTR_LAYER, KIT_ATTR_RKEY,
|
|
35
|
+
KIT_ATTR_SLOT, KIT_ATTR_SUMMARY_EMPTY, KIT_ATTR_TAB,
|
|
36
|
+
} from '../shared/dom-attrs';
|
|
29
37
|
import {
|
|
30
38
|
KIT_PART_ATTRIBUTE,
|
|
31
39
|
KIT_PART_BADGE,
|
|
@@ -35,10 +43,11 @@ import {
|
|
|
35
43
|
KIT_TYPOGRAPHY_RECIPE_MAP,
|
|
36
44
|
type KitTypographyRecipeRole,
|
|
37
45
|
} from '../recipes';
|
|
46
|
+
import { kitIsNextRuntime } from '../recipes/pipeline-runtime';
|
|
38
47
|
|
|
39
48
|
// ── 尺寸档 ────────────────────────────────────────────────────
|
|
40
49
|
|
|
41
|
-
export type KitSize
|
|
50
|
+
export type { KitSize };
|
|
42
51
|
export const KIT_SIZES: readonly KitSize[] = ['sm', 'md', 'lg'];
|
|
43
52
|
|
|
44
53
|
export function sizeOf(raw: unknown): KitSize {
|
|
@@ -54,10 +63,19 @@ export { KIT_TYPOGRAPHY_RECIPE_MAP };
|
|
|
54
63
|
|
|
55
64
|
export const FOCUS_RING = kitFocusRingRecipe('control');
|
|
56
65
|
|
|
66
|
+
const FIELD_ARIA_INVALID = 'aria-invalid:border-danger';
|
|
67
|
+
|
|
57
68
|
export const FIELD_CLASS: Record<KitSize, string> = {
|
|
58
|
-
sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'outline' }),
|
|
59
|
-
md: mergeClass(kitControlRecipe({ size: 'md', variant: 'outline' }),
|
|
60
|
-
lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'outline' }),
|
|
69
|
+
sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'outline' }), FIELD_ARIA_INVALID),
|
|
70
|
+
md: mergeClass(kitControlRecipe({ size: 'md', variant: 'outline' }), FIELD_ARIA_INVALID),
|
|
71
|
+
lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'outline' }), FIELD_ARIA_INVALID),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** 触发器按钮用的字段外观(<button> 恒匹配 CSS :read-only 伪类,省略只读态井色背景防常态误染灰底) */
|
|
75
|
+
export const FIELD_TRIGGER_CLASS: Record<KitSize, string> = {
|
|
76
|
+
sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'outline', trigger: true }), FIELD_ARIA_INVALID),
|
|
77
|
+
md: mergeClass(kitControlRecipe({ size: 'md', variant: 'outline', trigger: true }), FIELD_ARIA_INVALID),
|
|
78
|
+
lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'outline', trigger: true }), FIELD_ARIA_INVALID),
|
|
61
79
|
};
|
|
62
80
|
|
|
63
81
|
export const FIELD_INVALID_CLASS = kitInvalidRecipe();
|
|
@@ -66,7 +84,15 @@ export function withInvalid(base: string, invalid: boolean): string {
|
|
|
66
84
|
return invalid ? `${base} ${FIELD_INVALID_CLASS}` : base;
|
|
67
85
|
}
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
// 加载转圈三档(取值表 02 §7:Ant 14 / 20 / 32、TDesign 16 / 36 / 56 → 16 / 20 / 32):边长取间距阶(真源 kit-limits#icons.spinSteps,随 density),
|
|
88
|
+
// 环宽 2、轨与弧跟随宿主字色(border-current/30 border-t-current,解决实心彩色按钮上同色加载圈隐身);减弱动效静止
|
|
89
|
+
const spinClass = (step: number): string => `inline-block size-${step} motion-safe:animate-spin rounded-full border-2 border-current/30 border-t-current`;
|
|
90
|
+
export const KIT_SPIN_CLASS: Readonly<Record<KitSize, string>> = Object.freeze({
|
|
91
|
+
sm: spinClass(KIT_ICON_LIMITS.spinSteps.sm),
|
|
92
|
+
md: spinClass(KIT_ICON_LIMITS.spinSteps.md),
|
|
93
|
+
lg: spinClass(KIT_ICON_LIMITS.spinSteps.lg),
|
|
94
|
+
});
|
|
95
|
+
export const KIT_SPINNER_CLASS = KIT_SPIN_CLASS.sm;
|
|
70
96
|
|
|
71
97
|
// ── props 读取 ────────────────────────────────────────────────
|
|
72
98
|
|
|
@@ -113,9 +139,18 @@ export interface KitOption {
|
|
|
113
139
|
icon?: string;
|
|
114
140
|
/** Radio / Checkbox 读:纯图标选项的可访问名(缺省取 value) */
|
|
115
141
|
aria_label?: string;
|
|
142
|
+
/** Radio segmented 读:选项尾部的计数(来自列表响应 facets;没给不显示) */
|
|
143
|
+
count?: number;
|
|
144
|
+
/** 选项次要说明或分组(保留原始可选元数据供下游选择器读取) */
|
|
145
|
+
desc?: string;
|
|
146
|
+
description?: string;
|
|
147
|
+
group?: string;
|
|
116
148
|
}
|
|
117
149
|
|
|
118
150
|
const warnedDuplicates = new Set<string>();
|
|
151
|
+
const OPTIONS_CACHE = new WeakMap<readonly unknown[], readonly KitOption[]>();
|
|
152
|
+
const OPTIONS_MAP_CACHE = new WeakMap<readonly unknown[], ReadonlyMap<string, KitOption>>();
|
|
153
|
+
const EMPTY_OPTIONS_MAP: ReadonlyMap<string, KitOption> = new Map();
|
|
119
154
|
|
|
120
155
|
/** 开发环境提示一次(生产构建 / 无 process 时静默) */
|
|
121
156
|
function warnDuplicateOption(value: string): void {
|
|
@@ -128,9 +163,12 @@ function warnDuplicateOption(value: string): void {
|
|
|
128
163
|
/**
|
|
129
164
|
* 选项归一。value 按字符串比较(与 sameValue 同口径)去重:重复的第二项起直接丢弃,首项为准
|
|
130
165
|
* (不做「标记禁用」:重复项留在列表里会让选中态同时命中多项、键盘游标也停在重复键上);开发环境 warn 一次。
|
|
166
|
+
* 数组引用经 WeakMap 缓存,避免重绘与过滤循环重复归一。
|
|
131
167
|
*/
|
|
132
168
|
export function optionsOf(raw: unknown): KitOption[] {
|
|
133
169
|
if (!Array.isArray(raw)) return [];
|
|
170
|
+
const cached = OPTIONS_CACHE.get(raw);
|
|
171
|
+
if (cached !== undefined) return cached as KitOption[];
|
|
134
172
|
const out: KitOption[] = [];
|
|
135
173
|
const seen = new Set<string>();
|
|
136
174
|
const push = (opt: KitOption): void => {
|
|
@@ -166,18 +204,46 @@ export function optionsOf(raw: unknown): KitOption[] {
|
|
|
166
204
|
...(tone ? { tone } : {}),
|
|
167
205
|
...(unknownTone ? { unknown: true } : {}),
|
|
168
206
|
...(rec.disabled === true ? { disabled: true } : {}),
|
|
207
|
+
...(typeof rec.count === 'number' && Number.isInteger(rec.count) && rec.count >= 0 ? { count: rec.count } : {}),
|
|
208
|
+
...(typeof rec.desc === 'string' && rec.desc !== '' ? { desc: rec.desc } : {}),
|
|
209
|
+
...(typeof rec.description === 'string' && rec.description !== '' ? { description: rec.description } : {}),
|
|
210
|
+
...(typeof rec.group === 'string' && rec.group !== '' ? { group: rec.group } : {}),
|
|
169
211
|
});
|
|
170
212
|
}
|
|
213
|
+
OPTIONS_CACHE.set(raw, out);
|
|
214
|
+
OPTIONS_CACHE.set(out, out);
|
|
171
215
|
return out;
|
|
172
216
|
}
|
|
173
217
|
|
|
218
|
+
/** 选项按 String(value) -> KitOption 的 O(1) 查表映射(随数组引用 WeakMap 缓存) */
|
|
219
|
+
export function optionsMapOf(raw: unknown): ReadonlyMap<string, KitOption> {
|
|
220
|
+
if (!Array.isArray(raw)) return EMPTY_OPTIONS_MAP;
|
|
221
|
+
const cached = OPTIONS_MAP_CACHE.get(raw);
|
|
222
|
+
if (cached !== undefined) return cached;
|
|
223
|
+
const list = optionsOf(raw);
|
|
224
|
+
const cachedByList = OPTIONS_MAP_CACHE.get(list);
|
|
225
|
+
if (cachedByList !== undefined) {
|
|
226
|
+
OPTIONS_MAP_CACHE.set(raw, cachedByList);
|
|
227
|
+
return cachedByList;
|
|
228
|
+
}
|
|
229
|
+
const map = new Map<string, KitOption>();
|
|
230
|
+
for (const opt of list) {
|
|
231
|
+
if (opt.value === undefined || opt.value === null) continue;
|
|
232
|
+
const key = String(opt.value);
|
|
233
|
+
if (!map.has(key)) map.set(key, opt);
|
|
234
|
+
}
|
|
235
|
+
OPTIONS_MAP_CACHE.set(raw, map);
|
|
236
|
+
OPTIONS_MAP_CACHE.set(list, map);
|
|
237
|
+
return map;
|
|
238
|
+
}
|
|
239
|
+
|
|
174
240
|
/** 值比较统一走字符串:`1` / `'1'` / `true` / `'true'` 各自互认,option.value 为数字时页面传字符串也命中 */
|
|
175
241
|
export function sameValue(a: unknown, b: unknown): boolean {
|
|
176
242
|
return String(a) === String(b);
|
|
177
243
|
}
|
|
178
244
|
|
|
179
245
|
export function optionsKey(options: readonly KitOption[]): string {
|
|
180
|
-
return JSON.stringify(options.map((o) => [String(o.value), o.label, o.disabled === true, o.icon ?? '', o.aria_label ?? '']));
|
|
246
|
+
return JSON.stringify(options.map((o) => [String(o.value), o.label, o.disabled === true, o.icon ?? '', o.aria_label ?? '', o.count ?? -1]));
|
|
181
247
|
}
|
|
182
248
|
|
|
183
249
|
export function toneOf(raw: unknown, fallback: KitTone): KitTone;
|
|
@@ -191,13 +257,79 @@ export function toneOf(raw: unknown, fallback: KitTone | null): KitTone | null {
|
|
|
191
257
|
// ── 显示文字(Text / Tag 共用)──────────────────────────────────
|
|
192
258
|
|
|
193
259
|
const FALLBACK_LOCALE = 'zh-CN';
|
|
260
|
+
const FORMATTER_BY_LOCALE = new Map<string, SomaFormatter | null>();
|
|
261
|
+
const FORMAT_RUNNER_CACHE = new Map<string, (value: unknown, raw: string) => string>();
|
|
194
262
|
|
|
195
263
|
function formatterOf(locale: string): SomaFormatter | null {
|
|
264
|
+
if (FORMATTER_BY_LOCALE.has(locale)) return FORMATTER_BY_LOCALE.get(locale) ?? null;
|
|
265
|
+
let fmt: SomaFormatter | null = null;
|
|
196
266
|
try {
|
|
197
|
-
|
|
267
|
+
fmt = createFormatter({ locale, fallbackLocale: FALLBACK_LOCALE, placeholder: '', now: () => Date.now() });
|
|
198
268
|
} catch {
|
|
199
|
-
|
|
269
|
+
fmt = null;
|
|
200
270
|
}
|
|
271
|
+
FORMATTER_BY_LOCALE.set(locale, fmt);
|
|
272
|
+
return fmt;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function formatRunnerOf(locale: string, format: string): (value: unknown, raw: string) => string {
|
|
276
|
+
const effectiveLocale = locale === '' ? FALLBACK_LOCALE : locale;
|
|
277
|
+
const cacheKey = `${effectiveLocale}\0${format}`;
|
|
278
|
+
const hit = FORMAT_RUNNER_CACHE.get(cacheKey);
|
|
279
|
+
if (hit !== undefined) return hit;
|
|
280
|
+
const fmt = formatterOf(effectiveLocale);
|
|
281
|
+
let runner: (value: unknown, raw: string) => string;
|
|
282
|
+
if (!fmt) {
|
|
283
|
+
runner = (_v, raw) => raw;
|
|
284
|
+
} else {
|
|
285
|
+
const [kind, arg] = format.split(':');
|
|
286
|
+
switch (kind) {
|
|
287
|
+
case 'number':
|
|
288
|
+
runner = (v, raw) => fmt.number(v) || raw;
|
|
289
|
+
break;
|
|
290
|
+
case 'percent':
|
|
291
|
+
runner = (v, raw) => fmt.percent(v) || raw;
|
|
292
|
+
break;
|
|
293
|
+
case 'currency':
|
|
294
|
+
runner = arg ? (v, raw) => fmt.currency(v, { currency: arg }) || raw : (_v, raw) => raw;
|
|
295
|
+
break;
|
|
296
|
+
case 'date':
|
|
297
|
+
runner = (v, raw) => fmt.date(v, { style: 'medium', time: 'none' }) || raw;
|
|
298
|
+
break;
|
|
299
|
+
case 'datetime':
|
|
300
|
+
runner = (v, raw) => fmt.date(v, { style: 'medium', time: 'short' }) || raw;
|
|
301
|
+
break;
|
|
302
|
+
case 'relative':
|
|
303
|
+
runner = (v, raw) => fmt.relative(v) || raw;
|
|
304
|
+
break;
|
|
305
|
+
case 'bytes':
|
|
306
|
+
runner = (v, raw) => {
|
|
307
|
+
const n = Number(v);
|
|
308
|
+
return Number.isFinite(n) ? kitFileSizeText(fmt.bytes(n)) : raw;
|
|
309
|
+
};
|
|
310
|
+
break;
|
|
311
|
+
case 'duration': {
|
|
312
|
+
const unit = arg === 'ms' || arg === 's' || arg === 'min' || arg === 'h' || arg === 'd' ? arg : 's';
|
|
313
|
+
runner = (v, raw) => {
|
|
314
|
+
const n = Number(v);
|
|
315
|
+
return Number.isFinite(n) ? fmt.duration(n, unit) : raw;
|
|
316
|
+
};
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
default:
|
|
320
|
+
runner = (_v, raw) => raw;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const safeRunner = (v: unknown, raw: string): string => {
|
|
325
|
+
try {
|
|
326
|
+
return runner(v, raw);
|
|
327
|
+
} catch {
|
|
328
|
+
return raw;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
FORMAT_RUNNER_CACHE.set(cacheKey, safeRunner);
|
|
332
|
+
return safeRunner;
|
|
201
333
|
}
|
|
202
334
|
|
|
203
335
|
/**
|
|
@@ -208,27 +340,7 @@ function formatterOf(locale: string): SomaFormatter | null {
|
|
|
208
340
|
export function formatValue(value: unknown, format: string, locale: string): string {
|
|
209
341
|
const raw = Array.isArray(value) ? value.map((v) => String(v)).join(', ') : String(value);
|
|
210
342
|
if (format === '') return raw;
|
|
211
|
-
|
|
212
|
-
if (!fmt) return raw;
|
|
213
|
-
const [kind, arg] = format.split(':');
|
|
214
|
-
try {
|
|
215
|
-
switch (kind) {
|
|
216
|
-
case 'number': return fmt.number(value) || raw;
|
|
217
|
-
case 'percent': return fmt.percent(value) || raw;
|
|
218
|
-
case 'currency': return arg ? fmt.currency(value, { currency: arg }) || raw : raw;
|
|
219
|
-
case 'date': return fmt.date(value, { style: 'medium', time: 'none' }) || raw;
|
|
220
|
-
case 'datetime': return fmt.date(value, { style: 'medium', time: 'short' }) || raw;
|
|
221
|
-
case 'relative': return fmt.relative(value) || raw;
|
|
222
|
-
case 'bytes': return Number.isFinite(Number(value)) ? fmt.bytes(Number(value)) : raw;
|
|
223
|
-
case 'duration': {
|
|
224
|
-
const unit = arg === 'ms' || arg === 's' || arg === 'min' || arg === 'h' || arg === 'd' ? arg : 's';
|
|
225
|
-
return Number.isFinite(Number(value)) ? fmt.duration(Number(value), unit) : raw;
|
|
226
|
-
}
|
|
227
|
-
default: return raw;
|
|
228
|
-
}
|
|
229
|
-
} catch {
|
|
230
|
-
return raw;
|
|
231
|
-
}
|
|
343
|
+
return formatRunnerOf(locale, format)(value, raw);
|
|
232
344
|
}
|
|
233
345
|
|
|
234
346
|
export interface DisplayResult {
|
|
@@ -259,11 +371,15 @@ export function displayOf(
|
|
|
259
371
|
return { text: placeholder, option: null };
|
|
260
372
|
}
|
|
261
373
|
if (options.length > 0) {
|
|
374
|
+
const map = optionsMapOf(options);
|
|
262
375
|
if (Array.isArray(value)) {
|
|
263
|
-
const labels = value.map((v) =>
|
|
376
|
+
const labels = value.map((v) => {
|
|
377
|
+
const hit = (v !== undefined && v !== null ? map.get(String(v)) : undefined) ?? options.find((o) => sameValue(o.value, v));
|
|
378
|
+
return hit?.label ?? String(v);
|
|
379
|
+
});
|
|
264
380
|
return { text: labels.join(', '), option: null };
|
|
265
381
|
}
|
|
266
|
-
const hit = options.find((o) => sameValue(o.value, value)) ?? null;
|
|
382
|
+
const hit = map.get(String(value)) ?? options.find((o) => sameValue(o.value, value)) ?? null;
|
|
267
383
|
if (hit) return { text: hit.label, option: hit };
|
|
268
384
|
}
|
|
269
385
|
return { text: formatValue(value, format, locale), option: null };
|
|
@@ -279,13 +395,42 @@ export function findRoot(host: HTMLElement): HTMLElement {
|
|
|
279
395
|
}
|
|
280
396
|
|
|
281
397
|
/**
|
|
282
|
-
* 整块不渲染:收起组件根;根在没有标题的看板面板里(`data-kit-board-panel="bare"
|
|
398
|
+
* 整块不渲染:收起组件根;根在没有标题的看板面板里(`data-kit-board-panel="bare"`)时,面板壳在「面板里没有别的可见组件」时一并收起 / 恢复,不留空白圆角条。
|
|
399
|
+
* 面板里还有别的非空组件(如被并进同一面板的门控卡)时只收起自己的根,面板与其它组件不动。
|
|
283
400
|
* 带标题的面板壳不动(标题行仍在,空态由组件自己画)。
|
|
284
401
|
*/
|
|
285
402
|
export function kitCollapseBlock(root: HTMLElement, collapsed: boolean): void {
|
|
286
403
|
root.hidden = collapsed;
|
|
287
|
-
const panel = root.closest<HTMLElement>(
|
|
288
|
-
if (panel
|
|
404
|
+
const panel = root.closest<HTMLElement>(`[${KIT_ATTR_BOARD_PANEL}="bare"]`);
|
|
405
|
+
if (panel === null) return;
|
|
406
|
+
panel.hidden = collapsed && !panelHasOtherVisible(panel, root);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 概况条的统计一侧整体为空时给概况条标 `data-kit-hero-solo`(统计块与细线随之收起、结论占满整行,样式在多块看板壳的类串里);统计块自报空 / 非空后调用。
|
|
411
|
+
* 统计一侧 = 概况条里 `data-kit-hero-stats` 列内的全部组件宿主,全部带 data-kit-summary-empty 才算整体为空。
|
|
412
|
+
*/
|
|
413
|
+
export function kitSyncHeroSolo(host: HTMLElement): void {
|
|
414
|
+
const hero = host.closest<HTMLElement>(`[${KIT_ATTR_SLOT}="hero"]`);
|
|
415
|
+
const col = hero?.querySelector<HTMLElement>(`[${KIT_ATTR_HERO_STATS}]`) ?? null;
|
|
416
|
+
if (hero === null || col === null) return;
|
|
417
|
+
const members = Array.from(col.querySelectorAll<HTMLElement>('[data-soma-component]'));
|
|
418
|
+
const empty = members.length > 0 && members.every((m) => m.hasAttribute(KIT_ATTR_SUMMARY_EMPTY));
|
|
419
|
+
if (empty) hero.setAttribute(KIT_ATTR_HERO_SOLO, '');
|
|
420
|
+
else hero.removeAttribute(KIT_ATTR_HERO_SOLO);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** 面板里除 root 所在组件外,是否还有可见(根未收起)的组件宿主 */
|
|
424
|
+
function panelHasOtherVisible(panel: HTMLElement, root: HTMLElement): boolean {
|
|
425
|
+
for (const host of Array.from(panel.querySelectorAll<HTMLElement>('[data-soma-component]'))) {
|
|
426
|
+
if (host.contains(root) || root.contains(host)) continue;
|
|
427
|
+
const own = host.querySelector<HTMLElement>('[data-soma-scoped-id="root"]');
|
|
428
|
+
if (own === null && host.children.length === 0) continue;
|
|
429
|
+
let shown = own === null || !own.hidden;
|
|
430
|
+
for (let e: HTMLElement | null = host; shown && e !== null && e !== panel; e = e.parentElement) if (e.hidden) shown = false;
|
|
431
|
+
if (shown) return true;
|
|
432
|
+
}
|
|
433
|
+
return false;
|
|
289
434
|
}
|
|
290
435
|
|
|
291
436
|
export function setBoolAttr(el: Element, name: string, on: boolean): void {
|
|
@@ -298,6 +443,142 @@ export function setAttr(el: Element, name: string, value: string): void {
|
|
|
298
443
|
else el.setAttribute(name, value);
|
|
299
444
|
}
|
|
300
445
|
|
|
446
|
+
/** 同时写原生 hidden 与 Tailwind `hidden` 类,防止 `.flex` / `.grid` 覆盖 `[hidden]` */
|
|
447
|
+
export function toggleKitHidden(el: HTMLElement, hide: boolean): void {
|
|
448
|
+
el.hidden = hide;
|
|
449
|
+
el.classList.toggle('hidden', hide);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** 重绘前后保持滚动容器位置(stickBottom 为真时贴底) */
|
|
453
|
+
export function preserveKitScroll<T>(
|
|
454
|
+
scroller: HTMLElement | null | undefined,
|
|
455
|
+
mutate: () => T,
|
|
456
|
+
opts?: { stickBottom?: boolean },
|
|
457
|
+
): T {
|
|
458
|
+
const top = scroller ? scroller.scrollTop : 0;
|
|
459
|
+
const left = scroller ? scroller.scrollLeft : 0;
|
|
460
|
+
const out = mutate();
|
|
461
|
+
if (scroller) {
|
|
462
|
+
if (opts?.stickBottom) {
|
|
463
|
+
scroller.scrollTop = scroller.scrollHeight;
|
|
464
|
+
} else {
|
|
465
|
+
scroller.scrollTop = top;
|
|
466
|
+
scroller.scrollLeft = left;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** 安全同步输入框文本:值同跳过、聚焦组词期保护 IME、聚焦更新后按末尾偏移还原光标 */
|
|
473
|
+
export function syncKitTextValue(
|
|
474
|
+
el: HTMLInputElement | HTMLTextAreaElement,
|
|
475
|
+
next: string,
|
|
476
|
+
composing = false,
|
|
477
|
+
): void {
|
|
478
|
+
if (el.value === next) return;
|
|
479
|
+
const focused = el.ownerDocument.activeElement === el;
|
|
480
|
+
if (composing && focused) return;
|
|
481
|
+
if (!focused) {
|
|
482
|
+
el.value = next;
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const tail = el.value.length - (el.selectionEnd ?? el.value.length);
|
|
486
|
+
el.value = next;
|
|
487
|
+
try {
|
|
488
|
+
const pos = Math.max(0, next.length - tail);
|
|
489
|
+
el.setSelectionRange(pos, pos);
|
|
490
|
+
} catch {
|
|
491
|
+
// 不支持 setSelectionRange 的输入类型静默忽略
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* 基于专用属性 `data-kit-rkey` 原地调和子节点(避免与业务组件 `data-kit-key` 冲突):
|
|
497
|
+
* 同 rkey 节点不摘除重造(保住 `:focus` 与 CSS 过渡),仅摘除不在本轮列表的节点并按序对齐。
|
|
498
|
+
*/
|
|
499
|
+
export function reconcileKeyedElements<T>(
|
|
500
|
+
container: HTMLElement,
|
|
501
|
+
items: readonly T[],
|
|
502
|
+
keyOf: (item: T, index: number) => string,
|
|
503
|
+
create: (item: T, index: number) => HTMLElement,
|
|
504
|
+
update: (el: HTMLElement, item: T, index: number) => void,
|
|
505
|
+
): void {
|
|
506
|
+
const active = container.ownerDocument.activeElement;
|
|
507
|
+
const keepFocus = active !== null && active.nodeType === 1 && container.contains(active) ? (active as HTMLElement) : null;
|
|
508
|
+
const isTextControl = keepFocus !== null && (keepFocus.tagName === 'INPUT' || keepFocus.tagName === 'TEXTAREA');
|
|
509
|
+
let selStart: number | null = null;
|
|
510
|
+
let selEnd: number | null = null;
|
|
511
|
+
let selDir: 'forward' | 'backward' | 'none' | undefined;
|
|
512
|
+
if (isTextControl) {
|
|
513
|
+
try {
|
|
514
|
+
const ctrl = keepFocus as HTMLInputElement | HTMLTextAreaElement;
|
|
515
|
+
selStart = ctrl.selectionStart;
|
|
516
|
+
selEnd = ctrl.selectionEnd;
|
|
517
|
+
selDir = ctrl.selectionDirection ?? undefined;
|
|
518
|
+
} catch {
|
|
519
|
+
// 不支持选区读取的输入类型静默忽略
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
for (const node of Array.from(container.childNodes)) {
|
|
524
|
+
if (node.nodeType !== 1) node.remove();
|
|
525
|
+
}
|
|
526
|
+
const pool = new Map<string, HTMLElement>();
|
|
527
|
+
const orphans: Element[] = [];
|
|
528
|
+
for (const child of Array.from(container.children)) {
|
|
529
|
+
const k = child.getAttribute(KIT_ATTR_RKEY);
|
|
530
|
+
if (k !== null && !pool.has(k)) {
|
|
531
|
+
pool.set(k, child as HTMLElement);
|
|
532
|
+
} else {
|
|
533
|
+
orphans.push(child);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
for (const orphan of orphans) orphan.remove();
|
|
537
|
+
|
|
538
|
+
const resolved: Array<{ el: HTMLElement; item: T; index: number; key: string }> = [];
|
|
539
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
540
|
+
const item = items[i]!;
|
|
541
|
+
const key = keyOf(item, i);
|
|
542
|
+
let el = pool.get(key);
|
|
543
|
+
if (el !== undefined) {
|
|
544
|
+
pool.delete(key);
|
|
545
|
+
} else {
|
|
546
|
+
el = create(item, i);
|
|
547
|
+
el.setAttribute(KIT_ATTR_RKEY, key);
|
|
548
|
+
}
|
|
549
|
+
resolved.push({ el, item, index: i, key });
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
for (const stale of pool.values()) stale.remove();
|
|
553
|
+
|
|
554
|
+
for (let i = 0; i < resolved.length; i += 1) {
|
|
555
|
+
const { el, item, index, key } = resolved[i]!;
|
|
556
|
+
const ref = container.children[i] ?? null;
|
|
557
|
+
if (ref !== el) {
|
|
558
|
+
container.insertBefore(el, ref);
|
|
559
|
+
}
|
|
560
|
+
update(el, item, index);
|
|
561
|
+
if (el.getAttribute(KIT_ATTR_RKEY) !== key) {
|
|
562
|
+
el.setAttribute(KIT_ATTR_RKEY, key);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (keepFocus !== null && keepFocus.isConnected && container.ownerDocument.activeElement !== keepFocus) {
|
|
567
|
+
keepFocus.focus({ preventScroll: true });
|
|
568
|
+
if (
|
|
569
|
+
isTextControl
|
|
570
|
+
&& selStart !== null
|
|
571
|
+
&& selEnd !== null
|
|
572
|
+
) {
|
|
573
|
+
try {
|
|
574
|
+
(keepFocus as HTMLInputElement | HTMLTextAreaElement).setSelectionRange(selStart, selEnd, selDir);
|
|
575
|
+
} catch {
|
|
576
|
+
// 不支持 setSelectionRange 的输入类型静默忽略
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
301
582
|
/** 上一次由 applyCommon 写进 aria-describedby 的 id 串(合并时只替换自己写的那部分,不抹掉控件自带的说明 id) */
|
|
302
583
|
const APPLIED_DESCRIBEDBY = new WeakMap<Element, string[]>();
|
|
303
584
|
|
|
@@ -356,16 +637,16 @@ function applyAria(el: Element, p: KitProps): void {
|
|
|
356
637
|
el.removeAttribute('aria-required');
|
|
357
638
|
el.removeAttribute('aria-invalid');
|
|
358
639
|
el.removeAttribute('aria-errormessage');
|
|
359
|
-
setAttr(el,
|
|
640
|
+
setAttr(el, KIT_ATTR_INVALID, bool(p.invalid) ? 'true' : '');
|
|
360
641
|
} else {
|
|
361
642
|
applyValidity(el, p);
|
|
362
|
-
el.removeAttribute(
|
|
643
|
+
el.removeAttribute(KIT_ATTR_INVALID);
|
|
363
644
|
}
|
|
364
645
|
mergeDescribedby(el, str(p.aria_describedby, str(p.describedby)));
|
|
365
646
|
}
|
|
366
647
|
|
|
367
648
|
/** group 根上的无效标记(ARIA 不允许 group 带 aria-invalid;表单据此找首个出错字段) */
|
|
368
|
-
export
|
|
649
|
+
export { KIT_ATTR_INVALID as KIT_INVALID_MARK } from '../shared/dom-attrs';
|
|
369
650
|
|
|
370
651
|
/** 必填 / 无效 / 错误消息关联三个校验属性(只给支持它们的角色:原生输入、radiogroup、combobox、textbox 等) */
|
|
371
652
|
function applyValidity(el: Element, p: KitProps): void {
|
|
@@ -438,6 +719,8 @@ export interface KitApi {
|
|
|
438
719
|
emit(name: string, payload?: unknown): void;
|
|
439
720
|
props(): KitProps;
|
|
440
721
|
host: HTMLElement;
|
|
722
|
+
/** 实例 id(优先取 core 传入的 ctx.instanceId,回退宿主 data-soma-id) */
|
|
723
|
+
readonly instanceId?: string;
|
|
441
724
|
/** 契约 `services` 白名单过滤后的运行时服务(虚拟滚动取 `engines.virtual`) */
|
|
442
725
|
services?: Record<string, unknown>;
|
|
443
726
|
/** 请求组件重绘(等价于触发新一轮全量 render) */
|
|
@@ -468,10 +751,11 @@ export interface KitView {
|
|
|
468
751
|
|
|
469
752
|
export type KitViewSetup = (api: KitApi) => KitView;
|
|
470
753
|
|
|
471
|
-
|
|
472
|
-
|
|
754
|
+
export const KIT_ASYNC_ABORTED = Symbol.for('soma.kit.asyncAborted');
|
|
755
|
+
|
|
756
|
+
/** 包装异步引擎调用:当 await 返回时组件已卸载(!isAlive())则自动销毁返回实例并抛出取消哨兵以释放调用栈 finally 锁(createKitController 外层统一兜底静默消化);同存活期内的渲染轮次交组件经 renderApi.isCurrent() 自判 */
|
|
757
|
+
export function guardAsyncServices(
|
|
473
758
|
services: Record<string, unknown> | undefined,
|
|
474
|
-
isCurrent: () => boolean,
|
|
475
759
|
isAlive: () => boolean,
|
|
476
760
|
): Record<string, unknown> | undefined {
|
|
477
761
|
if (!services || typeof services !== 'object') return services;
|
|
@@ -487,18 +771,23 @@ function guardAsyncServices(
|
|
|
487
771
|
proxyPort[m] = (...args: unknown[]) => {
|
|
488
772
|
const res = (fn as (...a: unknown[]) => unknown).apply(port, args);
|
|
489
773
|
if (res && typeof (res as Promise<unknown>).then === 'function') {
|
|
490
|
-
return (res as Promise<unknown>).then(
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
(val as { dispose
|
|
774
|
+
return (res as Promise<unknown>).then(
|
|
775
|
+
(val) => {
|
|
776
|
+
if (!isAlive()) {
|
|
777
|
+
if (val && typeof (val as { dispose?: () => void }).dispose === 'function') {
|
|
778
|
+
(val as { dispose: () => void }).dispose();
|
|
779
|
+
}
|
|
780
|
+
throw KIT_ASYNC_ABORTED;
|
|
781
|
+
}
|
|
782
|
+
return val;
|
|
783
|
+
},
|
|
784
|
+
(err) => {
|
|
785
|
+
if (!isAlive()) {
|
|
786
|
+
throw KIT_ASYNC_ABORTED;
|
|
494
787
|
}
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return new Promise<never>(() => {});
|
|
499
|
-
}
|
|
500
|
-
return val;
|
|
501
|
-
});
|
|
788
|
+
throw err;
|
|
789
|
+
},
|
|
790
|
+
);
|
|
502
791
|
}
|
|
503
792
|
return res;
|
|
504
793
|
};
|
|
@@ -522,7 +811,110 @@ export function onKitControllerMount(hook: (host: HTMLElement) => void): void {
|
|
|
522
811
|
* onMount 取根、挂事件并首绘,onPropsChange 全量重绘,onUnmount 统一执行清理函数。
|
|
523
812
|
* 异步 render 由骨架统一处理后发先至(旧结果自动丢弃);handle 由骨架挂到 core 读取位置。
|
|
524
813
|
*/
|
|
525
|
-
|
|
814
|
+
/**
|
|
815
|
+
* 骨架的组件契约选项(主题流水线):组件只声明自己知道的事实,骨架在挂载时统一写到模板最外层根上(不覆盖已有属性),
|
|
816
|
+
* 各组件不必在每个文件里重复「找外层根 + 自报」。可以是函数:按当轮入参决定(如 Card 有无标题都是对象面,但组件按用途有别)。
|
|
817
|
+
*/
|
|
818
|
+
export interface KitControllerOptions {
|
|
819
|
+
/** 根节点自报(层级角色、元素部件、区域作用域);数据状态随数据变,组件在 render 里用 kitMarkDataState 写 */
|
|
820
|
+
readonly self?: KitSelfReportAttrs | ((p: KitProps) => KitSelfReportAttrs | undefined);
|
|
821
|
+
/**
|
|
822
|
+
* 模板内部节点的自报:[选择器(在组件宿主内取第一个匹配), 自报事实]。骨架每次绘制前写(经 kitReportSelf:按当前模式,旧版只写区域作用域;
|
|
823
|
+
* 已有的层级角色 / 元素部件不覆盖)。用它代替在静态模板串里拼 kitSelfAttrs——模板在组件创建时求值,那时的模式不可靠。
|
|
824
|
+
* 选择器按模板内的 data-soma-id 写时用 kitSid(id)(同时认核心改写后的 data-soma-scoped-id)。
|
|
825
|
+
*/
|
|
826
|
+
readonly selfParts?: readonly KitSelfPart[];
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* 一条模板内部节点的自报:缺省取第一个匹配;第三项写 'all' 时写全部匹配(按行重复的 <template data-soma-role="item"> 里的节点用)。
|
|
831
|
+
* 匹配范围 = 组件宿主内(不进嵌套的别的组件宿主)+ 本组件挂到浮层端口里的面板(面板打开时不在宿主的后代中,见 popup.ts#queryAllWithDropdowns)。
|
|
832
|
+
*/
|
|
833
|
+
export type KitSelfPart =
|
|
834
|
+
| readonly [selector: string, report: KitSelfReportAttrs]
|
|
835
|
+
| readonly [selector: string, report: KitSelfReportAttrs, match: 'all'];
|
|
836
|
+
|
|
837
|
+
/** 模板内节点的选择器:核心挂载后模板内的 data-soma-id 可能改写成 data-soma-scoped-id,两种都认 */
|
|
838
|
+
export function kitSid(id: string): string {
|
|
839
|
+
return `[data-soma-scoped-id="${id}"], [data-soma-id="${id}"]`;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/** 模板根(data-soma-id="root")下按子路径找的节点(没有 id 的模板节点用):path 如 'button > span' */
|
|
843
|
+
export function kitRootChild(path: string): string {
|
|
844
|
+
return `[data-soma-scoped-id="root"] > ${path}, [data-soma-id="root"] > ${path}`;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/** 节点属于宿主自己(不在宿主里嵌套的别的组件宿主里;插槽里收养的子组件可能有同名 id) */
|
|
848
|
+
function ownedBy(host: HTMLElement, el: Element): boolean {
|
|
849
|
+
const owner = el.parentElement?.closest('[data-soma-component]') ?? null;
|
|
850
|
+
return owner === null || owner === host || !host.contains(owner);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** 宿主内(含本宿主挂到浮层端口里的面板)全部属于宿主自己的匹配节点,宿主内的在前 */
|
|
854
|
+
function ownNodes(host: HTMLElement, sel: string): Element[] {
|
|
855
|
+
const inHost = Array.from(host.querySelectorAll(sel)).filter((el) => ownedBy(host, el));
|
|
856
|
+
// 端口里的面板:锚点在本宿主内的面板整块算本宿主的(面板里嵌套的别的组件宿主照样排除)
|
|
857
|
+
const ported = queryAllWithDropdowns(host, sel).filter((el) => !host.contains(el) && (el.parentElement?.closest('[data-soma-component]') ?? null) === null);
|
|
858
|
+
return [...inHost, ...ported];
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** 宿主内第一个匹配、且不在嵌套的别的组件宿主里的节点(命中即止,宿主内找到就不再扫浮层端口,避免分配全量数组) */
|
|
862
|
+
function ownNode(host: HTMLElement, sel: string): Element | null {
|
|
863
|
+
const inHost = host.querySelectorAll(sel);
|
|
864
|
+
for (let i = 0; i < inHost.length; i += 1) {
|
|
865
|
+
const el = inHost[i]!;
|
|
866
|
+
if (ownedBy(host, el)) return el;
|
|
867
|
+
}
|
|
868
|
+
const ported = queryAllWithDropdowns(host, sel);
|
|
869
|
+
for (let i = 0; i < ported.length; i += 1) {
|
|
870
|
+
const el = ported[i]!;
|
|
871
|
+
if (!host.contains(el) && (el.parentElement?.closest('[data-soma-component]') ?? null) === null) return el;
|
|
872
|
+
}
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** 按 selfParts 写一遍模板内部节点的自报(经 kitReportSelf:按当前模式,旧版只写区域作用域) */
|
|
877
|
+
function writeSelfParts(host: HTMLElement, parts: readonly KitSelfPart[]): void {
|
|
878
|
+
// 旧版只写区域作用域:不带区域作用域的项在旧版下什么也不写,先判断模式,不为它们查询节点(每次绘制都会走到这里)
|
|
879
|
+
const next = kitIsNextRuntime();
|
|
880
|
+
for (const part of parts) {
|
|
881
|
+
const [sel, report] = part;
|
|
882
|
+
if (!next && report.scope === undefined) continue;
|
|
883
|
+
if (part[2] === 'all') for (const el of ownNodes(host, sel)) kitReportSelf(el, report);
|
|
884
|
+
else kitReportSelf(ownNode(host, sel), report);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* 不经骨架的组件(或骨架之外的绘制时机,如核心按行重画之后)对全部匹配节点写自报:口径同 selfParts 的 'all'。
|
|
890
|
+
* 旧版只写区域作用域(kitReportSelf):旧版且 report 不带区域作用域时什么也不写,直接返回空、不查询节点。
|
|
891
|
+
* 返回本次写到的节点(调用方要对同一批节点再做别的事时复用,不必再查一遍)。
|
|
892
|
+
*/
|
|
893
|
+
export function kitReportSelfAll(host: HTMLElement, selector: string, report: KitSelfReportAttrs): readonly Element[] {
|
|
894
|
+
if (report.scope === undefined && !kitIsNextRuntime()) return [];
|
|
895
|
+
const nodes = ownNodes(host, selector);
|
|
896
|
+
for (const el of nodes) kitReportSelf(el, report);
|
|
897
|
+
return nodes;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* 面板挂到浮层端口时补写自报:首次绘制时面板可能还没建出或已不在宿主里,挂出那一刻按宿主登记的 selfParts 再写一遍。
|
|
902
|
+
* 登记在挂载时、撤销在卸载时(SELF_PART_WRITERS);从锚点往上逐个组件宿主找登记(嵌套组件各写各的)。
|
|
903
|
+
*/
|
|
904
|
+
const SELF_PART_WRITERS = new WeakMap<HTMLElement, () => void>();
|
|
905
|
+
let panelHookOn = false;
|
|
906
|
+
/** 首次有组件登记时才接到 popup.ts 的挂出钩子(不在模块顶层调:避免与 popup.ts 的加载次序相依) */
|
|
907
|
+
function ensurePanelHook(): void {
|
|
908
|
+
if (panelHookOn) return;
|
|
909
|
+
panelHookOn = true;
|
|
910
|
+
onKitPanelMounted((anchor) => {
|
|
911
|
+
for (let h: HTMLElement | null = anchor.closest<HTMLElement>('[data-soma-component]'); h !== null; h = h.parentElement?.closest<HTMLElement>('[data-soma-component]') ?? null) {
|
|
912
|
+
SELF_PART_WRITERS.get(h)?.();
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
export function createKitController(setup: KitViewSetup | KitView, options: KitControllerOptions = {}): SomaComponentControllerFactory {
|
|
526
918
|
const setupFn: KitViewSetup | null = typeof setup === 'function' ? setup : (setup && typeof setup === 'object' && typeof (setup as KitView).render === 'function' ? () => setup as KitView : null);
|
|
527
919
|
if (!setupFn) {
|
|
528
920
|
throw new Error('[soma-kit] createKitController 只接受 (api: KitApi) => KitView 构造函数');
|
|
@@ -534,6 +926,12 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
534
926
|
let seq = 0;
|
|
535
927
|
let view: KitView;
|
|
536
928
|
const readProps = (): KitProps => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
929
|
+
const resolveInstanceId = (): string | undefined => {
|
|
930
|
+
const raw = (ctx as { instanceId?: unknown }).instanceId;
|
|
931
|
+
if (typeof raw === 'string' && raw !== '') return raw;
|
|
932
|
+
const attr = ctx.host?.getAttribute?.('data-soma-id');
|
|
933
|
+
return typeof attr === 'string' && attr !== '' ? attr : undefined;
|
|
934
|
+
};
|
|
537
935
|
const applyPerm = (): void => {
|
|
538
936
|
const p = readProps();
|
|
539
937
|
if (p && 'permission' in p) {
|
|
@@ -550,11 +948,19 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
550
948
|
emit: api.emit,
|
|
551
949
|
props: readProps,
|
|
552
950
|
host: ctx.host,
|
|
553
|
-
|
|
951
|
+
get instanceId(): string | undefined { return resolveInstanceId(); },
|
|
952
|
+
services: guardAsyncServices(ctx.services, () => alive),
|
|
554
953
|
refresh: api.refresh,
|
|
555
954
|
isCurrent,
|
|
556
955
|
};
|
|
557
|
-
const
|
|
956
|
+
const props = readProps();
|
|
957
|
+
// 旧版(legacy)直接跳过全部自报 DOM 查询与回调计算;新模式下根节点自报放在 render 之前:
|
|
958
|
+
// 组件 render 里改写根的 className 不影响属性;self 返回值变了就改写,变成 undefined 时对称清掉自报上一次写的值。
|
|
959
|
+
if (kitIsNextRuntime()) {
|
|
960
|
+
if (options.self !== undefined) kitReportSelfTracked(kitOuterRoot(ctx.host, root), typeof options.self === 'function' ? options.self(props) : options.self);
|
|
961
|
+
if (options.selfParts !== undefined) writeSelfParts(ctx.host, options.selfParts);
|
|
962
|
+
}
|
|
963
|
+
const out = view.render(root, props, renderApi);
|
|
558
964
|
if (out && typeof (out as Promise<void>).then === 'function') {
|
|
559
965
|
(out as Promise<void>).catch(() => {});
|
|
560
966
|
}
|
|
@@ -564,6 +970,7 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
564
970
|
emit: (name, payload) => ctx.emit(name, payload),
|
|
565
971
|
props: readProps,
|
|
566
972
|
host: ctx.host,
|
|
973
|
+
get instanceId(): string | undefined { return resolveInstanceId(); },
|
|
567
974
|
services: ctx.services,
|
|
568
975
|
refresh: () => {
|
|
569
976
|
if (alive) {
|
|
@@ -585,26 +992,29 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
585
992
|
alive = true;
|
|
586
993
|
root = findRoot(ctx.host);
|
|
587
994
|
for (const hook of MOUNT_HOOKS) hook(ctx.host);
|
|
995
|
+
const parts = options.selfParts;
|
|
996
|
+
if (parts !== undefined) { ensurePanelHook(); SELF_PART_WRITERS.set(ctx.host, () => { if (alive && kitIsNextRuntime()) writeSelfParts(ctx.host, parts); }); }
|
|
588
997
|
offPerm = registerLivePermissionGate(applyPerm);
|
|
589
998
|
cleanup = view.attach?.(root, api);
|
|
590
999
|
paint();
|
|
591
1000
|
if (view.busyAware === true) {
|
|
592
|
-
lastBusy = kitBusyOf(api.props());
|
|
1001
|
+
lastBusy = kitBusyOf(api.props(), ctx.host);
|
|
593
1002
|
offBusy = onKitActionBusy(() => {
|
|
594
|
-
const now = kitBusyOf(api.props());
|
|
1003
|
+
const now = kitBusyOf(api.props(), ctx.host);
|
|
595
1004
|
if (now === lastBusy) return;
|
|
596
1005
|
lastBusy = now;
|
|
597
1006
|
paint();
|
|
598
|
-
});
|
|
1007
|
+
}, ctx.host);
|
|
599
1008
|
}
|
|
600
1009
|
},
|
|
601
1010
|
onPropsChange(): void {
|
|
602
|
-
if (view.busyAware === true) lastBusy = kitBusyOf(api.props());
|
|
1011
|
+
if (view.busyAware === true) lastBusy = kitBusyOf(api.props(), ctx.host);
|
|
603
1012
|
paint();
|
|
604
1013
|
},
|
|
605
1014
|
onUnmount(): void {
|
|
606
1015
|
alive = false;
|
|
607
1016
|
seq += 1;
|
|
1017
|
+
SELF_PART_WRITERS.delete(ctx.host);
|
|
608
1018
|
offPerm?.();
|
|
609
1019
|
offPerm = null;
|
|
610
1020
|
offBusy?.();
|
|
@@ -635,16 +1045,27 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
635
1045
|
// 角标是目标元素内的一个绝对定位子元素(目标补 `relative`):计数(超过 badge_max 显示 `99+`,≤0 与空不显示)或小红点。
|
|
636
1046
|
// 计数优先于小红点;文字走 textContent。Tag 已有 `dot`(文字前状态点),所以角标小红点统一叫 `badge_dot`。
|
|
637
1047
|
|
|
638
|
-
|
|
639
|
-
export const
|
|
1048
|
+
// 取值表 02 §2(Ant / Arco / TDesign):计数高 20 / 最小宽 20 / 横内边距 6 / 字 12 / 400 / 全圆;红点 6(size-status-dot,固定不随密度);与锚点间 2px 容器底色环
|
|
1049
|
+
export const BADGE_COUNT_CLASS = 'absolute -end-1 -top-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-danger px-1.5 text-xs font-normal text-danger-fg ring-2 ring-surface-current';
|
|
1050
|
+
export const BADGE_DOT_CLASS = 'absolute -end-0.5 -top-0.5 size-status-dot rounded-full bg-danger ring-2 ring-surface-current';
|
|
640
1051
|
const BADGE_ANCHOR_CLASS = 'relative';
|
|
641
1052
|
|
|
642
|
-
|
|
1053
|
+
/**
|
|
1054
|
+
* 计数角标的语气:danger = 提醒(未读、待办,缺省);primary = 状态计数(如「筛选」入口上的已设条件数——不是告警,不用红)。
|
|
1055
|
+
* 实心底只配同色 -fg 字(色彩角色配对)。
|
|
1056
|
+
* 状态计数挂在图标钮上(窄窗格「筛选」入口,14px 图标在 32px 钮心):小一档(16)并整枚外移到钮的右上角外侧,
|
|
1057
|
+
* 不压图标——图标必须完整可见(主会话裁决 2026-11-24:20 的提醒角标压在图标右上角,图标几乎看不见)
|
|
1058
|
+
*/
|
|
1059
|
+
const BADGE_COUNT_PRIMARY_CLASS = BADGE_COUNT_CLASS
|
|
1060
|
+
.replace('-end-1 -top-1', '-end-2 -top-2').replace('h-5 min-w-5', 'h-4 min-w-4')
|
|
1061
|
+
.replace('bg-danger', 'bg-primary').replace('text-danger-fg', 'text-primary-fg');
|
|
1062
|
+
export const KIT_BADGE_CLASS_CANDIDATES: readonly string[] = classCandidates(BADGE_COUNT_CLASS, BADGE_COUNT_PRIMARY_CLASS, BADGE_DOT_CLASS, BADGE_ANCHOR_CLASS, Object.values(KIT_SPIN_CLASS));
|
|
643
1063
|
|
|
644
1064
|
export const BADGE_PROPS = {
|
|
645
1065
|
badge: { type: 'string', default: '', desc: '右上角计数(超过 badge_max 显示 99+,0 / 空不显示;文字原样显示)' },
|
|
646
1066
|
badge_max: { type: 'number', default: 99, desc: '计数封顶值,超过显示「N+」' },
|
|
647
1067
|
badge_dot: { type: 'boolean', default: false, desc: '右上角小红点(badge 有值时以计数为准)' },
|
|
1068
|
+
badge_tone: { type: 'string', default: 'danger', desc: '计数角标语气 danger / primary:danger = 提醒(未读 / 待办,缺省);primary = 状态计数(如已设筛选条件数),不是告警;其它值按 danger' },
|
|
648
1069
|
} as const;
|
|
649
1070
|
|
|
650
1071
|
/** 角标文字:数字 ≤0 为空、超过 max 显示 `max+`,非数字原样 */
|
|
@@ -660,19 +1081,19 @@ export function paintBadge(host: HTMLElement, p: KitProps): boolean {
|
|
|
660
1081
|
const maxRaw = num(p.badge_max);
|
|
661
1082
|
const text = badgeText(p.badge, maxRaw !== null && maxRaw >= 1 ? Math.floor(maxRaw) : 99);
|
|
662
1083
|
const dot = text === '' && bool(p.badge_dot);
|
|
663
|
-
let el = Array.from(host.children).find((c) => c.hasAttribute(
|
|
1084
|
+
let el = Array.from(host.children).find((c) => c.hasAttribute(KIT_ATTR_BADGE)) as HTMLElement | undefined;
|
|
664
1085
|
if (text === '' && !dot) {
|
|
665
1086
|
el?.remove();
|
|
666
1087
|
return false;
|
|
667
1088
|
}
|
|
668
1089
|
if (!el) {
|
|
669
1090
|
el = document.createElement('span');
|
|
670
|
-
el.setAttribute(
|
|
1091
|
+
el.setAttribute(KIT_ATTR_BADGE, '');
|
|
671
1092
|
el.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_BADGE);
|
|
672
1093
|
host.appendChild(el);
|
|
673
1094
|
}
|
|
674
1095
|
if (text !== '') {
|
|
675
|
-
el.className = BADGE_COUNT_CLASS;
|
|
1096
|
+
el.className = p.badge_tone === 'primary' ? BADGE_COUNT_PRIMARY_CLASS : BADGE_COUNT_CLASS;
|
|
676
1097
|
el.textContent = text;
|
|
677
1098
|
el.removeAttribute('role');
|
|
678
1099
|
el.removeAttribute('aria-label');
|
|
@@ -774,7 +1195,7 @@ export interface KitTablistHandle {
|
|
|
774
1195
|
export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}): KitTablistHandle {
|
|
775
1196
|
const orientation = opts.orientation ?? 'horizontal';
|
|
776
1197
|
const activation = opts.activation ?? 'auto';
|
|
777
|
-
const tabsOf = opts.tabs ?? ((): HTMLElement[] => Array.from(root.querySelectorAll<HTMLElement>(
|
|
1198
|
+
const tabsOf = opts.tabs ?? ((): HTMLElement[] => Array.from(root.querySelectorAll<HTMLElement>(`[role="tab"], [${KIT_ATTR_TAB}]`)));
|
|
778
1199
|
const idOf = opts.idOf ?? ((tab: HTMLElement): string => tab.dataset.key ?? tab.id);
|
|
779
1200
|
const isDisabled = (tab: HTMLElement): boolean => tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true';
|
|
780
1201
|
|
|
@@ -897,11 +1318,11 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
897
1318
|
|
|
898
1319
|
const onKeydown = (event: KeyboardEvent): void => {
|
|
899
1320
|
const target = event.target as HTMLElement | null;
|
|
900
|
-
if (!target || !target.closest(
|
|
1321
|
+
if (!target || !target.closest(`[role="tab"], [${KIT_ATTR_TAB}]`)) return;
|
|
901
1322
|
if (wiring.onKeydown(event)) event.preventDefault();
|
|
902
1323
|
};
|
|
903
1324
|
const onClick = (event: Event): void => {
|
|
904
|
-
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
1325
|
+
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(`[role="tab"], [${KIT_ATTR_TAB}]`);
|
|
905
1326
|
if (!tab || !root.contains(tab)) return;
|
|
906
1327
|
select(idOf(tab));
|
|
907
1328
|
};
|
|
@@ -923,7 +1344,7 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
923
1344
|
|
|
924
1345
|
// ── 类候选小工具(K9 / D1:补齐波基础组件共用)────────────────
|
|
925
1346
|
|
|
926
|
-
export { classCandidates } from '
|
|
1347
|
+
export { classCandidates } from '../shared/class-candidates';
|
|
927
1348
|
|
|
928
1349
|
// ── 通用 tooltip(按钮类基础组件的可选 prop)─────────────────
|
|
929
1350
|
// 提示气泡是目标元素内的一个 role=tooltip 子元素(绝对定位,目标补 `relative`):hover / focus 显示,Esc 与移开隐藏,
|
|
@@ -963,6 +1384,12 @@ export function withTooltip(viewOrSetup: KitView | KitViewSetup, targetOf: (root
|
|
|
963
1384
|
return setupFn;
|
|
964
1385
|
}
|
|
965
1386
|
|
|
1387
|
+
/**
|
|
1388
|
+
* 提示气泡的出现时序(真源 motion#/timing/tooltip,经 kit-limits#overlay.tooltipOpenDelayMs / tooltipSkipDelayMs):
|
|
1389
|
+
* 指针首次悬停等 openDelay 才出现;任一气泡收起后 skipDelay 内移到相邻目标立即出现(全部气泡共用这一个时刻);键盘聚焦立即出现。
|
|
1390
|
+
*/
|
|
1391
|
+
let kitTipLastHideAt = Number.NEGATIVE_INFINITY;
|
|
1392
|
+
|
|
966
1393
|
function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
|
|
967
1394
|
// 视图对象在同一组件定义的所有实例间共享,逐实例状态按根元素存
|
|
968
1395
|
// bound / rebind:目标可随渲染变化(如 MenuButton split 时目标由箭头钮换成主钮),监听跟着目标走
|
|
@@ -1002,21 +1429,38 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
1002
1429
|
const s = stateOf(root);
|
|
1003
1430
|
const show = (): void => {
|
|
1004
1431
|
if (s.tip === null) return;
|
|
1432
|
+
// 禁用的按钮不挂提示气泡(knowledge/Kit主题规则与算法.md KT-K0-4 第 3 条,2026-11-25 裁决);为什么不可用由带原因的置灰(disabled_reason)另给
|
|
1433
|
+
const bound = s.bound;
|
|
1434
|
+
if (bound !== null && (bound.hasAttribute('disabled') || bound.getAttribute('aria-disabled') === 'true')) return;
|
|
1005
1435
|
s.shown = true;
|
|
1006
1436
|
paintTip(s);
|
|
1007
1437
|
};
|
|
1438
|
+
let pending: ReturnType<typeof setTimeout> | null = null;
|
|
1439
|
+
const cancelPending = (): void => {
|
|
1440
|
+
if (pending !== null) clearTimeout(pending);
|
|
1441
|
+
pending = null;
|
|
1442
|
+
};
|
|
1008
1443
|
const hide = (): void => {
|
|
1444
|
+
cancelPending();
|
|
1009
1445
|
if (!s.shown) return;
|
|
1010
1446
|
s.shown = false;
|
|
1447
|
+
kitTipLastHideAt = Date.now();
|
|
1011
1448
|
paintTip(s);
|
|
1012
1449
|
};
|
|
1450
|
+
// 指针悬停:相邻免延迟窗口内立即出现,否则等 openDelay(键盘聚焦走 show,立即出现)
|
|
1451
|
+
const hover = (): void => {
|
|
1452
|
+
cancelPending();
|
|
1453
|
+
if (Date.now() - kitTipLastHideAt <= KIT_OVERLAY_LIMITS.tooltipSkipDelayMs) { show(); return; }
|
|
1454
|
+
pending = setTimeout(() => { pending = null; show(); }, KIT_OVERLAY_LIMITS.tooltipOpenDelayMs);
|
|
1455
|
+
};
|
|
1013
1456
|
const onKey = (event: KeyboardEvent): void => {
|
|
1014
1457
|
if (event.key === 'Escape') hide();
|
|
1015
1458
|
};
|
|
1016
1459
|
const unbind = (): void => {
|
|
1017
1460
|
const t = s.bound;
|
|
1018
1461
|
if (t === null) return;
|
|
1019
|
-
|
|
1462
|
+
cancelPending();
|
|
1463
|
+
t.removeEventListener('mouseenter', hover);
|
|
1020
1464
|
t.removeEventListener('mouseleave', hide);
|
|
1021
1465
|
t.removeEventListener('focusin', show);
|
|
1022
1466
|
t.removeEventListener('focusout', hide);
|
|
@@ -1027,7 +1471,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
1027
1471
|
if (s.bound === t) return;
|
|
1028
1472
|
if (s.bound !== null && s.tip !== null) removeIdToken(s.bound, 'aria-describedby', s.tip.id);
|
|
1029
1473
|
unbind();
|
|
1030
|
-
t.addEventListener('mouseenter',
|
|
1474
|
+
t.addEventListener('mouseenter', hover);
|
|
1031
1475
|
t.addEventListener('mouseleave', hide);
|
|
1032
1476
|
t.addEventListener('focusin', show);
|
|
1033
1477
|
t.addEventListener('focusout', hide);
|
|
@@ -1067,6 +1511,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
1067
1511
|
s.tip = document.createElement('span');
|
|
1068
1512
|
s.tip.id = nextUid('kit-tip');
|
|
1069
1513
|
s.tip.setAttribute('role', 'tooltip');
|
|
1514
|
+
s.tip.setAttribute(KIT_ATTR_LAYER, 'float');
|
|
1070
1515
|
}
|
|
1071
1516
|
s.tip.textContent = text;
|
|
1072
1517
|
if (s.tip.parentNode !== target) target.appendChild(s.tip);
|
|
@@ -1083,5 +1528,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
1083
1528
|
}
|
|
1084
1529
|
|
|
1085
1530
|
export * from '../recipes';
|
|
1531
|
+
// 主题流水线组件契约通道(自报、读 kit 入参、可收纳、二次确认端口):基础组件统一从 shared 取
|
|
1532
|
+
export * from './kit-contract';
|
|
1086
1533
|
export * from './loading-gate';
|
|
1087
1534
|
export { withKitViewTransition, canKitViewTransition } from './view-transition';
|