Skip to content

Commit 9db0768

Browse files
committed
Merge master
2 parents 2e95454 + 95d89a7 commit 9db0768

File tree

187 files changed

+19923
-19027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+19923
-19027
lines changed

examples/with-script-in-browser/components/ExampleApp.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
transform: none;
5353
}
5454

55-
.excalidraw .panelColumn {
55+
.excalidraw .selected-shape-actions {
5656
text-align: left;
5757
}
5858

excalidraw-app/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ import {
4747
share,
4848
youtubeIcon,
4949
} from "@excalidraw/excalidraw/components/icons";
50-
import { isElementLink } from "@excalidraw/element/elementLink";
50+
import { isElementLink } from "@excalidraw/element";
5151
import { restore, restoreAppState } from "@excalidraw/excalidraw/data/restore";
52-
import { newElementWith } from "@excalidraw/element/mutateElement";
53-
import { isInitializedImageElement } from "@excalidraw/element/typeChecks";
52+
import { newElementWith } from "@excalidraw/element";
53+
import { isInitializedImageElement } from "@excalidraw/element";
5454
import clsx from "clsx";
5555
import {
5656
parseLibraryTokensFromUrl,

excalidraw-app/collab/Collab.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ import {
1919
throttleRAF,
2020
} from "@excalidraw/common";
2121
import { decryptData } from "@excalidraw/excalidraw/data/encryption";
22-
import { getVisibleSceneBounds } from "@excalidraw/element/bounds";
23-
import { newElementWith } from "@excalidraw/element/mutateElement";
24-
import {
25-
isImageElement,
26-
isInitializedImageElement,
27-
} from "@excalidraw/element/typeChecks";
22+
import { getVisibleSceneBounds } from "@excalidraw/element";
23+
import { newElementWith } from "@excalidraw/element";
24+
import { isImageElement, isInitializedImageElement } from "@excalidraw/element";
2825
import { AbortError } from "@excalidraw/excalidraw/errors";
2926
import { t } from "@excalidraw/excalidraw/i18n";
3027
import { withBatchedUpdates } from "@excalidraw/excalidraw/reactUtils";

excalidraw-app/collab/Portal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CaptureUpdateAction } from "@excalidraw/excalidraw";
22
import { trackEvent } from "@excalidraw/excalidraw/analytics";
33
import { encryptData } from "@excalidraw/excalidraw/data/encryption";
4-
import { newElementWith } from "@excalidraw/element/mutateElement";
4+
import { newElementWith } from "@excalidraw/element";
55
import throttle from "lodash.throttle";
66

77
import type { UserIdleState } from "@excalidraw/common";

excalidraw-app/components/ExportToExcalidrawPlus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
generateEncryptionKey,
1313
} from "@excalidraw/excalidraw/data/encryption";
1414
import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
15-
import { isInitializedImageElement } from "@excalidraw/element/typeChecks";
15+
import { isInitializedImageElement } from "@excalidraw/element";
1616
import { useI18n } from "@excalidraw/excalidraw/i18n";
1717

1818
import type {

excalidraw-app/data/FileManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CaptureUpdateAction } from "@excalidraw/excalidraw";
22
import { compressData } from "@excalidraw/excalidraw/data/encode";
3-
import { newElementWith } from "@excalidraw/element/mutateElement";
4-
import { isInitializedImageElement } from "@excalidraw/element/typeChecks";
3+
import { newElementWith } from "@excalidraw/element";
4+
import { isInitializedImageElement } from "@excalidraw/element";
55
import { t } from "@excalidraw/excalidraw/i18n";
66

77
import type {

excalidraw-app/data/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
} from "@excalidraw/excalidraw/data/encryption";
1010
import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
1111
import { restore } from "@excalidraw/excalidraw/data/restore";
12-
import { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers";
13-
import { isInitializedImageElement } from "@excalidraw/element/typeChecks";
12+
import { isInvisiblySmallElement } from "@excalidraw/element";
13+
import { isInitializedImageElement } from "@excalidraw/element";
1414
import { t } from "@excalidraw/excalidraw/i18n";
1515
import { bytesToHexString } from "@excalidraw/common";
1616

1717
import type { UserIdleState } from "@excalidraw/common";
1818
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
19-
import type { SceneBounds } from "@excalidraw/element/bounds";
19+
import type { SceneBounds } from "@excalidraw/element";
2020
import type {
2121
ExcalidrawElement,
2222
FileId,

excalidraw-app/tests/collab.test.tsx

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import {
33
createRedoAction,
44
createUndoAction,
55
} from "@excalidraw/excalidraw/actions/actionHistory";
6-
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
6+
import { syncInvalidIndices } from "@excalidraw/element";
77
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
88
import { act, render, waitFor } from "@excalidraw/excalidraw/tests/test-utils";
99
import { vi } from "vitest";
1010

11+
import { StoreIncrement } from "@excalidraw/element";
12+
13+
import type { DurableIncrement, EphemeralIncrement } from "@excalidraw/element";
14+
1115
import ExcalidrawApp from "../App";
1216

1317
const { h } = window;
@@ -65,6 +69,79 @@ vi.mock("socket.io-client", () => {
6569
* i.e. multiplayer history tests could be a good first candidate, as we could test both history stacks simultaneously.
6670
*/
6771
describe("collaboration", () => {
72+
it("should emit two ephemeral increments even though updates get batched", async () => {
73+
const durableIncrements: DurableIncrement[] = [];
74+
const ephemeralIncrements: EphemeralIncrement[] = [];
75+
76+
await render(<ExcalidrawApp />);
77+
78+
h.store.onStoreIncrementEmitter.on((increment) => {
79+
if (StoreIncrement.isDurable(increment)) {
80+
durableIncrements.push(increment);
81+
} else {
82+
ephemeralIncrements.push(increment);
83+
}
84+
});
85+
86+
// eslint-disable-next-line dot-notation
87+
expect(h.store["scheduledMicroActions"].length).toBe(0);
88+
expect(durableIncrements.length).toBe(0);
89+
expect(ephemeralIncrements.length).toBe(0);
90+
91+
const rectProps = {
92+
type: "rectangle",
93+
id: "A",
94+
height: 200,
95+
width: 100,
96+
x: 0,
97+
y: 0,
98+
} as const;
99+
100+
const rect = API.createElement({ ...rectProps });
101+
102+
API.updateScene({
103+
elements: [rect],
104+
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
105+
});
106+
107+
await waitFor(() => {
108+
// expect(commitSpy).toHaveBeenCalledTimes(1);
109+
expect(durableIncrements.length).toBe(1);
110+
});
111+
112+
// simulate two batched remote updates
113+
act(() => {
114+
h.app.updateScene({
115+
elements: [newElementWith(h.elements[0], { x: 100 })],
116+
captureUpdate: CaptureUpdateAction.NEVER,
117+
});
118+
h.app.updateScene({
119+
elements: [newElementWith(h.elements[0], { x: 200 })],
120+
captureUpdate: CaptureUpdateAction.NEVER,
121+
});
122+
123+
// we scheduled two micro actions,
124+
// which confirms they are going to be executed as part of one batched component update
125+
// eslint-disable-next-line dot-notation
126+
expect(h.store["scheduledMicroActions"].length).toBe(2);
127+
});
128+
129+
await waitFor(() => {
130+
// altough the updates get batched,
131+
// we expect two ephemeral increments for each update,
132+
// and each such update should have the expected change
133+
expect(ephemeralIncrements.length).toBe(2);
134+
expect(ephemeralIncrements[0].change.elements.A).toEqual(
135+
expect.objectContaining({ x: 100 }),
136+
);
137+
expect(ephemeralIncrements[1].change.elements.A).toEqual(
138+
expect.objectContaining({ x: 200 }),
139+
);
140+
// eslint-disable-next-line dot-notation
141+
expect(h.store["scheduledMicroActions"].length).toBe(0);
142+
});
143+
});
144+
68145
it("should allow to undo / redo even on force-deleted elements", async () => {
69146
await render(<ExcalidrawApp />);
70147
const rect1Props = {
@@ -122,7 +199,7 @@ describe("collaboration", () => {
122199
expect(h.elements).toEqual([expect.objectContaining(rect1Props)]);
123200
});
124201

125-
const undoAction = createUndoAction(h.history, h.store);
202+
const undoAction = createUndoAction(h.history);
126203
act(() => h.app.actionManager.executeAction(undoAction));
127204

128205
// with explicit undo (as addition) we expect our item to be restored from the snapshot!
@@ -154,7 +231,7 @@ describe("collaboration", () => {
154231
expect(h.elements).toEqual([expect.objectContaining(rect1Props)]);
155232
});
156233

157-
const redoAction = createRedoAction(h.history, h.store);
234+
const redoAction = createRedoAction(h.history);
158235
act(() => h.app.actionManager.executeAction(redoAction));
159236

160237
// with explicit redo (as removal) we again restore the element from the snapshot!

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"pepjs": "0.5.3",
3434
"prettier": "2.6.2",
3535
"rewire": "6.0.0",
36+
"rimraf": "^5.0.0",
3637
"typescript": "4.9.4",
3738
"vite": "5.0.12",
3839
"vite-plugin-checker": "0.7.2",
@@ -78,8 +79,8 @@
7879
"autorelease": "node scripts/autorelease.js",
7980
"prerelease:excalidraw": "node scripts/prerelease.js",
8081
"release:excalidraw": "node scripts/release.js",
81-
"rm:build": "rm -rf excalidraw-app/{build,dist,dev-dist} && rm -rf packages/*/{dist,build} && rm -rf examples/*/{build,dist}",
82-
"rm:node_modules": "rm -rf node_modules && rm -rf excalidraw-app/node_modules && rm -rf packages/*/node_modules",
82+
"rm:build": "rimraf --glob excalidraw-app/build excalidraw-app/dist excalidraw-app/dev-dist packages/*/dist packages/*/build examples/*/build examples/*/dist",
83+
"rm:node_modules": "rimraf --glob node_modules excalidraw-app/node_modules packages/*/node_modules",
8384
"clean-install": "yarn rm:node_modules && yarn install"
8485
},
8586
"resolutions": {

packages/common/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"default": "./dist/prod/index.js"
1414
},
1515
"./*": {
16-
"types": "./../common/dist/types/common/src/*.d.ts"
16+
"types": "./dist/types/common/src/*.d.ts"
1717
}
1818
},
1919
"files": [
@@ -50,7 +50,7 @@
5050
"bugs": "https://github.com/excalidraw/excalidraw/issues",
5151
"repository": "https://github.com/excalidraw/excalidraw",
5252
"scripts": {
53-
"gen:types": "rm -rf types && tsc",
54-
"build:esm": "rm -rf dist && node ../../scripts/buildBase.js && yarn gen:types"
53+
"gen:types": "rimraf types && tsc",
54+
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
5555
}
5656
}

0 commit comments

Comments
 (0)