mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add NonDeleted<ExcalidrawElement> (#1068)
* add NonDeleted * make test:all script run tests without prompt * rename helper * replace with helper * make element contructors return nonDeleted elements * cache filtered elements where appliacable for better perf * rename manager element getter * remove unnecessary assertion * fix test * make element types in resizeElement into nonDeleted Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
c714c778ab
commit
df0613d8ac
29 changed files with 260 additions and 189 deletions
|
@ -1,4 +1,7 @@
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import {
|
||||
ExcalidrawElement,
|
||||
NonDeletedExcalidrawElement,
|
||||
} from "../element/types";
|
||||
|
||||
import { getElementAbsoluteCoords, hitTest } from "../element";
|
||||
import { AppState } from "../types";
|
||||
|
@ -16,7 +19,7 @@ export const hasStroke = (type: string) =>
|
|||
export const hasText = (type: string) => type === "text";
|
||||
|
||||
export function getElementAtPosition(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
x: number,
|
||||
y: number,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import rough from "roughjs/bin/rough";
|
||||
import { ExcalidrawElement } from "../element/types";
|
||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||
import { getCommonBounds } from "../element/bounds";
|
||||
import { renderScene, renderSceneToSvg } from "../renderer/renderScene";
|
||||
import { distance, SVG_NS } from "../utils";
|
||||
|
@ -9,7 +9,7 @@ import { AppState } from "../types";
|
|||
export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
|
||||
|
||||
export function exportToCanvas(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
{
|
||||
exportBackground,
|
||||
|
@ -66,7 +66,7 @@ export function exportToCanvas(
|
|||
}
|
||||
|
||||
export function exportToSvg(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
{
|
||||
exportBackground,
|
||||
exportPadding = 10,
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import {
|
||||
ExcalidrawElement,
|
||||
NonDeletedExcalidrawElement,
|
||||
} from "../element/types";
|
||||
import { getNonDeletedElements } from "../element";
|
||||
|
||||
export interface SceneStateCallback {
|
||||
(): void;
|
||||
|
@ -8,15 +12,19 @@ export interface SceneStateCallbackRemover {
|
|||
(): void;
|
||||
}
|
||||
|
||||
class SceneState {
|
||||
class GlobalScene {
|
||||
private callbacks: Set<SceneStateCallback> = new Set();
|
||||
|
||||
constructor(private _elements: readonly ExcalidrawElement[] = []) {}
|
||||
|
||||
getAllElements() {
|
||||
getElementsIncludingDeleted() {
|
||||
return this._elements;
|
||||
}
|
||||
|
||||
getElements(): readonly NonDeletedExcalidrawElement[] {
|
||||
return getNonDeletedElements(this._elements);
|
||||
}
|
||||
|
||||
replaceAllElements(nextElements: readonly ExcalidrawElement[]) {
|
||||
this._elements = nextElements;
|
||||
this.informMutation();
|
||||
|
@ -44,4 +52,4 @@ class SceneState {
|
|||
}
|
||||
}
|
||||
|
||||
export const globalSceneState = new SceneState();
|
||||
export const globalSceneState = new GlobalScene();
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import {
|
||||
ExcalidrawElement,
|
||||
NonDeletedExcalidrawElement,
|
||||
} from "../element/types";
|
||||
import { getElementAbsoluteCoords, getElementBounds } from "../element";
|
||||
import { AppState } from "../types";
|
||||
import { newElementWith } from "../element/mutateElement";
|
||||
|
||||
export function getElementsWithinSelection(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
selection: ExcalidrawElement,
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
selection: NonDeletedExcalidrawElement,
|
||||
) {
|
||||
const [
|
||||
selectionX1,
|
||||
|
@ -47,7 +50,7 @@ export function deleteSelectedElements(
|
|||
}
|
||||
|
||||
export function isSomeElementSelected(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
): boolean {
|
||||
return elements.some((element) => appState.selectedElementIds[element.id]);
|
||||
|
@ -58,7 +61,7 @@ export function isSomeElementSelected(
|
|||
* elements. If elements don't share the same value, returns `null`.
|
||||
*/
|
||||
export function getCommonAttributeOfSelectedElements<T>(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
getAttribute: (element: ExcalidrawElement) => T,
|
||||
): T | null {
|
||||
|
@ -73,14 +76,14 @@ export function getCommonAttributeOfSelectedElements<T>(
|
|||
}
|
||||
|
||||
export function getSelectedElements(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
): readonly ExcalidrawElement[] {
|
||||
) {
|
||||
return elements.filter((element) => appState.selectedElementIds[element.id]);
|
||||
}
|
||||
|
||||
export function getTargetElement(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
) {
|
||||
return appState.editingElement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue