refactor: export everything from @excalidraw/element, don't import from subpaths (#9466)

* Don't import from subpaths

* Fix tests, move related tests to element
This commit is contained in:
Marcel Mraz
2025-05-09 23:01:33 +02:00
committed by GitHub
parent a8ebe514da
commit 7e41026812
129 changed files with 517 additions and 541 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ import {
import {
shouldAllowVerticalAlign,
suppportsHorizontalAlign,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -19,9 +19,9 @@ import {
isImageElement,
isLinearElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element/comparisons";
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element";
import type {
ExcalidrawElement,
+32 -44
View File
@@ -104,10 +104,7 @@ import {
Emitter,
} from "@excalidraw/common";
import {
getCommonBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import { getCommonBounds, getElementAbsoluteCoords } from "@excalidraw/element";
import {
bindOrUnbindLinearElement,
@@ -120,11 +117,11 @@ import {
shouldEnableBindingForPointerEvent,
updateBoundElements,
getSuggestedBindingsForArrows,
} from "@excalidraw/element/binding";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import {
newFrameElement,
@@ -138,12 +135,9 @@ import {
newLinearElement,
newTextElement,
refreshTextDimensions,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import {
deepCopyElement,
duplicateElements,
} from "@excalidraw/element/duplicate";
import { deepCopyElement, duplicateElements } from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -166,7 +160,7 @@ import {
isFlowchartNodeElement,
isBindableElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
getLockedLinearCursorAlignSize,
@@ -174,28 +168,28 @@ import {
isElementCompletelyInViewport,
isElementInViewport,
isInvisiblySmallElement,
} from "@excalidraw/element/sizeHelpers";
} from "@excalidraw/element";
import {
getBoundTextShape,
getCornerRadius,
getElementShape,
isPathALoop,
} from "@excalidraw/element/shapes";
} from "@excalidraw/element";
import {
createSrcDoc,
embeddableURLValidator,
maybeParseEmbedSrc,
getEmbedLink,
} from "@excalidraw/element/embeddable";
} from "@excalidraw/element";
import {
getInitializedImageElements,
loadHTMLImageElement,
normalizeSVG,
updateImageCache as _updateImageCache,
} from "@excalidraw/element/image";
} from "@excalidraw/element";
import {
getBoundTextElement,
@@ -203,9 +197,9 @@ import {
getContainerElement,
isValidTextContainer,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { shouldShowBoundingBox } from "@excalidraw/element/transformHandles";
import { shouldShowBoundingBox } from "@excalidraw/element";
import {
getFrameChildren,
@@ -222,30 +216,27 @@ import {
getFrameLikeTitle,
getElementsOverlappingFrame,
filterElementsEligibleAsFrameChildren,
} from "@excalidraw/element/frame";
} from "@excalidraw/element";
import {
hitElementBoundText,
hitElementBoundingBoxOnly,
hitElementItself,
} from "@excalidraw/element/collision";
} from "@excalidraw/element";
import { getVisibleSceneBounds } from "@excalidraw/element/bounds";
import { getVisibleSceneBounds } from "@excalidraw/element";
import {
FlowChartCreator,
FlowChartNavigator,
getLinkDirectionFromKey,
} from "@excalidraw/element/flowchart";
} from "@excalidraw/element";
import { cropElement } from "@excalidraw/element/cropElement";
import { cropElement } from "@excalidraw/element";
import { wrapText } from "@excalidraw/element/textWrapping";
import { wrapText } from "@excalidraw/element";
import {
isElementLink,
parseElementLinkFromURL,
} from "@excalidraw/element/elementLink";
import { isElementLink, parseElementLinkFromURL } from "@excalidraw/element";
import {
isMeasureTextSupported,
@@ -255,11 +246,11 @@ import {
getApproxMinLineWidth,
getApproxMinLineHeight,
getMinTextElementWidth,
} from "@excalidraw/element/textMeasurements";
} from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import { getRenderOpacity } from "@excalidraw/element/renderElement";
import { getRenderOpacity } from "@excalidraw/element";
import {
editGroupForSelectedElement,
@@ -269,44 +260,41 @@ import {
isElementInGroup,
isSelectedViaGroup,
selectGroupsForSelectedElements,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import {
syncInvalidIndices,
syncMovedIndices,
} from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices, syncMovedIndices } from "@excalidraw/element";
import {
excludeElementsInFramesFromSelection,
getSelectionStateForElements,
makeNextSelectedElementIds,
} from "@excalidraw/element/selection";
} from "@excalidraw/element";
import {
getResizeOffsetXY,
getResizeArrowDirection,
transformElements,
} from "@excalidraw/element/resizeElements";
} from "@excalidraw/element";
import {
getCursorForResizingElement,
getElementWithTransformHandleType,
getTransformHandleTypeFromCoords,
} from "@excalidraw/element/resizeTest";
} from "@excalidraw/element";
import {
dragNewElement,
dragSelectedElements,
getDragOffsetXY,
} from "@excalidraw/element/dragElements";
} from "@excalidraw/element";
import { isNonDeletedElement } from "@excalidraw/element";
import Scene from "@excalidraw/element/Scene";
import { Scene } from "@excalidraw/element";
import { Store, CaptureUpdateAction } from "@excalidraw/element/store";
import { Store, CaptureUpdateAction } from "@excalidraw/element";
import type { ElementUpdate } from "@excalidraw/element/mutateElement";
import type { ElementUpdate } from "@excalidraw/element";
import type { LocalPoint, Radians } from "@excalidraw/math";
@@ -1,6 +1,6 @@
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
import { updateElbowArrowPoints } from "@excalidraw/element/elbowArrow";
import { updateElbowArrowPoints } from "@excalidraw/element";
import { pointFrom, pointRotateRads, type LocalPoint } from "@excalidraw/math";
@@ -13,21 +13,21 @@ import {
isLinearElement,
isSharpArrow,
isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
getCommonBoundingBox,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
} from "@excalidraw/element";
import {
getBoundTextElement,
getBoundTextMaxHeight,
getBoundTextMaxWidth,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { wrapText } from "@excalidraw/element/textWrapping";
import { wrapText } from "@excalidraw/element";
import {
assertNever,
@@ -37,17 +37,19 @@ import {
updateActiveTool,
} from "@excalidraw/common";
import { measureText } from "@excalidraw/element/textMeasurements";
import { measureText } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import {
newArrowElement,
newElement,
newLinearElement,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type {
ConvertibleGenericTypes,
@@ -66,7 +68,7 @@ import type {
FixedSegment,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import {
bumpVersion,
@@ -76,7 +78,6 @@ import {
} from "..";
import { trackEvent } from "../analytics";
import { atom, editorJotaiStore, useSetAtom } from "../editor-jotai";
import { updateBindings } from "../../element/src/binding";
import "./ConvertElementTypePopup.scss";
import { ToolButton } from "./ToolButton";
@@ -1,5 +1,5 @@
import { sceneCoordsToViewportCoords } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import type {
ElementsMap,
@@ -5,11 +5,11 @@ import { normalizeLink, KEYS } from "@excalidraw/common";
import {
defaultGetElementLinkFromSelection,
getLinkIdAndTypeFromSelection,
} from "@excalidraw/element/elementLink";
} from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { t } from "../i18n";
import { getSelectedElements } from "../scene";
@@ -6,11 +6,11 @@ import {
isLinearElement,
isTextBindableContainer,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { getShortcutKey } from "@excalidraw/common";
import { isNodeInFlowchart } from "@excalidraw/element/flowchart";
import { isNodeInFlowchart } from "@excalidraw/element";
import { t } from "../i18n";
import { isEraserActive } from "../appState";
+3 -3
View File
@@ -10,11 +10,11 @@ import {
isShallowEqual,
} from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { mutateElement } from "@excalidraw/element";
import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions";
import { showSelectedShapeActions } from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -8,7 +8,7 @@ import React, {
import { MIME_TYPES, arrayToMap } from "@excalidraw/common";
import { duplicateElements } from "@excalidraw/element/duplicate";
import { duplicateElements } from "@excalidraw/element";
import { serializeLibraryAsJSON } from "../data/json";
import { useLibraryCache } from "../hooks/useLibraryItemSvg";
@@ -1,6 +1,6 @@
import React from "react";
import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions";
import { showSelectedShapeActions } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -11,9 +11,9 @@ import {
getLineHeight,
} from "@excalidraw/common";
import { isElementCompletelyInViewport } from "@excalidraw/element/sizeHelpers";
import { isElementCompletelyInViewport } from "@excalidraw/element";
import { measureText } from "@excalidraw/element/textMeasurements";
import { measureText } from "@excalidraw/element";
import {
KEYS,
@@ -22,11 +22,8 @@ import {
getFontString,
} from "@excalidraw/common";
import { newTextElement } from "@excalidraw/element/newElement";
import {
isFrameLikeElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
import { newTextElement } from "@excalidraw/element";
import { isTextElement, isFrameLikeElement } from "@excalidraw/element";
import { getDefaultFrameName } from "@excalidraw/element/frame";
@@ -1,18 +1,18 @@
import { degreesToRadians, radiansToDegrees } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { isArrowElement, isElbowArrow } from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isArrowElement, isElbowArrow } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { angleIcon } from "../icons";
import { updateBindings } from "../../../element/src/binding";
import DragInput from "./DragInput";
import { getStepSizedValue, isPropertyEditable } from "./utils";
@@ -1,4 +1,4 @@
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { getNormalizedGridStep } from "../../scene";
@@ -4,13 +4,13 @@ import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
import {
MINIMAL_CROP_SIZE,
getUncroppedWidthAndHeight,
} from "@excalidraw/element/cropElement";
import { resizeSingleElement } from "@excalidraw/element/resizeElements";
import { isImageElement } from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { resizeSingleElement } from "@excalidraw/element";
import { isImageElement } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import DragInput from "./DragInput";
import { getStepSizedValue, isPropertyEditable } from "./utils";
@@ -3,13 +3,13 @@ import { useEffect, useRef, useState } from "react";
import { EVENT, KEYS, cloneJSON } from "@excalidraw/common";
import { deepCopyElement } from "@excalidraw/element/duplicate";
import { deepCopyElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { useApp } from "../App";
import { InlineIcon } from "../InlineIcon";
@@ -1,18 +1,15 @@
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
import {
hasBoundTextElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasBoundTextElement, isTextElement } from "@excalidraw/element";
import type {
ExcalidrawElement,
ExcalidrawTextElement,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { fontSizeIcon } from "../icons";
@@ -1,15 +1,15 @@
import { degreesToRadians, radiansToDegrees } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { isArrowElement } from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isArrowElement } from "@excalidraw/element";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { angleIcon } from "../icons";
@@ -2,17 +2,14 @@ import { pointFrom, type GlobalPoint } from "@excalidraw/math";
import { useMemo } from "react";
import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
import { updateBoundElements } from "@excalidraw/element/binding";
import { updateBoundElements } from "@excalidraw/element";
import {
rescalePointsInElement,
resizeSingleElement,
} from "@excalidraw/element/resizeElements";
import {
getBoundTextElement,
handleBindTextResize,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { getBoundTextElement, handleBindTextResize } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/utils";
@@ -22,7 +19,7 @@ import type {
NonDeletedSceneElementsMap,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import DragInput from "./DragInput";
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
@@ -1,13 +1,10 @@
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
import {
hasBoundTextElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasBoundTextElement, isTextElement } from "@excalidraw/element";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import type {
ExcalidrawElement,
@@ -15,7 +12,7 @@ import type {
NonDeletedSceneElementsMap,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { fontSizeIcon } from "../icons";
@@ -1,13 +1,13 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { useMemo } from "react";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import StatsDragInput from "./DragInput";
import {
@@ -3,12 +3,12 @@ import { clamp, pointFrom, pointRotateRads, round } from "@excalidraw/math";
import {
getFlipAdjustedCropPosition,
getUncroppedWidthAndHeight,
} from "@excalidraw/element/cropElement";
import { isImageElement } from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { isImageElement } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import StatsDragInput from "./DragInput";
import { getStepSizedValue, moveElement, STEP_SIZE } from "./utils";
@@ -4,13 +4,13 @@ import throttle from "lodash.throttle";
import { useEffect, useMemo, useState, memo } from "react";
import { STATS_PANELS } from "@excalidraw/common";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
import { isElbowArrow, isImageElement } from "@excalidraw/element/typeChecks";
import { getCommonBounds } from "@excalidraw/element";
import { getUncroppedWidthAndHeight } from "@excalidraw/element";
import { isElbowArrow, isImageElement } from "@excalidraw/element";
import { frameAndChildrenSelectedTogether } from "@excalidraw/element/frame";
import { frameAndChildrenSelectedTogether } from "@excalidraw/element";
import { elementsAreInSameGroup } from "@excalidraw/element/groups";
import { elementsAreInSameGroup } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -5,9 +5,9 @@ import { vi } from "vitest";
import { setDateTimeForTests, reseed } from "@excalidraw/common";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
+7 -10
View File
@@ -1,18 +1,17 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import {
isFrameLikeElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isFrameLikeElement, isTextElement } from "@excalidraw/element";
import {
getSelectedGroupIds,
getElementsInGroup,
isInGroup,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import { getFrameChildren } from "@excalidraw/element/frame";
import { getFrameChildren } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type { Radians } from "@excalidraw/math";
@@ -22,9 +21,7 @@ import type {
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import { updateBindings } from "../../../element/src/binding";
import type { Scene } from "@excalidraw/element";
import type { AppState } from "../../types";
@@ -10,16 +10,13 @@ import {
import { EVENT, HYPERLINK_TOOLTIP_DELAY, KEYS } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { hitElementBoundingBox } from "@excalidraw/element/collision";
import { hitElementBoundingBox } from "@excalidraw/element";
import { isElementLink } from "@excalidraw/element/elementLink";
import { isElementLink } from "@excalidraw/element";
import {
getEmbedLink,
embeddableURLValidator,
} from "@excalidraw/element/embeddable";
import { getEmbedLink, embeddableURLValidator } from "@excalidraw/element";
import {
sceneCoordsToViewportCoords,
@@ -29,9 +26,9 @@ import {
normalizeLink,
} from "@excalidraw/common";
import { isEmbeddableElement } from "@excalidraw/element/typeChecks";
import { isEmbeddableElement } from "@excalidraw/element";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import type {
ElementsMap,
@@ -1,14 +1,14 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { MIME_TYPES } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { hitElementBoundingBox } from "@excalidraw/element/collision";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { hitElementBoundingBox } from "@excalidraw/element";
import { DEFAULT_LINK_SIZE } from "@excalidraw/element/renderElement";
import { DEFAULT_LINK_SIZE } from "@excalidraw/element";
import type { GlobalPoint, Radians } from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds";
import type { Bounds } from "@excalidraw/element";
import type {
ElementsMap,
NonDeletedExcalidrawElement,