override target pos

This commit is contained in:
Mutasem 2021-11-03 18:36:27 +01:00
parent 79d47c1688
commit 61b9584266
3 changed files with 34 additions and 14 deletions

View file

@ -205,18 +205,27 @@
return totalLength;
};
this.setTargetPos = function (pos) {
this.overrideTargetPos = pos;
};
this.resetTargetPos = function () {
this.overrideTargetPos = null;
};
var _prepareCompute = function (params) {
this.strokeWidth = params.strokeWidth;
var segment = _jg.quadrant(params.sourcePos, params.targetPos),
swapX = params.targetPos[0] < params.sourcePos[0],
swapY = params.targetPos[1] < params.sourcePos[1],
const targetPos = this.overrideTargetPos || params.targetPos;
var segment = _jg.quadrant(params.sourcePos, targetPos),
swapX = targetPos[0] < params.sourcePos[0],
swapY = targetPos[1] < params.sourcePos[1],
lw = params.strokeWidth || 1,
so = params.sourceEndpoint.anchor.getOrientation(params.sourceEndpoint),
to = params.targetEndpoint.anchor.getOrientation(params.targetEndpoint),
x = swapX ? params.targetPos[0] : params.sourcePos[0],
y = swapY ? params.targetPos[1] : params.sourcePos[1],
w = Math.abs(params.targetPos[0] - params.sourcePos[0]),
h = Math.abs(params.targetPos[1] - params.sourcePos[1]);
x = swapX ? targetPos[0] : params.sourcePos[0],
y = swapY ? targetPos[1] : params.sourcePos[1],
w = Math.abs(targetPos[0] - params.sourcePos[0]),
h = Math.abs(targetPos[1] - params.sourcePos[1]);
// if either anchor does not have an orientation set, we derive one from their relative
// positions. we fix the axis to be the one in which the two elements are further apart, and
@ -225,8 +234,8 @@
var index = w > h ? 0 : 1, oIndex = [1, 0][index];
so = [];
to = [];
so[index] = params.sourcePos[index] > params.targetPos[index] ? -1 : 1;
to[index] = params.sourcePos[index] > params.targetPos[index] ? 1 : -1;
so[index] = params.sourcePos[index] > targetPos[index] ? -1 : 1;
to[index] = params.sourcePos[index] > targetPos[index] ? 1 : -1;
so[oIndex] = 0;
to[oIndex] = 0;
}

View file

@ -1479,9 +1479,13 @@ export default mixins(
return;
}
const elements = document.querySelector('.jtk-endpoint.dropHover');
if (elements) {
CanvasHelpers.showDropConnectionState(connection);
const element = document.querySelector('.jtk-endpoint.dropHover');
if (element) {
const {top, left, right, bottom} = element.getBoundingClientRect();
const x = left + (right - left) / 2;
const y = top + (bottom - top) / 2;
const pos = CanvasHelpers.getRelativePosition(x, y, this.nodeViewScale, this.$store.getters.getNodeViewOffsetPosition);
CanvasHelpers.showDropConnectionState(connection, pos);
return;
}
@ -1495,7 +1499,12 @@ export default mixins(
const nodeType = this.$store.getters.nodeType(node.type) as INodeTypeDescription;
if (nodeType.inputs.length === 1) {
this.pullConnActiveNodeName = node.name;
CanvasHelpers.showDropConnectionState(connection);
const x = left + 1;
const y = top + (bottom - top) / 2;
const pos = CanvasHelpers.getRelativePosition(x, y, this.nodeViewScale, this.$store.getters.getNodeViewOffsetPosition);
CanvasHelpers.showDropConnectionState(connection, pos);
return true;
}
}

View file

@ -539,12 +539,14 @@ export const getUniqueNodeName = (nodes: INodeUi[], originalName: string, additi
return uniqueName;
};
export const showDropConnectionState = (connection: Connection) => {
export const showDropConnectionState = (connection: Connection, targetPos: XYPosition) => {
connection.connector.setTargetPos(targetPos);
connection.setPaintStyle(CONNECTOR_PAINT_STYLE_PRIMARY);
hideOverlay(connection, OVERLAY_DROP_NODE_ID);
};
export const showPullConnectionState = (connection: Connection) => {
connection.connector.resetTargetPos();
connection.setPaintStyle(CONNECTOR_PAINT_STYLE_DEFAULT);
showOverlay(connection, OVERLAY_DROP_NODE_ID);
};