@excalidraw/excalidraw 0.12.0-76cf560 → 0.12.0-78e254f

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 (45) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +56 -12
  3. package/dist/excalidraw.development.js +87 -43
  4. package/dist/excalidraw.production.min.js +1 -1
  5. package/package.json +1 -1
  6. package/types/actions/actionAddToLibrary.d.ts +6 -6
  7. package/types/actions/actionBoundText.d.ts +2 -2
  8. package/types/actions/actionCanvas.d.ts +16 -16
  9. package/types/actions/actionClipboard.d.ts +10 -10
  10. package/types/actions/actionDeleteSelected.d.ts +6 -6
  11. package/types/actions/actionExport.d.ts +18 -18
  12. package/types/actions/actionFinalize.d.ts +4 -4
  13. package/types/actions/actionLinearEditor.d.ts +2 -2
  14. package/types/actions/actionMenu.d.ts +6 -6
  15. package/types/actions/actionProperties.d.ts +26 -26
  16. package/types/actions/actionStyles.d.ts +2 -2
  17. package/types/actions/actionToggleGridMode.d.ts +2 -2
  18. package/types/actions/actionToggleLock.d.ts +2 -2
  19. package/types/actions/actionToggleStats.d.ts +2 -2
  20. package/types/actions/actionToggleViewMode.d.ts +2 -2
  21. package/types/actions/actionToggleZenMode.d.ts +2 -2
  22. package/types/appState.d.ts +2 -2
  23. package/types/components/App.d.ts +6 -1
  24. package/types/components/HintViewer.d.ts +3 -2
  25. package/types/components/LayerUI.d.ts +2 -1
  26. package/types/components/LibraryMenu.d.ts +14 -5
  27. package/types/components/LibraryMenuHeaderContent.d.ts +12 -0
  28. package/types/components/LibraryMenuItems.d.ts +2 -14
  29. package/types/components/LibraryUnit.d.ts +2 -3
  30. package/types/components/MobileMenu.d.ts +4 -3
  31. package/types/components/Sidebar/Sidebar.d.ts +73 -0
  32. package/types/components/Sidebar/SidebarHeader.d.ts +20 -0
  33. package/types/components/Sidebar/common.d.ts +15 -0
  34. package/types/components/hoc/withUpstreamOverride.d.ts +10 -0
  35. package/types/constants.d.ts +7 -1
  36. package/types/data/types.d.ts +16 -1
  37. package/types/element/Hyperlink.d.ts +2 -2
  38. package/types/element/image.d.ts +1 -1
  39. package/types/element/linearElementEditor.d.ts +3 -3
  40. package/types/keys.d.ts +3 -3
  41. package/types/packages/excalidraw/example/App.d.ts +2 -1
  42. package/types/packages/excalidraw/example/sidebar/{Sidebar.d.ts → ExampleSidebar.d.ts} +1 -1
  43. package/types/packages/excalidraw/index.d.ts +1 -0
  44. package/types/types.d.ts +8 -2
  45. package/types/components/SidebarLockButton.d.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -17,6 +17,8 @@ Please add the latest change on the top under the correct section.
17
17
 
18
18
  #### Features
19
19
 
20
+ - Support rendering custom sidebar using [`renderSidebar`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#renderSidebar) prop ([#5663](https://github.com/excalidraw/excalidraw/pull/5663)).
21
+ - Add [`toggleMenu`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onMenuToggle) prop to toggle specific menu open/close state ([#5663](https://github.com/excalidraw/excalidraw/pull/5663)).
20
22
  - Support [theme](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#theme) to be semi-controlled [#5660](https://github.com/excalidraw/excalidraw/pull/5660).
21
23
  - Added support for storing [`customData`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#storing-custom-data-to-excalidraw-elements) on Excalidraw elements [#5592].
22
24
  - Added `exportPadding?: number;` to [exportToCanvas](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exporttocanvas) and [exportToBlob](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exporttoblob). The default value of the padding is 10.
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) | <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. |
385
- | [`ref`](#ref) | [`createRef`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) &#124; [`useRef`](https://reactjs.org/docs/hooks-reference.html#useref) &#124; [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) &#124; <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
+ | [`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) &#124; [`useRef`](https://reactjs.org/docs/hooks-reference.html#useref) &#124; [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) &#124; <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) &#124; [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) | <pre>{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }</pre> | [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) |
400
- | [`onPaste`](#onPaste) | <pre>(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L21">ClipboardData</a>, event: ClipboardEvent &#124; null) => boolean</pre> | | Callback to be triggered if passed when the something is pasted in to the scene |
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 &#124; 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) | <pre>(items: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => void &#124; Promise&lt;any&gt; </pre> | | The callback if supplied is triggered when the library is updated and receives the library items. |
408
+ | [`onLibraryChange`](#onLibraryChange) | <code>(items: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => void &#124; Promise&lt;any&gt; </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) | <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. |
407
- | [`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 |
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
 
@@ -503,6 +508,7 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
503
508
  | [setActiveTool](#setActiveTool) | <code>(tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a> [number]["value"]&#124; "eraser" } &#124; { type: "custom"; customType: string }) => void</code> | This API can be used to set the active tool |
504
509
  | [setCursor](#setCursor) | <code>(cursor: string) => void </code> | This API can be used to set customise the mouse cursor on the canvas |
505
510
  | [resetCursor](#resetCursor) | <code>() => void </code> | This API can be used to reset to default mouse cursor on the canvas |
511
+ | [toggleMenu](#toggleMenu) | <code>(type: string, force?: boolean) => boolean</code> | Toggles specific menus on/off |
506
512
 
507
513
  #### `readyPromise`
508
514
 
@@ -619,6 +625,38 @@ A function returning JSX to render custom UI footer. For example, you can use th
619
625
 
620
626
  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.
621
627
 
628
+ #### `renderSidebar`
629
+
630
+ <pre>
631
+ () => JSX | null
632
+ </pre>
633
+
634
+ 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.
635
+
636
+ The `<Sidebar>` component takes these props (all are optional except `children`):
637
+
638
+ | name | type | description |
639
+ | --- | --- | --- |
640
+ | className | string |
641
+ | children | <pre>React.ReactNode</pre> | Content you want to render inside the sidebar. |
642
+ | 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. |
643
+ | onDock | <pre>(isDocked: boolean) => void</pre> | Invoked when the user toggles the dock button. |
644
+ | 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. |
645
+ | 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` |
646
+
647
+ The sidebar will always include a header with close/dock buttons (when applicable).
648
+
649
+ 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.
650
+
651
+ The `<Sidebar.Header>` component takes these props children (all are optional):
652
+
653
+ | name | type | description |
654
+ | --- | --- | --- |
655
+ | className | string |
656
+ | children | <pre>React.ReactNode</pre> | Content you want to render inside the sidebar header, sibling of the header buttons. |
657
+
658
+ For example code, see the example [`App.tsx`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/example/App.tsx#L524) file.
659
+
622
660
  #### `viewModeEnabled`
623
661
 
624
662
  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.
@@ -753,6 +791,16 @@ This API can be used to customise the mouse cursor on the canvas and has the bel
753
791
  (cursor: string) => void
754
792
  </pre>
755
793
 
794
+ #### `toggleMenu`
795
+
796
+ <pre>
797
+ (type: "library" | "customSidebar", force?: boolean) => boolean
798
+ </pre>
799
+
800
+ 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.
801
+
802
+ 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.
803
+
756
804
  #### `resetCursor`
757
805
 
758
806
  This API can be used to reset to default mouse cursor.
@@ -842,10 +890,6 @@ This prop if passed will be triggered when canvas is scrolled and has the below
842
890
  (scrollX: number, scrollY: number) => void
843
891
  ```
844
892
 
845
- ### Does it support collaboration ?
846
-
847
- 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).
848
-
849
893
  ### Restore utilities
850
894
 
851
895
  #### `restoreAppState`