@dwelle/excalidraw 0.3.61 → 0.3.64
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.
- package/CHANGELOG.md +14 -0
- package/README_NEXT.md +153 -32
- package/dist/excalidraw.development.js +43 -54
- package/dist/excalidraw.production.min.js +1 -1
- package/package.json +9 -9
- package/types/actions/actionAddToLibrary.d.ts +21 -3
- package/types/actions/actionBoundText.d.ts +7 -1
- package/types/actions/actionCanvas.d.ts +57 -9
- package/types/actions/actionClipboard.d.ts +36 -6
- package/types/actions/actionDeleteSelected.d.ts +22 -4
- package/types/actions/actionDuplicateSelection.d.ts +1 -1
- package/types/actions/actionExport.d.ts +64 -10
- package/types/actions/actionFinalize.d.ts +18 -5
- package/types/actions/actionMenu.d.ts +21 -3
- package/types/actions/actionProperties.d.ts +91 -13
- package/types/actions/actionStyles.d.ts +7 -1
- package/types/actions/actionToggleGridMode.d.ts +7 -1
- package/types/actions/actionToggleStats.d.ts +7 -1
- package/types/actions/actionToggleViewMode.d.ts +7 -1
- package/types/actions/actionToggleZenMode.d.ts +7 -1
- package/types/appState.d.ts +8 -2
- package/types/charts.d.ts +8 -0
- package/types/clipboard.d.ts +1 -1
- package/types/components/App.d.ts +3 -2
- package/types/components/Avatar.d.ts +3 -2
- package/types/components/LibraryMenuItems.d.ts +4 -3
- package/types/constants.d.ts +2 -0
- package/types/data/blob.d.ts +20 -1
- package/types/data/filesystem.d.ts +1 -1
- package/types/data/library.d.ts +37 -49
- package/types/element/Hyperlink.d.ts +7 -1
- package/types/element/linearElementEditor.d.ts +7 -1
- package/types/packages/excalidraw/dist/excalidraw.production.min.d.ts +1 -3
- package/types/packages/excalidraw/index.d.ts +2 -4
- package/types/packages/utils.d.ts +7 -3
- package/types/scene/Scene.d.ts +1 -2
- package/types/types.d.ts +18 -2
- package/types/utils.d.ts +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,11 +17,25 @@ Please add the latest change on the top under the correct section.
|
|
|
17
17
|
|
|
18
18
|
#### Features
|
|
19
19
|
|
|
20
|
+
- Add support for integrating custom elements [#5164](https://github.com/excalidraw/excalidraw/pull/5164).
|
|
21
|
+
|
|
22
|
+
- Add [`onPointerDown`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) callback which gets triggered on pointer down events.
|
|
23
|
+
- Add [`onScrollChange`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onScrollChange) callback which gets triggered when scrolling the canvas.
|
|
24
|
+
- Add API [`setActiveTool`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#setActiveTool) which host can call to set the active tool.
|
|
25
|
+
|
|
26
|
+
- Exported [`loadSceneOrLibraryFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadSceneOrLibraryFromBlob) function [#5057](https://github.com/excalidraw/excalidraw/pull/5057).
|
|
27
|
+
- Export [`MIME_TYPES`](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L92) supported by Excalidraw [#5135](https://github.com/excalidraw/excalidraw/pull/5135).
|
|
28
|
+
- Support [`src`](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L50) for collaborators. Now onwards host can pass `src` to render the customized avatar for collaborators [#5114](https://github.com/excalidraw/excalidraw/pull/5114).
|
|
29
|
+
- Support `libraryItems` argument in `initialData.libraryItems` and `updateScene({ libraryItems })` to be a Promise resolving to `LibraryItems`, and support functional update of `libraryItems` in [`updateScene({ libraryItems })`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#updateScene). [#5101](https://github.com/excalidraw/excalidraw/pull/5101).
|
|
30
|
+
- Expose util [`mergeLibraryItems`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#mergeLibraryItems) [#5101](https://github.com/excalidraw/excalidraw/pull/5101).
|
|
31
|
+
- Expose util [`exportToClipboard`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportToClipboard) which allows to copy the scene contents to clipboard as `svg`, `png` or `json` [#5103](https://github.com/excalidraw/excalidraw/pull/5103).
|
|
32
|
+
- Expose `window.EXCALIDRAW_EXPORT_SOURCE` which you can use to overwrite the `source` field in exported data [#5095](https://github.com/excalidraw/excalidraw/pull/5095).
|
|
20
33
|
- The `exportToBlob` utility now supports the `exportEmbedScene` option when generating a png image [#5047](https://github.com/excalidraw/excalidraw/pull/5047).
|
|
21
34
|
- Exported [`restoreLibraryItems`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#restoreLibraryItems) API [#4995](https://github.com/excalidraw/excalidraw/pull/4995).
|
|
22
35
|
|
|
23
36
|
#### Fixes
|
|
24
37
|
|
|
38
|
+
- Use `window.EXCALIDRAW_ASSET_PATH` for fonts when exporting to svg [#5065](https://github.com/excalidraw/excalidraw/pull/5065).
|
|
25
39
|
- Library menu now properly rerenders if open when library is updated using `updateScene({ libraryItems })` [#4995](https://github.com/excalidraw/excalidraw/pull/4995).
|
|
26
40
|
|
|
27
41
|
#### Refactor
|
package/README_NEXT.md
CHANGED
|
@@ -383,7 +383,7 @@ For a complete list of variables, check [theme.scss](https://github.com/excalidr
|
|
|
383
383
|
| Name | Type | Default | Description |
|
|
384
384
|
| --- | --- | --- | --- |
|
|
385
385
|
| [`onChange`](#onChange) | Function | | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw elements and the current app state. |
|
|
386
|
-
| [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
386
|
+
| [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState<a> } </pre> | null | The initial data with which app loads. |
|
|
387
387
|
| [`ref`](#ref) | [`createRef`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) | [`useRef`](https://reactjs.org/docs/hooks-reference.html#useref) | [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) | <pre>{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317">resolvablePromise</a> } }</pre> | | Ref to be passed to Excalidraw |
|
|
388
388
|
| [`onCollabButtonClick`](#onCollabButtonClick) | Function | | Callback to be triggered when the collab button is clicked |
|
|
389
389
|
| [`isCollaborating`](#isCollaborating) | `boolean` | | This implies if the app is in collaboration mode |
|
|
@@ -405,7 +405,9 @@ For a complete list of variables, check [theme.scss](https://github.com/excalidr
|
|
|
405
405
|
| [`onLibraryChange`](#onLibraryChange) | <pre>(items: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => void | Promise<any> </pre> | | The callback if supplied is triggered when the library is updated and receives the library items. |
|
|
406
406
|
| [`autoFocus`](#autoFocus) | boolean | false | Implies whether to focus the Excalidraw component on page load |
|
|
407
407
|
| [`generateIdForFile`](#generateIdForFile) | `(file: File) => string | Promise<string>` | Allows you to override `id` generation for files added on canvas |
|
|
408
|
-
| [`onLinkOpen`](#onLinkOpen) | <pre>(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
408
|
+
| [`onLinkOpen`](#onLinkOpen) | <pre>(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">NonDeletedExcalidrawElement</a>, event: CustomEvent) </pre> | | This prop if passed will be triggered when link of an element is clicked. |
|
|
409
|
+
| [`onPointerDown`](#onPointerDown) | <pre>(activeTool: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L93"> AppState["activeTool"]</a>, pointerDownState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L365">PointerDownState</a>) => void</pre> | | This prop if passed gets triggered on pointer down evenets |
|
|
410
|
+
| [`onScrollChange`](#onScrollChange) | (scrollX: number, scrollY: number) | | This prop if passed gets triggered when scrolling the canvas. |
|
|
409
411
|
|
|
410
412
|
### Dimensions of Excalidraw
|
|
411
413
|
|
|
@@ -419,9 +421,9 @@ Every time component updates, this callback if passed will get triggered and has
|
|
|
419
421
|
(excalidrawElements, appState, files) => void;
|
|
420
422
|
```
|
|
421
423
|
|
|
422
|
-
1.`excalidrawElements`: Array of [excalidrawElements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
424
|
+
1.`excalidrawElements`: Array of [excalidrawElements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) in the scene.
|
|
423
425
|
|
|
424
|
-
2.`appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
426
|
+
2.`appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) of the scene.
|
|
425
427
|
|
|
426
428
|
3. `files`: The [`BinaryFiles`]([BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) which are added to the scene.
|
|
427
429
|
|
|
@@ -433,10 +435,10 @@ This helps to load Excalidraw with `initialData`. It must be an object or a [pro
|
|
|
433
435
|
|
|
434
436
|
| Name | Type | Description |
|
|
435
437
|
| --- | --- | --- |
|
|
436
|
-
| `elements` | [ExcalidrawElement[]](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
437
|
-
| `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
438
|
+
| `elements` | [ExcalidrawElement[]](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) | The elements with which Excalidraw should be mounted. |
|
|
439
|
+
| `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) | The App state with which Excalidraw should be mounted. |
|
|
438
440
|
| `scrollToContent` | boolean | This attribute implies whether to scroll to the nearest element to center once Excalidraw is mounted. By default, it will not scroll the nearest element to the center. Make sure you pass `initialData.appState.scrollX` and `initialData.appState.scrollY` when `scrollToContent` is false so that scroll positions are retained |
|
|
439
|
-
| `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
441
|
+
| `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) | Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)> | This library items with which Excalidraw should be mounted. |
|
|
440
442
|
| `files` | [BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) | The files added to the scene. |
|
|
441
443
|
|
|
442
444
|
```json
|
|
@@ -481,16 +483,17 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
|
|
|
481
483
|
| [updateScene](#updateScene) | <pre>(scene: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L207">sceneData</a>) => void </pre> | updates the scene with the sceneData |
|
|
482
484
|
| [addFiles](#addFiles) | <pre>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </pre> | add files data to the appState |
|
|
483
485
|
| resetScene | `({ resetLoadingState: boolean }) => void` | Resets the scene. If `resetLoadingState` is passed as true then it will also force set the loading state to false. |
|
|
484
|
-
| getSceneElementsIncludingDeleted | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
485
|
-
| getSceneElements | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
486
|
-
| getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
486
|
+
| getSceneElementsIncludingDeleted | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></pre> | Returns all the elements including the deleted in the scene |
|
|
487
|
+
| getSceneElements | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></pre> | Returns all the elements excluding the deleted in the scene |
|
|
488
|
+
| getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a></pre> | Returns current appState |
|
|
487
489
|
| history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history |
|
|
488
|
-
| scrollToContent | <pre> (target?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
490
|
+
| scrollToContent | <pre> (target?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a> | <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a>[]) => void </pre> | Scroll the nearest element out of the elements supplied to the center. Defaults to the elements on the scene. |
|
|
489
491
|
| refresh | `() => void` | Updates the offsets for the Excalidraw component so that the coordinates are computed correctly (for example the cursor position). You don't have to call this when the position is changed on page scroll or when the excalidraw container resizes (we handle that ourselves). For any other cases if the position of excalidraw is updated (example due to scroll on parent container and not page scroll) you should call this API. |
|
|
490
492
|
| [importLibrary](#importlibrary) | `(url: string, token?: string) => void` | Imports library from given URL |
|
|
491
493
|
| setToastMessage | `(message: string) => void` | This API can be used to show the toast with custom message. |
|
|
492
494
|
| [id](#id) | string | Unique ID for the excalidraw component. |
|
|
493
495
|
| [getFiles](#getFiles) | <pre>() => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">files</a> </pre> | This API can be used to get the files present in the scene. It may contain files that aren't referenced by any element, so if you're persisting the files to a storage, you should compare them against stored elements. |
|
|
496
|
+
| [setActiveTool](#setActiveTool) | <pre>(tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a>[number]["value"] | "eraser" } | { type: "custom"; customType: string }) => void</pre> | This API can be used to set the active tool |
|
|
494
497
|
|
|
495
498
|
#### `readyPromise`
|
|
496
499
|
|
|
@@ -512,9 +515,9 @@ You can use this function to update the scene with the sceneData. It accepts the
|
|
|
512
515
|
| --- | --- | --- |
|
|
513
516
|
| `elements` | [`ImportedDataState["elements"]`](https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L17) | The `elements` to be updated in the scene |
|
|
514
517
|
| `appState` | [`ImportedDataState["appState"]`](https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L18) | The `appState` to be updated in the scene. |
|
|
515
|
-
| `collaborators` | <pre>Map<string, <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
518
|
+
| `collaborators` | <pre>Map<string, <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L35">Collaborator></a></pre> | The list of collaborators to be updated in the scene. |
|
|
516
519
|
| `commitToHistory` | `boolean` | Implies if the `history (undo/redo)` should be recorded. Defaults to `false`. |
|
|
517
|
-
| `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
520
|
+
| `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) | Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)> | ((currentItems: [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)>) => [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) | Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)>) | The `libraryItems` to be update in the scene. |
|
|
518
521
|
|
|
519
522
|
### `addFiles`
|
|
520
523
|
|
|
@@ -549,7 +552,7 @@ This callback is triggered when mouse pointer is updated.
|
|
|
549
552
|
```
|
|
550
553
|
|
|
551
554
|
1. `exportedElements`: An array of [non deleted elements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L87) which needs to be exported.
|
|
552
|
-
2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
555
|
+
2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) of the scene.
|
|
553
556
|
3. `canvas`: The `HTMLCanvasElement` of the scene.
|
|
554
557
|
|
|
555
558
|
#### `langCode`
|
|
@@ -568,7 +571,7 @@ import { defaultLang, languages } from "@excalidraw/excalidraw-next";
|
|
|
568
571
|
#### `renderTopRightUI`
|
|
569
572
|
|
|
570
573
|
<pre>
|
|
571
|
-
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
574
|
+
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>) => JSX
|
|
572
575
|
</pre>
|
|
573
576
|
|
|
574
577
|
A function returning JSX to render custom UI in the top right corner of the app.
|
|
@@ -576,7 +579,7 @@ A function returning JSX to render custom UI in the top right corner of the app.
|
|
|
576
579
|
#### `renderFooter`
|
|
577
580
|
|
|
578
581
|
<pre>
|
|
579
|
-
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
582
|
+
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>) => JSX
|
|
580
583
|
</pre>
|
|
581
584
|
|
|
582
585
|
A function returning JSX to render custom UI footer. For example, you can use this to render a language picker that was previously being rendered by Excalidraw itself (for now, you'll need to implement your own language picker).
|
|
@@ -673,6 +676,14 @@ useEffect(() => {
|
|
|
673
676
|
|
|
674
677
|
Try out the [Demo](#Demo) to see it in action.
|
|
675
678
|
|
|
679
|
+
#### `setActiveTool`
|
|
680
|
+
|
|
681
|
+
This API has the below signature. It sets the `tool` passed in param as the active tool.
|
|
682
|
+
|
|
683
|
+
<pre>
|
|
684
|
+
(tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a>[number]["value"] | "eraser" } | { type: "custom"; customType: string }) => void
|
|
685
|
+
</pre>
|
|
686
|
+
|
|
676
687
|
#### `detectScroll`
|
|
677
688
|
|
|
678
689
|
Indicates whether Excalidraw should listen for `scroll` event on the nearest scrollable container in the DOM tree and recompute the coordinates (e.g. to correctly handle the cursor) when the component's position changes. You can disable this when you either know this doesn't affect your app or you want to take care of it yourself (calling the [`refresh()`](#ref) method).
|
|
@@ -742,6 +753,22 @@ const onLinkOpen: ExcalidrawProps["onLinkOpen"] = useCallback(
|
|
|
742
753
|
);
|
|
743
754
|
```
|
|
744
755
|
|
|
756
|
+
#### `onPointerDown`
|
|
757
|
+
|
|
758
|
+
This prop if passed will be triggered on pointer down events and has the below signature.
|
|
759
|
+
|
|
760
|
+
<pre>
|
|
761
|
+
(activeTool: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L93"> AppState["activeTool"]</a>, pointerDownState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L365">PointerDownState</a>) => void
|
|
762
|
+
</pre>
|
|
763
|
+
|
|
764
|
+
#### `onScrollChange`
|
|
765
|
+
|
|
766
|
+
This prop if passed will be triggered when canvas is scrolled and has the below signature.
|
|
767
|
+
|
|
768
|
+
```ts
|
|
769
|
+
(scrollX: number, scrollY: number) => void
|
|
770
|
+
```
|
|
771
|
+
|
|
745
772
|
### Does it support collaboration ?
|
|
746
773
|
|
|
747
774
|
No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/src/excalidraw-app/index.tsx).
|
|
@@ -753,7 +780,7 @@ No, Excalidraw package doesn't come with collaboration built in, since the imple
|
|
|
753
780
|
**_Signature_**
|
|
754
781
|
|
|
755
782
|
<pre>
|
|
756
|
-
restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L17">ImportedDataState["appState"]</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
783
|
+
restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L17">ImportedDataState["appState"]</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>> | null): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>
|
|
757
784
|
</pre>
|
|
758
785
|
|
|
759
786
|
**_How to use_**
|
|
@@ -762,7 +789,7 @@ restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob
|
|
|
762
789
|
import { restoreAppState } from "@excalidraw/excalidraw-next";
|
|
763
790
|
```
|
|
764
791
|
|
|
765
|
-
This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
792
|
+
This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) and if any key is missing, it will be set to default value.
|
|
766
793
|
|
|
767
794
|
When `localAppState` is supplied, it's used in place of values that are missing (`undefined`) in `appState` instead of defaults. Use this as a way to not override user's defaults if you persist them. Required: supply `null`/`undefined` if not applicable.
|
|
768
795
|
|
|
@@ -771,7 +798,7 @@ When `localAppState` is supplied, it's used in place of values that are missing
|
|
|
771
798
|
**_Signature_**
|
|
772
799
|
|
|
773
800
|
<pre>
|
|
774
|
-
restoreElements(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ImportedDataState["elements"]</a>, localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ExcalidrawElement[]</a> | null | undefined): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
801
|
+
restoreElements(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ImportedDataState["elements"]</a>, localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ExcalidrawElement[]</a> | null | undefined): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>
|
|
775
802
|
</pre>
|
|
776
803
|
|
|
777
804
|
**_How to use_**
|
|
@@ -789,7 +816,7 @@ When `localElements` are supplied, they are used to ensure that existing restore
|
|
|
789
816
|
**_Signature_**
|
|
790
817
|
|
|
791
818
|
<pre>
|
|
792
|
-
restoreElements(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L12">ImportedDataState</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
819
|
+
restoreElements(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L12">ImportedDataState</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>> | null | undefined, localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ExcalidrawElement[]</a> | null | undefined): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L4">DataState</a>
|
|
793
820
|
</pre>
|
|
794
821
|
|
|
795
822
|
See [`restoreAppState()`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#restoreAppState) about `localAppState`, and [`restoreElements()`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#restoreElements) about `localElements`.
|
|
@@ -857,7 +884,7 @@ This function returns the canvas with the exported elements, appState and dimens
|
|
|
857
884
|
|
|
858
885
|
<pre>
|
|
859
886
|
exportToBlob(
|
|
860
|
-
opts: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/packages/utils.ts#
|
|
887
|
+
opts: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/packages/utils.ts#L14">ExportOpts</a> & {
|
|
861
888
|
mimeType?: string,
|
|
862
889
|
quality?: number;
|
|
863
890
|
})
|
|
@@ -883,8 +910,8 @@ Returns a promise which resolves with a [blob](https://developer.mozilla.org/en-
|
|
|
883
910
|
|
|
884
911
|
<pre>
|
|
885
912
|
exportToSvg({
|
|
886
|
-
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
887
|
-
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
913
|
+
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>,
|
|
914
|
+
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>,
|
|
888
915
|
exportPadding?: number,
|
|
889
916
|
metadata?: string,
|
|
890
917
|
files?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">BinaryFiles</a>
|
|
@@ -893,13 +920,41 @@ exportToSvg({
|
|
|
893
920
|
|
|
894
921
|
| Name | Type | Default | Description |
|
|
895
922
|
| --- | --- | --- | --- |
|
|
896
|
-
| elements | [Excalidraw Element []](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
897
|
-
| appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
923
|
+
| elements | [Excalidraw Element []](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) | | The elements to exported as svg |
|
|
924
|
+
| appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) | [defaultAppState](https://github.com/excalidraw/excalidraw/blob/master/src/appState.ts#L11) | The app state of the scene |
|
|
898
925
|
| exportPadding | number | 10 | The padding to be added on canvas |
|
|
899
926
|
| files | [BinaryFiles](The [`BinaryFiles`](<[BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64)>) | undefined | The files added to the scene. |
|
|
900
927
|
|
|
901
928
|
This function returns a promise which resolves to svg of the exported drawing.
|
|
902
929
|
|
|
930
|
+
#### `exportToClipboard`
|
|
931
|
+
|
|
932
|
+
**_Signature_**
|
|
933
|
+
|
|
934
|
+
<pre>
|
|
935
|
+
exportToClipboard(
|
|
936
|
+
opts: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/packages/utils.ts#L14">ExportOpts</a> & {
|
|
937
|
+
mimeType?: string,
|
|
938
|
+
quality?: number;
|
|
939
|
+
type: 'png' | 'svg' |'json'
|
|
940
|
+
})
|
|
941
|
+
</pre>
|
|
942
|
+
|
|
943
|
+
| Name | Type | Default | Description |
|
|
944
|
+
| --- | --- | --- | --- | --- | --- |
|
|
945
|
+
| opts | | | This param is same as the params passed to `exportToCanvas`. You can refer to [`exportToCanvas`](#exportToCanvas). |
|
|
946
|
+
| mimeType | string | "image/png" | Indicates the image format, this will be used when exporting as `png`. |
|
|
947
|
+
| quality | number | 0.92 | A value between 0 and 1 indicating the [image quality](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#parameters). Applies only to `image/jpeg`/`image/webp` MIME types. This will be used when exporting as `png`. |
|
|
948
|
+
| type | 'png' | 'svg' | 'json' | | This determines the format to which the scene data should be exported. |
|
|
949
|
+
|
|
950
|
+
**How to use**
|
|
951
|
+
|
|
952
|
+
```js
|
|
953
|
+
import { exportToClipboard } from "@excalidraw/excalidraw-next";
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
Copies the scene data in the specified format (determined by `type`) to clipboard.
|
|
957
|
+
|
|
903
958
|
##### Additional attributes of appState for `export\*` APIs
|
|
904
959
|
|
|
905
960
|
| Name | Type | Default | Description |
|
|
@@ -917,31 +972,35 @@ This function returns a promise which resolves to svg of the exported drawing.
|
|
|
917
972
|
|
|
918
973
|
<pre>
|
|
919
974
|
serializeAsJSON({
|
|
920
|
-
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
921
|
-
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
975
|
+
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>,
|
|
976
|
+
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>,
|
|
922
977
|
}): string
|
|
923
978
|
</pre>
|
|
924
979
|
|
|
925
980
|
Takes the scene elements and state and returns a JSON string. Deleted `elements`as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/src/data/json.ts#L16) source for details).
|
|
926
981
|
|
|
982
|
+
If you want to overwrite the source field in the JSON string, you can set `window.EXCALIDRAW_EXPORT_SOURCE` to the desired value.
|
|
983
|
+
|
|
927
984
|
#### `serializeLibraryAsJSON`
|
|
928
985
|
|
|
929
986
|
**_Signature_**
|
|
930
987
|
|
|
931
988
|
<pre>
|
|
932
989
|
serializeLibraryAsJSON({
|
|
933
|
-
libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
990
|
+
libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems[]</a>,
|
|
934
991
|
</pre>
|
|
935
992
|
|
|
936
993
|
Takes the library items and returns a JSON string.
|
|
937
994
|
|
|
995
|
+
If you want to overwrite the source field in the JSON string, you can set `window.EXCALIDRAW_EXPORT_SOURCE` to the desired value.
|
|
996
|
+
|
|
938
997
|
#### `getSceneVersion`
|
|
939
998
|
|
|
940
999
|
**How to use**
|
|
941
1000
|
|
|
942
1001
|
<pre>
|
|
943
1002
|
import { getSceneVersion } from "@excalidraw/excalidraw-next";
|
|
944
|
-
getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
1003
|
+
getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>)
|
|
945
1004
|
</pre>
|
|
946
1005
|
|
|
947
1006
|
This function returns the current scene version.
|
|
@@ -951,7 +1010,7 @@ This function returns the current scene version.
|
|
|
951
1010
|
**_Signature_**
|
|
952
1011
|
|
|
953
1012
|
<pre>
|
|
954
|
-
isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#
|
|
1013
|
+
isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a>): boolean
|
|
955
1014
|
</pre>
|
|
956
1015
|
|
|
957
1016
|
**How to use**
|
|
@@ -982,15 +1041,53 @@ This function loads the library from the blob.
|
|
|
982
1041
|
|
|
983
1042
|
```js
|
|
984
1043
|
import { loadFromBlob } from "@excalidraw/excalidraw-next";
|
|
1044
|
+
|
|
1045
|
+
const scene = await loadFromBlob(file, null, null);
|
|
1046
|
+
excalidrawAPI.updateScene(scene);
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
**Signature**
|
|
1050
|
+
|
|
1051
|
+
<pre>
|
|
1052
|
+
loadFromBlob(
|
|
1053
|
+
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,
|
|
1054
|
+
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a> | null,
|
|
1055
|
+
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
|
|
1056
|
+
fileHandle?: FileSystemHandle | null
|
|
1057
|
+
) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L53">RestoredDataState</a>>
|
|
1058
|
+
</pre>
|
|
1059
|
+
|
|
1060
|
+
This function loads the scene data from the blob (or file). If you pass `localAppState`, `localAppState` value will be preferred over the `appState` derived from `blob`. Throws if blob doesn't contain valid scene data.
|
|
1061
|
+
|
|
1062
|
+
#### `loadSceneOrLibraryFromBlob`
|
|
1063
|
+
|
|
1064
|
+
**How to use**
|
|
1065
|
+
|
|
1066
|
+
```js
|
|
1067
|
+
import { loadSceneOrLibraryFromBlob, MIME_TYPES } from "@excalidraw/excalidraw";
|
|
1068
|
+
|
|
1069
|
+
const contents = await loadSceneOrLibraryFromBlob(file, null, null);
|
|
1070
|
+
// if you need, you can check what data you're dealing with before
|
|
1071
|
+
// passing down
|
|
1072
|
+
if (contents.type === MIME_TYPES.excalidraw) {
|
|
1073
|
+
excalidrawAPI.updateScene(contents.data);
|
|
1074
|
+
} else {
|
|
1075
|
+
excalidrawAPI.updateScene(contents.data);
|
|
1076
|
+
}
|
|
985
1077
|
```
|
|
986
1078
|
|
|
987
1079
|
**Signature**
|
|
988
1080
|
|
|
989
1081
|
<pre>
|
|
990
|
-
|
|
1082
|
+
loadSceneOrLibraryFromBlob(
|
|
1083
|
+
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,
|
|
1084
|
+
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a> | null,
|
|
1085
|
+
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
|
|
1086
|
+
fileHandle?: FileSystemHandle | null
|
|
1087
|
+
) => Promise<{ type: string, data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L53">RestoredDataState</a> | <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L33">ImportedLibraryState</a>}>
|
|
991
1088
|
</pre>
|
|
992
1089
|
|
|
993
|
-
This function loads
|
|
1090
|
+
This function loads either scene or library data from the supplied blob. If the blob contains scene data, and you pass `localAppState`, `localAppState` value will be preferred over the `appState` derived from `blob`. Throws if blob doesn't contain neither valid scene data or library data.
|
|
994
1091
|
|
|
995
1092
|
#### `getFreeDrawSvgPath`
|
|
996
1093
|
|
|
@@ -1040,6 +1137,20 @@ getNonDeletedElements(elements: <a href="https://github.com/excalidraw/excalidra
|
|
|
1040
1137
|
|
|
1041
1138
|
This function returns an array of deleted elements.
|
|
1042
1139
|
|
|
1140
|
+
#### `mergeLibraryItems`
|
|
1141
|
+
|
|
1142
|
+
```js
|
|
1143
|
+
import { mergeLibraryItems } from "@excalidraw/excalidraw-next";
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
**_Signature_**
|
|
1147
|
+
|
|
1148
|
+
<pre>
|
|
1149
|
+
mergeLibraryItems(localItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>, otherItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>
|
|
1150
|
+
</pre>
|
|
1151
|
+
|
|
1152
|
+
This function merges two `LibraryItems` arrays, where unique items from `otherItems` are sorted first in the returned array.
|
|
1153
|
+
|
|
1043
1154
|
### Exported constants
|
|
1044
1155
|
|
|
1045
1156
|
#### `FONT_FAMILY`
|
|
@@ -1077,6 +1188,16 @@ import { THEME } from "@excalidraw/excalidraw-next";
|
|
|
1077
1188
|
|
|
1078
1189
|
Defaults to `THEME.LIGHT` unless passed in `initialData.appState.theme`
|
|
1079
1190
|
|
|
1191
|
+
### `MIME_TYPES`
|
|
1192
|
+
|
|
1193
|
+
**How to use **
|
|
1194
|
+
|
|
1195
|
+
```js
|
|
1196
|
+
import { MIME_TYPES } from "@excalidraw/excalidraw-next";
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
[`MIME_TYPES`](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L92) contains all the mime types supported by `Excalidraw`.
|
|
1200
|
+
|
|
1080
1201
|
## Need help?
|
|
1081
1202
|
|
|
1082
1203
|
Check out the existing [Q&A](https://github.com/excalidraw/excalidraw/discussions?discussions_q=label%3Apackage%3Aexcalidraw). If you have any queries or need help, ask us [here](https://github.com/excalidraw/excalidraw/discussions?discussions_q=label%3Apackage%3Aexcalidraw).
|