Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d0cb0262f | |||
| f49c931b7e | |||
| 193386003f | |||
| 9a3795ec2c | |||
| 5834e9f11f | |||
| 50749b8119 | |||
| 3b0a6af46f | |||
| 3b99b7aba2 | |||
| 84f087633e |
@@ -27,6 +27,7 @@ import type {
|
||||
ElementsMap,
|
||||
ExcalidrawArrowElement,
|
||||
ExcalidrawBindableElement,
|
||||
FixedPointBinding,
|
||||
NonDeletedSceneElementsMap,
|
||||
PointsPositionUpdates,
|
||||
} from "../types";
|
||||
@@ -110,10 +111,17 @@ const focusPointUpdate = (
|
||||
) => {
|
||||
const pointUpdates = new Map();
|
||||
|
||||
const originalAdjacentBinding =
|
||||
appState.selectedLinearElement?.initialState
|
||||
.arrowOtherEndpointInitialBinding;
|
||||
const bindingField = isStartBinding ? "startBinding" : "endBinding";
|
||||
const adjacentBindingField = isStartBinding ? "endBinding" : "startBinding";
|
||||
let currentBinding = arrow[bindingField];
|
||||
let adjacentBinding = arrow[adjacentBindingField];
|
||||
let adjacentBinding =
|
||||
originalAdjacentBinding?.mode === "orbit" &&
|
||||
arrow[adjacentBindingField]?.mode === "inside"
|
||||
? originalAdjacentBinding
|
||||
: arrow[adjacentBindingField];
|
||||
|
||||
// Update the dragged focus point related end
|
||||
if (currentBinding && bindableElement) {
|
||||
@@ -125,7 +133,7 @@ const focusPointUpdate = (
|
||||
if (switchToInsideBinding || boundToSameElement) {
|
||||
currentBinding = {
|
||||
...currentBinding,
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
};
|
||||
} else {
|
||||
currentBinding = {
|
||||
@@ -163,10 +171,10 @@ const focusPointUpdate = (
|
||||
// Same shape bound on both ends
|
||||
const boundToSameElementAfterUpdate =
|
||||
bindableElement && adjacentBinding.elementId === bindableElement.id;
|
||||
if (switchToInsideBinding || boundToSameElementAfterUpdate) {
|
||||
if (boundToSameElementAfterUpdate) {
|
||||
adjacentBinding = {
|
||||
...adjacentBinding,
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
};
|
||||
} else {
|
||||
adjacentBinding = {
|
||||
@@ -256,8 +264,8 @@ export const handleFocusPointDrag = (
|
||||
// Handle binding mode switch
|
||||
const newMode =
|
||||
switchToInsideBinding && arrow[bindingField]?.mode === "orbit"
|
||||
? "fixed"
|
||||
: !switchToInsideBinding && arrow[bindingField]?.mode === "fixed"
|
||||
? "inside"
|
||||
: !switchToInsideBinding && arrow[bindingField]?.mode === "inside"
|
||||
? "orbit"
|
||||
: null;
|
||||
|
||||
@@ -339,6 +347,7 @@ export const handleFocusPointPointerDown = (
|
||||
): {
|
||||
hitFocusPoint: "start" | "end" | null;
|
||||
pointerOffset: { x: number; y: number };
|
||||
arrowOtherEndpointInitialBinding: FixedPointBinding | null;
|
||||
} => {
|
||||
const pointerPos = pointFrom(
|
||||
pointerDownState.origin.x,
|
||||
@@ -376,6 +385,7 @@ export const handleFocusPointPointerDown = (
|
||||
x: pointerPos[0] - focusPoint[0],
|
||||
y: pointerPos[1] - focusPoint[1],
|
||||
},
|
||||
arrowOtherEndpointInitialBinding: arrow.endBinding,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -411,6 +421,7 @@ export const handleFocusPointPointerDown = (
|
||||
x: pointerPos[0] - focusPoint[0],
|
||||
y: pointerPos[1] - focusPoint[1],
|
||||
},
|
||||
arrowOtherEndpointInitialBinding: arrow.startBinding,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -419,13 +430,14 @@ export const handleFocusPointPointerDown = (
|
||||
return {
|
||||
hitFocusPoint: null,
|
||||
pointerOffset: { x: 0, y: 0 },
|
||||
arrowOtherEndpointInitialBinding: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const handleFocusPointPointerUp = (
|
||||
linearElementEditor: LinearElementEditor,
|
||||
scene: Scene,
|
||||
) => {
|
||||
): { arrowOtherEndpointInitialBinding: FixedPointBinding | null } => {
|
||||
invariant(
|
||||
linearElementEditor.draggedFocusPointBinding,
|
||||
"Must have a dragged focus point at pointer release",
|
||||
@@ -483,6 +495,10 @@ export const handleFocusPointPointerUp = (
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
arrowOtherEndpointInitialBinding: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const handleFocusPointHover = (
|
||||
|
||||
@@ -328,7 +328,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
if (hit) {
|
||||
start = {
|
||||
element: hit,
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
focusPoint: point,
|
||||
};
|
||||
} else {
|
||||
@@ -353,13 +353,13 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
start: isMultiPoint
|
||||
? { mode: undefined }
|
||||
: {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: origin ?? center,
|
||||
},
|
||||
end: isMultiPoint
|
||||
? { mode: "orbit", element: hit, focusPoint: point }
|
||||
: { mode: "fixed", element: hit, focusPoint: point },
|
||||
: { mode: "inside", element: hit, focusPoint: point },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
start: isMultiPoint
|
||||
? { mode: undefined }
|
||||
: {
|
||||
mode: otherElement.id !== hit.id ? "orbit" : "fixed",
|
||||
mode: otherElement.id !== hit.id ? "orbit" : "inside",
|
||||
element: otherElement,
|
||||
focusPoint: origin ?? pointFrom<GlobalPoint>(arrow.x, arrow.y),
|
||||
},
|
||||
@@ -402,7 +402,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
const otherIsInsideBinding =
|
||||
!!appState.selectedLinearElement?.initialState.arrowStartIsInside;
|
||||
const other: BindingStrategy = {
|
||||
mode: otherIsInsideBinding ? "fixed" : "orbit",
|
||||
mode: otherIsInsideBinding ? "inside" : "orbit",
|
||||
element: otherElement,
|
||||
focusPoint: shiftKey
|
||||
? elementCenterPoint(otherElement, elementsMap)
|
||||
@@ -416,9 +416,9 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
let current: BindingStrategy;
|
||||
if (hit) {
|
||||
const isInsideBinding =
|
||||
globalBindMode === "fixed" || globalBindMode === "skip";
|
||||
globalBindMode === "inside" || globalBindMode === "skip";
|
||||
current = {
|
||||
mode: isInsideBinding && !isNested ? "fixed" : "orbit",
|
||||
mode: isInsideBinding && !isNested ? "inside" : "orbit",
|
||||
element: hit,
|
||||
focusPoint: isInsideBinding || isNested ? point : point,
|
||||
};
|
||||
@@ -436,10 +436,10 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
||||
if (!arrow.startBinding) {
|
||||
if (hit) {
|
||||
const isInsideBinding =
|
||||
globalBindMode === "fixed" || globalBindMode === "skip";
|
||||
globalBindMode === "inside" || globalBindMode === "skip";
|
||||
|
||||
end = {
|
||||
mode: isInsideBinding ? "fixed" : "orbit",
|
||||
mode: isInsideBinding ? "inside" : "orbit",
|
||||
element: hit,
|
||||
focusPoint: point,
|
||||
};
|
||||
@@ -488,7 +488,7 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
||||
|
||||
// If the global bind mode is in free binding mode, just bind
|
||||
// where the pointer is and keep the other end intact
|
||||
if (globalBindMode === "fixed" || globalBindMode === "skip") {
|
||||
if (globalBindMode === "inside" || globalBindMode === "skip") {
|
||||
current = hit
|
||||
? {
|
||||
element:
|
||||
@@ -496,7 +496,7 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
||||
? hit
|
||||
: oppositeElement,
|
||||
focusPoint: point,
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
}
|
||||
: { mode: null };
|
||||
other =
|
||||
@@ -514,9 +514,12 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
||||
}
|
||||
|
||||
// Already inside binding over the same hit element should remain inside bound
|
||||
if (hit.id === currentBinding?.elementId && currentBinding.mode === "fixed") {
|
||||
if (
|
||||
hit.id === currentBinding?.elementId &&
|
||||
currentBinding.mode === "inside"
|
||||
) {
|
||||
return {
|
||||
current: { mode: "fixed", focusPoint: point, element: hit },
|
||||
current: { mode: "inside", focusPoint: point, element: hit },
|
||||
other,
|
||||
};
|
||||
}
|
||||
@@ -535,7 +538,7 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
||||
// The opposite binding is inside the same element
|
||||
// eslint-disable-next-line no-else-return
|
||||
else {
|
||||
current = { element: hit, mode: "fixed", focusPoint: point };
|
||||
current = { element: hit, mode: "inside", focusPoint: point };
|
||||
|
||||
return { current, other: isMultiPoint ? { mode: undefined } : other };
|
||||
}
|
||||
@@ -547,7 +550,7 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
||||
if (isOverlapping && oppositeElement && !otherIsTransparent) {
|
||||
current = {
|
||||
element: oppositeElement,
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
focusPoint: point,
|
||||
};
|
||||
} else {
|
||||
@@ -691,6 +694,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
localPoint,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
const hit = getHoveredElementForBinding(
|
||||
globalPoint,
|
||||
elements,
|
||||
@@ -738,13 +742,22 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
) {
|
||||
return {
|
||||
start: {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: startDragged
|
||||
? globalPoint
|
||||
: // NOTE: Can only affect the start point because new arrows always drag the end point
|
||||
opts?.newArrow
|
||||
? appState.selectedLinearElement!.initialState.origin!
|
||||
: otherBindableElement &&
|
||||
appState.selectedLinearElement?.initialState
|
||||
?.arrowOtherEndpointInitialBinding?.fixedPoint
|
||||
? getGlobalFixedPointForBindableElement(
|
||||
appState.selectedLinearElement?.initialState
|
||||
.arrowOtherEndpointInitialBinding.fixedPoint,
|
||||
otherBindableElement,
|
||||
elementsMap,
|
||||
)
|
||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||
arrow,
|
||||
0,
|
||||
@@ -752,10 +765,19 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
), // startFixedPoint,
|
||||
},
|
||||
end: {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: endDragged
|
||||
? globalPoint
|
||||
: otherBindableElement &&
|
||||
appState.selectedLinearElement?.initialState
|
||||
?.arrowOtherEndpointInitialBinding?.fixedPoint
|
||||
? getGlobalFixedPointForBindableElement(
|
||||
appState.selectedLinearElement?.initialState
|
||||
.arrowOtherEndpointInitialBinding.fixedPoint,
|
||||
otherBindableElement,
|
||||
elementsMap,
|
||||
)
|
||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||
arrow,
|
||||
-1,
|
||||
@@ -771,7 +793,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
start: startDragged
|
||||
? hit
|
||||
? {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: globalPoint,
|
||||
}
|
||||
@@ -780,7 +802,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
end: endDragged
|
||||
? hit
|
||||
? {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: globalPoint,
|
||||
}
|
||||
@@ -793,7 +815,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
const current: BindingStrategy = hit
|
||||
? pointInElement
|
||||
? {
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
element: hit,
|
||||
focusPoint: globalPoint,
|
||||
}
|
||||
@@ -828,36 +850,57 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
||||
threshold: maxBindingDistance_simple(appState.zoom),
|
||||
overrideShouldTestInside: true,
|
||||
});
|
||||
const otherPointWasInsideAtStart =
|
||||
appState.selectedLinearElement?.initialState
|
||||
.arrowOtherEndpointInitialBinding?.mode === "inside";
|
||||
const otherNeverOverride = opts?.newArrow
|
||||
? appState.selectedLinearElement?.initialState.arrowStartIsInside
|
||||
: otherBinding?.mode === "fixed";
|
||||
const other: BindingStrategy = !otherNeverOverride
|
||||
? otherBindableElement &&
|
||||
: otherBinding?.mode === "inside" && otherPointWasInsideAtStart;
|
||||
|
||||
let other: BindingStrategy = { mode: undefined };
|
||||
if (!otherNeverOverride) {
|
||||
if (
|
||||
otherBinding?.mode === "inside" &&
|
||||
!otherPointWasInsideAtStart &&
|
||||
otherBindableElement
|
||||
) {
|
||||
other = {
|
||||
mode: "orbit",
|
||||
element: otherBindableElement,
|
||||
focusPoint: getGlobalFixedPointForBindableElement(
|
||||
otherBinding.fixedPoint,
|
||||
otherBindableElement,
|
||||
elementsMap,
|
||||
),
|
||||
};
|
||||
} else if (
|
||||
otherBindableElement &&
|
||||
!otherFocusPointIsInElement &&
|
||||
!pointIsCloseToOtherElement &&
|
||||
appState.selectedLinearElement?.initialState.altFocusPoint
|
||||
? {
|
||||
mode: "orbit",
|
||||
element: otherBindableElement,
|
||||
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint,
|
||||
}
|
||||
: opts?.angleLocked && otherBindableElement
|
||||
? {
|
||||
mode: "orbit",
|
||||
element: otherBindableElement,
|
||||
focusPoint:
|
||||
projectFixedPointOntoDiagonal(
|
||||
arrow,
|
||||
otherEndpoint,
|
||||
otherBindableElement,
|
||||
startDragged ? "end" : "start",
|
||||
elementsMap,
|
||||
appState.zoom,
|
||||
appState.isMidpointSnappingEnabled,
|
||||
) || otherEndpoint,
|
||||
}
|
||||
: { mode: undefined }
|
||||
: { mode: undefined };
|
||||
) {
|
||||
other = {
|
||||
mode: "orbit",
|
||||
element: otherBindableElement,
|
||||
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint,
|
||||
};
|
||||
} else if (opts?.angleLocked && otherBindableElement) {
|
||||
other = {
|
||||
mode: "orbit",
|
||||
element: otherBindableElement,
|
||||
focusPoint:
|
||||
projectFixedPointOntoDiagonal(
|
||||
arrow,
|
||||
otherEndpoint,
|
||||
otherBindableElement,
|
||||
startDragged ? "end" : "start",
|
||||
elementsMap,
|
||||
appState.zoom,
|
||||
appState.isMidpointSnappingEnabled,
|
||||
) || otherEndpoint,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
start: startDragged ? current : other,
|
||||
@@ -1769,7 +1812,7 @@ export const updateBoundPoint = (
|
||||
|
||||
// 0. Short-circuit for inside binding as it doesn't require any
|
||||
// calculations and is not affected by other bindings
|
||||
if (binding.mode === "fixed") {
|
||||
if (binding.mode === "inside") {
|
||||
return LinearElementEditor.createPointAt(
|
||||
arrow,
|
||||
elementsMap,
|
||||
|
||||
@@ -762,7 +762,7 @@ export const isPointInElement = (
|
||||
(isLinearElement(element) || isFreeDrawElement(element)) &&
|
||||
!isPathALoop(element.points)
|
||||
) {
|
||||
// There isn't any "fixed" for a non-looping path
|
||||
// There isn't any "inside" for a non-looping path
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ export class LinearElementEditor {
|
||||
};
|
||||
arrowStartIsInside: boolean;
|
||||
altFocusPoint: Readonly<GlobalPoint> | null;
|
||||
arrowOtherEndpointInitialBinding: FixedPointBinding | null;
|
||||
}>;
|
||||
|
||||
/** whether you're dragging a point */
|
||||
@@ -193,6 +194,7 @@ export class LinearElementEditor {
|
||||
added: false,
|
||||
},
|
||||
arrowStartIsInside: false,
|
||||
arrowOtherEndpointInitialBinding: null,
|
||||
altFocusPoint: null,
|
||||
};
|
||||
this.hoverPointIndex = -1;
|
||||
@@ -764,6 +766,7 @@ export class LinearElementEditor {
|
||||
...editingLinearElement.initialState,
|
||||
origin: null,
|
||||
arrowStartIsInside: false,
|
||||
arrowOtherEndpointInitialBinding: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1083,8 +1086,9 @@ export class LinearElementEditor {
|
||||
},
|
||||
arrowStartIsInside:
|
||||
!!app.state.newElement &&
|
||||
(app.state.bindMode === "fixed" || app.state.bindMode === "skip"),
|
||||
(app.state.bindMode === "inside" || app.state.bindMode === "skip"),
|
||||
altFocusPoint: null,
|
||||
arrowOtherEndpointInitialBinding: element.startBinding,
|
||||
},
|
||||
selectedPointsIndices: [element.points.length - 1],
|
||||
lastUncommittedPoint: null,
|
||||
@@ -1145,8 +1149,11 @@ export class LinearElementEditor {
|
||||
},
|
||||
arrowStartIsInside:
|
||||
!!app.state.newElement &&
|
||||
(app.state.bindMode === "fixed" || app.state.bindMode === "skip"),
|
||||
(app.state.bindMode === "inside" || app.state.bindMode === "skip"),
|
||||
altFocusPoint: null,
|
||||
arrowOtherEndpointInitialBinding: nextSelectedPointsIndices?.includes(0)
|
||||
? element.endBinding
|
||||
: element.startBinding,
|
||||
},
|
||||
selectedPointsIndices: nextSelectedPointsIndices,
|
||||
pointerOffset: targetPoint
|
||||
@@ -2409,22 +2416,21 @@ const pointDraggingUpdates = (
|
||||
)! as ExcalidrawBindableElement)
|
||||
: null;
|
||||
|
||||
const endLocalPoint = startIsDraggingOverEndElement
|
||||
? nextArrow.points[nextArrow.points.length - 1]
|
||||
: endIsDraggingOverStartElement &&
|
||||
app.state.bindMode !== "fixed" &&
|
||||
getFeatureFlag("COMPLEX_BINDINGS")
|
||||
? nextArrow.points[0]
|
||||
: endBindable
|
||||
? updateBoundPoint(
|
||||
nextArrow,
|
||||
"endBinding",
|
||||
nextArrow.endBinding,
|
||||
endBindable,
|
||||
elementsMap,
|
||||
endIsDragged,
|
||||
) || nextArrow.points[nextArrow.points.length - 1]
|
||||
: nextArrow.points[nextArrow.points.length - 1];
|
||||
const endLocalPoint =
|
||||
endIsDraggingOverStartElement &&
|
||||
app.state.bindMode !== "inside" &&
|
||||
getFeatureFlag("COMPLEX_BINDINGS")
|
||||
? nextArrow.points[0]
|
||||
: endBindable
|
||||
? updateBoundPoint(
|
||||
nextArrow,
|
||||
"endBinding",
|
||||
nextArrow.endBinding,
|
||||
endBindable,
|
||||
elementsMap,
|
||||
endIsDragged,
|
||||
) || nextArrow.points[nextArrow.points.length - 1]
|
||||
: nextArrow.points[nextArrow.points.length - 1];
|
||||
|
||||
// We need to keep the simulated next arrow up-to-date, because
|
||||
// updateBoundPoint looks at the opposite point
|
||||
@@ -2443,7 +2449,7 @@ const pointDraggingUpdates = (
|
||||
endIsDraggingOverStartElement && getFeatureFlag("COMPLEX_BINDINGS")
|
||||
? nextArrow.points[0]
|
||||
: startIsDraggingOverEndElement &&
|
||||
app.state.bindMode !== "fixed" &&
|
||||
app.state.bindMode !== "inside" &&
|
||||
getFeatureFlag("COMPLEX_BINDINGS")
|
||||
? endLocalPoint
|
||||
: startBindable
|
||||
@@ -2458,13 +2464,11 @@ const pointDraggingUpdates = (
|
||||
: nextArrow.points[0];
|
||||
|
||||
const endChanged =
|
||||
!startIsDraggingOverEndElement &&
|
||||
!(
|
||||
endIsDraggingOverStartElement &&
|
||||
app.state.bindMode !== "fixed" &&
|
||||
app.state.bindMode !== "inside" &&
|
||||
getFeatureFlag("COMPLEX_BINDINGS")
|
||||
) &&
|
||||
!!endBindable;
|
||||
) && !!endBindable;
|
||||
const startChanged =
|
||||
pointDistance(startLocalPoint, nextArrow.points[0]) !== 0;
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ export type ExcalidrawTextElementWithContainer = {
|
||||
|
||||
export type FixedPoint = [number, number];
|
||||
|
||||
export type BindMode = "fixed" | "orbit" | "skip";
|
||||
export type BindMode = "inside" | "orbit" | "skip";
|
||||
|
||||
export type FixedPointBinding = {
|
||||
elementId: ExcalidrawBindableElement["id"];
|
||||
|
||||
@@ -72,14 +72,14 @@ describe("binding for simple arrows", () => {
|
||||
expect(startBinding.fixedPoint[0]).toBeLessThanOrEqual(1);
|
||||
expect(startBinding.fixedPoint[1]).toBeGreaterThanOrEqual(0);
|
||||
expect(startBinding.fixedPoint[1]).toBeLessThanOrEqual(1);
|
||||
expect(startBinding.mode).toBe("fixed");
|
||||
expect(startBinding.mode).toBe("inside");
|
||||
|
||||
const endBinding = arrow.endBinding as FixedPointBinding;
|
||||
expect(endBinding.fixedPoint[0]).toBeGreaterThanOrEqual(0);
|
||||
expect(endBinding.fixedPoint[0]).toBeLessThanOrEqual(1);
|
||||
expect(endBinding.fixedPoint[1]).toBeGreaterThanOrEqual(0);
|
||||
expect(endBinding.fixedPoint[1]).toBeLessThanOrEqual(1);
|
||||
expect(endBinding.mode).toBe("fixed");
|
||||
expect(endBinding.mode).toBe("inside");
|
||||
|
||||
// Move the bindable
|
||||
mouse.downAt(100, 150);
|
||||
|
||||
@@ -1940,7 +1940,7 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
||||
bindBindingElement(
|
||||
newElement,
|
||||
startElement,
|
||||
appState.bindMode === "fixed" ? "fixed" : "orbit",
|
||||
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||
"start",
|
||||
app.scene,
|
||||
);
|
||||
@@ -1954,7 +1954,7 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
||||
bindBindingElement(
|
||||
newElement,
|
||||
endElement,
|
||||
appState.bindMode === "fixed" ? "fixed" : "orbit",
|
||||
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||
"end",
|
||||
app.scene,
|
||||
);
|
||||
|
||||
@@ -1095,7 +1095,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||
);
|
||||
|
||||
this.setState({
|
||||
bindMode: "fixed",
|
||||
bindMode: "inside",
|
||||
selectedLinearElement: {
|
||||
...this.state.selectedLinearElement,
|
||||
initialState: {
|
||||
@@ -1176,16 +1176,16 @@ class App extends React.Component<AppProps, AppState> {
|
||||
: null;
|
||||
const isAlreadyInsideBindingToSameElement =
|
||||
(otherBinding &&
|
||||
arrow[otherBinding]?.mode === "fixed" &&
|
||||
arrow[otherBinding]?.mode === "inside" &&
|
||||
arrow[otherBinding]?.elementId === hoveredElement?.id) ||
|
||||
(currentBinding &&
|
||||
arrow[currentBinding]?.mode === "fixed" &&
|
||||
arrow[currentBinding]?.mode === "inside" &&
|
||||
hoveredElement?.id === arrow[currentBinding]?.elementId);
|
||||
|
||||
if (
|
||||
currentBinding &&
|
||||
otherBinding &&
|
||||
arrow[currentBinding]?.mode === "fixed" &&
|
||||
arrow[currentBinding]?.mode === "inside" &&
|
||||
hoveredElement?.id !== arrow[currentBinding]?.elementId &&
|
||||
arrow[otherBinding]?.elementId !== arrow[currentBinding]?.elementId
|
||||
) {
|
||||
@@ -1217,7 +1217,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||
}
|
||||
|
||||
// Clear the inside binding mode too
|
||||
if (this.state.bindMode === "fixed") {
|
||||
if (this.state.bindMode === "inside") {
|
||||
flushSync(() => {
|
||||
this.setState({
|
||||
bindMode: "orbit",
|
||||
@@ -8618,13 +8618,16 @@ class App extends React.Component<AppProps, AppState> {
|
||||
) as any;
|
||||
|
||||
if (arrow && isBindingElement(arrow)) {
|
||||
const { hitFocusPoint, pointerOffset } =
|
||||
handleFocusPointPointerDown(
|
||||
arrow,
|
||||
pointerDownState,
|
||||
elementsMap,
|
||||
this.state,
|
||||
);
|
||||
const {
|
||||
hitFocusPoint,
|
||||
pointerOffset,
|
||||
arrowOtherEndpointInitialBinding,
|
||||
} = handleFocusPointPointerDown(
|
||||
arrow,
|
||||
pointerDownState,
|
||||
elementsMap,
|
||||
this.state,
|
||||
);
|
||||
|
||||
// If focus point is hit, update state and prevent element selection
|
||||
if (hitFocusPoint) {
|
||||
@@ -8634,6 +8637,10 @@ class App extends React.Component<AppProps, AppState> {
|
||||
hoveredFocusPointBinding: hitFocusPoint,
|
||||
draggedFocusPointBinding: hitFocusPoint,
|
||||
pointerOffset,
|
||||
initialState: {
|
||||
...linearElementEditor.initialState,
|
||||
arrowOtherEndpointInitialBinding,
|
||||
},
|
||||
},
|
||||
});
|
||||
return false;
|
||||
@@ -10756,14 +10763,19 @@ class App extends React.Component<AppProps, AppState> {
|
||||
}
|
||||
|
||||
if (this.state.selectedLinearElement.draggedFocusPointBinding) {
|
||||
handleFocusPointPointerUp(
|
||||
this.state.selectedLinearElement,
|
||||
this.scene,
|
||||
);
|
||||
const { arrowOtherEndpointInitialBinding } =
|
||||
handleFocusPointPointerUp(
|
||||
this.state.selectedLinearElement,
|
||||
this.scene,
|
||||
);
|
||||
this.setState({
|
||||
selectedLinearElement: {
|
||||
...this.state.selectedLinearElement,
|
||||
draggedFocusPointBinding: null,
|
||||
initialState: {
|
||||
...this.state.selectedLinearElement.initialState,
|
||||
arrowOtherEndpointInitialBinding,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (
|
||||
|
||||
@@ -239,8 +239,8 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
if (binding.elementId) {
|
||||
return {
|
||||
elementId: binding.elementId,
|
||||
mode: (binding.mode as string) === "inside" ? "fixed" : binding.mode,
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint || [0.5, 0.5]),
|
||||
mode: binding.mode,
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint),
|
||||
} as FixedPointBinding | null;
|
||||
}
|
||||
return null;
|
||||
@@ -269,7 +269,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
elementsMap,
|
||||
);
|
||||
const mode = isPointInElement(p, boundElement, elementsMap)
|
||||
? "fixed"
|
||||
? "inside"
|
||||
: "orbit";
|
||||
const safeElement = {
|
||||
...element,
|
||||
@@ -289,7 +289,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
: null,
|
||||
};
|
||||
const focusPoint =
|
||||
mode === "fixed"
|
||||
mode === "inside"
|
||||
? p
|
||||
: projectFixedPointOntoDiagonal(
|
||||
safeElement,
|
||||
|
||||
@@ -8665,6 +8665,7 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
|
||||
"hoveredFocusPointBinding": null,
|
||||
"initialState": {
|
||||
"altFocusPoint": null,
|
||||
"arrowOtherEndpointInitialBinding": null,
|
||||
"arrowStartIsInside": false,
|
||||
"lastClickedPoint": -1,
|
||||
"origin": null,
|
||||
@@ -8898,6 +8899,7 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
|
||||
"hoveredFocusPointBinding": null,
|
||||
"initialState": {
|
||||
"altFocusPoint": null,
|
||||
"arrowOtherEndpointInitialBinding": null,
|
||||
"arrowStartIsInside": false,
|
||||
"lastClickedPoint": -1,
|
||||
"origin": null,
|
||||
@@ -9321,6 +9323,7 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
|
||||
"hoveredFocusPointBinding": null,
|
||||
"initialState": {
|
||||
"altFocusPoint": null,
|
||||
"arrowOtherEndpointInitialBinding": null,
|
||||
"arrowStartIsInside": false,
|
||||
"lastClickedPoint": -1,
|
||||
"origin": null,
|
||||
@@ -9734,6 +9737,7 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
|
||||
"hoveredFocusPointBinding": null,
|
||||
"initialState": {
|
||||
"altFocusPoint": null,
|
||||
"arrowOtherEndpointInitialBinding": null,
|
||||
"arrowStartIsInside": false,
|
||||
"lastClickedPoint": -1,
|
||||
"origin": null,
|
||||
|
||||
@@ -857,7 +857,7 @@ describe("repairing bindings", () => {
|
||||
endBinding: {
|
||||
elementId: container.id,
|
||||
fixedPoint: [0.5, 0.5],
|
||||
mode: "fixed",
|
||||
mode: "inside",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user