@dou-ui/flow 0.1.0-alpha.29 → 0.1.0-alpha.30

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.
Files changed (44) hide show
  1. package/dist/components/flow-toolbar.js.map +1 -1
  2. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js +300 -9
  3. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/export/color.js +49 -6
  5. package/dist/export/color.js.map +1 -1
  6. package/dist/export/context.js +16 -9
  7. package/dist/export/context.js.map +1 -1
  8. package/dist/export/draw.js +6 -5
  9. package/dist/export/draw.js.map +1 -1
  10. package/dist/flow-editor.js.map +1 -1
  11. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +318 -87
  12. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/locale.js +90 -3
  15. package/dist/locale.js.map +1 -1
  16. package/dist/style.css +1 -1
  17. package/dist/style.js +1 -0
  18. package/dist/types/core/menu.d.ts +55 -0
  19. package/dist/types/export/color.d.ts +6 -1
  20. package/dist/types/flow-editor.vue.d.ts +1 -1
  21. package/dist/types/index.d.ts +4 -4
  22. package/dist/types/locale.d.ts +19 -1
  23. package/dist/types/whiteboard/board-node.vue.d.ts +5 -0
  24. package/dist/types/whiteboard/colors.d.ts +36 -0
  25. package/dist/types/whiteboard/index.d.ts +2 -2
  26. package/dist/types/whiteboard/model.d.ts +22 -3
  27. package/dist/types/whiteboard/toolbar.d.ts +46 -0
  28. package/dist/whiteboard/board-node.js.map +1 -1
  29. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +50 -10
  30. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  31. package/dist/whiteboard/colors.js +84 -0
  32. package/dist/whiteboard/colors.js.map +1 -0
  33. package/dist/whiteboard/connector.js +42 -3
  34. package/dist/whiteboard/connector.js.map +1 -1
  35. package/dist/whiteboard/draw.js +26 -9
  36. package/dist/whiteboard/draw.js.map +1 -1
  37. package/dist/whiteboard/index.js +2 -1
  38. package/dist/whiteboard/kit.js +2 -0
  39. package/dist/whiteboard/kit.js.map +1 -1
  40. package/dist/whiteboard/model.js +2 -1
  41. package/dist/whiteboard/model.js.map +1 -1
  42. package/dist/whiteboard/toolbar.js +296 -0
  43. package/dist/whiteboard/toolbar.js.map +1 -0
  44. package/package.json +3 -3
@@ -44,39 +44,42 @@ var _hoisted_5 = ["data-edge-id", "data-edge-type"];
44
44
  var _hoisted_6 = ["d"];
45
45
  var _hoisted_7 = ["d"];
46
46
  var _hoisted_8 = ["d"];
47
- var _hoisted_9 = ["d"];
48
- var _hoisted_10 = ["data-edge-id", "data-value"];
49
- var _hoisted_11 = ["aria-label"];
50
- var _hoisted_12 = [
47
+ var _hoisted_9 = ["data-edge-type"];
48
+ var _hoisted_10 = ["d"];
49
+ var _hoisted_11 = ["d"];
50
+ var _hoisted_12 = ["data-edge-id", "data-value"];
51
+ var _hoisted_13 = ["aria-label"];
52
+ var _hoisted_14 = [
51
53
  "data-node-id",
52
54
  "aria-roledescription",
53
55
  "aria-label"
54
56
  ];
55
- var _hoisted_13 = {
57
+ var _hoisted_15 = {
56
58
  key: 0,
57
59
  class: "dou-flow-editor__simple-label"
58
60
  };
59
- var _hoisted_14 = {
60
- key: 1,
61
+ var _hoisted_16 = ["data-edge-id", "data-edge-end"];
62
+ var _hoisted_17 = {
63
+ key: 3,
61
64
  class: "dou-flow-editor__guides",
62
65
  "aria-hidden": "true"
63
66
  };
64
- var _hoisted_15 = [
67
+ var _hoisted_18 = [
65
68
  "x1",
66
69
  "y1",
67
70
  "x2",
68
71
  "y2"
69
72
  ];
70
- var _hoisted_16 = { class: "dou-flow-editor__ghost-card" };
71
- var _hoisted_17 = {
73
+ var _hoisted_19 = { class: "dou-flow-editor__ghost-card" };
74
+ var _hoisted_20 = {
72
75
  key: 0,
73
76
  class: "dou-flow-editor__ghost-icon"
74
77
  };
75
- var _hoisted_18 = {
78
+ var _hoisted_21 = {
76
79
  class: "dou-flow-editor__live",
77
80
  "aria-live": "polite"
78
81
  };
79
- var _hoisted_19 = {
82
+ var _hoisted_22 = {
80
83
  key: 1,
81
84
  class: "dou-flow-editor__notice",
82
85
  "aria-hidden": "true"
@@ -98,6 +101,7 @@ var PANEL_GAP = 16;
98
101
  var TIDY_NEAR = 24;
99
102
  var FIELDS = "input, textarea, [contenteditable]:not([contenteditable=\"false\"]), [data-dou-nodrag]";
100
103
  var MAGNET = 24;
104
+ /** The topmost non-container node under the pointer, if any. */
101
105
  var FIND_INSET = 12;
102
106
  var DRAW_MARGIN = 200;
103
107
  /** The part of the canvas that is drawn: the view and a margin around it. */
@@ -584,6 +588,12 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
584
588
  out.push({
585
589
  edge,
586
590
  route: edgeTypeOf(edge.type).route(a, b, edge),
591
+ source: a,
592
+ target: b,
593
+ folded: {
594
+ source: from !== edge.source,
595
+ target: to !== edge.target
596
+ },
587
597
  box: {
588
598
  x: x - EDGE_REACH,
589
599
  y: y - EDGE_REACH,
@@ -631,6 +641,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
631
641
  const bend = computed(() => {
632
642
  const { nodes, edges } = selection.value;
633
643
  if (props.readonly || nodes.length || edges.length !== 1) return null;
644
+ if (connecting.value?.edge === edges[0]) return null;
634
645
  const item = edgeRoutes.value.find((e) => e.edge.id === edges[0]);
635
646
  const handle = item?.route.handle;
636
647
  return handle && item ? {
@@ -638,6 +649,28 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
638
649
  handle
639
650
  } : null;
640
651
  });
652
+ /** The draggable endpoint handles at both ends of the one selected edge. */
653
+ const edgeHandles = computed(() => {
654
+ const { nodes, edges } = selection.value;
655
+ if (props.readonly || simple.value || nodes.length || edges.length !== 1) return null;
656
+ const id = edges[0];
657
+ if (editingLabel.value === id || connecting.value?.edge === id) return null;
658
+ const item = edgeRoutes.value.find((e) => e.edge.id === id);
659
+ if (!item) return null;
660
+ const ends = [];
661
+ if (!item.folded.source && resolvedPortEnd(item.edge.target, "target")) ends.push({
662
+ end: "source",
663
+ at: item.source
664
+ });
665
+ if (!item.folded.target && resolvedPortEnd(item.edge.source, "source")) ends.push({
666
+ end: "target",
667
+ at: item.target
668
+ });
669
+ return ends.length ? {
670
+ edge: item.edge,
671
+ ends
672
+ } : null;
673
+ });
641
674
  /** The node whose edges `E` goes through, and the one last selected. */
642
675
  let edgeCycle = null;
643
676
  /**
@@ -1410,6 +1443,27 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1410
1443
  };
1411
1444
  return;
1412
1445
  }
1446
+ const edgeEndEl = target.closest(".dou-flow-editor__edge-end");
1447
+ if (edgeEndEl && !props.readonly) {
1448
+ const edge = doc.value.edges.find((e) => e.id === edgeEndEl.dataset.edgeId);
1449
+ const end = edgeEndEl.dataset.edgeEnd;
1450
+ const link = edge && (end === "source" || end === "target") ? linkFromEdge(edge, end) : null;
1451
+ if (link) {
1452
+ gesture.value = {
1453
+ kind: "connect",
1454
+ id: event.pointerId,
1455
+ touch,
1456
+ node: null,
1457
+ start: client,
1458
+ client,
1459
+ started: false,
1460
+ link
1461
+ };
1462
+ capture(event.pointerId);
1463
+ root.value.focus({ preventScroll: true });
1464
+ return;
1465
+ }
1466
+ }
1413
1467
  const portEl = target.closest(".dou-flow-port");
1414
1468
  if (nodeEl && portEl && !props.readonly) {
1415
1469
  const link = linkFrom({
@@ -1791,8 +1845,74 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1791
1845
  const connectOptions = () => ({
1792
1846
  portTypes: portTypes.value,
1793
1847
  acyclic: props.acyclic,
1794
- canConnect: canConnect.value
1848
+ canConnect: canConnect.value ? (connection) => canConnect.value(connection, toRaw(doc.value)) : void 0
1795
1849
  });
1850
+ const sameEnd = (a, b) => a.node === b.node && a.port === b.port;
1851
+ /** Resolves an omitted `port` to the node's matching side port when available. */
1852
+ function resolveEndpoint(end, role) {
1853
+ if (end.port != null) return end;
1854
+ const node = nodeById.value.get(end.node);
1855
+ if (!node) return end;
1856
+ const kind = role === "source" ? "output" : "input";
1857
+ const side = role === "source" ? "right" : "left";
1858
+ const ports = portsOf(specOf(node), node).filter((p) => p.kind === kind);
1859
+ const match = ports.find((p) => portSide(p) === side) ?? ports[0];
1860
+ return match ? {
1861
+ node: end.node,
1862
+ port: match.id
1863
+ } : end;
1864
+ }
1865
+ /** Resolves an endpoint to a concrete port that currently exists with the matching direction. */
1866
+ function resolvedPortEnd(end, role) {
1867
+ const next = resolveEndpoint(end, role);
1868
+ if (next.port == null) return null;
1869
+ const spec = portSpec(next);
1870
+ if (!spec || spec.kind !== (role === "source" ? "output" : "input")) return null;
1871
+ return next;
1872
+ }
1873
+ /** Document view with omitted edge ports resolved to concrete side ports for join checks. */
1874
+ function connectDoc() {
1875
+ const raw = toRaw(doc.value);
1876
+ if (raw.edges.every((e) => e.source.port != null && e.target.port != null)) return raw;
1877
+ return {
1878
+ ...raw,
1879
+ edges: raw.edges.map((e) => {
1880
+ const source = resolveEndpoint(e.source, "source");
1881
+ const target = resolveEndpoint(e.target, "target");
1882
+ return source === e.source && target === e.target ? e : {
1883
+ ...e,
1884
+ source,
1885
+ target
1886
+ };
1887
+ })
1888
+ };
1889
+ }
1890
+ /** Picks up either end of an existing edge so it can be reconnected or disconnected. */
1891
+ function linkFromEdge(edge, moving) {
1892
+ const fixedRole = moving === "target" ? "source" : "target";
1893
+ const rawFixed = edge[fixedRole];
1894
+ const rawMoving = edge[moving];
1895
+ const fixed = resolvedPortEnd(rawFixed, fixedRole);
1896
+ if (!fixed) return null;
1897
+ const point = anchorOf(edgeEnd(rawMoving), moving);
1898
+ if (!point) return null;
1899
+ const base = {
1900
+ fixed,
1901
+ fixedRaw: rawFixed.port == null ? rawFixed : void 0,
1902
+ moving,
1903
+ edge: edge.id,
1904
+ point,
1905
+ candidate: null
1906
+ };
1907
+ const valid = validEnds(base);
1908
+ const resolvedMoving = resolveEndpoint(rawMoving, moving);
1909
+ const candidate = resolvedMoving.port != null && valid.get(resolvedMoving.node)?.has(resolvedMoving.port) ? resolvedMoving : null;
1910
+ return {
1911
+ ...base,
1912
+ candidate,
1913
+ valid
1914
+ };
1915
+ }
1796
1916
  /**
1797
1917
  * Starts an edge at a port. From an output, or an empty input, it draws a
1798
1918
  * new edge; from an input that has an edge, it picks that edge up.
@@ -1805,8 +1925,9 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1805
1925
  if (port.kind === "input") {
1806
1926
  for (const e of doc.value.edges) if (e.target.node === at.node && e.target.port === at.port) taken = e;
1807
1927
  }
1808
- if (taken && taken.source.port != null) link = {
1809
- fixed: taken.source,
1928
+ const fixed = taken && taken.source.port != null ? resolvedPortEnd(taken.source, "source") : null;
1929
+ if (taken && fixed) link = {
1930
+ fixed,
1810
1931
  moving: "target",
1811
1932
  edge: taken.id,
1812
1933
  point: anchorOf(at, "target") ?? {
@@ -1840,11 +1961,16 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1840
1961
  const valid = /* @__PURE__ */ new Map();
1841
1962
  const fixedPort = portSpec(link.fixed);
1842
1963
  if (!fixedPort) return valid;
1964
+ const fixed = link.fixed;
1965
+ const normalized = connectDoc();
1843
1966
  const options = connectOptions();
1844
1967
  for (const node of doc.value.nodes) {
1845
1968
  const ids = /* @__PURE__ */ new Set();
1846
1969
  for (const port of portsOf(specOf(node), node)) {
1847
- const connection = connectionOf(link, {
1970
+ const connection = connectionOf({
1971
+ fixed,
1972
+ moving: link.moving
1973
+ }, {
1848
1974
  node: node.id,
1849
1975
  port: port.id
1850
1976
  });
@@ -1855,13 +1981,33 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1855
1981
  source: port,
1856
1982
  target: fixedPort
1857
1983
  };
1858
- if (canJoin(toRaw(doc.value), connection, ports, options, link.edge)) ids.add(port.id);
1984
+ if (canJoin(normalized, connection, ports, options, link.edge)) ids.add(port.id);
1859
1985
  }
1860
1986
  if (ids.size) valid.set(node.id, ids);
1861
1987
  }
1862
1988
  return valid;
1863
1989
  }
1864
1990
  /** How close, in screen px, the pointer must come to a port to snap to it. */
1991
+ function nodeUnderLink(point, client) {
1992
+ const under = (root.value?.getRootNode())?.elementFromPoint?.(client.x, client.y);
1993
+ const hit = under && root.value?.contains(under) ? under.closest("[data-node-id]")?.dataset.nodeId : void 0;
1994
+ if (hit) {
1995
+ const node = nodeById.value.get(hit);
1996
+ if (node && !isContainer(node) && !hiddenIn.value.has(node.id)) return node.id;
1997
+ }
1998
+ for (let i = doc.value.nodes.length - 1; i >= 0; i--) {
1999
+ const node = doc.value.nodes[i];
2000
+ if (isContainer(node) || hiddenIn.value.has(node.id)) continue;
2001
+ const r = rectOf(node);
2002
+ const rot = nodeRotation(node.id);
2003
+ const p = rot ? turn(point, {
2004
+ x: r.x + r.width / 2,
2005
+ y: r.y + r.height / 2
2006
+ }, -rot) : point;
2007
+ if (p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height) return node.id;
2008
+ }
2009
+ return null;
2010
+ }
1865
2011
  function updateLink(g) {
1866
2012
  const link = g.link;
1867
2013
  const point = toCanvas(g.client);
@@ -1883,37 +2029,51 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1883
2029
  };
1884
2030
  };
1885
2031
  for (const [node, ports] of link.valid) for (const port of ports) consider(node, port, radius);
1886
- if (!best) {
1887
- const over = document.elementFromPoint(g.client.x, g.client.y)?.closest("[data-node-id]")?.dataset.nodeId;
1888
- for (const port of over && link.valid.get(over) || []) consider(over, port, Infinity);
1889
- }
2032
+ const over = nodeUnderLink(point, g.client);
2033
+ if (!best && over) for (const port of link.valid.get(over) || []) consider(over, port, Infinity);
1890
2034
  const candidate = best?.end ?? null;
1891
2035
  g.link = {
1892
2036
  ...link,
1893
2037
  point,
1894
2038
  candidate,
1895
- refused: candidate ? null : refusedAt(link, point, radius)
2039
+ over: candidate ? null : over,
2040
+ refused: candidate ? null : refusedAt(link, point, radius, over)
1896
2041
  };
1897
2042
  gesture.value = { ...g };
1898
2043
  }
1899
- /** The nearest port within `radius` of `point` that the link can't land on, and why. */
1900
- function refusedAt(link, point, radius) {
2044
+ /** The nearest port within `radius` (or on the hovered node) that the link can't land on, and why. */
2045
+ function refusedAt(link, point, radius, over) {
1901
2046
  const fixedPort = portSpec(link.fixed);
1902
2047
  if (!fixedPort) return null;
2048
+ const fixed = link.fixed;
2049
+ const wantedKind = link.moving === "target" ? "input" : "output";
1903
2050
  let best = null;
1904
- for (const node of doc.value.nodes) for (const port of portsOf(specOf(node), node)) {
1905
- if (link.valid.get(node.id)?.has(port.id)) continue;
1906
- const end = {
1907
- node: node.id,
1908
- port: port.id
1909
- };
1910
- if (end.node === link.fixed.node && end.port === link.fixed.port) continue;
1911
- const at = anchorOf(end, link.moving);
1912
- const d = at ? Math.hypot(at.x - point.x, at.y - point.y) : Infinity;
1913
- if (d <= radius && (!best || d < best.d)) best = {
1914
- end,
1915
- d
1916
- };
2051
+ const checkNode = (node, limit) => {
2052
+ for (const port of portsOf(specOf(node), node)) {
2053
+ if (link.valid.get(node.id)?.has(port.id)) continue;
2054
+ const end = {
2055
+ node: node.id,
2056
+ port: port.id
2057
+ };
2058
+ if (end.node === fixed.node && end.port === fixed.port) continue;
2059
+ const at = anchorOf(end, link.moving);
2060
+ const d = at ? Math.hypot(at.x - point.x, at.y - point.y) : Infinity;
2061
+ if (d > limit) continue;
2062
+ const matchKind = port.kind === wantedKind;
2063
+ if (!best || matchKind && !best.matchKind || matchKind === best.matchKind && d < best.d) best = {
2064
+ end,
2065
+ d,
2066
+ matchKind
2067
+ };
2068
+ }
2069
+ };
2070
+ for (const node of doc.value.nodes) {
2071
+ if (hiddenIn.value.has(node.id)) continue;
2072
+ checkNode(node, radius);
2073
+ }
2074
+ if (!best && over) {
2075
+ const node = nodeById.value.get(over);
2076
+ if (node && !isContainer(node) && !hiddenIn.value.has(node.id)) checkNode(node, Infinity);
1917
2077
  }
1918
2078
  if (!best) return null;
1919
2079
  const { end } = best;
@@ -1925,7 +2085,10 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1925
2085
  source: port,
1926
2086
  target: fixedPort
1927
2087
  };
1928
- const refusal = joinRefusal(toRaw(doc.value), connectionOf(link, end), ports, connectOptions(), link.edge);
2088
+ const refusal = joinRefusal(connectDoc(), connectionOf({
2089
+ fixed,
2090
+ moving: link.moving
2091
+ }, end), ports, connectOptions(), link.edge);
1929
2092
  return refusal && {
1930
2093
  end,
1931
2094
  refusal
@@ -1936,26 +2099,18 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1936
2099
  if (refusal.reason === "custom") return refusal.message ?? messages.value.refused.custom;
1937
2100
  return messages.value.refused[refusal.reason];
1938
2101
  }
1939
- /** Whether a link was let go over a node other than its own. */
1940
- function overNode(link) {
1941
- const { x, y } = link.point;
1942
- return doc.value.nodes.some((node) => {
1943
- if (node.id === link.fixed.node || isContainer(node)) return false;
1944
- const r = rectOf(node);
1945
- return x >= r.x && x <= r.x + r.width && y >= r.y && y <= r.y + r.height;
1946
- });
1947
- }
1948
- /** Adds the edge a link describes, replacing what it must. */
2102
+ /** Adds or updates the edge a link describes, replacing what it must. */
1949
2103
  function finishLink(link, event) {
1950
2104
  const { candidate } = link;
1951
2105
  if (!candidate) {
1952
2106
  if (link.refused) announce(refusalText(link.refused.refusal));
1953
- else if (!link.edge && overNode(link)) announce(messages.value.noTarget);
2107
+ else if (link.over) announce(link.over === link.fixed.node ? messages.value.refused.self : messages.value.noTarget);
1954
2108
  else if (link.edge) {
1955
2109
  const id = link.edge;
1956
- transact((tr) => tr.removeEdge(id));
2110
+ if (transact((t) => t.removeEdge(id)).changed) announce(format(messages.value.deleted, { count: 1 }));
1957
2111
  } else if (event) {
1958
- emit("connectToCanvas", link.fixed, link.point, event);
2112
+ const from = link.fixed;
2113
+ emit("connectToCanvas", from, link.point, event);
1959
2114
  if (!event.defaultPrevented && paletteTypes.value.length) quickAdd.value = {
1960
2115
  link,
1961
2116
  at: link.point,
@@ -1963,31 +2118,56 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1963
2118
  x: event.clientX,
1964
2119
  y: event.clientY
1965
2120
  },
1966
- types: typesTaking(link.fixed),
2121
+ types: typesTaking(from),
1967
2122
  touch: event.pointerType === "touch"
1968
2123
  };
1969
2124
  }
1970
2125
  return;
1971
2126
  }
1972
- const connection = connectionOf(link, candidate);
2127
+ const fixed = link.fixed;
2128
+ const connection = connectionOf({
2129
+ fixed,
2130
+ moving: link.moving
2131
+ }, candidate);
1973
2132
  const source = portSpec(connection.source);
1974
2133
  const target = portSpec(connection.target);
2134
+ const displaced = source && target ? displacedEdges(connectDoc(), connection, {
2135
+ source,
2136
+ target
2137
+ }, link.edge) : [];
2138
+ if (link.edge) {
2139
+ const existing = doc.value.edges.find((e) => e.id === link.edge);
2140
+ if (!existing) return;
2141
+ const originalSource = resolveEndpoint(existing.source, "source");
2142
+ const originalTarget = resolveEndpoint(existing.target, "target");
2143
+ if (sameEnd(originalSource, connection.source) && sameEnd(originalTarget, connection.target)) return;
2144
+ const patch = {
2145
+ ...link.moving === "source" ? { source: candidate } : { target: candidate },
2146
+ ...existing.points ? { points: void 0 } : {}
2147
+ };
2148
+ const tr = transact((t) => {
2149
+ for (const id of displaced) t.removeEdge(id);
2150
+ t.updateEdge(existing.id, patch);
2151
+ });
2152
+ const updated = tr.doc.edges.find((e) => e.id === existing.id);
2153
+ if (tr.changed && updated) {
2154
+ emit("connect", updated);
2155
+ announce(messages.value.connected);
2156
+ }
2157
+ return;
2158
+ }
1975
2159
  const edge = {
1976
2160
  id: createId("e"),
1977
2161
  source: connection.source,
1978
2162
  target: connection.target
1979
2163
  };
1980
- const displaced = source && target ? displacedEdges(toRaw(doc.value), connection, {
1981
- source,
1982
- target
1983
- }, link.edge) : [];
1984
- transact((tr) => {
1985
- if (link.edge) tr.removeEdge(link.edge);
1986
- for (const id of displaced) tr.removeEdge(id);
1987
- tr.addEdge(edge);
1988
- });
1989
- emit("connect", edge);
1990
- announce(messages.value.connected);
2164
+ if (transact((t) => {
2165
+ for (const id of displaced) t.removeEdge(id);
2166
+ t.addEdge(edge);
2167
+ }).changed) {
2168
+ emit("connect", edge);
2169
+ announce(messages.value.connected);
2170
+ }
1991
2171
  }
1992
2172
  /** What the canvas shows while an edge is being drawn, by mouse, touch or keyboard. */
1993
2173
  const connecting = computed(() => {
@@ -1995,11 +2175,11 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
1995
2175
  if (g?.kind === "connect" && g.started) return g.link;
1996
2176
  return keyLink.value;
1997
2177
  });
1998
- const previewPath = computed(() => {
2178
+ const previewEdge = computed(() => {
1999
2179
  const link = connecting.value ?? quickAdd.value?.link;
2000
2180
  if (!link) return null;
2001
2181
  const fixedRole = link.moving === "target" ? "source" : "target";
2002
- const a = anchorOf(link.fixed, fixedRole);
2182
+ const a = anchorOf(edgeEnd(link.fixedRaw ?? link.fixed), fixedRole);
2003
2183
  if (!a) return null;
2004
2184
  const c = link.candidate && anchorOf(link.candidate, link.moving);
2005
2185
  const opposite = {
@@ -2012,10 +2192,27 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2012
2192
  ...link.point,
2013
2193
  side: opposite[a.side]
2014
2194
  };
2015
- const moved = link.edge ? doc.value.edges.find((e) => e.id === link.edge) : void 0;
2016
- const route = edgeTypeOf(moved?.type).route;
2017
- return (link.moving === "target" ? route(a, b, moved) : route(b, a, moved)).path;
2195
+ const existing = link.edge ? doc.value.edges.find((e) => e.id === link.edge) : void 0;
2196
+ const moved = existing?.points ? {
2197
+ ...existing,
2198
+ points: void 0
2199
+ } : existing;
2200
+ const spec = edgeTypeOf(moved?.type);
2201
+ const route = link.moving === "target" ? spec.route(a, b, moved) : spec.route(b, a, moved);
2202
+ return {
2203
+ type: spec.type,
2204
+ route,
2205
+ style: moved ? edgeStyle(moved) : void 0,
2206
+ reconnecting: !!link.edge,
2207
+ detaching: !!link.edge && !link.candidate && !link.refused && !link.over,
2208
+ snapped: !!link.edge && !!link.candidate,
2209
+ end: {
2210
+ x: b.x,
2211
+ y: b.y
2212
+ }
2213
+ };
2018
2214
  });
2215
+ const previewPath = computed(() => previewEdge.value?.route.path ?? null);
2019
2216
  /** How each port looks while connecting: by node, then port. */
2020
2217
  const portStates = computed(() => {
2021
2218
  const link = connecting.value;
@@ -2036,7 +2233,6 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2036
2233
  return states;
2037
2234
  });
2038
2235
  const keyLink = shallowRef(null);
2039
- /** Valid ends of a link, nearest first. */
2040
2236
  /** A port's anchor; nodes not measured yet fall back to their corner. */
2041
2237
  function place(end, role) {
2042
2238
  return anchorOf(end, role) ?? nodeById.value.get(end.node) ?? {
@@ -2044,6 +2240,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2044
2240
  y: 0
2045
2241
  };
2046
2242
  }
2243
+ /** Valid ends of a link, nearest first. */
2047
2244
  function rankEnds(link) {
2048
2245
  const at = place(link.fixed, link.moving === "target" ? "source" : "target");
2049
2246
  const ends = [];
@@ -2521,7 +2718,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2521
2718
  const pendingAdd = quickAdd.value;
2522
2719
  quickAdd.value = null;
2523
2720
  if (!pendingAdd) return;
2524
- if (type) insertNode(type, {
2721
+ if (type && pendingAdd.link.fixed.port != null) insertNode(type, {
2525
2722
  at: pendingAdd.at,
2526
2723
  from: pendingAdd.link.fixed
2527
2724
  });
@@ -2675,7 +2872,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2675
2872
  return;
2676
2873
  } else if (g.kind === "connect") {
2677
2874
  if (g.started) finishLink(g.link, event);
2678
- else setSelection({
2875
+ else if (g.node) setSelection({
2679
2876
  nodes: [g.node],
2680
2877
  edges: []
2681
2878
  });
@@ -2771,11 +2968,13 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
2771
2968
  return false;
2772
2969
  }
2773
2970
  function onDblclick(event) {
2774
- const nodeEl = event.target.closest("[data-node-id]");
2971
+ const target = event.target;
2972
+ if (target.closest(".dou-flow-editor__edge-end")) return;
2973
+ const nodeEl = target.closest("[data-node-id]");
2775
2974
  const node = nodeEl && nodeById.value.get(nodeEl.dataset.nodeId);
2776
2975
  if (node) emit("nodeDblclick", node, event);
2777
2976
  else {
2778
- const edgeEl = event.target.closest("[data-edge-id]");
2977
+ const edgeEl = target.closest("[data-edge-id]");
2779
2978
  if (edgeEl) editLabel(edgeEl.getAttribute("data-edge-id"));
2780
2979
  }
2781
2980
  }
@@ -3036,8 +3235,9 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
3036
3235
  const nodeEl = target.closest("[data-node-id]");
3037
3236
  if (nodeEl && nodeEl !== target) return;
3038
3237
  if (keyLink.value) return onKeyLink(event);
3039
- if (event.key === "Escape" && gesture.value?.kind === "press") {
3238
+ if (event.key === "Escape" && (gesture.value?.kind === "press" || gesture.value?.kind === "connect")) {
3040
3239
  event.preventDefault();
3240
+ event.stopPropagation();
3041
3241
  endGesture();
3042
3242
  return;
3043
3243
  }
@@ -3422,7 +3622,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
3422
3622
  "is-space": spaceHeld.value,
3423
3623
  "is-dragging": !!dragging.value,
3424
3624
  "is-connecting": !!connecting.value,
3425
- "is-refused": !!connecting.value?.refused,
3625
+ "is-refused": !!connecting.value && (!!connecting.value.refused || !connecting.value.candidate && !!connecting.value.over),
3426
3626
  "is-bordered": props.bordered
3427
3627
  }));
3428
3628
  const context = {
@@ -3958,11 +4158,25 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
3958
4158
  d: item.route.marks
3959
4159
  }, null, 14, _hoisted_8)) : createCommentVNode("", true)
3960
4160
  ], 8, _hoisted_5);
3961
- }), 128)), previewPath.value ? (openBlock(), createElementBlock("path", {
4161
+ }), 128)), previewEdge.value ? (openBlock(), createElementBlock("g", {
4162
+ key: 0,
4163
+ "data-edge-type": previewEdge.value.type
4164
+ }, [createElementVNode("path", {
4165
+ class: normalizeClass(["dou-flow-editor__edge is-preview", {
4166
+ "is-detaching": previewEdge.value.detaching,
4167
+ "is-snapped": previewEdge.value.snapped
4168
+ }]),
4169
+ style: normalizeStyle(previewEdge.value.snapped ? previewEdge.value.style : void 0),
4170
+ d: previewEdge.value.route.path
4171
+ }, null, 14, _hoisted_10), previewEdge.value.route.marks ? (openBlock(), createElementBlock("path", {
3962
4172
  key: 0,
3963
- class: "dou-flow-editor__edge is-preview",
3964
- d: previewPath.value
3965
- }, null, 8, _hoisted_9)) : createCommentVNode("", true)])),
4173
+ class: normalizeClass(["dou-flow-editor__edge is-preview is-mark", {
4174
+ "is-detaching": previewEdge.value.detaching,
4175
+ "is-snapped": previewEdge.value.snapped
4176
+ }]),
4177
+ style: normalizeStyle(previewEdge.value.snapped ? previewEdge.value.style : void 0),
4178
+ d: previewEdge.value.route.marks
4179
+ }, null, 14, _hoisted_11)) : createCommentVNode("", true)], 8, _hoisted_9)) : createCommentVNode("", true)])),
3966
4180
  (openBlock(true), createElementBlock(Fragment, null, renderList(edgeLabels.value, (item) => {
3967
4181
  return openBlock(), createElementBlock("div", {
3968
4182
  key: item.edge.id,
@@ -3980,7 +4194,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
3980
4194
  "aria-label": unref(messages).label,
3981
4195
  onKeydown: onLabelKeydown,
3982
4196
  onBlur: _cache[1] || (_cache[1] = ($event) => finishLabel(true))
3983
- }, null, 40, _hoisted_11)), [[vModelText, labelDraft.value]]) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(item.edge.label), 1)], 64))], 14, _hoisted_10);
4197
+ }, null, 40, _hoisted_13)), [[vModelText, labelDraft.value]]) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(item.edge.label), 1)], 64))], 14, _hoisted_12);
3984
4198
  }), 128)),
3985
4199
  bend.value && !bend.value.edge.label && editingLabel.value !== bend.value.edge.id ? (openBlock(), createElementBlock("div", {
3986
4200
  key: 0,
@@ -4005,7 +4219,7 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4005
4219
  "aria-roledescription": roleOf(node),
4006
4220
  "aria-label": nameOf(node),
4007
4221
  tabindex: "-1"
4008
- }, [renderSlot(_ctx.$slots, "simple", { node }, () => [viewport.value.zoom >= TINY ? (openBlock(), createElementBlock("span", _hoisted_13, toDisplayString(unref(labelOf)(specOf(node), node, unref(messages))), 1)) : createCommentVNode("", true)])], 14, _hoisted_12)) : (openBlock(), createBlock(node_view_default, {
4222
+ }, [renderSlot(_ctx.$slots, "simple", { node }, () => [viewport.value.zoom >= TINY ? (openBlock(), createElementBlock("span", _hoisted_15, toDisplayString(unref(labelOf)(specOf(node), node, unref(messages))), 1)) : createCommentVNode("", true)])], 14, _hoisted_14)) : (openBlock(), createBlock(node_view_default, {
4009
4223
  key: 1,
4010
4224
  node,
4011
4225
  spec: specOf(node),
@@ -4034,17 +4248,34 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4034
4248
  "drop-target"
4035
4249
  ]))], 64);
4036
4250
  }), 128)),
4251
+ edgeHandles.value ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(edgeHandles.value.ends, (item) => {
4252
+ return openBlock(), createElementBlock("div", {
4253
+ key: `${edgeHandles.value.edge.id}-${item.end}`,
4254
+ class: normalizeClass(["dou-flow-editor__edge-end", `is-${item.end}`]),
4255
+ style: normalizeStyle({ translate: `calc(${item.at.x}px - 50%) calc(${item.at.y}px - 50%)` }),
4256
+ "data-edge-id": edgeHandles.value.edge.id,
4257
+ "data-edge-end": item.end,
4258
+ "data-flow-handle": "",
4259
+ "aria-hidden": "true"
4260
+ }, null, 14, _hoisted_16);
4261
+ }), 128)) : createCommentVNode("", true),
4262
+ previewEdge.value?.reconnecting && !previewEdge.value.snapped ? (openBlock(), createElementBlock("div", {
4263
+ key: 2,
4264
+ class: normalizeClass(["dou-flow-editor__edge-end is-dragging", { "is-detaching": previewEdge.value.detaching }]),
4265
+ style: normalizeStyle({ translate: `calc(${previewEdge.value.end.x}px - 50%) calc(${previewEdge.value.end.y}px - 50%)` }),
4266
+ "aria-hidden": "true"
4267
+ }, null, 6)) : createCommentVNode("", true),
4037
4268
  (openBlock(true), createElementBlock(Fragment, null, renderList(resolved.value.above, (layer, i) => {
4038
4269
  return openBlock(), createBlock(resolveDynamicComponent(layer), { key: `above-${i}` });
4039
4270
  }), 128)),
4040
- guides.value.length ? (openBlock(), createElementBlock("svg", _hoisted_14, [(openBlock(true), createElementBlock(Fragment, null, renderList(guides.value, (guide, i) => {
4271
+ guides.value.length ? (openBlock(), createElementBlock("svg", _hoisted_17, [(openBlock(true), createElementBlock(Fragment, null, renderList(guides.value, (guide, i) => {
4041
4272
  return openBlock(), createElementBlock("line", {
4042
4273
  key: i,
4043
4274
  x1: guide.axis === "x" ? guide.at : guide.from,
4044
4275
  y1: guide.axis === "x" ? guide.from : guide.at,
4045
4276
  x2: guide.axis === "x" ? guide.at : guide.to,
4046
4277
  y2: guide.axis === "x" ? guide.to : guide.at
4047
- }, null, 8, _hoisted_15);
4278
+ }, null, 8, _hoisted_18);
4048
4279
  }), 128))])) : createCommentVNode("", true)
4049
4280
  ], 4),
4050
4281
  marquee.value ? (openBlock(), createElementBlock("div", {
@@ -4148,15 +4379,15 @@ var flow_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4148
4379
  }, [renderSlot(_ctx.$slots, "ghost", {
4149
4380
  spec: insertDrag.value.spec,
4150
4381
  over: insertDrag.value.over
4151
- }, () => [createElementVNode("span", _hoisted_16, [insertDrag.value.spec.palette?.icon ? (openBlock(), createElementBlock("span", _hoisted_17, [(openBlock(), createBlock(resolveDynamicComponent(insertDrag.value.spec.palette.icon)))])) : createCommentVNode("", true), createTextVNode(" " + toDisplayString(insertDrag.value.spec.palette?.label ?? insertDrag.value.spec.type), 1)])])], 6)) : createCommentVNode("", true)])),
4382
+ }, () => [createElementVNode("span", _hoisted_19, [insertDrag.value.spec.palette?.icon ? (openBlock(), createElementBlock("span", _hoisted_20, [(openBlock(), createBlock(resolveDynamicComponent(insertDrag.value.spec.palette.icon)))])) : createCommentVNode("", true), createTextVNode(" " + toDisplayString(insertDrag.value.spec.palette?.label ?? insertDrag.value.spec.type), 1)])])], 6)) : createCommentVNode("", true)])),
4152
4383
  createElementVNode("span", {
4153
4384
  ref_key: "end",
4154
4385
  ref: end,
4155
4386
  class: "dou-flow-editor__end",
4156
4387
  tabindex: "-1"
4157
4388
  }, null, 512),
4158
- createElementVNode("div", _hoisted_18, toDisplayString(live.value), 1),
4159
- notice.value ? (openBlock(), createElementBlock("div", _hoisted_19, toDisplayString(notice.value), 1)) : createCommentVNode("", true)
4389
+ createElementVNode("div", _hoisted_21, toDisplayString(live.value), 1),
4390
+ notice.value ? (openBlock(), createElementBlock("div", _hoisted_22, toDisplayString(notice.value), 1)) : createCommentVNode("", true)
4160
4391
  ], 46, _hoisted_1);
4161
4392
  };
4162
4393
  }