@excalidraw/common 0.18.0-c65b684e9 → 0.18.0-c6f8ef9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,9 @@ export declare class Scene {
27
27
  getElementsMapIncludingDeleted(): Map<string, Ordered<ExcalidrawElement>> & import("@excalidraw/common/utility-types").MakeBrand<"SceneElementsMap">;
28
28
  getNonDeletedElements(): readonly Ordered<NonDeletedExcalidrawElement>[];
29
29
  getFramesIncludingDeleted(): readonly ExcalidrawFrameLikeElement[];
30
- constructor(elements?: ElementsMapOrArray | null);
30
+ constructor(elements?: ElementsMapOrArray | null, options?: {
31
+ skipValidation?: true;
32
+ });
31
33
  getSelectedElements(opts: {
32
34
  selectedElementIds: AppState["selectedElementIds"];
33
35
  /**
@@ -55,7 +57,9 @@ export declare class Scene {
55
57
  * @returns whether a change was made
56
58
  */
57
59
  mapElements(iteratee: (element: ExcalidrawElement) => ExcalidrawElement): boolean;
58
- replaceAllElements(nextElements: ElementsMapOrArray): void;
60
+ replaceAllElements(nextElements: ElementsMapOrArray, options?: {
61
+ skipValidation?: true;
62
+ }): void;
59
63
  triggerUpdate(): void;
60
64
  onUpdate(cb: SceneStateCallback): SceneStateCallbackRemover;
61
65
  destroy(): void;
@@ -32,13 +32,13 @@ export declare class Delta<T> {
32
32
  /**
33
33
  * Merges two deltas into a new one.
34
34
  */
35
- static merge<T>(delta1: Delta<T>, delta2: Delta<T>): Delta<T>;
35
+ static merge<T>(delta1: Delta<T>, delta2: Delta<T>, delta3?: Delta<T>): Delta<T>;
36
36
  /**
37
37
  * Merges deleted and inserted object partials.
38
38
  */
39
39
  static mergeObjects<T extends {
40
40
  [key: string]: unknown;
41
- }>(prev: T, added: T, removed: T): T;
41
+ }>(prev: T, added: T, removed?: T): T;
42
42
  /**
43
43
  * Merges deleted and inserted array partials.
44
44
  */
@@ -118,6 +118,7 @@ export interface DeltaContainer<T> {
118
118
  export declare class AppStateDelta implements DeltaContainer<AppState> {
119
119
  delta: Delta<ObservedAppState>;
120
120
  private constructor();
121
+ static create(delta: Delta<ObservedAppState>): AppStateDelta;
121
122
  static calculate<T extends ObservedAppState>(prevAppState: T, nextAppState: T): AppStateDelta;
122
123
  static restore(appStateDeltaDTO: DTO<AppStateDelta>): AppStateDelta;
123
124
  static empty(): AppStateDelta;
@@ -131,7 +132,6 @@ export declare class AppStateDelta implements DeltaContainer<AppState> {
131
132
  * @returns `true` if a visible change is found, `false` otherwise.
132
133
  */
133
134
  private filterInvisibleChanges;
134
- private static convertToAppStateKey;
135
135
  private static filterSelectedElements;
136
136
  private static filterSelectedGroups;
137
137
  private static stripElementsProps;
@@ -145,7 +145,7 @@ export declare class AppStateDelta implements DeltaContainer<AppState> {
145
145
  }
146
146
  type ElementPartial<TElement extends ExcalidrawElement = ExcalidrawElement> = Omit<Partial<Ordered<TElement>>, "id" | "updated" | "seed">;
147
147
  export type ApplyToOptions = {
148
- excludedProperties: Set<keyof ElementPartial>;
148
+ excludedProperties?: Set<keyof ElementPartial>;
149
149
  };
150
150
  /**
151
151
  * Elements change is a low level primitive to capture a change between two sets of elements.
@@ -164,6 +164,7 @@ export declare class ElementsDelta implements DeltaContainer<SceneElementsMap> {
164
164
  private static satisfiesRemoval;
165
165
  private static satisfiesUpdate;
166
166
  private static satisfiesCommmonInvariants;
167
+ private static satisfiesUniqueInvariants;
167
168
  private static validate;
168
169
  /**
169
170
  * Calculates the `Delta`s between the previous and next set of elements.
@@ -213,6 +214,7 @@ export declare class ElementsDelta implements DeltaContainer<SceneElementsMap> {
213
214
  * should be rebound (if possible) with the current element ~ bindings should be bidirectional.
214
215
  */
215
216
  private static rebindAffected;
217
+ static redrawElements(nextElements: SceneElementsMap, changedElements: Map<string, OrderedExcalidrawElement>): SceneElementsMap;
216
218
  private static redrawTextBoundingBoxes;
217
219
  private static redrawBoundArrows;
218
220
  private static reorderElements;
@@ -222,5 +224,6 @@ export declare class ElementsDelta implements DeltaContainer<SceneElementsMap> {
222
224
  */
223
225
  private static postProcess;
224
226
  private static stripIrrelevantProps;
227
+ private static stripVersionProps;
225
228
  }
226
229
  export {};
@@ -169,7 +169,11 @@ export declare class StoreDelta {
169
169
  /**
170
170
  * Parse and load the delta from the remote payload.
171
171
  */
172
- static load({ id, elements: { added, removed, updated }, }: DTO<StoreDelta>): StoreDelta;
172
+ static load({ id, elements: { added, removed, updated }, appState: { delta: appStateDelta }, }: DTO<StoreDelta>): StoreDelta;
173
+ /**
174
+ * Squash the passed deltas into the aggregated delta instance.
175
+ */
176
+ static squash(...deltas: StoreDelta[]): StoreDelta;
173
177
  /**
174
178
  * Inverse store delta, creates new instance of `StoreDelta`.
175
179
  */
@@ -182,6 +186,7 @@ export declare class StoreDelta {
182
186
  * Apply latest (remote) changes to the delta, creates new instance of `StoreDelta`.
183
187
  */
184
188
  static applyLatestChanges(delta: StoreDelta, prevElements: SceneElementsMap, nextElements: SceneElementsMap, modifierOptions?: "deleted" | "inserted"): StoreDelta;
189
+ static empty(): StoreDelta;
185
190
  isEmpty(): boolean;
186
191
  }
187
192
  /**
@@ -160,7 +160,6 @@ export declare const actionClearCanvas: {
160
160
  openMenu: "canvas" | "shape" | null;
161
161
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
162
162
  openSidebar: {
163
- /** zoom content to cover X of the viewport, when fitToViewport=true */
164
163
  name: string;
165
164
  tab?: string | undefined;
166
165
  } | null;
@@ -278,7 +277,6 @@ export declare const actionZoomIn: {
278
277
  openMenu: "canvas" | "shape" | null;
279
278
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
280
279
  openSidebar: {
281
- /** zoom content to cover X of the viewport, when fitToViewport=true */
282
280
  name: string;
283
281
  tab?: string | undefined;
284
282
  } | null;
@@ -465,7 +463,6 @@ export declare const actionZoomOut: {
465
463
  openMenu: "canvas" | "shape" | null;
466
464
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
467
465
  openSidebar: {
468
- /** zoom content to cover X of the viewport, when fitToViewport=true */
469
466
  name: string;
470
467
  tab?: string | undefined;
471
468
  } | null;
@@ -652,7 +649,6 @@ export declare const actionResetZoom: {
652
649
  openMenu: "canvas" | "shape" | null;
653
650
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
654
651
  openSidebar: {
655
- /** zoom content to cover X of the viewport, when fitToViewport=true */
656
652
  name: string;
657
653
  tab?: string | undefined;
658
654
  } | null;
@@ -845,7 +841,6 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fitToV
845
841
  openMenu: "canvas" | "shape" | null;
846
842
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
847
843
  openSidebar: {
848
- /** zoom content to cover X of the viewport, when fitToViewport=true */
849
844
  name: string;
850
845
  tab?: string | undefined;
851
846
  } | null;
@@ -1034,7 +1029,6 @@ export declare const zoomToFit: ({ canvasOffsets, targetElements, appState, fitT
1034
1029
  openMenu: "canvas" | "shape" | null;
1035
1030
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1036
1031
  openSidebar: {
1037
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1038
1032
  name: string;
1039
1033
  tab?: string | undefined;
1040
1034
  } | null;
@@ -1215,7 +1209,6 @@ export declare const actionZoomToFitSelectionInViewport: {
1215
1209
  openMenu: "canvas" | "shape" | null;
1216
1210
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1217
1211
  openSidebar: {
1218
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1219
1212
  name: string;
1220
1213
  tab?: string | undefined;
1221
1214
  } | null;
@@ -1400,7 +1393,6 @@ export declare const actionZoomToFitSelection: {
1400
1393
  openMenu: "canvas" | "shape" | null;
1401
1394
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1402
1395
  openSidebar: {
1403
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1404
1396
  name: string;
1405
1397
  tab?: string | undefined;
1406
1398
  } | null;
@@ -1586,7 +1578,6 @@ export declare const actionZoomToFit: {
1586
1578
  openMenu: "canvas" | "shape" | null;
1587
1579
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1588
1580
  openSidebar: {
1589
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1590
1581
  name: string;
1591
1582
  tab?: string | undefined;
1592
1583
  } | null;
@@ -1774,7 +1765,6 @@ export declare const actionToggleTheme: {
1774
1765
  openMenu: "canvas" | "shape" | null;
1775
1766
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1776
1767
  openSidebar: {
1777
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1778
1768
  name: string;
1779
1769
  tab?: string | undefined;
1780
1770
  } | null;
@@ -1957,7 +1947,6 @@ export declare const actionToggleEraserTool: {
1957
1947
  openMenu: "canvas" | "shape" | null;
1958
1948
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
1959
1949
  openSidebar: {
1960
- /** zoom content to cover X of the viewport, when fitToViewport=true */
1961
1950
  name: string;
1962
1951
  tab?: string | undefined;
1963
1952
  } | null;
@@ -2135,7 +2124,6 @@ export declare const actionToggleLassoTool: {
2135
2124
  openMenu: "canvas" | "shape" | null;
2136
2125
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
2137
2126
  openSidebar: {
2138
- /** zoom content to cover X of the viewport, when fitToViewport=true */
2139
2127
  name: string;
2140
2128
  tab?: string | undefined;
2141
2129
  } | null;
@@ -2313,7 +2301,6 @@ export declare const actionToggleHandTool: {
2313
2301
  openMenu: "canvas" | "shape" | null;
2314
2302
  openPopup: "fontFamily" | "canvasBackground" | "elementBackground" | "elementStroke" | null;
2315
2303
  openSidebar: {
2316
- /** zoom content to cover X of the viewport, when fitToViewport=true */
2317
2304
  name: string;
2318
2305
  tab?: string | undefined;
2319
2306
  } | null;
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { type EXPORT_IMAGE_TYPES, Emitter } from "@excalidraw/common";
3
- import { LinearElementEditor, FlowChartCreator, Scene, Store, type ElementUpdate } from "@excalidraw/element";
4
- import type { ExcalidrawElement, NonDeleted, NonDeletedExcalidrawElement, ExcalidrawFrameLikeElement, ExcalidrawIframeElement, ExcalidrawEmbeddableElement, Ordered } from "@excalidraw/element/types";
3
+ import { LinearElementEditor, FlowChartCreator, Scene, Store, type ElementUpdate, StoreDelta, type ApplyToOptions } from "@excalidraw/element";
4
+ import type { ExcalidrawElement, NonDeleted, NonDeletedExcalidrawElement, ExcalidrawFrameLikeElement, ExcalidrawIframeElement, ExcalidrawEmbeddableElement, Ordered, SceneElementsMap } from "@excalidraw/element/types";
5
5
  import type { Mutable } from "@excalidraw/common/utility-types";
6
6
  import { ActionManager } from "../actions/manager";
7
7
  import { AnimationFrameHandler } from "../animation-frame-handler";
@@ -397,6 +397,7 @@ declare class App extends React.Component<AppProps, AppState> {
397
397
  */
398
398
  captureUpdate?: SceneData["captureUpdate"];
399
399
  }) => void;
400
+ applyDeltas: (deltas: StoreDelta[], options?: ApplyToOptions) => [SceneElementsMap, AppState, boolean];
400
401
  mutateElement: <TElement extends Mutable<ExcalidrawElement>>(element: TElement, updates: ElementUpdate<TElement>, informMutation?: boolean) => TElement;
401
402
  private triggerRender;
402
403
  /**
@@ -3,4 +3,5 @@ import type { MakeBrand } from "@excalidraw/common/utility-types";
3
3
  import type { AppState } from "../types";
4
4
  export type ReconciledExcalidrawElement = OrderedExcalidrawElement & MakeBrand<"ReconciledElement">;
5
5
  export type RemoteExcalidrawElement = OrderedExcalidrawElement & MakeBrand<"RemoteExcalidrawElement">;
6
+ export declare const shouldDiscardRemoteElement: (localAppState: AppState, local: OrderedExcalidrawElement | undefined, remote: RemoteExcalidrawElement) => boolean;
6
7
  export declare const reconcileElements: (localElements: readonly OrderedExcalidrawElement[], remoteElements: readonly RemoteExcalidrawElement[], localAppState: AppState) => ReconciledExcalidrawElement[];
@@ -1,4 +1,4 @@
1
- import type { ExcalidrawElement, OrderedExcalidrawElement } from "@excalidraw/element/types";
1
+ import type { ExcalidrawArrowElement, ExcalidrawElement, ExcalidrawLinearElement, ExcalidrawSelectionElement, ExcalidrawTextElement, OrderedExcalidrawElement } from "@excalidraw/element/types";
2
2
  import type { AppState, BinaryFiles, LibraryItem } from "../types";
3
3
  import type { ImportedDataState } from "./types";
4
4
  type RestoredAppState = Omit<AppState, "offsetTop" | "offsetLeft" | "width" | "height">;
@@ -8,14 +8,19 @@ export type RestoredDataState = {
8
8
  appState: RestoredAppState;
9
9
  files: BinaryFiles;
10
10
  };
11
+ export declare const restoreElement: (element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>, opts?: {
12
+ deleteInvisibleElements?: boolean;
13
+ }) => ExcalidrawTextElement | import("@excalidraw/element/types").ExcalidrawRectangleElement | import("@excalidraw/element/types").ExcalidrawDiamondElement | import("@excalidraw/element/types").ExcalidrawFrameElement | import("@excalidraw/element/types").ExcalidrawMagicFrameElement | import("@excalidraw/element/types").ExcalidrawEmbeddableElement | import("@excalidraw/element/types").ExcalidrawImageElement | import("@excalidraw/element/types").ExcalidrawIframeElement | import("@excalidraw/element/types").ExcalidrawEllipseElement | ExcalidrawLinearElement | ExcalidrawArrowElement | import("@excalidraw/element/types").ExcalidrawFreeDrawElement | null;
11
14
  export declare const restoreElements: (elements: ImportedDataState["elements"], localElements: readonly ExcalidrawElement[] | null | undefined, opts?: {
12
15
  refreshDimensions?: boolean;
13
16
  repairBindings?: boolean;
17
+ deleteInvisibleElements?: boolean;
14
18
  } | undefined) => OrderedExcalidrawElement[];
15
19
  export declare const restoreAppState: (appState: ImportedDataState["appState"], localAppState: Partial<AppState> | null | undefined) => RestoredAppState;
16
20
  export declare const restore: (data: Pick<ImportedDataState, "appState" | "elements" | "files"> | null, localAppState: Partial<AppState> | null | undefined, localElements: readonly ExcalidrawElement[] | null | undefined, elementsConfig?: {
17
21
  refreshDimensions?: boolean;
18
22
  repairBindings?: boolean;
23
+ deleteInvisibleElements?: boolean;
19
24
  }) => RestoredDataState;
20
25
  export declare const restoreLibraryItems: (libraryItems: ImportedDataState["libraryItems"], defaultStatus: LibraryItem["status"]) => LibraryItem[];
21
26
  export {};
@@ -12,7 +12,7 @@ export { getSceneVersion, hashElementsVersion, hashString, getNonDeletedElements
12
12
  export { getTextFromElements } from "@excalidraw/element";
13
13
  export { isInvisiblySmallElement } from "@excalidraw/element";
14
14
  export { defaultLang, useI18n, languages } from "./i18n";
15
- export { restore, restoreAppState, restoreElements, restoreLibraryItems, } from "./data/restore";
15
+ export { restore, restoreAppState, restoreElement, restoreElements, restoreLibraryItems, } from "./data/restore";
16
16
  export { reconcileElements } from "./data/reconcile";
17
17
  export { exportToCanvas, exportToBlob, exportToSvg, exportToClipboard, } from "@excalidraw/utils/export";
18
18
  export { serializeAsJSON, serializeLibraryAsJSON } from "./data/json";
@@ -155,8 +155,10 @@ export type ObservedElementsAppState = {
155
155
  editingGroupId: AppState["editingGroupId"];
156
156
  selectedElementIds: AppState["selectedElementIds"];
157
157
  selectedGroupIds: AppState["selectedGroupIds"];
158
- selectedLinearElementId: LinearElementEditor["elementId"] | null;
159
- selectedLinearElementIsEditing: boolean | null;
158
+ selectedLinearElement: {
159
+ elementId: LinearElementEditor["elementId"];
160
+ isEditing: boolean;
161
+ } | null;
160
162
  croppingElementId: AppState["croppingElementId"];
161
163
  lockedMultiSelections: AppState["lockedMultiSelections"];
162
164
  activeLockedId: AppState["activeLockedId"];
@@ -616,6 +618,7 @@ export type PointerDownState = Readonly<{
616
618
  export type UnsubscribeCallback = () => void;
617
619
  export interface ExcalidrawImperativeAPI {
618
620
  updateScene: InstanceType<typeof App>["updateScene"];
621
+ applyDeltas: InstanceType<typeof App>["applyDeltas"];
619
622
  mutateElement: InstanceType<typeof App>["mutateElement"];
620
623
  updateLibrary: InstanceType<typeof Library>["updateLibrary"];
621
624
  resetScene: InstanceType<typeof App>["resetScene"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/common",
3
- "version": "0.18.0-c65b684e9",
3
+ "version": "0.18.0-c6f8ef9",
4
4
  "type": "module",
5
5
  "types": "./dist/types/common/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",