refactor: rename draggingElement -> newElement (#8294)

* add newElement to appState

* freedraw should not be an editing element

* do not set editing element for freedraw and generic

* remove ununsed `appState.draggingElement`

* remove setting dragged for new linear element

* decouple selection element from new element

* fix hint for text bindables

* update snapshot

* fixes

* fix frame regressions

* add comments to types

* document `editingElement`

---------

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Ryan Di 2024-08-06 19:26:06 +08:00 committed by GitHub
parent 8d530cf102
commit 3cf14c73a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 554 additions and 684 deletions

View file

@ -21,6 +21,7 @@ import type {
ExcalidrawElementType,
ExcalidrawIframeLikeElement,
OrderedExcalidrawElement,
ExcalidrawNonSelectionElement,
} from "./element/types";
import type { Action } from "./actions/types";
import type { Point as RoughPoint } from "roughjs/bin/geometry";
@ -233,9 +234,25 @@ export interface AppState {
element: NonDeletedExcalidrawElement;
state: "hover" | "active";
} | null;
draggingElement: NonDeletedExcalidrawElement | null;
/**
* for a newly created element
* - set on pointer down, updated during pointer move, used on pointer up
*/
newElement: NonDeleted<ExcalidrawNonSelectionElement> | null;
/**
* for a single element that's being resized
* - set on pointer down when it's selected and the active tool is selection
*/
resizingElement: NonDeletedExcalidrawElement | null;
/**
* multiElement is for multi-point linear element that's created by clicking as opposed to dragging
* - when set and present, the editor will handle linear element creation logic accordingly
*/
multiElement: NonDeleted<ExcalidrawLinearElement> | null;
/**
* decoupled from newElement, dragging selection only creates selectionElement
* - set on pointer down, updated during pointer move
*/
selectionElement: NonDeletedExcalidrawElement | null;
isBindingEnabled: boolean;
startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
@ -249,8 +266,13 @@ export interface AppState {
};
editingFrame: string | null;
elementsToHighlight: NonDeleted<ExcalidrawElement>[] | null;
// element being edited, but not necessarily added to elements array yet
// (e.g. text element when typing into the input)
/**
* currently set for:
* - text elements while in wysiwyg
* - newly created linear elements while in line editor (not set for existing
* elements in line editor)
* - and new images while being placed on canvas
*/
editingElement: NonDeletedExcalidrawElement | null;
editingLinearElement: LinearElementEditor | null;
activeTool: {