Compare commits
1 Commits
master
...
arrow-fram
Author | SHA1 | Date | |
---|---|---|---|
|
c0efc16270 |
@ -27,6 +27,7 @@ import { LinearElementEditor } from "./linearElementEditor";
|
|||||||
import { arrayToMap, tupleToCoors } from "../utils";
|
import { arrayToMap, tupleToCoors } from "../utils";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { getBoundTextElement, handleBindTextResize } from "./textElement";
|
import { getBoundTextElement, handleBindTextResize } from "./textElement";
|
||||||
|
import { getContainingFrame, isPointInFrame } from "../frame";
|
||||||
|
|
||||||
export type SuggestedBinding =
|
export type SuggestedBinding =
|
||||||
| NonDeleted<ExcalidrawBindableElement>
|
| NonDeleted<ExcalidrawBindableElement>
|
||||||
@ -274,6 +275,18 @@ export const getHoveredElementForBinding = (
|
|||||||
isBindableElement(element, false) &&
|
isBindableElement(element, false) &&
|
||||||
bindingBorderTest(element, pointerCoords),
|
bindingBorderTest(element, pointerCoords),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (hoveredElement) {
|
||||||
|
const frame = getContainingFrame(hoveredElement);
|
||||||
|
|
||||||
|
if (frame) {
|
||||||
|
if (isPointInFrame(pointerCoords, frame)) {
|
||||||
|
return hoveredElement as NonDeleted<ExcalidrawBindableElement>;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return hoveredElement as NonDeleted<ExcalidrawBindableElement> | null;
|
return hoveredElement as NonDeleted<ExcalidrawBindableElement> | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -499,10 +512,22 @@ const getElligibleElementsForBindingElement = (
|
|||||||
return [
|
return [
|
||||||
getElligibleElementForBindingElement(linearElement, "start"),
|
getElligibleElementForBindingElement(linearElement, "start"),
|
||||||
getElligibleElementForBindingElement(linearElement, "end"),
|
getElligibleElementForBindingElement(linearElement, "end"),
|
||||||
].filter(
|
].filter((element): element is NonDeleted<ExcalidrawBindableElement> => {
|
||||||
(element): element is NonDeleted<ExcalidrawBindableElement> =>
|
if (element != null) {
|
||||||
element != null,
|
const frame = getContainingFrame(element);
|
||||||
);
|
return frame
|
||||||
|
? isPointInFrame(
|
||||||
|
getLinearElementEdgeCoors(linearElement, "start"),
|
||||||
|
frame,
|
||||||
|
) ||
|
||||||
|
isPointInFrame(
|
||||||
|
getLinearElementEdgeCoors(linearElement, "end"),
|
||||||
|
frame,
|
||||||
|
)
|
||||||
|
: true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getElligibleElementForBindingElement = (
|
const getElligibleElementForBindingElement = (
|
||||||
|
10
src/frame.ts
10
src/frame.ts
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
getCommonBounds,
|
getCommonBounds,
|
||||||
getElementAbsoluteCoords,
|
getElementAbsoluteCoords,
|
||||||
|
getElementBounds,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
} from "./element";
|
} from "./element";
|
||||||
import {
|
import {
|
||||||
@ -299,6 +300,15 @@ export const groupsAreCompletelyOutOfFrame = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isPointInFrame = (
|
||||||
|
{ x, y }: { x: number; y: number },
|
||||||
|
frame: ExcalidrawFrameElement,
|
||||||
|
) => {
|
||||||
|
const [x1, y1, x2, y2] = getElementBounds(frame);
|
||||||
|
|
||||||
|
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
|
||||||
|
};
|
||||||
|
|
||||||
// --------------------------- Frame Utils ------------------------------------
|
// --------------------------- Frame Utils ------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user