Move group inside element

This commit is contained in:
Marcel Mraz 2025-03-18 19:12:49 +01:00
parent 0027f08cad
commit 1c5b8372b9
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
16 changed files with 73 additions and 56 deletions

View file

@ -5,11 +5,6 @@ import {
elementsOverlappingBBox, elementsOverlappingBBox,
} from "@excalidraw/utils"; } from "@excalidraw/utils";
import {
getElementsInGroup,
selectGroupsFromGivenElements,
} from "@excalidraw/excalidraw/groups";
import { import {
getElementsWithinSelection, getElementsWithinSelection,
getSelectedElements, getSelectedElements,
@ -36,6 +31,8 @@ import type {
import type { ReadonlySetLike } from "@excalidraw/excalidraw/utility-types"; import type { ReadonlySetLike } from "@excalidraw/excalidraw/utility-types";
import { getElementsInGroup, selectGroupsFromGivenElements } from "./groups";
import { getElementLineSegments, getCommonBounds } from "./bounds"; import { getElementLineSegments, getCommonBounds } from "./bounds";
import { mutateElement } from "./mutateElement"; import { mutateElement } from "./mutateElement";
import { getBoundTextElement, getContainerElement } from "./textElement"; import { getBoundTextElement, getContainerElement } from "./textElement";

View file

@ -1,5 +1,8 @@
import { getBoundTextElement } from "@excalidraw/element/textElement"; import { getBoundTextElement } from "@excalidraw/element/textElement";
import { getSelectedElements } from "@excalidraw/excalidraw/scene";
import { makeNextSelectedElementIds } from "@excalidraw/excalidraw/scene/selection";
import type { import type {
GroupId, GroupId,
ExcalidrawElement, ExcalidrawElement,
@ -9,15 +12,12 @@ import type {
ElementsMap, ElementsMap,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { getSelectedElements } from "./scene";
import { makeNextSelectedElementIds } from "./scene/selection";
import type { import type {
AppClassProperties, AppClassProperties,
AppState, AppState,
InteractiveCanvasAppState, InteractiveCanvasAppState,
} from "./types"; } from "@excalidraw/excalidraw/types";
import type { Mutable } from "./utility-types"; import type { Mutable } from "@excalidraw/excalidraw/utility-types";
export const selectGroup = ( export const selectGroup = (
groupId: GroupId, groupId: GroupId,

View file

@ -1,11 +1,17 @@
import {
convertToExcalidrawElements,
Excalidraw,
} from "@excalidraw/excalidraw";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { Keyboard, Pointer } from "@excalidraw/excalidraw/tests/helpers/ui";
import {
getCloneByOrigId,
render,
} from "@excalidraw/excalidraw/tests/test-utils";
import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { ExcalidrawElement } from "@excalidraw/element/types";
import { API } from "./tests/helpers/api";
import { Keyboard, Pointer } from "./tests/helpers/ui";
import { getCloneByOrigId, render } from "./tests/test-utils";
import { convertToExcalidrawElements, Excalidraw } from "./index";
const { h } = window; const { h } = window;
const mouse = new Pointer("mouse"); const mouse = new Pointer("mouse");

View file

@ -15,9 +15,13 @@ import {
} from "@excalidraw/element/typeChecks"; } from "@excalidraw/element/typeChecks";
import { getFrameChildren } from "@excalidraw/element/frame"; import { getFrameChildren } from "@excalidraw/element/frame";
import {
getElementsInGroup,
selectGroupsForSelectedElements,
} from "@excalidraw/element/groups";
import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { ExcalidrawElement } from "@excalidraw/element/types";
import { getElementsInGroup, selectGroupsForSelectedElements } from "../groups";
import { t } from "../i18n"; import { t } from "../i18n";
import { getSelectedElements, isSomeElementSelected } from "../scene"; import { getSelectedElements, isSomeElementSelected } from "../scene";
import { CaptureUpdateAction } from "../store"; import { CaptureUpdateAction } from "../store";

View file

@ -33,16 +33,17 @@ import {
getFrameChildren, getFrameChildren,
} from "@excalidraw/element/frame"; } from "@excalidraw/element/frame";
import {
selectGroupsForSelectedElements,
getSelectedGroupForElement,
getElementsInGroup,
} from "@excalidraw/element/groups";
import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { ExcalidrawElement } from "@excalidraw/element/types";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { DuplicateIcon } from "../components/icons"; import { DuplicateIcon } from "../components/icons";
import {
selectGroupsForSelectedElements,
getSelectedGroupForElement,
getElementsInGroup,
} from "../groups";
import { t } from "../i18n"; import { t } from "../i18n";
import { isSomeElementSelected } from "../scene"; import { isSomeElementSelected } from "../scene";
import { import {

View file

@ -10,9 +10,10 @@ import { getFrameChildren } from "@excalidraw/element/frame";
import { KEYS, updateActiveTool } from "@excalidraw/common"; import { KEYS, updateActiveTool } from "@excalidraw/common";
import { getElementsInGroup } from "@excalidraw/element/groups";
import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { ExcalidrawElement } from "@excalidraw/element/types";
import { getElementsInGroup } from "../groups";
import { setCursorForShape } from "../cursor"; import { setCursorForShape } from "../cursor";
import { frameToolIcon } from "../components/icons"; import { frameToolIcon } from "../components/icons";
import { getSelectedElements } from "../scene"; import { getSelectedElements } from "../scene";

View file

@ -16,6 +16,16 @@ import {
import { KEYS, randomId, arrayToMap, getShortcutKey } from "@excalidraw/common"; import { KEYS, randomId, arrayToMap, getShortcutKey } from "@excalidraw/common";
import {
getSelectedGroupIds,
selectGroup,
selectGroupsForSelectedElements,
getElementsInGroup,
addToGroup,
removeFromSelectedGroups,
isElementInGroup,
} from "@excalidraw/element/groups";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawTextElement, ExcalidrawTextElement,
@ -27,15 +37,6 @@ import { UngroupIcon, GroupIcon } from "../components/icons";
import { syncMovedIndices } from "../fractionalIndex"; import { syncMovedIndices } from "../fractionalIndex";
import {
getSelectedGroupIds,
selectGroup,
selectGroupsForSelectedElements,
getElementsInGroup,
addToGroup,
removeFromSelectedGroups,
isElementInGroup,
} from "../groups";
import { t } from "../i18n"; import { t } from "../i18n";
import { isSomeElementSelected } from "../scene"; import { isSomeElementSelected } from "../scene";

View file

@ -4,9 +4,10 @@ import { isLinearElement } from "@excalidraw/element/typeChecks";
import { KEYS } from "@excalidraw/common"; import { KEYS } from "@excalidraw/common";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { ExcalidrawElement } from "@excalidraw/element/types";
import { selectGroupsForSelectedElements } from "../groups";
import { CaptureUpdateAction } from "../store"; import { CaptureUpdateAction } from "../store";
import { selectAllIcon } from "../components/icons"; import { selectAllIcon } from "../components/icons";

View file

@ -2,11 +2,11 @@ import { updateBoundElements } from "@excalidraw/element/binding";
import { getCommonBoundingBox } from "@excalidraw/element/bounds"; import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { mutateElement } from "@excalidraw/element/mutateElement"; import { mutateElement } from "@excalidraw/element/mutateElement";
import { getMaximumGroups } from "@excalidraw/element/groups";
import type { BoundingBox } from "@excalidraw/element/bounds"; import type { BoundingBox } from "@excalidraw/element/bounds";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import { getMaximumGroups } from "./groups";
import type Scene from "./scene/Scene"; import type Scene from "./scene/Scene";
export interface Alignment { export interface Alignment {

View file

@ -29,6 +29,8 @@ import {
isTextElement, isTextElement,
} from "@excalidraw/element/typeChecks"; } from "@excalidraw/element/typeChecks";
import { getNonDeletedGroupIds } from "@excalidraw/element/groups";
import type { BindableProp, BindingProp } from "@excalidraw/element/binding"; import type { BindableProp, BindingProp } from "@excalidraw/element/binding";
import type { ElementUpdate } from "@excalidraw/element/mutateElement"; import type { ElementUpdate } from "@excalidraw/element/mutateElement";
@ -45,7 +47,6 @@ import type {
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex"; import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex";
import { getNonDeletedGroupIds } from "./groups";
import { getObservedAppState } from "./store"; import { getObservedAppState } from "./store";
import type { import type {

View file

@ -274,6 +274,16 @@ import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { getRenderOpacity } from "@excalidraw/element/renderElement"; import { getRenderOpacity } from "@excalidraw/element/renderElement";
import {
editGroupForSelectedElement,
getElementsInGroup,
getSelectedGroupIdForElement,
getSelectedGroupIds,
isElementInGroup,
isSelectedViaGroup,
selectGroupsForSelectedElements,
} from "@excalidraw/element/groups";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
import type { import type {
@ -362,15 +372,6 @@ import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
import { restore, restoreElements } from "../data/restore"; import { restore, restoreElements } from "../data/restore";
import { getCenter, getDistance } from "../gesture"; import { getCenter, getDistance } from "../gesture";
import {
editGroupForSelectedElement,
getElementsInGroup,
getSelectedGroupIdForElement,
getSelectedGroupIds,
isElementInGroup,
isSelectedViaGroup,
selectGroupsForSelectedElements,
} from "../groups";
import { History } from "../history"; import { History } from "../history";
import { defaultLang, getLanguage, languages, setLanguage, t } from "../i18n"; import { defaultLang, getLanguage, languages, setLanguage, t } from "../i18n";

View file

@ -1,9 +1,9 @@
import { getCommonBoundingBox } from "@excalidraw/element/bounds"; import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { newElementWith } from "@excalidraw/element/mutateElement"; import { newElementWith } from "@excalidraw/element/mutateElement";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; import { getMaximumGroups } from "@excalidraw/element/groups";
import { getMaximumGroups } from "./groups"; import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
export interface Distribution { export interface Distribution {
space: "between"; space: "between";

View file

@ -42,6 +42,13 @@ import { getCornerRadius } from "@excalidraw/element/shapes";
import { renderSelectionElement } from "@excalidraw/element/renderElement"; import { renderSelectionElement } from "@excalidraw/element/renderElement";
import {
isSelectedViaGroup,
getSelectedGroupIds,
getElementsInGroup,
selectGroupsFromGivenElements,
} from "@excalidraw/element/groups";
import type { import type {
SuggestedBinding, SuggestedBinding,
SuggestedPointBinding, SuggestedPointBinding,
@ -64,12 +71,6 @@ import type {
NonDeleted, NonDeleted,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import {
isSelectedViaGroup,
getSelectedGroupIds,
getElementsInGroup,
selectGroupsFromGivenElements,
} from "../groups";
import { renderSnaps } from "../renderer/renderSnaps"; import { renderSnaps } from "../renderer/renderSnaps";
import { roundRect } from "../renderer/roundRect"; import { roundRect } from "../renderer/roundRect";
import { import {

View file

@ -9,6 +9,8 @@ import {
import { isNonDeletedElement } from "@excalidraw/element"; import { isNonDeletedElement } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { getElementsInGroup } from "@excalidraw/element/groups";
import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
@ -22,7 +24,6 @@ import type {
Ordered, Ordered,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { getElementsInGroup } from "../groups";
import { import {
syncInvalidIndices, syncInvalidIndices,
syncMovedIndices, syncMovedIndices,

View file

@ -18,6 +18,8 @@ import {
isFrameLikeElement, isFrameLikeElement,
} from "@excalidraw/element/typeChecks"; } from "@excalidraw/element/typeChecks";
import { getMaximumGroups } from "@excalidraw/element/groups";
import type { InclusiveRange } from "@excalidraw/math"; import type { InclusiveRange } from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds"; import type { Bounds } from "@excalidraw/element/bounds";
@ -28,7 +30,6 @@ import type {
NonDeletedExcalidrawElement, NonDeletedExcalidrawElement,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { getMaximumGroups } from "./groups";
import { import {
getSelectedElements, getSelectedElements,
getVisibleAndNonSelectedElements, getVisibleAndNonSelectedElements,

View file

@ -2,13 +2,14 @@ import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common"; import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common";
import { getElementsInGroup } from "@excalidraw/element/groups";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawFrameLikeElement, ExcalidrawFrameLikeElement,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { syncMovedIndices } from "./fractionalIndex"; import { syncMovedIndices } from "./fractionalIndex";
import { getElementsInGroup } from "./groups";
import { getSelectedElements } from "./scene"; import { getSelectedElements } from "./scene";
import Scene from "./scene/Scene"; import Scene from "./scene/Scene";