From e7a0a7e0b7ecc3cf7daf2b8e03d9416b3ad335c6 Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Tue, 18 Mar 2025 20:17:40 +0100 Subject: [PATCH] Move align, distribute, zindex to element package --- packages/{excalidraw => element/src}/align.ts | 2 +- .../{excalidraw => element/src}/distribute.ts | 0 .../{excalidraw => element/src}/zindex.ts | 7 +++-- .../tests/align.test.tsx | 18 +++++++----- .../tests/zindex.test.tsx | 29 ++++++++++--------- packages/excalidraw/actions/actionAlign.tsx | 6 ++-- .../excalidraw/actions/actionDistribute.tsx | 7 +++-- packages/excalidraw/actions/actionZindex.tsx | 13 +++++---- 8 files changed, 46 insertions(+), 36 deletions(-) rename packages/{excalidraw => element/src}/align.ts (97%) rename packages/{excalidraw => element/src}/distribute.ts (100%) rename packages/{excalidraw => element/src}/zindex.ts (98%) rename packages/{excalidraw => element}/tests/align.test.tsx (97%) rename packages/{excalidraw => element}/tests/zindex.test.tsx (99%) diff --git a/packages/excalidraw/align.ts b/packages/element/src/align.ts similarity index 97% rename from packages/excalidraw/align.ts rename to packages/element/src/align.ts index 015c68dac..e96c631f0 100644 --- a/packages/excalidraw/align.ts +++ b/packages/element/src/align.ts @@ -7,7 +7,7 @@ import { getMaximumGroups } from "@excalidraw/element/groups"; import type { BoundingBox } from "@excalidraw/element/bounds"; import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; -import type Scene from "./scene/Scene"; +import type Scene from "@excalidraw/excalidraw/scene/Scene"; export interface Alignment { position: "start" | "center" | "end"; diff --git a/packages/excalidraw/distribute.ts b/packages/element/src/distribute.ts similarity index 100% rename from packages/excalidraw/distribute.ts rename to packages/element/src/distribute.ts diff --git a/packages/excalidraw/zindex.ts b/packages/element/src/zindex.ts similarity index 98% rename from packages/excalidraw/zindex.ts rename to packages/element/src/zindex.ts index 72c3daf09..0305da4ac 100644 --- a/packages/excalidraw/zindex.ts +++ b/packages/element/src/zindex.ts @@ -6,15 +6,16 @@ import { getElementsInGroup } from "@excalidraw/element/groups"; import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; +import { getSelectedElements } from "@excalidraw/excalidraw/scene"; + import type { ExcalidrawElement, ExcalidrawFrameLikeElement, } from "@excalidraw/element/types"; -import { getSelectedElements } from "./scene"; -import Scene from "./scene/Scene"; +import type { AppState } from "@excalidraw/excalidraw/types"; -import type { AppState } from "./types"; +import Scene from "../../excalidraw/scene/Scene"; const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => { return element.frameId === frameId || element.id === frameId; diff --git a/packages/excalidraw/tests/align.test.tsx b/packages/element/tests/align.test.tsx similarity index 97% rename from packages/excalidraw/tests/align.test.tsx rename to packages/element/tests/align.test.tsx index ce8f57e80..2dcafc65b 100644 --- a/packages/excalidraw/tests/align.test.tsx +++ b/packages/element/tests/align.test.tsx @@ -1,5 +1,3 @@ -import React from "react"; - import { KEYS } from "@excalidraw/common"; import { @@ -10,13 +8,17 @@ import { actionAlignBottom, actionAlignLeft, actionAlignRight, -} from "../actions"; -import { defaultLang, setLanguage } from "../i18n"; -import { Excalidraw } from "../index"; +} from "@excalidraw/excalidraw/actions"; +import { defaultLang, setLanguage } from "@excalidraw/excalidraw/i18n"; +import { Excalidraw } from "@excalidraw/excalidraw"; -import { API } from "./helpers/api"; -import { UI, Pointer, Keyboard } from "./helpers/ui"; -import { act, unmountComponent, render } from "./test-utils"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; +import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui"; +import { + act, + unmountComponent, + render, +} from "@excalidraw/excalidraw/tests/test-utils"; const mouse = new Pointer("mouse"); diff --git a/packages/excalidraw/tests/zindex.test.tsx b/packages/element/tests/zindex.test.tsx similarity index 99% rename from packages/excalidraw/tests/zindex.test.tsx rename to packages/element/tests/zindex.test.tsx index 7cccf5abe..67c197a8c 100644 --- a/packages/excalidraw/tests/zindex.test.tsx +++ b/packages/element/tests/zindex.test.tsx @@ -1,29 +1,32 @@ -import React from "react"; - import { selectGroupsForSelectedElements } from "@excalidraw/element/groups"; import { reseed } from "@excalidraw/common"; -import type { - ExcalidrawElement, - ExcalidrawFrameElement, - ExcalidrawSelectionElement, -} from "@excalidraw/element/types"; - import { actionSendBackward, actionBringForward, actionBringToFront, actionSendToBack, actionDuplicateSelection, -} from "../actions"; +} from "@excalidraw/excalidraw/actions"; -import { Excalidraw } from "../index"; +import { Excalidraw } from "@excalidraw/excalidraw"; -import { API } from "./helpers/api"; -import { act, getCloneByOrigId, render, unmountComponent } from "./test-utils"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; +import { + act, + getCloneByOrigId, + render, + unmountComponent, +} from "@excalidraw/excalidraw/tests/test-utils"; -import type { AppState } from "../types"; +import type { + ExcalidrawElement, + ExcalidrawFrameElement, + ExcalidrawSelectionElement, +} from "@excalidraw/element/types"; + +import type { AppState } from "@excalidraw/excalidraw/types"; unmountComponent(); diff --git a/packages/excalidraw/actions/actionAlign.tsx b/packages/excalidraw/actions/actionAlign.tsx index 2b4b48698..46023d61e 100644 --- a/packages/excalidraw/actions/actionAlign.tsx +++ b/packages/excalidraw/actions/actionAlign.tsx @@ -6,9 +6,12 @@ import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/fra import { KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common"; +import { alignElements } from "@excalidraw/element/align"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; -import { alignElements } from "../align"; +import type { Alignment } from "@excalidraw/element/align"; + import { ToolButton } from "../components/ToolButton"; import { AlignBottomIcon, @@ -26,7 +29,6 @@ import { CaptureUpdateAction } from "../store"; import { register } from "./register"; -import type { Alignment } from "../align"; import type { AppClassProperties, AppState, UIAppState } from "../types"; export const alignActionsPredicate = ( diff --git a/packages/excalidraw/actions/actionDistribute.tsx b/packages/excalidraw/actions/actionDistribute.tsx index 7af39e955..9f05ab6bf 100644 --- a/packages/excalidraw/actions/actionDistribute.tsx +++ b/packages/excalidraw/actions/actionDistribute.tsx @@ -6,14 +6,17 @@ import { CODES, KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common"; import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame"; +import { distributeElements } from "@excalidraw/element/distribute"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; +import type { Distribution } from "@excalidraw/element/distribute"; + import { ToolButton } from "../components/ToolButton"; import { DistributeHorizontallyIcon, DistributeVerticallyIcon, } from "../components/icons"; -import { distributeElements } from "../distribute"; import { t } from "../i18n"; @@ -22,8 +25,6 @@ import { CaptureUpdateAction } from "../store"; import { register } from "./register"; -import type { Distribution } from "../distribute"; - import type { AppClassProperties, AppState } from "../types"; const enableActionGroup = (appState: AppState, app: AppClassProperties) => { diff --git a/packages/excalidraw/actions/actionZindex.tsx b/packages/excalidraw/actions/actionZindex.tsx index 42a79a3c0..91de7a19b 100644 --- a/packages/excalidraw/actions/actionZindex.tsx +++ b/packages/excalidraw/actions/actionZindex.tsx @@ -1,5 +1,12 @@ import { KEYS, CODES, getShortcutKey, isDarwin } from "@excalidraw/common"; +import { + moveOneLeft, + moveOneRight, + moveAllLeft, + moveAllRight, +} from "@excalidraw/element/zindex"; + import { BringForwardIcon, BringToFrontIcon, @@ -8,12 +15,6 @@ import { } from "../components/icons"; import { t } from "../i18n"; import { CaptureUpdateAction } from "../store"; -import { - moveOneLeft, - moveOneRight, - moveAllLeft, - moveAllRight, -} from "../zindex"; import { register } from "./register";