mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Make all operations on elements array immutable (#283)
* Make scene functions return array instead of mutate array - Not all functions were changes; so the given argument was a new array to some * Make data restoration functions immutable - Make mutations in App component * Make history actions immutable * Fix an issue in change property that was causing elements to be removed * mark elements params as readonly & remove unnecessary copying * Make `clearSelection` return a new array * Perform Id comparisons instead of reference comparisons in onDoubleClick * Allow deselecting items with SHIFT key - Refactor hit detection code * Fix a bug in element selection and revert drag functionality Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
1ea72e9134
commit
862231da4f
11 changed files with 239 additions and 157 deletions
|
@ -2,7 +2,7 @@ import { ExcalidrawElement } from "../element/types";
|
|||
import { hitTest } from "../element/collision";
|
||||
import { getElementAbsoluteCoords } from "../element";
|
||||
|
||||
export const hasBackground = (elements: ExcalidrawElement[]) =>
|
||||
export const hasBackground = (elements: readonly ExcalidrawElement[]) =>
|
||||
elements.some(
|
||||
element =>
|
||||
element.isSelected &&
|
||||
|
@ -11,7 +11,7 @@ export const hasBackground = (elements: ExcalidrawElement[]) =>
|
|||
element.type === "diamond")
|
||||
);
|
||||
|
||||
export const hasStroke = (elements: ExcalidrawElement[]) =>
|
||||
export const hasStroke = (elements: readonly ExcalidrawElement[]) =>
|
||||
elements.some(
|
||||
element =>
|
||||
element.isSelected &&
|
||||
|
@ -21,11 +21,11 @@ export const hasStroke = (elements: ExcalidrawElement[]) =>
|
|||
element.type === "arrow")
|
||||
);
|
||||
|
||||
export const hasText = (elements: ExcalidrawElement[]) =>
|
||||
export const hasText = (elements: readonly ExcalidrawElement[]) =>
|
||||
elements.some(element => element.isSelected && element.type === "text");
|
||||
|
||||
export function getElementAtPosition(
|
||||
elements: ExcalidrawElement[],
|
||||
elements: readonly ExcalidrawElement[],
|
||||
x: number,
|
||||
y: number
|
||||
) {
|
||||
|
@ -42,7 +42,7 @@ export function getElementAtPosition(
|
|||
}
|
||||
|
||||
export function getElementContainingPosition(
|
||||
elements: ExcalidrawElement[],
|
||||
elements: readonly ExcalidrawElement[],
|
||||
x: number,
|
||||
y: number
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue