@excalidraw/excalidraw 0.17.1-a38e82f → 0.17.1-b7babe5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/browser/dev/excalidraw-assets-dev/{chunk-IM4WTX2M.js → chunk-6NMK7JTV.js} +2 -1
  3. package/dist/browser/dev/excalidraw-assets-dev/chunk-6NMK7JTV.js.map +7 -0
  4. package/dist/browser/dev/excalidraw-assets-dev/{chunk-5VWQDKDR.js → chunk-CX3RATXT.js} +50 -5
  5. package/dist/browser/dev/excalidraw-assets-dev/chunk-CX3RATXT.js.map +7 -0
  6. package/dist/browser/dev/excalidraw-assets-dev/{en-IOBA4CS2.js → en-BZY7JRTM.js} +2 -2
  7. package/dist/browser/dev/excalidraw-assets-dev/{image-VKDAL6BQ.js → image-CVN3YKRW.js} +2 -2
  8. package/dist/browser/dev/index.js +332 -76
  9. package/dist/browser/dev/index.js.map +4 -4
  10. package/dist/browser/prod/excalidraw-assets/{chunk-N2C5DK3B.js → chunk-VJAIK3AX.js} +15 -15
  11. package/dist/browser/prod/excalidraw-assets/{chunk-LIG3S5TN.js → chunk-YYO5DFUW.js} +3 -3
  12. package/dist/browser/prod/excalidraw-assets/{en-WFZVQ7I6.js → en-O2YCQM2W.js} +1 -1
  13. package/dist/browser/prod/excalidraw-assets/image-6FKY54X5.js +1 -0
  14. package/dist/browser/prod/index.js +16 -16
  15. package/dist/{prod/en-TDNWCAOT.json → dev/en-EY7E2L5O.json} +1 -0
  16. package/dist/dev/index.js +372 -77
  17. package/dist/dev/index.js.map +3 -3
  18. package/dist/excalidraw/data/library.d.ts +60 -8
  19. package/dist/excalidraw/data/library.js +302 -33
  20. package/dist/excalidraw/element/index.d.ts +8 -0
  21. package/dist/excalidraw/element/index.js +23 -0
  22. package/dist/excalidraw/element/textElement.d.ts +16 -1
  23. package/dist/excalidraw/element/textElement.js +10 -3
  24. package/dist/excalidraw/index.d.ts +2 -2
  25. package/dist/excalidraw/index.js +2 -2
  26. package/dist/excalidraw/locales/en.json +1 -0
  27. package/dist/excalidraw/queue.d.ts +9 -0
  28. package/dist/excalidraw/queue.js +27 -0
  29. package/dist/excalidraw/types.d.ts +6 -6
  30. package/dist/excalidraw/utility-types.d.ts +2 -0
  31. package/dist/excalidraw/utils.d.ts +3 -1
  32. package/dist/excalidraw/utils.js +6 -0
  33. package/dist/{dev/en-TDNWCAOT.json → prod/en-EY7E2L5O.json} +1 -0
  34. package/dist/prod/index.js +26 -26
  35. package/package.json +1 -1
  36. package/dist/browser/dev/excalidraw-assets-dev/chunk-5VWQDKDR.js.map +0 -7
  37. package/dist/browser/dev/excalidraw-assets-dev/chunk-IM4WTX2M.js.map +0 -7
  38. package/dist/browser/prod/excalidraw-assets/image-4AT7LYMR.js +0 -1
  39. /package/dist/browser/dev/excalidraw-assets-dev/{en-IOBA4CS2.js.map → en-BZY7JRTM.js.map} +0 -0
  40. /package/dist/browser/dev/excalidraw-assets-dev/{image-VKDAL6BQ.js.map → image-CVN3YKRW.js.map} +0 -0
@@ -95,14 +95,14 @@ const areEqual = (prevProps, nextProps) => {
95
95
  };
96
96
  export const Excalidraw = React.memo(ExcalidrawBase, areEqual);
97
97
  Excalidraw.displayName = "Excalidraw";
98
- export { getSceneVersion, isInvisiblySmallElement, getNonDeletedElements, } from "./element";
98
+ export { getSceneVersion, hashElementsVersion, hashString, isInvisiblySmallElement, getNonDeletedElements, } from "./element";
99
99
  export { defaultLang, useI18n, languages } from "./i18n";
100
100
  export { restore, restoreAppState, restoreElements, restoreLibraryItems, } from "./data/restore";
101
101
  export { exportToCanvas, exportToBlob, exportToSvg, exportToClipboard, } from "../utils/export";
102
102
  export { serializeAsJSON, serializeLibraryAsJSON } from "./data/json";
103
103
  export { loadFromBlob, loadSceneOrLibraryFromBlob, loadLibraryFromBlob, } from "./data/blob";
104
104
  export { getFreeDrawSvgPath } from "./renderer/renderElement";
105
- export { mergeLibraryItems } from "./data/library";
105
+ export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
106
106
  export { isLinearElement } from "./element/typeChecks";
107
107
  export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS } from "./constants";
108
108
  export { mutateElement, newElementWith, bumpVersion, } from "./element/mutateElement";
@@ -216,6 +216,7 @@
216
216
  "failedToFetchImage": "Failed to fetch image.",
217
217
  "cannotResolveCollabServer": "Couldn't connect to the collab server. Please reload the page and try again.",
218
218
  "importLibraryError": "Couldn't load library",
219
+ "saveLibraryError": "Couldn't save library to storage. Please save your library to a file locally to make sure you don't lose changes.",
219
220
  "collabSaveFailed": "Couldn't save to the backend database. If problems persist, you should save your file locally to ensure you don't lose your work.",
220
221
  "collabSaveFailed_sizeExceeded": "Couldn't save to the backend database, the canvas seems to be too big. You should save the file locally to ensure you don't lose your work.",
221
222
  "imageToolNotSupported": "Images are disabled.",
@@ -0,0 +1,9 @@
1
+ import { MaybePromise } from "./utility-types";
2
+ type Job<T, TArgs extends unknown[]> = (...args: TArgs) => MaybePromise<T>;
3
+ export declare class Queue {
4
+ private jobs;
5
+ private running;
6
+ private tick;
7
+ push<TValue, TArgs extends unknown[]>(jobFactory: Job<TValue, TArgs>, ...args: TArgs): Promise<TValue>;
8
+ }
9
+ export {};
@@ -0,0 +1,27 @@
1
+ import { promiseTry, resolvablePromise } from "./utils";
2
+ export class Queue {
3
+ jobs = [];
4
+ running = false;
5
+ tick() {
6
+ if (this.running) {
7
+ return;
8
+ }
9
+ const job = this.jobs.shift();
10
+ if (job) {
11
+ this.running = true;
12
+ job.promise.resolve(promiseTry(job.jobFactory, ...job.args).finally(() => {
13
+ this.running = false;
14
+ this.tick();
15
+ }));
16
+ }
17
+ else {
18
+ this.running = false;
19
+ }
20
+ }
21
+ push(jobFactory, ...args) {
22
+ const promise = resolvablePromise();
23
+ this.jobs.push({ jobFactory, promise, args });
24
+ this.tick();
25
+ return promise;
26
+ }
27
+ }
@@ -17,7 +17,7 @@ import type { FileSystemHandle } from "./data/filesystem";
17
17
  import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
18
18
  import { ContextMenuItems } from "./components/ContextMenu";
19
19
  import { SnapLine } from "./snapping";
20
- import { Merge, ValueOf } from "./utility-types";
20
+ import { Merge, MaybePromise, ValueOf } from "./utility-types";
21
21
  export type Point = Readonly<RoughPoint>;
22
22
  export type SocketId = string & {
23
23
  _brand: "SocketId";
@@ -304,9 +304,9 @@ export type LibraryItem = {
304
304
  };
305
305
  export type LibraryItems = readonly LibraryItem[];
306
306
  export type LibraryItems_anyVersion = LibraryItems | LibraryItems_v1;
307
- export type LibraryItemsSource = ((currentLibraryItems: LibraryItems) => Blob | LibraryItems_anyVersion | Promise<LibraryItems_anyVersion | Blob>) | Blob | LibraryItems_anyVersion | Promise<LibraryItems_anyVersion | Blob>;
307
+ export type LibraryItemsSource = ((currentLibraryItems: LibraryItems) => MaybePromise<LibraryItems_anyVersion | Blob>) | MaybePromise<LibraryItems_anyVersion | Blob>;
308
308
  export type ExcalidrawInitialDataState = Merge<ImportedDataState, {
309
- libraryItems?: Required<ImportedDataState>["libraryItems"] | Promise<Required<ImportedDataState>["libraryItems"]>;
309
+ libraryItems?: MaybePromise<Required<ImportedDataState>["libraryItems"]>;
310
310
  }>;
311
311
  export type OnUserFollowedPayload = {
312
312
  userToFollow: UserToFollow;
@@ -314,7 +314,7 @@ export type OnUserFollowedPayload = {
314
314
  };
315
315
  export interface ExcalidrawProps {
316
316
  onChange?: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
317
- initialData?: ExcalidrawInitialDataState | null | Promise<ExcalidrawInitialDataState | null>;
317
+ initialData?: MaybePromise<ExcalidrawInitialDataState | null>;
318
318
  excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
319
319
  isCollaborating?: boolean;
320
320
  onPointerUpdate?: (payload: {
@@ -486,7 +486,7 @@ export type PointerDownState = Readonly<{
486
486
  };
487
487
  }>;
488
488
  export type UnsubscribeCallback = () => void;
489
- export type ExcalidrawImperativeAPI = {
489
+ export interface ExcalidrawImperativeAPI {
490
490
  updateScene: InstanceType<typeof App>["updateScene"];
491
491
  updateLibrary: InstanceType<typeof Library>["updateLibrary"];
492
492
  resetScene: InstanceType<typeof App>["resetScene"];
@@ -519,7 +519,7 @@ export type ExcalidrawImperativeAPI = {
519
519
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
520
520
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
521
521
  onUserFollow: (callback: (payload: OnUserFollowedPayload) => void) => UnsubscribeCallback;
522
- };
522
+ }
523
523
  export type Device = Readonly<{
524
524
  viewport: {
525
525
  isMobile: boolean;
@@ -28,3 +28,5 @@ export type ReadonlySetLike<T> = ReadonlySet<T> | readonly T[];
28
28
  export type MakeBrand<T extends string> = {
29
29
  [K in `~brand~${T}`]: T;
30
30
  };
31
+ /** Maybe just promise or already fulfilled one! */
32
+ export type MaybePromise<T> = T | Promise<T>;
@@ -1,6 +1,7 @@
1
1
  import { EVENT } from "./constants";
2
2
  import { FontFamilyValues, FontString } from "./element/types";
3
3
  import { ActiveTool, AppState, ToolType, UnsubscribeCallback, Zoom } from "./types";
4
+ import { MaybePromise } from "./utility-types";
4
5
  export declare const setDateTimeForTests: (dateTime: string) => void;
5
6
  export declare const getDateTime: () => string;
6
7
  export declare const capitalizeString: (str: string) => string;
@@ -137,7 +138,7 @@ export declare const findIndex: <T>(array: readonly T[], cb: (element: T, index:
137
138
  export declare const findLastIndex: <T>(array: readonly T[], cb: (element: T, index: number, array: readonly T[]) => boolean, fromIndex?: number) => number;
138
139
  export declare const isTransparent: (color: string) => boolean;
139
140
  export type ResolvablePromise<T> = Promise<T> & {
140
- resolve: [T] extends [undefined] ? (value?: T) => void : (value: T) => void;
141
+ resolve: [T] extends [undefined] ? (value?: MaybePromise<Awaited<T>>) => void : (value: MaybePromise<Awaited<T>>) => void;
141
142
  reject: (error: Error) => void;
142
143
  };
143
144
  export declare const resolvablePromise: <T>() => ResolvablePromise<T>;
@@ -219,4 +220,5 @@ type Unbrand<T> = T extends Map<infer E, infer F> ? Map<E, F> : T extends Set<in
219
220
  * compose branded types which are not composite themselves.)
220
221
  */
221
222
  export declare const toBrandedType: <BrandedType, CurrentType = BrandedType>(value: Unbrand<BrandedType>) => CurrentType & BrandedType;
223
+ export declare const promiseTry: <TValue, TArgs extends unknown[]>(fn: (...args: TArgs) => TValue | PromiseLike<TValue>, ...args: TArgs) => Promise<TValue>;
222
224
  export {};
@@ -673,3 +673,9 @@ export const toBrandedType = (value) => {
673
673
  return value;
674
674
  };
675
675
  // -----------------------------------------------------------------------------
676
+ // Promise.try, adapted from https://github.com/sindresorhus/p-try
677
+ export const promiseTry = async (fn, ...args) => {
678
+ return new Promise((resolve) => {
679
+ resolve(fn(...args));
680
+ });
681
+ };
@@ -216,6 +216,7 @@
216
216
  "failedToFetchImage": "Failed to fetch image.",
217
217
  "cannotResolveCollabServer": "Couldn't connect to the collab server. Please reload the page and try again.",
218
218
  "importLibraryError": "Couldn't load library",
219
+ "saveLibraryError": "Couldn't save library to storage. Please save your library to a file locally to make sure you don't lose changes.",
219
220
  "collabSaveFailed": "Couldn't save to the backend database. If problems persist, you should save your file locally to ensure you don't lose your work.",
220
221
  "collabSaveFailed_sizeExceeded": "Couldn't save to the backend database, the canvas seems to be too big. You should save the file locally to ensure you don't lose your work.",
221
222
  "imageToolNotSupported": "Images are disabled.",