Compare commits
9 Commits
master
...
mrazator/v
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0428c07a63 | ||
![]() |
57c0eca619 | ||
![]() |
c1a9c68e04 | ||
![]() |
9093908663 | ||
![]() |
bc1a71e772 | ||
![]() |
14d512f321 | ||
![]() |
41c036e1a5 | ||
![]() |
91d36e9b81 | ||
![]() |
27522110df |
@ -1,3 +1,5 @@
|
|||||||
|
MODE="development"
|
||||||
|
|
||||||
VITE_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/
|
VITE_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/
|
||||||
VITE_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/
|
VITE_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
VITE_APP_BACKEND_V2_GET_URL=https://ex.dylanbanta.com/api/v2/scenes/
|
MODE="production"
|
||||||
VITE_APP_BACKEND_V2_POST_URL=https://ex.dylanbanta.com/api/v2/scenes/
|
|
||||||
|
VITE_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/
|
||||||
|
VITE_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/
|
||||||
|
|
||||||
VITE_APP_LIBRARY_URL=https://libraries.excalidraw.com
|
VITE_APP_LIBRARY_URL=https://libraries.excalidraw.com
|
||||||
VITE_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries
|
VITE_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries
|
||||||
|
@ -34,6 +34,9 @@
|
|||||||
<a href="https://discord.gg/UexuTaE">
|
<a href="https://discord.gg/UexuTaE">
|
||||||
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/>
|
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://deepwiki.com/excalidraw/excalidraw">
|
||||||
|
<img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" />
|
||||||
|
</a>
|
||||||
<a href="https://twitter.com/excalidraw">
|
<a href="https://twitter.com/excalidraw">
|
||||||
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/>
|
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/>
|
||||||
</a>
|
</a>
|
||||||
|
@ -19,7 +19,7 @@ services:
|
|||||||
- ./:/opt/node_app/app:delegated
|
- ./:/opt/node_app/app:delegated
|
||||||
- ./package.json:/opt/node_app/package.json
|
- ./package.json:/opt/node_app/package.json
|
||||||
- ./yarn.lock:/opt/node_app/yarn.lock
|
- ./yarn.lock:/opt/node_app/yarn.lock
|
||||||
# - notused:/opt/node_app/app/node_modules
|
- notused:/opt/node_app/app/node_modules
|
||||||
|
|
||||||
# volumes:
|
volumes:
|
||||||
# notused:
|
notused:
|
||||||
|
@ -926,21 +926,16 @@ const ExcalidrawWrapper = () => {
|
|||||||
<ShareDialog
|
<ShareDialog
|
||||||
collabAPI={collabAPI}
|
collabAPI={collabAPI}
|
||||||
onExportToBackend={async () => {
|
onExportToBackend={async () => {
|
||||||
if (!excalidrawAPI) {
|
if (excalidrawAPI) {
|
||||||
return;
|
try {
|
||||||
}
|
await onExportToBackend(
|
||||||
try {
|
excalidrawAPI.getSceneElements(),
|
||||||
const { url, errorMessage } = await exportToBackend(
|
excalidrawAPI.getAppState(),
|
||||||
excalidrawAPI.getSceneElements(),
|
excalidrawAPI.getFiles(),
|
||||||
excalidrawAPI.getAppState(),
|
);
|
||||||
excalidrawAPI.getFiles(),
|
} catch (error: any) {
|
||||||
);
|
setErrorMessage(error.message);
|
||||||
if (errorMessage) {
|
|
||||||
throw new Error(errorMessage);
|
|
||||||
}
|
}
|
||||||
setLatestShareableLink(url);
|
|
||||||
} catch (error: any) {
|
|
||||||
setErrorMessage(error.message);
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
"prettier": "@excalidraw/prettier-config",
|
"prettier": "@excalidraw/prettier-config",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-node": "node ./scripts/build-node.js",
|
"build-node": "node ./scripts/build-node.js",
|
||||||
"build:app:docker": "vite build",
|
"build:app:docker": "cross-env VITE_APP_DISABLE_SENTRY=true vite build",
|
||||||
"build:app": "vite build",
|
"build:app": "cross-env VITE_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA cross-env VITE_APP_ENABLE_TRACKING=true vite build",
|
||||||
"build:version": "node ../scripts/build-version.js",
|
"build:version": "node ../scripts/build-version.js",
|
||||||
"build": "yarn build:app && yarn build:version",
|
"build": "yarn build:app && yarn build:version",
|
||||||
"start": "yarn && vite",
|
"start": "yarn && vite",
|
||||||
|
@ -205,6 +205,7 @@ describe("collaboration", () => {
|
|||||||
// with explicit undo (as addition) we expect our item to be restored from the snapshot!
|
// with explicit undo (as addition) we expect our item to be restored from the snapshot!
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
expect(API.getSnapshot()).toEqual([
|
expect(API.getSnapshot()).toEqual([
|
||||||
expect.objectContaining(rect1Props),
|
expect.objectContaining(rect1Props),
|
||||||
expect.objectContaining({ ...rect2Props, isDeleted: false }),
|
expect.objectContaining({ ...rect2Props, isDeleted: false }),
|
||||||
@ -236,7 +237,7 @@ describe("collaboration", () => {
|
|||||||
|
|
||||||
// with explicit redo (as removal) we again restore the element from the snapshot!
|
// with explicit redo (as removal) we again restore the element from the snapshot!
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(API.getSnapshot()).toEqual([
|
expect(API.getSnapshot()).toEqual([
|
||||||
expect.objectContaining(rect1Props),
|
expect.objectContaining(rect1Props),
|
||||||
@ -248,13 +249,11 @@ describe("collaboration", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
act(() => h.app.actionManager.executeAction(undoAction));
|
|
||||||
|
|
||||||
// simulate local update
|
// simulate local update
|
||||||
API.updateScene({
|
API.updateScene({
|
||||||
elements: syncInvalidIndices([
|
elements: syncInvalidIndices([
|
||||||
h.elements[0],
|
h.elements[0],
|
||||||
newElementWith(h.elements[1], { x: 100 }),
|
newElementWith(h.elements[1], { x: 100, isDeleted: false }),
|
||||||
]),
|
]),
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
});
|
});
|
||||||
@ -271,55 +270,5 @@ describe("collaboration", () => {
|
|||||||
expect.objectContaining({ ...rect2Props, isDeleted: false, x: 100 }),
|
expect.objectContaining({ ...rect2Props, isDeleted: false, x: 100 }),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
act(() => h.app.actionManager.executeAction(undoAction));
|
|
||||||
|
|
||||||
// we expect to iterate the stack to the first visible change
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(API.getSnapshot()).toEqual([
|
|
||||||
expect.objectContaining(rect1Props),
|
|
||||||
expect.objectContaining({ ...rect2Props, isDeleted: false, x: 0 }),
|
|
||||||
]);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining(rect1Props),
|
|
||||||
expect.objectContaining({ ...rect2Props, isDeleted: false, x: 0 }),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
// simulate force deleting the element remotely
|
|
||||||
API.updateScene({
|
|
||||||
elements: syncInvalidIndices([rect1]),
|
|
||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
|
||||||
});
|
|
||||||
|
|
||||||
// snapshot was correctly updated and marked the element as deleted
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(API.getSnapshot()).toEqual([
|
|
||||||
expect.objectContaining(rect1Props),
|
|
||||||
expect.objectContaining({ ...rect2Props, isDeleted: true, x: 0 }),
|
|
||||||
]);
|
|
||||||
expect(h.elements).toEqual([expect.objectContaining(rect1Props)]);
|
|
||||||
});
|
|
||||||
|
|
||||||
act(() => h.app.actionManager.executeAction(redoAction));
|
|
||||||
|
|
||||||
// with explicit redo (as update) we again restored the element from the snapshot!
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(API.getSnapshot()).toEqual([
|
|
||||||
expect.objectContaining({ id: "A", isDeleted: false }),
|
|
||||||
expect.objectContaining({ id: "B", isDeleted: true, x: 100 }),
|
|
||||||
]);
|
|
||||||
expect(h.history.isRedoStackEmpty).toBeTruthy();
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({ id: "A", isDeleted: false }),
|
|
||||||
expect.objectContaining({ id: "B", isDeleted: true, x: 100 }),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -712,8 +712,8 @@ export const arrayToObject = <T>(
|
|||||||
array: readonly T[],
|
array: readonly T[],
|
||||||
groupBy?: (value: T) => string | number,
|
groupBy?: (value: T) => string | number,
|
||||||
) =>
|
) =>
|
||||||
array.reduce((acc, value) => {
|
array.reduce((acc, value, idx) => {
|
||||||
acc[groupBy ? groupBy(value) : String(value)] = value;
|
acc[groupBy ? groupBy(value) : idx] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as { [key: string]: T });
|
}, {} as { [key: string]: T });
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawImageElement,
|
ExcalidrawFreeDrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
NonDeleted,
|
NonDeleted,
|
||||||
@ -18,7 +18,12 @@ import type {
|
|||||||
SceneElementsMap,
|
SceneElementsMap,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type { DTO, SubtypeOf, ValueOf } from "@excalidraw/common/utility-types";
|
import type {
|
||||||
|
DTO,
|
||||||
|
Mutable,
|
||||||
|
SubtypeOf,
|
||||||
|
ValueOf,
|
||||||
|
} from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
AppState,
|
AppState,
|
||||||
@ -51,6 +56,8 @@ import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex";
|
|||||||
|
|
||||||
import { Scene } from "./Scene";
|
import { Scene } from "./Scene";
|
||||||
|
|
||||||
|
import { StoreSnapshot } from "./store";
|
||||||
|
|
||||||
import type { BindableProp, BindingProp } from "./binding";
|
import type { BindableProp, BindingProp } from "./binding";
|
||||||
|
|
||||||
import type { ElementUpdate } from "./mutateElement";
|
import type { ElementUpdate } from "./mutateElement";
|
||||||
@ -256,12 +263,14 @@ export class Delta<T> {
|
|||||||
arrayToObject(deletedArray, groupBy),
|
arrayToObject(deletedArray, groupBy),
|
||||||
arrayToObject(insertedArray, groupBy),
|
arrayToObject(insertedArray, groupBy),
|
||||||
),
|
),
|
||||||
|
(x) => x,
|
||||||
);
|
);
|
||||||
const insertedDifferences = arrayToObject(
|
const insertedDifferences = arrayToObject(
|
||||||
Delta.getRightDifferences(
|
Delta.getRightDifferences(
|
||||||
arrayToObject(deletedArray, groupBy),
|
arrayToObject(deletedArray, groupBy),
|
||||||
arrayToObject(insertedArray, groupBy),
|
arrayToObject(insertedArray, groupBy),
|
||||||
),
|
),
|
||||||
|
(x) => x,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -858,10 +867,17 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ElementPartial<T extends ExcalidrawElement = ExcalidrawElement> = Omit<
|
type ElementPartial<TElement extends ExcalidrawElement = ExcalidrawElement> =
|
||||||
ElementUpdate<Ordered<T>>,
|
Omit<Partial<Ordered<TElement>>, "id" | "updated" | "seed">;
|
||||||
"seed"
|
|
||||||
>;
|
export type ApplyToOptions = {
|
||||||
|
excludedProperties: Set<keyof ElementPartial>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ApplyToFlags = {
|
||||||
|
containsVisibleDifference: boolean;
|
||||||
|
containsZindexDifference: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elements change is a low level primitive to capture a change between two sets of elements.
|
* Elements change is a low level primitive to capture a change between two sets of elements.
|
||||||
@ -1150,12 +1166,15 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
|
|
||||||
public applyTo(
|
public applyTo(
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
elementsSnapshot: Map<string, OrderedExcalidrawElement>,
|
snapshot: StoreSnapshot["elements"] = StoreSnapshot.empty().elements,
|
||||||
|
options: ApplyToOptions = {
|
||||||
|
excludedProperties: new Set(),
|
||||||
|
},
|
||||||
): [SceneElementsMap, boolean] {
|
): [SceneElementsMap, boolean] {
|
||||||
let nextElements = new Map(elements) as SceneElementsMap;
|
let nextElements = new Map(elements) as SceneElementsMap;
|
||||||
let changedElements: Map<string, OrderedExcalidrawElement>;
|
let changedElements: Map<string, OrderedExcalidrawElement>;
|
||||||
|
|
||||||
const flags = {
|
const flags: ApplyToFlags = {
|
||||||
containsVisibleDifference: false,
|
containsVisibleDifference: false,
|
||||||
containsZindexDifference: false,
|
containsZindexDifference: false,
|
||||||
};
|
};
|
||||||
@ -1164,13 +1183,14 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
try {
|
try {
|
||||||
const applyDeltas = ElementsDelta.createApplier(
|
const applyDeltas = ElementsDelta.createApplier(
|
||||||
nextElements,
|
nextElements,
|
||||||
elementsSnapshot,
|
snapshot,
|
||||||
|
options,
|
||||||
flags,
|
flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
const addedElements = applyDeltas("added", this.added);
|
const addedElements = applyDeltas(this.added);
|
||||||
const removedElements = applyDeltas("removed", this.removed);
|
const removedElements = applyDeltas(this.removed);
|
||||||
const updatedElements = applyDeltas("updated", this.updated);
|
const updatedElements = applyDeltas(this.updated);
|
||||||
|
|
||||||
const affectedElements = this.resolveConflicts(elements, nextElements);
|
const affectedElements = this.resolveConflicts(elements, nextElements);
|
||||||
|
|
||||||
@ -1229,18 +1249,12 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
private static createApplier =
|
private static createApplier =
|
||||||
(
|
(
|
||||||
nextElements: SceneElementsMap,
|
nextElements: SceneElementsMap,
|
||||||
snapshot: Map<string, OrderedExcalidrawElement>,
|
snapshot: StoreSnapshot["elements"],
|
||||||
flags: {
|
options: ApplyToOptions,
|
||||||
containsVisibleDifference: boolean;
|
flags: ApplyToFlags,
|
||||||
containsZindexDifference: boolean;
|
|
||||||
},
|
|
||||||
) =>
|
) =>
|
||||||
(
|
(deltas: Record<string, Delta<ElementPartial>>) => {
|
||||||
type: "added" | "removed" | "updated",
|
|
||||||
deltas: Record<string, Delta<ElementPartial>>,
|
|
||||||
) => {
|
|
||||||
const getElement = ElementsDelta.createGetter(
|
const getElement = ElementsDelta.createGetter(
|
||||||
type,
|
|
||||||
nextElements,
|
nextElements,
|
||||||
snapshot,
|
snapshot,
|
||||||
flags,
|
flags,
|
||||||
@ -1250,7 +1264,13 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
const element = getElement(id, delta.inserted);
|
const element = getElement(id, delta.inserted);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
const newElement = ElementsDelta.applyDelta(element, delta, flags);
|
const newElement = ElementsDelta.applyDelta(
|
||||||
|
element,
|
||||||
|
delta,
|
||||||
|
options,
|
||||||
|
flags,
|
||||||
|
);
|
||||||
|
|
||||||
nextElements.set(newElement.id, newElement);
|
nextElements.set(newElement.id, newElement);
|
||||||
acc.set(newElement.id, newElement);
|
acc.set(newElement.id, newElement);
|
||||||
}
|
}
|
||||||
@ -1261,13 +1281,9 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
|
|
||||||
private static createGetter =
|
private static createGetter =
|
||||||
(
|
(
|
||||||
type: "added" | "removed" | "updated",
|
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
snapshot: Map<string, OrderedExcalidrawElement>,
|
snapshot: StoreSnapshot["elements"],
|
||||||
flags: {
|
flags: ApplyToFlags,
|
||||||
containsVisibleDifference: boolean;
|
|
||||||
containsZindexDifference: boolean;
|
|
||||||
},
|
|
||||||
) =>
|
) =>
|
||||||
(id: string, partial: ElementPartial) => {
|
(id: string, partial: ElementPartial) => {
|
||||||
let element = elements.get(id);
|
let element = elements.get(id);
|
||||||
@ -1281,10 +1297,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
flags.containsZindexDifference = true;
|
flags.containsZindexDifference = true;
|
||||||
|
|
||||||
// as the element was force deleted, we need to check if adding it back results in a visible change
|
// as the element was force deleted, we need to check if adding it back results in a visible change
|
||||||
if (
|
if (!partial.isDeleted || (partial.isDeleted && !element.isDeleted)) {
|
||||||
partial.isDeleted === false ||
|
|
||||||
(partial.isDeleted !== true && element.isDeleted === false)
|
|
||||||
) {
|
|
||||||
flags.containsVisibleDifference = true;
|
flags.containsVisibleDifference = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1304,16 +1317,28 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
private static applyDelta(
|
private static applyDelta(
|
||||||
element: OrderedExcalidrawElement,
|
element: OrderedExcalidrawElement,
|
||||||
delta: Delta<ElementPartial>,
|
delta: Delta<ElementPartial>,
|
||||||
flags: {
|
options: ApplyToOptions,
|
||||||
containsVisibleDifference: boolean;
|
flags: ApplyToFlags,
|
||||||
containsZindexDifference: boolean;
|
|
||||||
} = {
|
|
||||||
// by default we don't care about about the flags
|
|
||||||
containsVisibleDifference: true,
|
|
||||||
containsZindexDifference: true,
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
const { boundElements, ...directlyApplicablePartial } = delta.inserted;
|
const directlyApplicablePartial: Mutable<ElementPartial> = {};
|
||||||
|
|
||||||
|
// some properties are not directly applicable, such as:
|
||||||
|
// - boundElements which contains only diff)
|
||||||
|
// - version & versionNonce, if we don't want to return to previous versions
|
||||||
|
for (const key of Object.keys(delta.inserted) as Array<
|
||||||
|
keyof typeof delta.inserted
|
||||||
|
>) {
|
||||||
|
if (key === "boundElements") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.excludedProperties.has(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = delta.inserted[key];
|
||||||
|
Reflect.set(directlyApplicablePartial, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
delta.deleted.boundElements?.length ||
|
delta.deleted.boundElements?.length ||
|
||||||
@ -1331,19 +1356,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this looks wrong, shouldn't be here
|
|
||||||
if (element.type === "image") {
|
|
||||||
const _delta = delta as Delta<ElementPartial<ExcalidrawImageElement>>;
|
|
||||||
// we want to override `crop` only if modified so that we don't reset
|
|
||||||
// when undoing/redoing unrelated change
|
|
||||||
if (_delta.deleted.crop || _delta.inserted.crop) {
|
|
||||||
Object.assign(directlyApplicablePartial, {
|
|
||||||
// apply change verbatim
|
|
||||||
crop: _delta.inserted.crop ?? null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!flags.containsVisibleDifference) {
|
if (!flags.containsVisibleDifference) {
|
||||||
// strip away fractional index, as even if it would be different, it doesn't have to result in visible change
|
// strip away fractional index, as even if it would be different, it doesn't have to result in visible change
|
||||||
const { index, ...rest } = directlyApplicablePartial;
|
const { index, ...rest } = directlyApplicablePartial;
|
||||||
@ -1650,6 +1662,32 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
): [ElementPartial, ElementPartial] {
|
): [ElementPartial, ElementPartial] {
|
||||||
try {
|
try {
|
||||||
Delta.diffArrays(deleted, inserted, "boundElements", (x) => x.id);
|
Delta.diffArrays(deleted, inserted, "boundElements", (x) => x.id);
|
||||||
|
|
||||||
|
// don't diff the points as:
|
||||||
|
// - we can't ensure the multiplayer order consistency without fractional index on each point
|
||||||
|
// - we prefer to not merge the points, as it might just lead to unexpected / incosistent results
|
||||||
|
const deletedPoints =
|
||||||
|
(
|
||||||
|
deleted as ElementPartial<
|
||||||
|
ExcalidrawFreeDrawElement | ExcalidrawLinearElement
|
||||||
|
>
|
||||||
|
).points ?? [];
|
||||||
|
|
||||||
|
const insertedPoints =
|
||||||
|
(
|
||||||
|
inserted as ElementPartial<
|
||||||
|
ExcalidrawFreeDrawElement | ExcalidrawLinearElement
|
||||||
|
>
|
||||||
|
).points ?? [];
|
||||||
|
|
||||||
|
if (
|
||||||
|
!Delta.isLeftDifferent(deletedPoints, insertedPoints) &&
|
||||||
|
!Delta.isRightDifferent(deletedPoints, insertedPoints)
|
||||||
|
) {
|
||||||
|
// delete the points from delta if there is no difference, otherwise leave them as they were captured due to consistency
|
||||||
|
Reflect.deleteProperty(deleted, "points");
|
||||||
|
Reflect.deleteProperty(inserted, "points");
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// if postprocessing fails, it does not make sense to bubble up, but let's make sure we know about it
|
// if postprocessing fails, it does not make sense to bubble up, but let's make sure we know about it
|
||||||
console.error(`Couldn't postprocess elements delta.`);
|
console.error(`Couldn't postprocess elements delta.`);
|
||||||
@ -1665,7 +1703,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
private static stripIrrelevantProps(
|
private static stripIrrelevantProps(
|
||||||
partial: Partial<OrderedExcalidrawElement>,
|
partial: Partial<OrderedExcalidrawElement>,
|
||||||
): ElementPartial {
|
): ElementPartial {
|
||||||
const { id, updated, version, versionNonce, ...strippedPartial } = partial;
|
const { id, updated, ...strippedPartial } = partial;
|
||||||
|
|
||||||
return strippedPartial;
|
return strippedPartial;
|
||||||
}
|
}
|
||||||
|
@ -974,6 +974,25 @@ export const updateElbowArrowPoints = (
|
|||||||
),
|
),
|
||||||
"Elbow arrow segments must be either horizontal or vertical",
|
"Elbow arrow segments must be either horizontal or vertical",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
updates.fixedSegments?.find(
|
||||||
|
(segment) =>
|
||||||
|
segment.index === 1 &&
|
||||||
|
pointsEqual(segment.start, (updates.points ?? arrow.points)[0]),
|
||||||
|
) == null &&
|
||||||
|
updates.fixedSegments?.find(
|
||||||
|
(segment) =>
|
||||||
|
segment.index === (updates.points ?? arrow.points).length - 1 &&
|
||||||
|
pointsEqual(
|
||||||
|
segment.end,
|
||||||
|
(updates.points ?? arrow.points)[
|
||||||
|
(updates.points ?? arrow.points).length - 1
|
||||||
|
],
|
||||||
|
),
|
||||||
|
) == null,
|
||||||
|
"The first and last segments cannot be fixed",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixedSegments = updates.fixedSegments ?? arrow.fixedSegments ?? [];
|
const fixedSegments = updates.fixedSegments ?? arrow.fixedSegments ?? [];
|
||||||
|
@ -2,7 +2,9 @@ import { generateNKeysBetween } from "fractional-indexing";
|
|||||||
|
|
||||||
import { arrayToMap } from "@excalidraw/common";
|
import { arrayToMap } from "@excalidraw/common";
|
||||||
|
|
||||||
import { mutateElement } from "./mutateElement";
|
import type { Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
|
import { mutateElement, newElementWith } from "./mutateElement";
|
||||||
import { getBoundTextElement } from "./textElement";
|
import { getBoundTextElement } from "./textElement";
|
||||||
import { hasBoundTextElement } from "./typeChecks";
|
import { hasBoundTextElement } from "./typeChecks";
|
||||||
|
|
||||||
@ -161,9 +163,15 @@ export const syncMovedIndices = (
|
|||||||
|
|
||||||
// try generatating indices, throws on invalid movedElements
|
// try generatating indices, throws on invalid movedElements
|
||||||
const elementsUpdates = generateIndices(elements, indicesGroups);
|
const elementsUpdates = generateIndices(elements, indicesGroups);
|
||||||
const elementsCandidates = elements.map((x) =>
|
const elementsCandidates = elements.map((x) => {
|
||||||
elementsUpdates.has(x) ? { ...x, ...elementsUpdates.get(x) } : x,
|
const elementUpdates = elementsUpdates.get(x);
|
||||||
);
|
|
||||||
|
if (elementUpdates) {
|
||||||
|
return { ...x, index: elementUpdates.index };
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
});
|
||||||
|
|
||||||
// ensure next indices are valid before mutation, throws on invalid ones
|
// ensure next indices are valid before mutation, throws on invalid ones
|
||||||
validateFractionalIndices(
|
validateFractionalIndices(
|
||||||
@ -177,8 +185,8 @@ export const syncMovedIndices = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
// split mutation so we don't end up in an incosistent state
|
// split mutation so we don't end up in an incosistent state
|
||||||
for (const [element, update] of elementsUpdates) {
|
for (const [element, { index }] of elementsUpdates) {
|
||||||
mutateElement(element, elementsMap, update);
|
mutateElement(element, elementsMap, { index });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// fallback to default sync
|
// fallback to default sync
|
||||||
@ -189,19 +197,33 @@ export const syncMovedIndices = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronizes all invalid fractional indices with the array order by mutating passed elements.
|
* Synchronizes all invalid fractional indices with the array order by mutating passed elements array.
|
||||||
|
*
|
||||||
|
* When `shouldCreateNewInstances` is true, it creates new instances of the elements, instead of mutating the existing ones.
|
||||||
*
|
*
|
||||||
* WARN: in edge cases it could modify the elements which were not moved, as it's impossible to guess the actually moved elements from the elements array itself.
|
* WARN: in edge cases it could modify the elements which were not moved, as it's impossible to guess the actually moved elements from the elements array itself.
|
||||||
*/
|
*/
|
||||||
export const syncInvalidIndices = (
|
export const syncInvalidIndices = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
|
{
|
||||||
|
shouldCreateNewInstances = false,
|
||||||
|
}: {
|
||||||
|
shouldCreateNewInstances?: boolean;
|
||||||
|
} = {},
|
||||||
): OrderedExcalidrawElement[] => {
|
): OrderedExcalidrawElement[] => {
|
||||||
const elementsMap = arrayToMap(elements);
|
|
||||||
const indicesGroups = getInvalidIndicesGroups(elements);
|
const indicesGroups = getInvalidIndicesGroups(elements);
|
||||||
const elementsUpdates = generateIndices(elements, indicesGroups);
|
const elementsUpdates = generateIndices(elements, indicesGroups);
|
||||||
|
|
||||||
for (const [element, update] of elementsUpdates) {
|
for (const [element, { index, arrayIndex }] of elementsUpdates) {
|
||||||
mutateElement(element, elementsMap, update);
|
if (shouldCreateNewInstances) {
|
||||||
|
const updatedElement = newElementWith(element, { index });
|
||||||
|
|
||||||
|
// mutate the element in the array with the new updated instance
|
||||||
|
(elements as Mutable<typeof elements>)[arrayIndex] = updatedElement;
|
||||||
|
} else {
|
||||||
|
const elementsMap = arrayToMap(elements);
|
||||||
|
mutateElement(element, elementsMap, { index });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements as OrderedExcalidrawElement[];
|
return elements as OrderedExcalidrawElement[];
|
||||||
@ -380,7 +402,7 @@ const generateIndices = (
|
|||||||
) => {
|
) => {
|
||||||
const elementsUpdates = new Map<
|
const elementsUpdates = new Map<
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
{ index: FractionalIndex }
|
{ index: FractionalIndex; arrayIndex: number }
|
||||||
>();
|
>();
|
||||||
|
|
||||||
for (const indices of indicesGroups) {
|
for (const indices of indicesGroups) {
|
||||||
@ -398,6 +420,7 @@ const generateIndices = (
|
|||||||
|
|
||||||
elementsUpdates.set(element, {
|
elementsUpdates.set(element, {
|
||||||
index: fractionalIndices[i],
|
index: fractionalIndices[i],
|
||||||
|
arrayIndex: indices[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,16 +213,7 @@ export class Store {
|
|||||||
// using the same instance, since in history we have a check against `HistoryEntry`, so that we don't re-record the same delta again
|
// using the same instance, since in history we have a check against `HistoryEntry`, so that we don't re-record the same delta again
|
||||||
storeDelta = delta;
|
storeDelta = delta;
|
||||||
} else {
|
} else {
|
||||||
// calculate the deltas based on the previous and next snapshot
|
storeDelta = StoreDelta.calculate(prevSnapshot, snapshot);
|
||||||
const elementsDelta = snapshot.metadata.didElementsChange
|
|
||||||
? ElementsDelta.calculate(prevSnapshot.elements, snapshot.elements)
|
|
||||||
: ElementsDelta.empty();
|
|
||||||
|
|
||||||
const appStateDelta = snapshot.metadata.didAppStateChange
|
|
||||||
? AppStateDelta.calculate(prevSnapshot.appState, snapshot.appState)
|
|
||||||
: AppStateDelta.empty();
|
|
||||||
|
|
||||||
storeDelta = StoreDelta.create(elementsDelta, appStateDelta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!storeDelta.isEmpty()) {
|
if (!storeDelta.isEmpty()) {
|
||||||
@ -505,6 +496,24 @@ export class StoreDelta {
|
|||||||
return new this(opts.id, elements, appState);
|
return new this(opts.id, elements, appState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the delta between the previous and next snapshot.
|
||||||
|
*/
|
||||||
|
public static calculate(
|
||||||
|
prevSnapshot: StoreSnapshot,
|
||||||
|
nextSnapshot: StoreSnapshot,
|
||||||
|
) {
|
||||||
|
const elementsDelta = nextSnapshot.metadata.didElementsChange
|
||||||
|
? ElementsDelta.calculate(prevSnapshot.elements, nextSnapshot.elements)
|
||||||
|
: ElementsDelta.empty();
|
||||||
|
|
||||||
|
const appStateDelta = nextSnapshot.metadata.didAppStateChange
|
||||||
|
? AppStateDelta.calculate(prevSnapshot.appState, nextSnapshot.appState)
|
||||||
|
: AppStateDelta.empty();
|
||||||
|
|
||||||
|
return this.create(elementsDelta, appStateDelta);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore a store delta instance from a DTO.
|
* Restore a store delta instance from a DTO.
|
||||||
*/
|
*/
|
||||||
@ -524,9 +533,7 @@ export class StoreDelta {
|
|||||||
id,
|
id,
|
||||||
elements: { added, removed, updated },
|
elements: { added, removed, updated },
|
||||||
}: DTO<StoreDelta>) {
|
}: DTO<StoreDelta>) {
|
||||||
const elements = ElementsDelta.create(added, removed, updated, {
|
const elements = ElementsDelta.create(added, removed, updated);
|
||||||
shouldRedistribute: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
return new this(id, elements, AppStateDelta.empty());
|
return new this(id, elements, AppStateDelta.empty());
|
||||||
}
|
}
|
||||||
@ -534,27 +541,10 @@ export class StoreDelta {
|
|||||||
/**
|
/**
|
||||||
* Inverse store delta, creates new instance of `StoreDelta`.
|
* Inverse store delta, creates new instance of `StoreDelta`.
|
||||||
*/
|
*/
|
||||||
public static inverse(delta: StoreDelta): StoreDelta {
|
public static inverse(delta: StoreDelta) {
|
||||||
return this.create(delta.elements.inverse(), delta.appState.inverse());
|
return this.create(delta.elements.inverse(), delta.appState.inverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply latest (remote) changes to the delta, creates new instance of `StoreDelta`.
|
|
||||||
*/
|
|
||||||
public static applyLatestChanges(
|
|
||||||
delta: StoreDelta,
|
|
||||||
elements: SceneElementsMap,
|
|
||||||
modifierOptions: "deleted" | "inserted",
|
|
||||||
): StoreDelta {
|
|
||||||
return this.create(
|
|
||||||
delta.elements.applyLatestChanges(elements, modifierOptions),
|
|
||||||
delta.appState,
|
|
||||||
{
|
|
||||||
id: delta.id,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the delta to the passed elements and appState, does not modify the snapshot.
|
* Apply the delta to the passed elements and appState, does not modify the snapshot.
|
||||||
*/
|
*/
|
||||||
@ -562,12 +552,9 @@ export class StoreDelta {
|
|||||||
delta: StoreDelta,
|
delta: StoreDelta,
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
prevSnapshot: StoreSnapshot = StoreSnapshot.empty(),
|
|
||||||
): [SceneElementsMap, AppState, boolean] {
|
): [SceneElementsMap, AppState, boolean] {
|
||||||
const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
|
const [nextElements, elementsContainVisibleChange] =
|
||||||
elements,
|
delta.elements.applyTo(elements);
|
||||||
prevSnapshot.elements,
|
|
||||||
);
|
|
||||||
|
|
||||||
const [nextAppState, appStateContainsVisibleChange] =
|
const [nextAppState, appStateContainsVisibleChange] =
|
||||||
delta.appState.applyTo(appState, nextElements);
|
delta.appState.applyTo(appState, nextElements);
|
||||||
@ -687,11 +674,10 @@ export class StoreSnapshot {
|
|||||||
nextElements.set(id, changedElement);
|
nextElements.set(id, changedElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextAppState = Object.assign(
|
const nextAppState = getObservedAppState({
|
||||||
{},
|
...this.appState,
|
||||||
this.appState,
|
...change.appState,
|
||||||
change.appState,
|
});
|
||||||
) as ObservedAppState;
|
|
||||||
|
|
||||||
return StoreSnapshot.create(nextElements, nextAppState, {
|
return StoreSnapshot.create(nextElements, nextAppState, {
|
||||||
// by default we assume that change is different from what we have in the snapshot
|
// by default we assume that change is different from what we have in the snapshot
|
||||||
@ -944,18 +930,26 @@ const getDefaultObservedAppState = (): ObservedAppState => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getObservedAppState = (appState: AppState): ObservedAppState => {
|
export const getObservedAppState = (
|
||||||
|
appState: AppState | ObservedAppState,
|
||||||
|
): ObservedAppState => {
|
||||||
const observedAppState = {
|
const observedAppState = {
|
||||||
name: appState.name,
|
name: appState.name,
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
viewBackgroundColor: appState.viewBackgroundColor,
|
viewBackgroundColor: appState.viewBackgroundColor,
|
||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
selectedGroupIds: appState.selectedGroupIds,
|
selectedGroupIds: appState.selectedGroupIds,
|
||||||
editingLinearElementId: appState.editingLinearElement?.elementId || null,
|
|
||||||
selectedLinearElementId: appState.selectedLinearElement?.elementId || null,
|
|
||||||
croppingElementId: appState.croppingElementId,
|
croppingElementId: appState.croppingElementId,
|
||||||
activeLockedId: appState.activeLockedId,
|
activeLockedId: appState.activeLockedId,
|
||||||
lockedMultiSelections: appState.lockedMultiSelections,
|
lockedMultiSelections: appState.lockedMultiSelections,
|
||||||
|
editingLinearElementId:
|
||||||
|
(appState as AppState).editingLinearElement?.elementId ?? // prefer app state, as it's likely newer
|
||||||
|
(appState as ObservedAppState).editingLinearElementId ?? // fallback to observed app state, as it's likely older coming from a previous snapshot
|
||||||
|
null,
|
||||||
|
selectedLinearElementId:
|
||||||
|
(appState as AppState).selectedLinearElement?.elementId ??
|
||||||
|
(appState as ObservedAppState).selectedLinearElementId ??
|
||||||
|
null,
|
||||||
};
|
};
|
||||||
|
|
||||||
Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
|
Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
|
||||||
|
@ -505,8 +505,6 @@ describe("group-related duplication", () => {
|
|||||||
mouse.up(frame.x + frame.width + 50, frame.y + frame.height + 50);
|
mouse.up(frame.x + frame.width + 50, frame.y + frame.height + 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log(h.elements);
|
|
||||||
|
|
||||||
assertElements(h.elements, [
|
assertElements(h.elements, [
|
||||||
{ id: frame.id },
|
{ id: frame.id },
|
||||||
{ id: rectangle1.id, frameId: frame.id },
|
{ id: rectangle1.id, frameId: frame.id },
|
||||||
|
@ -1483,13 +1483,13 @@ const getArrowheadOptions = (flip: boolean) => {
|
|||||||
value: "crowfoot_one",
|
value: "crowfoot_one",
|
||||||
text: t("labels.arrowhead_crowfoot_one"),
|
text: t("labels.arrowhead_crowfoot_one"),
|
||||||
icon: <ArrowheadCrowfootOneIcon flip={flip} />,
|
icon: <ArrowheadCrowfootOneIcon flip={flip} />,
|
||||||
keyBinding: "c",
|
keyBinding: "x",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "crowfoot_many",
|
value: "crowfoot_many",
|
||||||
text: t("labels.arrowhead_crowfoot_many"),
|
text: t("labels.arrowhead_crowfoot_many"),
|
||||||
icon: <ArrowheadCrowfootIcon flip={flip} />,
|
icon: <ArrowheadCrowfootIcon flip={flip} />,
|
||||||
keyBinding: "x",
|
keyBinding: "c",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "crowfoot_one_or_many",
|
value: "crowfoot_one_or_many",
|
||||||
|
@ -104,7 +104,11 @@ import {
|
|||||||
Emitter,
|
Emitter,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { getCommonBounds, getElementAbsoluteCoords } from "@excalidraw/element";
|
import {
|
||||||
|
getCommonBounds,
|
||||||
|
getElementAbsoluteCoords,
|
||||||
|
getObservedAppState,
|
||||||
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
@ -3993,22 +3997,30 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}) => {
|
}) => {
|
||||||
const { elements, appState, collaborators, captureUpdate } = sceneData;
|
const { elements, appState, collaborators, captureUpdate } = sceneData;
|
||||||
|
|
||||||
const nextElements = elements ? syncInvalidIndices(elements) : undefined;
|
const nextElements = elements
|
||||||
|
? syncInvalidIndices(elements, {
|
||||||
|
// we have to create new instances here, otherwise scheduled micro action below won't be able to
|
||||||
|
// detect the fractional index change and won't update the store snapshot
|
||||||
|
shouldCreateNewInstances: true,
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (captureUpdate) {
|
if (captureUpdate) {
|
||||||
const nextElementsMap = elements
|
const nextElementsMap = elements
|
||||||
? (arrayToMap(nextElements ?? []) as SceneElementsMap)
|
? (arrayToMap(nextElements ?? []) as SceneElementsMap)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const nextAppState = appState
|
const nextObservedAppState = appState
|
||||||
? // new instance, with partial appstate applied to previously captured one, including hidden prop inside `prevCommittedAppState`
|
? getObservedAppState({
|
||||||
Object.assign({}, this.store.snapshot.appState, appState)
|
...this.store.snapshot.appState,
|
||||||
|
...appState,
|
||||||
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
this.store.scheduleMicroAction({
|
this.store.scheduleMicroAction({
|
||||||
action: captureUpdate,
|
action: captureUpdate,
|
||||||
elements: nextElementsMap,
|
elements: nextElementsMap,
|
||||||
appState: nextAppState,
|
appState: nextObservedAppState,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,7 +564,7 @@ export const convertElementTypes = (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fixedSegments: FixedSegment[] = [];
|
const fixedSegments: FixedSegment[] = [];
|
||||||
for (let i = 0; i < nextPoints.length - 1; i++) {
|
for (let i = 1; i < nextPoints.length - 2; i++) {
|
||||||
fixedSegments.push({
|
fixedSegments.push({
|
||||||
start: nextPoints[i],
|
start: nextPoints[i],
|
||||||
end: nextPoints[i + 1],
|
end: nextPoints[i + 1],
|
||||||
@ -581,6 +581,7 @@ export const convertElementTypes = (
|
|||||||
);
|
);
|
||||||
mutateElement(element, app.scene.getNonDeletedElementsMap(), {
|
mutateElement(element, app.scene.getNonDeletedElementsMap(), {
|
||||||
...updates,
|
...updates,
|
||||||
|
endArrowhead: "arrow",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// if we're converting to non-elbow linear element, check if
|
// if we're converting to non-elbow linear element, check if
|
||||||
|
@ -7,11 +7,62 @@ import {
|
|||||||
type Store,
|
type Store,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
|
import type { StoreSnapshot } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { SceneElementsMap } from "@excalidraw/element/types";
|
import type { SceneElementsMap } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type { AppState } from "./types";
|
import type { AppState } from "./types";
|
||||||
|
|
||||||
class HistoryEntry extends StoreDelta {}
|
export class HistoryDelta extends StoreDelta {
|
||||||
|
/**
|
||||||
|
* Apply the delta to the passed elements and appState, does not modify the snapshot.
|
||||||
|
*/
|
||||||
|
public applyTo(
|
||||||
|
elements: SceneElementsMap,
|
||||||
|
appState: AppState,
|
||||||
|
snapshot: StoreSnapshot,
|
||||||
|
): [SceneElementsMap, AppState, boolean] {
|
||||||
|
const [nextElements, elementsContainVisibleChange] = this.elements.applyTo(
|
||||||
|
elements,
|
||||||
|
// used to fallback into local snapshot in case we couldn't apply the delta
|
||||||
|
// due to a missing elements in the scene (force deleted)
|
||||||
|
snapshot.elements,
|
||||||
|
// we don't want to apply the `version` and `versionNonce` properties for history
|
||||||
|
// as we always need to end up with a new version due to collaboration,
|
||||||
|
// approaching each undo / redo as a new user operation
|
||||||
|
{
|
||||||
|
excludedProperties: new Set(["version", "versionNonce"]),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const [nextAppState, appStateContainsVisibleChange] = this.appState.applyTo(
|
||||||
|
appState,
|
||||||
|
nextElements,
|
||||||
|
);
|
||||||
|
|
||||||
|
const appliedVisibleChanges =
|
||||||
|
elementsContainVisibleChange || appStateContainsVisibleChange;
|
||||||
|
|
||||||
|
return [nextElements, nextAppState, appliedVisibleChanges];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overriding once to avoid type casting everywhere.
|
||||||
|
*/
|
||||||
|
public static override calculate(
|
||||||
|
prevSnapshot: StoreSnapshot,
|
||||||
|
nextSnapshot: StoreSnapshot,
|
||||||
|
) {
|
||||||
|
return super.calculate(prevSnapshot, nextSnapshot) as HistoryDelta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overriding once to avoid type casting everywhere.
|
||||||
|
*/
|
||||||
|
public static override inverse(delta: StoreDelta): HistoryDelta {
|
||||||
|
return super.inverse(delta) as HistoryDelta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class HistoryChangedEvent {
|
export class HistoryChangedEvent {
|
||||||
constructor(
|
constructor(
|
||||||
@ -25,8 +76,8 @@ export class History {
|
|||||||
[HistoryChangedEvent]
|
[HistoryChangedEvent]
|
||||||
>();
|
>();
|
||||||
|
|
||||||
public readonly undoStack: HistoryEntry[] = [];
|
public readonly undoStack: HistoryDelta[] = [];
|
||||||
public readonly redoStack: HistoryEntry[] = [];
|
public readonly redoStack: HistoryDelta[] = [];
|
||||||
|
|
||||||
public get isUndoStackEmpty() {
|
public get isUndoStackEmpty() {
|
||||||
return this.undoStack.length === 0;
|
return this.undoStack.length === 0;
|
||||||
@ -48,16 +99,16 @@ export class History {
|
|||||||
* Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
|
* Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
|
||||||
*/
|
*/
|
||||||
public record(delta: StoreDelta) {
|
public record(delta: StoreDelta) {
|
||||||
if (delta.isEmpty() || delta instanceof HistoryEntry) {
|
if (delta.isEmpty() || delta instanceof HistoryDelta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct history entry, so once it's emitted, it's not recorded again
|
// construct history entry, so once it's emitted, it's not recorded again
|
||||||
const entry = HistoryEntry.inverse(delta);
|
const historyDelta = HistoryDelta.inverse(delta);
|
||||||
|
|
||||||
this.undoStack.push(entry);
|
this.undoStack.push(historyDelta);
|
||||||
|
|
||||||
if (!entry.elements.isEmpty()) {
|
if (!historyDelta.elements.isEmpty()) {
|
||||||
// don't reset redo stack on local appState changes,
|
// don't reset redo stack on local appState changes,
|
||||||
// as a simple click (unselect) could lead to losing all the redo entries
|
// as a simple click (unselect) could lead to losing all the redo entries
|
||||||
// only reset on non empty elements changes!
|
// only reset on non empty elements changes!
|
||||||
@ -74,7 +125,7 @@ export class History {
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
() => History.pop(this.undoStack),
|
() => History.pop(this.undoStack),
|
||||||
(entry: HistoryEntry) => History.push(this.redoStack, entry, elements),
|
(entry: HistoryDelta) => History.push(this.redoStack, entry),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,20 +134,20 @@ export class History {
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
() => History.pop(this.redoStack),
|
() => History.pop(this.redoStack),
|
||||||
(entry: HistoryEntry) => History.push(this.undoStack, entry, elements),
|
(entry: HistoryDelta) => History.push(this.undoStack, entry),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private perform(
|
private perform(
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
pop: () => HistoryEntry | null,
|
pop: () => HistoryDelta | null,
|
||||||
push: (entry: HistoryEntry) => void,
|
push: (entry: HistoryDelta) => void,
|
||||||
): [SceneElementsMap, AppState] | void {
|
): [SceneElementsMap, AppState] | void {
|
||||||
try {
|
try {
|
||||||
let historyEntry = pop();
|
let historyDelta = pop();
|
||||||
|
|
||||||
if (historyEntry === null) {
|
if (historyDelta === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,15 +160,10 @@ export class History {
|
|||||||
let containsVisibleChange = false;
|
let containsVisibleChange = false;
|
||||||
|
|
||||||
// iterate through the history entries in case they result in no visible changes
|
// iterate through the history entries in case they result in no visible changes
|
||||||
while (historyEntry) {
|
while (historyDelta) {
|
||||||
try {
|
try {
|
||||||
[nextElements, nextAppState, containsVisibleChange] =
|
[nextElements, nextAppState, containsVisibleChange] =
|
||||||
StoreDelta.applyTo(
|
historyDelta.applyTo(nextElements, nextAppState, prevSnapshot);
|
||||||
historyEntry,
|
|
||||||
nextElements,
|
|
||||||
nextAppState,
|
|
||||||
prevSnapshot,
|
|
||||||
);
|
|
||||||
|
|
||||||
const nextSnapshot = prevSnapshot.maybeClone(
|
const nextSnapshot = prevSnapshot.maybeClone(
|
||||||
action,
|
action,
|
||||||
@ -125,24 +171,31 @@ export class History {
|
|||||||
nextAppState,
|
nextAppState,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const change = StoreChange.create(prevSnapshot, nextSnapshot);
|
||||||
|
|
||||||
|
// update the history entry, so that it's the a new history entry instance
|
||||||
|
// and so that it contains the latest changes in both inserted and deleted partials
|
||||||
|
// including version and versionNonce or properties which were in the meantime updated by a remote client
|
||||||
|
historyDelta = HistoryDelta.calculate(prevSnapshot, nextSnapshot);
|
||||||
|
|
||||||
// schedule immediate capture, so that it's emitted for the sync purposes
|
// schedule immediate capture, so that it's emitted for the sync purposes
|
||||||
this.store.scheduleMicroAction({
|
this.store.scheduleMicroAction({
|
||||||
action,
|
action,
|
||||||
change: StoreChange.create(prevSnapshot, nextSnapshot),
|
change,
|
||||||
delta: historyEntry,
|
delta: historyDelta,
|
||||||
});
|
});
|
||||||
|
|
||||||
prevSnapshot = nextSnapshot;
|
prevSnapshot = nextSnapshot;
|
||||||
} finally {
|
} finally {
|
||||||
// make sure to always push, even if the delta is corrupted
|
// make sure to always push, even if the delta is corrupted
|
||||||
push(historyEntry);
|
push(historyDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containsVisibleChange) {
|
if (containsVisibleChange) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
historyEntry = pop();
|
historyDelta = pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
return [nextElements, nextAppState];
|
return [nextElements, nextAppState];
|
||||||
@ -155,7 +208,7 @@ export class History {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static pop(stack: HistoryEntry[]): HistoryEntry | null {
|
private static pop(stack: HistoryDelta[]): HistoryDelta | null {
|
||||||
if (!stack.length) {
|
if (!stack.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -169,18 +222,12 @@ export class History {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static push(
|
private static push(stack: HistoryDelta[], entry: HistoryDelta) {
|
||||||
stack: HistoryEntry[],
|
if (entry.isEmpty()) {
|
||||||
entry: HistoryEntry,
|
return;
|
||||||
prevElements: SceneElementsMap,
|
}
|
||||||
) {
|
|
||||||
const inversedEntry = HistoryEntry.inverse(entry);
|
|
||||||
const updatedEntry = HistoryEntry.applyLatestChanges(
|
|
||||||
inversedEntry,
|
|
||||||
prevElements,
|
|
||||||
"inserted",
|
|
||||||
);
|
|
||||||
|
|
||||||
return stack.push(updatedEntry);
|
const inversedEntry = HistoryDelta.inverse(entry);
|
||||||
|
return stack.push(inversedEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1277,6 +1277,7 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -1525,6 +1526,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -1579,6 +1581,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -1614,9 +1617,11 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
|
|||||||
"id0": {
|
"id0": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1858,6 +1863,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -1912,6 +1918,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -1947,9 +1954,11 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
|
|||||||
"id0": {
|
"id0": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2159,6 +2168,7 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -2371,6 +2381,7 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -2402,9 +2413,11 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
|
|||||||
"id0": {
|
"id0": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"isDeleted": true,
|
"isDeleted": true,
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2648,6 +2661,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -2702,6 +2716,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 5,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 10,
|
"y": 10,
|
||||||
@ -2959,6 +2974,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -3013,6 +3029,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -3068,9 +3085,11 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"id3": {
|
"id3": {
|
||||||
@ -3078,9 +3097,11 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3324,6 +3345,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -3378,6 +3400,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -3405,9 +3428,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"strokeColor": "#e03131",
|
"strokeColor": "#e03131",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3428,9 +3453,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"backgroundColor": "#a5d8ff",
|
"backgroundColor": "#a5d8ff",
|
||||||
|
"version": 5,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"backgroundColor": "transparent",
|
"backgroundColor": "transparent",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3451,9 +3478,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"fillStyle": "cross-hatch",
|
"fillStyle": "cross-hatch",
|
||||||
|
"version": 6,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
|
"version": 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3474,9 +3503,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"strokeStyle": "dotted",
|
"strokeStyle": "dotted",
|
||||||
|
"version": 7,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
|
"version": 6,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3497,9 +3528,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"roughness": 2,
|
"roughness": 2,
|
||||||
|
"version": 8,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"roughness": 1,
|
"roughness": 1,
|
||||||
|
"version": 7,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3520,9 +3553,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"opacity": 60,
|
"opacity": 60,
|
||||||
|
"version": 9,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
|
"version": 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3556,6 +3591,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"roughness": 2,
|
"roughness": 2,
|
||||||
"strokeColor": "#e03131",
|
"strokeColor": "#e03131",
|
||||||
"strokeStyle": "dotted",
|
"strokeStyle": "dotted",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"backgroundColor": "transparent",
|
"backgroundColor": "transparent",
|
||||||
@ -3564,6 +3600,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"roughness": 1,
|
"roughness": 1,
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3805,6 +3842,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -3859,6 +3897,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -3886,9 +3925,11 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"index": "Zz",
|
"index": "Zz",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"index": "a1",
|
"index": "a1",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -4130,6 +4171,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -4184,6 +4226,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -4211,9 +4254,11 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
|
|||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"index": "Zz",
|
"index": "Zz",
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"index": "a1",
|
"index": "a1",
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -4458,6 +4503,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -4512,6 +4558,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": 20,
|
"x": 20,
|
||||||
"y": 30,
|
"y": 30,
|
||||||
@ -4567,9 +4614,11 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"id3": {
|
"id3": {
|
||||||
@ -4577,9 +4626,11 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -4606,21 +4657,25 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"id0": {
|
"id0": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 5,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"id3": {
|
"id3": {
|
||||||
"deleted": {
|
"deleted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 5,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id9",
|
"id9",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -5739,6 +5794,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 10,
|
"width": 10,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -5793,6 +5849,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 10,
|
"width": 10,
|
||||||
"x": 12,
|
"x": 12,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -6966,6 +7023,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 10,
|
"width": 10,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -7020,6 +7078,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 10,
|
"width": 10,
|
||||||
"x": 12,
|
"x": 12,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
@ -7097,9 +7156,11 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id12",
|
"id12",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"id3": {
|
"id3": {
|
||||||
@ -7107,9 +7168,11 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
|
|||||||
"groupIds": [
|
"groupIds": [
|
||||||
"id12",
|
"id12",
|
||||||
],
|
],
|
||||||
|
"version": 4,
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
"version": 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -9926,6 +9989,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] un
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "rectangle",
|
"type": "rectangle",
|
||||||
|
"version": 3,
|
||||||
"width": 20,
|
"width": 20,
|
||||||
"x": -10,
|
"x": -10,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,7 @@ import "@excalidraw/utils/test-utils";
|
|||||||
|
|
||||||
import { ElementsDelta, AppStateDelta } from "@excalidraw/element";
|
import { ElementsDelta, AppStateDelta } from "@excalidraw/element";
|
||||||
|
|
||||||
import { CaptureUpdateAction, StoreDelta } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LocalPoint, Radians } from "@excalidraw/math";
|
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ import type {
|
|||||||
ExcalidrawFrameElement,
|
ExcalidrawFrameElement,
|
||||||
ExcalidrawGenericElement,
|
ExcalidrawGenericElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
|
ExcalidrawRectangleElement,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
FixedPointBinding,
|
FixedPointBinding,
|
||||||
FractionalIndex,
|
FractionalIndex,
|
||||||
@ -53,6 +54,8 @@ import { getDefaultAppState } from "../appState";
|
|||||||
import { Excalidraw } from "../index";
|
import { Excalidraw } from "../index";
|
||||||
import * as StaticScene from "../renderer/staticScene";
|
import * as StaticScene from "../renderer/staticScene";
|
||||||
|
|
||||||
|
import { HistoryDelta } from "../history";
|
||||||
|
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
||||||
import {
|
import {
|
||||||
@ -120,9 +123,19 @@ describe("history", () => {
|
|||||||
|
|
||||||
API.setElements([rect]);
|
API.setElements([rect]);
|
||||||
|
|
||||||
const corrupedEntry = StoreDelta.create(
|
const corrupedEntry = HistoryDelta.create(
|
||||||
ElementsDelta.empty(),
|
ElementsDelta.empty(),
|
||||||
AppStateDelta.empty(),
|
// delta can't be empty, otherwise it won't be pushed into the undo stack
|
||||||
|
AppStateDelta.restore({
|
||||||
|
delta: {
|
||||||
|
inserted: {
|
||||||
|
selectedElementIds: {},
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
selectedElementIds: { [rect.id]: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
vi.spyOn(corrupedEntry.elements, "applyTo").mockImplementation(() => {
|
vi.spyOn(corrupedEntry.elements, "applyTo").mockImplementation(() => {
|
||||||
@ -389,7 +402,7 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should iterate through the history when selection changes do not produce visible change", async () => {
|
it("should not push into redo stack when selection changes dooes not produce a visible change", async () => {
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
|
||||||
const rect = UI.createElement("rectangle", { x: 10 });
|
const rect = UI.createElement("rectangle", { x: 10 });
|
||||||
@ -420,18 +433,18 @@ describe("history", () => {
|
|||||||
expect(API.getSelectedElements().length).toBe(0);
|
expect(API.getSelectedElements().length).toBe(0);
|
||||||
|
|
||||||
Keyboard.redo(); // acceptable empty redo
|
Keyboard.redo(); // acceptable empty redo
|
||||||
expect(API.getUndoStack().length).toBe(3);
|
expect(API.getUndoStack().length).toBe(2); // empty change, nothing goes into undo stack
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(API.getSelectedElements().length).toBe(0);
|
expect(API.getSelectedElements().length).toBe(0);
|
||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
assertSelectedElements(rect);
|
assertSelectedElements(rect);
|
||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(0); // now we iterated through the same undos!
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(3);
|
expect(API.getRedoStack().length).toBe(2);
|
||||||
expect(API.getSelectedElements().length).toBe(0);
|
expect(API.getSelectedElements().length).toBe(0);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ id: rect.id, isDeleted: true }),
|
expect.objectContaining({ id: rect.id, isDeleted: true }),
|
||||||
@ -1313,6 +1326,10 @@ describe("history", () => {
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rect1 = h.elements[0] as ExcalidrawRectangleElement;
|
||||||
|
text = h.elements[1] as ExcalidrawTextElement;
|
||||||
|
rect2 = h.elements[2] as ExcalidrawRectangleElement;
|
||||||
|
|
||||||
// bind text1 to rect1
|
// bind text1 to rect1
|
||||||
mouse.select([rect1, text]);
|
mouse.select([rect1, text]);
|
||||||
fireEvent.contextMenu(GlobalTestState.interactiveCanvas);
|
fireEvent.contextMenu(GlobalTestState.interactiveCanvas);
|
||||||
@ -2362,10 +2379,10 @@ describe("history", () => {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// We reached the bottom, again we iterate through invisible changes and reach the top
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
assertSelectedElements();
|
assertSelectedElements();
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
// We reached the bottom, now there is only one non-empty history delta, which will be pushed to the undo stack
|
||||||
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@ -2430,7 +2447,31 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(5);
|
expect(API.getUndoStack().length).toBe(2);
|
||||||
|
expect(API.getRedoStack().length).toBe(3);
|
||||||
|
// visible change detected, so we don't iterate up again
|
||||||
|
expect(API.getSelectedElements()).toEqual([]);
|
||||||
|
expect(h.elements).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: rect1.id,
|
||||||
|
isDeleted: false,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: rect2.id,
|
||||||
|
isDeleted: true,
|
||||||
|
backgroundColor: transparent,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: rect3.id,
|
||||||
|
isDeleted: true,
|
||||||
|
x: 30,
|
||||||
|
y: 30,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Keyboard.redo();
|
||||||
|
// we iterate all the way up, as there are no visible changes
|
||||||
|
expect(API.getUndoStack().length).toBe(4);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(API.getSelectedElements()).toEqual([]);
|
expect(API.getSelectedElements()).toEqual([]);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
@ -2489,8 +2530,8 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(3);
|
expect(API.getUndoStack().length).toBe(2);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
// do not expect any selectedElementIds, as all relate to deleted elements
|
// do not expect any selectedElementIds, as all relate to deleted elements
|
||||||
expect(API.getSelectedElements()).toEqual([]);
|
expect(API.getSelectedElements()).toEqual([]);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
@ -2506,7 +2547,6 @@ describe("history", () => {
|
|||||||
expect.objectContaining({ id: rect1.id, isDeleted: false }),
|
expect.objectContaining({ id: rect1.id, isDeleted: false }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Simulate remote update
|
|
||||||
API.updateScene({
|
API.updateScene({
|
||||||
elements: [
|
elements: [
|
||||||
h.elements[0],
|
h.elements[0],
|
||||||
@ -2523,14 +2563,13 @@ describe("history", () => {
|
|||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
expect(API.getUndoStack().length).toBe(2);
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
expect(API.getSelectedElements()).toEqual([
|
// redo entry was calculated again with the latest undo, which goes back to nothing being selected
|
||||||
expect.objectContaining({ id: rect2.id, isDeleted: false }),
|
expect(API.getSelectedElements()).toEqual([]);
|
||||||
]);
|
|
||||||
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(3);
|
expect(API.getUndoStack().length).toBe(3);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
// now we again expect these as selected, as they got restored remotely
|
// now we again expect these as selected, as they got restored remotely and this redo entry was calculated in the beginning
|
||||||
expect(API.getSelectedElements()).toEqual([
|
expect(API.getSelectedElements()).toEqual([
|
||||||
expect.objectContaining({ id: rect2.id }),
|
expect.objectContaining({ id: rect2.id }),
|
||||||
expect.objectContaining({ id: rect3.id }),
|
expect.objectContaining({ id: rect3.id }),
|
||||||
@ -2599,16 +2638,14 @@ describe("history", () => {
|
|||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(2); // iterated two steps back!
|
expect(API.getRedoStack().length).toBe(1); // iterated two steps back and reduce two empty entries into one!
|
||||||
expect(h.state.selectedGroupIds).toEqual({});
|
expect(h.state.selectedGroupIds).toEqual({});
|
||||||
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(2); // iterated two steps forward!
|
expect(API.getUndoStack().length).toBe(0); // no changes applied, so there is no new entry
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(h.state.selectedGroupIds).toEqual({});
|
expect(h.state.selectedGroupIds).toEqual({});
|
||||||
|
|
||||||
Keyboard.undo();
|
|
||||||
|
|
||||||
// Simulate remote update
|
// Simulate remote update
|
||||||
API.updateScene({
|
API.updateScene({
|
||||||
elements: [
|
elements: [
|
||||||
@ -2621,22 +2658,6 @@ describe("history", () => {
|
|||||||
],
|
],
|
||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
captureUpdate: CaptureUpdateAction.NEVER,
|
||||||
});
|
});
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(h.state.selectedGroupIds).toEqual({ A: true });
|
|
||||||
|
|
||||||
// Simulate remote update
|
|
||||||
API.updateScene({
|
|
||||||
elements: [h.elements[0], h.elements[1], rect3, rect4],
|
|
||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
|
||||||
});
|
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.state.selectedGroupIds).toEqual({ A: true, B: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should iterate through the history when editing group contains only remotely deleted elements", async () => {
|
it("should iterate through the history when editing group contains only remotely deleted elements", async () => {
|
||||||
@ -2681,33 +2702,7 @@ describe("history", () => {
|
|||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(3);
|
expect(API.getRedoStack().length).toBe(0); // all changes relate to remotely deleted elements, there is no change and thus nothing to redo
|
||||||
expect(h.state.editingGroupId).toBeNull();
|
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(3);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.state.editingGroupId).toBeNull();
|
|
||||||
|
|
||||||
// Simulate remote update
|
|
||||||
API.updateScene({
|
|
||||||
elements: [
|
|
||||||
newElementWith(h.elements[0], {
|
|
||||||
isDeleted: false,
|
|
||||||
}),
|
|
||||||
h.elements[1],
|
|
||||||
],
|
|
||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
|
||||||
});
|
|
||||||
|
|
||||||
Keyboard.undo();
|
|
||||||
expect(API.getUndoStack().length).toBe(2);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(h.state.editingGroupId).toBe("A");
|
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(3);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.state.editingGroupId).toBeNull();
|
expect(h.state.editingGroupId).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2744,13 +2739,13 @@ describe("history", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
expect(API.getUndoStack().length).toBe(1); // iterated few entries back
|
||||||
expect(API.getRedoStack().length).toBe(3);
|
expect(API.getRedoStack().length).toBe(1); // added just one non-empty entry into redo stack
|
||||||
expect(h.state.editingLinearElement).toBeNull();
|
expect(h.state.editingLinearElement).toBeNull();
|
||||||
expect(h.state.selectedLinearElement).toBeNull();
|
expect(h.state.selectedLinearElement).toBeNull();
|
||||||
|
|
||||||
Keyboard.redo();
|
Keyboard.redo();
|
||||||
expect(API.getUndoStack().length).toBe(4);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(h.state.editingLinearElement).toBeNull();
|
expect(h.state.editingLinearElement).toBeNull();
|
||||||
expect(h.state.selectedLinearElement).toBeNull();
|
expect(h.state.selectedLinearElement).toBeNull();
|
||||||
@ -2838,7 +2833,7 @@ describe("history", () => {
|
|||||||
// We iterated two steps as there was no change in order!
|
// We iterated two steps as there was no change in order!
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(2);
|
expect(API.getRedoStack().length).toBe(2);
|
||||||
expect(API.getSelectedElements().length).toBe(0);
|
assertSelectedElements([]);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ id: rect1.id }), // a "Zx"
|
expect.objectContaining({ id: rect1.id }), // a "Zx"
|
||||||
expect.objectContaining({ id: rect3.id }), // c "Zy"
|
expect.objectContaining({ id: rect3.id }), // c "Zy"
|
||||||
@ -2846,7 +2841,7 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should iterate through the history when z-index changes do not produce visible change and we synced all indices", async () => {
|
it("should tolerate remote z-index changes with incorrect fractional indices", async () => {
|
||||||
const rect1 = API.createElement({ type: "rectangle", x: 10, y: 10 });
|
const rect1 = API.createElement({ type: "rectangle", x: 10, y: 10 });
|
||||||
const rect2 = API.createElement({ type: "rectangle", x: 20, y: 20 });
|
const rect2 = API.createElement({ type: "rectangle", x: 20, y: 20 });
|
||||||
const rect3 = API.createElement({ type: "rectangle", x: 30, y: 30 });
|
const rect3 = API.createElement({ type: "rectangle", x: 30, y: 30 });
|
||||||
@ -2899,22 +2894,32 @@ describe("history", () => {
|
|||||||
// Simulate remote update
|
// Simulate remote update
|
||||||
API.updateScene({
|
API.updateScene({
|
||||||
elements: [
|
elements: [
|
||||||
h.elements[1], // rect2
|
|
||||||
h.elements[0], // rect3
|
h.elements[0], // rect3
|
||||||
h.elements[2], // rect1
|
h.elements[2], // rect1
|
||||||
|
h.elements[1], // rect2
|
||||||
],
|
],
|
||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
captureUpdate: CaptureUpdateAction.NEVER,
|
||||||
});
|
});
|
||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getRedoStack().length).toBe(2); // now we iterated two steps back!
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
assertSelectedElements([]);
|
assertSelectedElements([rect2]);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ id: rect2.id }),
|
expect.objectContaining({ id: rect2.id }),
|
||||||
expect.objectContaining({ id: rect3.id }),
|
expect.objectContaining({ id: rect3.id }),
|
||||||
expect.objectContaining({ id: rect1.id }),
|
expect.objectContaining({ id: rect1.id }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Keyboard.redo();
|
||||||
|
expect(API.getUndoStack().length).toBe(2);
|
||||||
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
|
assertSelectedElements([rect2]);
|
||||||
|
expect(h.elements).toEqual([
|
||||||
|
expect.objectContaining({ id: rect3.id }),
|
||||||
|
expect.objectContaining({ id: rect1.id }),
|
||||||
|
expect.objectContaining({ id: rect2.id }),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not let remote changes to interfere with in progress freedraw", async () => {
|
it("should not let remote changes to interfere with in progress freedraw", async () => {
|
||||||
@ -3724,54 +3729,52 @@ describe("history", () => {
|
|||||||
captureUpdate: CaptureUpdateAction.NEVER,
|
captureUpdate: CaptureUpdateAction.NEVER,
|
||||||
});
|
});
|
||||||
|
|
||||||
runTwice(() => {
|
Keyboard.redo();
|
||||||
Keyboard.redo();
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
expect(h.elements).toEqual([
|
||||||
expect(h.elements).toEqual([
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
id: container.id,
|
||||||
id: container.id,
|
// previously bound text is preserved
|
||||||
// previously bound text is preserved
|
// text bindings are not duplicated
|
||||||
// text bindings are not duplicated
|
boundElements: [{ id: remoteText.id, type: "text" }],
|
||||||
boundElements: [{ id: remoteText.id, type: "text" }],
|
isDeleted: false,
|
||||||
isDeleted: false,
|
}),
|
||||||
}),
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
id: text.id,
|
||||||
id: text.id,
|
// unbound
|
||||||
// unbound
|
containerId: null,
|
||||||
containerId: null,
|
isDeleted: false,
|
||||||
isDeleted: false,
|
}),
|
||||||
}),
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
id: remoteText.id,
|
||||||
id: remoteText.id,
|
// preserved existing binding!
|
||||||
// preserved existing binding!
|
containerId: container.id,
|
||||||
containerId: container.id,
|
isDeleted: false,
|
||||||
isDeleted: false,
|
}),
|
||||||
}),
|
]);
|
||||||
]);
|
|
||||||
|
|
||||||
Keyboard.undo();
|
Keyboard.undo();
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: container.id,
|
id: container.id,
|
||||||
boundElements: [{ id: remoteText.id, type: "text" }],
|
boundElements: [{ id: remoteText.id, type: "text" }],
|
||||||
isDeleted: false, // isDeleted got remotely updated to false
|
isDeleted: false, // isDeleted got remotely updated to false
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: text.id,
|
id: text.id,
|
||||||
containerId: null,
|
containerId: null,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: remoteText.id,
|
id: remoteText.id,
|
||||||
// unbound
|
// unbound
|
||||||
containerId: container.id,
|
containerId: container.id,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should preserve latest remotely added binding and unbind previous one when the text is added through history", async () => {
|
it("should preserve latest remotely added binding and unbind previous one when the text is added through history", async () => {
|
||||||
|
@ -435,12 +435,17 @@ export const assertElements = <T extends AllPossibleKeys<ExcalidrawElement>>(
|
|||||||
expect(h.state.selectedElementIds).toEqual(selectedElementIds);
|
expect(h.state.selectedElementIds).toEqual(selectedElementIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
const stripSeed = (deltas: Record<string, { deleted: any; inserted: any }>) =>
|
const stripProps = (
|
||||||
|
deltas: Record<string, { deleted: any; inserted: any }>,
|
||||||
|
props: string[],
|
||||||
|
) =>
|
||||||
Object.entries(deltas).reduce((acc, curr) => {
|
Object.entries(deltas).reduce((acc, curr) => {
|
||||||
const { inserted, deleted, ...rest } = curr[1];
|
const { inserted, deleted, ...rest } = curr[1];
|
||||||
|
|
||||||
delete inserted.seed;
|
for (const prop of props) {
|
||||||
delete deleted.seed;
|
delete inserted[prop];
|
||||||
|
delete deleted[prop];
|
||||||
|
}
|
||||||
|
|
||||||
acc[curr[0]] = {
|
acc[curr[0]] = {
|
||||||
inserted,
|
inserted,
|
||||||
@ -457,9 +462,9 @@ export const checkpointHistory = (history: History, name: string) => {
|
|||||||
...x,
|
...x,
|
||||||
elements: {
|
elements: {
|
||||||
...x.elements,
|
...x.elements,
|
||||||
added: stripSeed(x.elements.added),
|
added: stripProps(x.elements.added, ["seed", "versionNonce"]),
|
||||||
removed: stripSeed(x.elements.removed),
|
removed: stripProps(x.elements.removed, ["seed", "versionNonce"]),
|
||||||
updated: stripSeed(x.elements.updated),
|
updated: stripProps(x.elements.updated, ["seed", "versionNonce"]),
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
).toMatchSnapshot(`[${name}] undo stack`);
|
).toMatchSnapshot(`[${name}] undo stack`);
|
||||||
@ -469,9 +474,9 @@ export const checkpointHistory = (history: History, name: string) => {
|
|||||||
...x,
|
...x,
|
||||||
elements: {
|
elements: {
|
||||||
...x.elements,
|
...x.elements,
|
||||||
added: stripSeed(x.elements.added),
|
added: stripProps(x.elements.added, ["seed", "versionNonce"]),
|
||||||
removed: stripSeed(x.elements.removed),
|
removed: stripProps(x.elements.removed, ["seed", "versionNonce"]),
|
||||||
updated: stripSeed(x.elements.updated),
|
updated: stripProps(x.elements.updated, ["seed", "versionNonce"]),
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
).toMatchSnapshot(`[${name}] redo stack`);
|
).toMatchSnapshot(`[${name}] redo stack`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user