@dou-ui/flow 0.1.0-alpha.2 → 0.1.0-alpha.21
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/collaboration/index.js +114 -6
- package/dist/collaboration/index.js.map +1 -1
- package/dist/comments.js +245 -0
- package/dist/comments.js.map +1 -0
- package/dist/components/default-node.js.map +1 -1
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/default-node2.js.map +1 -1
- package/dist/components/flow-comments.js +6 -0
- package/dist/components/flow-comments.js.map +1 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/flow-port.js.map +1 -1
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/node-view.js.map +1 -1
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/port-view.js +6 -0
- package/dist/components/port-view.js.map +1 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/port.js +7 -0
- package/dist/components/port.js.map +1 -0
- package/dist/context.js.map +1 -1
- package/dist/core/edge-types.js +107 -3
- package/dist/core/edge-types.js.map +1 -1
- package/dist/core/extension.js.map +1 -1
- package/dist/core/history.js +26 -0
- package/dist/core/history.js.map +1 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/node-types.js +39 -1
- package/dist/core/node-types.js.map +1 -1
- package/dist/core/transaction.js +112 -15
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +1 -1
- package/dist/export/render.js +78 -0
- package/dist/export/render.js.map +1 -0
- package/dist/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +484 -39
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/kit.js +1 -1
- package/dist/locale.js +21 -9
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +1 -1
- package/dist/types/collaboration/index.d.ts +32 -4
- package/dist/types/comments.d.ts +73 -0
- package/dist/types/components/default-node.d.ts +1 -1
- package/dist/types/components/flow-comments.vue.d.ts +35 -0
- package/dist/types/components/flow-port.vue.d.ts +8 -2
- package/dist/types/components/port-view.vue.d.ts +10 -0
- package/dist/types/components/port.d.ts +7 -0
- package/dist/types/context.d.ts +54 -1
- package/dist/types/core/extension.d.ts +9 -1
- package/dist/types/core/history.d.ts +10 -0
- package/dist/types/core/menu.d.ts +5 -0
- package/dist/types/core/model.d.ts +28 -0
- package/dist/types/core/node-types.d.ts +18 -2
- package/dist/types/core/transaction.d.ts +23 -1
- package/dist/types/export/render.d.ts +27 -0
- package/dist/types/flow-editor.vue.d.ts +11 -0
- package/dist/types/index.d.ts +37 -10
- package/dist/types/locale.d.ts +11 -3
- package/dist/types/whiteboard/model.d.ts +2 -11
- package/dist/types/whiteboard/state.d.ts +2 -0
- package/dist/whiteboard/board-node.js.map +1 -1
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +30 -14
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/whiteboard/connector.js +5 -10
- package/dist/whiteboard/connector.js.map +1 -1
- package/dist/whiteboard/kit.js +63 -8
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +4 -31
- package/dist/whiteboard/model.js.map +1 -1
- package/dist/whiteboard/state.js +6 -1
- package/dist/whiteboard/state.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { flowEditorKey } from "./context.js";
|
|
2
|
-
import { boundsOf, clampPan, intersects, intersectsTurned, rectFrom, snapBox } from "./core/geometry.js";
|
|
3
|
-
import { labelOf, nodeBounds, portsOf, resizeOf } from "./core/node-types.js";
|
|
2
|
+
import { boundsOf, clampPan, intersects, intersectsTurned, rectFrom, snapBox, turn } from "./core/geometry.js";
|
|
3
|
+
import { labelOf, nodeBounds, portSide, portsOf, resizeOf, warnUnknownNodeType } from "./core/node-types.js";
|
|
4
4
|
import node_view_default from "./components/node-view.js";
|
|
5
5
|
import flow_menu_default from "./components/flow-menu.js";
|
|
6
|
+
import { format, useFlowMessages } from "./locale.js";
|
|
7
|
+
import flow_comments_default from "./components/flow-comments.js";
|
|
8
|
+
import { resolveFlowExtensions } from "./core/extension.js";
|
|
9
|
+
import { useFlowComments } from "./comments.js";
|
|
6
10
|
import flow_quick_add_default from "./components/flow-quick-add.js";
|
|
7
11
|
import flow_toolbar_default from "./components/flow-toolbar.js";
|
|
8
12
|
import { drawTools } from "./export/context.js";
|
|
@@ -13,8 +17,6 @@ import { canJoin, displacedEdges, joinRefusal, primaryType, typesMatch } from ".
|
|
|
13
17
|
import { FlowTransaction } from "./core/transaction.js";
|
|
14
18
|
import { FlowHistory } from "./core/history.js";
|
|
15
19
|
import { flowOrder } from "./core/order.js";
|
|
16
|
-
import { resolveFlowExtensions } from "./core/extension.js";
|
|
17
|
-
import { format, useFlowMessages } from "./locale.js";
|
|
18
20
|
import { flowKit } from "./kit.js";
|
|
19
21
|
import { readClipboard, writeClipboard } from "./core/clipboard.js";
|
|
20
22
|
import { createId, emptyDocument, emptySelection } from "./core/model.js";
|
|
@@ -93,12 +95,23 @@ var FIT_PADDING = 40;
|
|
|
93
95
|
* that; what still doesn't fit starts at the top left, to be panned to.
|
|
94
96
|
*/
|
|
95
97
|
var PANEL_GAP = 16;
|
|
98
|
+
var TIDY_NEAR = 24;
|
|
96
99
|
var FIELDS = "input, textarea, [contenteditable]:not([contenteditable=\"false\"]), [data-dou-nodrag]";
|
|
97
100
|
var MAGNET = 24;
|
|
98
101
|
var FIND_INSET = 12;
|
|
99
102
|
var DRAW_MARGIN = 200;
|
|
100
103
|
/** The part of the canvas that is drawn: the view and a margin around it. */
|
|
101
104
|
var TINY = .2;
|
|
105
|
+
var EDGE_LABEL_HALF = 10;
|
|
106
|
+
/** How far above an edge's label its marker sits, in screen px; a finger's target adds 8 (style.css). */
|
|
107
|
+
var EDGE_MARKER_LIFT = 14;
|
|
108
|
+
/** A marker's size, and how far apart two markers' middles keep, so a finger's 40px targets don't overlap. */
|
|
109
|
+
var MARKER_SIZE = 24;
|
|
110
|
+
var MARKER_GAP = 32;
|
|
111
|
+
/**
|
|
112
|
+
* A marker's middle, in px within the editor: a node's sits off its top
|
|
113
|
+
* right corner, a pin's bottom left corner is on its point (style.css).
|
|
114
|
+
*/
|
|
102
115
|
var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
103
116
|
name: "DouFlowEditor",
|
|
104
117
|
__name: "flow-editor",
|
|
@@ -136,8 +149,19 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
136
149
|
portTypes: {},
|
|
137
150
|
acyclic: { type: Boolean },
|
|
138
151
|
canConnect: {},
|
|
152
|
+
bordered: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
default: true
|
|
155
|
+
},
|
|
139
156
|
ariaLabel: {},
|
|
140
|
-
messages: {}
|
|
157
|
+
messages: {},
|
|
158
|
+
comments: { default: void 0 },
|
|
159
|
+
author: { default: void 0 },
|
|
160
|
+
activeComment: { default: void 0 },
|
|
161
|
+
commentable: {
|
|
162
|
+
type: Boolean,
|
|
163
|
+
default: true
|
|
164
|
+
}
|
|
141
165
|
}, {
|
|
142
166
|
"modelValue": { default: emptyDocument },
|
|
143
167
|
"modelModifiers": {},
|
|
@@ -153,6 +177,9 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
153
177
|
emits: /*@__PURE__*/ mergeModels([
|
|
154
178
|
"transaction",
|
|
155
179
|
"transactionCancel",
|
|
180
|
+
"update:comments",
|
|
181
|
+
"update:activeComment",
|
|
182
|
+
"commentAction",
|
|
156
183
|
"nodeClick",
|
|
157
184
|
"nodeDblclick",
|
|
158
185
|
"nodeContextmenu",
|
|
@@ -191,7 +218,20 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
191
218
|
/** The axis that levels two ports on this side. */
|
|
192
219
|
const level = (side) => side === "left" || side === "right" ? "y" : "x";
|
|
193
220
|
const same = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
194
|
-
const
|
|
221
|
+
const { comments, extension: commentsExtension, anchors: getCommentAnchors, anchorOf: commentAnchorOf } = useFlowComments({
|
|
222
|
+
props,
|
|
223
|
+
emit,
|
|
224
|
+
doc,
|
|
225
|
+
selection,
|
|
226
|
+
messages,
|
|
227
|
+
transact,
|
|
228
|
+
carry: (on, patch) => !customHistory && history.carry(on, patch),
|
|
229
|
+
shownOn: (on) => commentSpots.value.find((spot) => spot.key === spotKey(on))?.threads
|
|
230
|
+
});
|
|
231
|
+
const resolved = computed(() => {
|
|
232
|
+
const own = props.extensions ?? flowKit();
|
|
233
|
+
return resolveFlowExtensions(comments.enabled.value ? [...own, commentsExtension] : own);
|
|
234
|
+
});
|
|
195
235
|
const types = computed(() => {
|
|
196
236
|
const map = new Map(resolved.value.nodeTypes);
|
|
197
237
|
for (const spec of props.nodeTypes ?? []) map.set(spec.type, spec);
|
|
@@ -209,6 +249,9 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
209
249
|
/** The type of edges without one: the prop, else the extensions', else bezier. */
|
|
210
250
|
const defaultEdgeType = computed(() => props.edgeType ?? resolved.value.edgeType ?? "bezier");
|
|
211
251
|
const edgeTypeOf = (type) => edgeTypes.value.get(type ?? defaultEdgeType.value) ?? edgeTypes.value.get(defaultEdgeType.value) ?? bezierEdge;
|
|
252
|
+
if (process.env.NODE_ENV !== "production") watch(() => [doc.value.nodes, types.value], ([nodes, map]) => {
|
|
253
|
+
for (const node of nodes) if (node.type && !map.has(node.type)) warnUnknownNodeType(node.type);
|
|
254
|
+
}, { immediate: true });
|
|
212
255
|
const specOf = (node) => types.value.get(node.type ?? "default") ?? types.value.get("default") ?? defaultNode;
|
|
213
256
|
/** Each node's ports by id, worked out once per change rather than per edge. */
|
|
214
257
|
const portsByNode = computed(() => {
|
|
@@ -515,9 +558,14 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
515
558
|
const out = [];
|
|
516
559
|
const edges = doc.value.edges;
|
|
517
560
|
edges.length;
|
|
518
|
-
|
|
561
|
+
const tweening = tween.value !== null;
|
|
562
|
+
for (let edge of toRaw(edges)) {
|
|
519
563
|
const from = edgeEnd(edge.source);
|
|
520
564
|
const to = edgeEnd(edge.target);
|
|
565
|
+
if (edge.points && (tweening || from !== edge.source || to !== edge.target)) edge = {
|
|
566
|
+
...edge,
|
|
567
|
+
points: void 0
|
|
568
|
+
};
|
|
521
569
|
if (from.node === to.node && (from !== edge.source || to !== edge.target)) continue;
|
|
522
570
|
const source = nodeById.value.get(from.node);
|
|
523
571
|
const target = nodeById.value.get(to.node);
|
|
@@ -525,14 +573,22 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
525
573
|
const a = anchor(source, from.port, "source");
|
|
526
574
|
const b = anchor(target, to.port, "target");
|
|
527
575
|
if (!a || !b) continue;
|
|
576
|
+
const xs = [a.x, b.x];
|
|
577
|
+
const ys = [a.y, b.y];
|
|
578
|
+
for (const p of edge.points ?? []) {
|
|
579
|
+
xs.push(p.x);
|
|
580
|
+
ys.push(p.y);
|
|
581
|
+
}
|
|
582
|
+
const x = Math.min(...xs);
|
|
583
|
+
const y = Math.min(...ys);
|
|
528
584
|
out.push({
|
|
529
585
|
edge,
|
|
530
586
|
route: edgeTypeOf(edge.type).route(a, b, edge),
|
|
531
587
|
box: {
|
|
532
|
-
x:
|
|
533
|
-
y:
|
|
534
|
-
width: Math.
|
|
535
|
-
height: Math.
|
|
588
|
+
x: x - EDGE_REACH,
|
|
589
|
+
y: y - EDGE_REACH,
|
|
590
|
+
width: Math.max(...xs) - x + 160,
|
|
591
|
+
height: Math.max(...ys) - y + 160
|
|
536
592
|
},
|
|
537
593
|
style: edgeStyle(edge)
|
|
538
594
|
});
|
|
@@ -748,10 +804,11 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
748
804
|
}
|
|
749
805
|
/** Point on the screen relative to the editor's top left corner. */
|
|
750
806
|
function local(clientX, clientY) {
|
|
751
|
-
const
|
|
807
|
+
const el = root.value;
|
|
808
|
+
const rect = el.getBoundingClientRect();
|
|
752
809
|
return {
|
|
753
|
-
x: clientX - rect.left,
|
|
754
|
-
y: clientY - rect.top
|
|
810
|
+
x: clientX - rect.left - el.clientLeft,
|
|
811
|
+
y: clientY - rect.top - el.clientTop
|
|
755
812
|
};
|
|
756
813
|
}
|
|
757
814
|
function toCanvas(point) {
|
|
@@ -801,7 +858,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
801
858
|
left: FIT_PADDING,
|
|
802
859
|
right: FIT_PADDING
|
|
803
860
|
};
|
|
804
|
-
for (const panel of root.value.querySelectorAll(".dou-flow-editor__panels > :not(.dou-flow-toolbar)")) {
|
|
861
|
+
for (const panel of root.value.querySelectorAll(".dou-flow-editor__panels > :not(.dou-flow-toolbar, .dou-flow-editor__comments, .dou-flow-editor__comment-card)")) {
|
|
805
862
|
const rect = panel.getBoundingClientRect();
|
|
806
863
|
if (!rect.height) continue;
|
|
807
864
|
const upper = rect.top + rect.height / 2 < box.top + box.height / 2;
|
|
@@ -832,7 +889,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
832
889
|
zoom
|
|
833
890
|
}, animate);
|
|
834
891
|
}
|
|
835
|
-
/**
|
|
892
|
+
/** How near a note on a board is to a node, in px, to move along with it when tidying. */
|
|
836
893
|
const TIDY_GAP = {
|
|
837
894
|
horizontal: {
|
|
838
895
|
rank: 80,
|
|
@@ -844,6 +901,50 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
844
901
|
}
|
|
845
902
|
};
|
|
846
903
|
/**
|
|
904
|
+
* Which way tidying runs: the flow's `direction`, unless most edges between
|
|
905
|
+
* nodes with `ports: 'sides'` leave their nodes by the other
|
|
906
|
+
* sides, e.g. a whiteboard drawn top to bottom. Laying that out the other
|
|
907
|
+
* way would undo how it was drawn. Fixed ports say nothing about it.
|
|
908
|
+
*/
|
|
909
|
+
function tidiesVertically(blocks, blockOf) {
|
|
910
|
+
const vertical = props.direction === "vertical";
|
|
911
|
+
let along = 0;
|
|
912
|
+
let across = 0;
|
|
913
|
+
for (const edge of doc.value.edges) {
|
|
914
|
+
const from = blockOf(edge.source.node);
|
|
915
|
+
const to = blockOf(edge.target.node);
|
|
916
|
+
if (!from || !to || from === to || !blocks.has(from) || !blocks.has(to)) continue;
|
|
917
|
+
const port = portSpec(edge.source);
|
|
918
|
+
const node = nodeById.value.get(edge.source.node);
|
|
919
|
+
if (!port || !node || specOf(node).ports !== "sides" || specOf(node).rotation?.(node)) continue;
|
|
920
|
+
const side = portSide(port);
|
|
921
|
+
if ((side === "top" || side === "bottom") === vertical) along++;
|
|
922
|
+
else across++;
|
|
923
|
+
}
|
|
924
|
+
return across > along ? !vertical : vertical;
|
|
925
|
+
}
|
|
926
|
+
const OPPOSITE = {
|
|
927
|
+
top: "bottom",
|
|
928
|
+
bottom: "top",
|
|
929
|
+
left: "right",
|
|
930
|
+
right: "left"
|
|
931
|
+
};
|
|
932
|
+
/**
|
|
933
|
+
* The port an edge end moves to when tidying, on a node whose ports are
|
|
934
|
+
* `ports: 'sides'`: on the side facing the other end along the flow.
|
|
935
|
+
*/
|
|
936
|
+
function anchorFor(end, kind, side) {
|
|
937
|
+
const node = nodeById.value.get(end.node);
|
|
938
|
+
if (!node) return void 0;
|
|
939
|
+
const spec = specOf(node);
|
|
940
|
+
if (spec.ports !== "sides" || spec.rotation?.(node)) return void 0;
|
|
941
|
+
const port = portsOf(spec, node).find((p) => p.kind === kind && portSide(p) === side);
|
|
942
|
+
return port && port.id !== end.port ? {
|
|
943
|
+
...end,
|
|
944
|
+
port: port.id
|
|
945
|
+
} : void 0;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
847
948
|
* Lays the given nodes, or the selected ones when two or more are selected,
|
|
848
949
|
* or all, out in ranks along their edges in the flow's `direction`, as one
|
|
849
950
|
* undo step. The group keeps its top left corner; locked nodes stay put.
|
|
@@ -858,12 +959,26 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
858
959
|
return at;
|
|
859
960
|
};
|
|
860
961
|
const blocks = new Set([...chosen].flatMap((id) => blockOf(id) ?? []));
|
|
861
|
-
const
|
|
962
|
+
const board = [...blocks].some((id) => {
|
|
963
|
+
const node = nodeById.value.get(id);
|
|
964
|
+
return node && specOf(node).ports === "sides";
|
|
965
|
+
});
|
|
966
|
+
const linked = /* @__PURE__ */ new Set();
|
|
967
|
+
if (board) for (const edge of doc.value.edges) {
|
|
968
|
+
const a = blockOf(edge.source.node);
|
|
969
|
+
const b = blockOf(edge.target.node);
|
|
970
|
+
if (!a || !b || a === b || !blocks.has(a) || !blocks.has(b)) continue;
|
|
971
|
+
linked.add(a);
|
|
972
|
+
linked.add(b);
|
|
973
|
+
}
|
|
974
|
+
const loose = board ? doc.value.nodes.filter((n) => blocks.has(n.id) && !linked.has(n.id)) : [];
|
|
975
|
+
const nodes = doc.value.nodes.filter((node) => blocks.has(node.id) && (!board || linked.has(node.id)));
|
|
862
976
|
const bounds = boundsOf(nodes.map(rectOf));
|
|
863
977
|
if (!bounds || nodes.length < 2) return;
|
|
864
|
-
const vertical =
|
|
978
|
+
const vertical = tidiesVertically(blocks, blockOf);
|
|
865
979
|
const gap = TIDY_GAP[vertical ? "vertical" : "horizontal"];
|
|
866
980
|
const across = vertical ? ["top", "bottom"] : ["left", "right"];
|
|
981
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
867
982
|
const layout = layoutGraph(nodes.map((node) => {
|
|
868
983
|
const m = metrics.get(node.id);
|
|
869
984
|
const { width, height } = rectOf(node);
|
|
@@ -872,6 +987,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
872
987
|
offset = vertical ? port.x : port.y;
|
|
873
988
|
break;
|
|
874
989
|
}
|
|
990
|
+
offset = Math.round(offset);
|
|
991
|
+
anchors.set(node.id, offset);
|
|
875
992
|
return {
|
|
876
993
|
id: node.id,
|
|
877
994
|
width,
|
|
@@ -886,11 +1003,12 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
886
1003
|
to
|
|
887
1004
|
}] : [];
|
|
888
1005
|
}), {
|
|
889
|
-
direction:
|
|
1006
|
+
direction: vertical ? "vertical" : "horizontal",
|
|
890
1007
|
rankGap: gap.rank,
|
|
891
1008
|
laneGap: gap.row,
|
|
892
1009
|
equalWidth: false,
|
|
893
|
-
grid: props.grid || 8
|
|
1010
|
+
grid: props.grid || 8,
|
|
1011
|
+
straightChains: true
|
|
894
1012
|
});
|
|
895
1013
|
const snap = (v) => props.grid ? Math.round(v / props.grid) * props.grid : Math.round(v);
|
|
896
1014
|
const origin = {
|
|
@@ -905,15 +1023,112 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
905
1023
|
for (const node of nodes) {
|
|
906
1024
|
const placed = layout.nodes.get(node.id);
|
|
907
1025
|
if (!placed || node.locked) continue;
|
|
908
|
-
const
|
|
909
|
-
|
|
1026
|
+
const offset = anchors.get(node.id) ?? 0;
|
|
1027
|
+
const to = vertical ? {
|
|
1028
|
+
x: origin.x + snap(placed.x + offset) - offset,
|
|
910
1029
|
y: origin.y + snap(placed.y)
|
|
1030
|
+
} : {
|
|
1031
|
+
x: origin.x + snap(placed.x),
|
|
1032
|
+
y: origin.y + snap(placed.y + offset) - offset
|
|
911
1033
|
};
|
|
912
1034
|
if (to.x !== node.x || to.y !== node.y) moved.set(node.id, to);
|
|
913
1035
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1036
|
+
for (const note of loose) {
|
|
1037
|
+
if (note.locked) continue;
|
|
1038
|
+
const rect = rectOf(note);
|
|
1039
|
+
let host;
|
|
1040
|
+
let best = Infinity;
|
|
1041
|
+
for (const node of nodes) {
|
|
1042
|
+
const other = rectOf(node);
|
|
1043
|
+
const apart = Math.max(other.x - (rect.x + rect.width), rect.x - (other.x + other.width), other.y - (rect.y + rect.height), rect.y - (other.y + other.height), 0);
|
|
1044
|
+
if (apart > TIDY_NEAR) continue;
|
|
1045
|
+
const score = apart * 1e6 + Math.hypot(other.x + other.width / 2 - (rect.x + rect.width / 2), other.y + other.height / 2 - (rect.y + rect.height / 2));
|
|
1046
|
+
if (score < best) {
|
|
1047
|
+
best = score;
|
|
1048
|
+
host = node;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const to = host && moved.get(host.id);
|
|
1052
|
+
if (!host || !to) continue;
|
|
1053
|
+
from.set(note.id, {
|
|
1054
|
+
x: note.x,
|
|
1055
|
+
y: note.y
|
|
1056
|
+
});
|
|
1057
|
+
moved.set(note.id, {
|
|
1058
|
+
x: note.x + to.x - host.x,
|
|
1059
|
+
y: note.y + to.y - host.y
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
const through = new Map(layout.edges.map((e) => [`${e.from}\u0000${e.to}`, e.points]));
|
|
1063
|
+
const locked = new Set(nodes.filter((node) => node.locked).map((node) => node.id));
|
|
1064
|
+
const routes = /* @__PURE__ */ new Map();
|
|
1065
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
1066
|
+
for (const edge of doc.value.edges) {
|
|
1067
|
+
const a = edge.source.node;
|
|
1068
|
+
const b = edge.target.node;
|
|
1069
|
+
if (!blocks.has(a) || !blocks.has(b)) continue;
|
|
1070
|
+
const key = `${a}\u0000${b}`;
|
|
1071
|
+
pairs.set(key, [...pairs.get(key) ?? [], edge]);
|
|
1072
|
+
}
|
|
1073
|
+
for (const [key, group] of pairs) {
|
|
1074
|
+
const [a, b] = key.split("\0");
|
|
1075
|
+
const points = locked.has(a) || locked.has(b) ? void 0 : through.get(key);
|
|
1076
|
+
group.forEach((edge, i) => {
|
|
1077
|
+
const off = (i - (group.length - 1) / 2) * (props.grid || 8);
|
|
1078
|
+
const next = points?.length ? points.map((p) => ({
|
|
1079
|
+
x: origin.x + snap(p.x) + (vertical ? off : 0),
|
|
1080
|
+
y: origin.y + snap(p.y) + (vertical ? 0 : off)
|
|
1081
|
+
})) : void 0;
|
|
1082
|
+
routes.set(edge.id, next);
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
const rankOf = new Map(layout.ranks.flatMap((rank, i) => rank.map((id) => [id, i])));
|
|
1086
|
+
const centre = (id) => {
|
|
1087
|
+
const rect = rectOf(nodeById.value.get(id));
|
|
1088
|
+
const block = blockOf(id);
|
|
1089
|
+
const to = moved.get(block);
|
|
1090
|
+
const was = from.get(block);
|
|
1091
|
+
const dx = to ? to.x - was.x : 0;
|
|
1092
|
+
const dy = to ? to.y - was.y : 0;
|
|
1093
|
+
return {
|
|
1094
|
+
x: rect.x + dx + rect.width / 2,
|
|
1095
|
+
y: rect.y + dy + rect.height / 2
|
|
1096
|
+
};
|
|
1097
|
+
};
|
|
1098
|
+
const ends = /* @__PURE__ */ new Map();
|
|
1099
|
+
const joined = /* @__PURE__ */ new Set();
|
|
1100
|
+
for (const edge of doc.value.edges) {
|
|
1101
|
+
const a = blockOf(edge.source.node);
|
|
1102
|
+
const b = blockOf(edge.target.node);
|
|
1103
|
+
if (a && b) joined.add(`${a}\u0000${b}`);
|
|
1104
|
+
}
|
|
1105
|
+
const middle = (vertical ? origin.x + layout.width / 2 : origin.y + layout.height / 2) - .5;
|
|
1106
|
+
for (const edge of doc.value.edges) {
|
|
1107
|
+
const a = blockOf(edge.source.node);
|
|
1108
|
+
const b = blockOf(edge.target.node);
|
|
1109
|
+
if (!a || !b || a === b || !blocks.has(a) || !blocks.has(b)) continue;
|
|
1110
|
+
const s = centre(edge.source.node);
|
|
1111
|
+
const t = centre(edge.target.node);
|
|
1112
|
+
const along = !locked.has(a) && !locked.has(b) ? (rankOf.get(b) ?? 0) - (rankOf.get(a) ?? 0) : Math.round(vertical ? t.y - s.y : t.x - s.x);
|
|
1113
|
+
const aside = vertical ? t.x - s.x : t.y - s.y;
|
|
1114
|
+
const out = along ? vertical ? along > 0 ? "bottom" : "top" : along > 0 ? "right" : "left" : vertical ? aside >= 0 ? "right" : "left" : aside >= 0 ? "bottom" : "top";
|
|
1115
|
+
const round = along < 0 && (along < -1 || joined.has(`${b}\u0000${a}`));
|
|
1116
|
+
const outer = vertical ? (s.x + t.x) / 2 >= middle ? "right" : "left" : (s.y + t.y) / 2 >= middle ? "bottom" : "top";
|
|
1117
|
+
const source = anchorFor(edge.source, "output", round ? outer : out);
|
|
1118
|
+
const target = anchorFor(edge.target, "input", round ? outer : OPPOSITE[out]);
|
|
1119
|
+
if (source || target) ends.set(edge.id, {
|
|
1120
|
+
source: source ?? edge.source,
|
|
1121
|
+
target: target ?? edge.target
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
const rerouted = ends.size > 0 || doc.value.edges.some((edge) => routes.has(edge.id) && JSON.stringify(routes.get(edge.id)) !== JSON.stringify(edge.points));
|
|
1125
|
+
if (!moved.size && !rerouted) return;
|
|
1126
|
+
const edgesBefore = new Map(doc.value.edges.map((e) => [e.id, e]));
|
|
1127
|
+
const count = (/* @__PURE__ */ new Set([...[...moved.keys()].filter((id) => !linked.size || linked.has(id)), ...[...ends].flatMap(([id, end]) => {
|
|
1128
|
+
const was = edgesBefore.get(id);
|
|
1129
|
+
return [...was?.source.port !== end.source.port ? [end.source.node] : [], ...was?.target.port !== end.target.port ? [end.target.node] : []];
|
|
1130
|
+
})])).size;
|
|
1131
|
+
for (const { id } of [...nodes, ...loose]) {
|
|
917
1132
|
const to = moved.get(id);
|
|
918
1133
|
if (!to) continue;
|
|
919
1134
|
const block = from.get(id);
|
|
@@ -932,12 +1147,17 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
932
1147
|
}
|
|
933
1148
|
transact((tr) => {
|
|
934
1149
|
for (const [id, to] of moved) tr.moveNode(id, to.x, to.y);
|
|
1150
|
+
for (const [id, end] of ends) tr.updateEdge(id, end);
|
|
1151
|
+
for (const [id, points] of routes) if (JSON.stringify(points) !== JSON.stringify(tr.getEdge(id)?.points)) tr.updateEdge(id, { points });
|
|
935
1152
|
});
|
|
936
1153
|
announce(format(messages.value.tidied, { count }));
|
|
937
1154
|
animateTidy(from, moved);
|
|
938
|
-
const after = boundsOf(nodes.map((node) => ({
|
|
1155
|
+
const after = boundsOf([...nodes, ...loose].map((node) => ({
|
|
939
1156
|
...rectOf(node),
|
|
940
|
-
...moved.get(node.id) ??
|
|
1157
|
+
...moved.get(node.id) ?? {
|
|
1158
|
+
x: node.x,
|
|
1159
|
+
y: node.y
|
|
1160
|
+
}
|
|
941
1161
|
})));
|
|
942
1162
|
const { x, y, zoom } = viewport.value;
|
|
943
1163
|
const { width, height } = size.value;
|
|
@@ -982,7 +1202,11 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
982
1202
|
/** Keeps a node in view, e.g. when it gets keyboard focus. */
|
|
983
1203
|
function reveal(id) {
|
|
984
1204
|
const rect = getNodeRect(id);
|
|
985
|
-
if (
|
|
1205
|
+
if (rect) revealRect(rect);
|
|
1206
|
+
}
|
|
1207
|
+
/** Pans the least that brings `rect`, in canvas coordinates, into view. */
|
|
1208
|
+
function revealRect(rect) {
|
|
1209
|
+
if (!root.value) return;
|
|
986
1210
|
const { x, y, zoom } = viewport.value;
|
|
987
1211
|
const pad = 16;
|
|
988
1212
|
const left = rect.x * zoom + x;
|
|
@@ -1062,6 +1286,28 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
1062
1286
|
clearTimeout(pressTimer);
|
|
1063
1287
|
pressTimer = 0;
|
|
1064
1288
|
}
|
|
1289
|
+
/**
|
|
1290
|
+
* A touch browser may hand a press to a clickable element near the finger
|
|
1291
|
+
* instead of the one under it. That suits most of the board, where a finger
|
|
1292
|
+
* a little off a node or a port still means it, but not a handle drawn on
|
|
1293
|
+
* screen (`data-flow-handle`): on a small node an anchor beside a corner
|
|
1294
|
+
* handle would take the press, and connect instead of resize. A press whose
|
|
1295
|
+
* finger is on such a handle is stopped and sent again to the handle.
|
|
1296
|
+
*
|
|
1297
|
+
* It listens on the window, first among the editor's listeners there, so the
|
|
1298
|
+
* listeners further on (the document's, the editor's own) hear only the press
|
|
1299
|
+
* sent again; a window listener added earlier hears both. A handler that
|
|
1300
|
+
* cancels the press sent again cancels the browser's own one too.
|
|
1301
|
+
*/
|
|
1302
|
+
function onTouchPress(event) {
|
|
1303
|
+
if (event.pointerType !== "touch" || !root.value) return;
|
|
1304
|
+
const handle = (root.value.getRootNode().elementFromPoint?.(event.clientX, event.clientY))?.closest("[data-flow-handle]");
|
|
1305
|
+
if (!handle || !root.value.contains(handle)) return;
|
|
1306
|
+
const target = event.target;
|
|
1307
|
+
if (handle === target || handle.contains(target)) return;
|
|
1308
|
+
event.stopImmediatePropagation();
|
|
1309
|
+
if (!handle.dispatchEvent(new PointerEvent("pointerdown", event))) event.preventDefault();
|
|
1310
|
+
}
|
|
1065
1311
|
function onPointerDown(event) {
|
|
1066
1312
|
const target = event.target;
|
|
1067
1313
|
if (inPanels(target)) return;
|
|
@@ -1098,7 +1344,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
1098
1344
|
}
|
|
1099
1345
|
if (event.button !== 0) return;
|
|
1100
1346
|
if (target.closest(".dou-flow-editor__label-input")) return;
|
|
1101
|
-
if (resolved.value.presses.length && !
|
|
1347
|
+
if (resolved.value.presses.length && !isInteractive(target)) {
|
|
1102
1348
|
const pressedId = target.closest("[data-node-id]")?.dataset.nodeId;
|
|
1103
1349
|
const press = {
|
|
1104
1350
|
point: toCanvas(client),
|
|
@@ -1946,6 +2192,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
1946
2192
|
x,
|
|
1947
2193
|
y,
|
|
1948
2194
|
locked: void 0,
|
|
2195
|
+
comments: void 0,
|
|
2196
|
+
commentPins: void 0,
|
|
1949
2197
|
parent: copied ?? containerAt(centre, containers)
|
|
1950
2198
|
};
|
|
1951
2199
|
});
|
|
@@ -1957,7 +2205,12 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
1957
2205
|
if (!source || !target) continue;
|
|
1958
2206
|
tr.addEdge({
|
|
1959
2207
|
...edge,
|
|
2208
|
+
points: edge.points?.map((p) => ({
|
|
2209
|
+
x: p.x + shift.x,
|
|
2210
|
+
y: p.y + shift.y
|
|
2211
|
+
})),
|
|
1960
2212
|
id: createId("e"),
|
|
2213
|
+
comments: void 0,
|
|
1961
2214
|
source: {
|
|
1962
2215
|
...edge.source,
|
|
1963
2216
|
node: source
|
|
@@ -2202,21 +2455,27 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
2202
2455
|
return true;
|
|
2203
2456
|
}
|
|
2204
2457
|
onMounted(() => {
|
|
2458
|
+
window.addEventListener("pointerdown", onTouchPress, true);
|
|
2205
2459
|
window.addEventListener("pointerdown", onMenuPress, true);
|
|
2206
2460
|
window.addEventListener("click", onMenuClick);
|
|
2207
2461
|
});
|
|
2208
2462
|
onBeforeUnmount(() => {
|
|
2463
|
+
window.removeEventListener("pointerdown", onTouchPress, true);
|
|
2209
2464
|
window.removeEventListener("pointerdown", onMenuPress, true);
|
|
2210
2465
|
window.removeEventListener("click", onMenuClick);
|
|
2211
2466
|
});
|
|
2467
|
+
/** The toolbar's groups with something in; while read-only, only what is offered then too, such as comments. */
|
|
2468
|
+
function offeredItems(lists, readonly) {
|
|
2469
|
+
return lists.map((list) => readonly ? list.filter((item) => item.showWhenReadonly) : list).filter((list) => list.length);
|
|
2470
|
+
}
|
|
2212
2471
|
const toolbarItems = computed(() => {
|
|
2213
|
-
if (
|
|
2472
|
+
if (gesture.value || keyLink.value || quickAdd.value) return [];
|
|
2214
2473
|
const nodes = selection.value.nodes.flatMap((id) => nodeById.value.get(id) ?? []);
|
|
2215
|
-
if (nodes.length) return resolved.value.toolbars.map((fn) => fn(context, nodes))
|
|
2474
|
+
if (nodes.length) return offeredItems(resolved.value.toolbars.map((fn) => fn(context, nodes)), props.readonly);
|
|
2216
2475
|
const ids = new Set(selection.value.edges);
|
|
2217
2476
|
const edges = doc.value.edges.filter((edge) => ids.has(edge.id));
|
|
2218
2477
|
if (!edges.length) return [];
|
|
2219
|
-
return resolved.value.edgeToolbars.map((fn) => fn(context, edges))
|
|
2478
|
+
return offeredItems(resolved.value.edgeToolbars.map((fn) => fn(context, edges)), props.readonly);
|
|
2220
2479
|
});
|
|
2221
2480
|
/** Where the toolbar floats: above the selected nodes, in screen px within the editor. */
|
|
2222
2481
|
const toolbarAnchor = computed(() => {
|
|
@@ -2247,9 +2506,12 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
2247
2506
|
height: bounds.height + reach * 2
|
|
2248
2507
|
};
|
|
2249
2508
|
const avoid = nodes.length ? void 0 : shownNodes.value.filter((node) => !hiddenIn.value.has(node.id) && !isContainer(node)).map((node) => rectOf(node)).filter((rect) => intersects(rect, band)).map(screen);
|
|
2509
|
+
const keys = /* @__PURE__ */ new Set([...nodes.map((id) => `n:${id}`), ...edges.map((id) => `e:${id}`)]);
|
|
2510
|
+
const marked = commentMarkers.value.filter((marker) => keys.has(marker.key));
|
|
2511
|
+
const top = Math.min(bounds.y * zoom + y, ...marked.map(markerTop));
|
|
2250
2512
|
return {
|
|
2251
2513
|
x: (bounds.x + bounds.width / 2) * zoom + x,
|
|
2252
|
-
top
|
|
2514
|
+
top,
|
|
2253
2515
|
bottom: (bounds.y + bounds.height) * zoom + y,
|
|
2254
2516
|
avoid
|
|
2255
2517
|
};
|
|
@@ -2442,8 +2704,10 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
2442
2704
|
clearPress();
|
|
2443
2705
|
cancelAnimationFrame(autoPanFrame);
|
|
2444
2706
|
if (g && root.value?.hasPointerCapture(g.id)) root.value.releasePointerCapture(g.id);
|
|
2445
|
-
if ((g?.kind === "drag" || g?.kind === "bend") && g.started)
|
|
2446
|
-
|
|
2707
|
+
if ((g?.kind === "drag" || g?.kind === "bend") && g.started || g?.kind === "resize") {
|
|
2708
|
+
if (customHistory) customHistory.close?.();
|
|
2709
|
+
else history.close();
|
|
2710
|
+
}
|
|
2447
2711
|
gesture.value = null;
|
|
2448
2712
|
guides.value = [];
|
|
2449
2713
|
dropTarget.value = null;
|
|
@@ -2457,7 +2721,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
2457
2721
|
if (g.kind === "bend") tr.updateEdge(g.edge, { data: g.origin });
|
|
2458
2722
|
else for (const [id, o] of g.origins) tr.moveNode(id, o.x, o.y);
|
|
2459
2723
|
if (tr.changed) commit(tr);
|
|
2460
|
-
|
|
2724
|
+
if (customHistory) customHistory.drop?.(g.group);
|
|
2725
|
+
else history.drop(g.group);
|
|
2461
2726
|
syncHistory();
|
|
2462
2727
|
endGesture();
|
|
2463
2728
|
return true;
|
|
@@ -3157,7 +3422,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3157
3422
|
"is-space": spaceHeld.value,
|
|
3158
3423
|
"is-dragging": !!dragging.value,
|
|
3159
3424
|
"is-connecting": !!connecting.value,
|
|
3160
|
-
"is-refused": !!connecting.value?.refused
|
|
3425
|
+
"is-refused": !!connecting.value?.refused,
|
|
3426
|
+
"is-bordered": props.bordered
|
|
3161
3427
|
}));
|
|
3162
3428
|
const context = {
|
|
3163
3429
|
exportSVG,
|
|
@@ -3182,6 +3448,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3182
3448
|
portTypeOf,
|
|
3183
3449
|
colorOf,
|
|
3184
3450
|
getNodeRect,
|
|
3451
|
+
comment: (on, options) => comments.start(on, options?.focus ?? true),
|
|
3452
|
+
canComment: comments.writable,
|
|
3185
3453
|
tidy,
|
|
3186
3454
|
centerNode,
|
|
3187
3455
|
announce,
|
|
@@ -3371,6 +3639,170 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3371
3639
|
...PNG_SOURCE
|
|
3372
3640
|
});
|
|
3373
3641
|
}
|
|
3642
|
+
/** Half an edge label's height, in canvas px. */
|
|
3643
|
+
const markerCenter = (marker) => marker.number !== void 0 ? {
|
|
3644
|
+
x: marker.x + MARKER_SIZE / 2,
|
|
3645
|
+
y: marker.y - MARKER_SIZE / 2
|
|
3646
|
+
} : "node" in marker.anchor ? {
|
|
3647
|
+
x: marker.x + 6 + MARKER_SIZE / 2,
|
|
3648
|
+
y: marker.y - 6 - MARKER_SIZE / 2
|
|
3649
|
+
} : {
|
|
3650
|
+
x: marker.x,
|
|
3651
|
+
y: marker.y
|
|
3652
|
+
};
|
|
3653
|
+
/** A marker's key: one per node and edge, and one per pin (`thread`; a pin being started has none). */
|
|
3654
|
+
const spotKey = (on, thread) => "edge" in on ? `e:${on.edge}` : on.at ? `p:${thread ?? ""}` : `n:${on.node}`;
|
|
3655
|
+
/** The top of a marker with a finger's target around it, in px within the editor. */
|
|
3656
|
+
const markerTop = (marker) => markerCenter(marker).y - MARKER_SIZE / 2 - 8 - (marker.lifted ? 8 : 0);
|
|
3657
|
+
/** Where a node or edge shows its comments: a collapsed container hiding it shows them instead. */
|
|
3658
|
+
function commentSpotOf(on) {
|
|
3659
|
+
const hidden = hiddenIn.value;
|
|
3660
|
+
if ("node" in on) {
|
|
3661
|
+
if (!nodeById.value.has(on.node)) return null;
|
|
3662
|
+
const outer = hidden.get(on.node);
|
|
3663
|
+
return outer ? { node: outer } : on;
|
|
3664
|
+
}
|
|
3665
|
+
if (edgeRouteById.value.has(on.edge)) return on;
|
|
3666
|
+
const edge = doc.value.edges.find((e) => e.id === on.edge);
|
|
3667
|
+
const outer = edge && (hidden.get(edge.source.node) ?? hidden.get(edge.target.node));
|
|
3668
|
+
return outer ? { node: outer } : null;
|
|
3669
|
+
}
|
|
3670
|
+
const edgeRouteById = computed(() => new Map(edgeRoutes.value.map((item) => [item.edge.id, item])));
|
|
3671
|
+
/**
|
|
3672
|
+
* The markers, in canvas px: one at the top right of each node and on each
|
|
3673
|
+
* edge's middle with open threads. Worked out as the document changes; the
|
|
3674
|
+
* view only moves them, below.
|
|
3675
|
+
*/
|
|
3676
|
+
const commentSpots = computed(() => {
|
|
3677
|
+
if (!comments.enabled.value) return [];
|
|
3678
|
+
const { nodes, edges, pins } = comments.openOn.value;
|
|
3679
|
+
const spots = /* @__PURE__ */ new Map();
|
|
3680
|
+
const add = (on, threads, extra = {}) => {
|
|
3681
|
+
const spot = commentSpotOf(on);
|
|
3682
|
+
if (!spot) return;
|
|
3683
|
+
const key = spotKey(spot, extra.thread);
|
|
3684
|
+
const had = spots.get(key);
|
|
3685
|
+
if (had) {
|
|
3686
|
+
for (const id of threads) if (!had.threads.includes(id)) had.threads.push(id);
|
|
3687
|
+
if (extra.pending) had.pending = true;
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
let at;
|
|
3691
|
+
let lift = 0;
|
|
3692
|
+
if ("node" in spot && spot.at) {
|
|
3693
|
+
const node = nodeById.value.get(spot.node);
|
|
3694
|
+
const rect = rectOf(node);
|
|
3695
|
+
const point = {
|
|
3696
|
+
x: rect.x + spot.at.x * rect.width,
|
|
3697
|
+
y: rect.y + spot.at.y * rect.height
|
|
3698
|
+
};
|
|
3699
|
+
const centre = {
|
|
3700
|
+
x: rect.x + rect.width / 2,
|
|
3701
|
+
y: rect.y + rect.height / 2
|
|
3702
|
+
};
|
|
3703
|
+
at = turn(point, centre, nodeRotation(node.id));
|
|
3704
|
+
} else if ("node" in spot) {
|
|
3705
|
+
const node = nodeById.value.get(spot.node);
|
|
3706
|
+
const box = nodeBounds(specOf(node), node, rectOf(node));
|
|
3707
|
+
at = {
|
|
3708
|
+
x: box.x + box.width,
|
|
3709
|
+
y: box.y
|
|
3710
|
+
};
|
|
3711
|
+
} else {
|
|
3712
|
+
const item = edgeRouteById.value.get(spot.edge);
|
|
3713
|
+
at = item.route.label;
|
|
3714
|
+
if (item.edge.label) {
|
|
3715
|
+
at = {
|
|
3716
|
+
x: at.x,
|
|
3717
|
+
y: at.y - EDGE_LABEL_HALF
|
|
3718
|
+
};
|
|
3719
|
+
lift = EDGE_MARKER_LIFT;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
spots.set(key, {
|
|
3723
|
+
key,
|
|
3724
|
+
anchor: spot,
|
|
3725
|
+
threads: [...threads],
|
|
3726
|
+
shown: [],
|
|
3727
|
+
pending: !!extra.pending,
|
|
3728
|
+
number: "node" in spot && spot.at ? extra.number ?? spot.number ?? 0 : void 0,
|
|
3729
|
+
node: "node" in spot ? nodeName(spot.node) : void 0,
|
|
3730
|
+
...at,
|
|
3731
|
+
lift
|
|
3732
|
+
});
|
|
3733
|
+
};
|
|
3734
|
+
for (const [id, threads] of nodes) add({ node: id }, threads);
|
|
3735
|
+
for (const pin of pins) add({
|
|
3736
|
+
node: pin.node,
|
|
3737
|
+
at: pin.at
|
|
3738
|
+
}, [pin.thread], {
|
|
3739
|
+
number: pin.number,
|
|
3740
|
+
thread: pin.thread
|
|
3741
|
+
});
|
|
3742
|
+
for (const [id, threads] of edges) add({ edge: id }, threads);
|
|
3743
|
+
const starting = comments.pending.value;
|
|
3744
|
+
if (starting) add(starting, [], { pending: true });
|
|
3745
|
+
const list = [...spots.values()];
|
|
3746
|
+
const active = comments.active.value;
|
|
3747
|
+
const where = active ? commentAnchorOf(active) : null;
|
|
3748
|
+
for (const spot of list) spot.shown = spot.threads;
|
|
3749
|
+
if (active && where) {
|
|
3750
|
+
const spot = commentSpotOf(where);
|
|
3751
|
+
const key = spot && spotKey(spot, active);
|
|
3752
|
+
const there = key && spots.get(key);
|
|
3753
|
+
if (there && !there.threads.includes(active)) there.shown = [...there.threads, active];
|
|
3754
|
+
else if (!there) {
|
|
3755
|
+
add(where, [], { thread: active });
|
|
3756
|
+
const added = key && spots.get(key);
|
|
3757
|
+
if (added) {
|
|
3758
|
+
added.shown = [active];
|
|
3759
|
+
list.push(added);
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
return list;
|
|
3764
|
+
});
|
|
3765
|
+
/**
|
|
3766
|
+
* The markers in px within the editor: only this follows the view as it
|
|
3767
|
+
* pans and zooms. An edge's marker that would sit on another one moves
|
|
3768
|
+
* aside, so each can be tapped.
|
|
3769
|
+
*/
|
|
3770
|
+
const commentMarkers = computed(() => {
|
|
3771
|
+
const { x: vx, y: vy, zoom } = viewport.value;
|
|
3772
|
+
const markers = commentSpots.value.map(({ x, y, lift, ...spot }) => ({
|
|
3773
|
+
...spot,
|
|
3774
|
+
x: x * zoom + vx,
|
|
3775
|
+
y: y * zoom + vy - lift,
|
|
3776
|
+
lifted: lift > 0
|
|
3777
|
+
}));
|
|
3778
|
+
const placed = markers.filter((marker) => "node" in marker.anchor).map(markerCenter);
|
|
3779
|
+
for (const marker of markers) {
|
|
3780
|
+
if ("node" in marker.anchor) continue;
|
|
3781
|
+
for (let tries = 0; tries < 8; tries++) {
|
|
3782
|
+
const other = placed.find((p) => Math.abs(p.x - marker.x) < MARKER_GAP && Math.abs(p.y - marker.y) < MARKER_GAP);
|
|
3783
|
+
if (!other) break;
|
|
3784
|
+
marker.x = other.x + (marker.x < other.x ? -32 : MARKER_GAP);
|
|
3785
|
+
}
|
|
3786
|
+
placed.push(markerCenter(marker));
|
|
3787
|
+
}
|
|
3788
|
+
return markers;
|
|
3789
|
+
});
|
|
3790
|
+
watch(() => props.activeComment, (id) => {
|
|
3791
|
+
const at = id && !comments.openedHere(id) ? commentAnchorOf(id) : null;
|
|
3792
|
+
const on = at && commentSpotOf(at);
|
|
3793
|
+
if (!on) return;
|
|
3794
|
+
if ("node" in on) return reveal(on.node);
|
|
3795
|
+
const label = edgeRouteById.value.get(on.edge)?.route.label;
|
|
3796
|
+
if (label) revealRect({
|
|
3797
|
+
x: label.x - 16,
|
|
3798
|
+
y: label.y - 16,
|
|
3799
|
+
width: 32,
|
|
3800
|
+
height: 32
|
|
3801
|
+
});
|
|
3802
|
+
});
|
|
3803
|
+
function restoreCommentFocus(on) {
|
|
3804
|
+
((on && "node" in on ? root.value?.querySelector(`[data-node-id="${CSS.escape(on.node)}"]`) : null) ?? root.value)?.focus({ preventScroll: true });
|
|
3805
|
+
}
|
|
3374
3806
|
__expose({
|
|
3375
3807
|
setViewport,
|
|
3376
3808
|
openSearch,
|
|
@@ -3399,6 +3831,8 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3399
3831
|
return [...staleEdges.value];
|
|
3400
3832
|
},
|
|
3401
3833
|
removeStaleEdges,
|
|
3834
|
+
comment: (on, options) => comments.start(on, options?.focus ?? true),
|
|
3835
|
+
getCommentAnchors,
|
|
3402
3836
|
insertNode,
|
|
3403
3837
|
startInsertDrag,
|
|
3404
3838
|
editLabel,
|
|
@@ -3627,8 +4061,19 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3627
4061
|
(openBlock(true), createElementBlock(Fragment, null, renderList(resolved.value.overlays, (overlay, i) => {
|
|
3628
4062
|
return openBlock(), createBlock(resolveDynamicComponent(overlay), { key: i });
|
|
3629
4063
|
}), 128)),
|
|
3630
|
-
|
|
4064
|
+
unref(comments).enabled.value ? (openBlock(), createBlock(flow_comments_default, {
|
|
3631
4065
|
key: 0,
|
|
4066
|
+
comments: unref(comments),
|
|
4067
|
+
markers: commentMarkers.value,
|
|
4068
|
+
messages: unref(messages),
|
|
4069
|
+
restore: restoreCommentFocus
|
|
4070
|
+
}, null, 8, [
|
|
4071
|
+
"comments",
|
|
4072
|
+
"markers",
|
|
4073
|
+
"messages"
|
|
4074
|
+
])) : createCommentVNode("", true),
|
|
4075
|
+
toolbarItems.value.length && toolbarAnchor.value ? (openBlock(), createBlock(flow_toolbar_default, {
|
|
4076
|
+
key: 1,
|
|
3632
4077
|
groups: toolbarItems.value,
|
|
3633
4078
|
anchor: toolbarAnchor.value,
|
|
3634
4079
|
size: size.value
|
|
@@ -3638,7 +4083,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
3638
4083
|
"size"
|
|
3639
4084
|
])) : createCommentVNode("", true),
|
|
3640
4085
|
findOpen.value ? (openBlock(), createElementBlock("div", {
|
|
3641
|
-
key:
|
|
4086
|
+
key: 2,
|
|
3642
4087
|
ref_key: "findBox",
|
|
3643
4088
|
ref: findBox,
|
|
3644
4089
|
class: "dou-flow-editor__find",
|