MCPcopy
hub / github.com/excalidraw/excalidraw / createElement

Function createElement

packages/excalidraw/tests/data/reconcile.test.ts:22–42  ·  view source on GitHub ↗
(opts: { uid: string } | ElementLike)

Source from the content-addressed store, hash-verified

20type Cache = Record<string, ExcalidrawElement | undefined>;
21
22const createElement = (opts: { uid: string } | ElementLike) => {
23 let uid: string;
24 let id: string;
25 let version: number | null;
26 let versionNonce: number | null = null;
27 if ("uid" in opts) {
28 const match = opts.uid.match(/^(\w+)(?::(\d+))?$/)!;
29 id = match[1];
30 version = match[2] ? parseInt(match[2]) : null;
31 uid = version ? `${id}:${version}` : id;
32 } else {
33 ({ id, version, versionNonce } = opts);
34 uid = id;
35 }
36 return {
37 uid,
38 id,
39 version,
40 versionNonce: versionNonce || randomInteger(),
41 };
42};
43
44const idsToElements = (ids: (Id | ElementLike)[], cache: Cache = {}) => {
45 return syncInvalidIndices(

Callers 1

idsToElementsFunction · 0.85

Calls 1

randomIntegerFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…