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:
Pete Hunt 2020-04-08 09:49:52 -07:00 committed by GitHub
parent c714c778ab
commit df0613d8ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 260 additions and 189 deletions

View file

@ -3,6 +3,7 @@ import {
ExcalidrawTextElement,
ExcalidrawLinearElement,
ExcalidrawGenericElement,
NonDeleted,
} from "../element/types";
import { measureText } from "../utils";
import { randomInteger, randomId } from "../random";
@ -56,7 +57,7 @@ function _newElementBase<T extends ExcalidrawElement>(
seed: rest.seed ?? randomInteger(),
version: rest.version || 1,
versionNonce: rest.versionNonce ?? 0,
isDeleted: rest.isDeleted ?? false,
isDeleted: false as false,
};
}
@ -64,7 +65,7 @@ export function newElement(
opts: {
type: ExcalidrawGenericElement["type"];
} & ElementConstructorOpts,
): ExcalidrawGenericElement {
): NonDeleted<ExcalidrawGenericElement> {
return _newElementBase<ExcalidrawGenericElement>(opts.type, opts);
}
@ -73,13 +74,12 @@ export function newTextElement(
text: string;
font: string;
} & ElementConstructorOpts,
): ExcalidrawTextElement {
): NonDeleted<ExcalidrawTextElement> {
const { text, font } = opts;
const metrics = measureText(text, font);
const textElement = newElementWith(
{
..._newElementBase<ExcalidrawTextElement>("text", opts),
isDeleted: false,
text: text,
font: font,
// Center the text
@ -100,7 +100,7 @@ export function newLinearElement(
type: ExcalidrawLinearElement["type"];
lastCommittedPoint?: ExcalidrawLinearElement["lastCommittedPoint"];
} & ElementConstructorOpts,
): ExcalidrawLinearElement {
): NonDeleted<ExcalidrawLinearElement> {
return {
..._newElementBase<ExcalidrawLinearElement>(opts.type, opts),
points: [],