@stonecrop/node-editor 0.31.0 → 0.33.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/dist/assets/index.css +430 -0
- package/dist/node-editor.js +821 -644
- package/dist/node-editor.js.map +1 -1
- package/dist/src/components/EditableEdge.vue.d.ts +11 -0
- package/dist/src/components/EditableEdge.vue.d.ts.map +1 -0
- package/dist/src/components/EditableNode.vue.d.ts +10 -0
- package/dist/src/components/EditableNode.vue.d.ts.map +1 -0
- package/dist/src/components/NodeEditor.vue.d.ts +14 -0
- package/dist/src/components/NodeEditor.vue.d.ts.map +1 -0
- package/dist/src/components/SelfLoopEdge.vue.d.ts +11 -0
- package/dist/src/components/SelfLoopEdge.vue.d.ts.map +1 -0
- package/dist/src/components/StateEditor.vue.d.ts +69 -0
- package/dist/src/components/StateEditor.vue.d.ts.map +1 -0
- package/dist/{tsdoc-metadata.json → src/tsdoc-metadata.json} +1 -1
- package/package.json +35 -28
- package/dist/node-editor.css +0 -1
- package/dist/node-editor.d.ts +0 -60
- package/dist/node_editor.tsbuildinfo +0 -1
- package/dist/src/index.js +0 -16
- package/dist/src/types/index.js +0 -0
- package/dist/src/utils/autoLayout.js +0 -50
- package/dist/src/utils/stateTransforms.js +0 -148
- package/src/components/EditableEdge.vue +0 -92
- package/src/components/EditableNode.vue +0 -65
- package/src/components/NodeEditor.vue +0 -397
- package/src/components/SelfLoopEdge.vue +0 -88
- package/src/components/StateEditor.vue +0 -46
- package/src/index.ts +0 -22
- package/src/shims-vue.d.ts +0 -5
- package/src/types/index.ts +0 -33
- package/src/utils/autoLayout.ts +0 -67
- package/src/utils/stateTransforms.ts +0 -164
package/dist/node-editor.js
CHANGED
|
@@ -1,651 +1,828 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
sourceX: {},
|
|
205
|
-
sourceY: {},
|
|
206
|
-
targetX: {},
|
|
207
|
-
targetY: {}
|
|
208
|
-
},
|
|
209
|
-
emits: ["change", "remove"],
|
|
210
|
-
setup(l, { emit: f }) {
|
|
211
|
-
const d = l, p = f, n = 90, u = 45, t = M(() => {
|
|
212
|
-
const { sourceX: h, sourceY: k, targetX: $, targetY: L } = d, j = `M ${h},${k} C ${h + u},${k - n} ${$ - u},${L - n} ${$},${L}`, z = (h + $) / 2, V = Math.min(k, L) - n * 0.72;
|
|
213
|
-
return { d: j, labelX: z, labelY: V };
|
|
214
|
-
}), e = Y("labelInput"), a = E(""), s = E(!1);
|
|
215
|
-
let g = 0;
|
|
216
|
-
const m = async () => {
|
|
217
|
-
let h = Date.now();
|
|
218
|
-
h - g < 500 && !s.value && await v(), g = h;
|
|
219
|
-
}, v = async () => {
|
|
220
|
-
a.value = d.label, s.value = !0, await I(), e.value?.focus();
|
|
221
|
-
}, y = () => {
|
|
222
|
-
s.value = !1, p("change", a.value);
|
|
223
|
-
};
|
|
224
|
-
return (h, k) => (S(), P(Q, null, [
|
|
225
|
-
c("path", {
|
|
226
|
-
d: t.value.d,
|
|
227
|
-
fill: "none",
|
|
228
|
-
stroke: "transparent",
|
|
229
|
-
"stroke-width": "20",
|
|
230
|
-
class: "vue-flow__edge-interaction"
|
|
231
|
-
}, null, 8, Ce),
|
|
232
|
-
c("path", {
|
|
233
|
-
id: l.id,
|
|
234
|
-
style: K(l.style),
|
|
235
|
-
class: "vue-flow__edge-path",
|
|
236
|
-
d: t.value.d,
|
|
237
|
-
"marker-end": l.markerEnd
|
|
238
|
-
}, null, 12, Ee),
|
|
239
|
-
O(_(ee), null, {
|
|
240
|
-
default: R(() => [
|
|
241
|
-
c("div", {
|
|
242
|
-
style: K({
|
|
243
|
-
pointerEvents: "all",
|
|
244
|
-
position: "absolute",
|
|
245
|
-
transform: `translate(-50%, -50%) translate(${t.value.labelX}px,${t.value.labelY}px)`
|
|
246
|
-
}),
|
|
247
|
-
class: "nodrag nopan editable-edge-label",
|
|
248
|
-
onClick: k[2] || (k[2] = ($) => m()),
|
|
249
|
-
onContextmenu: k[3] || (k[3] = D(($) => h.$emit("remove", l.id), ["prevent"]))
|
|
250
|
-
}, [
|
|
251
|
-
c("div", Pe, F(l.label), 1),
|
|
252
|
-
s.value ? (S(), P("div", Ne, [
|
|
253
|
-
X(c("input", {
|
|
254
|
-
ref: "labelInput",
|
|
255
|
-
"onUpdate:modelValue": k[0] || (k[0] = ($) => a.value = $),
|
|
256
|
-
class: "label-input",
|
|
257
|
-
onBlur: k[1] || (k[1] = ($) => s.value = !1),
|
|
258
|
-
onKeypress: W(y, ["enter"])
|
|
259
|
-
}, null, 544), [
|
|
260
|
-
[U, a.value]
|
|
261
|
-
])
|
|
262
|
-
])) : B("", !0)
|
|
263
|
-
], 36)
|
|
264
|
-
]),
|
|
265
|
-
_: 1
|
|
266
|
-
})
|
|
267
|
-
], 64));
|
|
268
|
-
}
|
|
1
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, toDisplayString, unref, useModel, useTemplateRef, vModelText, withCtx, withDirectives, withKeys, withModifiers } from "vue";
|
|
2
|
+
import { EdgeLabelRenderer, Handle, Position, Position as Position$1, VueFlow, getBezierPath, useVueFlow } from "@vue-flow/core";
|
|
3
|
+
import { Graph, layout } from "@dagrejs/dagre";
|
|
4
|
+
import './assets/index.css';//#region src/components/EditableEdge.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
+
var _hoisted_1$3 = ["d"];
|
|
6
|
+
var _hoisted_2$2 = [
|
|
7
|
+
"id",
|
|
8
|
+
"d",
|
|
9
|
+
"marker-end"
|
|
10
|
+
];
|
|
11
|
+
var _hoisted_3$2 = { class: "vue-flow__edge-label" };
|
|
12
|
+
var _hoisted_4$2 = {
|
|
13
|
+
key: 0,
|
|
14
|
+
class: "label-input-wrapper"
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/components/EditableEdge.vue
|
|
18
|
+
var EditableEdge_default = /* @__PURE__ */ defineComponent({
|
|
19
|
+
inheritAttrs: false,
|
|
20
|
+
__name: "EditableEdge",
|
|
21
|
+
props: {
|
|
22
|
+
id: {},
|
|
23
|
+
sourceNode: {},
|
|
24
|
+
targetNode: {},
|
|
25
|
+
source: {},
|
|
26
|
+
target: {},
|
|
27
|
+
type: {},
|
|
28
|
+
label: { type: [
|
|
29
|
+
String,
|
|
30
|
+
Object,
|
|
31
|
+
Function
|
|
32
|
+
] },
|
|
33
|
+
style: {},
|
|
34
|
+
selected: { type: Boolean },
|
|
35
|
+
sourcePosition: {},
|
|
36
|
+
targetPosition: {},
|
|
37
|
+
sourceHandleId: {},
|
|
38
|
+
targetHandleId: {},
|
|
39
|
+
animated: { type: Boolean },
|
|
40
|
+
updatable: { type: Boolean },
|
|
41
|
+
markerStart: {},
|
|
42
|
+
markerEnd: {},
|
|
43
|
+
curvature: {},
|
|
44
|
+
interactionWidth: {},
|
|
45
|
+
data: {},
|
|
46
|
+
events: {},
|
|
47
|
+
labelStyle: {},
|
|
48
|
+
labelShowBg: { type: Boolean },
|
|
49
|
+
labelBgStyle: {},
|
|
50
|
+
labelBgPadding: {},
|
|
51
|
+
labelBgBorderRadius: {},
|
|
52
|
+
sourceX: {},
|
|
53
|
+
sourceY: {},
|
|
54
|
+
targetX: {},
|
|
55
|
+
targetY: {}
|
|
56
|
+
},
|
|
57
|
+
emits: ["change", "remove"],
|
|
58
|
+
setup(__props, { emit: __emit }) {
|
|
59
|
+
const props = __props;
|
|
60
|
+
const emit = __emit;
|
|
61
|
+
const inputRef = useTemplateRef("labelInput");
|
|
62
|
+
const newLabel = ref("");
|
|
63
|
+
const showInput = ref(false);
|
|
64
|
+
let lastClick = 0;
|
|
65
|
+
const labelOnClick = async () => {
|
|
66
|
+
let now = Date.now();
|
|
67
|
+
if (now - lastClick < 500 && !showInput.value) await showLabelInput();
|
|
68
|
+
lastClick = now;
|
|
69
|
+
};
|
|
70
|
+
const showLabelInput = async () => {
|
|
71
|
+
newLabel.value = props.label;
|
|
72
|
+
showInput.value = true;
|
|
73
|
+
await nextTick();
|
|
74
|
+
inputRef.value?.focus();
|
|
75
|
+
};
|
|
76
|
+
const submitNewLabel = () => {
|
|
77
|
+
showInput.value = false;
|
|
78
|
+
emit("change", newLabel.value);
|
|
79
|
+
};
|
|
80
|
+
const path = computed(() => getBezierPath(props));
|
|
81
|
+
return (_ctx, _cache) => {
|
|
82
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
83
|
+
createElementVNode("path", {
|
|
84
|
+
d: path.value[0],
|
|
85
|
+
fill: "none",
|
|
86
|
+
stroke: "transparent",
|
|
87
|
+
"stroke-width": "20",
|
|
88
|
+
class: "vue-flow__edge-interaction"
|
|
89
|
+
}, null, 8, _hoisted_1$3),
|
|
90
|
+
createElementVNode("path", {
|
|
91
|
+
id: __props.id,
|
|
92
|
+
style: normalizeStyle(__props.style),
|
|
93
|
+
class: "vue-flow__edge-path",
|
|
94
|
+
d: path.value[0],
|
|
95
|
+
"marker-end": __props.markerEnd
|
|
96
|
+
}, null, 12, _hoisted_2$2),
|
|
97
|
+
createVNode(unref(EdgeLabelRenderer), null, {
|
|
98
|
+
default: withCtx(() => [createElementVNode("div", {
|
|
99
|
+
style: normalizeStyle({
|
|
100
|
+
pointerEvents: "all",
|
|
101
|
+
position: "absolute",
|
|
102
|
+
transform: `translate(-50%, -50%) translate(${path.value[1]}px,${path.value[2]}px)`
|
|
103
|
+
}),
|
|
104
|
+
class: "nodrag nopan editable-edge-label",
|
|
105
|
+
onClick: _cache[2] || (_cache[2] = ($event) => labelOnClick()),
|
|
106
|
+
onContextmenu: _cache[3] || (_cache[3] = withModifiers(($event) => _ctx.$emit("remove", __props.id), ["prevent"]))
|
|
107
|
+
}, [createElementVNode("div", _hoisted_3$2, toDisplayString(__props.label), 1), showInput.value ? (openBlock(), createElementBlock("div", _hoisted_4$2, [withDirectives(createElementVNode("input", {
|
|
108
|
+
ref: "labelInput",
|
|
109
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => newLabel.value = $event),
|
|
110
|
+
class: "label-input",
|
|
111
|
+
onBlur: _cache[1] || (_cache[1] = ($event) => showInput.value = false),
|
|
112
|
+
onKeypress: withKeys(submitNewLabel, ["enter"])
|
|
113
|
+
}, null, 544), [[vModelText, newLabel.value]])])) : createCommentVNode("", true)], 36)]),
|
|
114
|
+
_: 1
|
|
115
|
+
})
|
|
116
|
+
], 64);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/components/EditableNode.vue?vue&type=script&setup=true&lang.ts
|
|
122
|
+
var _hoisted_1$2 = {
|
|
123
|
+
key: 0,
|
|
124
|
+
class: "label-input-wrapper"
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/components/EditableNode.vue
|
|
128
|
+
var EditableNode_default = /* @__PURE__ */ defineComponent({
|
|
129
|
+
__name: "EditableNode",
|
|
130
|
+
props: {
|
|
131
|
+
id: {},
|
|
132
|
+
type: {},
|
|
133
|
+
selected: { type: Boolean },
|
|
134
|
+
connectable: { type: [
|
|
135
|
+
Boolean,
|
|
136
|
+
Number,
|
|
137
|
+
String,
|
|
138
|
+
Function
|
|
139
|
+
] },
|
|
140
|
+
position: {},
|
|
141
|
+
dimensions: {},
|
|
142
|
+
label: {},
|
|
143
|
+
isValidTargetPos: { type: Function },
|
|
144
|
+
isValidSourcePos: { type: Function },
|
|
145
|
+
parent: {},
|
|
146
|
+
parentNodeId: {},
|
|
147
|
+
dragging: { type: Boolean },
|
|
148
|
+
resizing: { type: Boolean },
|
|
149
|
+
zIndex: {},
|
|
150
|
+
targetPosition: {},
|
|
151
|
+
sourcePosition: {},
|
|
152
|
+
dragHandle: {},
|
|
153
|
+
data: {},
|
|
154
|
+
events: {}
|
|
155
|
+
},
|
|
156
|
+
emits: ["change"],
|
|
157
|
+
setup(__props, { emit: __emit }) {
|
|
158
|
+
const props = __props;
|
|
159
|
+
const emit = __emit;
|
|
160
|
+
const inputRef = useTemplateRef("labelInput");
|
|
161
|
+
const newLabel = ref("");
|
|
162
|
+
const showInput = ref(false);
|
|
163
|
+
let lastClick = 0;
|
|
164
|
+
const nodeOnClick = async () => {
|
|
165
|
+
let now = Date.now();
|
|
166
|
+
if (now - lastClick < 500 && !showInput.value) await showLabelInput();
|
|
167
|
+
lastClick = now;
|
|
168
|
+
};
|
|
169
|
+
const showLabelInput = async () => {
|
|
170
|
+
newLabel.value = props.label;
|
|
171
|
+
showInput.value = true;
|
|
172
|
+
await nextTick();
|
|
173
|
+
inputRef.value?.focus();
|
|
174
|
+
};
|
|
175
|
+
const submitNewLabel = () => {
|
|
176
|
+
showInput.value = false;
|
|
177
|
+
emit("change", newLabel.value);
|
|
178
|
+
};
|
|
179
|
+
return (_ctx, _cache) => {
|
|
180
|
+
return openBlock(), createElementBlock("div", { onClick: _cache[2] || (_cache[2] = ($event) => nodeOnClick()) }, [
|
|
181
|
+
createElementVNode("div", null, toDisplayString(__props.label), 1),
|
|
182
|
+
showInput.value ? (openBlock(), createElementBlock("div", _hoisted_1$2, [withDirectives(createElementVNode("input", {
|
|
183
|
+
ref: "labelInput",
|
|
184
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => newLabel.value = $event),
|
|
185
|
+
class: "label-input",
|
|
186
|
+
onBlur: _cache[1] || (_cache[1] = ($event) => showInput.value = false),
|
|
187
|
+
onKeypress: withKeys(submitNewLabel, ["enter"])
|
|
188
|
+
}, null, 544), [[vModelText, newLabel.value]])])) : createCommentVNode("", true),
|
|
189
|
+
__props.data.hasInput ? (openBlock(), createBlock(unref(Handle), {
|
|
190
|
+
key: 1,
|
|
191
|
+
id: "a",
|
|
192
|
+
type: "target",
|
|
193
|
+
position: __props.targetPosition
|
|
194
|
+
}, null, 8, ["position"])) : createCommentVNode("", true),
|
|
195
|
+
__props.data.hasOutput ? (openBlock(), createBlock(unref(Handle), {
|
|
196
|
+
key: 2,
|
|
197
|
+
id: "b",
|
|
198
|
+
type: "source",
|
|
199
|
+
position: __props.sourcePosition
|
|
200
|
+
}, null, 8, ["position"])) : createCommentVNode("", true)
|
|
201
|
+
]);
|
|
202
|
+
};
|
|
203
|
+
}
|
|
269
204
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/components/SelfLoopEdge.vue?vue&type=script&setup=true&lang.ts
|
|
207
|
+
var _hoisted_1$1 = ["d"];
|
|
208
|
+
var _hoisted_2$1 = [
|
|
209
|
+
"id",
|
|
210
|
+
"d",
|
|
211
|
+
"marker-end"
|
|
212
|
+
];
|
|
213
|
+
var _hoisted_3$1 = { class: "vue-flow__edge-label" };
|
|
214
|
+
var _hoisted_4$1 = {
|
|
215
|
+
key: 0,
|
|
216
|
+
class: "label-input-wrapper"
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/components/SelfLoopEdge.vue
|
|
220
|
+
var SelfLoopEdge_default = /* @__PURE__ */ defineComponent({
|
|
221
|
+
inheritAttrs: false,
|
|
222
|
+
__name: "SelfLoopEdge",
|
|
223
|
+
props: {
|
|
224
|
+
id: {},
|
|
225
|
+
sourceNode: {},
|
|
226
|
+
targetNode: {},
|
|
227
|
+
source: {},
|
|
228
|
+
target: {},
|
|
229
|
+
type: {},
|
|
230
|
+
label: { type: [
|
|
231
|
+
String,
|
|
232
|
+
Object,
|
|
233
|
+
Function
|
|
234
|
+
] },
|
|
235
|
+
style: {},
|
|
236
|
+
selected: { type: Boolean },
|
|
237
|
+
sourcePosition: {},
|
|
238
|
+
targetPosition: {},
|
|
239
|
+
sourceHandleId: {},
|
|
240
|
+
targetHandleId: {},
|
|
241
|
+
animated: { type: Boolean },
|
|
242
|
+
updatable: { type: Boolean },
|
|
243
|
+
markerStart: {},
|
|
244
|
+
markerEnd: {},
|
|
245
|
+
curvature: {},
|
|
246
|
+
interactionWidth: {},
|
|
247
|
+
data: {},
|
|
248
|
+
events: {},
|
|
249
|
+
labelStyle: {},
|
|
250
|
+
labelShowBg: { type: Boolean },
|
|
251
|
+
labelBgStyle: {},
|
|
252
|
+
labelBgPadding: {},
|
|
253
|
+
labelBgBorderRadius: {},
|
|
254
|
+
sourceX: {},
|
|
255
|
+
sourceY: {},
|
|
256
|
+
targetX: {},
|
|
257
|
+
targetY: {}
|
|
258
|
+
},
|
|
259
|
+
emits: ["change", "remove"],
|
|
260
|
+
setup(__props, { emit: __emit }) {
|
|
261
|
+
const props = __props;
|
|
262
|
+
const emit = __emit;
|
|
263
|
+
const LOOP_HEIGHT = 90;
|
|
264
|
+
const LOOP_SPREAD = 45;
|
|
265
|
+
const path = computed(() => {
|
|
266
|
+
const { sourceX, sourceY, targetX, targetY } = props;
|
|
267
|
+
return {
|
|
268
|
+
d: `M ${sourceX},${sourceY} C ${sourceX + LOOP_SPREAD},${sourceY - LOOP_HEIGHT} ${targetX - LOOP_SPREAD},${targetY - LOOP_HEIGHT} ${targetX},${targetY}`,
|
|
269
|
+
labelX: (sourceX + targetX) / 2,
|
|
270
|
+
labelY: Math.min(sourceY, targetY) - LOOP_HEIGHT * .72
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
const inputRef = useTemplateRef("labelInput");
|
|
274
|
+
const newLabel = ref("");
|
|
275
|
+
const showInput = ref(false);
|
|
276
|
+
let lastClick = 0;
|
|
277
|
+
const labelOnClick = async () => {
|
|
278
|
+
let now = Date.now();
|
|
279
|
+
if (now - lastClick < 500 && !showInput.value) await showLabelInput();
|
|
280
|
+
lastClick = now;
|
|
281
|
+
};
|
|
282
|
+
const showLabelInput = async () => {
|
|
283
|
+
newLabel.value = props.label;
|
|
284
|
+
showInput.value = true;
|
|
285
|
+
await nextTick();
|
|
286
|
+
inputRef.value?.focus();
|
|
287
|
+
};
|
|
288
|
+
const submitNewLabel = () => {
|
|
289
|
+
showInput.value = false;
|
|
290
|
+
emit("change", newLabel.value);
|
|
291
|
+
};
|
|
292
|
+
return (_ctx, _cache) => {
|
|
293
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
294
|
+
createElementVNode("path", {
|
|
295
|
+
d: path.value.d,
|
|
296
|
+
fill: "none",
|
|
297
|
+
stroke: "transparent",
|
|
298
|
+
"stroke-width": "20",
|
|
299
|
+
class: "vue-flow__edge-interaction"
|
|
300
|
+
}, null, 8, _hoisted_1$1),
|
|
301
|
+
createElementVNode("path", {
|
|
302
|
+
id: __props.id,
|
|
303
|
+
style: normalizeStyle(__props.style),
|
|
304
|
+
class: "vue-flow__edge-path",
|
|
305
|
+
d: path.value.d,
|
|
306
|
+
"marker-end": __props.markerEnd
|
|
307
|
+
}, null, 12, _hoisted_2$1),
|
|
308
|
+
createVNode(unref(EdgeLabelRenderer), null, {
|
|
309
|
+
default: withCtx(() => [createElementVNode("div", {
|
|
310
|
+
style: normalizeStyle({
|
|
311
|
+
pointerEvents: "all",
|
|
312
|
+
position: "absolute",
|
|
313
|
+
transform: `translate(-50%, -50%) translate(${path.value.labelX}px,${path.value.labelY}px)`
|
|
314
|
+
}),
|
|
315
|
+
class: "nodrag nopan editable-edge-label",
|
|
316
|
+
onClick: _cache[2] || (_cache[2] = ($event) => labelOnClick()),
|
|
317
|
+
onContextmenu: _cache[3] || (_cache[3] = withModifiers(($event) => _ctx.$emit("remove", __props.id), ["prevent"]))
|
|
318
|
+
}, [createElementVNode("div", _hoisted_3$1, toDisplayString(__props.label), 1), showInput.value ? (openBlock(), createElementBlock("div", _hoisted_4$1, [withDirectives(createElementVNode("input", {
|
|
319
|
+
ref: "labelInput",
|
|
320
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => newLabel.value = $event),
|
|
321
|
+
class: "label-input",
|
|
322
|
+
onBlur: _cache[1] || (_cache[1] = ($event) => showInput.value = false),
|
|
323
|
+
onKeypress: withKeys(submitNewLabel, ["enter"])
|
|
324
|
+
}, null, 544), [[vModelText, newLabel.value]])])) : createCommentVNode("", true)], 36)]),
|
|
325
|
+
_: 1
|
|
326
|
+
})
|
|
327
|
+
], 64);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/utils/autoLayout.ts
|
|
333
|
+
/**
|
|
334
|
+
* Compute node positions for a workflow graph with dagre's layered (Sugiyama) algorithm.
|
|
335
|
+
*
|
|
336
|
+
* Pure and synchronous: takes VueFlow elements (nodes + edges) and returns a new elements array with
|
|
337
|
+
* each node's `position` replaced by a laid-out coordinate; edges and every other node field are
|
|
338
|
+
* passed through untouched. Used two ways — as the seed for an un-arranged workflow (fixed default
|
|
339
|
+
* dimensions, no DOM) and behind the toolbar button (measured `dimensions`).
|
|
340
|
+
*
|
|
341
|
+
* Self-loop edges (`source === target`) are skipped: dagre doesn't rank them, and they're reserved
|
|
342
|
+
* for the separate mutate-in-place self-transition feature.
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
function autoLayout(elements, options = {}) {
|
|
346
|
+
const { rankdir = "LR", nodeWidth = 160, nodeHeight = 40, dimensions } = options;
|
|
347
|
+
const sizeOf = (id) => dimensions?.[id] ?? {
|
|
348
|
+
width: nodeWidth,
|
|
349
|
+
height: nodeHeight
|
|
350
|
+
};
|
|
351
|
+
const nodeIds = [];
|
|
352
|
+
for (const el of elements) if (!("source" in el)) nodeIds.push(el.id);
|
|
353
|
+
if (nodeIds.length === 0) return [...elements];
|
|
354
|
+
const graph = new Graph();
|
|
355
|
+
graph.setGraph({
|
|
356
|
+
rankdir,
|
|
357
|
+
nodesep: 40,
|
|
358
|
+
ranksep: 80,
|
|
359
|
+
edgesep: 20
|
|
360
|
+
});
|
|
361
|
+
graph.setDefaultEdgeLabel(() => ({}));
|
|
362
|
+
for (const id of nodeIds) {
|
|
363
|
+
const { width, height } = sizeOf(id);
|
|
364
|
+
graph.setNode(id, {
|
|
365
|
+
width,
|
|
366
|
+
height
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
for (const el of elements) {
|
|
370
|
+
if (!("source" in el)) continue;
|
|
371
|
+
if (el.source === el.target) continue;
|
|
372
|
+
graph.setEdge(el.source, el.target);
|
|
373
|
+
}
|
|
374
|
+
layout(graph);
|
|
375
|
+
return elements.map((el) => {
|
|
376
|
+
if ("source" in el) return el;
|
|
377
|
+
const center = graph.node(el.id);
|
|
378
|
+
if (!center) return el;
|
|
379
|
+
const { width, height } = sizeOf(el.id);
|
|
380
|
+
return {
|
|
381
|
+
...el,
|
|
382
|
+
position: {
|
|
383
|
+
x: center.x - width / 2,
|
|
384
|
+
y: center.y - height / 2
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
});
|
|
290
388
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/components/NodeEditor.vue?vue&type=script&setup=true&lang.ts
|
|
391
|
+
var _hoisted_1 = { class: "chart-controls" };
|
|
392
|
+
var _hoisted_2 = { class: "chart-controls-left" };
|
|
393
|
+
var _hoisted_3 = { class: "chart-controls-right" };
|
|
394
|
+
var _hoisted_4 = { key: 0 };
|
|
395
|
+
var _hoisted_5 = { key: 1 };
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/components/NodeEditor.vue
|
|
398
|
+
var NodeEditor_default = /* @__PURE__ */ defineComponent({
|
|
399
|
+
__name: "NodeEditor",
|
|
400
|
+
props: {
|
|
401
|
+
modelValue: {},
|
|
402
|
+
nodeContainerClass: {
|
|
403
|
+
type: [
|
|
404
|
+
Boolean,
|
|
405
|
+
null,
|
|
406
|
+
String,
|
|
407
|
+
Object,
|
|
408
|
+
Array
|
|
409
|
+
],
|
|
410
|
+
default: ""
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
emits: ["update:modelValue"],
|
|
414
|
+
setup(__props, { emit: __emit }) {
|
|
415
|
+
const emit = __emit;
|
|
416
|
+
const hover = ref(false);
|
|
417
|
+
const vueFlowElements = ref([]);
|
|
418
|
+
const vueFlowInstance = ref();
|
|
419
|
+
const activeElementKey = ref("");
|
|
420
|
+
const activeElementIndex = computed(() => vueFlowElements.value.findIndex((element) => element.id === activeElementKey.value));
|
|
421
|
+
const elements = computed({
|
|
422
|
+
get: () => {
|
|
423
|
+
const items = __props.modelValue;
|
|
424
|
+
for (const element of items) {
|
|
425
|
+
element.data = { ...element.data };
|
|
426
|
+
if (element.type === "input") {
|
|
427
|
+
element.data.hasInput = false;
|
|
428
|
+
element.data.hasOutput = true;
|
|
429
|
+
} else if (element.type === "output") {
|
|
430
|
+
element.data.hasInput = true;
|
|
431
|
+
element.data.hasOutput = false;
|
|
432
|
+
} else {
|
|
433
|
+
element.data.hasInput = true;
|
|
434
|
+
element.data.hasOutput = true;
|
|
435
|
+
}
|
|
436
|
+
element.class = "vue-flow__node-default";
|
|
437
|
+
element.type = "source" in element && element.source === element.target ? "selfloop" : "editable";
|
|
438
|
+
}
|
|
439
|
+
return items;
|
|
440
|
+
},
|
|
441
|
+
set: (newValue) => {
|
|
442
|
+
emit("update:modelValue", JSON.parse(JSON.stringify(newValue)));
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
const { addEdges, removeEdges } = useVueFlow();
|
|
446
|
+
onMounted(() => {
|
|
447
|
+
document.removeEventListener("keypress", handleKeypress);
|
|
448
|
+
document.addEventListener("keypress", handleKeypress);
|
|
449
|
+
});
|
|
450
|
+
onBeforeUnmount(() => {
|
|
451
|
+
document.removeEventListener("keypress", handleKeypress);
|
|
452
|
+
});
|
|
453
|
+
const setInstance = (instance) => {
|
|
454
|
+
vueFlowInstance.value = instance;
|
|
455
|
+
};
|
|
456
|
+
vueFlowElements.value = elements.value;
|
|
457
|
+
const shiftTerminal = (currentTerminal) => {
|
|
458
|
+
return {
|
|
459
|
+
[Position$1.Top]: Position$1.Right,
|
|
460
|
+
[Position$1.Right]: Position$1.Bottom,
|
|
461
|
+
[Position$1.Bottom]: Position$1.Left,
|
|
462
|
+
[Position$1.Left]: Position$1.Top
|
|
463
|
+
}[currentTerminal];
|
|
464
|
+
};
|
|
465
|
+
const shiftOutput = () => {
|
|
466
|
+
if (activeElementIndex.value > -1) {
|
|
467
|
+
const activeNode = vueFlowElements.value[activeElementIndex.value];
|
|
468
|
+
if (!activeNode.sourcePosition) return;
|
|
469
|
+
activeNode.sourcePosition = shiftTerminal(activeNode.sourcePosition);
|
|
470
|
+
emitElements();
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
const shiftInput = () => {
|
|
474
|
+
if (activeElementIndex.value > -1) {
|
|
475
|
+
const activeNode = vueFlowElements.value[activeElementIndex.value];
|
|
476
|
+
if (!activeNode.targetPosition) return;
|
|
477
|
+
activeNode.targetPosition = shiftTerminal(activeNode.targetPosition);
|
|
478
|
+
emitElements();
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
const onWheel = (event) => {
|
|
482
|
+
window.scrollBy(0, event.deltaY);
|
|
483
|
+
};
|
|
484
|
+
const handleKeypress = (event) => {
|
|
485
|
+
if (hover.value && event.ctrlKey == true) {
|
|
486
|
+
if (event.key == "+" || event.key == "=") vueFlowInstance.value?.zoomIn();
|
|
487
|
+
if (event.key == "-") vueFlowInstance.value?.zoomOut();
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const fitView = async () => {
|
|
491
|
+
await vueFlowInstance.value?.fitView();
|
|
492
|
+
};
|
|
493
|
+
const autoArrange = async () => {
|
|
494
|
+
const store = vueFlowInstance.value;
|
|
495
|
+
const dimensions = {};
|
|
496
|
+
for (const el of vueFlowElements.value) {
|
|
497
|
+
if ("source" in el) continue;
|
|
498
|
+
const dims = store?.findNode?.(el.id)?.dimensions;
|
|
499
|
+
if (dims?.width && dims?.height) dimensions[el.id] = {
|
|
500
|
+
width: dims.width,
|
|
501
|
+
height: dims.height
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
const laid = autoLayout(vueFlowElements.value, { dimensions });
|
|
505
|
+
const positionById = /* @__PURE__ */ new Map();
|
|
506
|
+
for (const el of laid) {
|
|
507
|
+
if ("source" in el) continue;
|
|
508
|
+
positionById.set(el.id, el.position);
|
|
509
|
+
}
|
|
510
|
+
for (const el of vueFlowElements.value) {
|
|
511
|
+
if ("source" in el) continue;
|
|
512
|
+
const position = positionById.get(el.id);
|
|
513
|
+
if (position) el.position = position;
|
|
514
|
+
}
|
|
515
|
+
emitElements();
|
|
516
|
+
await nextTick();
|
|
517
|
+
await fitView();
|
|
518
|
+
};
|
|
519
|
+
const addNode = () => {
|
|
520
|
+
let makeEdge = false;
|
|
521
|
+
let newNodePosition = {
|
|
522
|
+
x: Math.random() * 200,
|
|
523
|
+
y: Math.random() * 200
|
|
524
|
+
};
|
|
525
|
+
if (activeElementIndex.value > -1) {
|
|
526
|
+
const activeNode = vueFlowElements.value[activeElementIndex.value];
|
|
527
|
+
if (activeNode.data?.hasOutput) {
|
|
528
|
+
newNodePosition = {
|
|
529
|
+
x: activeNode.position.x + 200,
|
|
530
|
+
y: activeNode.position.y + 50
|
|
531
|
+
};
|
|
532
|
+
makeEdge = true;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const id = vueFlowElements.value.length;
|
|
536
|
+
const nodeId = `node-${id}`;
|
|
537
|
+
vueFlowElements.value.push({
|
|
538
|
+
id: nodeId,
|
|
539
|
+
label: "Node " + id,
|
|
540
|
+
sourcePosition: Position$1.Right,
|
|
541
|
+
targetPosition: Position$1.Left,
|
|
542
|
+
class: "vue-flow__node-default",
|
|
543
|
+
type: "editable",
|
|
544
|
+
data: {
|
|
545
|
+
hasInput: true,
|
|
546
|
+
hasOutput: true
|
|
547
|
+
},
|
|
548
|
+
position: newNodePosition
|
|
549
|
+
});
|
|
550
|
+
if (makeEdge) {
|
|
551
|
+
const edgeId = `edge-${id + 1}`;
|
|
552
|
+
vueFlowElements.value.push({
|
|
553
|
+
id: edgeId,
|
|
554
|
+
source: activeElementKey.value,
|
|
555
|
+
target: nodeId,
|
|
556
|
+
type: "editable",
|
|
557
|
+
label: `EDGE ${id + 1}`,
|
|
558
|
+
animated: true
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
emitElements();
|
|
562
|
+
};
|
|
563
|
+
const labelChanged = (event, id) => {
|
|
564
|
+
for (let j = 0; j < vueFlowElements.value.length; j++) if (vueFlowElements.value[j].id == id) {
|
|
565
|
+
vueFlowElements.value[j].label = event;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
emitElements();
|
|
569
|
+
};
|
|
570
|
+
const handleNodeClick = ({ node }) => {
|
|
571
|
+
activeElementKey.value = node.id;
|
|
572
|
+
};
|
|
573
|
+
const handleEdgeClick = ({ edge }) => {
|
|
574
|
+
activeElementKey.value = edge.id;
|
|
575
|
+
};
|
|
576
|
+
const handleConnect = async (event) => {
|
|
577
|
+
const id = vueFlowElements.value.length;
|
|
578
|
+
const isSelfLoop = event.source === event.target;
|
|
579
|
+
const newEdge = {
|
|
580
|
+
id: `edge-${id}`,
|
|
581
|
+
source: event.source,
|
|
582
|
+
target: event.target,
|
|
583
|
+
type: isSelfLoop ? "selfloop" : "editable",
|
|
584
|
+
label: `New Edge`,
|
|
585
|
+
interactionWidth: 400,
|
|
586
|
+
animated: true
|
|
587
|
+
};
|
|
588
|
+
addEdges([newEdge]);
|
|
589
|
+
await nextTick();
|
|
590
|
+
emitElements();
|
|
591
|
+
};
|
|
592
|
+
const handleEdgeContextMenu = async (event) => {
|
|
593
|
+
removeEdges([event.edge.id]);
|
|
594
|
+
await nextTick();
|
|
595
|
+
emitElements();
|
|
596
|
+
};
|
|
597
|
+
const removeEdge = async (id) => {
|
|
598
|
+
removeEdges([id]);
|
|
599
|
+
await nextTick();
|
|
600
|
+
emitElements();
|
|
601
|
+
};
|
|
602
|
+
const emitElements = () => {
|
|
603
|
+
emit("update:modelValue", JSON.parse(JSON.stringify(vueFlowElements.value)));
|
|
604
|
+
};
|
|
605
|
+
return (_ctx, _cache) => {
|
|
606
|
+
return openBlock(), createElementBlock("div", {
|
|
607
|
+
class: normalizeClass(["node-editor-wrapper", __props.nodeContainerClass]),
|
|
608
|
+
onContextmenu: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"])),
|
|
609
|
+
onMouseover: _cache[2] || (_cache[2] = ($event) => hover.value = true),
|
|
610
|
+
onMouseleave: _cache[3] || (_cache[3] = ($event) => hover.value = false)
|
|
611
|
+
}, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("div", null, [_cache[4] || (_cache[4] = createElementVNode("b", null, "Selected Node:", -1)), createTextVNode(" " + toDisplayString(activeElementKey.value ? activeElementKey.value : "none"), 1)])]), createElementVNode("div", _hoisted_3, [
|
|
612
|
+
createElementVNode("div", null, [createElementVNode("button", {
|
|
613
|
+
class: "button-default",
|
|
614
|
+
onClick: addNode
|
|
615
|
+
}, "Add Node")]),
|
|
616
|
+
createElementVNode("div", null, [createElementVNode("button", {
|
|
617
|
+
class: "button-default",
|
|
618
|
+
onClick: fitView
|
|
619
|
+
}, "Center")]),
|
|
620
|
+
createElementVNode("div", null, [createElementVNode("button", {
|
|
621
|
+
class: "button-default",
|
|
622
|
+
onClick: autoArrange
|
|
623
|
+
}, "Auto-arrange")]),
|
|
624
|
+
activeElementIndex.value > -1 ? (openBlock(), createElementBlock("div", _hoisted_4, [createElementVNode("button", {
|
|
625
|
+
class: "button-default",
|
|
626
|
+
onClick: shiftInput
|
|
627
|
+
}, "Shift Input Position")])) : createCommentVNode("", true),
|
|
628
|
+
activeElementIndex.value > -1 ? (openBlock(), createElementBlock("div", _hoisted_5, [createElementVNode("button", {
|
|
629
|
+
class: "button-default",
|
|
630
|
+
onClick: shiftOutput
|
|
631
|
+
}, "Shift Output Position")])) : createCommentVNode("", true)
|
|
632
|
+
])]), vueFlowElements.value && vueFlowElements.value.length ? (openBlock(), createBlock(unref(VueFlow), {
|
|
633
|
+
key: 0,
|
|
634
|
+
modelValue: vueFlowElements.value,
|
|
635
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vueFlowElements.value = $event),
|
|
636
|
+
class: "nowheel",
|
|
637
|
+
"prevent-scrolling": true,
|
|
638
|
+
"zoom-on-scroll": false,
|
|
639
|
+
"fit-view-on-init": true,
|
|
640
|
+
"pan-activation-key-code": null,
|
|
641
|
+
onConnect: handleConnect,
|
|
642
|
+
onPaneReady: setInstance,
|
|
643
|
+
onNodeClick: handleNodeClick,
|
|
644
|
+
onEdgeClick: handleEdgeClick,
|
|
645
|
+
onEdgeContextMenu: handleEdgeContextMenu,
|
|
646
|
+
onNodeDragStop: emitElements,
|
|
647
|
+
onWheel: withModifiers(onWheel, ["prevent"])
|
|
648
|
+
}, {
|
|
649
|
+
"node-editable": withCtx((props) => [createVNode(EditableNode_default, mergeProps(props, { onChange: ($event) => labelChanged($event, props.id) }), null, 16, ["onChange"])]),
|
|
650
|
+
"edge-editable": withCtx((props) => [createVNode(EditableEdge_default, mergeProps(props, {
|
|
651
|
+
onChange: ($event) => labelChanged($event, props.id),
|
|
652
|
+
onRemove: ($event) => removeEdge(props.id)
|
|
653
|
+
}), null, 16, ["onChange", "onRemove"])]),
|
|
654
|
+
"edge-selfloop": withCtx((props) => [createVNode(SelfLoopEdge_default, mergeProps(props, {
|
|
655
|
+
onChange: ($event) => labelChanged($event, props.id),
|
|
656
|
+
onRemove: ($event) => removeEdge(props.id)
|
|
657
|
+
}), null, 16, ["onChange", "onRemove"])]),
|
|
658
|
+
_: 1
|
|
659
|
+
}, 8, ["modelValue"])) : createCommentVNode("", true)], 34);
|
|
660
|
+
};
|
|
661
|
+
}
|
|
505
662
|
});
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region src/utils/stateTransforms.ts
|
|
665
|
+
function statesToFlowElements(workflow, layout) {
|
|
666
|
+
const { states = [], actions = {} } = workflow;
|
|
667
|
+
const edges = [];
|
|
668
|
+
const nodes = [];
|
|
669
|
+
for (const [actionKey, actionDef] of Object.entries(actions)) {
|
|
670
|
+
if (actionDef.stateless || !actionDef.allowedStates?.length) continue;
|
|
671
|
+
if (actionDef.selfTransition) {
|
|
672
|
+
for (const source of actionDef.allowedStates) edges.push({
|
|
673
|
+
id: `${actionKey}-${source}`,
|
|
674
|
+
source,
|
|
675
|
+
target: source,
|
|
676
|
+
label: actionDef.label ?? actionKey,
|
|
677
|
+
data: { actionKey },
|
|
678
|
+
animated: true,
|
|
679
|
+
type: "selfloop",
|
|
680
|
+
interactionWidth: 40
|
|
681
|
+
});
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
if (!actionDef.nextState) continue;
|
|
685
|
+
for (const source of actionDef.allowedStates) edges.push({
|
|
686
|
+
id: `${actionKey}-${source}`,
|
|
687
|
+
source,
|
|
688
|
+
target: actionDef.nextState,
|
|
689
|
+
label: actionDef.label ?? actionKey,
|
|
690
|
+
data: { actionKey },
|
|
691
|
+
animated: true,
|
|
692
|
+
type: "smoothstep",
|
|
693
|
+
interactionWidth: 40
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
for (let index = 0; index < states.length; index++) {
|
|
697
|
+
const state = states[index];
|
|
698
|
+
const node = {
|
|
699
|
+
id: state,
|
|
700
|
+
label: state,
|
|
701
|
+
position: layout?.[state]?.position ?? {
|
|
702
|
+
x: 200 * index,
|
|
703
|
+
y: 100
|
|
704
|
+
},
|
|
705
|
+
targetPosition: layout?.[state]?.targetPosition ?? Position$1.Left,
|
|
706
|
+
sourcePosition: layout?.[state]?.sourcePosition ?? Position$1.Right
|
|
707
|
+
};
|
|
708
|
+
nodes.push(node);
|
|
709
|
+
}
|
|
710
|
+
return [...edges, ...nodes];
|
|
550
711
|
}
|
|
551
|
-
function
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
712
|
+
function flowElementsToStates(nextElements, existingWorkflow) {
|
|
713
|
+
const idToLabel = {};
|
|
714
|
+
const nextLayout = {};
|
|
715
|
+
const stateNames = [];
|
|
716
|
+
for (const el of nextElements) {
|
|
717
|
+
if ("source" in el) continue;
|
|
718
|
+
const label = typeof el.label === "string" ? el.label : el.id;
|
|
719
|
+
idToLabel[el.id] = label;
|
|
720
|
+
stateNames.push(label);
|
|
721
|
+
if (el.position) nextLayout[label] = {
|
|
722
|
+
position: el.position,
|
|
723
|
+
...el.targetPosition !== void 0 && { targetPosition: el.targetPosition },
|
|
724
|
+
...el.sourcePosition !== void 0 && { sourcePosition: el.sourcePosition }
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
const transitionGroups = {};
|
|
728
|
+
for (const el of nextElements) {
|
|
729
|
+
if (!("source" in el)) continue;
|
|
730
|
+
const edgeLabel = typeof el.label === "string" ? el.label : el.id;
|
|
731
|
+
const actionKey = el.data?.actionKey ?? edgeLabel;
|
|
732
|
+
const sourceLabel = idToLabel[el.source] || el.source;
|
|
733
|
+
const targetLabel = idToLabel[el.target] || el.target;
|
|
734
|
+
const isSelf = el.source === el.target;
|
|
735
|
+
if (!transitionGroups[actionKey]) transitionGroups[actionKey] = {
|
|
736
|
+
allowedStates: [sourceLabel],
|
|
737
|
+
label: edgeLabel,
|
|
738
|
+
selfLoop: isSelf,
|
|
739
|
+
...isSelf ? {} : { nextState: targetLabel }
|
|
740
|
+
};
|
|
741
|
+
else transitionGroups[actionKey].allowedStates.push(sourceLabel);
|
|
742
|
+
}
|
|
743
|
+
const nextActions = {};
|
|
744
|
+
for (const [actionKey, group] of Object.entries(transitionGroups)) {
|
|
745
|
+
const existing = existingWorkflow?.actions?.[actionKey];
|
|
746
|
+
nextActions[actionKey] = {
|
|
747
|
+
...existing,
|
|
748
|
+
label: group.label || existing?.label || actionKey,
|
|
749
|
+
allowedStates: group.allowedStates,
|
|
750
|
+
nextState: group.selfLoop ? void 0 : group.nextState,
|
|
751
|
+
selfTransition: group.selfLoop ? true : void 0
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
for (const [actionKey, actionDef] of Object.entries(existingWorkflow?.actions ?? {})) {
|
|
755
|
+
if (actionKey in transitionGroups) continue;
|
|
756
|
+
if (actionDef.stateless || !actionDef.allowedStates?.length) nextActions[actionKey] = actionDef;
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
workflow: {
|
|
760
|
+
...existingWorkflow,
|
|
761
|
+
states: stateNames,
|
|
762
|
+
actions: nextActions
|
|
763
|
+
},
|
|
764
|
+
layout: nextLayout
|
|
765
|
+
};
|
|
605
766
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region src/components/StateEditor.vue
|
|
769
|
+
var StateEditor_default = /* @__PURE__ */ defineComponent({
|
|
770
|
+
__name: "StateEditor",
|
|
771
|
+
props: /*@__PURE__*/ mergeModels({ nodeContainerClass: {
|
|
772
|
+
type: [
|
|
773
|
+
Boolean,
|
|
774
|
+
null,
|
|
775
|
+
String,
|
|
776
|
+
Object,
|
|
777
|
+
Array
|
|
778
|
+
],
|
|
779
|
+
default: ""
|
|
780
|
+
} }, {
|
|
781
|
+
"modelValue": {},
|
|
782
|
+
"modelModifiers": {},
|
|
783
|
+
"layout": {},
|
|
784
|
+
"layoutModifiers": {}
|
|
785
|
+
}),
|
|
786
|
+
emits: ["update:modelValue", "update:layout"],
|
|
787
|
+
setup(__props) {
|
|
788
|
+
const workflow = useModel(__props, "modelValue");
|
|
789
|
+
const layout = useModel(__props, "layout");
|
|
790
|
+
onMounted(() => {
|
|
791
|
+
if (layout.value === void 0) console.warn("[StateEditor] v-model:layout is not bound. Node position changes will not be persisted.");
|
|
792
|
+
});
|
|
793
|
+
const elements = computed({
|
|
794
|
+
get: () => {
|
|
795
|
+
if (!workflow.value) return [];
|
|
796
|
+
const els = statesToFlowElements(workflow.value, layout.value);
|
|
797
|
+
return !layout.value || Object.keys(layout.value).length === 0 ? autoLayout(els) : els;
|
|
798
|
+
},
|
|
799
|
+
set: (newValue) => {
|
|
800
|
+
const { workflow: nextWorkflow, layout: nextLayout } = flowElementsToStates(newValue, workflow.value);
|
|
801
|
+
workflow.value = nextWorkflow;
|
|
802
|
+
if (layout.value !== void 0) layout.value = nextLayout;
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
return (_ctx, _cache) => {
|
|
806
|
+
return openBlock(), createElementBlock("div", null, [createVNode(NodeEditor_default, {
|
|
807
|
+
modelValue: elements.value,
|
|
808
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => elements.value = $event),
|
|
809
|
+
"node-container-class": __props.nodeContainerClass
|
|
810
|
+
}, null, 8, ["modelValue", "node-container-class"])]);
|
|
811
|
+
};
|
|
812
|
+
}
|
|
641
813
|
});
|
|
642
|
-
|
|
643
|
-
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region src/index.ts
|
|
816
|
+
/**
|
|
817
|
+
* Install all Node Editor components
|
|
818
|
+
* @param app - Vue app instance
|
|
819
|
+
* @public
|
|
820
|
+
*/
|
|
821
|
+
function install(app) {
|
|
822
|
+
app.component("NodeEditor", NodeEditor_default);
|
|
823
|
+
app.component("StateEditor", StateEditor_default);
|
|
644
824
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
je as install
|
|
650
|
-
};
|
|
651
|
-
//# sourceMappingURL=node-editor.js.map
|
|
825
|
+
//#endregion
|
|
826
|
+
export { NodeEditor_default as NodeEditor, Position, StateEditor_default as StateEditor, install };
|
|
827
|
+
|
|
828
|
+
//# sourceMappingURL=node-editor.js.map
|