@antelopejs/dms-automation 0.7.0 → 0.9.0
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 +33 -22
- package/dist/cluster/bus.js +8 -6
- package/dist/cluster/bus.js.map +1 -1
- package/dist/cluster/leader.js.map +1 -1
- package/dist/data/procedures-query.d.ts +19 -0
- package/dist/data/procedures-query.js +105 -0
- package/dist/data/procedures-query.js.map +1 -0
- package/dist/data/procedures-table.d.ts +5 -20
- package/dist/data/procedures-table.js +10 -106
- package/dist/data/procedures-table.js.map +1 -1
- package/dist/data/runs-table.d.ts +3 -3
- package/dist/data/runs-table.js.map +1 -1
- package/dist/db/models/automation_template.model.d.ts +13 -13
- package/dist/db/models/automation_template.model.js +13 -14
- package/dist/db/models/automation_template.model.js.map +1 -1
- package/dist/db/models/procedure.model.d.ts +7 -5
- package/dist/db/models/procedure_run.model.d.ts +9 -6
- package/dist/db/models/procedure_run.model.js +8 -8
- package/dist/db/models/procedure_run.model.js.map +1 -1
- package/dist/db/models/stats.model.js.map +1 -1
- package/dist/db/models/type_switch.model.d.ts +7 -5
- package/dist/db/tables/procedure_run.table.d.ts +2 -1
- package/dist/db/tables/procedure_run.table.js.map +1 -1
- package/dist/implementations/dms-automation/index.d.ts +2 -2
- package/dist/implementations/dms-automation/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/category.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/procedures.js.map +1 -1
- package/dist/pages/runs.js.map +1 -1
- package/dist/pages/shared.js +1 -1
- package/dist/pages/shared.js.map +1 -1
- package/dist/realtime.d.ts +2 -1
- package/dist/realtime.js.map +1 -1
- package/dist/routes/action-types.d.ts +3 -2
- package/dist/routes/action-types.js.map +1 -1
- package/dist/routes/data-node-types.d.ts +1 -1
- package/dist/routes/deleteConfirm.js +4 -3
- package/dist/routes/deleteConfirm.js.map +1 -1
- package/dist/routes/graphSchema.d.ts +2 -1
- package/dist/routes/graphSchema.js +13 -10
- package/dist/routes/graphSchema.js.map +1 -1
- package/dist/routes/library.d.ts +12 -1
- package/dist/routes/library.js +38 -34
- package/dist/routes/library.js.map +1 -1
- package/dist/routes/procedureChecks.js +5 -5
- package/dist/routes/procedureChecks.js.map +1 -1
- package/dist/routes/procedureRuns.d.ts +3 -3
- package/dist/routes/procedureRuns.js +1 -1
- package/dist/routes/procedureRuns.js.map +1 -1
- package/dist/routes/procedureSchemas.d.ts +7 -6
- package/dist/routes/procedureSchemas.js +4 -2
- package/dist/routes/procedureSchemas.js.map +1 -1
- package/dist/routes/procedures.d.ts +15 -14
- package/dist/routes/procedures.js +2 -1
- package/dist/routes/procedures.js.map +1 -1
- package/dist/routes/requests.d.ts +12 -6
- package/dist/routes/requests.js +2 -1
- package/dist/routes/requests.js.map +1 -1
- package/dist/routes/runs.d.ts +9 -8
- package/dist/routes/runs.js +5 -3
- package/dist/routes/runs.js.map +1 -1
- package/dist/routes/stats.js.map +1 -1
- package/dist/routes/templates.d.ts +5 -4
- package/dist/routes/templates.js +2 -1
- package/dist/routes/templates.js.map +1 -1
- package/dist/routes/trigger-types.d.ts +3 -2
- package/dist/routes/trigger-types.js.map +1 -1
- package/dist/routes/typeConfigShared.d.ts +2 -1
- package/dist/routes/typeConfigShared.js.map +1 -1
- package/dist/routes/zodJson.d.ts +3 -0
- package/dist/routes/zodJson.js +21 -0
- package/dist/routes/zodJson.js.map +1 -0
- package/dist/runtime/armErrors.d.ts +0 -1
- package/dist/runtime/armErrors.js +5 -12
- package/dist/runtime/armErrors.js.map +1 -1
- package/dist/runtime/boundRunLog.d.ts +7 -5
- package/dist/runtime/boundRunLog.js +24 -20
- package/dist/runtime/boundRunLog.js.map +1 -1
- package/dist/runtime/builtins/actions/http.d.ts +7 -3
- package/dist/runtime/builtins/actions/http.js +33 -22
- package/dist/runtime/builtins/actions/http.js.map +1 -1
- package/dist/runtime/builtins/actions/log.d.ts +5 -4
- package/dist/runtime/builtins/actions/log.js.map +1 -1
- package/dist/runtime/builtins/data/boolean.d.ts +2 -1
- package/dist/runtime/builtins/data/boolean.js +4 -5
- package/dist/runtime/builtins/data/boolean.js.map +1 -1
- package/dist/runtime/builtins/data/compare.js +8 -10
- package/dist/runtime/builtins/data/compare.js.map +1 -1
- package/dist/runtime/builtins/data/constant.js +1 -1
- package/dist/runtime/builtins/data/constant.js.map +1 -1
- package/dist/runtime/builtins/data/json.js +4 -5
- package/dist/runtime/builtins/data/json.js.map +1 -1
- package/dist/runtime/builtins/data/math.js +4 -4
- package/dist/runtime/builtins/data/math.js.map +1 -1
- package/dist/runtime/builtins/data/object.js +27 -27
- package/dist/runtime/builtins/data/object.js.map +1 -1
- package/dist/runtime/builtins/data/string.js +13 -18
- package/dist/runtime/builtins/data/string.js.map +1 -1
- package/dist/runtime/builtins/nodes/action.js +16 -5
- package/dist/runtime/builtins/nodes/action.js.map +1 -1
- package/dist/runtime/builtins/nodes/data.js +2 -2
- package/dist/runtime/builtins/nodes/data.js.map +1 -1
- package/dist/runtime/builtins/nodes/delay.js +2 -2
- package/dist/runtime/builtins/nodes/delay.js.map +1 -1
- package/dist/runtime/builtins/nodes/forRange.js +2 -2
- package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
- package/dist/runtime/builtins/nodes/foreach.js +2 -2
- package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupInput.js +2 -2
- package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
- package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
- package/dist/runtime/builtins/nodes/if.js +2 -2
- package/dist/runtime/builtins/nodes/if.js.map +1 -1
- package/dist/runtime/builtins/nodes/parallel.js +2 -2
- package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
- package/dist/runtime/builtins/nodes/retry.js +13 -5
- package/dist/runtime/builtins/nodes/retry.js.map +1 -1
- package/dist/runtime/builtins/nodes/setVariable.js +2 -2
- package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
- package/dist/runtime/builtins/nodes/switch.js +8 -3
- package/dist/runtime/builtins/nodes/switch.js.map +1 -1
- package/dist/runtime/builtins/nodes/trigger.js +2 -2
- package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
- package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
- package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
- package/dist/runtime/builtins/triggers/cron.d.ts +4 -3
- package/dist/runtime/builtins/triggers/cron.js +5 -7
- package/dist/runtime/builtins/triggers/cron.js.map +1 -1
- package/dist/runtime/builtins/triggers/webhook.d.ts +11 -7
- package/dist/runtime/builtins/triggers/webhook.js +15 -12
- package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
- package/dist/runtime/declaredProcedures.d.ts +2 -2
- package/dist/runtime/declaredProcedures.js +3 -2
- package/dist/runtime/declaredProcedures.js.map +1 -1
- package/dist/runtime/describe.d.ts +3 -1
- package/dist/runtime/describe.js +14 -13
- package/dist/runtime/describe.js.map +1 -1
- package/dist/runtime/executor.d.ts +2 -1
- package/dist/runtime/executor.js +18 -13
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/flatten.d.ts +1 -1
- package/dist/runtime/flatten.js +1 -1
- package/dist/runtime/flatten.js.map +1 -1
- package/dist/runtime/graphIssues.d.ts +2 -2
- package/dist/runtime/graphIssues.js +39 -32
- package/dist/runtime/graphIssues.js.map +1 -1
- package/dist/runtime/graphVersion.d.ts +1 -1
- package/dist/runtime/graphVersion.js +4 -3
- package/dist/runtime/graphVersion.js.map +1 -1
- package/dist/runtime/nodeKinds.d.ts +6 -5
- package/dist/runtime/nodeKinds.js.map +1 -1
- package/dist/runtime/reconcile.d.ts +3 -0
- package/dist/runtime/reconcile.js +178 -0
- package/dist/runtime/reconcile.js.map +1 -0
- package/dist/runtime/registry.d.ts +3 -3
- package/dist/runtime/resolveInputs.d.ts +13 -8
- package/dist/runtime/resolveInputs.js +18 -18
- package/dist/runtime/resolveInputs.js.map +1 -1
- package/dist/runtime/resolveSubgraph.js +4 -5
- package/dist/runtime/resolveSubgraph.js.map +1 -1
- package/dist/runtime/retention.js.map +1 -1
- package/dist/runtime/runProcedure.d.ts +3 -2
- package/dist/runtime/runProcedure.js +2 -1
- package/dist/runtime/runProcedure.js.map +1 -1
- package/dist/runtime/schedule.js +3 -0
- package/dist/runtime/schedule.js.map +1 -1
- package/dist/runtime/schemaProperties.d.ts +3 -0
- package/dist/runtime/schemaProperties.js +7 -0
- package/dist/runtime/schemaProperties.js.map +1 -0
- package/dist/runtime/serialQueue.d.ts +1 -1
- package/dist/runtime/serialQueue.js +4 -4
- package/dist/runtime/serialQueue.js.map +1 -1
- package/dist/runtime/sideEffects.d.ts +2 -2
- package/dist/runtime/subscriptions.d.ts +6 -4
- package/dist/runtime/subscriptions.js +21 -180
- package/dist/runtime/subscriptions.js.map +1 -1
- package/dist/runtime/subwalk.js.map +1 -1
- package/dist/runtime/templateCacheState.d.ts +6 -0
- package/dist/runtime/templateCacheState.js +10 -0
- package/dist/runtime/templateCacheState.js.map +1 -0
- package/dist/runtime/templateUsages.js +4 -5
- package/dist/runtime/templateUsages.js.map +1 -1
- package/dist/runtime/topo.js +2 -4
- package/dist/runtime/topo.js.map +1 -1
- package/dist/runtime/trace.d.ts +5 -2
- package/dist/runtime/trace.js +27 -17
- package/dist/runtime/trace.js.map +1 -1
- package/dist/runtime/triggerHandles.d.ts +4 -3
- package/dist/runtime/triggerHandles.js +9 -1
- package/dist/runtime/triggerHandles.js.map +1 -1
- package/dist/runtime/typeOrigin.js +12 -1
- package/dist/runtime/typeOrigin.js.map +1 -1
- package/dist/runtime/validate.js.map +1 -1
- package/dist/runtime/validateTemplate.js.map +1 -1
- package/dist/runtime/withTimeout.js.map +1 -1
- package/dist/runtime/wording.js +12 -8
- package/dist/runtime/wording.js.map +1 -1
- package/dist/stats/health-banner.js.map +1 -1
- package/dist/stats/health.js.map +1 -1
- package/dist/stats/kpi.js +1 -1
- package/dist/stats/kpi.js.map +1 -1
- package/dist/stats/overview.js +2 -1
- package/dist/stats/overview.js.map +1 -1
- package/dist/types/dataValue.d.ts +7 -0
- package/dist/types/dataValue.js +56 -0
- package/dist/types/dataValue.js.map +1 -0
- package/dist/types/graph.d.ts +19 -13
- package/dist/types/graph.js +8 -0
- package/dist/types/graph.js.map +1 -1
- package/dist/types/guards.d.ts +8 -0
- package/dist/types/guards.js +35 -0
- package/dist/types/guards.js.map +1 -0
- package/dist/types/runLog.d.ts +8 -7
- package/dist/types/runLog.js.map +1 -1
- package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
- package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
- package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
- package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
- package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
- package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
- package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
- package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
- package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
- package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
- package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
- package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
- package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
- package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
- package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
- package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
- package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
- package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
- package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
- package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
- package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
- package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
- package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
- package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
- package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
- package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
- package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
- package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
- package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
- package/frontend-vue/app/build/types/editor.ts +94 -0
- package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
- package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
- package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
- package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
- package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
- package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
- package/frontend-vue/app/build/utils/templates.ts +88 -0
- package/frontend-vue/app/components/AttentionList.vue +2 -6
- package/frontend-vue/app/components/Catalog.vue +2 -1
- package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
- package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
- package/frontend-vue/app/components/Editor.vue +134 -3484
- package/frontend-vue/app/components/Templates.vue +14 -84
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint-rules/index.mjs +103 -0
- package/frontend-vue/eslint.config.mjs +15 -0
- package/frontend-vue/package.json +8 -5
- package/frontend-vue/pnpm-lock.yaml +168 -139
- package/frontend-vue/tests/api-error-presentation.test.cjs +254 -0
- package/frontend-vue/tests/helpers/setup.cjs +44 -0
- package/package.json +18 -15
- package/skills/dms-automation/SKILL.md +2 -2
- package/skills/dms-automation/cases.json +58 -0
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import { newId } from '../../utils/automation'
|
|
4
|
-
import { roleOf, summarizeNode, type WordedTrigger } from '../../utils/describe'
|
|
5
|
-
import type { NodeRunState } from './nodes/GenericNode.vue'
|
|
2
|
+
import { markRaw, ref } from 'vue'
|
|
6
3
|
// The canvas chrome (dotted DMS background, zoom controls, themed
|
|
7
4
|
// node/handle/edge styling, pan/zoom + fit-view) now comes from the shared
|
|
8
5
|
// DmsFlowCanvas wrapper (dms ≥0.0.25). We only keep the @vue-flow/core bits
|
|
@@ -10,13 +7,6 @@ import type { NodeRunState } from './nodes/GenericNode.vue'
|
|
|
10
7
|
// the connection / change / edge types for our wiring handlers. The imperative
|
|
11
8
|
// flow controller (zoom/fit/updateNodeInternals/viewport) is reached through
|
|
12
9
|
// DmsFlowCanvas's exposed store via a template ref (see `flowRef`).
|
|
13
|
-
import { Position } from '@vue-flow/core'
|
|
14
|
-
import type {
|
|
15
|
-
Connection,
|
|
16
|
-
NodeChange,
|
|
17
|
-
EdgeChange,
|
|
18
|
-
Edge as VfEdge,
|
|
19
|
-
} from '@vue-flow/core'
|
|
20
10
|
// Most node kinds share a single port-spec-driven renderer. Group and the
|
|
21
11
|
// two group sentinels stay custom because they have cross-graph port
|
|
22
12
|
// declarations and special handle naming.
|
|
@@ -24,128 +14,32 @@ import GenericNode from './nodes/GenericNode.vue'
|
|
|
24
14
|
import GroupNode from './nodes/GroupNode.vue'
|
|
25
15
|
import GroupInputNode from './nodes/GroupInputNode.vue'
|
|
26
16
|
import GroupOutputNode from './nodes/GroupOutputNode.vue'
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} from '../../composables/
|
|
17
|
+
import { useCanvasEdges } from '../../build/composables/graphCanvas/edges'
|
|
18
|
+
import { connectionCheck, useConnections } from '../../build/composables/graphCanvas/connect'
|
|
19
|
+
import { useEdgeEvents } from '../../build/composables/graphCanvas/edgeEvents'
|
|
20
|
+
import { useLinkMenu } from '../../build/composables/graphCanvas/linkMenu'
|
|
21
|
+
import { useCanvasNodes } from '../../build/composables/graphCanvas/nodeData'
|
|
22
|
+
import { useNodePlacement } from '../../build/composables/graphCanvas/placement'
|
|
23
|
+
import { useCanvasSelection } from '../../build/composables/graphCanvas/selection'
|
|
24
|
+
import { MAX_ZOOM, MIN_ZOOM } from '../../build/composables/graphCanvas/types'
|
|
35
25
|
import type {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
DataNodeType,
|
|
44
|
-
JsonSchema,
|
|
45
|
-
GroupPort,
|
|
46
|
-
ConnectResult,
|
|
47
|
-
} from '../../composables/useGraphConnect'
|
|
48
|
-
import {
|
|
49
|
-
PALETTE_DRAG_TYPE,
|
|
50
|
-
type NodeKindEntry,
|
|
51
|
-
type NodeKindUI,
|
|
52
|
-
type PaletteBlock,
|
|
53
|
-
type TemplateSummary,
|
|
54
|
-
} from '../../composables/useAutomationNodeKinds'
|
|
55
|
-
|
|
56
|
-
// A template's `ports` are deep-cloned (JSON round-trip) onto each new
|
|
57
|
-
// template-instance group node so future template edits don't retroactively
|
|
58
|
-
// mutate the instance's port list (the resolved subgraph still updates live —
|
|
59
|
-
// that's the live-link model).
|
|
60
|
-
const props = defineProps<{
|
|
61
|
-
graph: ProcedureGraph
|
|
62
|
-
triggerTypes: TriggerType[]
|
|
63
|
-
actionTypes: ActionType[]
|
|
64
|
-
dataNodeTypes: DataNodeType[]
|
|
65
|
-
/**
|
|
66
|
-
* Per-NodeKind metadata served by `/api/automation/node-kinds`. The
|
|
67
|
-
* `ui` block on each entry tells `dataFor` how to render the node —
|
|
68
|
-
* label, icon, port lists, type-registry / dynamic-config hooks. The
|
|
69
|
-
* frontend has zero kind-specific code beyond group + sentinels.
|
|
70
|
-
*/
|
|
71
|
-
nodeKinds: NodeKindEntry[]
|
|
72
|
-
canUndo?: boolean
|
|
73
|
-
canRedo?: boolean
|
|
74
|
-
// When the canvas is showing a group's inner subgraph, these are the
|
|
75
|
-
// parent group's declared ports — the sentinel nodes (groupInput /
|
|
76
|
-
// groupOutput) render handles derived from this list rather than
|
|
77
|
-
// reading from their own node data. (Sentinel nodes themselves don't
|
|
78
|
-
// carry ports; their parent group does.) Undefined at the procedure
|
|
79
|
-
// root.
|
|
80
|
-
parentGroupPorts?: GroupPort[]
|
|
81
|
-
// When true, the canvas suppresses graph mutations from user input —
|
|
82
|
-
// used for the read-only view of template-instance inner subgraphs.
|
|
83
|
-
// User can still pan / zoom / select / inspect, just not connect,
|
|
84
|
-
// move, delete, or edit. The "Apply / Cancel" buttons are hidden too.
|
|
85
|
-
readOnly?: boolean
|
|
86
|
-
/** Outcome of each node in the run shown over the canvas (a test run, a debugged run). */
|
|
87
|
-
runStates?: Record<string, NodeRunState>
|
|
88
|
-
/** The problem of each node the validator named. */
|
|
89
|
-
issues?: Record<string, NodeIssue>
|
|
90
|
-
/**
|
|
91
|
-
* The node the editor has selected (inspector, dock "Select node", a
|
|
92
|
-
* `?node=` link): the canvas selects it too and brings it into view.
|
|
93
|
-
*/
|
|
94
|
-
selectedNodeId?: string | null
|
|
95
|
-
/**
|
|
96
|
-
* Names the graph shown (the procedure, the group entered): a new key
|
|
97
|
-
* fits the new graph into view.
|
|
98
|
-
*/
|
|
99
|
-
viewKey?: string
|
|
100
|
-
/**
|
|
101
|
-
* An element drawn over the canvas's right edge (the inspector on narrow
|
|
102
|
-
* screens): fitting and centring keep the nodes out from under it.
|
|
103
|
-
*/
|
|
104
|
-
coveredBy?: HTMLElement | null
|
|
105
|
-
/** The draft's triggers, worded by the server: a schedule reads in words. */
|
|
106
|
-
triggers?: WordedTrigger[]
|
|
107
|
-
}>()
|
|
26
|
+
CanvasEmits,
|
|
27
|
+
CanvasProps,
|
|
28
|
+
FlowController,
|
|
29
|
+
Reveal,
|
|
30
|
+
} from '../../build/composables/graphCanvas/types'
|
|
31
|
+
import { useCanvasView } from '../../build/composables/graphCanvas/view'
|
|
32
|
+
import type { ProcedureGraph } from '../../composables/useGraphConnect'
|
|
108
33
|
|
|
109
|
-
|
|
110
|
-
severity: 'error' | 'warning'
|
|
111
|
-
message: string
|
|
112
|
-
/** Problem code, translated as `dms_automation.editor.problems.codes.<code>`. */
|
|
113
|
-
code?: string
|
|
114
|
-
params?: Record<string, unknown>
|
|
115
|
-
}
|
|
34
|
+
const props = defineProps<CanvasProps>()
|
|
116
35
|
|
|
117
|
-
const emit = defineEmits<
|
|
118
|
-
(e: 'update:graph', g: ProcedureGraph): void
|
|
119
|
-
(e: 'select:node', id: string | null): void
|
|
120
|
-
// Fires whenever the selection set changes (single or multi). `ids` is
|
|
121
|
-
// the full set of currently selected node ids in this canvas — used by
|
|
122
|
-
// Editor.vue to drive the "Group selection" toolbar action. Sentinel
|
|
123
|
-
// nodes (groupInput / groupOutput) are filtered out before emitting.
|
|
124
|
-
(e: 'selection-change', payload: { ids: string[] }): void
|
|
125
|
-
(e: 'undo'): void
|
|
126
|
-
(e: 'redo'): void
|
|
127
|
-
// Bubbles up GroupNode's @dblclick — Editor.vue uses this to push the
|
|
128
|
-
// group onto the subgraph navigation path. Filtered by kind here so
|
|
129
|
-
// the parent doesn't need to look the node up itself.
|
|
130
|
-
(e: 'group:enter', payload: { id: string }): void
|
|
131
|
-
}>()
|
|
36
|
+
const emit = defineEmits<CanvasEmits>()
|
|
132
37
|
|
|
133
38
|
const toast = useToast()
|
|
134
39
|
const { processI18n } = useTranslation()
|
|
135
40
|
const { processText } = useComposedText()
|
|
136
41
|
const { t, te } = useI18n()
|
|
137
42
|
|
|
138
|
-
// Fit view never zooms past 100% (a lone trigger would fill the canvas) and
|
|
139
|
-
// may go down to 10% so a large graph fits whole.
|
|
140
|
-
const FIT_PADDING = 0.15
|
|
141
|
-
const FIT_MAX_ZOOM = 1
|
|
142
|
-
const MIN_ZOOM = 0.1
|
|
143
|
-
const MAX_ZOOM = 1.5
|
|
144
|
-
// Room left around a new node, and the size assumed for a node not drawn
|
|
145
|
-
// yet (GenericNode's width, a typical height).
|
|
146
|
-
const NODE_GAP = 60
|
|
147
|
-
const NEW_NODE_SIZE = { width: 230, height: 90 }
|
|
148
|
-
|
|
149
43
|
const nodeTypes = markRaw({
|
|
150
44
|
genericNode: GenericNode,
|
|
151
45
|
group: GroupNode,
|
|
@@ -153,1240 +47,87 @@ const nodeTypes = markRaw({
|
|
|
153
47
|
groupOutput: GroupOutputNode,
|
|
154
48
|
})
|
|
155
49
|
|
|
156
|
-
// Sentinel node kinds — only valid inside a group's subgraph and never
|
|
157
|
-
// user-deletable. We filter them out of keyboard/right-click delete in
|
|
158
|
-
// onNodesChange below.
|
|
159
|
-
const SENTINEL_KINDS: ReadonlySet<NodeKind> = new Set<NodeKind>([
|
|
160
|
-
'groupInput',
|
|
161
|
-
'groupOutput',
|
|
162
|
-
])
|
|
163
|
-
|
|
164
|
-
function vfTypeFor(kind: NodeKind): string {
|
|
165
|
-
if (kind === 'group') return 'group'
|
|
166
|
-
if (kind === 'groupInput') return 'groupInput'
|
|
167
|
-
if (kind === 'groupOutput') return 'groupOutput'
|
|
168
|
-
return 'genericNode'
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function propsOf(schema: JsonSchema | undefined) {
|
|
172
|
-
if (!schema?.properties) return []
|
|
173
|
-
return Object.entries(schema.properties).map(([name, p]) => ({
|
|
174
|
-
name,
|
|
175
|
-
type: Array.isArray(p?.type) ? p?.type[0] : p?.type,
|
|
176
|
-
title: p?.title,
|
|
177
|
-
}))
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Index node-kind metadata by kind for O(1) lookup.
|
|
181
|
-
const nodeKindUiByKind = computed<Map<string, NodeKindUI>>(() => {
|
|
182
|
-
const m = new Map<string, NodeKindUI>()
|
|
183
|
-
for (const entry of props.nodeKinds ?? []) {
|
|
184
|
-
if (entry.meta?.ui) m.set(entry.kind, entry.meta.ui)
|
|
185
|
-
}
|
|
186
|
-
return m
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
// Pull a registered TriggerType / ActionType / DataNodeType from the
|
|
190
|
-
// type-registry prop indicated by a NodeKindUI.typeRegistry hint.
|
|
191
|
-
function lookupTypeBySpec(spec: NodeKindUI, typeId: string | undefined) {
|
|
192
|
-
if (!spec.typeRegistry || !typeId) return null
|
|
193
|
-
if (spec.typeRegistry === 'triggers')
|
|
194
|
-
return props.triggerTypes.find((t) => t.id === typeId) ?? null
|
|
195
|
-
if (spec.typeRegistry === 'actions')
|
|
196
|
-
return props.actionTypes.find((a) => a.id === typeId) ?? null
|
|
197
|
-
if (spec.typeRegistry === 'dataNodes')
|
|
198
|
-
return props.dataNodeTypes.find((d) => d.id === typeId) ?? null
|
|
199
|
-
return null
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// A schedule in words, once the server has worded its current expression.
|
|
203
|
-
function scheduleTextOf(node: AppGraphNode): string | undefined {
|
|
204
|
-
const cron = node.config?.cron
|
|
205
|
-
const worded = props.triggers?.find((tr) => tr.nodeId === node.id && tr.cron === cron)
|
|
206
|
-
return worded ? processText(worded.text) : undefined
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// The validator's problem on a node, in the reader's language (its English
|
|
210
|
-
// message when this version has no text for the code).
|
|
211
|
-
function issueOf(id: string): NodeIssue | null {
|
|
212
|
-
const issue = props.issues?.[id]
|
|
213
|
-
if (!issue) return null
|
|
214
|
-
const key = `dms_automation.editor.problems.codes.${issue.code}`
|
|
215
|
-
return issue.code && te(key) ? { ...issue, message: t(key, issue.params ?? {}) } : issue
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Build the GenericNode `data` payload from a graph node. For every kind
|
|
219
|
-
// with `ui` metadata (every kind except group + sentinels), one
|
|
220
|
-
// data-driven resolver applies: combine `spec` from the backend with the
|
|
221
|
-
// node's `typeId` (for type-registered kinds) and `config` (for dynamic
|
|
222
|
-
// trigger-out ports).
|
|
223
|
-
function dataFor(node: AppGraphNode) {
|
|
224
|
-
const spec = nodeKindUiByKind.value.get(node.kind)
|
|
225
|
-
if (spec) {
|
|
226
|
-
// Kind labels may be `$`-prefixed i18n keys too.
|
|
227
|
-
let label = processI18n(spec.label)
|
|
228
|
-
let icon = spec.icon
|
|
229
|
-
let category: string | undefined
|
|
230
|
-
let dataIns = [...spec.staticDataIns]
|
|
231
|
-
let dataOuts = [...spec.staticDataOuts]
|
|
232
|
-
|
|
233
|
-
const type = lookupTypeBySpec(spec, node.typeId) as
|
|
234
|
-
| {
|
|
235
|
-
name?: string
|
|
236
|
-
icon?: string
|
|
237
|
-
category?: string
|
|
238
|
-
inputSchema?: JsonSchema
|
|
239
|
-
outputSchema?: JsonSchema
|
|
240
|
-
configSchema?: JsonSchema
|
|
241
|
-
}
|
|
242
|
-
| null
|
|
243
|
-
if (type) {
|
|
244
|
-
// Type names may be `$`-prefixed DMS i18n keys; plain text passes through.
|
|
245
|
-
if (spec.labelFromType && type.name !== undefined)
|
|
246
|
-
label = processI18n(type.name)
|
|
247
|
-
if (spec.iconFromType) icon = type.icon ?? icon
|
|
248
|
-
if (spec.categoryFromType) category = type.category
|
|
249
|
-
if (spec.dataInsFromTypeSchema)
|
|
250
|
-
dataIns = propsOf(type[spec.dataInsFromTypeSchema])
|
|
251
|
-
if (spec.dataOutsFromTypeSchema)
|
|
252
|
-
dataOuts = propsOf(type[spec.dataOutsFromTypeSchema])
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const dynPorts = spec.dynamicTriggerOutsFromConfig
|
|
256
|
-
? ((node.config?.[spec.dynamicTriggerOutsFromConfig] as
|
|
257
|
-
| string[]
|
|
258
|
-
| undefined) ?? [])
|
|
259
|
-
: []
|
|
260
|
-
const triggerOuts = [...dynPorts, ...spec.staticTriggerOuts]
|
|
261
|
-
|
|
262
|
-
const own = (node as AppGraphNode & { label?: string }).label
|
|
263
|
-
const module = (type as { module?: string } | null)?.module
|
|
264
|
-
return {
|
|
265
|
-
label: own || label,
|
|
266
|
-
typeName: label,
|
|
267
|
-
role: roleOf(node.kind, spec.category),
|
|
268
|
-
module,
|
|
269
|
-
summary: summarizeNode(node.kind, node.typeId, node.config, processI18n, scheduleTextOf(node)),
|
|
270
|
-
run: props.runStates?.[node.id] ?? null,
|
|
271
|
-
issue: issueOf(node.id),
|
|
272
|
-
icon,
|
|
273
|
-
category,
|
|
274
|
-
typeId: node.typeId,
|
|
275
|
-
config: node.config,
|
|
276
|
-
hasTriggerIn: spec.hasTriggerIn,
|
|
277
|
-
hasMainTriggerOut: spec.hasMainTriggerOut,
|
|
278
|
-
triggerOuts,
|
|
279
|
-
dataIns,
|
|
280
|
-
dataOuts,
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (node.kind === 'group') {
|
|
285
|
-
// Group node carries its own port list + (optional) inline subgraph
|
|
286
|
-
// or templateId. The fields live on the node itself (per backend
|
|
287
|
-
// GroupNode interface) — surface them so the renderer can display
|
|
288
|
-
// handles, linked badges, etc.
|
|
289
|
-
const g = node as AppGraphNode & {
|
|
290
|
-
label?: string
|
|
291
|
-
ports?: unknown
|
|
292
|
-
templateId?: string
|
|
293
|
-
subgraph?: unknown
|
|
294
|
-
}
|
|
295
|
-
// Step name (`label`) first, as for any node; `config.name` is the name
|
|
296
|
-
// the group or its template was created with.
|
|
297
|
-
return {
|
|
298
|
-
label: g.label || (node.config?.name as string | undefined) || t('dms_automation.nodes.role.group'),
|
|
299
|
-
run: props.runStates?.[node.id] ?? null,
|
|
300
|
-
issue: issueOf(node.id),
|
|
301
|
-
ports: Array.isArray(g.ports) ? g.ports : [],
|
|
302
|
-
templateId: g.templateId,
|
|
303
|
-
subgraph: g.subgraph,
|
|
304
|
-
config: node.config,
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (node.kind === 'groupInput' || node.kind === 'groupOutput') {
|
|
308
|
-
// Sentinels render the parent group's ports. In subgraph-editor
|
|
309
|
-
// mode (C5.3) Editor.vue passes `parentGroupPorts` so both
|
|
310
|
-
// sentinels share one source of truth — the outer group node.
|
|
311
|
-
// At the procedure-graph root there's no parent group, so we
|
|
312
|
-
// fall back to whatever ports the sentinel carries (which
|
|
313
|
-
// should normally be none — a stray sentinel renders empty).
|
|
314
|
-
if (Array.isArray(props.parentGroupPorts)) {
|
|
315
|
-
return { ports: props.parentGroupPorts }
|
|
316
|
-
}
|
|
317
|
-
const s = node as AppGraphNode & { ports?: unknown }
|
|
318
|
-
return { ports: Array.isArray(s.ports) ? s.ports : [] }
|
|
319
|
-
}
|
|
320
|
-
return {}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// What a screen reader announces for a node: its type when the node has a
|
|
324
|
-
// name of its own, its name, and what it does.
|
|
325
|
-
function ariaLabelOf(data: { label?: string; typeName?: string; summary?: string }) {
|
|
326
|
-
if (!data.label) return undefined
|
|
327
|
-
const type = data.typeName && data.typeName !== data.label ? `${data.typeName}: ` : ''
|
|
328
|
-
return `${type}${data.label}${data.summary ? `, ${data.summary}` : ''}`
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const vfNodes = computed(() =>
|
|
332
|
-
props.graph.nodes.map((n) => {
|
|
333
|
-
const data = dataFor(n)
|
|
334
|
-
return {
|
|
335
|
-
id: n.id,
|
|
336
|
-
type: vfTypeFor(n.kind),
|
|
337
|
-
position: n.position,
|
|
338
|
-
data,
|
|
339
|
-
ariaLabel: SENTINEL_KINDS.has(n.kind)
|
|
340
|
-
? t(n.kind === 'groupInput' ? 'dms_automation.nodes.groupInput' : 'dms_automation.nodes.groupOutput')
|
|
341
|
-
: ariaLabelOf(data),
|
|
342
|
-
sourcePosition: Position.Bottom,
|
|
343
|
-
targetPosition: Position.Top,
|
|
344
|
-
}
|
|
345
|
-
}),
|
|
346
|
-
)
|
|
347
|
-
|
|
348
|
-
// How the canvas names a node in its messages: its label, else (a group's
|
|
349
|
-
// sentinels) the group role.
|
|
350
|
-
const nodeNames = computed(
|
|
351
|
-
() => new Map(vfNodes.value.map((n) => [n.id, (n.data as { label?: string }).label])),
|
|
352
|
-
)
|
|
353
|
-
function nodeName(id: string): string {
|
|
354
|
-
return nodeNames.value.get(id) || t('dms_automation.nodes.role.group')
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Look up the kind of an edge endpoint by node id — needed for the group
|
|
358
|
-
// handle-id derivation below. Sentinels and groups have richer handle
|
|
359
|
-
// naming than regular nodes (`group-trigger-in-<port>` vs `trigger-in`),
|
|
360
|
-
// so the edge mapping needs to know which target/source it's wiring to.
|
|
361
|
-
const nodeKindById = computed<Map<string, NodeKind>>(() => {
|
|
362
|
-
const m = new Map<string, NodeKind>()
|
|
363
|
-
for (const n of props.graph.nodes) m.set(n.id, n.kind)
|
|
364
|
-
return m
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
// Trigger edges into a group node or groupOutput sentinel target a specific
|
|
368
|
-
// trigger-in port — the port name lives on `e.to.branch`. Ordinary target
|
|
369
|
-
// nodes have a single fixed `trigger-in` handle.
|
|
370
|
-
function triggerTargetHandle(e: TriggerEdge, targetKind: NodeKind | undefined): string {
|
|
371
|
-
if (targetKind === 'group') {
|
|
372
|
-
return `group-trigger-in-${e.to.branch}`
|
|
373
|
-
}
|
|
374
|
-
if (targetKind === 'groupOutput') {
|
|
375
|
-
// Trigger edge from an inner node into the groupOutput sentinel —
|
|
376
|
-
// the sentinel exposes a `groupOutput-trigger-in-<port>` handle per
|
|
377
|
-
// declared trigger-OUT port (since trigger-OUT on the OUTER group is
|
|
378
|
-
// trigger-IN on the sentinel side).
|
|
379
|
-
return `groupOutput-trigger-in-${e.to.branch}`
|
|
380
|
-
}
|
|
381
|
-
return 'trigger-in'
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function triggerSourceHandle(e: TriggerEdge, sourceKind: NodeKind | undefined): string {
|
|
385
|
-
if (sourceKind === 'group') {
|
|
386
|
-
// Source is the OUTER group node firing into an outer downstream
|
|
387
|
-
// node — the branch name IS the port name (see planNewGroup's
|
|
388
|
-
// outerTriggerEdges where `from.branch = portName`).
|
|
389
|
-
return `group-trigger-out-${e.from.branch ?? 'main'}`
|
|
390
|
-
}
|
|
391
|
-
if (sourceKind === 'groupInput') {
|
|
392
|
-
// Inner edge out of groupInput into an inner node — handle id is
|
|
393
|
-
// `groupInput-trigger-out-<port>` and the port name lives on
|
|
394
|
-
// `from.branch` (per planNewGroup's innerTriggerEdges).
|
|
395
|
-
return `groupInput-trigger-out-${e.from.branch ?? 'main'}`
|
|
396
|
-
}
|
|
397
|
-
return `trigger-out-${e.from.branch ?? 'main'}`
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function dataSourceHandle(e: DataEdge, sourceKind: NodeKind | undefined): string {
|
|
401
|
-
if (sourceKind === 'group') return `group-data-out-${e.from.port}`
|
|
402
|
-
if (sourceKind === 'groupInput') return `groupInput-data-out-${e.from.port}`
|
|
403
|
-
return `data-out-${e.from.port}`
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
function dataTargetHandle(e: DataEdge, targetKind: NodeKind | undefined): string {
|
|
407
|
-
if (targetKind === 'group') return `group-data-in-${e.to.field}`
|
|
408
|
-
if (targetKind === 'groupOutput') return `groupOutput-data-in-${e.to.field}`
|
|
409
|
-
return `data-in-${e.to.field}`
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// After a run, the edges it took are drawn solid and the one into the failing
|
|
413
|
-
// step red; the others fade.
|
|
414
|
-
function edgeClass(from: string, to: string): string {
|
|
415
|
-
const runs = props.runStates
|
|
416
|
-
if (!runs) return 'edge-trigger'
|
|
417
|
-
const target = runs[to]?.status
|
|
418
|
-
const taken = runs[from] && target && target !== 'skipped'
|
|
419
|
-
if (taken && target === 'failed') return 'edge-trigger edge-failed'
|
|
420
|
-
return taken ? 'edge-trigger edge-taken' : 'edge-trigger edge-idle'
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Edge styling lives in <style> (.edge-trigger / .edge-data) so the
|
|
424
|
-
// `.selected` highlight can win without `!important`. Inline `style`
|
|
425
|
-
// on a vue-flow edge defeats the .selected rule — documented gotcha.
|
|
426
|
-
const vfEdges = computed(() => {
|
|
427
|
-
const kinds = nodeKindById.value
|
|
428
|
-
const triggerEdges = props.graph.triggerEdges.map((e) => ({
|
|
429
|
-
id: e.id,
|
|
430
|
-
source: e.from.node,
|
|
431
|
-
target: e.to.node,
|
|
432
|
-
sourceHandle: triggerSourceHandle(e, kinds.get(e.from.node)),
|
|
433
|
-
targetHandle: triggerTargetHandle(e, kinds.get(e.to.node)),
|
|
434
|
-
data: { kind: 'trigger' as const },
|
|
435
|
-
ariaLabel: `${menuName(e.from.node)} → ${menuName(e.to.node)}`,
|
|
436
|
-
class: edgeClass(e.from.node, e.to.node),
|
|
437
|
-
}))
|
|
438
|
-
const dataEdges = props.graph.dataEdges.map((e) => ({
|
|
439
|
-
id: e.id,
|
|
440
|
-
source: e.from.node,
|
|
441
|
-
target: e.to.node,
|
|
442
|
-
sourceHandle: dataSourceHandle(e, kinds.get(e.from.node)),
|
|
443
|
-
targetHandle: dataTargetHandle(e, kinds.get(e.to.node)),
|
|
444
|
-
data: { kind: 'data' as const },
|
|
445
|
-
ariaLabel: `${menuName(e.from.node)} · ${e.from.port} → ${menuName(e.to.node)} · ${e.to.field}`,
|
|
446
|
-
class: 'edge-data',
|
|
447
|
-
}))
|
|
448
|
-
return [...triggerEdges, ...dataEdges]
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
|
|
452
50
|
function emitGraph(g: ProcedureGraph) {
|
|
453
51
|
emit('update:graph', g)
|
|
454
52
|
}
|
|
455
53
|
|
|
456
|
-
interface XY {
|
|
457
|
-
x: number
|
|
458
|
-
y: number
|
|
459
|
-
}
|
|
460
|
-
interface Rect extends XY {
|
|
461
|
-
width: number
|
|
462
|
-
height: number
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function nodeRects(): Rect[] {
|
|
466
|
-
return props.graph.nodes.map((n) => {
|
|
467
|
-
const size = flowRef.value?.findNode(n.id)?.dimensions
|
|
468
|
-
return {
|
|
469
|
-
...n.position,
|
|
470
|
-
width: size?.width || NEW_NODE_SIZE.width,
|
|
471
|
-
height: size?.height || NEW_NODE_SIZE.height,
|
|
472
|
-
}
|
|
473
|
-
})
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function overlaps(a: Rect, b: Rect): boolean {
|
|
477
|
-
const gap = NODE_GAP / 2
|
|
478
|
-
return a.x < b.x + b.width + gap && b.x < a.x + a.width + gap && a.y < b.y + b.height + gap && b.y < a.y + a.height + gap
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// The first place at or below `pos` where a new node covers no other one.
|
|
482
|
-
function freeSpot(pos: XY): XY {
|
|
483
|
-
const rects = nodeRects()
|
|
484
|
-
const spot: Rect = { ...pos, ...NEW_NODE_SIZE }
|
|
485
|
-
for (let hit = rects.find((r) => overlaps(spot, r)); hit; hit = rects.find((r) => overlaps(spot, r))) {
|
|
486
|
-
spot.y = hit.y + hit.height + NODE_GAP
|
|
487
|
-
}
|
|
488
|
-
return { x: Math.round(spot.x), y: Math.round(spot.y) }
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// A new step goes right of the selected one, else in the middle of what the
|
|
492
|
-
// canvas shows.
|
|
493
|
-
function newNodePosition(anchor: AppGraphNode | undefined): XY {
|
|
494
|
-
const flow = flowRef.value
|
|
495
|
-
if (anchor) {
|
|
496
|
-
const width = flow?.findNode(anchor.id)?.dimensions.width || NEW_NODE_SIZE.width
|
|
497
|
-
return freeSpot({ x: anchor.position.x + width + NODE_GAP, y: anchor.position.y })
|
|
498
|
-
}
|
|
499
|
-
if (!flow) return freeSpot({ x: 0, y: 0 })
|
|
500
|
-
const { x, y, zoom } = flow.viewport
|
|
501
|
-
return freeSpot({
|
|
502
|
-
x: (flow.dimensions.width / 2 - x) / zoom - NEW_NODE_SIZE.width / 2,
|
|
503
|
-
y: (flow.dimensions.height / 2 - y) / zoom - NEW_NODE_SIZE.height / 2,
|
|
504
|
-
})
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// The node a new step follows: the one selected last on this canvas.
|
|
508
|
-
function anchorNode(): AppGraphNode | undefined {
|
|
509
|
-
const id = props.selectedNodeId ?? canvasSelection.value[canvasSelection.value.length - 1]
|
|
510
|
-
return props.graph.nodes.find((n) => n.id === id)
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
interface Port {
|
|
514
|
-
/** Vue Flow handle id. */
|
|
515
|
-
id: string
|
|
516
|
-
/** Port name ('' for the single trigger input of a step). */
|
|
517
|
-
name: string
|
|
518
|
-
}
|
|
519
|
-
interface NodeHandles {
|
|
520
|
-
triggerIns: Port[]
|
|
521
|
-
triggerOuts: Port[]
|
|
522
|
-
dataIns: Port[]
|
|
523
|
-
dataOuts: Port[]
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// The handles a node draws, named as its renderer names them (see the
|
|
527
|
-
// handle prefix table in useGraphConnect).
|
|
528
|
-
function handlesOf(node: AppGraphNode): NodeHandles {
|
|
529
|
-
if (node.kind === 'group' || SENTINEL_KINDS.has(node.kind)) {
|
|
530
|
-
const ports =
|
|
531
|
-
node.kind === 'group'
|
|
532
|
-
? ((node as AppGraphNode & { ports?: GroupPort[] }).ports ?? [])
|
|
533
|
-
: (props.parentGroupPorts ?? [])
|
|
534
|
-
const pick = (kind: GroupPort['kind'], direction: GroupPort['direction'], prefix: string) =>
|
|
535
|
-
ports
|
|
536
|
-
.filter((p) => p.kind === kind && p.direction === direction)
|
|
537
|
-
.map((p) => ({ id: `${prefix}${p.name}`, name: p.name }))
|
|
538
|
-
if (node.kind === 'group') {
|
|
539
|
-
return {
|
|
540
|
-
triggerIns: pick('trigger', 'in', 'group-trigger-in-'),
|
|
541
|
-
triggerOuts: pick('trigger', 'out', 'group-trigger-out-'),
|
|
542
|
-
dataIns: pick('data', 'in', 'group-data-in-'),
|
|
543
|
-
dataOuts: pick('data', 'out', 'group-data-out-'),
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
// The sentinels face inwards: the group's inputs leave groupInput, its
|
|
547
|
-
// outputs enter groupOutput.
|
|
548
|
-
if (node.kind === 'groupInput') {
|
|
549
|
-
return {
|
|
550
|
-
triggerIns: [],
|
|
551
|
-
triggerOuts: pick('trigger', 'in', 'groupInput-trigger-out-'),
|
|
552
|
-
dataIns: [],
|
|
553
|
-
dataOuts: pick('data', 'in', 'groupInput-data-out-'),
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return {
|
|
557
|
-
triggerIns: pick('trigger', 'out', 'groupOutput-trigger-in-'),
|
|
558
|
-
triggerOuts: [],
|
|
559
|
-
dataIns: pick('data', 'out', 'groupOutput-data-in-'),
|
|
560
|
-
dataOuts: [],
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
const data = dataFor(node) as {
|
|
564
|
-
hasTriggerIn?: boolean
|
|
565
|
-
hasMainTriggerOut?: boolean
|
|
566
|
-
triggerOuts?: string[]
|
|
567
|
-
dataIns?: Array<{ name: string }>
|
|
568
|
-
dataOuts?: Array<{ name: string }>
|
|
569
|
-
}
|
|
570
|
-
const branches = [...(data.hasMainTriggerOut === false ? [] : ['main']), ...(data.triggerOuts ?? [])]
|
|
571
|
-
return {
|
|
572
|
-
triggerIns: data.hasTriggerIn === false ? [] : [{ id: 'trigger-in', name: '' }],
|
|
573
|
-
triggerOuts: branches.map((name) => ({ id: `trigger-out-${name}`, name })),
|
|
574
|
-
dataIns: (data.dataIns ?? []).map((p) => ({ id: `data-in-${p.name}`, name: p.name })),
|
|
575
|
-
dataOuts: (data.dataOuts ?? []).map((p) => ({ id: `data-out-${p.name}`, name: p.name })),
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
function check(graph: ProcedureGraph, conn: Connection) {
|
|
580
|
-
return canConnect(
|
|
581
|
-
graph,
|
|
582
|
-
props.nodeKinds,
|
|
583
|
-
props.triggerTypes,
|
|
584
|
-
props.actionTypes,
|
|
585
|
-
props.dataNodeTypes,
|
|
586
|
-
conn,
|
|
587
|
-
{ parentGroupPorts: props.parentGroupPorts },
|
|
588
|
-
)
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// The link from `from`'s main output to `to`, when that output is free and
|
|
592
|
-
// `to` has an input that accepts it.
|
|
593
|
-
function nextStepConnection(graph: ProcedureGraph, from: AppGraphNode, to: AppGraphNode): Connection | null {
|
|
594
|
-
const out = handlesOf(from).triggerOuts.find((p) => p.name === 'main')
|
|
595
|
-
const ins = handlesOf(to).triggerIns
|
|
596
|
-
const into = ins.find((p) => p.name === 'main' || p.name === '') ?? ins[0]
|
|
597
|
-
if (!out || !into) return null
|
|
598
|
-
if (graph.triggerEdges.some((e) => e.from.node === from.id && (e.from.branch ?? 'main') === 'main')) return null
|
|
599
|
-
const conn: Connection = { source: from.id, sourceHandle: out.id, target: to.id, targetHandle: into.id }
|
|
600
|
-
return check(graph, conn).ok ? conn : null
|
|
601
|
-
}
|
|
602
|
-
|
|
603
54
|
// The node to select and bring into view once drawn: one just added, or one
|
|
604
55
|
// the editor points at (`readable`).
|
|
605
|
-
|
|
56
|
+
const reveal: Reveal = { pending: null }
|
|
606
57
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
function insertNode(node: AppGraphNode, at?: XY) {
|
|
610
|
-
const anchor = at ? undefined : anchorNode()
|
|
611
|
-
const placed = { ...node, position: at ? freeSpot(at) : newNodePosition(anchor) }
|
|
612
|
-
const graph = { ...props.graph, nodes: [...props.graph.nodes, placed] }
|
|
613
|
-
const link = anchor ? nextStepConnection(graph, anchor, placed) : null
|
|
614
|
-
emitGraph(link ? (withConnection(graph, link)?.graph ?? graph) : graph)
|
|
615
|
-
revealPending = { id: placed.id, readable: false }
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
function defaultsFromSchema(schema: JsonSchema | undefined): Record<string, unknown> {
|
|
619
|
-
if (!schema?.properties) return {}
|
|
620
|
-
const out: Record<string, unknown> = {}
|
|
621
|
-
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
622
|
-
if (prop && prop.default !== undefined) out[name] = prop.default
|
|
623
|
-
}
|
|
624
|
-
return out
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function defaultConfigFor(kind: NodeKind, typeId?: string): Record<string, unknown> {
|
|
628
|
-
const ui = nodeKindUiByKind.value.get(kind)
|
|
629
|
-
if (ui?.typeRegistry === 'triggers') {
|
|
630
|
-
const t = props.triggerTypes.find((tt) => tt.id === typeId)
|
|
631
|
-
return defaultsFromSchema(t?.configSchema)
|
|
632
|
-
}
|
|
633
|
-
if (ui?.typeRegistry === 'actions') {
|
|
634
|
-
const a = props.actionTypes.find((aa) => aa.id === typeId)
|
|
635
|
-
return defaultsFromSchema(a?.inputSchema)
|
|
636
|
-
}
|
|
637
|
-
if (ui?.typeRegistry === 'dataNodes') {
|
|
638
|
-
const d = props.dataNodeTypes.find((dd) => dd.id === typeId)
|
|
639
|
-
// Constant nodes seed from `configSchema` (their value lives there);
|
|
640
|
-
// wired-port data nodes seed any `inputSchema` field defaults.
|
|
641
|
-
return { ...defaultsFromSchema(d?.inputSchema), ...defaultsFromSchema(d?.configSchema) }
|
|
642
|
-
}
|
|
643
|
-
// Static-config kinds carry their seed config in metadata; deep-clone
|
|
644
|
-
// so each instance gets its own mutable copy. JSON round-trip strips
|
|
645
|
-
// the Vue reactive proxy that wraps `props.nodeKinds` — structuredClone
|
|
646
|
-
// would throw on the proxy.
|
|
647
|
-
return ui?.defaultConfig
|
|
648
|
-
? (JSON.parse(JSON.stringify(ui.defaultConfig)) as Record<string, unknown>)
|
|
649
|
-
: {}
|
|
650
|
-
}
|
|
58
|
+
const flowRef = ref<FlowController | null>(null)
|
|
59
|
+
const wrapRef = ref<HTMLElement | null>(null)
|
|
651
60
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
id: newId(),
|
|
656
|
-
kind,
|
|
657
|
-
typeId,
|
|
658
|
-
config: defaultConfigFor(kind, typeId),
|
|
659
|
-
position: { x: 0, y: 0 },
|
|
660
|
-
},
|
|
661
|
-
at,
|
|
662
|
-
)
|
|
663
|
-
}
|
|
61
|
+
// The same set, reactive (sentinels included), for the toolbar's link menu
|
|
62
|
+
// and the placement of new nodes.
|
|
63
|
+
const canvasSelection = ref<string[]>([])
|
|
664
64
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
// JSON round-trip strips Vue's reactive proxy that wraps the template
|
|
685
|
-
// passed from the palette; structuredClone throws on proxies.
|
|
686
|
-
ports: JSON.parse(JSON.stringify(template.ports ?? [])) as GroupPort[],
|
|
687
|
-
}
|
|
688
|
-
insertNode(node, at)
|
|
689
|
-
}
|
|
65
|
+
const { nodeKindUiByKind, handlesOf, vfNodes, menuName } = useCanvasNodes(props, {
|
|
66
|
+
t,
|
|
67
|
+
te,
|
|
68
|
+
processI18n,
|
|
69
|
+
processText,
|
|
70
|
+
})
|
|
71
|
+
const vfEdges = useCanvasEdges(props, menuName)
|
|
72
|
+
const check = connectionCheck(props)
|
|
73
|
+
|
|
74
|
+
const { addNode, addTemplateInstance, onDragOver, onDrop } = useNodePlacement({
|
|
75
|
+
props,
|
|
76
|
+
flowRef,
|
|
77
|
+
canvasSelection,
|
|
78
|
+
nodeKindUiByKind,
|
|
79
|
+
emitGraph,
|
|
80
|
+
reveal,
|
|
81
|
+
check,
|
|
82
|
+
handlesOf,
|
|
83
|
+
})
|
|
690
84
|
|
|
691
85
|
// Node creation is driven from the left BuilderPalette (in Editor.vue) — expose
|
|
692
86
|
// the two add helpers so the palette's events can reach the graph mutation.
|
|
693
87
|
defineExpose({ addNode, addTemplateInstance })
|
|
694
88
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function onDrop(event: DragEvent) {
|
|
703
|
-
const raw = event.dataTransfer?.getData(PALETTE_DRAG_TYPE)
|
|
704
|
-
const flow = flowRef.value
|
|
705
|
-
if (props.readOnly || !raw || !flow) return
|
|
706
|
-
event.preventDefault()
|
|
707
|
-
const point = flow.screenToFlowCoordinate({ x: event.clientX, y: event.clientY })
|
|
708
|
-
const at = { x: point.x - NEW_NODE_SIZE.width / 2, y: point.y - NEW_NODE_SIZE.height / 2 }
|
|
709
|
-
const block = JSON.parse(raw) as PaletteBlock
|
|
710
|
-
if (block.template) addTemplateInstance(block.template, at)
|
|
711
|
-
else if (block.kind) addNode(block.kind, block.typeId, at)
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
// DmsFlowCanvas owns the VueFlow store (it calls `useVueFlow(flowId)` with a
|
|
715
|
-
// private id and `defineExpose`s the resulting controller). We grab that
|
|
716
|
-
// controller through a template ref instead of calling `useVueFlow()` here —
|
|
717
|
-
// a bare `useVueFlow()` would resolve to the DEFAULT store, which is NOT the
|
|
718
|
-
// one DmsFlowCanvas drives, so zoom/fit/updateNodeInternals would silently
|
|
719
|
-
// no-op. Only the handful of imperative methods we actually use are typed.
|
|
720
|
-
interface FlowNodeState {
|
|
721
|
-
id: string
|
|
722
|
-
selected?: boolean
|
|
723
|
-
computedPosition: XY
|
|
724
|
-
dimensions: { width: number; height: number }
|
|
725
|
-
}
|
|
726
|
-
interface FlowController {
|
|
727
|
-
zoomIn: () => void
|
|
728
|
-
zoomOut: () => void
|
|
729
|
-
zoomTo: (zoom: number) => void
|
|
730
|
-
setViewport: (viewport: XY & { zoom: number }, options?: { duration?: number }) => Promise<boolean>
|
|
731
|
-
screenToFlowCoordinate: (position: XY) => XY
|
|
732
|
-
findNode: (id: string) => FlowNodeState | undefined
|
|
733
|
-
addSelectedNodes: (nodes: FlowNodeState[]) => void
|
|
734
|
-
removeSelectedNodes: (nodes: FlowNodeState[]) => void
|
|
735
|
-
updateNodeInternals: (ids?: string | string[]) => void
|
|
736
|
-
// DmsFlowCanvas `defineExpose`s the VueFlow controller; Vue's expose proxy
|
|
737
|
-
// unwraps the `viewport` ref, so consumers read `.viewport.zoom` directly
|
|
738
|
-
// (NOT `.viewport.value.zoom` — that extra `.value` is undefined and pinned
|
|
739
|
-
// the zoom readout at 100%). Same for the refs below.
|
|
740
|
-
viewport: XY & { zoom: number }
|
|
741
|
-
/** Size of the canvas on screen. */
|
|
742
|
-
dimensions: { width: number; height: number }
|
|
743
|
-
getSelectedNodes: FlowNodeState[]
|
|
744
|
-
getSelectedEdges: Array<{ id: string }>
|
|
745
|
-
/** 'invalid' while the link being drawn hovers a port that refuses it. */
|
|
746
|
-
connectionStatus: 'valid' | 'invalid' | null
|
|
747
|
-
}
|
|
748
|
-
const flowRef = ref<FlowController | null>(null)
|
|
749
|
-
const wrapRef = ref<HTMLElement | null>(null)
|
|
750
|
-
|
|
751
|
-
// The width of the canvas the inspector covers when it is drawn over it.
|
|
752
|
-
function coveredRight(): number {
|
|
753
|
-
const cover = props.coveredBy?.getBoundingClientRect()
|
|
754
|
-
const own = wrapRef.value?.getBoundingClientRect()
|
|
755
|
-
if (!cover?.width || !own) return 0
|
|
756
|
-
return Math.max(0, Math.min(own.right, cover.right) - Math.max(own.left, cover.left))
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// Fit every node into the part of the canvas left visible.
|
|
760
|
-
function fitView() {
|
|
761
|
-
const flow = flowRef.value
|
|
762
|
-
if (!flow) return
|
|
763
|
-
const nodes = props.graph.nodes
|
|
764
|
-
.map((n) => flow.findNode(n.id))
|
|
765
|
-
.filter((n): n is FlowNodeState => !!n?.dimensions.width)
|
|
766
|
-
if (nodes.length === 0) return
|
|
767
|
-
const left = Math.min(...nodes.map((n) => n.computedPosition.x))
|
|
768
|
-
const top = Math.min(...nodes.map((n) => n.computedPosition.y))
|
|
769
|
-
const width = Math.max(...nodes.map((n) => n.computedPosition.x + n.dimensions.width)) - left
|
|
770
|
-
const height = Math.max(...nodes.map((n) => n.computedPosition.y + n.dimensions.height)) - top
|
|
771
|
-
const visible = flow.dimensions.width - coveredRight()
|
|
772
|
-
const room = 1 + FIT_PADDING
|
|
773
|
-
const fit = Math.min(visible / (width * room), flow.dimensions.height / (height * room))
|
|
774
|
-
const zoom = Math.min(Math.max(fit, MIN_ZOOM), FIT_MAX_ZOOM)
|
|
775
|
-
flow.setViewport({
|
|
776
|
-
x: (visible - width * zoom) / 2 - left * zoom,
|
|
777
|
-
y: (flow.dimensions.height - height * zoom) / 2 - top * zoom,
|
|
778
|
-
zoom,
|
|
779
|
-
})
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// Select a node and bring it into the visible part of the canvas. A node the
|
|
783
|
-
// editor points at (a link, a problem) is also shown at a readable zoom; a
|
|
784
|
-
// new node keeps the zoom.
|
|
785
|
-
function focusNode(id: string, readable = false) {
|
|
786
|
-
const flow = flowRef.value
|
|
787
|
-
const node = flow?.findNode(id)
|
|
788
|
-
if (!flow || !node) return
|
|
789
|
-
if (!node.selected) flow.addSelectedNodes([node])
|
|
790
|
-
// Selecting opens the inspector, which narrows or covers the canvas:
|
|
791
|
-
// look once it is drawn (two frames).
|
|
792
|
-
requestAnimationFrame(() => requestAnimationFrame(() => panTo(id, readable)))
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
function panTo(id: string, readable: boolean) {
|
|
796
|
-
const flow = flowRef.value
|
|
797
|
-
const node = flow?.findNode(id)
|
|
798
|
-
if (!flow || !node) return
|
|
799
|
-
const visible = flow.dimensions.width - coveredRight()
|
|
800
|
-
const zoom = readable ? Math.max(flow.viewport.zoom, 1) : flow.viewport.zoom
|
|
801
|
-
const left = node.computedPosition.x * zoom + flow.viewport.x
|
|
802
|
-
const top = node.computedPosition.y * zoom + flow.viewport.y
|
|
803
|
-
const inSight =
|
|
804
|
-
left >= 0 &&
|
|
805
|
-
top >= 0 &&
|
|
806
|
-
left + node.dimensions.width * zoom <= visible &&
|
|
807
|
-
top + node.dimensions.height * zoom <= flow.dimensions.height
|
|
808
|
-
if (inSight && zoom === flow.viewport.zoom) return
|
|
809
|
-
flow.setViewport(
|
|
810
|
-
{
|
|
811
|
-
x: visible / 2 - (node.computedPosition.x + node.dimensions.width / 2) * zoom,
|
|
812
|
-
y: flow.dimensions.height / 2 - (node.computedPosition.y + node.dimensions.height / 2) * zoom,
|
|
813
|
-
zoom,
|
|
814
|
-
},
|
|
815
|
-
// A node pointed at is shown at once; a new one slides into view.
|
|
816
|
-
{ duration: readable ? 0 : 200 },
|
|
817
|
-
)
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
// A new graph on the canvas (first load, another procedure, a group entered
|
|
821
|
-
// or left) is fitted into view; a node just added or pointed at is shown.
|
|
822
|
-
// Both wait until every node is measured and the panels around the canvas
|
|
823
|
-
// have settled (two frames): Vue Flow keeps the measures of nodes whose id
|
|
824
|
-
// the previous graph shared, so it does not always report them again.
|
|
825
|
-
let fitPending = true
|
|
826
|
-
let settleQueued = false
|
|
827
|
-
function settleView() {
|
|
828
|
-
if (settleQueued) return
|
|
829
|
-
settleQueued = true
|
|
830
|
-
requestAnimationFrame(() =>
|
|
831
|
-
requestAnimationFrame(() => {
|
|
832
|
-
settleQueued = false
|
|
833
|
-
const flow = flowRef.value
|
|
834
|
-
if (!flow || !props.graph.nodes.every((n) => flow.findNode(n.id)?.dimensions.width)) return
|
|
835
|
-
if (fitPending) {
|
|
836
|
-
fitPending = false
|
|
837
|
-
fitView()
|
|
838
|
-
// The node the editor points at stays the one shown.
|
|
839
|
-
if (props.selectedNodeId) revealPending ??= { id: props.selectedNodeId, readable: true }
|
|
840
|
-
}
|
|
841
|
-
if (revealPending) {
|
|
842
|
-
const { id, readable } = revealPending
|
|
843
|
-
revealPending = null
|
|
844
|
-
focusNode(id, readable)
|
|
845
|
-
}
|
|
846
|
-
}),
|
|
847
|
-
)
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
// Vue Flow emits this once every node on the canvas has been measured.
|
|
851
|
-
function onNodesInitialized() {
|
|
852
|
-
settleView()
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
watch(
|
|
856
|
-
() => props.viewKey,
|
|
857
|
-
() => {
|
|
858
|
-
fitPending = true
|
|
859
|
-
nextTick(settleView)
|
|
860
|
-
},
|
|
861
|
-
)
|
|
862
|
-
|
|
863
|
-
watch(
|
|
864
|
-
() => props.selectedNodeId,
|
|
865
|
-
(id) => {
|
|
866
|
-
const flow = flowRef.value
|
|
867
|
-
// The editor closed its inspector: the canvas lets go of the node too.
|
|
868
|
-
if (!id) {
|
|
869
|
-
if (flow?.getSelectedNodes.length) flow.removeSelectedNodes(flow.getSelectedNodes)
|
|
870
|
-
return
|
|
871
|
-
}
|
|
872
|
-
// A node selected on the canvas itself is already where the user looks.
|
|
873
|
-
if (flow?.findNode(id)?.selected) return
|
|
874
|
-
revealPending = { id, readable: true }
|
|
875
|
-
nextTick(settleView)
|
|
876
|
-
},
|
|
877
|
-
// The editor may name a node (a `?node=` link) before the canvas exists.
|
|
878
|
-
{ immediate: true },
|
|
879
|
-
)
|
|
880
|
-
|
|
881
|
-
// Vue Flow caches each node's handle bounding boxes in its internal store and
|
|
882
|
-
// only re-measures when `updateNodeInternals(id)` is called. When a port is
|
|
883
|
-
// renamed or moved between the title bar and body (e.g. renaming a port to
|
|
884
|
-
// "main" moves the handle from a body row into the header), the Handle DOM
|
|
885
|
-
// element ends up in a different on-screen position but the cached bbox stays
|
|
886
|
-
// stale — connected edges keep drawing to the OLD coordinates until the next
|
|
887
|
-
// re-measure.
|
|
888
|
-
//
|
|
889
|
-
// To keep edges glued to handles, watch a signature derived from the per-node
|
|
890
|
-
// port lists / kinds and force a re-measure of every node after the DOM has
|
|
891
|
-
// applied the new template. Watching the full `props.graph` would fire on
|
|
892
|
-
// every drag (each emitGraph returns a fresh object) — costly and pointless,
|
|
893
|
-
// since node positions trigger their own internal updates already. The
|
|
894
|
-
// signature only changes when port shape changes, which is exactly when we
|
|
895
|
-
// need to re-measure.
|
|
896
|
-
const portsSignature = computed(() => {
|
|
897
|
-
const own = props.graph.nodes
|
|
898
|
-
.map((n) => {
|
|
899
|
-
const ports = (n as AppGraphNode & { ports?: unknown }).ports
|
|
900
|
-
const portsKey = Array.isArray(ports) ? JSON.stringify(ports) : ''
|
|
901
|
-
return `${n.id}:${n.kind}:${portsKey}`
|
|
902
|
-
})
|
|
903
|
-
.join('|')
|
|
904
|
-
// Sentinel nodes (groupInput / groupOutput) inside this canvas render
|
|
905
|
-
// handles derived from `parentGroupPorts`, not from their own node data.
|
|
906
|
-
// A rename on the outer group's port list re-renders the sentinel but
|
|
907
|
-
// doesn't show up in `props.graph.nodes` above, so we must also fold
|
|
908
|
-
// the parent ports into the signature.
|
|
909
|
-
const parent = Array.isArray(props.parentGroupPorts)
|
|
910
|
-
? JSON.stringify(props.parentGroupPorts)
|
|
911
|
-
: ''
|
|
912
|
-
return `${own}#${parent}`
|
|
913
|
-
})
|
|
914
|
-
watch(portsSignature, () => {
|
|
915
|
-
nextTick(() => {
|
|
916
|
-
for (const node of props.graph.nodes) {
|
|
917
|
-
flowRef.value?.updateNodeInternals(node.id)
|
|
918
|
-
}
|
|
919
|
-
})
|
|
89
|
+
const { fitView, onNodesInitialized, zoomPercent, resetZoom } = useCanvasView({
|
|
90
|
+
props,
|
|
91
|
+
flowRef,
|
|
92
|
+
wrapRef,
|
|
93
|
+
reveal,
|
|
920
94
|
})
|
|
921
95
|
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
96
|
+
const { onConnect, refusal, refusalShown, isValidConnection, onConnectEnd } = useConnections({
|
|
97
|
+
props,
|
|
98
|
+
t,
|
|
99
|
+
toast,
|
|
100
|
+
emitGraph,
|
|
101
|
+
menuName,
|
|
102
|
+
check,
|
|
103
|
+
flowRef,
|
|
925
104
|
})
|
|
926
105
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
): { graph: ProcedureGraph; added: TriggerEdge | DataEdge; replaced?: TriggerEdge | DataEdge } | null {
|
|
936
|
-
const kind = connectionKind(conn.sourceHandle)
|
|
937
|
-
if (kind === 'trigger') {
|
|
938
|
-
const branch = parseSourceBranch(conn.sourceHandle)
|
|
939
|
-
const toBranch = parseTargetBranch(conn.targetHandle)
|
|
940
|
-
const newEdge: TriggerEdge = {
|
|
941
|
-
id: newId(),
|
|
942
|
-
from: { node: conn.source, branch },
|
|
943
|
-
to: toBranch !== undefined
|
|
944
|
-
? { node: conn.target, branch: toBranch }
|
|
945
|
-
: { node: conn.target },
|
|
946
|
-
}
|
|
947
|
-
// Each source/branch carries exactly one outgoing trigger edge.
|
|
948
|
-
// Connecting again replaces any existing edge from that source/branch.
|
|
949
|
-
// (Branching across if/switch named branches still works because each
|
|
950
|
-
// branch has its own `from.branch` and only conflicts with itself.)
|
|
951
|
-
const replaced = graph.triggerEdges.find(
|
|
952
|
-
(e) => e.from.node === conn.source && (e.from.branch ?? 'main') === branch,
|
|
953
|
-
)
|
|
954
|
-
return {
|
|
955
|
-
graph: { ...graph, triggerEdges: [...graph.triggerEdges.filter((e) => e !== replaced), newEdge] },
|
|
956
|
-
added: newEdge,
|
|
957
|
-
replaced,
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
if (kind !== 'data') return null
|
|
961
|
-
const port = parseDataPort(conn.sourceHandle)
|
|
962
|
-
const field = parseDataField(conn.targetHandle)
|
|
963
|
-
if (!port || !field) return null
|
|
964
|
-
const newEdge: DataEdge = {
|
|
965
|
-
id: newId(),
|
|
966
|
-
from: { node: conn.source, port },
|
|
967
|
-
to: { node: conn.target, field },
|
|
968
|
-
}
|
|
969
|
-
// Overwrite: a field reads from one output only.
|
|
970
|
-
const replaced = graph.dataEdges.find((e) => e.to.node === conn.target && e.to.field === field)
|
|
971
|
-
return {
|
|
972
|
-
graph: { ...graph, dataEdges: [...graph.dataEdges.filter((e) => e !== replaced), newEdge] },
|
|
973
|
-
added: newEdge,
|
|
974
|
-
replaced,
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
function refusalText(result: ConnectResult): string {
|
|
979
|
-
return result.ok ? '' : t(`dms_automation.editor.canvas.connect.${result.code}`, result.params ?? {})
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
// Undo of a replacement: the new link goes, the old one comes back — unless
|
|
983
|
-
// the new link is gone already, or an end of the old one was deleted since.
|
|
984
|
-
function restoreLink(added: TriggerEdge | DataEdge, old: TriggerEdge | DataEdge) {
|
|
985
|
-
const graph = props.graph
|
|
986
|
-
const ids = new Set(graph.nodes.map((n) => n.id))
|
|
987
|
-
const back = ids.has(old.from.node) && ids.has(old.to.node)
|
|
988
|
-
if ('port' in added.from) {
|
|
989
|
-
if (!graph.dataEdges.some((e) => e.id === added.id)) return
|
|
990
|
-
const edges = graph.dataEdges.filter((e) => e.id !== added.id)
|
|
991
|
-
emitGraph({ ...graph, dataEdges: back ? [...edges, old as DataEdge] : edges })
|
|
992
|
-
} else {
|
|
993
|
-
if (!graph.triggerEdges.some((e) => e.id === added.id)) return
|
|
994
|
-
const edges = graph.triggerEdges.filter((e) => e.id !== added.id)
|
|
995
|
-
emitGraph({ ...graph, triggerEdges: back ? [...edges, old as TriggerEdge] : edges })
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
// Drawing over an existing link replaces it: say which one, with an undo of
|
|
1000
|
-
// that replacement only.
|
|
1001
|
-
function notifyReplaced(added: TriggerEdge | DataEdge, old: TriggerEdge | DataEdge, conn: Connection) {
|
|
1002
|
-
let description: string
|
|
1003
|
-
if ('port' in old.from) {
|
|
1004
|
-
const port = parseDataPort(conn.sourceHandle)
|
|
1005
|
-
if (old.from.node === conn.source && old.from.port === port) return
|
|
1006
|
-
description = t('dms_automation.editor.canvas.replaced.data', {
|
|
1007
|
-
field: (old as DataEdge).to.field,
|
|
1008
|
-
step: menuName(conn.target),
|
|
1009
|
-
source: `${menuName(conn.source)} · ${port}`,
|
|
1010
|
-
previous: `${menuName(old.from.node)} · ${old.from.port}`,
|
|
1011
|
-
})
|
|
1012
|
-
} else {
|
|
1013
|
-
if (old.to.node === conn.target) return
|
|
1014
|
-
description = t('dms_automation.editor.canvas.replaced.trigger', {
|
|
1015
|
-
source: menuName(conn.source),
|
|
1016
|
-
target: menuName(conn.target),
|
|
1017
|
-
previous: menuName(old.to.node),
|
|
1018
|
-
})
|
|
1019
|
-
}
|
|
1020
|
-
toast.add({
|
|
1021
|
-
title: t('dms_automation.editor.canvas.replaced.title'),
|
|
1022
|
-
description,
|
|
1023
|
-
color: 'info',
|
|
1024
|
-
icon: 'i-ph-arrows-left-right',
|
|
1025
|
-
actions: [{ label: t('dms_automation.editor.canvas.undo'), onClick: () => restoreLink(added, old) }],
|
|
1026
|
-
})
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
function onConnect(conn: Connection) {
|
|
1030
|
-
if (props.readOnly) return
|
|
1031
|
-
const result = check(props.graph, conn)
|
|
1032
|
-
if (!result.ok) {
|
|
1033
|
-
toast.add({
|
|
1034
|
-
title: t('dms_automation.editor.canvas.connect.title'),
|
|
1035
|
-
description: refusalText(result),
|
|
1036
|
-
color: 'warning',
|
|
1037
|
-
icon: 'i-ph-warning',
|
|
1038
|
-
})
|
|
1039
|
-
return
|
|
1040
|
-
}
|
|
1041
|
-
const next = withConnection(props.graph, conn)
|
|
1042
|
-
if (!next) return
|
|
1043
|
-
emitGraph(next.graph)
|
|
1044
|
-
if (next.replaced) notifyReplaced(next.added, next.replaced, conn)
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
// Why the port under a link being drawn refuses it, shown while it hovers.
|
|
1048
|
-
const refusal = ref('')
|
|
1049
|
-
const refusalShown = computed(() => flowRef.value?.connectionStatus === 'invalid' && refusal.value !== '')
|
|
1050
|
-
|
|
1051
|
-
function isValidConnection(conn: Connection): boolean {
|
|
1052
|
-
const result = check(props.graph, conn)
|
|
1053
|
-
refusal.value = refusalText(result)
|
|
1054
|
-
return result.ok
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
// Released over a port that refuses the link: keep the reason on screen.
|
|
1058
|
-
function onConnectEnd() {
|
|
1059
|
-
if (refusalShown.value) {
|
|
1060
|
-
toast.add({
|
|
1061
|
-
title: t('dms_automation.editor.canvas.connect.title'),
|
|
1062
|
-
description: refusal.value,
|
|
1063
|
-
color: 'warning',
|
|
1064
|
-
icon: 'i-ph-warning',
|
|
1065
|
-
})
|
|
1066
|
-
}
|
|
1067
|
-
refusal.value = ''
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
// Without a mouse: every link the selected step can make, from the canvas
|
|
1071
|
-
// toolbar (WCAG 2.5.7).
|
|
1072
|
-
|
|
1073
|
-
// Two steps with the same name are told apart by the end of their id (link
|
|
1074
|
-
// menu, replacement toast, links read aloud).
|
|
1075
|
-
function menuName(id: string): string {
|
|
1076
|
-
const name = nodeName(id)
|
|
1077
|
-
const twins = props.graph.nodes.filter((n) => nodeName(n.id) === name).length
|
|
1078
|
-
return twins > 1 ? `${name} #${id.slice(-4)}` : name
|
|
1079
|
-
}
|
|
1080
|
-
interface LinkItem {
|
|
1081
|
-
label: string
|
|
1082
|
-
connection: Connection
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
const linkGroups = computed(() => {
|
|
1086
|
-
const id = canvasSelection.value.length === 1 ? canvasSelection.value[0] : undefined
|
|
1087
|
-
const node = props.graph.nodes.find((n) => n.id === id)
|
|
1088
|
-
if (!node || props.readOnly) return []
|
|
1089
|
-
const mine = handlesOf(node)
|
|
1090
|
-
const next: LinkItem[] = []
|
|
1091
|
-
const send: LinkItem[] = []
|
|
1092
|
-
const read: LinkItem[] = []
|
|
1093
|
-
const wired = (target: string, field: string) =>
|
|
1094
|
-
props.graph.dataEdges.some((e) => e.to.node === target && e.to.field === field)
|
|
1095
|
-
const add = (into: LinkItem[], label: string, connection: Connection) => {
|
|
1096
|
-
if (check(props.graph, connection).ok) into.push({ label, connection })
|
|
1097
|
-
}
|
|
1098
|
-
for (const other of props.graph.nodes) {
|
|
1099
|
-
if (other.id === node.id) continue
|
|
1100
|
-
const theirs = handlesOf(other)
|
|
1101
|
-
const name = menuName(other.id)
|
|
1102
|
-
for (const out of mine.triggerOuts) {
|
|
1103
|
-
const current = props.graph.triggerEdges.find(
|
|
1104
|
-
(e) => e.from.node === node.id && (e.from.branch ?? 'main') === out.name,
|
|
1105
|
-
)
|
|
1106
|
-
if (current?.to.node === other.id) continue
|
|
1107
|
-
// The output already leads somewhere: the menu says what goes.
|
|
1108
|
-
const replaces = current ? ` (${t('dms_automation.editor.canvas.link.replaces', { name: menuName(current.to.node) })})` : ''
|
|
1109
|
-
for (const into of theirs.triggerIns) {
|
|
1110
|
-
const branch = out.name === 'main' ? '' : `${out.name} `
|
|
1111
|
-
const port = into.name && into.name !== 'main' ? ` · ${into.name}` : ''
|
|
1112
|
-
add(next, `${branch}→ ${name}${port}${replaces}`, { source: node.id, sourceHandle: out.id, target: other.id, targetHandle: into.id })
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
for (const out of mine.dataOuts) {
|
|
1116
|
-
for (const into of theirs.dataIns) {
|
|
1117
|
-
if (wired(other.id, into.name)) continue
|
|
1118
|
-
add(send, `${out.name} → ${name} · ${into.name}`, { source: node.id, sourceHandle: out.id, target: other.id, targetHandle: into.id })
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
for (const out of theirs.dataOuts) {
|
|
1122
|
-
for (const into of mine.dataIns) {
|
|
1123
|
-
if (wired(node.id, into.name)) continue
|
|
1124
|
-
add(read, `${name} · ${out.name} → ${into.name}`, { source: other.id, sourceHandle: out.id, target: node.id, targetHandle: into.id })
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
const group = (key: string, items: LinkItem[]) =>
|
|
1129
|
-
items.length ? [{ type: 'label' as const, label: t(`dms_automation.editor.canvas.link.${key}`) }, ...items] : []
|
|
1130
|
-
return [group('next', next), group('send', send), group('read', read)].filter((g) => g.length > 0)
|
|
106
|
+
const { linkGroups, canLink, linkChoice, onLink } = useLinkMenu({
|
|
107
|
+
props,
|
|
108
|
+
t,
|
|
109
|
+
canvasSelection,
|
|
110
|
+
check,
|
|
111
|
+
handlesOf,
|
|
112
|
+
menuName,
|
|
113
|
+
onConnect,
|
|
1131
114
|
})
|
|
1132
115
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
if (item?.connection) onConnect(item.connection)
|
|
1140
|
-
linkChoice.value = null
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// Multi-selection tracking — Vue Flow emits one NodeSelectionChange per
|
|
1144
|
-
// affected node when the user box-selects or shift-clicks. We accumulate
|
|
1145
|
-
// the current set here and emit a single `selection-change` event with
|
|
1146
|
-
// the full list (sentinels filtered out — the user shouldn't be able to
|
|
1147
|
-
// fold a sentinel into a new group). The single-node `select:node` event
|
|
1148
|
-
// is preserved for the inspector (it expects exactly one node id).
|
|
1149
|
-
const selectedNodeIds = new Set<string>()
|
|
1150
|
-
// The same set, reactive (sentinels included), for the toolbar's link menu
|
|
1151
|
-
// and the placement of new nodes.
|
|
1152
|
-
const canvasSelection = ref<string[]>([])
|
|
1153
|
-
|
|
1154
|
-
// Drop any tracked ids that no longer exist in the current graph (e.g.
|
|
1155
|
-
// after navigating to a different procedure / subgraph, or after the
|
|
1156
|
-
// "Group selection" action removes the selected nodes). Re-emit if the
|
|
1157
|
-
// set shrank. We can't `watch(() => props.graph, ...)` because that
|
|
1158
|
-
// fires on every node drag (each emitGraph returns a fresh object).
|
|
1159
|
-
watch(
|
|
1160
|
-
() => props.graph.nodes,
|
|
1161
|
-
(nodes) => {
|
|
1162
|
-
if (selectedNodeIds.size === 0) return
|
|
1163
|
-
const valid = new Set(nodes.map((n) => n.id))
|
|
1164
|
-
let pruned = false
|
|
1165
|
-
for (const id of [...selectedNodeIds]) {
|
|
1166
|
-
if (!valid.has(id)) {
|
|
1167
|
-
selectedNodeIds.delete(id)
|
|
1168
|
-
pruned = true
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
if (pruned) {
|
|
1172
|
-
const ids = [...selectedNodeIds].filter((id) => {
|
|
1173
|
-
const n = nodes.find((nn) => nn.id === id)
|
|
1174
|
-
return n ? !SENTINEL_KINDS.has(n.kind) : false
|
|
1175
|
-
})
|
|
1176
|
-
canvasSelection.value = [...selectedNodeIds]
|
|
1177
|
-
emit('selection-change', { ids })
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
)
|
|
1181
|
-
|
|
1182
|
-
function onNodesChange(changes: NodeChange[]) {
|
|
1183
|
-
let nextNodes = props.graph.nodes
|
|
1184
|
-
let nextTrigger = props.graph.triggerEdges
|
|
1185
|
-
let nextData = props.graph.dataEdges
|
|
1186
|
-
let changed = false
|
|
1187
|
-
let selectionChanged = false
|
|
1188
|
-
|
|
1189
|
-
for (const c of changes) {
|
|
1190
|
-
// In read-only mode, still surface selection so the inspector
|
|
1191
|
-
// can show node details; suppress position drag and delete.
|
|
1192
|
-
if (props.readOnly && c.type !== 'select') continue
|
|
1193
|
-
if (c.type === 'position' && c.position) {
|
|
1194
|
-
// Positions are stored as whole pixels, and a click that moves a
|
|
1195
|
-
// node by less than one (a select, not a drag) changes nothing:
|
|
1196
|
-
// otherwise selecting a node would count as an unsaved change.
|
|
1197
|
-
const pos = { x: Math.round(c.position.x), y: Math.round(c.position.y) }
|
|
1198
|
-
const current = nextNodes.find((n) => n.id === c.id)
|
|
1199
|
-
if (current && current.position.x === pos.x && current.position.y === pos.y) continue
|
|
1200
|
-
nextNodes = nextNodes.map((n) => (n.id === c.id ? { ...n, position: pos } : n))
|
|
1201
|
-
changed = true
|
|
1202
|
-
} else if (c.type === 'remove') {
|
|
1203
|
-
// Sentinel nodes (groupInput / groupOutput) are auto-managed by
|
|
1204
|
-
// the editor and never user-deletable. Drop the change silently
|
|
1205
|
-
// so keyboard delete + right-click delete both no-op on them.
|
|
1206
|
-
const victim = nextNodes.find((n) => n.id === c.id)
|
|
1207
|
-
if (victim && SENTINEL_KINDS.has(victim.kind)) continue
|
|
1208
|
-
nextNodes = nextNodes.filter((n) => n.id !== c.id)
|
|
1209
|
-
nextTrigger = nextTrigger.filter(
|
|
1210
|
-
(e) => e.from.node !== c.id && e.to.node !== c.id,
|
|
1211
|
-
)
|
|
1212
|
-
nextData = nextData.filter(
|
|
1213
|
-
(e) => e.from.node !== c.id && e.to.node !== c.id,
|
|
1214
|
-
)
|
|
1215
|
-
if (selectedNodeIds.delete(c.id)) selectionChanged = true
|
|
1216
|
-
changed = true
|
|
1217
|
-
} else if (c.type === 'select') {
|
|
1218
|
-
if (c.selected) {
|
|
1219
|
-
if (!selectedNodeIds.has(c.id)) {
|
|
1220
|
-
selectedNodeIds.add(c.id)
|
|
1221
|
-
selectionChanged = true
|
|
1222
|
-
}
|
|
1223
|
-
emit('select:node', c.id)
|
|
1224
|
-
} else {
|
|
1225
|
-
if (selectedNodeIds.delete(c.id)) selectionChanged = true
|
|
1226
|
-
// Re-point the single-node inspector on deselect: fall back to a
|
|
1227
|
-
// still-selected node (most-recent), or clear it once the
|
|
1228
|
-
// selection is empty. A click-swap fires `select: true` above in
|
|
1229
|
-
// the same batch, which then overrides this.
|
|
1230
|
-
const remaining = [...selectedNodeIds]
|
|
1231
|
-
emit('select:node', remaining[remaining.length - 1] ?? null)
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
if (selectionChanged) {
|
|
1237
|
-
// Filter out sentinels — folding them into a new group makes no
|
|
1238
|
-
// sense and the toolbar gating depends on a clean set.
|
|
1239
|
-
const ids = [...selectedNodeIds].filter((id) => {
|
|
1240
|
-
const n = props.graph.nodes.find((nn) => nn.id === id)
|
|
1241
|
-
return n ? !SENTINEL_KINDS.has(n.kind) : false
|
|
1242
|
-
})
|
|
1243
|
-
canvasSelection.value = [...selectedNodeIds]
|
|
1244
|
-
emit('selection-change', { ids })
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
if (changed) {
|
|
1248
|
-
emitGraph({
|
|
1249
|
-
...props.graph,
|
|
1250
|
-
nodes: nextNodes,
|
|
1251
|
-
triggerEdges: nextTrigger,
|
|
1252
|
-
dataEdges: nextData,
|
|
1253
|
-
})
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
// DmsFlowCanvas's delete affordance (trash badge on the selected node + the
|
|
1258
|
-
// Delete/Backspace key path it now owns) is emit-only: it hands us the ids and
|
|
1259
|
-
// we perform the mutation. Route them through onNodesChange's `remove` path so
|
|
1260
|
-
// sentinel filtering, edge cleanup, selection sync and emitGraph stay in one
|
|
1261
|
-
// place.
|
|
1262
|
-
function onDeleteNodes(ids: string[]) {
|
|
1263
|
-
if (props.readOnly) return
|
|
1264
|
-
onNodesChange(ids.map((id) => ({ type: 'remove', id }) as NodeChange))
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
function onEdgesChange(changes: EdgeChange[]) {
|
|
1268
|
-
if (props.readOnly) return
|
|
1269
|
-
let nextTrigger = props.graph.triggerEdges
|
|
1270
|
-
let nextData = props.graph.dataEdges
|
|
1271
|
-
let changed = false
|
|
1272
|
-
|
|
1273
|
-
for (const c of changes) {
|
|
1274
|
-
if (c.type === 'remove') {
|
|
1275
|
-
const beforeT = nextTrigger.length
|
|
1276
|
-
nextTrigger = nextTrigger.filter((e) => e.id !== c.id)
|
|
1277
|
-
if (nextTrigger.length !== beforeT) {
|
|
1278
|
-
changed = true
|
|
1279
|
-
continue
|
|
1280
|
-
}
|
|
1281
|
-
const beforeD = nextData.length
|
|
1282
|
-
nextData = nextData.filter((e) => e.id !== c.id)
|
|
1283
|
-
if (nextData.length !== beforeD) changed = true
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
if (changed) {
|
|
1288
|
-
emitGraph({
|
|
1289
|
-
...props.graph,
|
|
1290
|
-
triggerEdges: nextTrigger,
|
|
1291
|
-
dataEdges: nextData,
|
|
1292
|
-
})
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
// The DMS canvas deletes the selected nodes on Delete / Backspace, not the
|
|
1297
|
-
// selected links: remove those here (a deleted node takes its links along).
|
|
1298
|
-
function onKeydown(event: KeyboardEvent) {
|
|
1299
|
-
if (props.readOnly || (event.key !== 'Delete' && event.key !== 'Backspace')) return
|
|
1300
|
-
const target = event.target
|
|
1301
|
-
if (target instanceof HTMLElement && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName))) return
|
|
1302
|
-
const flow = flowRef.value
|
|
1303
|
-
if (!flow || flow.getSelectedNodes.length > 0 || flow.getSelectedEdges.length === 0) return
|
|
1304
|
-
event.preventDefault()
|
|
1305
|
-
onEdgesChange(flow.getSelectedEdges.map((e) => ({ type: 'remove', id: e.id }) as EdgeChange))
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
// Edge-update flow (drag an existing edge's endpoint to reattach or delete):
|
|
1309
|
-
// 1. @edge-update-start clears the success flag.
|
|
1310
|
-
// 2. @edge-update fires only if the user drops on a valid target — mark
|
|
1311
|
-
// successful and rewrite the edge with the new connection.
|
|
1312
|
-
// 3. @edge-update-end fires unconditionally; if no successful update
|
|
1313
|
-
// happened, the user dropped in empty space → delete the edge.
|
|
1314
|
-
let edgeUpdateSuccessful = false
|
|
1315
|
-
|
|
1316
|
-
function onEdgeUpdateStart() {
|
|
1317
|
-
edgeUpdateSuccessful = false
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
function onEdgeUpdate(payload: {
|
|
1321
|
-
event: MouseEvent
|
|
1322
|
-
edge: VfEdge
|
|
1323
|
-
connection: Connection
|
|
1324
|
-
}) {
|
|
1325
|
-
edgeUpdateSuccessful = true
|
|
1326
|
-
const { edge, connection } = payload
|
|
1327
|
-
const kind = (edge.data as { kind?: 'trigger' | 'data' } | undefined)?.kind
|
|
1328
|
-
if (kind === 'trigger') {
|
|
1329
|
-
const branch = parseSourceBranch(connection.sourceHandle)
|
|
1330
|
-
const toBranch = parseTargetBranch(connection.targetHandle)
|
|
1331
|
-
const nextTrigger = props.graph.triggerEdges.map((e) =>
|
|
1332
|
-
e.id === edge.id
|
|
1333
|
-
? {
|
|
1334
|
-
...e,
|
|
1335
|
-
from: { node: connection.source, branch },
|
|
1336
|
-
to: toBranch !== undefined
|
|
1337
|
-
? { node: connection.target, branch: toBranch }
|
|
1338
|
-
: { node: connection.target },
|
|
1339
|
-
}
|
|
1340
|
-
: e,
|
|
1341
|
-
)
|
|
1342
|
-
emitGraph({ ...props.graph, triggerEdges: nextTrigger })
|
|
1343
|
-
} else if (kind === 'data') {
|
|
1344
|
-
const port = parseDataPort(connection.sourceHandle)
|
|
1345
|
-
const field = parseDataField(connection.targetHandle)
|
|
1346
|
-
if (!port || !field) return
|
|
1347
|
-
const nextData = props.graph.dataEdges.map((e) =>
|
|
1348
|
-
e.id === edge.id
|
|
1349
|
-
? {
|
|
1350
|
-
...e,
|
|
1351
|
-
from: { node: connection.source, port },
|
|
1352
|
-
to: { node: connection.target, field },
|
|
1353
|
-
}
|
|
1354
|
-
: e,
|
|
1355
|
-
)
|
|
1356
|
-
emitGraph({ ...props.graph, dataEdges: nextData })
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
// Vue Flow fires @node-double-click with a single `{ event, node }` payload.
|
|
1361
|
-
// Filter to group nodes so Editor.vue receives a clean group:enter signal —
|
|
1362
|
-
// double-clicking any other node kind is reserved for future inline edit
|
|
1363
|
-
// affordances.
|
|
1364
|
-
function onNodeDoubleClick(payload: {
|
|
1365
|
-
event: MouseEvent
|
|
1366
|
-
node: { id: string; type?: string }
|
|
1367
|
-
}) {
|
|
1368
|
-
if (payload.node?.type !== 'group') return
|
|
1369
|
-
emit('group:enter', { id: payload.node.id })
|
|
1370
|
-
}
|
|
116
|
+
const { onNodesChange, onDeleteNodes } = useCanvasSelection({
|
|
117
|
+
props,
|
|
118
|
+
emit,
|
|
119
|
+
canvasSelection,
|
|
120
|
+
emitGraph,
|
|
121
|
+
})
|
|
1371
122
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
nextData.length === props.graph.dataEdges.length
|
|
1381
|
-
) {
|
|
1382
|
-
return
|
|
1383
|
-
}
|
|
1384
|
-
emitGraph({
|
|
1385
|
-
...props.graph,
|
|
1386
|
-
triggerEdges: nextTrigger,
|
|
1387
|
-
dataEdges: nextData,
|
|
1388
|
-
})
|
|
1389
|
-
}
|
|
123
|
+
const {
|
|
124
|
+
onEdgesChange,
|
|
125
|
+
onKeydown,
|
|
126
|
+
onEdgeUpdateStart,
|
|
127
|
+
onEdgeUpdate,
|
|
128
|
+
onNodeDoubleClick,
|
|
129
|
+
onEdgeUpdateEnd,
|
|
130
|
+
} = useEdgeEvents({ props, emit, flowRef, emitGraph })
|
|
1390
131
|
</script>
|
|
1391
132
|
|
|
1392
133
|
<template>
|