mirror of
https://github.com/excalidraw/excalidraw
synced 2025-07-25 13:58:22 +08:00
z-index update
This commit is contained in:
@ -55,7 +55,6 @@ import {
|
|||||||
|
|
||||||
import { aabbForElement, elementCenterPoint } from "./bounds";
|
import { aabbForElement, elementCenterPoint } from "./bounds";
|
||||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||||
import { moveArrowAboveBindable } from "./zindex";
|
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
|
|
||||||
@ -173,6 +172,8 @@ export const bindOrUnbindBindingElement = (
|
|||||||
|
|
||||||
LinearElementEditor.movePoints(arrow, scene, updates);
|
LinearElementEditor.movePoints(arrow, scene, updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { start, end };
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindOrUnbindBindingElementEdge = (
|
const bindOrUnbindBindingElementEdge = (
|
||||||
@ -606,8 +607,6 @@ export const bindBindingElement = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
moveArrowAboveBindable(arrow, hoveredElement, scene);
|
|
||||||
|
|
||||||
scene.mutateElement(arrow, {
|
scene.mutateElement(arrow, {
|
||||||
[startOrEnd === "start" ? "startBinding" : "endBinding"]: binding,
|
[startOrEnd === "start" ? "startBinding" : "endBinding"]: binding,
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,9 @@ import type { Scene } from "./Scene";
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawBindableElement,
|
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawFrameLikeElement,
|
ExcalidrawFrameLikeElement,
|
||||||
|
OrderedExcalidrawElement,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {
|
const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {
|
||||||
@ -146,19 +146,23 @@ const getContiguousFrameRangeElements = (
|
|||||||
|
|
||||||
export const moveArrowAboveBindable = (
|
export const moveArrowAboveBindable = (
|
||||||
arrow: ExcalidrawArrowElement,
|
arrow: ExcalidrawArrowElement,
|
||||||
bindable: ExcalidrawBindableElement,
|
bindableIds: string[],
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
) => {
|
): readonly OrderedExcalidrawElement[] => {
|
||||||
const elements = scene.getElementsIncludingDeleted();
|
const elements = scene.getElementsIncludingDeleted();
|
||||||
const bindableIdx = elements.findIndex((el) => el.id === bindable.id);
|
const bindableIdx = elements.findIndex((el) => bindableIds.includes(el.id));
|
||||||
const arrowIdx = elements.findIndex((el) => el.id === arrow.id);
|
const arrowIdx = elements.findIndex((el) => el.id === arrow.id);
|
||||||
|
|
||||||
if (arrowIdx !== -1 && bindableIdx !== -1 && arrowIdx < bindableIdx) {
|
if (arrowIdx !== -1 && bindableIdx !== -1 && arrowIdx < bindableIdx) {
|
||||||
const updatedElements = Array.from(elements);
|
const updatedElements = Array.from(elements);
|
||||||
const arrow = updatedElements.splice(arrowIdx, 1)[0];
|
const arrow = updatedElements.splice(arrowIdx, 1)[0];
|
||||||
updatedElements.splice(bindableIdx, 0, arrow);
|
updatedElements.splice(bindableIdx, 0, arrow);
|
||||||
scene.replaceAllElements(updatedElements);
|
syncMovedIndices(elements, arrayToMap([arrow]));
|
||||||
|
|
||||||
|
return updatedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
isArrowElement,
|
isArrowElement,
|
||||||
isValidPolygon,
|
isValidPolygon,
|
||||||
LinearElementEditor,
|
LinearElementEditor,
|
||||||
|
moveArrowAboveBindable,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -49,6 +50,7 @@ export const actionFinalize = register({
|
|||||||
label: "",
|
label: "",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, data, app) => {
|
perform: (elements, appState, data, app) => {
|
||||||
|
let newElements = elements;
|
||||||
const { interactiveCanvas, focusContainer, scene } = app;
|
const { interactiveCanvas, focusContainer, scene } = app;
|
||||||
const { event, sceneCoords } =
|
const { event, sceneCoords } =
|
||||||
(data as {
|
(data as {
|
||||||
@ -87,13 +89,22 @@ export const actionFinalize = register({
|
|||||||
app.scene,
|
app.scene,
|
||||||
);
|
);
|
||||||
|
|
||||||
bindOrUnbindBindingElement(element, draggedPoints, scene, appState);
|
const { start, end } = bindOrUnbindBindingElement(
|
||||||
|
element,
|
||||||
|
draggedPoints,
|
||||||
|
scene,
|
||||||
|
appState,
|
||||||
|
);
|
||||||
|
const bindableIds = [];
|
||||||
|
start.element && bindableIds.push(start.element.id);
|
||||||
|
end.element && bindableIds.push(end.element.id);
|
||||||
|
newElements = moveArrowAboveBindable(element, bindableIds, scene);
|
||||||
|
|
||||||
if (linearElementEditor !== appState.selectedLinearElement) {
|
if (linearElementEditor !== appState.selectedLinearElement) {
|
||||||
// `handlePointerUp()` updated the linear element instance,
|
// `handlePointerUp()` updated the linear element instance,
|
||||||
// so filter out this element if it is too small,
|
// so filter out this element if it is too small,
|
||||||
// but do an update to all new elements anyway for undo/redo purposes.
|
// but do an update to all new elements anyway for undo/redo purposes.
|
||||||
let newElements = elements;
|
|
||||||
if (element && isInvisiblySmallElement(element)) {
|
if (element && isInvisiblySmallElement(element)) {
|
||||||
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
||||||
newElements = newElements.filter((el) => el.id !== element!.id);
|
newElements = newElements.filter((el) => el.id !== element!.id);
|
||||||
@ -149,7 +160,7 @@ export const actionFinalize = register({
|
|||||||
return {
|
return {
|
||||||
elements:
|
elements:
|
||||||
element.points.length < 2 || isInvisiblySmallElement(element)
|
element.points.length < 2 || isInvisiblySmallElement(element)
|
||||||
? elements.filter((el) => el.id !== element.id)
|
? newElements.filter((el) => el.id !== element.id)
|
||||||
: undefined,
|
: undefined,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
@ -161,8 +172,6 @@ export const actionFinalize = register({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let newElements = elements;
|
|
||||||
|
|
||||||
if (window.document.activeElement instanceof HTMLElement) {
|
if (window.document.activeElement instanceof HTMLElement) {
|
||||||
focusContainer();
|
focusContainer();
|
||||||
}
|
}
|
||||||
@ -256,7 +265,7 @@ export const actionFinalize = register({
|
|||||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
element,
|
element,
|
||||||
-1,
|
-1,
|
||||||
arrayToMap(elements),
|
arrayToMap(newElements),
|
||||||
);
|
);
|
||||||
const point = LinearElementEditor.pointFromAbsoluteCoords(
|
const point = LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
element,
|
element,
|
||||||
|
Reference in New Issue
Block a user