soma-kit 0.1.15 → 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/ops/error-budget-card.ts +3 -3
- package/packs/ops/release-readiness-card.ts +3 -3
- package/packs/security/control-evidence-card.ts +3 -3
- package/packs/security/finding-card.ts +3 -2
- package/packs/shared/card-util.ts +17 -0
- package/spec/generated/kit-app.schema.json +2148 -340
- package/spec/generated/kit-page.schema.json +1134 -139
- package/spec/kit-grammar.json +934 -92
- package/spec/kit-grammar.schema.json +167 -2
- package/src/app/app-config.ts +219 -186
- package/src/app/define-kit-actions.ts +126 -20
- package/src/app/define-kit-app.ts +49 -4
- package/src/app/index.ts +5 -0
- package/src/app/kit-view-context.ts +39 -1
- package/src/app/list-page-defaults.ts +14 -0
- package/src/app/server-pages.ts +239 -7
- package/src/app/server.ts +466 -25
- package/src/app/theme-endpoint.ts +67 -23
- package/src/app/theme-runtime.ts +414 -85
- package/src/app/theme-shards.ts +69 -0
- package/src/app/tier-compat.ts +107 -0
- package/src/base/action-busy.ts +215 -38
- package/src/base/affix.ts +137 -0
- package/src/base/alert.ts +104 -59
- package/src/base/anchored-layer.ts +7 -6
- package/src/base/avatar.ts +147 -61
- package/src/base/badge.ts +186 -0
- package/src/base/button-group.ts +227 -0
- package/src/base/button.ts +347 -50
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +143 -32
- package/src/base/check-core.ts +193 -33
- package/src/base/checkbox.ts +67 -2
- package/src/base/choice.ts +132 -31
- package/src/base/collapse.ts +249 -0
- package/src/base/color-picker.ts +399 -27
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +148 -36
- package/src/base/context-menu.ts +23 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +114 -96
- package/src/base/date.ts +481 -74
- package/src/base/delta.ts +16 -9
- package/src/base/divider.ts +51 -33
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +57 -21
- package/src/base/gap-value.ts +34 -15
- package/src/base/hint-tips.ts +99 -29
- package/src/base/identity-cells.ts +839 -0
- package/src/base/illustrations.ts +6 -4
- package/src/base/image.ts +40 -19
- package/src/base/index.ts +79 -22
- package/src/base/inline-error.ts +13 -7
- package/src/base/input.ts +135 -35
- package/src/base/kbd.ts +30 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +282 -101
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +55 -22
- package/src/base/menu-button.ts +73 -22
- package/src/base/menu-core.ts +201 -24
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +7 -5
- package/src/base/motion/hover-gallery.ts +16 -12
- package/src/base/motion/limits.ts +10 -0
- package/src/base/motion/marquee.ts +18 -11
- package/src/base/motion/text-rotate.ts +34 -16
- package/src/base/notification.ts +292 -0
- package/src/base/number.ts +93 -12
- package/src/base/otp.ts +139 -27
- package/src/base/overlay-runtime.ts +30 -23
- package/src/base/overlay-shell.ts +59 -14
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +624 -73
- package/src/base/popup.ts +187 -52
- package/src/base/portal-core.ts +99 -2
- package/src/base/price-text.ts +51 -17
- package/src/base/progress.ts +100 -18
- package/src/base/qr-code.ts +64 -17
- package/src/base/qty-stepper.ts +141 -22
- package/src/base/radio.ts +43 -2
- package/src/base/range.ts +194 -39
- package/src/base/rating.ts +117 -31
- package/src/base/reason-tip.ts +58 -16
- package/src/base/relation-cells.ts +541 -0
- package/src/base/resize-handle.ts +5 -3
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +70 -26
- package/src/base/select.ts +8 -3
- package/src/base/shared.ts +482 -71
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/sticky-edge.ts +96 -29
- package/src/base/swap.ts +39 -21
- package/src/base/switch.ts +158 -38
- package/src/base/tabs.ts +292 -0
- package/src/base/tag-input.ts +123 -54
- package/src/base/tag.ts +184 -66
- package/src/base/text.ts +461 -71
- package/src/base/textarea.ts +88 -39
- package/src/base/time-picker.ts +335 -55
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +342 -88
- package/src/base/upload.ts +604 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +70 -5
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +52 -12
- package/src/biz/auth-panel/compile.ts +13 -3
- package/src/biz/auth-panel/shell.ts +27 -7
- package/src/biz/category-crud/compile.ts +51 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +29 -9
- package/src/biz/checkout-page/compile.ts +37 -3
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +26 -9
- package/src/biz/compose.ts +6 -1
- package/src/biz/data-components.ts +2 -0
- package/src/biz/import-wizard/compile.ts +4 -1
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +32 -18
- package/src/biz/index.ts +1 -1
- package/src/biz/landing-page/compile.ts +3 -2
- package/src/biz/landing-page/shell.ts +22 -3
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +54 -15
- package/src/biz/master-sub/compile.ts +194 -57
- package/src/biz/master-sub/detail-head.ts +141 -18
- package/src/biz/master-sub/index.ts +3 -0
- package/src/biz/master-sub/shell.ts +186 -57
- package/src/biz/multi-board/compile.ts +87 -36
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +3 -2
- package/src/biz/multi-board/prose-fold.ts +15 -11
- package/src/biz/multi-board/shell.ts +148 -37
- package/src/biz/notification-center/compile.ts +20 -6
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +43 -10
- package/src/biz/page-templates/domain-templates.ts +145 -22
- package/src/biz/page-templates/result-page/compile.ts +4 -1
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +17 -4
- package/src/biz/page-templates/sign-in-page/compile.ts +19 -8
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +28 -12
- package/src/biz/record-detail/compile.ts +39 -11
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +41 -10
- package/src/biz/settings-center/compile.ts +4 -1
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +30 -9
- package/src/biz/shared/action-host.ts +137 -46
- package/src/biz/shared/compile-helpers.ts +130 -28
- package/src/biz/shared/coordinator.ts +628 -147
- package/src/biz/shared/focus-return.ts +180 -0
- package/src/biz/shared/object-aliases.ts +7 -1
- package/src/biz/shared/overlay-compile.ts +58 -10
- package/src/biz/shared/overlay-shell.ts +40 -10
- package/src/biz/shared/page-form-actions.ts +151 -0
- package/src/biz/shared/page-form.ts +255 -0
- package/src/biz/shared/pipeline.ts +74 -0
- package/src/biz/shared/runtime-hub.ts +101 -8
- package/src/biz/shared/verbs.ts +129 -0
- package/src/biz/single-form/compile.ts +4 -2
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +21 -11
- package/src/biz/standard-crud/compile.ts +206 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +82 -22
- package/src/biz/standard-crud/summary.ts +2 -37
- package/src/biz/step-form/compile.ts +12 -3
- package/src/biz/step-form/hub.ts +165 -50
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +31 -15
- package/src/biz/types.ts +40 -4
- package/src/cli/kit-cli.ts +145 -26
- package/src/cli/kit-init.ts +3 -3
- package/src/cli/migrate/theme-map.ts +35 -28
- package/src/cli/migrate/ts-rules.ts +2 -2
- package/src/cli/migrate/types.ts +3 -3
- package/src/cli/migrate/yaml-rules.ts +11 -9
- package/src/cli/view-writes.ts +13 -0
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +446 -53
- package/src/compile/component-candidates.ts +56 -4
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +1 -1
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/rules-composition.ts +2 -1
- package/src/compile/layout-lint/rules-table.ts +4 -19
- package/src/compile/look-page.ts +551 -0
- package/src/compile/look.ts +376 -0
- package/src/compile/page-composition.ts +382 -46
- package/src/compile/page-hierarchy.ts +131 -0
- package/src/compile/page-pipeline-look.ts +156 -0
- package/src/compile/page-pipeline.ts +200 -0
- package/src/compile/parse.ts +12 -11
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +645 -28
- package/src/compile/styles.ts +226 -26
- package/src/compile/types.ts +62 -5
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +49 -22
- package/src/data/anchor-nav.ts +73 -15
- package/src/data/approval-flow.ts +210 -124
- package/src/data/assignment-picker.ts +163 -85
- package/src/data/async-result-panel.ts +110 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +141 -19
- package/src/data/calendar.ts +434 -96
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +72 -38
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +904 -77
- package/src/data/checklist.ts +78 -35
- package/src/data/code-view.ts +106 -48
- package/src/data/comment-thread.ts +607 -87
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +198 -30
- package/src/data/context-menu.ts +95 -21
- package/src/data/d9-limits.ts +2 -0
- package/src/data/d9-util.ts +13 -5
- package/src/data/diff.ts +107 -50
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +33 -17
- package/src/data/embed.ts +142 -7
- package/src/data/engine-ports.ts +13 -4
- package/src/data/field-mapper.ts +104 -48
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +603 -142
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +85 -27
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +637 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +38 -15
- package/src/data/image-viewer.ts +261 -62
- package/src/data/index.ts +63 -1
- package/src/data/item-list.ts +217 -57
- package/src/data/json-view.ts +165 -100
- package/src/data/kanban.ts +339 -87
- package/src/data/kit-contract.ts +230 -0
- package/src/data/leaderboard.ts +343 -0
- package/src/data/level-class.ts +21 -0
- package/src/data/log-stream.ts +347 -0
- package/src/data/markdown-view.ts +155 -45
- package/src/data/matrix.ts +217 -112
- package/src/data/media-grid.ts +162 -38
- package/src/data/mega-menu.ts +39 -23
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +50 -15
- package/src/data/menu.ts +131 -47
- package/src/data/mockup.ts +30 -22
- package/src/data/modal-dialog.ts +90 -13
- package/src/data/navbar.ts +143 -61
- package/src/data/notice-list.ts +100 -48
- package/src/data/notify-renderer.ts +61 -7
- package/src/data/object-form.ts +1389 -130
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +122 -42
- package/src/data/panel-head.ts +237 -75
- package/src/data/permission-matrix.ts +371 -119
- package/src/data/permission-tree.ts +135 -80
- package/src/data/pricing-table.ts +106 -42
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +63 -31
- package/src/data/record-card.ts +239 -70
- package/src/data/record-picker.ts +56 -27
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +131 -41
- package/src/data/resident.ts +11 -1
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +206 -35
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +376 -102
- package/src/data/rule-builder.ts +129 -80
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +86 -43
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +438 -86
- package/src/data/static-lazy.ts +18 -0
- package/src/data/static-registry.ts +38 -2
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +63 -34
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +128 -47
- package/src/data/system-switcher.ts +40 -20
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +99 -31
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +110 -47
- package/src/data/transfer.ts +195 -47
- package/src/data/tree-table.ts +194 -112
- package/src/data/tree.ts +191 -70
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +242 -102
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +26 -4
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +1 -2
- package/src/frames/inherited-shell.ts +54 -13
- package/src/frames/page-bar.ts +205 -27
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +0 -2
- package/src/frames/shared.ts +64 -21
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +11 -7
- package/src/frames/split-frame/wiring.ts +14 -10
- package/src/frames/tabs-frame/shell.ts +3 -2
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +2 -0
- package/src/frames/workspace-frame/extras.ts +5 -3
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/pipeline-key.ts +6 -0
- package/src/frames/workspace-frame/shell.ts +22 -2
- package/src/frames/workspace-frame/state.ts +42 -14
- package/src/frames/workspace-frame/view.ts +697 -167
- package/src/generated/kit-grammar-runtime.ts +1015 -53
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +96 -3
- package/src/object-renderer/action-group.ts +175 -23
- package/src/object-renderer/action-more.ts +48 -17
- package/src/object-renderer/arrange.ts +241 -29
- package/src/object-renderer/category-tone.ts +96 -0
- package/src/object-renderer/collapse-wiring.ts +19 -9
- package/src/object-renderer/collection-expand.ts +3 -3
- package/src/object-renderer/collection-parts.ts +432 -107
- package/src/object-renderer/collection-table.ts +347 -45
- package/src/object-renderer/collection.ts +291 -62
- package/src/object-renderer/compile-data.ts +12 -2
- package/src/object-renderer/defaults.ts +6 -5
- package/src/object-renderer/emit-events.ts +45 -19
- package/src/object-renderer/emit-object.ts +35 -9
- package/src/object-renderer/emit-static.ts +734 -159
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +105 -18
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +18 -2
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +44 -2
- package/src/object-renderer/pick-component.ts +8 -2
- package/src/object-renderer/pipeline-mode.ts +6 -0
- package/src/object-renderer/relation-field.ts +79 -0
- package/src/object-renderer/render-object.ts +71 -26
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +424 -103
- package/src/object-renderer/table-gap.ts +2 -1
- package/src/object-renderer/table-reorder.ts +237 -0
- package/src/object-renderer/table-summary.ts +26 -12
- package/src/object-renderer/table-tools.ts +428 -128
- package/src/object-renderer/types.ts +91 -2
- package/src/object-renderer/value-present.ts +49 -0
- package/src/page-target/ai-surface.ts +15 -22
- package/src/page-target/compile.ts +5 -6
- package/src/page-target/drift.ts +0 -7
- package/src/page-target/intent-schema.ts +46 -43
- package/src/page-target/target.ts +4 -5
- package/src/page-target/writer-policy.ts +4 -5
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +15 -14
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +3 -2
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +76 -19
- package/src/recipes/control.ts +64 -5
- package/src/recipes/desc-list.ts +101 -7
- package/src/recipes/divider.ts +30 -9
- package/src/recipes/emphasis.ts +90 -5
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +3 -2
- package/src/recipes/index.ts +28 -4
- package/src/recipes/inherited-shell.ts +21 -15
- package/src/recipes/json-view.ts +6 -5
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +16 -6
- package/src/recipes/overlay.ts +47 -19
- package/src/recipes/page-width.ts +31 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +37 -19
- package/src/recipes/rail-grid.ts +6 -3
- package/src/recipes/self-owned.ts +59 -0
- package/src/recipes/slot-align.ts +5 -3
- package/src/recipes/stat-state.ts +5 -5
- package/src/recipes/state.ts +54 -3
- package/src/recipes/status.ts +14 -14
- package/src/recipes/strip.ts +47 -5
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +33 -4
- package/src/recipes/table-gap.ts +3 -2
- package/src/recipes/table-native-edit.ts +22 -9
- package/src/recipes/table-row.ts +45 -12
- package/src/recipes/tabs.ts +54 -22
- package/src/recipes/text-diff.ts +15 -8
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +68 -3
- package/src/shared/action-func.ts +106 -0
- package/src/shared/color-scheme.ts +127 -0
- package/src/shared/confirm-decl.ts +5 -2
- package/src/shared/danger-facts.ts +55 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +58 -12
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/icons.ts +28 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/shared/order-value.ts +15 -0
- package/src/shared/page-attrs-runtime.ts +327 -0
- package/src/shared/page-attrs.ts +262 -0
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +165 -24
- package/src/shared/theme-usage.ts +16 -0
- package/src/shared/value-table-contract.ts +68 -0
- package/src/spatial/action-func.ts +4 -0
- package/src/spatial/declared-actions.ts +116 -0
- package/src/spatial/emit.ts +660 -0
- package/src/spatial/expand.ts +1482 -0
- package/src/spatial/field-types.ts +48 -0
- package/src/spatial/index.ts +82 -0
- package/src/spatial/layout.ts +697 -0
- package/src/spatial/look-apply.ts +206 -0
- package/src/spatial/page-decl.ts +44 -0
- package/src/spatial/page-object.ts +349 -0
- package/src/spatial/recognize.ts +491 -0
- package/src/spatial/self-report.ts +571 -0
- package/src/spatial/shape.ts +205 -0
- package/src/spatial/spatial-map.ts +136 -0
- package/src/spatial/tone.ts +145 -0
- package/src/theme/index.ts +11 -2
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +527 -16
- package/src/theme/kit-theme.tpl +491 -16
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +522 -185
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +3 -2
- package/src/theme/theme-tokens.ts +1601 -93
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/frames/list-summary.ts +0 -123
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
package/src/data/flow-editor.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// 本文件依次是:数据与配置形状、类串表、几何、撤销栈、分层布局、输入解析、图编辑规则、组件。
|
|
12
12
|
// 纯函数(布局、几何、规则、撤销栈、解析)均已导出,供业务组件与测试直接用。
|
|
13
13
|
|
|
14
|
+
import { kitApplyLevelClass } from './level-class';
|
|
14
15
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
15
16
|
import { mappingPrefixOf } from './flow-remote-options';
|
|
16
17
|
import { clearFlowNodeField, withNodeOptions } from './flow-node-options';
|
|
@@ -18,14 +19,25 @@ import { FLOW_EDITOR_CONTRACT } from './flow-editor-contract';
|
|
|
18
19
|
import { designFlowEditorGeometry } from 'soma-foundation/layout';
|
|
19
20
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
21
|
import { applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
22
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
21
23
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
24
|
import { setKitFace } from '../recipes';
|
|
25
|
+
import { KIT_DIMMED_CLASS, KIT_FOCUS_RING } from '../recipes/state';
|
|
23
26
|
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
24
27
|
import { kitShellRecipe } from '../recipes/container';
|
|
25
28
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
26
29
|
import { mergeClass } from '../shared/merge-class';
|
|
30
|
+
import { kitClosedValueRecipe } from '../recipes/field-text';
|
|
31
|
+
import {
|
|
32
|
+
KIT_CANVAS_DOT_FILL_CLASS,
|
|
33
|
+
KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
34
|
+
kitResolveStatusOrCategoryTone,
|
|
35
|
+
kitToneAccentBorderClass,
|
|
36
|
+
kitToneSoftBadgeClass,
|
|
37
|
+
} from '../recipes/color-role';
|
|
27
38
|
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
28
|
-
import { kitIcon, type KitIconName } from '../shared/icons';
|
|
39
|
+
import { KIT_ICON_CLASS_CANDIDATES, kitIcon, resolveKitIconName, type KitIconName, type KitIconSize } from '../shared/icons';
|
|
40
|
+
import { kitGlyph } from '../shared/glyphs';
|
|
29
41
|
import { createInput, KIT_INPUT_CLASS_CANDIDATES } from '../base/input';
|
|
30
42
|
import { createTextarea, KIT_TEXTAREA_CLASS_CANDIDATES } from '../base/textarea';
|
|
31
43
|
import { createSwitch, KIT_SWITCH_CLASS_CANDIDATES } from '../base/switch';
|
|
@@ -34,6 +46,10 @@ import { KIT_QTY_STEPPER_CLASS_CANDIDATES } from '../base/qty-stepper';
|
|
|
34
46
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
35
47
|
import { createFieldMapper, KIT_FIELD_MAPPER_CLASS_CANDIDATES } from './field-mapper';
|
|
36
48
|
import { createKitEmbedBag, mountKitComponent, mountKitSelectField } from './embed';
|
|
49
|
+
import { kitMarkDataFacts, kitMarkLevel, kitMarkPart, kitMarkPicked } from './kit-contract';
|
|
50
|
+
import {
|
|
51
|
+
KIT_ATTR_CONTAINER, KIT_ATTR_FLOW_DRAFT_EDGE, KIT_ATTR_GRAPH_SUMMARY, KIT_ATTR_PORT_ACTIVE, KIT_ATTR_RETRY, KIT_ATTR_STATE,
|
|
52
|
+
} from '../shared/dom-attrs';
|
|
37
53
|
|
|
38
54
|
// ════════════════════════════════════════════════════════════════
|
|
39
55
|
// 数据与配置形状(纯类型 + 默认文案,无 DOM)
|
|
@@ -133,6 +149,12 @@ export interface FlowNodeType {
|
|
|
133
149
|
}
|
|
134
150
|
|
|
135
151
|
export type FlowLayoutMode = 'manual' | 'layered';
|
|
152
|
+
export type FlowDirection = 'LR' | 'TB';
|
|
153
|
+
|
|
154
|
+
export interface FlowEditorModeOptions {
|
|
155
|
+
/** GraphView 只读拓扑图模式:强制只读、无配置面板、支持 node_pick / edge_pick / retry 与无障碍邻接摘要表 */
|
|
156
|
+
graphView?: boolean;
|
|
157
|
+
}
|
|
136
158
|
|
|
137
159
|
export interface FlowIssue {
|
|
138
160
|
target: 'node' | 'edge';
|
|
@@ -152,6 +174,7 @@ export interface FlowSuggestion {
|
|
|
152
174
|
export interface FlowConfig {
|
|
153
175
|
nodeTypes: Record<string, FlowNodeType>;
|
|
154
176
|
layout: FlowLayoutMode;
|
|
177
|
+
direction: FlowDirection;
|
|
155
178
|
readonly: boolean;
|
|
156
179
|
/** 允许成环,缺省 false:连线会形成环时拒绝 */
|
|
157
180
|
allowCycles: boolean;
|
|
@@ -181,7 +204,7 @@ const FLOW_TEXT_KEYS: Readonly<Record<string, KitTextKey>> = {
|
|
|
181
204
|
|
|
182
205
|
/** 默认文案(占位 `{x}` 原样保留);`at` 是元素(读页面语言)或语言串,缺省取 zh-CN */
|
|
183
206
|
export function flowDefaultTexts(at?: Element | string | null): Record<string, string> {
|
|
184
|
-
const out: Record<string, string> = { add: '
|
|
207
|
+
const out: Record<string, string> = { add: '{type}', nodeAria: '{type}:{label}' };
|
|
185
208
|
for (const [k, key] of Object.entries(FLOW_TEXT_KEYS)) out[k] = kitText(key, undefined, at);
|
|
186
209
|
return out;
|
|
187
210
|
}
|
|
@@ -200,31 +223,34 @@ export function fmt(template: string, vars: Record<string, string | number>): st
|
|
|
200
223
|
|
|
201
224
|
const EDGE_STILL = kitControlEdgeRecipe({ wrapper: true, hover: false });
|
|
202
225
|
const EDGE_LIVE = kitControlEdgeRecipe({ wrapper: true });
|
|
226
|
+
const IN_PORT_BASE = `pointer-events-none absolute -left-1 top-10 -mt-1 h-2 w-2 rounded-full ${EDGE_STILL} bg-surface`;
|
|
203
227
|
export const FLOW_CLASS = Object.freeze({
|
|
204
|
-
root: 'flex w-full flex-col gap-2',
|
|
228
|
+
root: '@container flex w-full flex-col gap-2',
|
|
205
229
|
toolbar: 'flex flex-wrap items-center gap-2',
|
|
206
230
|
btnGroup: 'inline-flex shrink-0 flex-nowrap items-center gap-1',
|
|
207
231
|
btn: mergeClass(kitEmphasisButtonRecipe('button.toolbar'), 'shrink-0 whitespace-nowrap'),
|
|
208
|
-
btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-
|
|
232
|
+
btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-control border border-primary bg-primary px-3 text-sm text-primary-fg transition-colors hover:bg-primary-hover ' + KIT_FOCUS_RING.button + ' disabled:cursor-not-allowed disabled:bg-control-disabled disabled:text-fg-disabled',
|
|
209
233
|
zoomLabel: 'text-xs text-fg-muted',
|
|
210
|
-
row: 'flex w-full items-
|
|
211
|
-
panelOuter: 'w-
|
|
234
|
+
row: 'flex w-full flex-col items-stretch gap-2 @2xl:flex-row @2xl:items-start',
|
|
235
|
+
panelOuter: 'w-full shrink-0 @2xl:w-80',
|
|
212
236
|
// 配置面板与画布外缘 = 壳配方(容器边,KT-B2);节点 / 端口 / 节点条的轮廓 = 控件轮廓(KT-B1);右键菜单 = 浮起表面(KT-B4)
|
|
213
|
-
panel: mergeClass('flex h-120 flex-col gap-3 overflow-y-auto p-3', kitShellRecipe({ tone: 'base', shadow: false })),
|
|
214
|
-
|
|
237
|
+
panel: mergeClass('flex max-h-120 flex-col gap-3 overflow-y-auto p-3 @2xl:h-120', kitShellRecipe({ tone: 'base', shadow: false })),
|
|
238
|
+
panelHead: 'flex items-center justify-between gap-2',
|
|
239
|
+
panelTitle: 'min-w-0 flex-1 truncate text-sm font-semibold text-fg',
|
|
240
|
+
panelClose: 'inline-flex size-7 shrink-0 items-center justify-center rounded-item p-0 text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.button,
|
|
215
241
|
panelField: 'flex flex-col gap-1',
|
|
216
242
|
panelFull: 'w-full',
|
|
217
243
|
panelLabel: 'text-xs font-medium text-fg-muted',
|
|
218
244
|
panelReq: 'ms-1 text-danger-on-soft',
|
|
219
245
|
panelHelp: 'text-xs text-fg-muted',
|
|
220
|
-
panelWarn: 'rounded-
|
|
221
|
-
stage: mergeClass('relative h-120 w-full touch-none select-none overflow-hidden
|
|
246
|
+
panelWarn: 'rounded-item bg-warning-soft px-2 py-1 text-xs text-warning-on-soft',
|
|
247
|
+
stage: mergeClass(mergeClass('relative h-120 min-w-0 w-full flex-1 touch-none select-none overflow-hidden', KIT_FOCUS_RING.button), kitShellRecipe({ tone: 'sunken', shadow: false })),
|
|
222
248
|
svgRoot: 'absolute left-0 top-0 h-full w-full',
|
|
223
|
-
gridDot:
|
|
249
|
+
gridDot: KIT_CANVAS_DOT_FILL_CLASS,
|
|
224
250
|
gridRect: 'h-full w-full',
|
|
225
251
|
overlaySvg: 'pointer-events-none absolute left-0 top-0 h-full w-full',
|
|
226
252
|
fo: 'overflow-visible',
|
|
227
|
-
nodeBase: 'relative box-border flex h-auto min-h-full w-full flex-col justify-between gap-1 rounded-
|
|
253
|
+
nodeBase: 'relative box-border flex h-auto min-h-full w-full flex-col justify-between gap-1 rounded-card border px-3 py-2 text-sm text-fg shadow-xs ' + KIT_FOCUS_RING.button,
|
|
228
254
|
head: 'flex items-center gap-2',
|
|
229
255
|
body: 'flex min-w-0 flex-col',
|
|
230
256
|
barCap: 'min-w-0 flex-1 truncate',
|
|
@@ -233,22 +259,25 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
233
259
|
line: 'truncate text-xs text-fg-muted',
|
|
234
260
|
lineError: 'truncate text-xs text-danger-on-soft',
|
|
235
261
|
lineWarning: 'truncate text-xs text-warning-on-soft',
|
|
236
|
-
cfgBtn: 'shrink-0 rounded-
|
|
237
|
-
inPort:
|
|
238
|
-
|
|
239
|
-
|
|
262
|
+
cfgBtn: 'inline-flex size-6 shrink-0 items-center justify-center rounded-item p-0 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.button,
|
|
263
|
+
inPort: IN_PORT_BASE,
|
|
264
|
+
inPortSnap: mergeClass(IN_PORT_BASE, 'bg-primary ring-2 ring-primary'),
|
|
265
|
+
outPort: `absolute -right-2 top-10 -mt-2 h-4 w-4 p-0 cursor-crosshair rounded-full ${EDGE_LIVE} bg-surface hover:bg-state-layer-hover ${KIT_FOCUS_RING.button}`,
|
|
266
|
+
draftEdge: 'fill-none stroke-primary stroke-2 pointer-events-none',
|
|
267
|
+
bar: `box-border flex h-full w-full max-w-full items-center gap-1 overflow-hidden rounded-float ${EDGE_STILL} bg-surface px-2 text-xs text-fg shadow-sm`,
|
|
240
268
|
edgeG: 'group cursor-pointer outline-none',
|
|
241
269
|
edgeHit: 'fill-none stroke-transparent stroke-12',
|
|
242
270
|
edgeLabel: 'fill-fg-muted text-xs',
|
|
243
271
|
edgeLabelBg: 'fill-surface stroke-border-subtle',
|
|
244
272
|
emptyOuter: '',
|
|
245
273
|
emptyInner: 'pointer-events-none absolute inset-0 flex items-center justify-center px-4 text-center text-sm text-fg-muted',
|
|
246
|
-
|
|
274
|
+
errorRow: 'flex flex-wrap items-center justify-between gap-2',
|
|
275
|
+
errorInner: 'min-w-0 flex-1 rounded-item border border-danger bg-danger-soft px-3 py-2 text-sm text-danger-on-soft',
|
|
247
276
|
marqueeRect: 'fill-primary-soft stroke-primary opacity-50',
|
|
248
277
|
menuFo: 'pointer-events-auto overflow-visible',
|
|
249
278
|
menuInner: mergeClass('box-border flex w-full flex-col gap-1 p-1', kitSurfaceRecipe('raised')),
|
|
250
|
-
menuItem: 'rounded-
|
|
251
|
-
menuItemDanger: 'rounded-
|
|
279
|
+
menuItem: 'rounded-item px-2 py-1 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.item,
|
|
280
|
+
menuItemDanger: 'rounded-item px-2 py-1 text-start text-sm text-danger-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ' + KIT_FOCUS_RING.item,
|
|
252
281
|
status: 'text-xs text-fg-muted',
|
|
253
282
|
srOnly: 'sr-only',
|
|
254
283
|
hidden: 'hidden',
|
|
@@ -258,8 +287,9 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
258
287
|
|
|
259
288
|
export const FLOW_NODE_BG = Object.freeze({
|
|
260
289
|
normal: 'bg-surface',
|
|
261
|
-
|
|
262
|
-
|
|
290
|
+
// 选中 = 主色环(不再直写 primary-soft 作选中底,KT-HB-F);建议虚影 = 面底 + 降透明
|
|
291
|
+
selected: 'bg-surface ring-2 ring-primary',
|
|
292
|
+
ghost: mergeClass('bg-surface', KIT_DIMMED_CLASS),
|
|
263
293
|
});
|
|
264
294
|
|
|
265
295
|
export const FLOW_NODE_BORDER = Object.freeze({
|
|
@@ -287,13 +317,14 @@ export const FLOW_MARKER_FILL = Object.freeze({
|
|
|
287
317
|
ghost: 'fill-primary',
|
|
288
318
|
});
|
|
289
319
|
|
|
320
|
+
// 节点类型 / 状态小标签 = 闭集值出口(F7 kitClosedValueRecipe),仅追加 shrink-0
|
|
290
321
|
export const FLOW_TONE_BADGE: Readonly<Record<FlowTone, string>> = Object.freeze({
|
|
291
|
-
neutral: 'shrink-0
|
|
292
|
-
info: 'shrink-0
|
|
293
|
-
success: 'shrink-0
|
|
294
|
-
warning: 'shrink-0
|
|
295
|
-
danger: 'shrink-0
|
|
296
|
-
primary: 'shrink-0
|
|
322
|
+
neutral: mergeClass(kitClosedValueRecipe('neutral'), 'shrink-0'),
|
|
323
|
+
info: mergeClass(kitClosedValueRecipe('info'), 'shrink-0'),
|
|
324
|
+
success: mergeClass(kitClosedValueRecipe('success'), 'shrink-0'),
|
|
325
|
+
warning: mergeClass(kitClosedValueRecipe('warning'), 'shrink-0'),
|
|
326
|
+
danger: mergeClass(kitClosedValueRecipe('danger'), 'shrink-0'),
|
|
327
|
+
primary: mergeClass(kitClosedValueRecipe('primary'), 'shrink-0'),
|
|
297
328
|
});
|
|
298
329
|
|
|
299
330
|
export const FLOW_TONE_DOT: Readonly<Record<FlowTone, string>> = Object.freeze({
|
|
@@ -309,6 +340,10 @@ function split(value: string): string[] {
|
|
|
309
340
|
return value.split(/\s+/).filter((c) => c !== '');
|
|
310
341
|
}
|
|
311
342
|
|
|
343
|
+
const FLOW_AUTO_TONE_CANDIDATES: readonly string[] = (
|
|
344
|
+
['neutral', 'primary', 'info', 'success', 'warning', 'danger', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8'] as const
|
|
345
|
+
).flatMap((t) => [...split(kitToneSoftBadgeClass(t)), ...split(kitToneAccentBorderClass(t))]);
|
|
346
|
+
|
|
312
347
|
/** 本组件自带的全部类(供编译器并入候选类):由上面的表推出,不手抄 */
|
|
313
348
|
export const KIT_FLOW_EDITOR_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
314
349
|
[...new Set([
|
|
@@ -320,6 +355,10 @@ export const KIT_FLOW_EDITOR_CLASS_CANDIDATES: readonly string[] = Object.freeze
|
|
|
320
355
|
...Object.values(FLOW_MARKER_FILL).flatMap(split),
|
|
321
356
|
...Object.values(FLOW_TONE_BADGE).flatMap(split),
|
|
322
357
|
...Object.values(FLOW_TONE_DOT).flatMap(split),
|
|
358
|
+
...FLOW_AUTO_TONE_CANDIDATES,
|
|
359
|
+
...KIT_COLOR_ROLE_CLASS_CANDIDATES,
|
|
360
|
+
'inline-flex', 'size-5', 'items-center', 'justify-center', 'p-0',
|
|
361
|
+
...KIT_ICON_CLASS_CANDIDATES,
|
|
323
362
|
// 配置面板嵌入的基础组件与 FieldMapper
|
|
324
363
|
...KIT_INPUT_CLASS_CANDIDATES,
|
|
325
364
|
...KIT_TEXTAREA_CLASS_CANDIDATES,
|
|
@@ -371,15 +410,40 @@ export function inPort(p: Pt): Pt {
|
|
|
371
410
|
return { x: p.x, y: p.y + FLOW_GEOMETRY.nodeH / 2 };
|
|
372
411
|
}
|
|
373
412
|
|
|
413
|
+
/** 拖拽端口橡皮筋预览连线:起点锚定源端口中心,终点跟随画布世界坐标(或吸附至目标入端口中心)的三次贝塞尔路径 */
|
|
414
|
+
export function draftEdgePath(fromPort: Pt, toPt: Pt, direction: FlowDirection = 'LR'): string {
|
|
415
|
+
if (direction === 'TB') {
|
|
416
|
+
const dy = Math.max(FLOW_GEOMETRY.bezierMin, Math.abs(toPt.y - fromPort.y) / 2);
|
|
417
|
+
const c1 = { x: fromPort.x, y: fromPort.y + dy };
|
|
418
|
+
const c2 = { x: toPt.x, y: toPt.y - dy };
|
|
419
|
+
return `M ${r2(fromPort.x)} ${r2(fromPort.y)} C ${r2(c1.x)} ${r2(c1.y)} ${r2(c2.x)} ${r2(c2.y)} ${r2(toPt.x)} ${r2(toPt.y)}`;
|
|
420
|
+
}
|
|
421
|
+
const dx = Math.max(FLOW_GEOMETRY.bezierMin, Math.abs(toPt.x - fromPort.x) / 2);
|
|
422
|
+
const c1 = { x: fromPort.x + dx, y: fromPort.y };
|
|
423
|
+
const c2 = { x: toPt.x - dx, y: toPt.y };
|
|
424
|
+
return `M ${r2(fromPort.x)} ${r2(fromPort.y)} C ${r2(c1.x)} ${r2(c1.y)} ${r2(c2.x)} ${r2(c2.y)} ${r2(toPt.x)} ${r2(toPt.y)}`;
|
|
425
|
+
}
|
|
426
|
+
|
|
374
427
|
/** 连线:从 from 的出端口到 to 的入端口的三次贝塞尔;mid 是 t=0.5 处,放连线标签 */
|
|
375
|
-
export function edgeGeometry(from: Pt, to: Pt): { d: string; mid: Pt } {
|
|
428
|
+
export function edgeGeometry(from: Pt, to: Pt, direction: FlowDirection = 'LR'): { d: string; mid: Pt } {
|
|
429
|
+
if (direction === 'TB') {
|
|
430
|
+
const a = { x: from.x + FLOW_GEOMETRY.nodeW / 2, y: from.y + FLOW_GEOMETRY.nodeH };
|
|
431
|
+
const b = { x: to.x + FLOW_GEOMETRY.nodeW / 2, y: to.y };
|
|
432
|
+
const dy = Math.max(FLOW_GEOMETRY.bezierMin, Math.abs(b.y - a.y) / 2);
|
|
433
|
+
const c1 = { x: a.x, y: a.y + dy };
|
|
434
|
+
const c2 = { x: b.x, y: b.y - dy };
|
|
435
|
+
return {
|
|
436
|
+
d: draftEdgePath(a, b, 'TB'),
|
|
437
|
+
mid: { x: r2((a.x + 3 * c1.x + 3 * c2.x + b.x) / 8), y: r2((a.y + 3 * c1.y + 3 * c2.y + b.y) / 8) },
|
|
438
|
+
};
|
|
439
|
+
}
|
|
376
440
|
const a = outPort(from);
|
|
377
441
|
const b = inPort(to);
|
|
378
442
|
const dx = Math.max(FLOW_GEOMETRY.bezierMin, Math.abs(b.x - a.x) / 2);
|
|
379
443
|
const c1 = { x: a.x + dx, y: a.y };
|
|
380
444
|
const c2 = { x: b.x - dx, y: b.y };
|
|
381
445
|
return {
|
|
382
|
-
d:
|
|
446
|
+
d: draftEdgePath(a, b, 'LR'),
|
|
383
447
|
mid: { x: r2((a.x + 3 * c1.x + 3 * c2.x + b.x) / 8), y: r2((a.y + 3 * c1.y + 3 * c2.y + b.y) / 8) },
|
|
384
448
|
};
|
|
385
449
|
}
|
|
@@ -515,7 +579,7 @@ export interface LayeredResult {
|
|
|
515
579
|
backEdges: string[];
|
|
516
580
|
}
|
|
517
581
|
|
|
518
|
-
export function layeredLayout(nodes: readonly FlowNode[], edges: readonly FlowEdge[]): LayeredResult {
|
|
582
|
+
export function layeredLayout(nodes: readonly FlowNode[], edges: readonly FlowEdge[], direction: FlowDirection = 'LR'): LayeredResult {
|
|
519
583
|
const ids = nodes.map((n) => n.id);
|
|
520
584
|
const known = new Set(ids);
|
|
521
585
|
const order = new Map(ids.map((id, i) => [id, i] as const));
|
|
@@ -569,7 +633,12 @@ export function layeredLayout(nodes: readonly FlowNode[], edges: readonly FlowEd
|
|
|
569
633
|
const r = rank.get(id)!;
|
|
570
634
|
const k = slot.get(r) ?? 0;
|
|
571
635
|
slot.set(r, k + 1);
|
|
572
|
-
positions.set(
|
|
636
|
+
positions.set(
|
|
637
|
+
id,
|
|
638
|
+
direction === 'TB'
|
|
639
|
+
? { x: pad + k * (nodeW + gapX), y: pad + r * (nodeH + gapY) }
|
|
640
|
+
: { x: pad + r * (nodeW + gapX), y: pad + k * (nodeH + gapY) },
|
|
641
|
+
);
|
|
573
642
|
}
|
|
574
643
|
return { positions, ranks: rank, backEdges: edges.filter((e) => back.has(e.id)).map((e) => e.id) };
|
|
575
644
|
}
|
|
@@ -901,8 +970,12 @@ export function suggestionsOf(raw: unknown): FlowSuggestion[] {
|
|
|
901
970
|
return out;
|
|
902
971
|
}
|
|
903
972
|
|
|
904
|
-
function layoutOf(raw: unknown): FlowLayoutMode {
|
|
905
|
-
return raw === 'layered' ? 'layered' : 'manual';
|
|
973
|
+
function layoutOf(raw: unknown, fallback: FlowLayoutMode = 'manual'): FlowLayoutMode {
|
|
974
|
+
return raw === 'layered' ? 'layered' : raw === 'manual' ? 'manual' : fallback;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function directionOf(raw: unknown): FlowDirection {
|
|
978
|
+
return typeof raw === 'string' && raw.toUpperCase() === 'TB' ? 'TB' : 'LR';
|
|
906
979
|
}
|
|
907
980
|
|
|
908
981
|
function tonesOf(raw: unknown): Record<string, FlowTone> {
|
|
@@ -927,14 +1000,19 @@ export function pickOf(props: Record<string, unknown>, key: string): unknown {
|
|
|
927
1000
|
return empty ? rec(rec(props.data).config)[key] : v;
|
|
928
1001
|
}
|
|
929
1002
|
|
|
930
|
-
export function configOf(
|
|
1003
|
+
export function configOf(
|
|
1004
|
+
props: Record<string, unknown>,
|
|
1005
|
+
at?: Element | null,
|
|
1006
|
+
defaults?: { readonly?: boolean; layout?: FlowLayoutMode },
|
|
1007
|
+
): FlowConfig {
|
|
931
1008
|
const dataCfg = rec(rec(props.data).config);
|
|
932
1009
|
const pick = (key: string): unknown => pickOf(props, key);
|
|
933
1010
|
return {
|
|
934
1011
|
// nodeOptions:展示对象给的节点字段候选项(页面 nodeOptions: view.<成员>),并进对应 select 字段的 options
|
|
935
1012
|
nodeTypes: nodeTypesOf(withNodeOptions(pick('nodeTypes'), pick('nodeOptions'))),
|
|
936
|
-
layout: layoutOf(pick('layout')),
|
|
937
|
-
|
|
1013
|
+
layout: layoutOf(pick('layout'), defaults?.layout ?? 'manual'),
|
|
1014
|
+
direction: directionOf(pick('direction')),
|
|
1015
|
+
readonly: defaults?.readonly === true || bool(props.readonly) || bool(props.disabled) || bool(dataCfg.readonly),
|
|
938
1016
|
allowCycles: bool(pick('allowCycles')),
|
|
939
1017
|
statusTones: tonesOf(pick('statusTones')),
|
|
940
1018
|
texts: textsOf(pick('texts'), at),
|
|
@@ -1141,20 +1219,26 @@ export function moveInChain(
|
|
|
1141
1219
|
return { ok: true, graph: { ...graph, nodes, edges }, a, b };
|
|
1142
1220
|
}
|
|
1143
1221
|
|
|
1144
|
-
/** 序号(只读):声明了 numbered
|
|
1145
|
-
export function ordinalsOf(graph: FlowGraph, types: Readonly<Record<string, FlowNodeType
|
|
1222
|
+
/** 序号(只读):声明了 numbered 前缀的节点类型(或 autoNumber 开启时全部节点),按「分层、再按节点输入顺序」依次编号,随图实时重算,不保存 */
|
|
1223
|
+
export function ordinalsOf(graph: FlowGraph, types: Readonly<Record<string, FlowNodeType>>, autoNumber = false): Map<string, string> {
|
|
1146
1224
|
const out = new Map<string, string>();
|
|
1147
|
-
|
|
1225
|
+
const hasTyped = Object.values(types).some((t) => (t.numbered ?? '') !== '');
|
|
1226
|
+
if (!autoNumber && !hasTyped) return out;
|
|
1148
1227
|
const ranks = layeredLayout(graph.nodes, graph.edges).ranks;
|
|
1149
1228
|
const order = new Map(graph.nodes.map((n, i) => [n.id, i] as const));
|
|
1150
1229
|
const counters = new Map<string, number>();
|
|
1230
|
+
let globalSeq = 0;
|
|
1151
1231
|
const sorted = [...graph.nodes].sort((x, y) => ((ranks.get(x.id) ?? 0) - (ranks.get(y.id) ?? 0)) || (order.get(x.id)! - order.get(y.id)!));
|
|
1152
1232
|
for (const n of sorted) {
|
|
1153
1233
|
const prefix = types[n.type]?.numbered ?? '';
|
|
1154
|
-
if (prefix
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1234
|
+
if (prefix !== '') {
|
|
1235
|
+
const c = (counters.get(n.type) ?? 0) + 1;
|
|
1236
|
+
counters.set(n.type, c);
|
|
1237
|
+
out.set(n.id, `${prefix}${c}`);
|
|
1238
|
+
} else if (autoNumber) {
|
|
1239
|
+
globalSeq += 1;
|
|
1240
|
+
out.set(n.id, String(globalSeq));
|
|
1241
|
+
}
|
|
1158
1242
|
}
|
|
1159
1243
|
return out;
|
|
1160
1244
|
}
|
|
@@ -1204,9 +1288,10 @@ interface DragPortLike {
|
|
|
1204
1288
|
|
|
1205
1289
|
type Level = 'error' | 'warning' | '';
|
|
1206
1290
|
type Press =
|
|
1207
|
-
| { kind: 'node'; key: string; sx: number; sy: number; moved: boolean; additive: boolean; origin: Map<string, Pt> | null }
|
|
1208
|
-
| { kind: 'pan'; sx: number; sy: number; moved: boolean; start: FlowView; additive: boolean }
|
|
1209
|
-
| { kind: 'marquee'; sx: number; sy: number; moved: boolean; ax: number; ay: number }
|
|
1291
|
+
| { kind: 'node'; key: string; sx: number; sy: number; moved: boolean; hadButtons: boolean; additive: boolean; origin: Map<string, Pt> | null }
|
|
1292
|
+
| { kind: 'pan'; sx: number; sy: number; moved: boolean; hadButtons: boolean; start: FlowView; additive: boolean }
|
|
1293
|
+
| { kind: 'marquee'; sx: number; sy: number; moved: boolean; hadButtons: boolean; ax: number; ay: number }
|
|
1294
|
+
| { kind: 'port'; fromId: string; sx: number; sy: number; moved: boolean; hadButtons: boolean; snapTo: string | null };
|
|
1210
1295
|
|
|
1211
1296
|
function el<K extends keyof HTMLElementTagNameMap>(tag: K, cls = '', attrs: Record<string, string> = {}): HTMLElementTagNameMap[K] {
|
|
1212
1297
|
const e = document.createElement(tag);
|
|
@@ -1238,7 +1323,9 @@ function place(target: Element, at: Pt, w: number, h: number): void {
|
|
|
1238
1323
|
const keyOfNode = (id: string): string => `n:${id}`;
|
|
1239
1324
|
const keyOfEdge = (id: string): string => `e:${id}`;
|
|
1240
1325
|
|
|
1241
|
-
export function createFlowEditor(): SomaComponentDefinition {
|
|
1326
|
+
export function createFlowEditor(mode: FlowEditorModeOptions = {}): SomaComponentDefinition {
|
|
1327
|
+
const isGraphView = mode.graphView === true;
|
|
1328
|
+
const cfgDefaults = isGraphView ? { readonly: true, layout: 'layered' as const } : undefined;
|
|
1242
1329
|
return {
|
|
1243
1330
|
contract: FLOW_EDITOR_CONTRACT,
|
|
1244
1331
|
services: ['engines', 'data'],
|
|
@@ -1250,9 +1337,21 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1250
1337
|
// ---- 状态
|
|
1251
1338
|
let root: HTMLElement | null = null;
|
|
1252
1339
|
let mounted = false;
|
|
1253
|
-
let cfg: FlowConfig = configOf({});
|
|
1340
|
+
let cfg: FlowConfig = configOf({}, null, cfgDefaults);
|
|
1254
1341
|
let graph: FlowGraph = { nodes: [], edges: [] };
|
|
1255
1342
|
let history: FlowHistory = emptyHistory();
|
|
1343
|
+
const emittedSigs = new Set<string>();
|
|
1344
|
+
const recordEmitted = (g: FlowGraph): void => {
|
|
1345
|
+
if (emittedSigs.size >= 50) {
|
|
1346
|
+
const firstKey = emittedSigs.values().next().value;
|
|
1347
|
+
if (firstKey !== undefined) emittedSigs.delete(firstKey);
|
|
1348
|
+
}
|
|
1349
|
+
emittedSigs.add(graphSig(g));
|
|
1350
|
+
};
|
|
1351
|
+
const topologySig = (g: FlowGraph): string => JSON.stringify([
|
|
1352
|
+
g.nodes.map((n) => [n.id, n.type]),
|
|
1353
|
+
g.edges.map((e) => [e.id, e.from, e.to]),
|
|
1354
|
+
]);
|
|
1256
1355
|
let external: FlowIssue[] = [];
|
|
1257
1356
|
let suggestions: FlowSuggestion[] = [];
|
|
1258
1357
|
let rejected = new Set<string>();
|
|
@@ -1277,8 +1376,17 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1277
1376
|
// H2a:面板 select 字段的候选签名(宿主异步取到 / 换了候选就重画,不受「正在打字」保护)
|
|
1278
1377
|
let panelOptsSig = '';
|
|
1279
1378
|
let panelForce = false;
|
|
1379
|
+
// 面板代次守卫:节点切换、面板清空或卸载时递增,拦截旧嵌入控件迟到的异步变更回调
|
|
1380
|
+
let panelGen = 0;
|
|
1280
1381
|
let hintEls: Array<{ el: HTMLElement; field: FlowField }> = [];
|
|
1281
1382
|
const panelEmbeds = createKitEmbedBag();
|
|
1383
|
+
// 边标签外框按文本签名缓存(消除拖动节点、平移或面板键入时每帧对全图边重复触发 getBBox() 同步布局回流)
|
|
1384
|
+
const labelBoxCache = new Map<string, { w: number; h: number; dx: number; dy: number }>();
|
|
1385
|
+
// 端口拖拽橡皮筋预览线状态与 SVG 节点(仅在拖拽期间挂入 svgLayer,释放/取消/卸载即移除)
|
|
1386
|
+
let draftEdgeEl: SVGPathElement | null = null;
|
|
1387
|
+
let draftState: { fromId: string; endPt: Pt; snapTo: string | null } | null = null;
|
|
1388
|
+
let suppressNextPortClick = false;
|
|
1389
|
+
let recentPortDrop = '';
|
|
1282
1390
|
|
|
1283
1391
|
// ---- 骨架元素(建一次)
|
|
1284
1392
|
let panelOuter!: HTMLElement;
|
|
@@ -1300,14 +1408,19 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1300
1408
|
let emptyInner!: HTMLElement;
|
|
1301
1409
|
let errorOuter!: HTMLElement;
|
|
1302
1410
|
let errorInner!: HTMLElement;
|
|
1411
|
+
let retryBtn: HTMLButtonElement | null = null;
|
|
1412
|
+
let summaryTable: HTMLTableElement | null = null;
|
|
1303
1413
|
let statusEl!: HTMLElement;
|
|
1304
1414
|
let removers: Array<() => void> = [];
|
|
1305
1415
|
let dndCleanups: Array<() => void> = [];
|
|
1306
1416
|
let offMove: (() => void) | null = null;
|
|
1307
1417
|
|
|
1308
1418
|
const t = (key: string, vars: Record<string, string | number> = {}): string => fmt(cfg.texts[key] ?? key, vars);
|
|
1309
|
-
const editable = (): boolean => !cfg.readonly;
|
|
1419
|
+
const editable = (): boolean => !isGraphView && !cfg.readonly;
|
|
1310
1420
|
const movable = (): boolean => editable() && cfg.layout === 'manual';
|
|
1421
|
+
const canZoom = (): boolean => P().zoomable !== false && P().zoomable !== 'false';
|
|
1422
|
+
const canPan = (): boolean => P().pannable !== false && P().pannable !== 'false';
|
|
1423
|
+
const autoFit = (): boolean => P().fit !== false && P().fit !== 'false';
|
|
1311
1424
|
const dndPort = (): DragPortLike | null => {
|
|
1312
1425
|
const engines = (api.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
|
|
1313
1426
|
return engines?.dnd ?? null;
|
|
@@ -1320,7 +1433,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1320
1433
|
|
|
1321
1434
|
// ---- 位置与问题
|
|
1322
1435
|
const computePositions = (): Map<string, Pt> => {
|
|
1323
|
-
const lay = layeredLayout(graph.nodes, graph.edges).positions;
|
|
1436
|
+
const lay = layeredLayout(graph.nodes, graph.edges, cfg.direction).positions;
|
|
1324
1437
|
const out = new Map<string, Pt>();
|
|
1325
1438
|
for (const n of graph.nodes) {
|
|
1326
1439
|
const auto = lay.get(n.id) ?? { x: 0, y: 0 };
|
|
@@ -1376,10 +1489,21 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1376
1489
|
};
|
|
1377
1490
|
|
|
1378
1491
|
const emitSelect = (lastKey?: string): void => {
|
|
1492
|
+
if (isGraphView) return;
|
|
1379
1493
|
const k = lastKey ?? [...selected][selected.size - 1];
|
|
1380
1494
|
if (k === undefined) api.emit('select', { id: '', kind: 'none' });
|
|
1381
1495
|
else api.emit('select', { id: k.slice(2), kind: k.startsWith('n:') ? 'node' : 'edge' });
|
|
1382
1496
|
};
|
|
1497
|
+
const emitNodePick = (id: string): void => {
|
|
1498
|
+
if (!isGraphView) return;
|
|
1499
|
+
const n = nodeById(id);
|
|
1500
|
+
if (n) api.emit('node_pick', { id, node: { ...n, ...(n.meta ? { meta: { ...n.meta } } : {}) } });
|
|
1501
|
+
};
|
|
1502
|
+
const emitEdgePick = (id: string): void => {
|
|
1503
|
+
if (!isGraphView) return;
|
|
1504
|
+
const ed = graph.edges.find((x) => x.id === id);
|
|
1505
|
+
if (ed) api.emit('edge_pick', { id, edge: { ...ed } });
|
|
1506
|
+
};
|
|
1383
1507
|
|
|
1384
1508
|
const setSelection = (keys: Iterable<string>, lastKey?: string): void => {
|
|
1385
1509
|
const next = new Set(keys);
|
|
@@ -1399,6 +1523,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1399
1523
|
history = pushHistory(history, graph, FLOW_GEOMETRY.historyLimit, coalesce);
|
|
1400
1524
|
graph = next;
|
|
1401
1525
|
pruneSelection();
|
|
1526
|
+
recordEmitted(graph);
|
|
1402
1527
|
api.emit('change', payload(graph));
|
|
1403
1528
|
paint();
|
|
1404
1529
|
};
|
|
@@ -1509,7 +1634,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1509
1634
|
|
|
1510
1635
|
const autoLayout = (): void => {
|
|
1511
1636
|
if (!movable()) return;
|
|
1512
|
-
const lay = layeredLayout(graph.nodes, graph.edges).positions;
|
|
1637
|
+
const lay = layeredLayout(graph.nodes, graph.edges, cfg.direction).positions;
|
|
1513
1638
|
commit(setPositions(graph, lay));
|
|
1514
1639
|
fit();
|
|
1515
1640
|
};
|
|
@@ -1518,6 +1643,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1518
1643
|
const r = undoHistory(history, graph);
|
|
1519
1644
|
if (!r) return;
|
|
1520
1645
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1646
|
+
recordEmitted(graph);
|
|
1521
1647
|
api.emit('change', payload(graph));
|
|
1522
1648
|
paint();
|
|
1523
1649
|
};
|
|
@@ -1525,13 +1651,14 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1525
1651
|
const r = redoHistory(history, graph);
|
|
1526
1652
|
if (!r) return;
|
|
1527
1653
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1654
|
+
recordEmitted(graph);
|
|
1528
1655
|
api.emit('change', payload(graph));
|
|
1529
1656
|
paint();
|
|
1530
1657
|
};
|
|
1531
1658
|
|
|
1532
1659
|
// ---- 内置节点配置面板:选中单个节点,按类型的 kind 字段画表单;改动 -> 新图 -> change(经 core 事件写回)+ node_change
|
|
1533
1660
|
const panelTarget = (): { node: FlowNode; fields: FlowField[] } | null => {
|
|
1534
|
-
if (P().panel === false) return null;
|
|
1661
|
+
if (isGraphView || P().panel === false) return null;
|
|
1535
1662
|
const ids = selectedNodeIds();
|
|
1536
1663
|
if (ids.length !== 1 || selectedEdgeIds().length > 0) return null;
|
|
1537
1664
|
const node = nodeById(ids[0]!);
|
|
@@ -1540,7 +1667,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1540
1667
|
};
|
|
1541
1668
|
|
|
1542
1669
|
let panelRefocus = '';
|
|
1543
|
-
const setField = (id: string, f: FlowField, value: unknown): void => {
|
|
1670
|
+
const setField = (id: string, f: FlowField, value: unknown, gen = panelGen): void => {
|
|
1671
|
+
if (!mounted || !root || gen !== panelGen) return;
|
|
1544
1672
|
const cur = nodeById(id);
|
|
1545
1673
|
if (!cur || !editable()) return;
|
|
1546
1674
|
const latest = panelFieldsOf(typeOf(cur)).find((x) => x.key === f.key) ?? f;
|
|
@@ -1560,7 +1688,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1560
1688
|
return Array.isArray(v) ? v.map(String).join('、') : str(v);
|
|
1561
1689
|
};
|
|
1562
1690
|
|
|
1563
|
-
const buildMapping = (row: HTMLElement, id: string, f: FlowField, meta: Record<string, unknown
|
|
1691
|
+
const buildMapping = (row: HTMLElement, id: string, f: FlowField, meta: Record<string, unknown>, gen: number): void => {
|
|
1564
1692
|
const { targets, waiting } = mappingTargets(f, meta);
|
|
1565
1693
|
if (waiting) {
|
|
1566
1694
|
const by = panelFieldsOf(typeOf(nodeById(id)!)).find((x) => x.key === f.targets_by);
|
|
@@ -1581,15 +1709,16 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1581
1709
|
empty_text: f.empty_text ?? t('mapEmpty'),
|
|
1582
1710
|
}, {
|
|
1583
1711
|
change: (p: { value?: unknown }) => {
|
|
1712
|
+
if (!mounted || !root || gen !== panelGen) return;
|
|
1584
1713
|
const { mapping, dropped } = cleanFlowMapping(p.value, prefix);
|
|
1585
1714
|
warn.className = dropped.length > 0 ? FLOW_CLASS.panelWarn : FLOW_CLASS.hidden;
|
|
1586
1715
|
warn.textContent = dropped.length > 0 ? t('dropped', { prefix, names: dropped.join('、') }) : '';
|
|
1587
|
-
setField(id, f, mapping);
|
|
1716
|
+
setField(id, f, mapping, gen);
|
|
1588
1717
|
},
|
|
1589
1718
|
});
|
|
1590
1719
|
};
|
|
1591
1720
|
|
|
1592
|
-
const buildField = (node: FlowNode, f: FlowField): HTMLElement => {
|
|
1721
|
+
const buildField = (node: FlowNode, f: FlowField, gen: number): HTMLElement => {
|
|
1593
1722
|
const meta = node.meta ?? {};
|
|
1594
1723
|
const id = node.id;
|
|
1595
1724
|
const ro = !editable();
|
|
@@ -1599,7 +1728,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1599
1728
|
if (f.required) { const r = el('span', FLOW_CLASS.panelReq, { 'aria-hidden': 'true' }); r.textContent = '*'; lab.appendChild(r); }
|
|
1600
1729
|
row.appendChild(lab);
|
|
1601
1730
|
const common = { aria_label: f.label, disabled: ro, placeholder: f.placeholder ?? '' };
|
|
1602
|
-
const set = (v: unknown): void => setField(id, f, v);
|
|
1731
|
+
const set = (v: unknown): void => setField(id, f, v, gen);
|
|
1603
1732
|
switch (f.kind) {
|
|
1604
1733
|
case 'text': mountCtl(createInput(), row, { ...common, value: str(meta[f.key]) }, { change: (p) => set(str(p.value)) }); break;
|
|
1605
1734
|
case 'textarea': mountCtl(createTextarea(), row, { ...common, value: str(meta[f.key]) }, { change: (p) => set(str(p.value)) }); break;
|
|
@@ -1616,7 +1745,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1616
1745
|
row.appendChild(sel.el);
|
|
1617
1746
|
break;
|
|
1618
1747
|
}
|
|
1619
|
-
case 'mapping': buildMapping(row, id, f, meta); break;
|
|
1748
|
+
case 'mapping': buildMapping(row, id, f, meta, gen); break;
|
|
1620
1749
|
default: break;
|
|
1621
1750
|
}
|
|
1622
1751
|
if (f.help) { const h = el('p', FLOW_CLASS.panelHelp); h.textContent = f.help; row.appendChild(h); }
|
|
@@ -1629,15 +1758,26 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1629
1758
|
};
|
|
1630
1759
|
|
|
1631
1760
|
const buildPanel = (node: FlowNode, fields: readonly FlowField[]): void => {
|
|
1761
|
+
const gen = ++panelGen;
|
|
1632
1762
|
panelEmbeds.release(panelInner);
|
|
1633
1763
|
panelInner.textContent = '';
|
|
1634
1764
|
hintEls = [];
|
|
1765
|
+
const head = el('div', FLOW_CLASS.panelHead);
|
|
1635
1766
|
panelTitleEl = el('h3', FLOW_CLASS.panelTitle);
|
|
1636
|
-
|
|
1637
|
-
|
|
1767
|
+
panelTitleEl.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
1768
|
+
const closeBtn = el('button', FLOW_CLASS.panelClose, {
|
|
1769
|
+
type: 'button',
|
|
1770
|
+
'data-flow-act': 'panel-close',
|
|
1771
|
+
'aria-label': kitText('soma.kit.close', undefined, root),
|
|
1772
|
+
});
|
|
1773
|
+
closeBtn.appendChild(kitIcon('close', 'sm'));
|
|
1774
|
+
head.append(panelTitleEl, closeBtn);
|
|
1775
|
+
panelInner.appendChild(head);
|
|
1776
|
+
for (const f of fields) panelInner.appendChild(buildField(node, f, gen));
|
|
1638
1777
|
};
|
|
1639
1778
|
|
|
1640
1779
|
const clearPanel = (): void => {
|
|
1780
|
+
panelGen += 1;
|
|
1641
1781
|
panelEmbeds.release(panelInner);
|
|
1642
1782
|
panelInner.textContent = '';
|
|
1643
1783
|
hintEls = [];
|
|
@@ -1647,8 +1787,15 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1647
1787
|
};
|
|
1648
1788
|
|
|
1649
1789
|
const focusPanel = (key = ''): void => {
|
|
1650
|
-
|
|
1651
|
-
|
|
1790
|
+
if (key !== '') {
|
|
1791
|
+
const scope = panelInner.querySelector<HTMLElement>(`[data-flow-field="${key}"]`);
|
|
1792
|
+
if (scope) {
|
|
1793
|
+
scope.querySelector<HTMLElement>('[role="combobox"], input:not([type="hidden"]), textarea, button')?.focus();
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
const firstCtl = panelInner.querySelector<HTMLElement>('[data-flow-field] [role="combobox"], [data-flow-field] input:not([type="hidden"]), [data-flow-field] textarea, [data-flow-field] button');
|
|
1798
|
+
(firstCtl ?? panelInner.querySelector<HTMLElement>('[data-flow-act="panel-close"]'))?.focus();
|
|
1652
1799
|
};
|
|
1653
1800
|
|
|
1654
1801
|
function paintPanel(): void {
|
|
@@ -1672,7 +1819,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1672
1819
|
if (f.kind === 'mapping') {
|
|
1673
1820
|
const by = f.targets_by !== undefined ? str(node.meta?.[f.targets_by]) : '';
|
|
1674
1821
|
const base = f.targets_by !== undefined ? (f.targets_map?.[by] ?? []) : (f.targets ?? []);
|
|
1675
|
-
return [f.key, f.prefix ?? '', by, base.map((x) => [x.key, x.label])];
|
|
1822
|
+
return [f.key, f.prefix ?? '', f.placeholder ?? '', f.empty_text ?? '', by, base.map((x) => [x.key, x.label, x.hint ?? ''])];
|
|
1676
1823
|
}
|
|
1677
1824
|
return null;
|
|
1678
1825
|
}));
|
|
@@ -1719,7 +1866,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1719
1866
|
}
|
|
1720
1867
|
|
|
1721
1868
|
const requestConfig = (id: string): void => {
|
|
1722
|
-
if (!nodeById(id)) return;
|
|
1869
|
+
if (isGraphView || !nodeById(id)) return;
|
|
1723
1870
|
const key = keyOfNode(id);
|
|
1724
1871
|
if (!(selected.size === 1 && selected.has(key))) { setSelection([key], key); paint(); }
|
|
1725
1872
|
api.emit('node_config', { id });
|
|
@@ -1768,7 +1915,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1768
1915
|
const first = gh.nodes.find((n) => n.sid === s.id);
|
|
1769
1916
|
const anchor = first ? ghostPosCache.get(first.id) : undefined;
|
|
1770
1917
|
const firstEdge = gh.edges.find((e) => e.sid === s.id);
|
|
1771
|
-
const mid = firstEdge && posOf(firstEdge.from) && posOf(firstEdge.to) ? edgeGeometry(posOf(firstEdge.from)!, posOf(firstEdge.to)
|
|
1918
|
+
const mid = firstEdge && posOf(firstEdge.from) && posOf(firstEdge.to) ? edgeGeometry(posOf(firstEdge.from)!, posOf(firstEdge.to)!, cfg.direction).mid : undefined;
|
|
1772
1919
|
const rawAt = anchor ? { x: anchor.x, y: anchor.y + FLOW_GEOMETRY.nodeH + 4 } : mid;
|
|
1773
1920
|
if (!rawAt) continue;
|
|
1774
1921
|
const x = anchor && barW > FLOW_GEOMETRY.nodeW && rawAt.x + barW > maxRight
|
|
@@ -1830,22 +1977,25 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1830
1977
|
};
|
|
1831
1978
|
|
|
1832
1979
|
// ---- 绘制
|
|
1833
|
-
const mkButton = (act: string, text: string, opts: { disabled?: boolean; primary?: boolean; icon?: KitIconName } = {}): HTMLButtonElement => {
|
|
1980
|
+
const mkButton = (act: string, text: string, opts: { disabled?: boolean; primary?: boolean; icon?: KitIconName; iconSize?: KitIconSize } = {}): HTMLButtonElement => {
|
|
1834
1981
|
const b = el('button', opts.primary ? FLOW_CLASS.btnPrimary : FLOW_CLASS.btn, { type: 'button', 'data-flow-act': act });
|
|
1835
1982
|
if (opts.icon !== undefined) {
|
|
1836
|
-
const ic = kitIcon(opts.icon, 'sm');
|
|
1983
|
+
const ic = kitIcon(opts.icon, opts.iconSize ?? 'sm');
|
|
1837
1984
|
ic.setAttribute('aria-hidden', 'true');
|
|
1838
1985
|
b.appendChild(ic);
|
|
1839
|
-
b.appendChild(document.createTextNode(` ${text}`));
|
|
1986
|
+
if (text !== '') b.appendChild(document.createTextNode(` ${text}`));
|
|
1840
1987
|
} else b.textContent = text;
|
|
1841
1988
|
if (opts.disabled) b.disabled = true;
|
|
1842
1989
|
// 工具栏按钮(btn / btnPrimary 都带边框与底色)单点标 raised
|
|
1843
1990
|
setKitFace(b, 'raised');
|
|
1991
|
+
// 画布工具条与出错行的按钮都经这里:元素部件「动作」单点自报
|
|
1992
|
+
kitMarkPart(b, 'action');
|
|
1844
1993
|
return b;
|
|
1845
1994
|
};
|
|
1846
1995
|
|
|
1847
1996
|
const paintToolbar = (): void => {
|
|
1848
1997
|
toolbar.textContent = '';
|
|
1998
|
+
const cleanAdd = (raw: string): string => raw.replace(/^[++]\s*/, '');
|
|
1849
1999
|
const group = (...btns: HTMLButtonElement[]): HTMLElement => {
|
|
1850
2000
|
const g = el('div', FLOW_CLASS.btnGroup);
|
|
1851
2001
|
g.append(...btns);
|
|
@@ -1853,8 +2003,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1853
2003
|
};
|
|
1854
2004
|
if (editable()) {
|
|
1855
2005
|
const types = Object.values(cfg.nodeTypes);
|
|
1856
|
-
if (types.length === 0) toolbar.appendChild(mkButton('add:', t('add', { type: t('nodeDefault') })));
|
|
1857
|
-
for (const ty of types) toolbar.appendChild(mkButton(`add:${ty.type}`, t('add', { type: ty.label })));
|
|
2006
|
+
if (types.length === 0) toolbar.appendChild(mkButton('add:', cleanAdd(t('add', { type: t('nodeDefault') })), { icon: 'plus', iconSize: 'xs' }));
|
|
2007
|
+
for (const ty of types) toolbar.appendChild(mkButton(`add:${ty.type}`, cleanAdd(t('add', { type: ty.label })), { icon: 'plus', iconSize: 'xs' }));
|
|
1858
2008
|
toolbar.appendChild(group(
|
|
1859
2009
|
mkButton('undo', t('undo'), { disabled: !canUndo(history) }),
|
|
1860
2010
|
mkButton('redo', t('redo'), { disabled: !canRedo(history) }),
|
|
@@ -1870,17 +2020,21 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1870
2020
|
));
|
|
1871
2021
|
if (cfg.layout === 'manual') toolbar.appendChild(mkButton('layout', t('layout'), { disabled: graph.nodes.length === 0 }));
|
|
1872
2022
|
}
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
mkButton('zoom-in', t('zoomIn'))
|
|
1876
|
-
|
|
1877
|
-
));
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2023
|
+
const zoomBtns: HTMLButtonElement[] = [];
|
|
2024
|
+
if (canZoom()) {
|
|
2025
|
+
zoomBtns.push(mkButton('zoom-out', t('zoomOut')), mkButton('zoom-in', t('zoomIn')));
|
|
2026
|
+
}
|
|
2027
|
+
if (canZoom() || canPan()) zoomBtns.push(mkButton('fit', t('fit')));
|
|
2028
|
+
if (zoomBtns.length > 0) toolbar.appendChild(group(...zoomBtns));
|
|
2029
|
+
if (canZoom()) {
|
|
2030
|
+
const z = el('span', FLOW_CLASS.zoomLabel, { 'data-flow-zoom': '' });
|
|
2031
|
+
z.textContent = t('zoomLabel', { n: Math.round(view.zoom * 100) });
|
|
2032
|
+
toolbar.appendChild(z);
|
|
2033
|
+
toolbar.appendChild(el('span', FLOW_CLASS.zoomLabel, { 'data-flow-hint': '' })).textContent = t('zoomHint');
|
|
2034
|
+
}
|
|
1882
2035
|
// 作为表单字段嵌入时不画独立主色蓝底「保存」,避免与弹窗底栏主按钮冲突
|
|
1883
2036
|
if (editable() && !isFormField()) toolbar.appendChild(mkButton('save', t('save'), { primary: true }));
|
|
2037
|
+
toolbar.className = toolbar.childElementCount === 0 ? FLOW_CLASS.hidden : FLOW_CLASS.toolbar;
|
|
1884
2038
|
};
|
|
1885
2039
|
|
|
1886
2040
|
const nodeClass = (sel: boolean, level: Level, ghost: boolean, canMove: boolean): string => {
|
|
@@ -1899,11 +2053,24 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1899
2053
|
const buildNode = (n: FlowNode, at: Pt, opts: { ghost: boolean; issues?: FlowIssue[]; ghostOf?: string }): SVGForeignObjectElement => {
|
|
1900
2054
|
const key = keyOfNode(n.id);
|
|
1901
2055
|
const def = typeOf(n);
|
|
2056
|
+
const typeKeys = Object.keys(cfg.nodeTypes);
|
|
2057
|
+
const typeIdx = Math.max(0, typeKeys.indexOf(n.type));
|
|
2058
|
+
const explicitNodeTone = str(n.meta?.tone) || (def && def.tone !== 'neutral' ? def.tone : '');
|
|
2059
|
+
const resolvedTypeTone = kitResolveStatusOrCategoryTone(
|
|
2060
|
+
str(n.meta?.kind) || n.type || def?.label || n.label,
|
|
2061
|
+
typeIdx,
|
|
2062
|
+
{
|
|
2063
|
+
...(explicitNodeTone !== '' ? { explicitTone: explicitNodeTone } : {}),
|
|
2064
|
+
preferHash: true,
|
|
2065
|
+
host: api.host,
|
|
2066
|
+
},
|
|
2067
|
+
);
|
|
1902
2068
|
const sel = !opts.ghost && selected.has(key);
|
|
1903
2069
|
const level = levelOf(opts.issues);
|
|
1904
2070
|
const fo = svg('foreignObject', FLOW_CLASS.fo);
|
|
1905
2071
|
place(fo, at, FLOW_GEOMETRY.nodeW, FLOW_GEOMETRY.nodeH);
|
|
1906
|
-
const
|
|
2072
|
+
const baseNodeCls = nodeClass(sel, level, opts.ghost, movable() && !opts.ghost);
|
|
2073
|
+
const node = el('div', !opts.ghost && level === '' ? mergeClass(baseNodeCls, kitToneAccentBorderClass(resolvedTypeTone)) : baseNodeCls);
|
|
1907
2074
|
fo.appendChild(node);
|
|
1908
2075
|
const worstIssue = worst(opts.issues);
|
|
1909
2076
|
if (opts.ghost) {
|
|
@@ -1915,11 +2082,19 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1915
2082
|
node.setAttribute('role', 'article');
|
|
1916
2083
|
node.tabIndex = 0;
|
|
1917
2084
|
if (sel) node.setAttribute('data-flow-selected', '');
|
|
2085
|
+
// 选中节点自报(节点角色 article 不支持 aria-selected,只写自报)
|
|
2086
|
+
kitMarkPicked(node, 'selected', sel, null);
|
|
1918
2087
|
const lv = worstIssue ? `,${worstIssue.level === 'error' ? t('levelError') : t('levelWarning')}:${worstIssue.message}` : '';
|
|
1919
2088
|
node.setAttribute('aria-label', `${t('nodeAria', { type: def?.label ?? n.type, label: n.label })}${lv}`);
|
|
1920
2089
|
}
|
|
1921
2090
|
const head = el('div', FLOW_CLASS.head);
|
|
1922
|
-
if (def?.icon) {
|
|
2091
|
+
if (def?.icon) {
|
|
2092
|
+
const i = el('span', mergeClass(mergeClass(FLOW_TONE_BADGE.neutral, 'inline-flex size-5 shrink-0 items-center justify-center overflow-hidden p-0'), kitToneSoftBadgeClass(resolvedTypeTone)), { 'aria-hidden': 'true' });
|
|
2093
|
+
const iconName = resolveKitIconName(def.icon);
|
|
2094
|
+
if (iconName !== null) i.appendChild(kitIcon(iconName, 'xs'));
|
|
2095
|
+
else i.textContent = def.icon;
|
|
2096
|
+
head.appendChild(i);
|
|
2097
|
+
}
|
|
1923
2098
|
const ord = opts.ghost ? undefined : ordinals.get(n.id);
|
|
1924
2099
|
if (ord !== undefined) { const o = el('span', FLOW_CLASS.line, { 'data-flow-ordinal': '' }); o.textContent = ord; head.appendChild(o); }
|
|
1925
2100
|
const label = el('span', FLOW_CLASS.label);
|
|
@@ -1927,9 +2102,9 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1927
2102
|
head.appendChild(label);
|
|
1928
2103
|
const tone = n.status !== undefined ? statusTone(n.status) : null;
|
|
1929
2104
|
if (tone) head.appendChild(el('span', FLOW_TONE_DOT[tone], { 'aria-hidden': 'true' }));
|
|
1930
|
-
if (!opts.ghost) {
|
|
2105
|
+
if (!opts.ghost && editable()) {
|
|
1931
2106
|
const cb = el('button', FLOW_CLASS.cfgBtn, { type: 'button', tabindex: '-1', 'data-flow-act': `cfg:${n.id}`, 'aria-label': `${t('config')} ${n.label}` });
|
|
1932
|
-
cb.
|
|
2107
|
+
cb.appendChild(kitGlyph('settings', 'xs'));
|
|
1933
2108
|
head.appendChild(cb);
|
|
1934
2109
|
}
|
|
1935
2110
|
node.appendChild(head);
|
|
@@ -1937,7 +2112,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1937
2112
|
const body = el('div', FLOW_CLASS.body);
|
|
1938
2113
|
const meta = el('div', FLOW_CLASS.head);
|
|
1939
2114
|
if (def) {
|
|
1940
|
-
const badge = el('span', FLOW_TONE_BADGE[def.tone]);
|
|
2115
|
+
const badge = el('span', mergeClass(FLOW_TONE_BADGE[def.tone], kitToneSoftBadgeClass(resolvedTypeTone)));
|
|
1941
2116
|
badge.textContent = def.label;
|
|
1942
2117
|
meta.appendChild(badge);
|
|
1943
2118
|
}
|
|
@@ -1961,17 +2136,89 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1961
2136
|
}
|
|
1962
2137
|
node.appendChild(body);
|
|
1963
2138
|
|
|
1964
|
-
if (!opts.ghost) {
|
|
1965
|
-
node.appendChild(el('span', FLOW_CLASS.inPort, { 'aria-hidden': 'true' }));
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
node.appendChild(port);
|
|
1969
|
-
}
|
|
2139
|
+
if (!opts.ghost && editable()) {
|
|
2140
|
+
node.appendChild(el('span', FLOW_CLASS.inPort, { 'aria-hidden': 'true', 'data-flow-in-port': n.id }));
|
|
2141
|
+
const port = el('button', FLOW_CLASS.outPort, { type: 'button', tabindex: '-1', 'data-flow-port': n.id, 'aria-label': t('port', { label: n.label }) });
|
|
2142
|
+
node.appendChild(port);
|
|
1970
2143
|
}
|
|
1971
2144
|
return fo;
|
|
1972
2145
|
};
|
|
1973
2146
|
|
|
1974
2147
|
const markerId = (kind: string): string => `${uid}-arrow-${kind}`;
|
|
2148
|
+
const portOutOf = (at: Pt): Pt => (
|
|
2149
|
+
cfg.direction === 'TB'
|
|
2150
|
+
? { x: at.x + FLOW_GEOMETRY.nodeW / 2, y: at.y + FLOW_GEOMETRY.nodeH }
|
|
2151
|
+
: outPort(at)
|
|
2152
|
+
);
|
|
2153
|
+
const portInOf = (at: Pt): Pt => (
|
|
2154
|
+
cfg.direction === 'TB'
|
|
2155
|
+
? { x: at.x + FLOW_GEOMETRY.nodeW / 2, y: at.y }
|
|
2156
|
+
: inPort(at)
|
|
2157
|
+
);
|
|
2158
|
+
|
|
2159
|
+
/** 同步端口拖拽橡皮筋预览线与目标入端口吸附高亮(全程纯 SVG 属性与类令牌,零 .style 写入) */
|
|
2160
|
+
const syncDraftEdgeDom = (): void => {
|
|
2161
|
+
if (nodesLayer) {
|
|
2162
|
+
for (const pEl of nodesLayer.querySelectorAll<HTMLElement>('[data-flow-in-port]')) {
|
|
2163
|
+
const pid = pEl.getAttribute('data-flow-in-port') ?? '';
|
|
2164
|
+
const isSnap = draftState !== null && editable() && draftState.snapTo !== null && pid === draftState.snapTo;
|
|
2165
|
+
if (isSnap) {
|
|
2166
|
+
pEl.className = FLOW_CLASS.inPortSnap;
|
|
2167
|
+
pEl.setAttribute(KIT_ATTR_PORT_ACTIVE, '');
|
|
2168
|
+
} else if (pEl.hasAttribute(KIT_ATTR_PORT_ACTIVE)) {
|
|
2169
|
+
pEl.className = FLOW_CLASS.inPort;
|
|
2170
|
+
pEl.removeAttribute(KIT_ATTR_PORT_ACTIVE);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
if (!draftState || !editable() || !svgLayer) {
|
|
2175
|
+
draftEdgeEl?.remove();
|
|
2176
|
+
draftEdgeEl = null;
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
const fromPos = posOf(draftState.fromId);
|
|
2180
|
+
if (!fromPos) {
|
|
2181
|
+
draftEdgeEl?.remove();
|
|
2182
|
+
draftEdgeEl = null;
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const d = draftEdgePath(portOutOf(fromPos), draftState.endPt, cfg.direction);
|
|
2186
|
+
if (!draftEdgeEl || draftEdgeEl.parentNode !== svgLayer) {
|
|
2187
|
+
draftEdgeEl?.remove();
|
|
2188
|
+
draftEdgeEl = svg('path', FLOW_CLASS.draftEdge, {
|
|
2189
|
+
[KIT_ATTR_FLOW_DRAFT_EDGE]: '',
|
|
2190
|
+
'stroke-dasharray': '5 4',
|
|
2191
|
+
'aria-hidden': 'true',
|
|
2192
|
+
'marker-end': `url(#${markerId('selected')})`,
|
|
2193
|
+
d,
|
|
2194
|
+
});
|
|
2195
|
+
svgLayer.appendChild(draftEdgeEl);
|
|
2196
|
+
} else {
|
|
2197
|
+
draftEdgeEl.setAttribute('d', d);
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
const clearDraftEdge = (): void => {
|
|
2202
|
+
draftState = null;
|
|
2203
|
+
syncDraftEdgeDom();
|
|
2204
|
+
};
|
|
2205
|
+
|
|
2206
|
+
/** 指针靠近合法目标 inPort 时吸附至目标入端口中心并返回目标节点 id */
|
|
2207
|
+
const resolvePortSnap = (fromId: string, worldPt: Pt): { endPt: Pt; snapTo: string | null } => {
|
|
2208
|
+
const snapRadius = 28 / Math.min(1, view.zoom);
|
|
2209
|
+
let best: { id: string; pt: Pt; dist: number } | null = null;
|
|
2210
|
+
for (const n of graph.nodes) {
|
|
2211
|
+
if (n.id === fromId || !canConnect(graph, cfg.nodeTypes, fromId, n.id, cfg.allowCycles).ok) continue;
|
|
2212
|
+
const at = posOf(n.id);
|
|
2213
|
+
if (!at) continue;
|
|
2214
|
+
const pt = portInOf(at);
|
|
2215
|
+
const dist = Math.hypot(worldPt.x - pt.x, worldPt.y - pt.y);
|
|
2216
|
+
if (dist <= snapRadius && (best === null || dist < best.dist)) {
|
|
2217
|
+
best = { id: n.id, pt, dist };
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
return best ? { endPt: best.pt, snapTo: best.id } : { endPt: worldPt, snapTo: null };
|
|
2221
|
+
};
|
|
1975
2222
|
|
|
1976
2223
|
const paintEdges = (): void => {
|
|
1977
2224
|
svgLayer.textContent = '';
|
|
@@ -1989,7 +2236,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1989
2236
|
const b = posOf(e.to);
|
|
1990
2237
|
if (!a || !b) return;
|
|
1991
2238
|
const key = keyOfEdge(e.id);
|
|
1992
|
-
const geo = edgeGeometry(a, b);
|
|
2239
|
+
const geo = edgeGeometry(a, b, cfg.direction);
|
|
1993
2240
|
const sel = !ghost && selected.has(key);
|
|
1994
2241
|
const level = levelOf(issues.get(key));
|
|
1995
2242
|
const kind = ghost ? 'ghost' : sel ? 'selected' : level === 'error' ? 'error' : level === 'warning' ? 'warning' : 'normal';
|
|
@@ -2003,6 +2250,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2003
2250
|
g.setAttribute('role', 'button');
|
|
2004
2251
|
g.setAttribute('tabindex', '0');
|
|
2005
2252
|
g.setAttribute('aria-pressed', sel ? 'true' : 'false');
|
|
2253
|
+
// 连线是 role=button,无障碍属性用上一行的 aria-pressed,这里只补自报
|
|
2254
|
+
kitMarkPicked(g, 'selected', sel, null);
|
|
2006
2255
|
g.setAttribute('aria-label', `${base}${e.label ? `(${e.label})` : ''}${w ? `,${w.level === 'error' ? t('levelError') : t('levelWarning')}:${w.message}` : ''}`);
|
|
2007
2256
|
if (w) {
|
|
2008
2257
|
const tip = svg('title');
|
|
@@ -2026,15 +2275,33 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2026
2275
|
lg.appendChild(text);
|
|
2027
2276
|
labelLayer.appendChild(lg);
|
|
2028
2277
|
labelText = text;
|
|
2029
|
-
//
|
|
2278
|
+
// 标签白底衬垫:按文本签名缓存 getBBox 测量尺寸与中心偏移,避免拖动或键入时每帧重复触发同步回流
|
|
2030
2279
|
let bx = geo.mid.x - (e.label.length * FLOW_LABEL_FONT) / 2;
|
|
2031
2280
|
let by = geo.mid.y - FLOW_LABEL_FONT / 2;
|
|
2032
2281
|
let bw = e.label.length * FLOW_LABEL_FONT;
|
|
2033
2282
|
let bh = FLOW_LABEL_FONT;
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2283
|
+
const cachedBox = labelBoxCache.get(e.label);
|
|
2284
|
+
if (cachedBox !== undefined) {
|
|
2285
|
+
bw = cachedBox.w;
|
|
2286
|
+
bh = cachedBox.h;
|
|
2287
|
+
bx = geo.mid.x + cachedBox.dx;
|
|
2288
|
+
by = geo.mid.y + cachedBox.dy;
|
|
2289
|
+
} else {
|
|
2290
|
+
try {
|
|
2291
|
+
const bb = labelText.getBBox();
|
|
2292
|
+
if (bb.width > 0 && bb.height > 0) {
|
|
2293
|
+
bx = bb.x;
|
|
2294
|
+
by = bb.y;
|
|
2295
|
+
bw = bb.width;
|
|
2296
|
+
bh = bb.height;
|
|
2297
|
+
if (labelBoxCache.size >= 256) {
|
|
2298
|
+
const oldest = labelBoxCache.keys().next().value;
|
|
2299
|
+
if (oldest !== undefined) labelBoxCache.delete(oldest);
|
|
2300
|
+
}
|
|
2301
|
+
labelBoxCache.set(e.label, { w: bw, h: bh, dx: bx - geo.mid.x, dy: by - geo.mid.y });
|
|
2302
|
+
}
|
|
2303
|
+
} catch { /* 无布局环境:用估算 */ }
|
|
2304
|
+
}
|
|
2038
2305
|
lg.insertBefore(svg('rect', FLOW_CLASS.edgeLabelBg, {
|
|
2039
2306
|
x: String(bx - FLOW_LABEL_PAD_X), y: String(by - FLOW_LABEL_PAD_Y), width: String(bw + FLOW_LABEL_PAD_X * 2), height: String(bh + FLOW_LABEL_PAD_Y * 2), rx: '4',
|
|
2040
2307
|
}), text);
|
|
@@ -2046,6 +2313,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2046
2313
|
svgLayer.appendChild(labelLayer);
|
|
2047
2314
|
for (const e of graph.edges) draw(e, false);
|
|
2048
2315
|
for (const e of ghostsOf().edges) draw(e, true);
|
|
2316
|
+
if (draftState !== null) syncDraftEdgeDom();
|
|
2049
2317
|
};
|
|
2050
2318
|
|
|
2051
2319
|
const paintNodes = (issues: Map<string, FlowIssue[]>): void => {
|
|
@@ -2053,7 +2321,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2053
2321
|
dndCleanups = [];
|
|
2054
2322
|
dragFrom = null; // 注销后源的 onDragEnd 可能不再触发
|
|
2055
2323
|
nodesLayer.textContent = '';
|
|
2056
|
-
ordinals = ordinalsOf(graph, cfg.nodeTypes);
|
|
2324
|
+
ordinals = ordinalsOf(graph, cfg.nodeTypes, bool(pickOf(P(), 'numbered')));
|
|
2057
2325
|
const port = dndPort();
|
|
2058
2326
|
const valid = (from: string, to: string): boolean => canConnect(graph, cfg.nodeTypes, from, to, cfg.allowCycles).ok;
|
|
2059
2327
|
for (const n of graph.nodes) {
|
|
@@ -2070,7 +2338,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2070
2338
|
data: () => ({ flowFrom: n.id }),
|
|
2071
2339
|
canDrag: () => editable(),
|
|
2072
2340
|
onDragStart: () => { dragFrom = n.id; markTargets(n.id); },
|
|
2073
|
-
onDragEnd: () => { dragFrom = null; markTargets(
|
|
2341
|
+
onDragEnd: () => { dragFrom = null; clearDraftEdge(); markTargets(connectFrom); },
|
|
2074
2342
|
}));
|
|
2075
2343
|
dndCleanups.push(port.dropTarget(node, {
|
|
2076
2344
|
id: `${uid}|in|${n.id}`,
|
|
@@ -2130,12 +2398,59 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2130
2398
|
paintEdges();
|
|
2131
2399
|
paintPanel();
|
|
2132
2400
|
|
|
2133
|
-
const errText = str(p.error);
|
|
2134
|
-
errorOuter.className = errText === '' ? FLOW_CLASS.hidden :
|
|
2401
|
+
const errText = str(p.error_text) || str(p.error);
|
|
2402
|
+
errorOuter.className = errText === '' ? FLOW_CLASS.hidden : FLOW_CLASS.errorRow;
|
|
2135
2403
|
errorInner.textContent = errText;
|
|
2404
|
+
if (retryBtn) {
|
|
2405
|
+
retryBtn.textContent = str(p.retry_text, kitText('soma.kit.retry', undefined, root));
|
|
2406
|
+
retryBtn.className = errText === '' ? FLOW_CLASS.hidden : FLOW_CLASS.btn;
|
|
2407
|
+
}
|
|
2408
|
+
const loading = bool(p.loading);
|
|
2409
|
+
if (loading) {
|
|
2410
|
+
root.setAttribute('aria-busy', 'true');
|
|
2411
|
+
emptyInner.setAttribute('aria-busy', 'true');
|
|
2412
|
+
emptyInner.setAttribute(KIT_ATTR_STATE, 'loading');
|
|
2413
|
+
} else {
|
|
2414
|
+
root.removeAttribute('aria-busy');
|
|
2415
|
+
emptyInner.removeAttribute('aria-busy');
|
|
2416
|
+
emptyInner.removeAttribute(KIT_ATTR_STATE);
|
|
2417
|
+
}
|
|
2136
2418
|
const empty = graph.nodes.length === 0 && gh.nodes.length === 0;
|
|
2419
|
+
// 数据状态自报到组件根:出错 > 加载 > 空 > 只读(GraphView 恒只读,只读对它不是状态,不报)
|
|
2420
|
+
kitMarkDataFacts(root, { error: errText !== '', loading, empty, readonly: !isGraphView && cfg.readonly });
|
|
2137
2421
|
emptyOuter.className = empty ? '' : FLOW_CLASS.hidden;
|
|
2138
|
-
|
|
2422
|
+
const customEmpty = str(p.empty_text);
|
|
2423
|
+
emptyInner.textContent = loading ? t('loading') : customEmpty !== '' ? customEmpty : cfg.readonly ? t('emptyReadonly') : t('empty');
|
|
2424
|
+
|
|
2425
|
+
if (summaryTable) {
|
|
2426
|
+
summaryTable.textContent = '';
|
|
2427
|
+
if (graph.nodes.length > 0) {
|
|
2428
|
+
const cap = el('caption', '');
|
|
2429
|
+
cap.textContent = t('summary', { nodes: graph.nodes.length, edges: graph.edges.length });
|
|
2430
|
+
const thead = el('thead', '');
|
|
2431
|
+
const hr = el('tr', '');
|
|
2432
|
+
for (const col of [t('nodeDefault'), 'Type', '->']) {
|
|
2433
|
+
const th = el('th', '', { scope: 'col' });
|
|
2434
|
+
th.textContent = col;
|
|
2435
|
+
hr.appendChild(th);
|
|
2436
|
+
}
|
|
2437
|
+
thead.appendChild(hr);
|
|
2438
|
+
const tbody = el('tbody', '');
|
|
2439
|
+
for (const n of graph.nodes) {
|
|
2440
|
+
const tr = el('tr', '');
|
|
2441
|
+
const nh = el('th', '', { scope: 'row' });
|
|
2442
|
+
nh.textContent = n.label;
|
|
2443
|
+
const tdType = el('td', '');
|
|
2444
|
+
tdType.textContent = [typeOf(n)?.label ?? n.type, n.status ?? ''].filter((s) => s !== '').join(' · ');
|
|
2445
|
+
const tdEdges = el('td', '');
|
|
2446
|
+
const outs = graph.edges.filter((e) => e.from === n.id);
|
|
2447
|
+
tdEdges.textContent = outs.map((e) => `${labelOf(e.to)}${e.label ? ` (${e.label})` : ''}`).join(', ') || '—';
|
|
2448
|
+
tr.append(nh, tdType, tdEdges);
|
|
2449
|
+
tbody.appendChild(tr);
|
|
2450
|
+
}
|
|
2451
|
+
summaryTable.append(cap, thead, tbody);
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2139
2454
|
|
|
2140
2455
|
if (needFit && (graph.nodes.length > 0 || gh.nodes.length > 0) && stage.clientWidth > 0 && stage.clientHeight > 0) fit();
|
|
2141
2456
|
applyView();
|
|
@@ -2145,20 +2460,26 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2145
2460
|
const parts = [t('summary', { nodes: graph.nodes.length, edges: graph.edges.length })];
|
|
2146
2461
|
if (errors > 0) parts.push(t('errors', { n: errors }));
|
|
2147
2462
|
if (warns > 0) parts.push(t('warnings', { n: warns }));
|
|
2148
|
-
statusEl.textContent = flash !== '' ? flash :
|
|
2463
|
+
statusEl.textContent = flash !== '' ? flash : loading ? t('loading') : parts.join(' · ');
|
|
2149
2464
|
|
|
2150
2465
|
if (token) {
|
|
2151
2466
|
const target = findByAttr(token.name, token.value);
|
|
2152
|
-
if (target
|
|
2467
|
+
if (target && !(target as HTMLButtonElement).disabled) {
|
|
2468
|
+
(target as unknown as { focus?: () => void }).focus?.();
|
|
2469
|
+
} else if (token.name === 'data-flow-act' && (token.value === 'undo' || token.value === 'redo')) {
|
|
2470
|
+
const alt = findByAttr('data-flow-act', token.value === 'undo' ? 'redo' : 'undo');
|
|
2471
|
+
if (alt && !(alt as HTMLButtonElement).disabled) alt.focus();
|
|
2472
|
+
else stage.focus();
|
|
2473
|
+
}
|
|
2153
2474
|
}
|
|
2154
2475
|
}
|
|
2155
2476
|
|
|
2156
2477
|
// ---- 数据同步
|
|
2157
2478
|
const sync = (first: boolean): void => {
|
|
2158
2479
|
const p = P();
|
|
2159
|
-
cfg = configOf(p, root);
|
|
2480
|
+
cfg = configOf(p, root, cfgDefaults);
|
|
2160
2481
|
// GB4 作表单字段控件(表单给了字段名 name):图来自 value(草稿里的值),否则来自 data
|
|
2161
|
-
const data = graphOf(typeof p.name === 'string' && p.name !== '' ? p.value : p.data);
|
|
2482
|
+
const data = graphOf(!isGraphView && typeof p.name === 'string' && p.name !== '' ? p.value : p.data);
|
|
2162
2483
|
if (root && typeof p.id === 'string' && p.id !== '') root.id = p.id;
|
|
2163
2484
|
// 画布(可聚焦的 group)承载表单传入的标签关联 / 必填 / 无效 / 说明:与自带的说明节点合并,重绘不丢
|
|
2164
2485
|
if (stage) {
|
|
@@ -2166,26 +2487,29 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2166
2487
|
id: stage.id,
|
|
2167
2488
|
aria_label: t('canvas'),
|
|
2168
2489
|
labelledby: p.labelledby,
|
|
2169
|
-
|
|
2170
|
-
|
|
2490
|
+
...(isGraphView ? {} : {
|
|
2491
|
+
required: p.required,
|
|
2492
|
+
invalid: p.invalid,
|
|
2493
|
+
errormessage: p.errormessage,
|
|
2494
|
+
aria_errormessage: p.aria_errormessage,
|
|
2495
|
+
}),
|
|
2171
2496
|
describedby: p.describedby,
|
|
2172
2497
|
aria_describedby: p.aria_describedby,
|
|
2173
|
-
errormessage: p.errormessage,
|
|
2174
|
-
aria_errormessage: p.aria_errormessage,
|
|
2175
2498
|
});
|
|
2176
2499
|
}
|
|
2177
2500
|
const dsig = graphSig(data);
|
|
2178
2501
|
if (first || (dsig !== lastDataSig && dsig !== graphSig(graph))) {
|
|
2179
|
-
// 节点集合不变(宿主只回灌了规整后的 meta
|
|
2502
|
+
// 节点集合不变(宿主只回灌了规整后的 meta)时保持视口,不重新适应画布;拓扑相同时仅更新 present,不清空撤销栈
|
|
2180
2503
|
const sameIds = !first && graph.nodes.length === data.nodes.length && graph.nodes.every((n, i) => n.id === data.nodes[i]?.id);
|
|
2504
|
+
const sameTopoOrEcho = !first && (topologySig(graph) === topologySig(data) || emittedSigs.has(dsig));
|
|
2181
2505
|
graph = data;
|
|
2182
|
-
history = emptyHistory();
|
|
2183
|
-
if (!sameIds) needFit =
|
|
2506
|
+
if (first || !sameTopoOrEcho) history = emptyHistory();
|
|
2507
|
+
if (first || !sameIds) needFit = autoFit();
|
|
2184
2508
|
pruneSelection();
|
|
2185
2509
|
}
|
|
2186
2510
|
lastDataSig = dsig;
|
|
2187
|
-
external = (pickOf(p, 'validation') !== undefined ? issuesOf(pickOf(p, 'validation')) : []);
|
|
2188
|
-
deriveSuggestions(p);
|
|
2511
|
+
external = (!isGraphView && pickOf(p, 'validation') !== undefined ? issuesOf(pickOf(p, 'validation')) : []);
|
|
2512
|
+
if (!isGraphView) deriveSuggestions(p);
|
|
2189
2513
|
};
|
|
2190
2514
|
|
|
2191
2515
|
// 建议 = 显式 suggestions;集合变了「忽略」重置
|
|
@@ -2209,6 +2533,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2209
2533
|
};
|
|
2210
2534
|
|
|
2211
2535
|
const openMenu = (key: string, at: Pt): void => {
|
|
2536
|
+
if (isGraphView) return;
|
|
2212
2537
|
menuInner.textContent = '';
|
|
2213
2538
|
menuInner.setAttribute('aria-label', t('menu'));
|
|
2214
2539
|
const id = key.slice(2);
|
|
@@ -2229,7 +2554,14 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2229
2554
|
b.textContent = text;
|
|
2230
2555
|
menuInner.appendChild(b);
|
|
2231
2556
|
}
|
|
2232
|
-
|
|
2557
|
+
const menuW = FLOW_GEOMETRY.menuW;
|
|
2558
|
+
const menuH = items.length * FLOW_GEOMETRY.menuItemH + 12;
|
|
2559
|
+
const { w: sw, h: sh } = stageSize();
|
|
2560
|
+
const clamped: Pt = {
|
|
2561
|
+
x: sw > 0 ? clamp(at.x, 4, Math.max(4, sw - menuW - 4)) : Math.max(0, at.x),
|
|
2562
|
+
y: sh > 0 ? clamp(at.y, 4, Math.max(4, sh - menuH - 4)) : Math.max(0, at.y),
|
|
2563
|
+
};
|
|
2564
|
+
place(menuFo, clamped, menuW, menuH);
|
|
2233
2565
|
setCls(menuOuter, '');
|
|
2234
2566
|
menuOpen = true;
|
|
2235
2567
|
menuInner.querySelector<HTMLElement>('button')?.focus();
|
|
@@ -2246,28 +2578,65 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2246
2578
|
const target = e.target as Element | null;
|
|
2247
2579
|
if (!target) return;
|
|
2248
2580
|
if (menuOpen && !target.closest('[data-flow-act^="menu-"]')) closeMenu();
|
|
2249
|
-
|
|
2581
|
+
const portEl = target.closest<HTMLElement>('[data-flow-port]');
|
|
2582
|
+
if (portEl) {
|
|
2583
|
+
const fromId = portEl.getAttribute('data-flow-port') ?? '';
|
|
2584
|
+
const fromPos = fromId !== '' ? posOf(fromId) : undefined;
|
|
2585
|
+
if (editable() && fromId !== '' && nodeById(fromId) && fromPos) {
|
|
2586
|
+
const p = stagePoint(e);
|
|
2587
|
+
const startPt = portOutOf(fromPos);
|
|
2588
|
+
const rawWorld = e.clientX === 0 && e.clientY === 0 ? startPt : screenToWorld(view, p.x, p.y);
|
|
2589
|
+
const snapped = resolvePortSnap(fromId, rawWorld);
|
|
2590
|
+
press = { kind: 'port', fromId, sx: e.clientX, sy: e.clientY, moved: false, hadButtons: e.buttons > 0, snapTo: snapped.snapTo };
|
|
2591
|
+
draftState = { fromId, endPt: snapped.endPt, snapTo: snapped.snapTo };
|
|
2592
|
+
markTargets(fromId);
|
|
2593
|
+
syncDraftEdgeDom();
|
|
2594
|
+
}
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
if (target.closest('[data-flow-act]')) return;
|
|
2250
2598
|
const additive = e.shiftKey || e.ctrlKey || e.metaKey;
|
|
2251
2599
|
const nodeEl = target.closest('[data-flow-key^="n:"]');
|
|
2252
2600
|
const p = stagePoint(e);
|
|
2601
|
+
const hadButtons = e.buttons > 0;
|
|
2253
2602
|
if (nodeEl) {
|
|
2254
2603
|
const key = nodeEl.getAttribute('data-flow-key') ?? '';
|
|
2255
|
-
press = { kind: 'node', key, sx: e.clientX, sy: e.clientY, moved: false, additive, origin: null };
|
|
2604
|
+
press = { kind: 'node', key, sx: e.clientX, sy: e.clientY, moved: false, hadButtons, additive, origin: null };
|
|
2256
2605
|
} else if (target.closest('[data-flow-key^="e:"],[data-flow-bar],[data-flow-ghost]')) {
|
|
2257
2606
|
return;
|
|
2258
2607
|
} else if (e.shiftKey) {
|
|
2259
|
-
press = { kind: 'marquee', sx: e.clientX, sy: e.clientY, moved: false, ax: p.x, ay: p.y };
|
|
2608
|
+
press = { kind: 'marquee', sx: e.clientX, sy: e.clientY, moved: false, hadButtons, ax: p.x, ay: p.y };
|
|
2260
2609
|
} else {
|
|
2261
|
-
press = { kind: 'pan', sx: e.clientX, sy: e.clientY, moved: false, start: { ...view }, additive };
|
|
2610
|
+
press = { kind: 'pan', sx: e.clientX, sy: e.clientY, moved: false, hadButtons, start: { ...view }, additive };
|
|
2262
2611
|
}
|
|
2263
2612
|
};
|
|
2264
2613
|
|
|
2265
2614
|
const onPointerMove = (e: PointerEvent): void => {
|
|
2266
2615
|
if (!press) return;
|
|
2267
2616
|
// 按键已在画布外松开(未捕获指针时收不到 up):当作取消,避免无按键的“拖动”
|
|
2268
|
-
if (e.buttons === 0) {
|
|
2617
|
+
if (press.hadButtons && e.buttons === 0) {
|
|
2618
|
+
const wasPort = press.kind === 'port';
|
|
2619
|
+
press = null;
|
|
2620
|
+
dragPos = null;
|
|
2621
|
+
setCls(marqueeOuter, FLOW_CLASS.hidden);
|
|
2622
|
+
if (wasPort) { clearDraftEdge(); markTargets(connectFrom); }
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2269
2625
|
const dx = e.clientX - press.sx;
|
|
2270
2626
|
const dy = e.clientY - press.sy;
|
|
2627
|
+
if (press.kind === 'port') {
|
|
2628
|
+
if (!press.moved && Math.hypot(dx, dy) >= FLOW_GEOMETRY.dragThreshold) {
|
|
2629
|
+
press.moved = true;
|
|
2630
|
+
try { stage.setPointerCapture?.(e.pointerId); } catch { /* 不支持捕获的环境 */ }
|
|
2631
|
+
}
|
|
2632
|
+
const p = stagePoint(e);
|
|
2633
|
+
const worldPt = screenToWorld(view, p.x, p.y);
|
|
2634
|
+
const snapped = resolvePortSnap(press.fromId, worldPt);
|
|
2635
|
+
press.snapTo = snapped.snapTo;
|
|
2636
|
+
draftState = { fromId: press.fromId, endPt: snapped.endPt, snapTo: snapped.snapTo };
|
|
2637
|
+
syncDraftEdgeDom();
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2271
2640
|
if (!press.moved && Math.hypot(dx, dy) < FLOW_GEOMETRY.dragThreshold) return;
|
|
2272
2641
|
if (!press.moved) {
|
|
2273
2642
|
// 越过拖动阈值才捕获指针:单击 / 双击的目标保持为节点本身(捕获会把 click、dblclick 改投给画布)
|
|
@@ -2275,6 +2644,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2275
2644
|
}
|
|
2276
2645
|
press.moved = true;
|
|
2277
2646
|
if (press.kind === 'pan') {
|
|
2647
|
+
if (!canPan()) return;
|
|
2278
2648
|
view = { ...press.start, panX: press.start.panX + dx, panY: press.start.panY + dy };
|
|
2279
2649
|
needFit = false;
|
|
2280
2650
|
applyView();
|
|
@@ -2300,11 +2670,36 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2300
2670
|
}
|
|
2301
2671
|
};
|
|
2302
2672
|
|
|
2673
|
+
const pointInRect = (pt: Pt, r: Rect): boolean => pt.x >= r.x && pt.x <= r.x + r.w && pt.y >= r.y && pt.y <= r.y + r.h;
|
|
2674
|
+
|
|
2303
2675
|
const onPointerUp = (e: PointerEvent): void => {
|
|
2304
2676
|
const pr = press;
|
|
2305
2677
|
press = null;
|
|
2306
2678
|
try { stage.releasePointerCapture?.(e.pointerId); } catch { /* 同上 */ }
|
|
2307
2679
|
if (!pr) return;
|
|
2680
|
+
if (pr.kind === 'port') {
|
|
2681
|
+
clearDraftEdge();
|
|
2682
|
+
markTargets(connectFrom);
|
|
2683
|
+
if (!pr.moved) return;
|
|
2684
|
+
suppressNextPortClick = true;
|
|
2685
|
+
queueMicrotask(() => { suppressNextPortClick = false; });
|
|
2686
|
+
const p = stagePoint(e);
|
|
2687
|
+
const worldPt = screenToWorld(view, p.x, p.y);
|
|
2688
|
+
const domNodeKey = (e.target as Element | null)?.closest('[data-flow-key^="n:"]')?.getAttribute('data-flow-key');
|
|
2689
|
+
const domNodeId = domNodeKey ? domNodeKey.slice(2) : null;
|
|
2690
|
+
const hitNodeId = graph.nodes.find((n) => n.id !== pr.fromId && posOf(n.id) !== undefined && pointInRect(worldPt, nodeRect(posOf(n.id)!)))?.id ?? null;
|
|
2691
|
+
const toId = pr.snapTo ?? (domNodeId !== pr.fromId ? domNodeId : null) ?? hitNodeId;
|
|
2692
|
+
if (toId !== null && toId !== pr.fromId) {
|
|
2693
|
+
const pairKey = `${pr.fromId}\u0000${toId}`;
|
|
2694
|
+
if (recentPortDrop !== pairKey) {
|
|
2695
|
+
recentPortDrop = pairKey;
|
|
2696
|
+
queueMicrotask(() => { if (recentPortDrop === pairKey) recentPortDrop = ''; });
|
|
2697
|
+
flash = '';
|
|
2698
|
+
tryConnect(pr.fromId, toId);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2308
2703
|
flash = '';
|
|
2309
2704
|
if (pr.kind === 'pan') {
|
|
2310
2705
|
if (!pr.moved && !pr.additive && selected.size > 0) { setSelection([]); paint(); }
|
|
@@ -2333,17 +2728,28 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2333
2728
|
};
|
|
2334
2729
|
|
|
2335
2730
|
const onPointerCancel = (): void => {
|
|
2336
|
-
if (!press) return;
|
|
2731
|
+
if (!press && draftState === null) return;
|
|
2337
2732
|
press = null;
|
|
2338
2733
|
dragPos = null;
|
|
2339
|
-
dragFrom = null;
|
|
2340
2734
|
setCls(marqueeOuter, FLOW_CLASS.hidden);
|
|
2341
|
-
|
|
2735
|
+
if (dragFrom === null) {
|
|
2736
|
+
clearDraftEdge();
|
|
2737
|
+
paint();
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
|
|
2741
|
+
const onDragOver = (e: DragEvent): void => {
|
|
2742
|
+
if (dragFrom === null || !editable()) return;
|
|
2743
|
+
const p = stagePoint(e);
|
|
2744
|
+
const worldPt = screenToWorld(view, p.x, p.y);
|
|
2745
|
+
const snapped = resolvePortSnap(dragFrom, worldPt);
|
|
2746
|
+
draftState = { fromId: dragFrom, endPt: snapped.endPt, snapTo: snapped.snapTo };
|
|
2747
|
+
syncDraftEdgeDom();
|
|
2342
2748
|
};
|
|
2343
2749
|
|
|
2344
2750
|
const onWheel = (e: WheelEvent): void => {
|
|
2345
2751
|
// 只有 Ctrl / ⌘ + 滚轮(触控板双指捏合浏览器也会带 ctrlKey)才缩放并拦截;普通滚轮放行,页面照常滚动
|
|
2346
|
-
if (!(e.ctrlKey || e.metaKey)) return;
|
|
2752
|
+
if (!(e.ctrlKey || e.metaKey) || !canZoom()) return;
|
|
2347
2753
|
e.preventDefault();
|
|
2348
2754
|
needFit = false;
|
|
2349
2755
|
const p = stagePoint(e);
|
|
@@ -2367,10 +2773,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2367
2773
|
case 'move-up': case 'move-down': { const ids = selectedNodeIds(); if (ids.length === 1) moveNode(ids[0]!, name === 'move-up' ? 'up' : 'down'); break; }
|
|
2368
2774
|
case 'menu-insert': { closeMenu(); insertAbove(arg, nodeById(arg)?.type ?? ''); break; }
|
|
2369
2775
|
case 'menu-up': case 'menu-down': { closeMenu(); moveNode(arg, name === 'menu-up' ? 'up' : 'down'); break; }
|
|
2370
|
-
case 'zoom-in': zoomBy(FLOW_GEOMETRY.zoomFactor); break;
|
|
2371
|
-
case 'zoom-out': zoomBy(1 / FLOW_GEOMETRY.zoomFactor); break;
|
|
2776
|
+
case 'zoom-in': if (canZoom()) zoomBy(FLOW_GEOMETRY.zoomFactor); break;
|
|
2777
|
+
case 'zoom-out': if (canZoom()) zoomBy(1 / FLOW_GEOMETRY.zoomFactor); break;
|
|
2372
2778
|
case 'fit': fit(); break;
|
|
2373
|
-
case 'save': api.emit('save', payload(graph)); break;
|
|
2779
|
+
case 'save': if (editable()) api.emit('save', payload(graph)); break;
|
|
2780
|
+
case 'retry': api.emit('retry', {}); break;
|
|
2781
|
+
case 'panel-close': setSelection([]); active = ''; paint(); stage.focus(); break;
|
|
2374
2782
|
case 'cfg': requestConfig(arg); break;
|
|
2375
2783
|
case 'accept': accept(arg); break;
|
|
2376
2784
|
case 'reject': reject(arg); break;
|
|
@@ -2399,6 +2807,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2399
2807
|
}
|
|
2400
2808
|
active = nodeKey;
|
|
2401
2809
|
paint();
|
|
2810
|
+
emitNodePick(id);
|
|
2402
2811
|
};
|
|
2403
2812
|
|
|
2404
2813
|
const onClick = (e: MouseEvent): void => {
|
|
@@ -2409,7 +2818,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2409
2818
|
const act = target.closest('[data-flow-act]')?.getAttribute('data-flow-act');
|
|
2410
2819
|
if (act) { runAct(act); return; }
|
|
2411
2820
|
const port = target.closest('[data-flow-port]')?.getAttribute('data-flow-port');
|
|
2412
|
-
if (port) {
|
|
2821
|
+
if (port) {
|
|
2822
|
+
if (suppressNextPortClick) { suppressNextPortClick = false; return; }
|
|
2823
|
+
flash = '';
|
|
2824
|
+
startConnect(port);
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2413
2827
|
const nodeKey = target.closest('[data-flow-key^="n:"]')?.getAttribute('data-flow-key');
|
|
2414
2828
|
if (nodeKey) {
|
|
2415
2829
|
if (consumedPointerKey === nodeKey) return;
|
|
@@ -2426,6 +2840,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2426
2840
|
active = edgeKey;
|
|
2427
2841
|
setSelection(next, edgeKey);
|
|
2428
2842
|
paint();
|
|
2843
|
+
emitEdgePick(edgeKey.slice(2));
|
|
2429
2844
|
}
|
|
2430
2845
|
};
|
|
2431
2846
|
|
|
@@ -2467,29 +2882,42 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2467
2882
|
e.preventDefault();
|
|
2468
2883
|
return;
|
|
2469
2884
|
}
|
|
2470
|
-
if (target.closest('[data-flow-act],[data-flow-port]') && !target.closest('[data-flow-key]')) return;
|
|
2471
|
-
const itemKey = target.closest('[data-flow-key]')?.getAttribute('data-flow-key') ?? null;
|
|
2472
|
-
if (target !== stage && itemKey === null) return;
|
|
2473
2885
|
const mod = e.ctrlKey || e.metaKey;
|
|
2474
2886
|
const key = e.key;
|
|
2475
2887
|
const handled = (): void => { e.preventDefault(); };
|
|
2888
|
+
const inTextEntry = target instanceof HTMLInputElement
|
|
2889
|
+
|| target instanceof HTMLTextAreaElement
|
|
2890
|
+
|| (target instanceof HTMLElement && target.isContentEditable);
|
|
2891
|
+
if (mod && !inTextEntry && editable()) {
|
|
2892
|
+
if (key === 'z' || key === 'Z') { handled(); flash = ''; if (e.shiftKey) doRedo(); else doUndo(); return; }
|
|
2893
|
+
if (key === 'y' || key === 'Y') { handled(); flash = ''; doRedo(); return; }
|
|
2894
|
+
if (key === 's' || key === 'S') { handled(); api.emit('save', payload(graph)); return; }
|
|
2895
|
+
}
|
|
2896
|
+
if (target.closest('[data-flow-act],[data-flow-port]') && !target.closest('[data-flow-key]')) return;
|
|
2897
|
+
const itemKey = target.closest('[data-flow-key]')?.getAttribute('data-flow-key') ?? null;
|
|
2898
|
+
if (target !== stage && itemKey === null) return;
|
|
2476
2899
|
|
|
2477
|
-
if (mod && (key === 'z' || key === 'Z')) { handled(); flash = ''; if (e.shiftKey) doRedo(); else doUndo(); return; }
|
|
2478
|
-
if (mod && (key === 'y' || key === 'Y')) { handled(); flash = ''; doRedo(); return; }
|
|
2479
2900
|
if (mod && (key === 'a' || key === 'A')) { handled(); setSelection(graph.nodes.map((n) => keyOfNode(n.id))); paint(); return; }
|
|
2480
|
-
if (mod && (key === 's' || key === 'S') && editable()) { handled(); api.emit('save', payload(graph)); return; }
|
|
2481
2901
|
if (mod) return;
|
|
2482
|
-
if (key === '+' || key === '=') { handled(); zoomBy(FLOW_GEOMETRY.zoomFactor); return; }
|
|
2483
|
-
if (key === '-' || key === '_') { handled(); zoomBy(1 / FLOW_GEOMETRY.zoomFactor); return; }
|
|
2484
|
-
if (key === '0') { handled(); fit(); return; }
|
|
2902
|
+
if ((key === '+' || key === '=') && canZoom()) { handled(); zoomBy(FLOW_GEOMETRY.zoomFactor); return; }
|
|
2903
|
+
if ((key === '-' || key === '_') && canZoom()) { handled(); zoomBy(1 / FLOW_GEOMETRY.zoomFactor); return; }
|
|
2904
|
+
if (key === '0' && (canZoom() || canPan())) { handled(); fit(); return; }
|
|
2485
2905
|
if (key === 'Escape') {
|
|
2486
2906
|
// 没有可取消的东西时不拦截,让外层浮层的 Esc 照常关闭
|
|
2907
|
+
if (press?.kind === 'port' || draftState !== null) {
|
|
2908
|
+
handled();
|
|
2909
|
+
press = null;
|
|
2910
|
+
dragFrom = null;
|
|
2911
|
+
clearDraftEdge();
|
|
2912
|
+
markTargets(connectFrom);
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2487
2915
|
if (connectFrom !== null) { handled(); connectFrom = null; flash = ''; paint(); return; }
|
|
2488
2916
|
if (selected.size > 0) { handled(); setSelection([]); paint(); }
|
|
2489
2917
|
return;
|
|
2490
2918
|
}
|
|
2491
2919
|
if (key === 'ContextMenu' || (key === 'F10' && e.shiftKey)) {
|
|
2492
|
-
if (itemKey === null) return;
|
|
2920
|
+
if (itemKey === null || isGraphView) return;
|
|
2493
2921
|
handled();
|
|
2494
2922
|
const r = (target.closest('[data-flow-key]') as Element).getBoundingClientRect();
|
|
2495
2923
|
const s = stage.getBoundingClientRect();
|
|
@@ -2511,6 +2939,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2511
2939
|
const dx = dir === 'left' ? -step : dir === 'right' ? step : 0;
|
|
2512
2940
|
const dy = dir === 'up' ? -step : dir === 'down' ? step : 0;
|
|
2513
2941
|
if (itemKey === null) {
|
|
2942
|
+
if (!canPan()) return;
|
|
2514
2943
|
// 画布本体:方向键平移
|
|
2515
2944
|
view = { ...view, panX: view.panX - dx * 5, panY: view.panY - dy * 5 };
|
|
2516
2945
|
needFit = false;
|
|
@@ -2532,10 +2961,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2532
2961
|
if (connectFrom !== null) { tryConnect(connectFrom, itemKey.slice(2)); return; }
|
|
2533
2962
|
setSelection([itemKey], itemKey);
|
|
2534
2963
|
paint();
|
|
2535
|
-
|
|
2964
|
+
if (isGraphView) emitNodePick(itemKey.slice(2));
|
|
2965
|
+
else requestConfig(itemKey.slice(2));
|
|
2536
2966
|
} else {
|
|
2537
2967
|
setSelection([itemKey], itemKey);
|
|
2538
2968
|
paint();
|
|
2969
|
+
emitEdgePick(itemKey.slice(2));
|
|
2539
2970
|
}
|
|
2540
2971
|
return;
|
|
2541
2972
|
}
|
|
@@ -2545,6 +2976,10 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2545
2976
|
if (next.has(itemKey)) next.delete(itemKey); else next.add(itemKey);
|
|
2546
2977
|
setSelection(next, itemKey);
|
|
2547
2978
|
paint();
|
|
2979
|
+
if (isGraphView) {
|
|
2980
|
+
if (itemKey.startsWith('n:')) emitNodePick(itemKey.slice(2));
|
|
2981
|
+
else emitEdgePick(itemKey.slice(2));
|
|
2982
|
+
}
|
|
2548
2983
|
return;
|
|
2549
2984
|
}
|
|
2550
2985
|
if ((key === 'c' || key === 'C') && itemKey.startsWith('n:')) { handled(); flash = ''; startConnect(itemKey.slice(2)); return; }
|
|
@@ -2564,6 +2999,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2564
2999
|
const build = (host: HTMLElement): void => {
|
|
2565
3000
|
host.textContent = '';
|
|
2566
3001
|
toolbar = el('div', FLOW_CLASS.toolbar, { role: 'toolbar', 'aria-label': t('canvas') });
|
|
3002
|
+
// 自管布局的编辑器只报一级结构:工具条 = 面头,右键菜单 = 浮起,空态 / 出错行 / 配置面板 = 子块(不深入画布内部)
|
|
3003
|
+
kitMarkLevel(toolbar, 'head'); kitApplyLevelClass(toolbar);
|
|
2567
3004
|
const help = el('p', FLOW_CLASS.srOnly, { id: `${uid}-help` });
|
|
2568
3005
|
help.textContent = t('help');
|
|
2569
3006
|
stage = el('div', FLOW_CLASS.stage, { tabindex: '0', role: 'group', 'aria-roledescription': t('canvas'), 'aria-label': t('canvas'), 'aria-describedby': `${uid}-help` });
|
|
@@ -2590,26 +3027,38 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2590
3027
|
menuOuter = svg('g', FLOW_CLASS.hidden);
|
|
2591
3028
|
menuFo = svg('foreignObject', FLOW_CLASS.menuFo);
|
|
2592
3029
|
menuInner = el('div', FLOW_CLASS.menuInner, { role: 'menu' });
|
|
3030
|
+
kitMarkLevel(menuInner, 'float'); kitApplyLevelClass(menuInner);
|
|
2593
3031
|
menuFo.appendChild(menuInner);
|
|
2594
3032
|
menuOuter.appendChild(menuFo);
|
|
2595
3033
|
overlay.append(marqueeOuter, menuOuter);
|
|
2596
3034
|
emptyOuter = el('div', '');
|
|
2597
3035
|
emptyInner = el('div', FLOW_CLASS.emptyInner, { role: 'status' });
|
|
3036
|
+
kitMarkLevel(emptyInner, 'sub'); kitApplyLevelClass(emptyInner);
|
|
2598
3037
|
emptyOuter.appendChild(emptyInner);
|
|
2599
3038
|
stage.append(canvas, overlay, emptyOuter);
|
|
2600
3039
|
errorOuter = el('div', FLOW_CLASS.hidden);
|
|
2601
3040
|
errorInner = el('div', FLOW_CLASS.errorInner, { role: 'alert' });
|
|
3041
|
+
kitMarkLevel(errorOuter, 'sub'); kitApplyLevelClass(errorOuter);
|
|
2602
3042
|
errorOuter.appendChild(errorInner);
|
|
3043
|
+
if (isGraphView) {
|
|
3044
|
+
retryBtn = mkButton('retry', kitText('soma.kit.retry', undefined, host));
|
|
3045
|
+
retryBtn.setAttribute(KIT_ATTR_RETRY, '');
|
|
3046
|
+
errorOuter.appendChild(retryBtn);
|
|
3047
|
+
} else {
|
|
3048
|
+
retryBtn = null;
|
|
3049
|
+
}
|
|
2603
3050
|
statusEl = el('p', FLOW_CLASS.status, { role: 'status', 'aria-live': 'polite' });
|
|
2604
3051
|
// 画布 + 右侧配置面板同一行;面板外层只管显隐,内层管样式
|
|
2605
3052
|
panelOuter = el('div', FLOW_CLASS.hidden);
|
|
2606
|
-
panelInner = el('div', FLOW_CLASS.panel, { role: 'region',
|
|
3053
|
+
panelInner = el('div', FLOW_CLASS.panel, { role: 'region', [KIT_ATTR_CONTAINER]: 'card' });
|
|
3054
|
+
kitMarkLevel(panelInner, 'sub'); kitApplyLevelClass(panelInner);
|
|
2607
3055
|
panelOuter.appendChild(panelInner);
|
|
2608
3056
|
panelId = '';
|
|
2609
3057
|
panelVals = '';
|
|
2610
3058
|
const row = el('div', FLOW_CLASS.row);
|
|
2611
3059
|
row.append(stage, panelOuter);
|
|
2612
|
-
|
|
3060
|
+
summaryTable = isGraphView ? el('table', FLOW_CLASS.srOnly, { [KIT_ATTR_GRAPH_SUMMARY]: '' }) : null;
|
|
3061
|
+
host.append(errorOuter, toolbar, help, row, ...(summaryTable ? [summaryTable] : []), statusEl);
|
|
2613
3062
|
};
|
|
2614
3063
|
|
|
2615
3064
|
return {
|
|
@@ -2636,6 +3085,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2636
3085
|
on(stage, 'pointermove', onPointerMove as (e: Event) => void);
|
|
2637
3086
|
on(stage, 'pointerup', onPointerUp as (e: Event) => void);
|
|
2638
3087
|
on(stage, 'pointercancel', onPointerCancel);
|
|
3088
|
+
on(stage, 'dragover', onDragOver as (e: Event) => void);
|
|
2639
3089
|
on(stage, 'wheel', onWheel as (e: Event) => void, { passive: false });
|
|
2640
3090
|
on(root, 'pointerdown', ((e: PointerEvent) => {
|
|
2641
3091
|
if (menuOpen && !(e.target as Element | null)?.closest('[data-flow-act^="menu-"]')) closeMenu();
|
|
@@ -2675,13 +3125,24 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2675
3125
|
const from = fromOf(intent.sourceId);
|
|
2676
3126
|
const prefix = `${uid}|in|`;
|
|
2677
3127
|
if (from === null || !intent.targetId.startsWith(prefix)) return;
|
|
3128
|
+
const to = intent.targetId.slice(prefix.length);
|
|
3129
|
+
const pairKey = `${from}\u0000${to}`;
|
|
2678
3130
|
flash = '';
|
|
2679
3131
|
dragFrom = null;
|
|
2680
|
-
|
|
3132
|
+
clearDraftEdge();
|
|
3133
|
+
if (recentPortDrop === pairKey) return;
|
|
3134
|
+
recentPortDrop = pairKey;
|
|
3135
|
+
queueMicrotask(() => { if (recentPortDrop === pairKey) recentPortDrop = ''; });
|
|
3136
|
+
tryConnect(from, to);
|
|
2681
3137
|
});
|
|
2682
3138
|
}
|
|
2683
3139
|
return () => {
|
|
2684
3140
|
mounted = false;
|
|
3141
|
+
panelGen += 1;
|
|
3142
|
+
press = null;
|
|
3143
|
+
dragFrom = null;
|
|
3144
|
+
clearDraftEdge();
|
|
3145
|
+
labelBoxCache.clear();
|
|
2685
3146
|
for (const fn of removers) fn();
|
|
2686
3147
|
removers = [];
|
|
2687
3148
|
for (const fn of dndCleanups) fn();
|