mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Refactor
This commit is contained in:
parent
689179f428
commit
02aeb5ab63
2 changed files with 15 additions and 35 deletions
|
@ -2,7 +2,7 @@ import { ToolButton } from "../components/ToolButton";
|
||||||
import { DuplicateIcon } from "../components/icons";
|
import { DuplicateIcon } from "../components/icons";
|
||||||
import { DEFAULT_GRID_SIZE } from "../constants";
|
import { DEFAULT_GRID_SIZE } from "../constants";
|
||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { isBoundToContainer } from "../element/typeChecks";
|
import { isBoundToContainer, isLinearElement } from "../element/typeChecks";
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
import { selectGroupsForSelectedElements } from "../groups";
|
import { selectGroupsForSelectedElements } from "../groups";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
@ -52,8 +52,7 @@ export const actionDuplicateSelection = register({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const origElements: ExcalidrawElement[] = elements.slice();
|
const duplicatedElements = duplicateElements(elements, {
|
||||||
const clonedElements = duplicateElements(elements, {
|
|
||||||
idsOfElementsToDuplicate: arrayToMap(
|
idsOfElementsToDuplicate: arrayToMap(
|
||||||
getSelectedElements(elements, appState, {
|
getSelectedElements(elements, appState, {
|
||||||
includeBoundTextElement: true,
|
includeBoundTextElement: true,
|
||||||
|
@ -68,7 +67,9 @@ export const actionDuplicateSelection = register({
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
let nextElements = origElements.concat(clonedElements);
|
let nextElements = (elements as ExcalidrawElement[])
|
||||||
|
.slice()
|
||||||
|
.concat(duplicatedElements);
|
||||||
|
|
||||||
if (app.props.onDuplicate && nextElements) {
|
if (app.props.onDuplicate && nextElements) {
|
||||||
const mappedElements = app.props.onDuplicate(nextElements, elements);
|
const mappedElements = app.props.onDuplicate(nextElements, elements);
|
||||||
|
@ -77,38 +78,22 @@ export const actionDuplicateSelection = register({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nextElements = syncMovedIndices(nextElements, arrayToMap(clonedElements));
|
|
||||||
// clonedElements
|
|
||||||
// .filter((e) => e.type === "text")
|
|
||||||
// .forEach((e) => {
|
|
||||||
// console.log(JSON.stringify(e.boundElements));
|
|
||||||
// });
|
|
||||||
// console.log("----");
|
|
||||||
// nextElements
|
|
||||||
// .filter((e) => e.type === "text")
|
|
||||||
// .forEach((e) => {
|
|
||||||
// console.log(JSON.stringify(e.boundElements));
|
|
||||||
// });
|
|
||||||
const nextElementsToSelect =
|
|
||||||
excludeElementsInFramesFromSelection(clonedElements);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements: nextElements,
|
elements: syncMovedIndices(nextElements, arrayToMap(duplicatedElements)),
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
...updateLinearElementEditors(nextElements),
|
...updateLinearElementEditors(duplicatedElements),
|
||||||
...selectGroupsForSelectedElements(
|
...selectGroupsForSelectedElements(
|
||||||
{
|
{
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
selectedElementIds: nextElementsToSelect.reduce(
|
selectedElementIds: excludeElementsInFramesFromSelection(
|
||||||
(acc: Record<ExcalidrawElement["id"], true>, element) => {
|
duplicatedElements,
|
||||||
|
).reduce((acc: Record<ExcalidrawElement["id"], true>, element) => {
|
||||||
if (!isBoundToContainer(element)) {
|
if (!isBoundToContainer(element)) {
|
||||||
acc[element.id] = true;
|
acc[element.id] = true;
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
},
|
}, {}),
|
||||||
{},
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
getNonDeletedElements(nextElements),
|
getNonDeletedElements(nextElements),
|
||||||
appState,
|
appState,
|
||||||
|
|
|
@ -27,7 +27,6 @@ import { bumpVersion } from "./mutateElement";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
hasBoundTextElement,
|
hasBoundTextElement,
|
||||||
isArrowElement,
|
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isFrameLikeElement,
|
isFrameLikeElement,
|
||||||
|
@ -321,10 +320,6 @@ export const duplicateElements = (
|
||||||
duplicatedElementsMap: NonDeletedSceneElementsMap,
|
duplicatedElementsMap: NonDeletedSceneElementsMap,
|
||||||
) => {
|
) => {
|
||||||
for (const element of newElements) {
|
for (const element of newElements) {
|
||||||
if (!isArrowElement(element)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("boundElements" in element && element.boundElements) {
|
if ("boundElements" in element && element.boundElements) {
|
||||||
Object.assign(element, {
|
Object.assign(element, {
|
||||||
boundElements: element.boundElements.reduce(
|
boundElements: element.boundElements.reduce(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue