feat: add element.updated (#4070)

This commit is contained in:
David Luzar 2021-11-24 18:38:33 +01:00 committed by GitHub
parent dac970c640
commit f9d2d537a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 500 additions and 4 deletions

View file

@ -12,7 +12,7 @@ import {
ExcalidrawFreeDrawElement,
FontFamilyValues,
} from "../element/types";
import { measureText, getFontString } from "../utils";
import { measureText, getFontString, getUpdatedTimestamp } from "../utils";
import { randomInteger, randomId } from "../random";
import { newElementWith } from "./mutateElement";
import { getNewGroupIdsForDuplication } from "../groups";
@ -22,7 +22,7 @@ import { adjustXYWithRotation } from "../math";
import { getResizedElementAbsoluteCoords } from "./bounds";
type ElementConstructorOpts = MarkOptional<
Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted">,
Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">,
| "width"
| "height"
| "angle"
@ -75,6 +75,7 @@ const _newElementBase = <T extends ExcalidrawElement>(
versionNonce: rest.versionNonce ?? 0,
isDeleted: false as false,
boundElementIds,
updated: getUpdatedTimestamp(),
});
export const newElement = (
@ -337,6 +338,7 @@ export const duplicateElement = <TElement extends Mutable<ExcalidrawElement>>(
} else {
copy.id = randomId();
}
copy.updated = getUpdatedTimestamp();
copy.seed = randomInteger();
copy.groupIds = getNewGroupIdsForDuplication(
copy.groupIds,