@zsviczian/excalidraw 0.12.0-obsidian-11 → 0.13.0-obsidian
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/README.md +68 -14
- package/dist/excalidraw.development.js +138 -61
- package/dist/excalidraw.production.min.js +1 -1
- package/package.json +1 -1
- package/types/actions/actionAddToLibrary.d.ts +6 -6
- package/types/actions/actionBoundText.d.ts +2 -2
- package/types/actions/actionCanvas.d.ts +18 -18
- package/types/actions/actionClipboard.d.ts +10 -10
- package/types/actions/actionDeleteSelected.d.ts +6 -6
- package/types/actions/actionExport.d.ts +18 -18
- package/types/actions/actionFinalize.d.ts +4 -4
- package/types/actions/actionLinearEditor.d.ts +2 -2
- package/types/actions/actionMenu.d.ts +6 -6
- package/types/actions/actionProperties.d.ts +26 -26
- package/types/actions/actionStyles.d.ts +2 -2
- package/types/actions/actionToggleGridMode.d.ts +2 -2
- package/types/actions/actionToggleLock.d.ts +2 -2
- package/types/actions/actionToggleStats.d.ts +2 -2
- package/types/actions/actionToggleViewMode.d.ts +2 -2
- package/types/actions/actionToggleZenMode.d.ts +2 -2
- package/types/appState.d.ts +2 -2
- package/types/components/App.d.ts +6 -1
- package/types/components/HintViewer.d.ts +3 -2
- package/types/components/LayerUI.d.ts +2 -1
- package/types/components/LibraryMenu.d.ts +14 -5
- package/types/components/LibraryMenuHeaderContent.d.ts +12 -0
- package/types/components/LibraryMenuItems.d.ts +2 -14
- package/types/components/LibraryUnit.d.ts +2 -3
- package/types/components/MobileMenu.d.ts +4 -3
- package/types/components/Sidebar/Sidebar.d.ts +73 -0
- package/types/components/Sidebar/SidebarHeader.d.ts +20 -0
- package/types/components/Sidebar/common.d.ts +15 -0
- package/types/components/hoc/withUpstreamOverride.d.ts +10 -0
- package/types/data/restore.d.ts +1 -1
- package/types/data/types.d.ts +16 -1
- package/types/element/Hyperlink.d.ts +2 -2
- package/types/element/index.d.ts +1 -1
- package/types/element/linearElementEditor.d.ts +2 -2
- package/types/element/newElement.d.ts +8 -0
- package/types/keys.d.ts +3 -3
- package/types/packages/excalidraw/example/App.d.ts +2 -1
- package/types/packages/excalidraw/example/sidebar/ExampleSidebar.d.ts +5 -0
- package/types/packages/excalidraw/index.d.ts +1 -0
- package/types/scene/scrollbars.d.ts +1 -1
- package/types/types.d.ts +8 -2
package/README.md
CHANGED
|
@@ -376,13 +376,17 @@ Most notably, you can customize the primary colors, by overriding these variable
|
|
|
376
376
|
|
|
377
377
|
For a complete list of variables, check [theme.scss](https://github.com/excalidraw/excalidraw/blob/master/src/css/theme.scss), though most of them will not make sense to override.
|
|
378
378
|
|
|
379
|
+
### Does this package support collaboration ?
|
|
380
|
+
|
|
381
|
+
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).
|
|
382
|
+
|
|
379
383
|
### Props
|
|
380
384
|
|
|
381
385
|
| Name | Type | Default | Description |
|
|
382
386
|
| --- | --- | --- | --- |
|
|
383
387
|
| [`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. |
|
|
384
|
-
| [`initialData`](#initialData) | <
|
|
385
|
-
| [`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) | <
|
|
388
|
+
| [`initialData`](#initialData) | <code>{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> } </code> | null | The initial data with which app loads. |
|
|
389
|
+
| [`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) | <code>{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317">resolvablePromise</a> } }</code> | | Ref to be passed to Excalidraw |
|
|
386
390
|
| [`onCollabButtonClick`](#onCollabButtonClick) | Function | | Callback to be triggered when the collab button is clicked |
|
|
387
391
|
| [`isCollaborating`](#isCollaborating) | `boolean` | | This implies if the app is in collaboration mode |
|
|
388
392
|
| [`onPointerUpdate`](#onPointerUpdate) | Function | | Callback triggered when mouse pointer is updated. |
|
|
@@ -390,22 +394,23 @@ For a complete list of variables, check [theme.scss](https://github.com/excalidr
|
|
|
390
394
|
| [`renderTopRightUI`](#renderTopRightUI) | Function | | Function that renders custom UI in top right corner |
|
|
391
395
|
| [`renderFooter `](#renderFooter) | Function | | Function that renders custom UI footer |
|
|
392
396
|
| [`renderCustomStats`](#renderCustomStats) | Function | | Function that can be used to render custom stats on the stats dialog. |
|
|
397
|
+
| [`renderSIdebar`](#renderSIdebar) | Function | | Render function that renders custom sidebar. |
|
|
393
398
|
| [`viewModeEnabled`](#viewModeEnabled) | boolean | | This implies if the app is in view mode. |
|
|
394
399
|
| [`zenModeEnabled`](#zenModeEnabled) | boolean | | This implies if the zen mode is enabled |
|
|
395
400
|
| [`gridModeEnabled`](#gridModeEnabled) | boolean | | This implies if the grid mode is enabled |
|
|
396
401
|
| [`libraryReturnUrl`](#libraryReturnUrl) | string | | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to |
|
|
397
402
|
| [`theme`](#theme) | [THEME.LIGHT](#THEME-1) | [THEME.DARK](#THEME-1) | [THEME.LIGHT](#THEME-1) | The theme of the Excalidraw component |
|
|
398
403
|
| [`name`](#name) | string | | Name of the drawing |
|
|
399
|
-
| [`UIOptions`](#UIOptions) | <
|
|
400
|
-
| [`onPaste`](#onPaste) | <
|
|
404
|
+
| [`UIOptions`](#UIOptions) | <code>{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }</code> | [DEFAULT UI OPTIONS](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L129) | To customise UI options. Currently we support customising [`canvas actions`](#canvasActions) |
|
|
405
|
+
| [`onPaste`](#onPaste) | <code>(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L21">ClipboardData</a>, event: ClipboardEvent | null) => boolean</code> | | Callback to be triggered if passed when the something is pasted in to the scene |
|
|
401
406
|
| [`detectScroll`](#detectScroll) | boolean | true | Indicates whether to update the offsets when nearest ancestor is scrolled. |
|
|
402
407
|
| [`handleKeyboardGlobally`](#handleKeyboardGlobally) | boolean | false | Indicates whether to bind the keyboard events to document. |
|
|
403
|
-
| [`onLibraryChange`](#onLibraryChange) | <
|
|
408
|
+
| [`onLibraryChange`](#onLibraryChange) | <code>(items: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => void | Promise<any> </code> | | The callback if supplied is triggered when the library is updated and receives the library items. |
|
|
404
409
|
| [`autoFocus`](#autoFocus) | boolean | false | Implies whether to focus the Excalidraw component on page load |
|
|
405
410
|
| [`generateIdForFile`](#generateIdForFile) | `(file: File) => string | Promise<string>` | Allows you to override `id` generation for files added on canvas |
|
|
406
|
-
| [`onLinkOpen`](#onLinkOpen) | <
|
|
407
|
-
| [`onPointerDown`](#onPointerDown) | <
|
|
408
|
-
| [`onScrollChange`](#onScrollChange) | (scrollX: number, scrollY: number) | | This prop if passed gets triggered when scrolling the canvas. |
|
|
411
|
+
| [`onLinkOpen`](#onLinkOpen) | <code>(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">NonDeletedExcalidrawElement</a>, event: CustomEvent) </code> | | This prop if passed will be triggered when link of an element is clicked. |
|
|
412
|
+
| [`onPointerDown`](#onPointerDown) | <code>(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</code> | | This prop if passed gets triggered on pointer down evenets |
|
|
413
|
+
| [`onScrollChange`](#onScrollChange) | <code>(scrollX: number, scrollY: number)</code> | | This prop if passed gets triggered when scrolling the canvas. |
|
|
409
414
|
|
|
410
415
|
### Dimensions of Excalidraw
|
|
411
416
|
|
|
@@ -504,6 +509,7 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
|
|
|
504
509
|
| [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 |
|
|
505
510
|
| [setCursor](#setCursor) | <code>(cursor: string) => void </code> | This API can be used to set customise the mouse cursor on the canvas |
|
|
506
511
|
| [resetCursor](#resetCursor) | <code>() => void </code> | This API can be used to reset to default mouse cursor on the canvas |
|
|
512
|
+
| [toggleMenu](#toggleMenu) | <code>(type: string, force?: boolean) => boolean</code> | Toggles specific menus on/off |
|
|
507
513
|
|
|
508
514
|
#### `readyPromise`
|
|
509
515
|
|
|
@@ -620,6 +626,38 @@ A function returning JSX to render custom UI footer. For example, you can use th
|
|
|
620
626
|
|
|
621
627
|
A function that can be used to render custom stats (returns JSX) in the nerd stats dialog. For example you can use this prop to render the size of the elements in the storage.
|
|
622
628
|
|
|
629
|
+
#### `renderSidebar`
|
|
630
|
+
|
|
631
|
+
<pre>
|
|
632
|
+
() => JSX | null
|
|
633
|
+
</pre>
|
|
634
|
+
|
|
635
|
+
Optional function that can render custom sidebar. This sidebar is the same that the library menu sidebar is using, and can be used for any purposes your app needs. The render function should return a `<Sidebar>` instance — a component that is exported from the Excalidraw package. It accepts `children` which can be any content you like to render inside.
|
|
636
|
+
|
|
637
|
+
The `<Sidebar>` component takes these props (all are optional except `children`):
|
|
638
|
+
|
|
639
|
+
| name | type | description |
|
|
640
|
+
| --- | --- | --- |
|
|
641
|
+
| className | string |
|
|
642
|
+
| children | <pre>React.ReactNode</pre> | Content you want to render inside the sidebar. |
|
|
643
|
+
| onClose | <pre>() => void</pre> | Invoked when the component is closed (by user, or the editor). No need to act on this event, as the editor manages the sidebar open state on its own. |
|
|
644
|
+
| onDock | <pre>(isDocked: boolean) => void</pre> | Invoked when the user toggles the dock button. |
|
|
645
|
+
| docked | boolean | Indicates whether the sidebar is docked. By default, the sidebar is undocked. If passed, the docking becomes controlled, and you are responsible for updating the `docked` state by listening on `onDock` callback. See [here](#dockedSidebarBreakpoint) for more info docking. |
|
|
646
|
+
| dockable | boolean | Indicates whether the sidebar can be docked by user (=the dock button is shown). If `false`, you can still dock programmatically by passing `docked=true` |
|
|
647
|
+
|
|
648
|
+
The sidebar will always include a header with close/dock buttons (when applicable).
|
|
649
|
+
|
|
650
|
+
You can also add custom content to the header, by rendering `<Sidebar.Header>` as a child of the `<Sidebar>` component. Note that the custom header will still include the default buttons.
|
|
651
|
+
|
|
652
|
+
The `<Sidebar.Header>` component takes these props children (all are optional):
|
|
653
|
+
|
|
654
|
+
| name | type | description |
|
|
655
|
+
| --- | --- | --- |
|
|
656
|
+
| className | string |
|
|
657
|
+
| children | <pre>React.ReactNode</pre> | Content you want to render inside the sidebar header, sibling of the header buttons. |
|
|
658
|
+
|
|
659
|
+
For example code, see the example [`App.tsx`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/example/App.tsx#L524) file.
|
|
660
|
+
|
|
623
661
|
#### `viewModeEnabled`
|
|
624
662
|
|
|
625
663
|
This prop indicates whether the app is in `view mode`. When supplied, the value takes precedence over `intialData.appState.viewModeEnabled`, the `view mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
|
@@ -754,6 +792,16 @@ This API can be used to customise the mouse cursor on the canvas and has the bel
|
|
|
754
792
|
(cursor: string) => void
|
|
755
793
|
</pre>
|
|
756
794
|
|
|
795
|
+
#### `toggleMenu`
|
|
796
|
+
|
|
797
|
+
<pre>
|
|
798
|
+
(type: "library" | "customSidebar", force?: boolean) => boolean
|
|
799
|
+
</pre>
|
|
800
|
+
|
|
801
|
+
This API can be used to toggle a specific menu (currently only the sidebars), and returns whether the menu was toggled on or off. If the `force` flag passed, it will force the menu to be toggled either on/off based on the boolean passed.
|
|
802
|
+
|
|
803
|
+
This API is especially useful when you render a custom sidebar using [`renderSidebar`](#renderSidebar) prop, and you want to toggle it from your app based on a user action.
|
|
804
|
+
|
|
757
805
|
#### `resetCursor`
|
|
758
806
|
|
|
759
807
|
This API can be used to reset to default mouse cursor.
|
|
@@ -843,10 +891,6 @@ This prop if passed will be triggered when canvas is scrolled and has the below
|
|
|
843
891
|
(scrollX: number, scrollY: number) => void
|
|
844
892
|
```
|
|
845
893
|
|
|
846
|
-
### Does it support collaboration ?
|
|
847
|
-
|
|
848
|
-
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).
|
|
849
|
-
|
|
850
894
|
### Restore utilities
|
|
851
895
|
|
|
852
896
|
#### `restoreAppState`
|
|
@@ -872,7 +916,11 @@ When `localAppState` is supplied, it's used in place of values that are missing
|
|
|
872
916
|
**_Signature_**
|
|
873
917
|
|
|
874
918
|
<pre>
|
|
875
|
-
restoreElements(
|
|
919
|
+
restoreElements(
|
|
920
|
+
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ImportedDataState["elements"]</a>,
|
|
921
|
+
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>,
|
|
922
|
+
refreshDimensions: boolean
|
|
923
|
+
)
|
|
876
924
|
</pre>
|
|
877
925
|
|
|
878
926
|
**_How to use_**
|
|
@@ -885,12 +933,18 @@ This function will make sure all properties of element is correctly set and if a
|
|
|
885
933
|
|
|
886
934
|
When `localElements` are supplied, they are used to ensure that existing restored elements reuse `version` (and increment it), and regenerate `versionNonce`. Use this when you import elements which may already be present in the scene to ensure that you do not disregard the newly imported elements if you're using element version to detect the updates.
|
|
887
935
|
|
|
936
|
+
Parameter `refreshDimensions` indicates whether we should also recalculate text element dimensions. Defaults to `true`, but since this is a potentially costly operation, you may want to disable it if you restore elements in tight loops, such as during collaboration.
|
|
937
|
+
|
|
888
938
|
#### `restore`
|
|
889
939
|
|
|
890
940
|
**_Signature_**
|
|
891
941
|
|
|
892
942
|
<pre>
|
|
893
|
-
restoreElements(
|
|
943
|
+
restoreElements(
|
|
944
|
+
data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L12">ImportedDataState</a>,
|
|
945
|
+
localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>> | null | undefined,
|
|
946
|
+
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>
|
|
947
|
+
)
|
|
894
948
|
</pre>
|
|
895
949
|
|
|
896
950
|
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`.
|