diff --git a/packages/element/global.d.ts b/packages/element/global.d.ts
index 16ade7a7df..d10130f589 100644
--- a/packages/element/global.d.ts
+++ b/packages/element/global.d.ts
@@ -1,3 +1,7 @@
///
-import "@excalidraw/excalidraw/global";
-import "@excalidraw/excalidraw/css";
+///
+
+interface Window {
+ // set to debug fractional index validation in the scene
+ DEBUG_FRACTIONAL_INDICES: boolean | undefined;
+}
diff --git a/packages/element/package.json b/packages/element/package.json
index d883849e8c..b695a94ff0 100644
--- a/packages/element/package.json
+++ b/packages/element/package.json
@@ -95,7 +95,6 @@
"roughjs": "4.6.4"
},
"devDependencies": {
- "@excalidraw/excalidraw": "workspace:*",
"@excalidraw/laser-pointer": "workspace:*",
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.2.0",
diff --git a/packages/element/src/arrows/helpers.ts b/packages/element/src/arrows/helpers.ts
index 66613278e7..31a5de3d6d 100644
--- a/packages/element/src/arrows/helpers.ts
+++ b/packages/element/src/arrows/helpers.ts
@@ -1,27 +1,16 @@
-import type { NullableGridSize } from "@excalidraw/common";
-
import { LinearElementEditor } from "../linearElementEditor";
import { handleFocusPointDrag } from "./focus";
-import type { Scene } from "../Scene";
-import type { ElementsState } from "../types";
+import type { LinearElementEditorHost } from "../linearElementEditor";
/**
- * What arrow point dragging needs from the editor. Point dragging itself
- * (`LinearElementEditor.handlePointDragging`) still takes the whole editor.
+ * What arrow point dragging needs from the editor: point dragging's own needs
+ * (`LinearElementEditorHost`) plus the last pointer position and event.
*/
-export type ArrowPointDragHost = Parameters<
- typeof LinearElementEditor.handlePointDragging
->[1] & {
- state: Pick<
- ElementsState,
- "selectedLinearElement" | "isBindingEnabled" | "zoom"
- >;
- scene: Scene;
+export type ArrowPointDragHost = LinearElementEditorHost & {
lastPointerMoveCoords: { x: number; y: number } | null;
lastPointerMoveEvent: PointerEvent | null;
- getEffectiveGridSize(): NullableGridSize;
};
export const maybeHandleArrowPointlikeDrag = ({
diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts
index 1e2554864c..633b12c071 100644
--- a/packages/element/src/linearElementEditor.ts
+++ b/packages/element/src/linearElementEditor.ts
@@ -30,15 +30,8 @@ import {
import type { Radians } from "@excalidraw/math";
-import type {
- AppState,
- InteractiveCanvasAppState,
- AppClassProperties,
-} from "@excalidraw/excalidraw/types";
import type { Bounds } from "@excalidraw/common";
-import type { Store } from "@excalidraw/excalidraw/store";
-
import type { NullableGridSize, Zoom } from "@excalidraw/common";
import { getCurvePathOps } from "./geometricShapes";
@@ -96,6 +89,7 @@ import type {
} from "./types";
import type { PointerCoords } from "./types";
import type { ElementsState } from "./types";
+import type { RenderEnvironment } from "./renderEnvironment";
/**
* Normalizes line points so that the start point is at [0,0]. This is
@@ -141,6 +135,40 @@ const BoundTextPositionCache = new WeakMap<
}
>();
+/**
+ * What the linear element pointer handlers need from the editor. The editor
+ * (`App`) satisfies it.
+ */
+export type LinearElementEditorHost = {
+ state: Pick<
+ ElementsState,
+ | "bindMode"
+ | "gridModeEnabled"
+ | "gridSize"
+ | "isBindingEnabled"
+ | "isMidpointSnappingEnabled"
+ | "newElement"
+ | "selectedLinearElement"
+ | "suggestedBinding"
+ | "zoom"
+ >;
+ scene: Scene;
+ renderEnvironment: RenderEnvironment;
+ getEffectiveGridSize(): NullableGridSize;
+ arrowText: {
+ isBoundTextGrabbable(
+ element: NonDeletedExcalidrawElement,
+ x: number,
+ y: number,
+ ): boolean;
+ };
+};
+
+/** The history store, as far as point editing is concerned. */
+export type LinearElementEditorStore = {
+ scheduleCapture(): void;
+};
+
export class LinearElementEditor {
public readonly elementId: ExcalidrawElement["id"] & {
_brand: "excalidrawLinearElementId";
@@ -248,8 +276,8 @@ export class LinearElementEditor {
static handleBoxSelection(
event: PointerEvent,
- appState: AppState,
- setState: React.Component["setState"],
+ appState: Pick,
+ setState: (state: Pick) => void,
elementsMap: NonDeletedSceneElementsMap,
) {
if (
@@ -311,7 +339,7 @@ export class LinearElementEditor {
static handlePointerMove(
event: PointerEvent,
- app: AppClassProperties,
+ app: LinearElementEditorHost,
scenePointerX: number,
scenePointerY: number,
linearElementEditor: LinearElementEditor,
@@ -470,7 +498,7 @@ export class LinearElementEditor {
static handlePointDragging(
event: PointerEvent,
- app: AppClassProperties,
+ app: LinearElementEditorHost,
scenePointerX: number,
scenePointerY: number,
linearElementEditor: LinearElementEditor,
@@ -726,7 +754,7 @@ export class LinearElementEditor {
static handlePointerUp(
event: PointerEvent,
editingLinearElement: LinearElementEditor,
- appState: AppState,
+ appState: Pick,
scene: Scene,
): LinearElementEditor {
const elementsMap = scene.getNonDeletedElementsMap();
@@ -818,7 +846,7 @@ export class LinearElementEditor {
static getEditorMidPoints = (
element: ExcalidrawLinearElement,
elementsMap: ElementsMap,
- appState: InteractiveCanvasAppState,
+ appState: Pick,
): (GlobalPoint | null)[] => {
const boundText = getBoundTextElement(element, elementsMap);
@@ -869,7 +897,7 @@ export class LinearElementEditor {
static getSegmentMidpointHitCoords = (
linearElementEditor: LinearElementEditor,
scenePointer: { x: number; y: number },
- appState: AppState,
+ appState: Pick,
elementsMap: ElementsMap,
): GlobalPoint | null => {
const { elementId } = linearElementEditor;
@@ -1026,7 +1054,7 @@ export class LinearElementEditor {
static getSegmentMidPointIndex(
linearElementEditor: LinearElementEditor,
- appState: AppState,
+ appState: Pick,
midPoint: GlobalPoint,
elementsMap: ElementsMap,
) {
@@ -1054,8 +1082,8 @@ export class LinearElementEditor {
static handlePointerDown(
event: React.PointerEvent,
- app: AppClassProperties,
- store: Store,
+ app: LinearElementEditorHost,
+ store: LinearElementEditorStore,
scenePointer: { x: number; y: number },
linearElementEditor: LinearElementEditor,
scene: Scene,
@@ -1266,7 +1294,7 @@ export class LinearElementEditor {
event: React.PointerEvent,
scenePointerX: number,
scenePointerY: number,
- app: AppClassProperties,
+ app: LinearElementEditorHost,
): LinearElementEditor | null {
const appState = app.state;
if (!appState.selectedLinearElement?.isEditing) {
@@ -1504,7 +1532,9 @@ export class LinearElementEditor {
// element-mutating methods
// ---------------------------------------------------------------------------
- static duplicateSelectedPoints(appState: AppState, scene: Scene): AppState {
+ static duplicateSelectedPoints<
+ T extends Pick,
+ >(appState: T, scene: Scene): T {
invariant(
appState.selectedLinearElement?.isEditing,
"Not currently editing a linear element",
@@ -1582,7 +1612,7 @@ export class LinearElementEditor {
static deletePoints(
element: NonDeleted,
- app: AppClassProperties,
+ app: LinearElementEditorHost,
pointIndices: readonly number[],
) {
const isUncommittedPoint =
@@ -1743,7 +1773,7 @@ export class LinearElementEditor {
static shouldAddMidpoint(
linearElementEditor: LinearElementEditor,
pointerCoords: PointerCoords,
- appState: AppState,
+ appState: Pick,
elementsMap: ElementsMap,
) {
const element = LinearElementEditor.getElement(
@@ -1788,7 +1818,7 @@ export class LinearElementEditor {
static addMidpoint(
linearElementEditor: LinearElementEditor,
pointerCoords: PointerCoords,
- app: AppClassProperties,
+ app: LinearElementEditorHost,
snapToGrid: boolean,
scene: Scene,
) {
@@ -2410,7 +2440,7 @@ const pointDraggingUpdates = (
elementsMap: NonDeletedSceneElementsMap,
element: NonDeleted,
elements: readonly Ordered[],
- app: AppClassProperties,
+ app: LinearElementEditorHost,
angleLocked: boolean,
altKey: boolean,
linearElementEditor: LinearElementEditor,
diff --git a/packages/element/src/types.ts b/packages/element/src/types.ts
index a0882114cf..cc445a9ceb 100644
--- a/packages/element/src/types.ts
+++ b/packages/element/src/types.ts
@@ -719,6 +719,11 @@ export interface ElementsState {
gridSize: number;
gridModeEnabled: boolean;
shouldCacheIgnoreZoom: boolean;
+ /**
+ * decoupled from newElement, dragging selection only creates selectionElement
+ * - set on pointer down, updated during pointer move
+ */
+ selectionElement: NonDeletedExcalidrawElement | null;
/** the open dialog, if any (`AppState` narrows this to its dialogs) */
openDialog: { name: string } | null;
}
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index 5eaaf9a5fb..53d0e0cc0a 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -339,11 +339,6 @@ export interface AppState extends ElementsState {
* - when set and present, the editor will handle linear element creation logic accordingly
*/
multiElement: NonDeleted | null;
- /**
- * decoupled from newElement, dragging selection only creates selectionElement
- * - set on pointer down, updated during pointer move
- */
- selectionElement: NonDeletedExcalidrawElement | null;
/** user box selection preference; defaults to "contain" when unset */
boxSelectionMode: BoxSelectionMode;
/** user arrow binding preference */
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3c1eec8bce..1bfa37790a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -337,9 +337,6 @@ importers:
specifier: 4.6.4
version: 4.6.4
devDependencies:
- '@excalidraw/excalidraw':
- specifier: workspace:*
- version: link:../excalidraw
'@excalidraw/laser-pointer':
specifier: workspace:*
version: link:../laser-pointer
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 7eda269226..a8785fa0aa 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -12,8 +12,3 @@ onlyBuiltDependencies:
- core-js
- esbuild
- protobufjs
-
-# Type- and test-only edges close a cycle (element imports editor types from
-# excalidraw, and its tests use excalidraw's test harness). Runtime deps are
-# acyclic.
-ignoreWorkspaceCycles: true