Deprecate mutateElement, use scene.mutateElement or mutateElementWIth instead

This commit is contained in:
Marcel Mraz 2025-04-11 22:07:42 +00:00
parent a9c3b2a4d4
commit 94c773a990
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
45 changed files with 593 additions and 704 deletions

View file

@ -25,7 +25,7 @@ import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import { duplicateElements } from "@excalidraw/element/duplicate";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import { ToolButton } from "../components/ToolButton";
import { DuplicateIcon } from "../components/icons";
@ -52,7 +52,7 @@ export const actionDuplicateSelection = register({
try {
const newAppState = LinearElementEditor.duplicateSelectedPoints(
appState,
app.scene.getNonDeletedElementsMap(),
app.scene,
);
return {
@ -91,11 +91,16 @@ export const actionDuplicateSelection = register({
}
}
syncMovedIndices(nextElements, arrayToMap(duplicatedElements));
return {
elements: syncMovedIndices(nextElements, arrayToMap(duplicatedElements)),
elements: nextElements,
appState: {
...appState,
...updateLinearElementEditors(duplicatedElements),
...updateLinearElementEditors(
duplicatedElements,
arrayToMap(nextElements),
),
...selectGroupsForSelectedElements(
{
editingGroupId: appState.editingGroupId,
@ -131,7 +136,10 @@ export const actionDuplicateSelection = register({
),
});
const updateLinearElementEditors = (clonedElements: ExcalidrawElement[]) => {
const updateLinearElementEditors = (
clonedElements: ExcalidrawElement[],
elementsMap: ElementsMap,
) => {
const linears = clonedElements.filter(isLinearElement);
if (linears.length === 1) {
const linear = linears[0];
@ -142,7 +150,7 @@ const updateLinearElementEditors = (clonedElements: ExcalidrawElement[]) => {
if (onlySingleLinearSelected) {
return {
selectedLinearElement: new LinearElementEditor(linear),
selectedLinearElement: new LinearElementEditor(linear, elementsMap),
};
}
}