soma-kit 0.1.11 → 0.1.13
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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/data/flow-editor.ts
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
// 本文件依次是:数据与配置形状、类串表、几何、撤销栈、分层布局、输入解析、图编辑规则、组件。
|
|
12
12
|
// 纯函数(布局、几何、规则、撤销栈、解析)均已导出,供业务组件与测试直接用。
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
import { watchKitOutcome } from './outcome-watch';
|
|
14
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
15
|
import { mappingPrefixOf } from './flow-remote-options';
|
|
16
|
+
import { clearFlowNodeField, withNodeOptions } from './flow-node-options';
|
|
17
17
|
import { FLOW_EDITOR_CONTRACT } from './flow-editor-contract';
|
|
18
|
-
import { pickPath } from '../object-renderer/adopt-gate';
|
|
19
18
|
import { designFlowEditorGeometry } from 'soma-foundation/layout';
|
|
20
19
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
21
|
-
import { bool,
|
|
20
|
+
import { applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
22
21
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
|
+
import { setKitFace } from '../recipes';
|
|
23
23
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
24
24
|
import { createInput, KIT_INPUT_CLASS_CANDIDATES } from '../base/input';
|
|
25
25
|
import { createTextarea, KIT_TEXTAREA_CLASS_CANDIDATES } from '../base/textarea';
|
|
@@ -196,7 +196,7 @@ export function fmt(template: string, vars: Record<string, string | number>): st
|
|
|
196
196
|
export const FLOW_CLASS = Object.freeze({
|
|
197
197
|
root: 'flex w-full flex-col gap-2',
|
|
198
198
|
toolbar: 'flex flex-wrap items-center gap-2',
|
|
199
|
-
btn: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-
|
|
199
|
+
btn: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-button-edge bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
200
200
|
btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-primary bg-primary px-3 text-sm text-primary-fg transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
201
201
|
zoomLabel: 'text-xs text-fg-muted',
|
|
202
202
|
row: 'flex w-full items-start gap-2',
|
|
@@ -224,9 +224,9 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
224
224
|
line: 'truncate text-xs text-fg-muted',
|
|
225
225
|
lineError: 'truncate text-xs text-danger-on-soft',
|
|
226
226
|
lineWarning: 'truncate text-xs text-warning-on-soft',
|
|
227
|
-
cfgBtn: 'shrink-0 rounded-sm px-1 text-xs text-fg-muted transition-colors hover:bg-
|
|
227
|
+
cfgBtn: 'shrink-0 rounded-sm px-1 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
228
228
|
inPort: 'pointer-events-none absolute -left-1 top-10 -mt-1 h-2 w-2 rounded-full border border-border bg-surface',
|
|
229
|
-
outPort: 'absolute -right-2 top-10 -mt-2 h-4 w-4 cursor-crosshair rounded-full border border-border bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
229
|
+
outPort: 'absolute -right-2 top-10 -mt-2 h-4 w-4 p-0 cursor-crosshair rounded-full border border-border bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
230
230
|
bar: 'box-border flex h-full w-full items-center gap-1 rounded-md border border-border bg-surface px-2 text-xs text-fg shadow-sm',
|
|
231
231
|
edgeG: 'group cursor-pointer outline-none',
|
|
232
232
|
edgeHit: 'fill-none stroke-transparent stroke-12',
|
|
@@ -238,8 +238,8 @@ export const FLOW_CLASS = Object.freeze({
|
|
|
238
238
|
marqueeRect: 'fill-primary-soft stroke-primary opacity-50',
|
|
239
239
|
menuFo: 'pointer-events-auto overflow-visible',
|
|
240
240
|
menuInner: 'box-border flex w-full flex-col gap-1 rounded-md border border-border bg-surface p-1 shadow-lg',
|
|
241
|
-
menuItem: 'rounded-sm px-2 py-1 text-start text-sm text-fg transition-colors hover:bg-
|
|
242
|
-
menuItemDanger: 'rounded-sm px-2 py-1 text-start text-sm text-danger-on-soft transition-colors hover:bg-
|
|
241
|
+
menuItem: 'rounded-sm px-2 py-1 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring',
|
|
242
|
+
menuItemDanger: 'rounded-sm px-2 py-1 text-start text-sm text-danger-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring',
|
|
243
243
|
status: 'text-xs text-fg-muted',
|
|
244
244
|
srOnly: 'sr-only',
|
|
245
245
|
hidden: 'hidden',
|
|
@@ -892,21 +892,6 @@ export function suggestionsOf(raw: unknown): FlowSuggestion[] {
|
|
|
892
892
|
return out;
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
-
/**
|
|
896
|
-
* 请求结果 -> 画布建议(纯函数;`adopt: { from, path? }` 的取值,与表单采纳同口径):outcome.data 按 path 取值,
|
|
897
|
-
* 数组 = 多条建议,带 nodes / edges 的对象 = 一条。建议 id 带请求序号前缀,重新请求后「忽略」自动重置;
|
|
898
|
-
* 节点与连线 id 保持原样(采纳后就是画布草稿里的 id)。个数不超过 dataLimits.flowEditor.adoptSuggestMax。
|
|
899
|
-
*/
|
|
900
|
-
export function adoptSuggestionsOf(data: unknown, path: string, seq: number, label: string): FlowSuggestion[] {
|
|
901
|
-
const root = pickPath(data, path);
|
|
902
|
-
const items = Array.isArray(root) ? root : root !== null && typeof root === 'object' ? [root] : [];
|
|
903
|
-
const raw = items.slice(0, KIT_DATA_LIMITS.flowEditor.adoptSuggestMax).map((item, i) => {
|
|
904
|
-
const o = rec(item);
|
|
905
|
-
return { ...o, id: `adopt${seq}-${str(o.id) !== '' ? str(o.id) : String(i)}`, label: str(o.label) !== '' ? str(o.label) : label };
|
|
906
|
-
});
|
|
907
|
-
return suggestionsOf(raw);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
895
|
function layoutOf(raw: unknown): FlowLayoutMode {
|
|
911
896
|
return raw === 'layered' ? 'layered' : 'manual';
|
|
912
897
|
}
|
|
@@ -937,7 +922,8 @@ export function configOf(props: Record<string, unknown>, at?: Element | null): F
|
|
|
937
922
|
const dataCfg = rec(rec(props.data).config);
|
|
938
923
|
const pick = (key: string): unknown => pickOf(props, key);
|
|
939
924
|
return {
|
|
940
|
-
|
|
925
|
+
// nodeOptions:展示对象给的节点字段候选项(页面 nodeOptions: view.<成员>),并进对应 select 字段的 options
|
|
926
|
+
nodeTypes: nodeTypesOf(withNodeOptions(pick('nodeTypes'), pick('nodeOptions'))),
|
|
941
927
|
layout: layoutOf(pick('layout')),
|
|
942
928
|
readonly: bool(props.readonly) || bool(props.disabled) || bool(dataCfg.readonly),
|
|
943
929
|
allowCycles: bool(pick('allowCycles')),
|
|
@@ -1248,12 +1234,13 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1248
1234
|
contract: FLOW_EDITOR_CONTRACT,
|
|
1249
1235
|
services: ['engines', 'data'],
|
|
1250
1236
|
templateHtml: `<div data-soma-id="root" class="${FLOW_CLASS.root}"></div>`,
|
|
1251
|
-
controllerFactory: (
|
|
1252
|
-
const P = (): Record<string, unknown> =>
|
|
1237
|
+
controllerFactory: createKitController((api) => {
|
|
1238
|
+
const P = (): Record<string, unknown> => api.props();
|
|
1253
1239
|
const uid = `kit-flow-${++SEQ}`;
|
|
1254
1240
|
|
|
1255
1241
|
// ---- 状态
|
|
1256
1242
|
let root: HTMLElement | null = null;
|
|
1243
|
+
let mounted = false;
|
|
1257
1244
|
let cfg: FlowConfig = configOf({});
|
|
1258
1245
|
let graph: FlowGraph = { nodes: [], edges: [] };
|
|
1259
1246
|
let history: FlowHistory = emptyHistory();
|
|
@@ -1261,12 +1248,6 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1261
1248
|
let suggestions: FlowSuggestion[] = [];
|
|
1262
1249
|
let rejected = new Set<string>();
|
|
1263
1250
|
let sugSig = '';
|
|
1264
|
-
// adopt:来自请求结果的建议(订阅的 into 名、路径、标签、当前建议、退订)
|
|
1265
|
-
let adoptFrom = '';
|
|
1266
|
-
let adoptPath = '';
|
|
1267
|
-
let adoptLabel = '';
|
|
1268
|
-
let adoptSug: FlowSuggestion[] = [];
|
|
1269
|
-
let adoptOff: (() => void) | null = null;
|
|
1270
1251
|
let lastDataSig = '';
|
|
1271
1252
|
let view: FlowView = { zoom: 1, panX: 0, panY: 0 };
|
|
1272
1253
|
let needFit = true;
|
|
@@ -1319,7 +1300,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1319
1300
|
const editable = (): boolean => !cfg.readonly;
|
|
1320
1301
|
const movable = (): boolean => editable() && cfg.layout === 'manual';
|
|
1321
1302
|
const dndPort = (): DragPortLike | null => {
|
|
1322
|
-
const engines = (
|
|
1303
|
+
const engines = (api.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
|
|
1323
1304
|
return engines?.dnd ?? null;
|
|
1324
1305
|
};
|
|
1325
1306
|
const nodeById = (id: string): FlowNode | undefined => graph.nodes.find((n) => n.id === id);
|
|
@@ -1387,8 +1368,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1387
1368
|
|
|
1388
1369
|
const emitSelect = (lastKey?: string): void => {
|
|
1389
1370
|
const k = lastKey ?? [...selected][selected.size - 1];
|
|
1390
|
-
if (k === undefined)
|
|
1391
|
-
else
|
|
1371
|
+
if (k === undefined) api.emit('select', { id: '', kind: 'none' });
|
|
1372
|
+
else api.emit('select', { id: k.slice(2), kind: k.startsWith('n:') ? 'node' : 'edge' });
|
|
1392
1373
|
};
|
|
1393
1374
|
|
|
1394
1375
|
const setSelection = (keys: Iterable<string>, lastKey?: string): void => {
|
|
@@ -1409,7 +1390,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1409
1390
|
history = pushHistory(history, graph, FLOW_GEOMETRY.historyLimit, coalesce);
|
|
1410
1391
|
graph = next;
|
|
1411
1392
|
pruneSelection();
|
|
1412
|
-
|
|
1393
|
+
api.emit('change', payload(graph));
|
|
1413
1394
|
paint();
|
|
1414
1395
|
};
|
|
1415
1396
|
|
|
@@ -1528,14 +1509,14 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1528
1509
|
const r = undoHistory(history, graph);
|
|
1529
1510
|
if (!r) return;
|
|
1530
1511
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1531
|
-
|
|
1512
|
+
api.emit('change', payload(graph));
|
|
1532
1513
|
paint();
|
|
1533
1514
|
};
|
|
1534
1515
|
const doRedo = (): void => {
|
|
1535
1516
|
const r = redoHistory(history, graph);
|
|
1536
1517
|
if (!r) return;
|
|
1537
1518
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1538
|
-
|
|
1519
|
+
api.emit('change', payload(graph));
|
|
1539
1520
|
paint();
|
|
1540
1521
|
};
|
|
1541
1522
|
|
|
@@ -1553,11 +1534,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1553
1534
|
const setField = (id: string, f: FlowField, value: unknown): void => {
|
|
1554
1535
|
const cur = nodeById(id);
|
|
1555
1536
|
if (!cur || !editable()) return;
|
|
1556
|
-
const
|
|
1537
|
+
const latest = panelFieldsOf(typeOf(cur)).find((x) => x.key === f.key) ?? f;
|
|
1538
|
+
const next = applyFieldValue(cur, latest, value);
|
|
1557
1539
|
panelVals = panelSig(next, panelFieldsOf(typeOf(cur)));
|
|
1558
1540
|
if (f.kind === 'select' || (f.resets?.length ?? 0) > 0) { panelForce = true; panelRefocus = f.key; }
|
|
1559
1541
|
commit({ ...graph, nodes: graph.nodes.map((n) => (n.id === id ? next : n)) }, `meta:${id}:${f.key}`);
|
|
1560
|
-
|
|
1542
|
+
api.emit('node_change', { id, label: next.label, meta: next.meta ?? {} });
|
|
1561
1543
|
};
|
|
1562
1544
|
|
|
1563
1545
|
const mountCtl = (def: SomaComponentDefinition, parent: HTMLElement, props: Record<string, unknown>, handlers: Record<string, (p: any) => void>): void => {
|
|
@@ -1652,6 +1634,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1652
1634
|
hintEls = [];
|
|
1653
1635
|
panelId = '';
|
|
1654
1636
|
panelVals = '';
|
|
1637
|
+
panelOptsSig = '';
|
|
1655
1638
|
};
|
|
1656
1639
|
|
|
1657
1640
|
const focusPanel = (key = ''): void => {
|
|
@@ -1676,7 +1659,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1676
1659
|
// 候选签名覆盖候选的真实内容:select 的选项(值 + 标签)、mapping 的声明目标(key + 标签,随 targets_by 当前值取);
|
|
1677
1660
|
// 不含 meta 里用户自己写出的映射键(那随打字变化,不该触发重建)
|
|
1678
1661
|
const optsSig = JSON.stringify(fields.map((f) => {
|
|
1679
|
-
if (f.kind === 'select') return [f.key, f.placeholder ?? '', (f.options ?? []).map((o) => [o.value, o.label])];
|
|
1662
|
+
if (f.kind === 'select') return [f.key, f.placeholder ?? '', (f.options ?? []).map((o) => [o.value, o.label, o.meta])];
|
|
1680
1663
|
if (f.kind === 'mapping') {
|
|
1681
1664
|
const by = f.targets_by !== undefined ? str(node.meta?.[f.targets_by]) : '';
|
|
1682
1665
|
const base = f.targets_by !== undefined ? (f.targets_map?.[by] ?? []) : (f.targets ?? []);
|
|
@@ -1730,7 +1713,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1730
1713
|
if (!nodeById(id)) return;
|
|
1731
1714
|
const key = keyOfNode(id);
|
|
1732
1715
|
if (!(selected.size === 1 && selected.has(key))) { setSelection([key], key); paint(); }
|
|
1733
|
-
|
|
1716
|
+
api.emit('node_config', { id });
|
|
1734
1717
|
if (panelTarget() !== null) focusPanel();
|
|
1735
1718
|
};
|
|
1736
1719
|
|
|
@@ -1739,13 +1722,14 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1739
1722
|
if (!s || !editable()) return;
|
|
1740
1723
|
const base = withPositions(graph);
|
|
1741
1724
|
const next = applySuggestion(base, s, ghostPosCache);
|
|
1725
|
+
// 并入后虚影按节点 / 连线 id 去重自然退场(撤销后虚影回来);建议本身由展示对象在 onDraft 里清掉
|
|
1742
1726
|
commit(next);
|
|
1743
|
-
|
|
1727
|
+
api.emit('suggestion_accept', { id: sid });
|
|
1744
1728
|
};
|
|
1745
1729
|
const reject = (sid: string): void => {
|
|
1746
1730
|
rejected = new Set([...rejected, sid]);
|
|
1747
1731
|
paint();
|
|
1748
|
-
|
|
1732
|
+
api.emit('suggestion_reject', { id: sid });
|
|
1749
1733
|
};
|
|
1750
1734
|
|
|
1751
1735
|
// ---- 视图
|
|
@@ -1810,6 +1794,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1810
1794
|
b.appendChild(document.createTextNode(` ${text}`));
|
|
1811
1795
|
} else b.textContent = text;
|
|
1812
1796
|
if (opts.disabled) b.disabled = true;
|
|
1797
|
+
// 工具栏按钮(btn / btnPrimary 都带边框与底色)单点标 raised
|
|
1798
|
+
setKitFace(b, 'raised');
|
|
1813
1799
|
return b;
|
|
1814
1800
|
};
|
|
1815
1801
|
|
|
@@ -1852,7 +1838,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1852
1838
|
};
|
|
1853
1839
|
|
|
1854
1840
|
/** 节点 = foreignObject(x、y、宽、高是几何属性)里放一个 HTML 卡片 */
|
|
1855
|
-
const buildNode = (n: FlowNode, at: Pt, opts: { ghost: boolean; issues?: FlowIssue[] }): SVGForeignObjectElement => {
|
|
1841
|
+
const buildNode = (n: FlowNode, at: Pt, opts: { ghost: boolean; issues?: FlowIssue[]; ghostOf?: string }): SVGForeignObjectElement => {
|
|
1856
1842
|
const key = keyOfNode(n.id);
|
|
1857
1843
|
const def = typeOf(n);
|
|
1858
1844
|
const sel = !opts.ghost && selected.has(key);
|
|
@@ -1865,7 +1851,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1865
1851
|
if (opts.ghost) {
|
|
1866
1852
|
node.setAttribute('data-flow-ghost', '');
|
|
1867
1853
|
node.setAttribute('role', 'img');
|
|
1868
|
-
node.setAttribute('aria-label', `${t('suggestion', { label: n.label })}`);
|
|
1854
|
+
node.setAttribute('aria-label', `${t('suggestion', { label: opts.ghostOf !== undefined && opts.ghostOf !== '' ? `${opts.ghostOf} · ${n.label}` : n.label })}`);
|
|
1869
1855
|
} else {
|
|
1870
1856
|
node.setAttribute('data-flow-key', key);
|
|
1871
1857
|
node.setAttribute('role', 'article');
|
|
@@ -2040,7 +2026,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2040
2026
|
}
|
|
2041
2027
|
}
|
|
2042
2028
|
const gh = ghostsOf();
|
|
2043
|
-
|
|
2029
|
+
const sugLabels = new Map(visibleSuggestions().map((s) => [s.id, s.label] as const));
|
|
2030
|
+
for (const n of gh.nodes) nodesLayer.appendChild(buildNode(n, ghostPosCache.get(n.id) ?? { x: 0, y: 0 }, { ghost: true, ghostOf: n.sid === undefined ? undefined : sugLabels.get(n.sid) }));
|
|
2044
2031
|
for (const s of visibleSuggestions()) {
|
|
2045
2032
|
const first = gh.nodes.find((n) => n.sid === s.id);
|
|
2046
2033
|
const anchor = first ? ghostPosCache.get(first.id) : undefined;
|
|
@@ -2120,6 +2107,20 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2120
2107
|
// GB4 作表单字段控件(表单给了字段名 name):图来自 value(草稿里的值),否则来自 data
|
|
2121
2108
|
const data = graphOf(typeof p.name === 'string' && p.name !== '' ? p.value : p.data);
|
|
2122
2109
|
if (root && typeof p.id === 'string' && p.id !== '') root.id = p.id;
|
|
2110
|
+
// 画布(可聚焦的 group)承载表单传入的标签关联 / 必填 / 无效 / 说明:与自带的说明节点合并,重绘不丢
|
|
2111
|
+
if (stage) {
|
|
2112
|
+
applyCommon(stage, {
|
|
2113
|
+
id: stage.id,
|
|
2114
|
+
aria_label: t('canvas'),
|
|
2115
|
+
labelledby: p.labelledby,
|
|
2116
|
+
required: p.required,
|
|
2117
|
+
invalid: p.invalid,
|
|
2118
|
+
describedby: p.describedby,
|
|
2119
|
+
aria_describedby: p.aria_describedby,
|
|
2120
|
+
errormessage: p.errormessage,
|
|
2121
|
+
aria_errormessage: p.aria_errormessage,
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2123
2124
|
const dsig = graphSig(data);
|
|
2124
2125
|
if (first || (dsig !== lastDataSig && dsig !== graphSig(graph))) {
|
|
2125
2126
|
// 节点集合不变(宿主只回灌了规整后的 meta)时保持视口,不重新适应画布
|
|
@@ -2131,40 +2132,16 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2131
2132
|
}
|
|
2132
2133
|
lastDataSig = dsig;
|
|
2133
2134
|
external = (pickOf(p, 'validation') !== undefined ? issuesOf(pickOf(p, 'validation')) : []);
|
|
2134
|
-
bindAdopt(p);
|
|
2135
2135
|
deriveSuggestions(p);
|
|
2136
2136
|
};
|
|
2137
2137
|
|
|
2138
|
-
// 建议 = 显式 suggestions
|
|
2138
|
+
// 建议 = 显式 suggestions;集合变了「忽略」重置
|
|
2139
2139
|
const deriveSuggestions = (p: Record<string, unknown>): void => {
|
|
2140
|
-
suggestions =
|
|
2140
|
+
suggestions = suggestionsOf(pickOf(p, 'suggestions'));
|
|
2141
2141
|
const sig = JSON.stringify(suggestions.map((s) => s.id));
|
|
2142
2142
|
if (sig !== sugSig) { sugSig = sig; rejected = new Set(); }
|
|
2143
2143
|
};
|
|
2144
2144
|
|
|
2145
|
-
// adopt.from 变了才重订;订阅当下的那次回调只取值不重绘(sync 随后会 paint)
|
|
2146
|
-
const bindAdopt = (p: Record<string, unknown>): void => {
|
|
2147
|
-
const decl = rec(p.adopt);
|
|
2148
|
-
adoptPath = str(decl.path);
|
|
2149
|
-
adoptLabel = str(decl.label) !== '' ? str(decl.label) : kitText('soma.kit.flow_adopt_label', undefined, root);
|
|
2150
|
-
const from = str(decl.from);
|
|
2151
|
-
if (from === adoptFrom) return;
|
|
2152
|
-
adoptOff?.();
|
|
2153
|
-
adoptOff = null;
|
|
2154
|
-
adoptFrom = from;
|
|
2155
|
-
adoptSug = [];
|
|
2156
|
-
if (from === '') return;
|
|
2157
|
-
let subscribing = true;
|
|
2158
|
-
adoptOff = watchKitOutcome((ctx.services as { data?: SomaDataPort } | undefined)?.data, from, (o) => {
|
|
2159
|
-
adoptSug = o.status === 'saved' ? adoptSuggestionsOf(o.data, adoptPath, o.seq, adoptLabel) : [];
|
|
2160
|
-
flash = o.status === 'saved' && adoptSug.length === 0 ? kitText('soma.kit.flow_adopt_none', undefined, root) : '';
|
|
2161
|
-
if (subscribing) return;
|
|
2162
|
-
deriveSuggestions(P());
|
|
2163
|
-
paint();
|
|
2164
|
-
});
|
|
2165
|
-
subscribing = false;
|
|
2166
|
-
};
|
|
2167
|
-
|
|
2168
2145
|
// ---- 指针
|
|
2169
2146
|
const stagePoint = (e: PointerEvent | MouseEvent | WheelEvent): Pt => {
|
|
2170
2147
|
const r = stage.getBoundingClientRect();
|
|
@@ -2291,6 +2268,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2291
2268
|
return;
|
|
2292
2269
|
}
|
|
2293
2270
|
// 节点
|
|
2271
|
+
lastPointerNodeKey = pr.key;
|
|
2294
2272
|
if (pr.moved && dragPos !== null && movable()) {
|
|
2295
2273
|
const moved = dragPos;
|
|
2296
2274
|
dragPos = null;
|
|
@@ -2298,17 +2276,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2298
2276
|
return;
|
|
2299
2277
|
}
|
|
2300
2278
|
dragPos = null;
|
|
2301
|
-
|
|
2302
|
-
if (connectFrom !== null) { tryConnect(connectFrom, id); return; }
|
|
2303
|
-
if (pr.additive) {
|
|
2304
|
-
const next = new Set(selected);
|
|
2305
|
-
if (next.has(pr.key)) next.delete(pr.key); else next.add(pr.key);
|
|
2306
|
-
setSelection(next, pr.key);
|
|
2307
|
-
} else {
|
|
2308
|
-
setSelection([pr.key], pr.key);
|
|
2309
|
-
}
|
|
2310
|
-
active = pr.key;
|
|
2311
|
-
paint();
|
|
2279
|
+
activateNodeKey(pr.key, pr.additive);
|
|
2312
2280
|
};
|
|
2313
2281
|
|
|
2314
2282
|
const onPointerCancel = (): void => {
|
|
@@ -2349,7 +2317,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2349
2317
|
case 'zoom-in': zoomBy(FLOW_GEOMETRY.zoomFactor); break;
|
|
2350
2318
|
case 'zoom-out': zoomBy(1 / FLOW_GEOMETRY.zoomFactor); break;
|
|
2351
2319
|
case 'fit': fit(); break;
|
|
2352
|
-
case 'save':
|
|
2320
|
+
case 'save': api.emit('save', payload(graph)); break;
|
|
2353
2321
|
case 'cfg': requestConfig(arg); break;
|
|
2354
2322
|
case 'accept': accept(arg); break;
|
|
2355
2323
|
case 'reject': reject(arg); break;
|
|
@@ -2365,13 +2333,37 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2365
2333
|
}
|
|
2366
2334
|
};
|
|
2367
2335
|
|
|
2336
|
+
let lastPointerNodeKey = '';
|
|
2337
|
+
const activateNodeKey = (nodeKey: string, additive: boolean): void => {
|
|
2338
|
+
const id = nodeKey.slice(2);
|
|
2339
|
+
if (connectFrom !== null) { tryConnect(connectFrom, id); return; }
|
|
2340
|
+
if (additive) {
|
|
2341
|
+
const next = new Set(selected);
|
|
2342
|
+
if (next.has(nodeKey)) next.delete(nodeKey); else next.add(nodeKey);
|
|
2343
|
+
setSelection(next, nodeKey);
|
|
2344
|
+
} else {
|
|
2345
|
+
setSelection([nodeKey], nodeKey);
|
|
2346
|
+
}
|
|
2347
|
+
active = nodeKey;
|
|
2348
|
+
paint();
|
|
2349
|
+
};
|
|
2350
|
+
|
|
2368
2351
|
const onClick = (e: MouseEvent): void => {
|
|
2352
|
+
const consumedPointerKey = lastPointerNodeKey;
|
|
2353
|
+
lastPointerNodeKey = '';
|
|
2369
2354
|
const target = e.target as Element | null;
|
|
2370
2355
|
if (!target) return;
|
|
2371
2356
|
const act = target.closest('[data-flow-act]')?.getAttribute('data-flow-act');
|
|
2372
2357
|
if (act) { runAct(act); return; }
|
|
2373
2358
|
const port = target.closest('[data-flow-port]')?.getAttribute('data-flow-port');
|
|
2374
2359
|
if (port) { flash = ''; startConnect(port); return; }
|
|
2360
|
+
const nodeKey = target.closest('[data-flow-key^="n:"]')?.getAttribute('data-flow-key');
|
|
2361
|
+
if (nodeKey) {
|
|
2362
|
+
if (consumedPointerKey === nodeKey) return;
|
|
2363
|
+
flash = '';
|
|
2364
|
+
activateNodeKey(nodeKey, e.shiftKey || e.ctrlKey || e.metaKey);
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2375
2367
|
const edgeKey = target.closest('[data-flow-key^="e:"]')?.getAttribute('data-flow-key');
|
|
2376
2368
|
if (edgeKey) {
|
|
2377
2369
|
flash = '';
|
|
@@ -2432,7 +2424,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2432
2424
|
if (mod && (key === 'z' || key === 'Z')) { handled(); flash = ''; if (e.shiftKey) doRedo(); else doUndo(); return; }
|
|
2433
2425
|
if (mod && (key === 'y' || key === 'Y')) { handled(); flash = ''; doRedo(); return; }
|
|
2434
2426
|
if (mod && (key === 'a' || key === 'A')) { handled(); setSelection(graph.nodes.map((n) => keyOfNode(n.id))); paint(); return; }
|
|
2435
|
-
if (mod && (key === 's' || key === 'S') && editable()) { handled();
|
|
2427
|
+
if (mod && (key === 's' || key === 'S') && editable()) { handled(); api.emit('save', payload(graph)); return; }
|
|
2436
2428
|
if (mod) return;
|
|
2437
2429
|
if (key === '+' || key === '=') { handled(); zoomBy(FLOW_GEOMETRY.zoomFactor); return; }
|
|
2438
2430
|
if (key === '-' || key === '_') { handled(); zoomBy(1 / FLOW_GEOMETRY.zoomFactor); return; }
|
|
@@ -2568,9 +2560,24 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2568
2560
|
};
|
|
2569
2561
|
|
|
2570
2562
|
return {
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2563
|
+
/**
|
|
2564
|
+
* 展示对象可调用的公开方法(core 的 ctx.component(id).call):读当前节点、清空某类型节点的某个字段值。
|
|
2565
|
+
* 清空走 commit:入撤销栈、抛 change、重绘,与用户在面板里改值同一条通道。
|
|
2566
|
+
*/
|
|
2567
|
+
handle: {
|
|
2568
|
+
nodes: (): FlowNode[] => graph.nodes.map((n) => ({ ...n, ...(n.meta ? { meta: { ...n.meta } } : {}) })),
|
|
2569
|
+
clearNodeField: (type: unknown, key: unknown): number => {
|
|
2570
|
+
if (typeof type !== 'string' || typeof key !== 'string' || type === '' || key === '' || !editable()) return 0;
|
|
2571
|
+
const rawTypes = pickOf(P(), 'nodeTypes');
|
|
2572
|
+
const res = clearFlowNodeField({ nodes: graph.nodes, edges: graph.edges }, rawTypes, type, key);
|
|
2573
|
+
if (res.cleared === 0) return 0;
|
|
2574
|
+
commit({ ...graph, nodes: (res.value as { nodes: FlowNode[] }).nodes });
|
|
2575
|
+
return res.cleared;
|
|
2576
|
+
},
|
|
2577
|
+
},
|
|
2578
|
+
attach(rootEl) {
|
|
2579
|
+
root = rootEl;
|
|
2580
|
+
mounted = false;
|
|
2574
2581
|
build(root);
|
|
2575
2582
|
on(stage, 'pointerdown', onPointerDown as (e: Event) => void);
|
|
2576
2583
|
on(stage, 'pointermove', onPointerMove as (e: Event) => void);
|
|
@@ -2596,27 +2603,25 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2596
2603
|
tryConnect(from, intent.targetId.slice(prefix.length));
|
|
2597
2604
|
});
|
|
2598
2605
|
}
|
|
2599
|
-
|
|
2606
|
+
return () => {
|
|
2607
|
+
mounted = false;
|
|
2608
|
+
for (const fn of removers) fn();
|
|
2609
|
+
removers = [];
|
|
2610
|
+
for (const fn of dndCleanups) fn();
|
|
2611
|
+
dndCleanups = [];
|
|
2612
|
+
offMove?.();
|
|
2613
|
+
offMove = null;
|
|
2614
|
+
panelEmbeds.release(panelInner);
|
|
2615
|
+
root = null;
|
|
2616
|
+
};
|
|
2600
2617
|
},
|
|
2601
|
-
|
|
2602
|
-
|
|
2618
|
+
render(rootEl) {
|
|
2619
|
+
root = rootEl;
|
|
2620
|
+
sync(!mounted);
|
|
2621
|
+
mounted = true;
|
|
2603
2622
|
paint();
|
|
2604
2623
|
},
|
|
2605
|
-
onUnmount(): void {
|
|
2606
|
-
for (const fn of removers) fn();
|
|
2607
|
-
removers = [];
|
|
2608
|
-
for (const fn of dndCleanups) fn();
|
|
2609
|
-
dndCleanups = [];
|
|
2610
|
-
offMove?.();
|
|
2611
|
-
offMove = null;
|
|
2612
|
-
adoptOff?.();
|
|
2613
|
-
adoptOff = null;
|
|
2614
|
-
adoptFrom = '';
|
|
2615
|
-
adoptSug = [];
|
|
2616
|
-
panelEmbeds.release(panelInner);
|
|
2617
|
-
root = null;
|
|
2618
|
-
},
|
|
2619
2624
|
};
|
|
2620
|
-
},
|
|
2625
|
+
}),
|
|
2621
2626
|
};
|
|
2622
2627
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// 流程画布节点候选项的纯函数(无 DOM;表单与画布共用,不拉画布分片)。
|
|
2
|
+
// 展示对象把「各节点字段的候选项」写成一个对象成员,页面用纯路径 `nodeOptions: view.<成员>` 绑到画布字段;
|
|
3
|
+
// 成员形如 { "<节点类型>.<字段键>": [{ value, label, meta? }] }。画布把它并进 nodeTypes 里对应 select 字段的 options,
|
|
4
|
+
// 键不在表里的字段保持自己的静态 / 远程候选;表里给了键(哪怕是空数组)就以它为准。
|
|
5
|
+
// 另提供展示对象经控制器 handle 要用的两个操作:读节点、清空某类型节点的某个 meta 字段。
|
|
6
|
+
// 数字读 kit-limits#formLinkage.flowOptions.rowsMax,不手抄。
|
|
7
|
+
|
|
8
|
+
import { KIT_FORM_LINKAGE_LIMITS } from 'soma-foundation/kit-limits';
|
|
9
|
+
|
|
10
|
+
type Rec = Record<string, unknown>;
|
|
11
|
+
type Json = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
const ROWS_MAX = ((KIT_FORM_LINKAGE_LIMITS as unknown as Json).flowOptions as { rowsMax: number }).rowsMax;
|
|
14
|
+
|
|
15
|
+
const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
16
|
+
|
|
17
|
+
/** nodeOptions 对象成员的键:节点类型与字段键用点连接 */
|
|
18
|
+
export function flowNodeOptionKey(type: string, key: string): string {
|
|
19
|
+
return `${type}.${key}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 一条候选行规整成 { value, label, meta? };value 为空丢弃 */
|
|
23
|
+
function optionRows(raw: unknown): Rec[] {
|
|
24
|
+
if (!Array.isArray(raw)) return [];
|
|
25
|
+
const out: Rec[] = [];
|
|
26
|
+
for (const item of raw) {
|
|
27
|
+
if (out.length >= ROWS_MAX) break;
|
|
28
|
+
if (!isRec(item)) continue;
|
|
29
|
+
const value = typeof item.value === 'string' ? item.value : typeof item.value === 'number' ? String(item.value) : '';
|
|
30
|
+
if (value === '') continue;
|
|
31
|
+
out.push({
|
|
32
|
+
value,
|
|
33
|
+
label: typeof item.label === 'string' && item.label !== '' ? item.label : value,
|
|
34
|
+
...(isRec(item.meta) ? { meta: item.meta } : {}),
|
|
35
|
+
// mapping 字段的映射目标:分组(对应 targets_by 字段的值)与提示文字
|
|
36
|
+
...(typeof item.group === 'string' ? { group: item.group } : {}),
|
|
37
|
+
...(typeof item.hint === 'string' && item.hint !== '' ? { hint: item.hint } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 候选行(已规整)-> mapping 字段的映射目标 { key, label, hint? } */
|
|
44
|
+
function mapTargetOf(row: Rec): Rec {
|
|
45
|
+
return { key: row.value, label: row.label, ...(typeof row.hint === 'string' ? { hint: row.hint } : {}) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 把 columnOptions 并进子表字段(RowEditor)的 columns(数组):返回新数组,不改入参。
|
|
50
|
+
* columnOptions 形如 { "<列键>": [{ value, label }] },只作用于 kind 为 select 的列;
|
|
51
|
+
* 表里给了键(哪怕是空数组)就以它为准(替换该列的静态 / 远程候选),键不在表里的列保持自己的候选。
|
|
52
|
+
*/
|
|
53
|
+
export function withColumnOptions(columns: unknown, columnOptions: unknown): unknown {
|
|
54
|
+
if (!Array.isArray(columns) || !isRec(columnOptions) || Object.keys(columnOptions).length === 0) return columns;
|
|
55
|
+
return columns.map((c) => {
|
|
56
|
+
if (!isRec(c) || c.kind !== 'select' || typeof c.key !== 'string' || !Object.prototype.hasOwnProperty.call(columnOptions, c.key)) return c;
|
|
57
|
+
return { ...c, options: optionRows(columnOptions[c.key]).map((o) => ({ value: o.value, label: o.label })) };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 把 nodeOptions 并进 nodeTypes(原始配置,数组或对象两种写法都认):返回新对象,不改入参。
|
|
63
|
+
* 作用于 kind 为 select(候选项)与 mapping(映射目标候选,可按 group 分组)的字段;没给 nodeOptions(或不是对象)原样返回。
|
|
64
|
+
*/
|
|
65
|
+
export function withNodeOptions(nodeTypes: unknown, nodeOptions: unknown): unknown {
|
|
66
|
+
if (!isRec(nodeOptions) || Object.keys(nodeOptions).length === 0) return nodeTypes;
|
|
67
|
+
const patch = (type: string, def: unknown): unknown => {
|
|
68
|
+
if (!isRec(def) || !Array.isArray(def.fields)) return def;
|
|
69
|
+
const fields = def.fields.map((f) => {
|
|
70
|
+
if (!isRec(f) || (f.kind !== 'select' && f.kind !== 'mapping') || typeof f.key !== 'string') return f;
|
|
71
|
+
const k = flowNodeOptionKey(type, f.key);
|
|
72
|
+
if (!Object.prototype.hasOwnProperty.call(nodeOptions, k)) return f;
|
|
73
|
+
const rows = optionRows(nodeOptions[k]);
|
|
74
|
+
if (f.kind === 'select') return { ...f, options: rows };
|
|
75
|
+
// mapping:候选行换成映射目标;字段写了 targets_by 时按候选的 group 分组(节点取自己依赖别名那一组)
|
|
76
|
+
if (typeof f.targets_by === 'string' && f.targets_by !== '') {
|
|
77
|
+
const grouped: Record<string, Rec[]> = {};
|
|
78
|
+
for (const r of rows) (grouped[typeof r.group === 'string' ? r.group : ''] ??= []).push(mapTargetOf(r));
|
|
79
|
+
return { ...f, targets: [], targets_map: grouped };
|
|
80
|
+
}
|
|
81
|
+
return { ...f, targets: rows.map(mapTargetOf) };
|
|
82
|
+
});
|
|
83
|
+
return { ...def, fields };
|
|
84
|
+
};
|
|
85
|
+
if (Array.isArray(nodeTypes)) return nodeTypes.map((d) => patch(isRec(d) && typeof d.type === 'string' ? d.type : '', d));
|
|
86
|
+
if (!isRec(nodeTypes)) return nodeTypes;
|
|
87
|
+
const out: Rec = {};
|
|
88
|
+
for (const [type, def] of Object.entries(nodeTypes)) out[type] = patch(type, def);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 画布字段的值 { nodes, edges, mappings? } 里的节点(浅拷贝,调用方改不到草稿) */
|
|
93
|
+
export function flowValueNodes(value: unknown): Rec[] {
|
|
94
|
+
return isRec(value) && Array.isArray(value.nodes) ? value.nodes.filter(isRec).map((n) => ({ ...n })) : [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 清空某类型节点的某个 meta 字段(连带该字段声明的 resets 键):返回新的画布值与被清的节点数,不改入参。
|
|
99
|
+
* nodeTypes 用来找字段的 resets 声明(可缺省:只清这一个键)。没有节点带该键时返回原值。
|
|
100
|
+
* 字段声明了 as_label(选中的值同步成节点标题)时,清空后节点标题重置为该节点类型的默认名(类型的 label,缺省用类型名)。
|
|
101
|
+
*/
|
|
102
|
+
export function clearFlowNodeField(value: unknown, nodeTypes: unknown, type: string, key: string): { value: unknown; cleared: number } {
|
|
103
|
+
if (!isRec(value) || !Array.isArray(value.nodes)) return { value, cleared: 0 };
|
|
104
|
+
const defs: unknown = Array.isArray(nodeTypes)
|
|
105
|
+
? nodeTypes.find((d) => isRec(d) && d.type === type)
|
|
106
|
+
: isRec(nodeTypes) ? nodeTypes[type] : undefined;
|
|
107
|
+
const decl = isRec(defs) && Array.isArray(defs.fields) ? defs.fields.find((f) => isRec(f) && f.key === key) : undefined;
|
|
108
|
+
const drop = [key, ...(isRec(decl) && Array.isArray(decl.resets) ? decl.resets.filter((k): k is string => typeof k === 'string') : [])];
|
|
109
|
+
const defaultName = isRec(defs) && typeof defs.label === 'string' && defs.label !== '' ? defs.label : type;
|
|
110
|
+
const resetsLabel = isRec(decl) && decl.as_label === true;
|
|
111
|
+
let cleared = 0;
|
|
112
|
+
const nodes = value.nodes.map((n) => {
|
|
113
|
+
if (!isRec(n) || n.type !== type || !isRec(n.meta) || !(key in n.meta)) return n;
|
|
114
|
+
const meta: Rec = { ...n.meta };
|
|
115
|
+
for (const k of drop) delete meta[k];
|
|
116
|
+
cleared += 1;
|
|
117
|
+
return { ...n, ...(resetsLabel ? { label: defaultName } : {}), meta };
|
|
118
|
+
});
|
|
119
|
+
return cleared === 0 ? { value, cleared: 0 } : { value: { ...value, nodes }, cleared };
|
|
120
|
+
}
|