🐛 Fix bug with connections deleted when node is renamed (#2467)

* fix bug when node is renamed

* update comment

* support touch when dragging
This commit is contained in:
Mutasem Aldmour 2021-11-25 18:41:49 +01:00 committed by GitHub
parent 889921f5fe
commit 5fd3f8a244
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -74,7 +74,7 @@ export const nodeBase = mixins(
type: inputName, type: inputName,
index, index,
}, },
enabled: !this.isReadOnly, enabled: !this.isReadOnly && nodeTypeData.inputs.length > 1, // only enabled for nodes with multiple inputs.. otherwise attachment handled by connectionDrag event in NodeView
dragAllowedWhenFull: true, dragAllowedWhenFull: true,
dropOptions: { dropOptions: {
tolerance: 'touch', tolerance: 'touch',

View file

@ -1522,7 +1522,7 @@ export default mixins(
CanvasHelpers.addOverlays(connection, CanvasHelpers.CONNECTOR_DROP_NODE_OVERLAY); CanvasHelpers.addOverlays(connection, CanvasHelpers.CONNECTOR_DROP_NODE_OVERLAY);
const nodes = [...document.querySelectorAll('.node-default')]; const nodes = [...document.querySelectorAll('.node-default')];
const onMouseMove = (e: MouseEvent) => { const onMouseMove = (e: MouseEvent | TouchEvent) => {
if (!connection) { if (!connection) {
return; return;
} }
@ -1537,7 +1537,8 @@ export default mixins(
const inputMargin = 24; const inputMargin = 24;
const intersecting = nodes.find((element: Element) => { const intersecting = nodes.find((element: Element) => {
const {top, left, right, bottom} = element.getBoundingClientRect(); const {top, left, right, bottom} = element.getBoundingClientRect();
if (top <= e.pageY && bottom >= e.pageY && (left - inputMargin) <= e.pageX && right >= e.pageX) { const [x, y] = CanvasHelpers.getMousePosition(e);
if (top <= y && bottom >= y && (left - inputMargin) <= x && right >= x) {
const nodeName = (element as HTMLElement).dataset['name'] as string; const nodeName = (element as HTMLElement).dataset['name'] as string;
const node = this.$store.getters.getNodeByName(nodeName) as INodeUi | null; const node = this.$store.getters.getNodeByName(nodeName) as INodeUi | null;
if (node) { if (node) {
@ -1562,7 +1563,7 @@ export default mixins(
} }
}; };
const onMouseUp = (e: MouseEvent) => { const onMouseUp = (e: MouseEvent | TouchEvent) => {
this.pullConnActive = false; this.pullConnActive = false;
this.newNodeInsertPosition = this.getMousePositionWithinNodeView(e); this.newNodeInsertPosition = this.getMousePositionWithinNodeView(e);
CanvasHelpers.resetConnectionAfterPull(connection); CanvasHelpers.resetConnectionAfterPull(connection);
@ -1571,7 +1572,9 @@ export default mixins(
}; };
window.addEventListener('mousemove', onMouseMove); window.addEventListener('mousemove', onMouseMove);
window.addEventListener('touchmove', onMouseMove);
window.addEventListener('mouseup', onMouseUp); window.addEventListener('mouseup', onMouseUp);
window.addEventListener('touchend', onMouseMove);
} catch (e) { } catch (e) {
console.error(e); // eslint-disable-line no-console console.error(e); // eslint-disable-line no-console
} }