mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix groups
This commit is contained in:
parent
ccbd004f22
commit
65d5595c79
3 changed files with 45 additions and 6 deletions
|
@ -2,15 +2,13 @@
|
||||||
* Create and link between shapes.
|
* Create and link between shapes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { ELEMENT_LINK_KEY, normalizeLink } from "@excalidraw/common";
|
||||||
ELEMENT_LINK_KEY,
|
|
||||||
normalizeLink,
|
|
||||||
elementsAreInSameGroup,
|
|
||||||
} from "@excalidraw/common";
|
|
||||||
|
|
||||||
import type { AppProps, AppState } from "@excalidraw/excalidraw/types";
|
import type { AppProps, AppState } from "@excalidraw/excalidraw/types";
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
|
import { elementsAreInSameGroup } from "./groups";
|
||||||
|
|
||||||
export const defaultGetElementLinkFromSelection: Exclude<
|
export const defaultGetElementLinkFromSelection: Exclude<
|
||||||
AppProps["generateLinkForSelection"],
|
AppProps["generateLinkForSelection"],
|
||||||
undefined
|
undefined
|
||||||
|
|
|
@ -360,3 +360,42 @@ export const getNonDeletedGroupIds = (elements: ElementsMap) => {
|
||||||
|
|
||||||
return nonDeletedGroupIds;
|
return nonDeletedGroupIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const elementsAreInSameGroup = (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
) => {
|
||||||
|
const allGroups = elements.flatMap((element) => element.groupIds);
|
||||||
|
const groupCount = new Map<string, number>();
|
||||||
|
let maxGroup = 0;
|
||||||
|
|
||||||
|
for (const group of allGroups) {
|
||||||
|
groupCount.set(group, (groupCount.get(group) ?? 0) + 1);
|
||||||
|
if (groupCount.get(group)! > maxGroup) {
|
||||||
|
maxGroup = groupCount.get(group)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxGroup === elements.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isInGroup = (element: NonDeletedExcalidrawElement) => {
|
||||||
|
return element.groupIds.length > 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getNewGroupIdsForDuplication = (
|
||||||
|
groupIds: ExcalidrawElement["groupIds"],
|
||||||
|
editingGroupId: AppState["editingGroupId"],
|
||||||
|
mapper: (groupId: GroupId) => GroupId,
|
||||||
|
) => {
|
||||||
|
const copy = [...groupIds];
|
||||||
|
const positionOfEditingGroupId = editingGroupId
|
||||||
|
? groupIds.indexOf(editingGroupId)
|
||||||
|
: -1;
|
||||||
|
const endIndex =
|
||||||
|
positionOfEditingGroupId > -1 ? positionOfEditingGroupId : groupIds.length;
|
||||||
|
for (let index = 0; index < endIndex; index++) {
|
||||||
|
copy[index] = mapper(copy[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
};
|
||||||
|
|
|
@ -3,13 +3,15 @@ import clsx from "clsx";
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
import { useEffect, useMemo, useState, memo } from "react";
|
import { useEffect, useMemo, useState, memo } from "react";
|
||||||
|
|
||||||
import { STATS_PANELS, elementsAreInSameGroup } from "@excalidraw/common";
|
import { STATS_PANELS } from "@excalidraw/common";
|
||||||
import { getCommonBounds } from "@excalidraw/element/bounds";
|
import { getCommonBounds } from "@excalidraw/element/bounds";
|
||||||
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
|
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
|
||||||
import { isElbowArrow, isImageElement } from "@excalidraw/element/typeChecks";
|
import { isElbowArrow, isImageElement } from "@excalidraw/element/typeChecks";
|
||||||
|
|
||||||
import { frameAndChildrenSelectedTogether } from "@excalidraw/element/frame";
|
import { frameAndChildrenSelectedTogether } from "@excalidraw/element/frame";
|
||||||
|
|
||||||
|
import { elementsAreInSameGroup } from "@excalidraw/element/groups";
|
||||||
|
|
||||||
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { t } from "../../i18n";
|
import { t } from "../../i18n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue