@dwelle/excalidraw 0.3.64 → 0.3.65
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 +17 -1
- package/README_NEXT.md +120 -26
- package/dist/excalidraw.development.js +29 -29
- package/dist/excalidraw.production.min.js +1 -1
- package/package.json +1 -1
- package/types/appState.d.ts +1 -1
- package/types/components/App.d.ts +7 -2
- package/types/components/LibraryMenu.d.ts +3 -3
- package/types/components/LibraryMenuItems.d.ts +2 -2
- package/types/components/LibraryUnit.d.ts +2 -1
- package/types/data/blob.d.ts +1 -0
- package/types/data/json.d.ts +0 -2
- package/types/data/library.d.ts +18 -7
- package/types/data/types.d.ts +2 -2
- package/types/distribute.d.ts +6 -0
- package/types/element/linearElementEditor.d.ts +4 -1
- package/types/packages/excalidraw/index.d.ts +3 -2
- package/types/types.d.ts +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,22 @@ Please add the latest change on the top under the correct section.
|
|
|
17
17
|
|
|
18
18
|
#### Features
|
|
19
19
|
|
|
20
|
+
- Export [`sceneCoordsToViewportCoords`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) and [`viewportCoordsToSceneCoords`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) utilities [#5187](https://github.com/excalidraw/excalidraw/pull/5187).
|
|
21
|
+
|
|
22
|
+
- Added [`useHandleLibrary`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#useHandleLibrary) hook to automatically handle importing of libraries when `#addLibrary` URL hash key is present, and potentially for initializing library as well [#5115](https://github.com/excalidraw/excalidraw/pull/5115).
|
|
23
|
+
|
|
24
|
+
Also added [`parseLibraryTokensFromUrl`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#parseLibraryTokensFromUrl) to help in manually importing library from URL if desired.
|
|
25
|
+
|
|
26
|
+
##### BREAKING CHANGE
|
|
27
|
+
|
|
28
|
+
- Libraries are no longer automatically initialized from URL when `#addLibrary` hash key is present. Host apps now need to handle this themselves with the help of either of the above APIs (`useHandleLibrary` is recommended).
|
|
29
|
+
|
|
30
|
+
- Added [`updateLibrary`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#updateLibrary) API to update (replace/merge) the library [#5115](https://github.com/excalidraw/excalidraw/pull/5115).
|
|
31
|
+
|
|
32
|
+
##### BREAKING CHANGE
|
|
33
|
+
|
|
34
|
+
- `updateScene` API no longer supports passing `libraryItems`. Instead, use the `updateLibrary` API.
|
|
35
|
+
|
|
20
36
|
- Add support for integrating custom elements [#5164](https://github.com/excalidraw/excalidraw/pull/5164).
|
|
21
37
|
|
|
22
38
|
- Add [`onPointerDown`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) callback which gets triggered on pointer down events.
|
|
@@ -25,7 +41,7 @@ Please add the latest change on the top under the correct section.
|
|
|
25
41
|
|
|
26
42
|
- 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
43
|
- 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 [`
|
|
44
|
+
- Support [`avatarUrl`](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L50) for collaborators. Now onwards host can pass `avatarUrl` to render the customized avatar for collaborators [#5114](https://github.com/excalidraw/excalidraw/pull/5114), renamed in [#5177](https://github.com/excalidraw/excalidraw/pull/5177).
|
|
29
45
|
- 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
46
|
- 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
47
|
- 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).
|
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#L106">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/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#L79">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 |
|
|
@@ -423,7 +423,7 @@ Every time component updates, this callback if passed will get triggered and has
|
|
|
423
423
|
|
|
424
424
|
1.`excalidrawElements`: Array of [excalidrawElements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) in the scene.
|
|
425
425
|
|
|
426
|
-
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#L79) of the scene.
|
|
427
427
|
|
|
428
428
|
3. `files`: The [`BinaryFiles`]([BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) which are added to the scene.
|
|
429
429
|
|
|
@@ -436,7 +436,7 @@ This helps to load Excalidraw with `initialData`. It must be an object or a [pro
|
|
|
436
436
|
| Name | Type | Description |
|
|
437
437
|
| --- | --- | --- |
|
|
438
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#
|
|
439
|
+
| `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) | The App state with which Excalidraw should be mounted. |
|
|
440
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 |
|
|
441
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. |
|
|
442
442
|
| `files` | [BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) | The files added to the scene. |
|
|
@@ -480,20 +480,21 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
|
|
|
480
480
|
| --- | --- | --- |
|
|
481
481
|
| ready | `boolean` | This is set to true once Excalidraw is rendered |
|
|
482
482
|
| readyPromise | [resolvablePromise](https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317) | This promise will be resolved with the api once excalidraw has rendered. This will be helpful when you want do some action on the host app once this promise resolves. For this to work you will have to pass ref as shown [here](#readyPromise) |
|
|
483
|
-
| [updateScene](#updateScene) | <
|
|
484
|
-
| [
|
|
483
|
+
| [updateScene](#updateScene) | <code>(scene: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L207">sceneData</a>) => void </code> | updates the scene with the sceneData |
|
|
484
|
+
| [updateLibrary](#updateLibrary) | <code>(<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/library.ts#L136">opts</a>) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>> </code> | updates the scene with the sceneData |
|
|
485
|
+
| [addFiles](#addFiles) | <code>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </code> | add files data to the appState |
|
|
485
486
|
| resetScene | `({ resetLoadingState: boolean }) => void` | Resets the scene. If `resetLoadingState` is passed as true then it will also force set the loading state to false. |
|
|
486
|
-
| getSceneElementsIncludingDeleted | <
|
|
487
|
-
| getSceneElements | <
|
|
488
|
-
| getAppState | <
|
|
487
|
+
| getSceneElementsIncludingDeleted | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></code> | Returns all the elements including the deleted in the scene |
|
|
488
|
+
| getSceneElements | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></code> | Returns all the elements excluding the deleted in the scene |
|
|
489
|
+
| getAppState | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a></code> | Returns current appState |
|
|
489
490
|
| history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history |
|
|
490
|
-
| scrollToContent | <
|
|
491
|
+
| scrollToContent | <code> (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 </code> | Scroll the nearest element out of the elements supplied to the center. Defaults to the elements on the scene. |
|
|
491
492
|
| 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. |
|
|
492
493
|
| [importLibrary](#importlibrary) | `(url: string, token?: string) => void` | Imports library from given URL |
|
|
493
494
|
| setToastMessage | `(message: string) => void` | This API can be used to show the toast with custom message. |
|
|
494
495
|
| [id](#id) | string | Unique ID for the excalidraw component. |
|
|
495
|
-
| [getFiles](#getFiles) | <
|
|
496
|
-
| [setActiveTool](#setActiveTool) | <
|
|
496
|
+
| [getFiles](#getFiles) | <code>() => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">files</a> </code> | 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. |
|
|
497
|
+
| [setActiveTool](#setActiveTool) | <code>(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</code> | This API can be used to set the active tool |
|
|
497
498
|
|
|
498
499
|
#### `readyPromise`
|
|
499
500
|
|
|
@@ -519,6 +520,28 @@ You can use this function to update the scene with the sceneData. It accepts the
|
|
|
519
520
|
| `commitToHistory` | `boolean` | Implies if the `history (undo/redo)` should be recorded. Defaults to `false`. |
|
|
520
521
|
| `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. |
|
|
521
522
|
|
|
523
|
+
### `updateLibrary`
|
|
524
|
+
|
|
525
|
+
<pre>
|
|
526
|
+
(opts: {
|
|
527
|
+
libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224">LibraryItemsSource</a>;
|
|
528
|
+
merge?: boolean;
|
|
529
|
+
prompt?: boolean;
|
|
530
|
+
openLibraryMenu?: boolean;
|
|
531
|
+
defaultStatus?: "unpublished" | "published";
|
|
532
|
+
}) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>>
|
|
533
|
+
</pre>
|
|
534
|
+
|
|
535
|
+
You can use this function to update the library. It accepts the below attributes.
|
|
536
|
+
|
|
537
|
+
| Name | Type | Default | Description |
|
|
538
|
+
| --- | --- | --- | --- |
|
|
539
|
+
| `libraryItems` | | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224) | The `libraryItems` to be replaced/merged with current library |
|
|
540
|
+
| `merge` | boolean | `false` | Whether to merge with existing library items. |
|
|
541
|
+
| `prompt` | boolean | `false` | Whether to prompt user for confirmation. |
|
|
542
|
+
| `openLibraryMenu` | boolean | `false` | Whether to open the library menu before importing. |
|
|
543
|
+
| `defaultStatus` | <code>"unpublished" | "published"</code> | `"unpublished"` | Default library item's `status` if not present. |
|
|
544
|
+
|
|
522
545
|
### `addFiles`
|
|
523
546
|
|
|
524
547
|
<pre>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </pre>
|
|
@@ -552,7 +575,7 @@ This callback is triggered when mouse pointer is updated.
|
|
|
552
575
|
```
|
|
553
576
|
|
|
554
577
|
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.
|
|
555
|
-
2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
578
|
+
2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) of the scene.
|
|
556
579
|
3. `canvas`: The `HTMLCanvasElement` of the scene.
|
|
557
580
|
|
|
558
581
|
#### `langCode`
|
|
@@ -571,7 +594,7 @@ import { defaultLang, languages } from "@excalidraw/excalidraw-next";
|
|
|
571
594
|
#### `renderTopRightUI`
|
|
572
595
|
|
|
573
596
|
<pre>
|
|
574
|
-
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
597
|
+
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX
|
|
575
598
|
</pre>
|
|
576
599
|
|
|
577
600
|
A function returning JSX to render custom UI in the top right corner of the app.
|
|
@@ -579,7 +602,7 @@ A function returning JSX to render custom UI in the top right corner of the app.
|
|
|
579
602
|
#### `renderFooter`
|
|
580
603
|
|
|
581
604
|
<pre>
|
|
582
|
-
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
605
|
+
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX
|
|
583
606
|
</pre>
|
|
584
607
|
|
|
585
608
|
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).
|
|
@@ -780,7 +803,7 @@ No, Excalidraw package doesn't come with collaboration built in, since the imple
|
|
|
780
803
|
**_Signature_**
|
|
781
804
|
|
|
782
805
|
<pre>
|
|
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#
|
|
806
|
+
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#L79">AppState</a>> | null): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>
|
|
784
807
|
</pre>
|
|
785
808
|
|
|
786
809
|
**_How to use_**
|
|
@@ -789,7 +812,7 @@ restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob
|
|
|
789
812
|
import { restoreAppState } from "@excalidraw/excalidraw-next";
|
|
790
813
|
```
|
|
791
814
|
|
|
792
|
-
This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#
|
|
815
|
+
This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) and if any key is missing, it will be set to default value.
|
|
793
816
|
|
|
794
817
|
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.
|
|
795
818
|
|
|
@@ -816,7 +839,7 @@ When `localElements` are supplied, they are used to ensure that existing restore
|
|
|
816
839
|
**_Signature_**
|
|
817
840
|
|
|
818
841
|
<pre>
|
|
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#
|
|
842
|
+
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#L79">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>
|
|
820
843
|
</pre>
|
|
821
844
|
|
|
822
845
|
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`.
|
|
@@ -911,7 +934,7 @@ Returns a promise which resolves with a [blob](https://developer.mozilla.org/en-
|
|
|
911
934
|
<pre>
|
|
912
935
|
exportToSvg({
|
|
913
936
|
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#
|
|
937
|
+
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>,
|
|
915
938
|
exportPadding?: number,
|
|
916
939
|
metadata?: string,
|
|
917
940
|
files?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">BinaryFiles</a>
|
|
@@ -921,7 +944,7 @@ exportToSvg({
|
|
|
921
944
|
| Name | Type | Default | Description |
|
|
922
945
|
| --- | --- | --- | --- |
|
|
923
946
|
| 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#
|
|
947
|
+
| appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) | [defaultAppState](https://github.com/excalidraw/excalidraw/blob/master/src/appState.ts#L11) | The app state of the scene |
|
|
925
948
|
| exportPadding | number | 10 | The padding to be added on canvas |
|
|
926
949
|
| files | [BinaryFiles](The [`BinaryFiles`](<[BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64)>) | undefined | The files added to the scene. |
|
|
927
950
|
|
|
@@ -973,7 +996,7 @@ Copies the scene data in the specified format (determined by `type`) to clipboar
|
|
|
973
996
|
<pre>
|
|
974
997
|
serializeAsJSON({
|
|
975
998
|
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#
|
|
999
|
+
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>,
|
|
977
1000
|
}): string
|
|
978
1001
|
</pre>
|
|
979
1002
|
|
|
@@ -1051,7 +1074,7 @@ excalidrawAPI.updateScene(scene);
|
|
|
1051
1074
|
<pre>
|
|
1052
1075
|
loadFromBlob(
|
|
1053
1076
|
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#
|
|
1077
|
+
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a> | null,
|
|
1055
1078
|
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
|
|
1056
1079
|
fileHandle?: FileSystemHandle | null
|
|
1057
1080
|
) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L53">RestoredDataState</a>>
|
|
@@ -1067,12 +1090,10 @@ This function loads the scene data from the blob (or file). If you pass `localAp
|
|
|
1067
1090
|
import { loadSceneOrLibraryFromBlob, MIME_TYPES } from "@excalidraw/excalidraw";
|
|
1068
1091
|
|
|
1069
1092
|
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
1093
|
if (contents.type === MIME_TYPES.excalidraw) {
|
|
1073
1094
|
excalidrawAPI.updateScene(contents.data);
|
|
1074
|
-
} else {
|
|
1075
|
-
excalidrawAPI.
|
|
1095
|
+
} else if (contents.type === MIME_TYPES.excalidrawlib) {
|
|
1096
|
+
excalidrawAPI.updateLibrary(contents.data);
|
|
1076
1097
|
}
|
|
1077
1098
|
```
|
|
1078
1099
|
|
|
@@ -1081,7 +1102,7 @@ if (contents.type === MIME_TYPES.excalidraw) {
|
|
|
1081
1102
|
<pre>
|
|
1082
1103
|
loadSceneOrLibraryFromBlob(
|
|
1083
1104
|
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#
|
|
1105
|
+
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a> | null,
|
|
1085
1106
|
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
|
|
1086
1107
|
fileHandle?: FileSystemHandle | null
|
|
1087
1108
|
) => 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>}>
|
|
@@ -1151,6 +1172,79 @@ mergeLibraryItems(localItems: <a href="https://github.com/excalidraw/excalidraw/
|
|
|
1151
1172
|
|
|
1152
1173
|
This function merges two `LibraryItems` arrays, where unique items from `otherItems` are sorted first in the returned array.
|
|
1153
1174
|
|
|
1175
|
+
#### `parseLibraryTokensFromUrl`
|
|
1176
|
+
|
|
1177
|
+
**How to use**
|
|
1178
|
+
|
|
1179
|
+
```js
|
|
1180
|
+
import { parseLibraryTokensFromUrl } from "@excalidraw/excalidraw-next";
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
**Signature**
|
|
1184
|
+
|
|
1185
|
+
<pre>
|
|
1186
|
+
parseLibraryTokensFromUrl(): {
|
|
1187
|
+
libraryUrl: string;
|
|
1188
|
+
idToken: string | null;
|
|
1189
|
+
} | null
|
|
1190
|
+
</pre>
|
|
1191
|
+
|
|
1192
|
+
Parses library parameters from URL if present (expects the `#addLibrary` hash key), and returns an object with the `libraryUrl` and `idToken`. Returns `null` if `#addLibrary` hash key not found.
|
|
1193
|
+
|
|
1194
|
+
#### `useHandleLibrary`
|
|
1195
|
+
|
|
1196
|
+
**How to use**
|
|
1197
|
+
|
|
1198
|
+
```js
|
|
1199
|
+
import { useHandleLibrary } from "@excalidraw/excalidraw-next";
|
|
1200
|
+
|
|
1201
|
+
export const App = () => {
|
|
1202
|
+
// ...
|
|
1203
|
+
useHandleLibrary({ excalidrawAPI });
|
|
1204
|
+
};
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1207
|
+
**Signature**
|
|
1208
|
+
|
|
1209
|
+
<pre>
|
|
1210
|
+
useHandleLibrary(opts: {
|
|
1211
|
+
excalidrawAPI: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L432">ExcalidrawAPI</a>,
|
|
1212
|
+
getInitialLibraryItems?: () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224">LibraryItemsSource</a>
|
|
1213
|
+
});
|
|
1214
|
+
</pre>
|
|
1215
|
+
|
|
1216
|
+
A hook that automatically imports library from url if `#addLibrary` hash key exists on initial load, or when it changes during the editing session (e.g. when a user installs a new library), and handles initial library load if `getInitialLibraryItems` getter is supplied.
|
|
1217
|
+
|
|
1218
|
+
In the future, we will be adding support for handling library persistence to browser storage (or elsewhere).
|
|
1219
|
+
|
|
1220
|
+
#### `sceneCoordsToViewportCoords`
|
|
1221
|
+
|
|
1222
|
+
```js
|
|
1223
|
+
import { sceneCoordsToViewportCoords } from "@excalidraw/excalidraw-next";
|
|
1224
|
+
```
|
|
1225
|
+
|
|
1226
|
+
**_Signature_**
|
|
1227
|
+
|
|
1228
|
+
<pre>
|
|
1229
|
+
sceneCoordsToViewportCoords({sceneX: number, sceneY: number}, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>): {x: number, y: number}
|
|
1230
|
+
</pre>
|
|
1231
|
+
|
|
1232
|
+
This function returns equivalent viewport coords for the provided scene coords in params.
|
|
1233
|
+
|
|
1234
|
+
#### `viewportCoordsToSceneCoords`
|
|
1235
|
+
|
|
1236
|
+
```js
|
|
1237
|
+
import { viewportCoordsToSceneCoords } from "@excalidraw/excalidraw-next";
|
|
1238
|
+
```
|
|
1239
|
+
|
|
1240
|
+
**_Signature_**
|
|
1241
|
+
|
|
1242
|
+
<pre>
|
|
1243
|
+
viewportCoordsToSceneCoords({clientX: number, clientY: number}, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>): {x: number, y: number}
|
|
1244
|
+
</pre>
|
|
1245
|
+
|
|
1246
|
+
This function returns equivalent scene coords for the provided viewport coords in params.
|
|
1247
|
+
|
|
1154
1248
|
### Exported constants
|
|
1155
1249
|
|
|
1156
1250
|
#### `FONT_FAMILY`
|