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/data/code-view.ts
CHANGED
|
@@ -1,26 +1,190 @@
|
|
|
1
1
|
// CodeView:只读代码 / 文本块(layer: data,写死形状,accept: single)。
|
|
2
2
|
//
|
|
3
3
|
// 数据:`data` 是 { title?, text, caption? };`text` 非字符串(对象、数组)时按两空格缩进的 JSON 展示。
|
|
4
|
-
// 等宽、保留换行、可滚动(有 max_height
|
|
4
|
+
// 等宽、保留换行、可滚动(有 max_height 档时);顶部标题行右侧「复制」钮(缺省显示,copyable: false 关闭):
|
|
5
5
|
// 经剪贴板接口写入,成功把按钮文字短暂换成 copied_label,抛 `copy { ok }`(不带文本,避免凭据类文本再次上行)。
|
|
6
6
|
// 数据只经 textContent 写入。无文本显示 empty_text。
|
|
7
7
|
|
|
8
|
+
import { kitApplyLevelClass } from './level-class';
|
|
8
9
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
10
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
10
|
-
import { kitIcon } from '../
|
|
11
|
+
import { kitIcon } from '../shared/icons';
|
|
11
12
|
import { KIT_PART_ATTRIBUTE, KIT_PART_WELL } from '../recipes';
|
|
13
|
+
import { KIT_FOCUS_RING } from '../recipes/state';
|
|
14
|
+
import { KIT_DIVIDER_HEAD_CLASS, kitDividerRecipe } from '../recipes/divider';
|
|
15
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
12
16
|
import { kitText } from '../i18n/kit-text';
|
|
13
17
|
import { actionButton, classTokens, BUTTON_CLASS_TOKENS, mk, recOf, textOf } from './shape-util';
|
|
14
18
|
import {
|
|
15
19
|
CODE_FOLLOW_SLACK_PX, CODE_MAX_LINES_CAP, CODE_TREE_MAX_DEPTH, CODE_TREE_MAX_NODES, CODE_TREE_OPEN_DEPTH, CODE_VARIANTS_MAX,
|
|
16
20
|
} from './d9-limits';
|
|
21
|
+
import { KIT_CONTENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
22
|
+
import {
|
|
23
|
+
KIT_CODE_BIDI_CLASS, KIT_CODE_GUTTER_CLASS, KIT_CODE_LANG_CLASS, KIT_CODE_LINES_SCROLL_CLASS, KIT_CODE_LINES_WRAP_CLASS, KIT_CODE_LINE_CLASS,
|
|
24
|
+
KIT_CODE_LINE_MARKED_CLASS, KIT_CODE_LINE_MARKED_WRAP_CLASS, KIT_CODE_LINE_WRAP_CLASS, KIT_CODE_NOTE_CLASS, KIT_CODE_TEXT_CLASS,
|
|
25
|
+
KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES, kitCodeTokenClass,
|
|
26
|
+
} from '../recipes/code-view';
|
|
27
|
+
import { kitEnginePort, type KitCodeResult, type KitHighlightEnginePort } from './engine-ports';
|
|
28
|
+
import { textActionButton, TEXT_ACTION_CLASS_TOKENS } from './text-action-button';
|
|
29
|
+
import { kitMarkDataFacts, kitMarkLevel, kitMarkPart, kitMarkPicked } from './kit-contract';
|
|
30
|
+
import {
|
|
31
|
+
KIT_ATTR_ACTION, KIT_ATTR_CODE, KIT_ATTR_CODE_LINES, KIT_ATTR_CODE_LIVE, KIT_ATTR_CONTAINER, KIT_ATTR_EMPTY, KIT_ATTR_STREAM, KIT_ATTR_TREE,
|
|
32
|
+
KIT_ATTR_TREE_TOGGLE, KIT_ATTR_VARIANT, kitAttrHtml, kitAttrSel,
|
|
33
|
+
} from '../shared/dom-attrs';
|
|
34
|
+
|
|
35
|
+
const CL = KIT_CONTENT_LIMITS.codeView;
|
|
36
|
+
|
|
37
|
+
export const KIT_CODE_VIEW_DEFAULT_MAP = Object.freeze({
|
|
38
|
+
title: 'title', text: 'text', caption: 'caption', copy: 'copy',
|
|
39
|
+
language: 'language', filename: 'filename', highlight_lines: 'highlight_lines', start_line: 'start_line',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ── 高亮形态的纯函数(内容展示批次 ③;规格 knowledge/Kit主题规则与算法.md §10.16) ──
|
|
43
|
+
|
|
44
|
+
/** 高亮行:`"1-3,7"` 或 `[1, 2, 3]`(1 起,按显示行号)→ 集合;非法片段忽略 */
|
|
45
|
+
export function parseLineRanges(raw: unknown): Set<number> {
|
|
46
|
+
const out = new Set<number>();
|
|
47
|
+
const add = (n: number): void => { if (Number.isInteger(n) && n > 0 && out.size < CL.markedLinesMax) out.add(n); };
|
|
48
|
+
if (Array.isArray(raw)) { for (const v of raw) add(Number(v)); return out; }
|
|
49
|
+
if (typeof raw !== 'string') return out;
|
|
50
|
+
for (const part of raw.split(',')) {
|
|
51
|
+
const m = /^\s*(\d+)\s*(?:-\s*(\d+))?\s*$/u.exec(part);
|
|
52
|
+
if (!m) continue;
|
|
53
|
+
const a = Number(m[1]);
|
|
54
|
+
const b = m[2] !== undefined ? Number(m[2]) : a;
|
|
55
|
+
for (let n = Math.min(a, b); n <= Math.max(a, b) && out.size < CL.markedLinesMax; n += 1) add(n);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const BIDI = /[--]/u;
|
|
61
|
+
/** 行内含 Unicode 双向控制字符(Trojan Source 风险)→ 行首警告 */
|
|
62
|
+
export const hasBidiControl = (line: string): boolean => BIDI.test(line);
|
|
63
|
+
|
|
64
|
+
const HAN_LINE = /[㐀-鿿豈-]/u;
|
|
65
|
+
/** 换行缺省:text / markdown,或含中文的行占比 > 阈值 → 换行;否则横向滚动 */
|
|
66
|
+
export function codeWrapDefault(language: string, lines: readonly string[]): boolean {
|
|
67
|
+
if (language === 'text' || language === 'markdown') return true;
|
|
68
|
+
const nonEmpty = lines.filter((l) => l.trim() !== '');
|
|
69
|
+
if (nonEmpty.length === 0) return false;
|
|
70
|
+
return nonEmpty.filter((l) => HAN_LINE.test(l)).length / nonEmpty.length > CL.wrapCjkRatio;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface KitCodeLinesOptions {
|
|
74
|
+
readonly language: string;
|
|
75
|
+
readonly wrap: boolean;
|
|
76
|
+
/** null = 宿主没装配高亮端口(只画纯文本行) */
|
|
77
|
+
readonly port: KitHighlightEnginePort | null;
|
|
78
|
+
/** 组件根(取页面语言的文案) */
|
|
79
|
+
readonly root: HTMLElement;
|
|
80
|
+
readonly marked?: ReadonlySet<number>;
|
|
81
|
+
readonly start?: number;
|
|
82
|
+
/** 只画前 N 行(折叠);缺省全部 */
|
|
83
|
+
readonly shown?: number;
|
|
84
|
+
/** 异步着色回来时是否仍是当前这次绘制(后发先至时丢弃旧结果) */
|
|
85
|
+
readonly current?: () => boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const HIGHLIGHT_CACHE_MAX = 8;
|
|
89
|
+
const HIGHLIGHT_CACHE = new WeakMap<HTMLElement, Map<string, KitCodeResult>>();
|
|
90
|
+
|
|
91
|
+
function getCachedHighlight(root: HTMLElement, language: string, text: string): KitCodeResult | undefined {
|
|
92
|
+
return HIGHLIGHT_CACHE.get(root)?.get(`${language}\0${text}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function setCachedHighlight(root: HTMLElement, language: string, text: string, res: KitCodeResult): void {
|
|
96
|
+
let map = HIGHLIGHT_CACHE.get(root);
|
|
97
|
+
if (!map) {
|
|
98
|
+
map = new Map();
|
|
99
|
+
HIGHLIGHT_CACHE.set(root, map);
|
|
100
|
+
}
|
|
101
|
+
const key = `${language}\0${text}`;
|
|
102
|
+
if (map.has(key)) map.delete(key);
|
|
103
|
+
else if (map.size >= HIGHLIGHT_CACHE_MAX) {
|
|
104
|
+
const oldest = map.keys().next().value;
|
|
105
|
+
if (oldest !== undefined) map.delete(oldest);
|
|
106
|
+
}
|
|
107
|
+
map.set(key, res);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function applyHighlightTokens(host: HTMLElement, rows: readonly HTMLElement[], res: KitCodeResult, root: HTMLElement): void {
|
|
111
|
+
rows.forEach((row, i) => {
|
|
112
|
+
const toks = res.lines[i];
|
|
113
|
+
if (toks === undefined || toks.length === 0) return;
|
|
114
|
+
const body = row.lastElementChild as HTMLElement | null;
|
|
115
|
+
if (!body) return;
|
|
116
|
+
body.textContent = '';
|
|
117
|
+
for (const tok of toks) {
|
|
118
|
+
const cls = kitCodeTokenClass(tok.kind);
|
|
119
|
+
body.appendChild(cls === '' ? document.createTextNode(tok.text) : mk('span', cls, tok.text));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (res.fallback === 'too-large' || res.fallback === 'timeout') {
|
|
123
|
+
host.appendChild(mk('p', KIT_CODE_NOTE_CLASS, kitText('soma.kit.code_partly_plain', undefined, root)));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
17
126
|
|
|
18
|
-
|
|
127
|
+
/**
|
|
128
|
+
* 按行画代码区(CodeView 高亮形态与 JsonView「原文」共用的唯一画法):先画纯文本行(行号槽、高亮行、双向字符警告),
|
|
129
|
+
* 命中最近一次 (text, language) 高亮缓存时同步上色消除重绘闪白,未命中再经 engines.highlight 异步取记号替换各行正文;超长 / 超时补一行说明。返回行容器。
|
|
130
|
+
*/
|
|
131
|
+
export function paintCodeLines(host: HTMLElement, text: string, o: KitCodeLinesOptions): HTMLElement {
|
|
132
|
+
const allLines = text.split('\n');
|
|
133
|
+
const shownLines = o.shown !== undefined && o.shown < allLines.length ? allLines.slice(0, o.shown) : allLines;
|
|
134
|
+
const start = o.start ?? 1;
|
|
135
|
+
const marked = o.marked ?? new Set<number>();
|
|
136
|
+
const numbers = allLines.length >= CL.lineNumbersMin;
|
|
137
|
+
const root = o.root;
|
|
138
|
+
const box = mk('div', o.wrap ? KIT_CODE_LINES_WRAP_CLASS : KIT_CODE_LINES_SCROLL_CLASS);
|
|
139
|
+
box.setAttribute(KIT_ATTR_CODE_LINES, '');
|
|
140
|
+
const rows: HTMLElement[] = shownLines.map((line, i) => {
|
|
141
|
+
const n = start + i;
|
|
142
|
+
const on = marked.has(n);
|
|
143
|
+
const row = mk('div', on ? (o.wrap ? KIT_CODE_LINE_MARKED_WRAP_CLASS : KIT_CODE_LINE_MARKED_CLASS) : (o.wrap ? KIT_CODE_LINE_WRAP_CLASS : KIT_CODE_LINE_CLASS));
|
|
144
|
+
if (numbers) {
|
|
145
|
+
const g = mk('span', KIT_CODE_GUTTER_CLASS, String(n));
|
|
146
|
+
g.setAttribute('aria-hidden', 'true');
|
|
147
|
+
row.appendChild(g);
|
|
148
|
+
}
|
|
149
|
+
if (on) row.appendChild(mk('span', 'sr-only', kitText('soma.kit.code_marked_line', { n }, root)));
|
|
150
|
+
if (hasBidiControl(line)) {
|
|
151
|
+
const w = mk('span', KIT_CODE_BIDI_CLASS);
|
|
152
|
+
w.title = kitText('soma.kit.code_bidi_warning', undefined, root);
|
|
153
|
+
w.setAttribute('aria-label', w.title);
|
|
154
|
+
w.appendChild(kitIcon('warning', 'xs'));
|
|
155
|
+
row.appendChild(w);
|
|
156
|
+
}
|
|
157
|
+
row.appendChild(mk('span', KIT_CODE_TEXT_CLASS, line === '' ? ' ' : line));
|
|
158
|
+
box.appendChild(row);
|
|
159
|
+
return row;
|
|
160
|
+
});
|
|
161
|
+
host.appendChild(box);
|
|
162
|
+
if (o.port !== null && o.language !== 'text') {
|
|
163
|
+
const cached = getCachedHighlight(root, o.language, text);
|
|
164
|
+
if (cached !== undefined) {
|
|
165
|
+
applyHighlightTokens(host, rows, cached, root);
|
|
166
|
+
} else {
|
|
167
|
+
const current = o.current ?? ((): boolean => true);
|
|
168
|
+
void o.port.highlight(text, o.language).then((res: KitCodeResult) => {
|
|
169
|
+
setCachedHighlight(root, o.language, text, res);
|
|
170
|
+
if (!current() || !host.contains(box)) return;
|
|
171
|
+
applyHighlightTokens(host, rows, res, root);
|
|
172
|
+
}, () => { /* 端口不抛;保险起见吞掉,保留纯文本 */ });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return box;
|
|
176
|
+
}
|
|
19
177
|
|
|
20
178
|
const ROOT_CLASS = 'flex flex-col gap-2';
|
|
21
179
|
const HEAD_CLASS = 'flex items-center justify-between gap-2';
|
|
180
|
+
const HEAD_META_CLASS = 'flex min-w-0 items-center gap-2';
|
|
181
|
+
const PLAIN_TEXT_HINTS: ReadonlySet<string> = new Set(['text', 'txt', 'plain', 'plaintext']);
|
|
182
|
+
// 页签头只画朝内的一条分隔线(分隔线出口);代码井 / 结构树 = 凹槽面的壳配方(容器边,嵌套在面板里由层级规则去框,KT-B2 / KT-L2);树的缩进导线 = 分隔线出口
|
|
183
|
+
const HEAD_TABS_CLASS = `flex items-center justify-between gap-2 ${KIT_DIVIDER_HEAD_CLASS}`;
|
|
22
184
|
const TITLE_CLASS = 'text-sm font-medium text-fg';
|
|
23
|
-
|
|
185
|
+
const WELL_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
|
|
186
|
+
const TREE_GUIDE = kitDividerRecipe('start');
|
|
187
|
+
export const KIT_CODE_PRE_CLASS = `m-0 whitespace-pre-wrap break-all ${WELL_EDGE} p-3 font-mono text-xs text-fg ${KIT_FOCUS_RING.button}`;
|
|
24
188
|
const PRE_HEIGHT: Readonly<Record<string, string>> = Object.freeze({
|
|
25
189
|
none: '',
|
|
26
190
|
sm: 'max-h-40 overflow-y-auto',
|
|
@@ -31,10 +195,10 @@ const EMPTY_CLASS = 'text-fg-subtle';
|
|
|
31
195
|
const CAPTION_CLASS = 'text-xs text-fg-subtle';
|
|
32
196
|
|
|
33
197
|
// variants:同一块位置按页签切换多份文本(如同一服务的多个客户端配置)
|
|
34
|
-
//
|
|
35
|
-
const TABS_CLASS = 'flex min-w-0 flex-1 flex-
|
|
198
|
+
// 页签行单行不折行可横向滚动,底部分割线挂在整行 header 容器上贯通左右,右侧「复制」钮齐平不错位
|
|
199
|
+
const TABS_CLASS = '-mb-px flex min-w-0 flex-1 flex-nowrap items-center gap-1 overflow-x-auto';
|
|
36
200
|
const HEAD_END_BUTTON = 'shrink-0';
|
|
37
|
-
const TAB_CLASS = 'h-8 -
|
|
201
|
+
const TAB_CLASS = 'h-8 shrink-0 whitespace-nowrap border-b-2 border-transparent bg-transparent px-3 text-sm text-fg-muted hover:text-fg motion-safe:transition-colors ' + KIT_FOCUS_RING.button;
|
|
38
202
|
const TAB_ACTIVE_CLASS = 'border-primary font-medium text-fg';
|
|
39
203
|
|
|
40
204
|
export interface KitCodeVariant {
|
|
@@ -79,13 +243,13 @@ export function codeVariantsFromProps(p: Record<string, unknown>): KitCodeVarian
|
|
|
79
243
|
}
|
|
80
244
|
|
|
81
245
|
// tree:JSON 树(自绘 disclosure:标题 button + aria-expanded / aria-controls,Enter / Space 由 button 触发点击切换)
|
|
82
|
-
const TREE_CLASS =
|
|
83
|
-
const TREE_SUMMARY_CLASS = 'block w-full cursor-pointer select-none rounded-
|
|
84
|
-
const TREE_CHILDREN_CLASS =
|
|
246
|
+
const TREE_CLASS = `m-0 ${WELL_EDGE} p-3 font-mono text-xs text-fg ${KIT_FOCUS_RING.button}`;
|
|
247
|
+
const TREE_SUMMARY_CLASS = 'block w-full cursor-pointer select-none rounded-item bg-transparent p-0 text-start font-mono text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.item;
|
|
248
|
+
const TREE_CHILDREN_CLASS = `ms-3 ${TREE_GUIDE} ps-3`;
|
|
85
249
|
const TREE_LEAF_CLASS = 'py-0.5 break-all';
|
|
86
250
|
const TREE_KEY_CLASS = 'text-fg-muted';
|
|
87
251
|
const TREE_VALUE_CLASS: Readonly<Record<'string' | 'number' | 'other', string>> = Object.freeze({
|
|
88
|
-
string: 'text-
|
|
252
|
+
string: 'text-syntax-string', number: 'text-syntax-number', other: 'text-syntax-keyword',
|
|
89
253
|
});
|
|
90
254
|
const TREE_MORE_CLASS = 'text-fg-subtle';
|
|
91
255
|
const TREE_MARK_CLASS = 'inline-block w-4 text-fg-muted';
|
|
@@ -94,8 +258,8 @@ let treeSeq = 0;
|
|
|
94
258
|
|
|
95
259
|
export const KIT_CODE_VIEW_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
96
260
|
TREE_CLASS, TREE_SUMMARY_CLASS, TREE_CHILDREN_CLASS, TREE_LEAF_CLASS, TREE_KEY_CLASS, TREE_MARK_CLASS, TREE_HIDDEN_CLASS, Object.values(TREE_VALUE_CLASS), TREE_MORE_CLASS,
|
|
97
|
-
ROOT_CLASS, HEAD_CLASS, TITLE_CLASS, KIT_CODE_PRE_CLASS, Object.values(PRE_HEIGHT), EMPTY_CLASS, CAPTION_CLASS, BUTTON_CLASS_TOKENS,
|
|
98
|
-
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS, HEAD_END_BUTTON,
|
|
261
|
+
ROOT_CLASS, HEAD_CLASS, HEAD_META_CLASS, HEAD_TABS_CLASS, TITLE_CLASS, KIT_CODE_PRE_CLASS, Object.values(PRE_HEIGHT), EMPTY_CLASS, CAPTION_CLASS, BUTTON_CLASS_TOKENS,
|
|
262
|
+
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS, HEAD_END_BUTTON, KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES, TEXT_ACTION_CLASS_TOKENS, 'sr-only',
|
|
99
263
|
);
|
|
100
264
|
|
|
101
265
|
/** 展示文本(纯函数,便于单测):字符串原样,其余 JSON 缩进;不可序列化回空串 */
|
|
@@ -148,7 +312,7 @@ export function treeNode(key: string, value: unknown, depth: number, budget: { l
|
|
|
148
312
|
const bodyId = `kit-code-tree-${(treeSeq += 1)}`;
|
|
149
313
|
const summary = mk('button', TREE_SUMMARY_CLASS) as HTMLButtonElement;
|
|
150
314
|
summary.type = 'button';
|
|
151
|
-
summary.setAttribute(
|
|
315
|
+
summary.setAttribute(KIT_ATTR_TREE_TOGGLE, '');
|
|
152
316
|
summary.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
153
317
|
summary.setAttribute('aria-controls', bodyId);
|
|
154
318
|
const mark = mk('span', TREE_MARK_CLASS, '');
|
|
@@ -177,6 +341,10 @@ export function treeNode(key: string, value: unknown, depth: number, budget: { l
|
|
|
177
341
|
|
|
178
342
|
export function createCodeView(): SomaComponentDefinition {
|
|
179
343
|
const timers = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>();
|
|
344
|
+
// 长代码「展开全部」已点开的实例;内容变化时重置展开态;高亮请求的序号(后发先至,旧结果丢弃)
|
|
345
|
+
const unfolded = new WeakSet<HTMLElement>();
|
|
346
|
+
const renderedText = new WeakMap<HTMLElement, string>();
|
|
347
|
+
const hlSeq = new WeakMap<HTMLElement, number>();
|
|
180
348
|
// stream + follow:滚动区是否贴在底部(用户往上翻就不再自动跟随);键 = 组件根
|
|
181
349
|
const pinned = new WeakMap<HTMLElement, boolean>();
|
|
182
350
|
// variants:当前页签序号与外部 variant 的上次取值(外部变化才覆盖内部选择)
|
|
@@ -200,9 +368,10 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
200
368
|
name: 'CodeView',
|
|
201
369
|
layer: 'data',
|
|
202
370
|
props: {
|
|
203
|
-
data: { type: 'object', default: {}, desc: '{ title?, text, caption?, copy? };text 非字符串时按缩进 JSON 展示;copy
|
|
204
|
-
map: { type: 'object', default: {}, desc: '键名对照:title / text / caption / copy' },
|
|
205
|
-
|
|
371
|
+
data: { type: 'object', default: {}, desc: '{ title?, text, caption?, copy?, language?, filename?, highlight_lines?, start_line? };text 非字符串时按缩进 JSON 展示;copy 非空时复制钮复制它而不是展示文本;语言按 language → filename → JSON 确定性推断,经 core 端口 engines.highlight 着色(闭集外按纯文本并注明)' },
|
|
372
|
+
map: { type: 'object', default: {}, desc: '键名对照:title / text / caption / copy / language / filename / highlight_lines / start_line' },
|
|
373
|
+
wrap: { type: 'enum', values: ['auto', 'on', 'off'], default: 'auto', desc: '长行:auto = text / markdown 或含中文行占比过半时换行,否则横向滚动;on 换行;off 横向滚动' },
|
|
374
|
+
copyable: { type: 'boolean', default: true, desc: '显示「复制」钮(缺省显示,裁决 2026-11-24:缺省即最佳;写 false 关闭)' },
|
|
206
375
|
copy_label: { type: 'string', default: '', desc: '复制钮文字;缺省取内置文案(按页面语言)' },
|
|
207
376
|
copied_label: { type: 'string', default: '', desc: '复制成功后短暂显示的文字;缺省取内置文案(按页面语言)' },
|
|
208
377
|
stream: { type: 'boolean', default: false, desc: '流式日志:text 是不断追加的全文;内容区标 role=log(读屏礼貌播报新增);配合 max_lines 只保留末尾若干行' },
|
|
@@ -222,11 +391,12 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
222
391
|
variant: { payload: { key: { type: 'string' }, index: { type: 'number' } }, desc: '切换页签后抛(variants 非空时)' },
|
|
223
392
|
},
|
|
224
393
|
},
|
|
225
|
-
|
|
394
|
+
services: ['engines'],
|
|
395
|
+
templateHtml: `<section${kitAttrHtml(KIT_ATTR_CONTAINER, 'card')} data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
226
396
|
controllerFactory: createKitController(() => ({
|
|
227
397
|
attach(root, api) {
|
|
228
398
|
const onClick = (event: Event): void => {
|
|
229
|
-
const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>('
|
|
399
|
+
const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>(kitAttrSel(KIT_ATTR_ACTION, 'copy'));
|
|
230
400
|
if (!btn || btn.disabled) return;
|
|
231
401
|
const p = api.props();
|
|
232
402
|
const data = recOf(p.data);
|
|
@@ -246,20 +416,31 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
246
416
|
} catch { ok = false; }
|
|
247
417
|
if (ok) {
|
|
248
418
|
btn.textContent = str(p.copied_label, kitText('soma.kit.copied', undefined, root));
|
|
419
|
+
const live = root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_CODE_LIVE));
|
|
420
|
+
if (live) live.textContent = kitText('soma.kit.copied', undefined, root);
|
|
249
421
|
const prev = timers.get(root);
|
|
250
422
|
if (prev !== undefined) clearTimeout(prev);
|
|
251
423
|
timers.set(root, setTimeout(() => {
|
|
252
424
|
btn.textContent = str(api.props().copy_label, kitText('soma.kit.copy', undefined, root));
|
|
425
|
+
if (live) live.textContent = '';
|
|
253
426
|
timers.delete(root);
|
|
254
|
-
},
|
|
427
|
+
}, CL.copyFeedbackMs));
|
|
255
428
|
}
|
|
256
429
|
api.emit('copy', { ok });
|
|
257
430
|
})();
|
|
258
431
|
};
|
|
259
432
|
root.addEventListener('click', onClick);
|
|
433
|
+
// 长代码折叠条:展开全部(只展开不收起,与 Carbon 一致)
|
|
434
|
+
const onUnfold = (event: Event): void => {
|
|
435
|
+
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_ACTION, 'code-unfold'));
|
|
436
|
+
if (!btn || !root.contains(btn)) return;
|
|
437
|
+
unfolded.add(root);
|
|
438
|
+
renderCode(root, api.props(), api.services);
|
|
439
|
+
};
|
|
440
|
+
root.addEventListener('click', onUnfold);
|
|
260
441
|
// 树节点折叠:button 的 Enter / Space 原生触发 click;这里切 aria-expanded、折叠体显隐与标记
|
|
261
442
|
const onToggle = (event: Event): void => {
|
|
262
|
-
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
443
|
+
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_TREE_TOGGLE));
|
|
263
444
|
if (!btn || !root.contains(btn)) return;
|
|
264
445
|
const id = btn.getAttribute('aria-controls') ?? '';
|
|
265
446
|
const body = id === '' ? null : Array.from(root.querySelectorAll<HTMLElement>('[id]')).find((e) => e.id === id) ?? null;
|
|
@@ -279,20 +460,20 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
279
460
|
if (st.index === index) return;
|
|
280
461
|
st.index = index;
|
|
281
462
|
picked.set(root, st);
|
|
282
|
-
renderCode(root, p);
|
|
283
|
-
if (refocus) root.querySelector<HTMLElement>(
|
|
463
|
+
renderCode(root, p, api.services);
|
|
464
|
+
if (refocus) root.querySelector<HTMLElement>(`${kitAttrSel(KIT_ATTR_VARIANT)}[aria-selected="true"]`)?.focus();
|
|
284
465
|
api.emit('variant', { key: list[index]!.key, index });
|
|
285
466
|
};
|
|
286
467
|
const onTab = (event: Event): void => {
|
|
287
|
-
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
468
|
+
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_VARIANT));
|
|
288
469
|
if (!tab || !root.contains(tab)) return;
|
|
289
|
-
chooseVariant(Number(tab.getAttribute(
|
|
470
|
+
chooseVariant(Number(tab.getAttribute(KIT_ATTR_VARIANT)), false);
|
|
290
471
|
};
|
|
291
472
|
const onTabKey = (event: KeyboardEvent): void => {
|
|
292
|
-
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
473
|
+
const tab = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_VARIANT));
|
|
293
474
|
if (!tab || !root.contains(tab)) return;
|
|
294
475
|
const n = codeVariantsFromProps(api.props()).length;
|
|
295
|
-
const at = Number(tab.getAttribute(
|
|
476
|
+
const at = Number(tab.getAttribute(KIT_ATTR_VARIANT));
|
|
296
477
|
const rtl = getComputedStyle(root).direction === 'rtl';
|
|
297
478
|
const next = event.key === 'ArrowRight' ? at + (rtl ? -1 : 1) : event.key === 'ArrowLeft' ? at + (rtl ? 1 : -1)
|
|
298
479
|
: event.key === 'Home' ? 0 : event.key === 'End' ? n - 1 : -1;
|
|
@@ -305,30 +486,34 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
305
486
|
// scroll 不冒泡,捕获阶段挂在根上:记录内容区是否贴底(stream + follow 用)
|
|
306
487
|
const onScroll = (event: Event): void => {
|
|
307
488
|
const el = event.target as HTMLElement | null;
|
|
308
|
-
if (!el || el.getAttribute?.(
|
|
489
|
+
if (!el || el.getAttribute?.(KIT_ATTR_CODE) === null) return;
|
|
309
490
|
pinned.set(root, el.scrollHeight - el.scrollTop - el.clientHeight <= CODE_FOLLOW_SLACK_PX);
|
|
310
491
|
};
|
|
311
492
|
root.addEventListener('scroll', onScroll, true);
|
|
312
493
|
return () => {
|
|
313
494
|
root.removeEventListener('click', onClick);
|
|
495
|
+
root.removeEventListener('click', onUnfold);
|
|
496
|
+
unfolded.delete(root);
|
|
497
|
+
renderedText.delete(root);
|
|
314
498
|
root.removeEventListener('click', onToggle);
|
|
315
499
|
root.removeEventListener('click', onTab);
|
|
316
500
|
root.removeEventListener('keydown', onTabKey as EventListener);
|
|
317
501
|
root.removeEventListener('scroll', onScroll, true);
|
|
318
502
|
picked.delete(root);
|
|
319
503
|
pinned.delete(root);
|
|
504
|
+
HIGHLIGHT_CACHE.delete(root);
|
|
320
505
|
const t = timers.get(root);
|
|
321
506
|
if (t !== undefined) clearTimeout(t);
|
|
322
507
|
timers.delete(root);
|
|
323
508
|
};
|
|
324
509
|
},
|
|
325
|
-
render(root, p) {
|
|
326
|
-
renderCode(root, p);
|
|
510
|
+
render(root, p, renderApi) {
|
|
511
|
+
renderCode(root, p, renderApi.services);
|
|
327
512
|
},
|
|
328
513
|
})),
|
|
329
514
|
};
|
|
330
515
|
|
|
331
|
-
function renderCode(root: HTMLElement, p: Record<string, unknown
|
|
516
|
+
function renderCode(root: HTMLElement, p: Record<string, unknown>, services: unknown): void {
|
|
332
517
|
const data = recOf(p.data);
|
|
333
518
|
const m = { ...KIT_CODE_VIEW_DEFAULT_MAP, ...recOf(p.map) } as Record<string, string>;
|
|
334
519
|
const variants = codeVariantsFromProps(p);
|
|
@@ -344,7 +529,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
344
529
|
const caption = limited.omitted > 0
|
|
345
530
|
? `${captionBase}${captionBase !== '' ? ' · ' : ''}${kitText(stream ? 'soma.kit.code_omitted_head' : 'soma.kit.code_omitted_tail', { n: limited.omitted }, root)}`
|
|
346
531
|
: captionBase;
|
|
347
|
-
const copyable = bool(p.copyable);
|
|
532
|
+
const copyable = p.copyable === undefined ? true : bool(p.copyable);
|
|
348
533
|
const heightKey = str(p.max_height, 'md');
|
|
349
534
|
// tree:对象 / 数组,或能解析成对象 / 数组的 JSON 字符串
|
|
350
535
|
let treeValue: unknown = null;
|
|
@@ -357,13 +542,32 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
357
542
|
} catch { treeValue = null; }
|
|
358
543
|
}
|
|
359
544
|
}
|
|
360
|
-
const oldPre = root.querySelector<HTMLElement>(
|
|
545
|
+
const oldPre = root.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_CODE));
|
|
361
546
|
const prevTop = oldPre?.scrollTop ?? 0;
|
|
547
|
+
const prevLeft = oldPre?.scrollLeft ?? 0;
|
|
548
|
+
const prevLinesLeft = oldPre?.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_CODE_LINES))?.scrollLeft ?? 0;
|
|
362
549
|
|
|
550
|
+
// 内容变化时重置长代码展开状态,避免切换新代码后沿用旧代码的 unfolded 标记
|
|
551
|
+
if (renderedText.get(root) !== text) {
|
|
552
|
+
unfolded.delete(root);
|
|
553
|
+
renderedText.set(root, text);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// 高亮形态(非流式、非树):语言确定性推断(长文件仍传 firstLine 以支持 shebang);头部有文件名显示文件名,否则显示语言名(显式 text 不显示且不报未知语言)
|
|
557
|
+
const port = kitEnginePort<KitHighlightEnginePort>(services, 'highlight');
|
|
558
|
+
const filename = textOf(data[m.filename ?? 'filename']);
|
|
559
|
+
const langHint = textOf(data[m.language ?? 'language']);
|
|
560
|
+
const firstLine = text.split('\n', 1)[0] ?? '';
|
|
561
|
+
const language = stream || port === null ? 'text' : port.resolveLanguage({ language: langHint, filename, firstLine, sample: text.length <= CL.sniffMaxChars ? text : '' });
|
|
562
|
+
const explicitPlain = langHint !== '' && PLAIN_TEXT_HINTS.has(langHint.trim().toLowerCase());
|
|
563
|
+
const unknownLang = langHint !== '' && language === 'text' && !explicitPlain;
|
|
564
|
+
const langLabel = filename !== '' ? filename : language !== 'text' && port !== null ? port.languageLabel(language) : unknownLang ? langHint : '';
|
|
363
565
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
364
566
|
root.textContent = '';
|
|
365
|
-
if (title !== '' || copyable || variants.length > 0) {
|
|
366
|
-
const head = mk('div', HEAD_CLASS);
|
|
567
|
+
if (title !== '' || copyable || variants.length > 0 || langLabel !== '') {
|
|
568
|
+
const head = mk('div', variants.length > 0 ? HEAD_TABS_CLASS : HEAD_CLASS);
|
|
569
|
+
// 标题行(含页签行)= 面头;标题文字 = 块标题;复制钮经 actionButton 已自报「动作」
|
|
570
|
+
kitMarkLevel(head, 'head'); kitApplyLevelClass(head);
|
|
367
571
|
if (variants.length > 0) {
|
|
368
572
|
const tabs = mk('div', TABS_CLASS);
|
|
369
573
|
tabs.setAttribute('role', 'tablist');
|
|
@@ -373,12 +577,23 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
373
577
|
tab.type = 'button';
|
|
374
578
|
tab.setAttribute('role', 'tab');
|
|
375
579
|
tab.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
580
|
+
// 当前页签自报选中(aria-selected 上一行已写)
|
|
581
|
+
kitMarkPicked(tab, 'selected', on, null);
|
|
376
582
|
tab.tabIndex = on ? 0 : -1;
|
|
377
|
-
tab.setAttribute(
|
|
583
|
+
tab.setAttribute(KIT_ATTR_VARIANT, String(i));
|
|
378
584
|
tabs.appendChild(tab);
|
|
379
585
|
});
|
|
380
586
|
head.appendChild(tabs);
|
|
381
|
-
} else
|
|
587
|
+
} else if (title !== '' || langLabel !== '') {
|
|
588
|
+
const meta = mk('div', HEAD_META_CLASS);
|
|
589
|
+
if (title !== '') {
|
|
590
|
+
const titleEl = mk('span', TITLE_CLASS, title);
|
|
591
|
+
kitMarkPart(titleEl, 'block-title');
|
|
592
|
+
meta.appendChild(titleEl);
|
|
593
|
+
}
|
|
594
|
+
if (langLabel !== '') meta.appendChild(mk('span', KIT_CODE_LANG_CLASS, langLabel));
|
|
595
|
+
head.appendChild(meta);
|
|
596
|
+
}
|
|
382
597
|
if (copyable) {
|
|
383
598
|
const copyBtn = actionButton({ key: 'copy', label: str(p.copy_label, kitText('soma.kit.copy', undefined, root)), tone: 'neutral', disabled: text === '', reason: '' });
|
|
384
599
|
copyBtn.classList.add(HEAD_END_BUTTON);
|
|
@@ -388,33 +603,70 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
388
603
|
}
|
|
389
604
|
const height = PRE_HEIGHT[heightKey] ?? 'max-h-80 overflow-y-auto';
|
|
390
605
|
const asTree = treeValue !== null;
|
|
606
|
+
// 高亮形态每行一个块元素,外壳用 div(pre 里只许短语内容);流式与空态仍是 pre
|
|
607
|
+
const lineMode = !asTree && !stream && text !== '';
|
|
391
608
|
const pre = asTree
|
|
392
609
|
? mk('div', `${TREE_CLASS}${height !== '' ? ` ${height}` : ''}`)
|
|
393
|
-
: mk('pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
610
|
+
: mk(lineMode ? 'div' : 'pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
394
611
|
pre.tabIndex = 0;
|
|
395
|
-
pre.setAttribute(
|
|
612
|
+
pre.setAttribute(KIT_ATTR_CODE, '');
|
|
396
613
|
pre.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_WELL);
|
|
397
614
|
const label = str(p.aria_label) !== '' ? str(p.aria_label) : title;
|
|
398
615
|
if (label !== '') pre.setAttribute('aria-label', label);
|
|
399
616
|
if (stream) {
|
|
400
617
|
pre.setAttribute('role', 'log');
|
|
401
618
|
pre.setAttribute('aria-live', 'polite');
|
|
402
|
-
pre.setAttribute(
|
|
619
|
+
pre.setAttribute(KIT_ATTR_STREAM, '');
|
|
403
620
|
}
|
|
621
|
+
// 数据状态:无文本即内容全空(根每次重画,按本轮事实写)
|
|
622
|
+
kitMarkDataFacts(root, { empty: !asTree && text === '' });
|
|
404
623
|
if (asTree) {
|
|
405
|
-
pre.setAttribute(
|
|
624
|
+
pre.setAttribute(KIT_ATTR_TREE, '');
|
|
406
625
|
pre.appendChild(treeNode('', treeValue, 0, { left: CODE_TREE_MAX_NODES, truncated: kitText('soma.kit.code_truncated', undefined, root) }));
|
|
407
626
|
} else if (text === '') {
|
|
408
627
|
pre.appendChild(mk('span', EMPTY_CLASS, str(p.empty_text, kitText('soma.kit.empty_content', undefined, root))));
|
|
409
|
-
pre.setAttribute(
|
|
410
|
-
} else {
|
|
628
|
+
pre.setAttribute(KIT_ATTR_EMPTY, '');
|
|
629
|
+
} else if (stream) {
|
|
411
630
|
pre.textContent = text;
|
|
631
|
+
} else {
|
|
632
|
+
// 高亮形态:先画纯文本行(行号、折叠、换行、高亮行都在这一步定好),再异步取记号替换各行正文
|
|
633
|
+
pre.setAttribute('role', 'region');
|
|
634
|
+
pre.setAttribute(KIT_ATTR_CONTAINER, 'plain');
|
|
635
|
+
pre.setAttribute('aria-label', label !== '' ? label : kitText('soma.kit.code_region', { name: langLabel !== '' ? langLabel : kitText('soma.kit.code_plain', undefined, root) }, root));
|
|
636
|
+
const allLines = text.split('\n');
|
|
637
|
+
const folded = allLines.length > CL.foldAbove && !unfolded.has(root);
|
|
638
|
+
const wrapMode = str(p.wrap, 'auto');
|
|
639
|
+
const wrapOn = wrapMode === 'on' || (wrapMode === 'auto' && codeWrapDefault(language, allLines));
|
|
640
|
+
const startRaw = Number(data[m.start_line ?? 'start_line']);
|
|
641
|
+
const mine = (hlSeq.get(root) ?? 0) + 1;
|
|
642
|
+
hlSeq.set(root, mine);
|
|
643
|
+
paintCodeLines(pre, text, {
|
|
644
|
+
language, wrap: wrapOn, port, root,
|
|
645
|
+
marked: parseLineRanges(data[m.highlight_lines ?? 'highlight_lines']),
|
|
646
|
+
start: Number.isInteger(startRaw) && startRaw > 0 ? startRaw : 1,
|
|
647
|
+
shown: folded ? CL.foldTo : allLines.length,
|
|
648
|
+
current: () => hlSeq.get(root) === mine,
|
|
649
|
+
});
|
|
650
|
+
if (folded) pre.appendChild(textActionButton('code-unfold', kitText('soma.kit.code_unfold', { n: allLines.length }, root), 'expand'));
|
|
651
|
+
if (unknownLang && port !== null) {
|
|
652
|
+
pre.appendChild(mk('p', KIT_CODE_NOTE_CLASS, kitText('soma.kit.code_unknown_language', undefined, root)));
|
|
653
|
+
}
|
|
412
654
|
}
|
|
413
655
|
root.appendChild(pre);
|
|
414
|
-
|
|
656
|
+
const live = mk('span', 'sr-only');
|
|
657
|
+
live.setAttribute('aria-live', 'polite');
|
|
658
|
+
live.setAttribute(KIT_ATTR_CODE_LIVE, '');
|
|
659
|
+
root.appendChild(live);
|
|
660
|
+
// 流式:贴底(或首次)且 follow 时滚到最新;用户翻上去过就保持原位置;非流式重绘同样恢复纵横滚动位置
|
|
415
661
|
if (stream) {
|
|
416
662
|
const wasPinned = pinned.get(root) ?? true;
|
|
417
663
|
pre.scrollTop = follow && wasPinned ? pre.scrollHeight : prevTop;
|
|
664
|
+
pre.scrollLeft = prevLeft;
|
|
665
|
+
} else {
|
|
666
|
+
pre.scrollTop = prevTop;
|
|
667
|
+
pre.scrollLeft = prevLeft;
|
|
668
|
+
const linesBox = pre.querySelector<HTMLElement>(kitAttrSel(KIT_ATTR_CODE_LINES));
|
|
669
|
+
if (linesBox && prevLinesLeft > 0) linesBox.scrollLeft = prevLinesLeft;
|
|
418
670
|
}
|
|
419
671
|
if (caption !== '') root.appendChild(mk('p', CAPTION_CLASS, caption));
|
|
420
672
|
}
|