@dwelle/excalidraw 0.4.0-d8d86cf → 0.4.0-e3bee83

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 (89) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/README.md +417 -19
  3. package/dist/excalidraw.development.js +427 -229
  4. package/dist/excalidraw.production.min.js +1 -1
  5. package/package.json +1 -1
  6. package/types/actions/actionAddToLibrary.d.ts +21 -9
  7. package/types/actions/actionAlign.d.ts +6 -18
  8. package/types/actions/actionBoundText.d.ts +9 -5
  9. package/types/actions/actionCanvas.d.ts +69 -45
  10. package/types/actions/actionClipboard.d.ts +54 -16
  11. package/types/actions/actionDeleteSelected.d.ts +22 -12
  12. package/types/actions/actionDistribute.d.ts +2 -6
  13. package/types/actions/actionDuplicateSelection.d.ts +1 -3
  14. package/types/actions/actionExport.d.ts +72 -51
  15. package/types/actions/actionFinalize.d.ts +15 -9
  16. package/types/actions/actionFlip.d.ts +2 -2
  17. package/types/actions/actionGroup.d.ts +4 -8
  18. package/types/actions/actionLinearEditor.d.ts +8 -4
  19. package/types/actions/actionMenu.d.ts +24 -17
  20. package/types/actions/actionNavigate.d.ts +2 -3
  21. package/types/actions/actionProperties.d.ts +106 -80
  22. package/types/actions/actionStyles.d.ts +7 -3
  23. package/types/actions/actionToggleGridMode.d.ts +9 -3
  24. package/types/actions/actionToggleLock.d.ts +7 -3
  25. package/types/actions/actionToggleStats.d.ts +8 -3
  26. package/types/actions/actionToggleViewMode.d.ts +9 -3
  27. package/types/actions/actionToggleZenMode.d.ts +9 -3
  28. package/types/actions/actionZindex.d.ts +4 -12
  29. package/types/actions/manager.d.ts +2 -1
  30. package/types/actions/types.d.ts +6 -5
  31. package/types/appState.d.ts +3 -4
  32. package/types/components/App.d.ts +7 -50
  33. package/types/components/Button.d.ts +15 -0
  34. package/types/components/Card.d.ts +7 -0
  35. package/types/components/ContextMenu.d.ts +8 -21
  36. package/types/components/JSONExportDialog.d.ts +3 -1
  37. package/types/components/LayerUI.d.ts +3 -5
  38. package/types/components/LibraryMenuHeaderContent.d.ts +23 -0
  39. package/types/components/MobileMenu.d.ts +5 -8
  40. package/types/components/UserList.d.ts +0 -2
  41. package/types/components/dropdownMenu/DropdownMenu.d.ts +64 -0
  42. package/types/components/dropdownMenu/DropdownMenuContent.d.ts +11 -0
  43. package/types/components/dropdownMenu/DropdownMenuGroup.d.ts +11 -0
  44. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +13 -0
  45. package/types/components/dropdownMenu/DropdownMenuItemContent.d.ts +6 -0
  46. package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +6 -0
  47. package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +12 -0
  48. package/types/components/dropdownMenu/DropdownMenuSeparator.d.ts +5 -0
  49. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +9 -0
  50. package/types/components/dropdownMenu/dropdownMenuUtils.d.ts +3 -0
  51. package/types/components/footer/Footer.d.ts +13 -0
  52. package/types/components/footer/FooterCenter.d.ts +8 -0
  53. package/types/components/icons.d.ts +1 -1
  54. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +10 -0
  55. package/types/components/main-menu/DefaultItems.d.ts +47 -0
  56. package/types/components/main-menu/MainMenu.d.ts +55 -0
  57. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +58 -0
  58. package/types/components/welcome-screen/WelcomeScreen.Hints.d.ts +19 -0
  59. package/types/components/welcome-screen/WelcomeScreen.d.ts +85 -0
  60. package/types/constants.d.ts +11 -8
  61. package/types/data/index.d.ts +1 -1
  62. package/types/element/Hyperlink.d.ts +9 -7
  63. package/types/element/bounds.d.ts +1 -1
  64. package/types/element/linearElementEditor.d.ts +8 -4
  65. package/types/element/textElement.d.ts +7 -0
  66. package/types/element/textWysiwyg.d.ts +6 -1
  67. package/types/element/typeChecks.d.ts +9 -1
  68. package/types/element/types.d.ts +9 -5
  69. package/types/keys.d.ts +2 -0
  70. package/types/math.d.ts +2 -1
  71. package/types/packages/excalidraw/example/CustomFooter.d.ts +5 -0
  72. package/types/packages/excalidraw/example/MobileFooter.d.ts +5 -0
  73. package/types/packages/excalidraw/index.d.ts +12 -1
  74. package/types/packages/utils.d.ts +22 -25
  75. package/types/renderer/renderScene.d.ts +1 -3
  76. package/types/scene/comparisons.d.ts +1 -1
  77. package/types/scene/export.d.ts +143 -9
  78. package/types/scene/index.d.ts +1 -1
  79. package/types/scene/types.d.ts +9 -1
  80. package/types/types.d.ts +44 -24
  81. package/types/utils.d.ts +17 -0
  82. package/types/components/ActiveFile.d.ts +0 -7
  83. package/types/components/ClearCanvas.d.ts +0 -4
  84. package/types/components/CollabButton.d.ts +0 -6
  85. package/types/components/Footer.d.ts +0 -10
  86. package/types/components/MenuItem.d.ts +0 -11
  87. package/types/components/MenuUtils.d.ts +0 -1
  88. package/types/components/WelcomeScreen.d.ts +0 -10
  89. package/types/components/WelcomeScreenDecor.d.ts +0 -6
package/CHANGELOG.md CHANGED
@@ -11,6 +11,195 @@ The change should be grouped under one of the below section and must contain PR
11
11
  Please add the latest change on the top under the correct section.
12
12
  -->
13
13
 
14
+ ## 0.14.1 (2023-01-16)
15
+
16
+ ### Fixes
17
+
18
+ - remove overflow hidden from button [#6110](https://github.com/excalidraw/excalidraw/pull/6110). This fixes the collaborator count css in the [LiveCollaborationTrigger](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#LiveCollaborationTrigger) component.
19
+
20
+ ## 0.14.0 (2023-01-13)
21
+
22
+ ### Features
23
+
24
+ - Support customization for the editor [welcome screen](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#WelcomeScreen) [#6048](https://github.com/excalidraw/excalidraw/pull/6048).
25
+
26
+ - Expose component API for the Excalidraw main menu [#6034](https://github.com/excalidraw/excalidraw/pull/6034), You can read more about its usage [here](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#MainMenu)
27
+
28
+ - Support customization for the Excalidraw [main menu](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#MainMenu) [#6034](https://github.com/excalidraw/excalidraw/pull/6034).
29
+
30
+ - [Footer](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#Footer) is now rendered as child component instead of passed as a render prop [#5970](https://github.com/excalidraw/excalidraw/pull/5970).
31
+
32
+ - Any top-level children passed to the `<Excalidraw/>` component that do not belong to one of the officially supported Excalidraw children components are now rendered directly inside the Excalidraw container (previously, they weren't rendered at all) [#6096](https://github.com/excalidraw/excalidraw/pull/6096).
33
+
34
+ - Expose [LiveCollaborationTrigger](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#LiveCollaborationTrigger) component. Replaces `props.onCollabButtonClick` [#6104](https://github.com/excalidraw/excalidraw/pull/6104).
35
+
36
+ #### BREAKING CHANGES
37
+
38
+ - `props.onCollabButtonClick` is now removed. You need to render the main menu item yourself, and optionally also render the `<LiveCollaborationTrigger>` component using [renderTopRightUI](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#renderTopRightUI) prop if you want to retain the canvas button at top-right.
39
+ - The prop `renderFooter` is now removed in favor of rendering as a child component.
40
+
41
+ ### Excalidraw schema
42
+
43
+ - Merged `appState.currentItemStrokeSharpness` and `appState.currentItemLinearStrokeSharpness` into `appState.currentItemRoundness`. Renamed `changeSharpness` action to `changeRoundness`. Excalidraw element's `strokeSharpness` was changed to `roundness`. Check the PR for types and more details [#5553](https://github.com/excalidraw/excalidraw/pull/5553).
44
+
45
+ ## Excalidraw Library
46
+
47
+ **_This section lists the updates made to the excalidraw library and will not affect the integration._**
48
+
49
+ ### Features
50
+
51
+ - Generic button export [#6092](https://github.com/excalidraw/excalidraw/pull/6092)
52
+
53
+ - Scroll using PageUp and PageDown [#6038](https://github.com/excalidraw/excalidraw/pull/6038)
54
+
55
+ - Support shrinking text containers to original height when text removed [#6025](https://github.com/excalidraw/excalidraw/pull/6025)
56
+
57
+ - Move contextMenu into the component tree and control via appState [#6021](https://github.com/excalidraw/excalidraw/pull/6021)
58
+
59
+ - Allow readonly actions to be used in viewMode [#5982](https://github.com/excalidraw/excalidraw/pull/5982)
60
+
61
+ - Support labels for arrow 🔥 [#5723](https://github.com/excalidraw/excalidraw/pull/5723)
62
+
63
+ - Don't add midpoint until dragged beyond a threshold [#5927](https://github.com/excalidraw/excalidraw/pull/5927)
64
+
65
+ - Changed text copy/paste behaviour [#5786](https://github.com/excalidraw/excalidraw/pull/5786)
66
+
67
+ - Reintroduce `x` shortcut for `freedraw` [#5840](https://github.com/excalidraw/excalidraw/pull/5840)
68
+
69
+ - Tweak toolbar shortcuts & remove library shortcut [#5832](https://github.com/excalidraw/excalidraw/pull/5832)
70
+
71
+ - Clean unused images only after 24hrs (local-only) [#5839](https://github.com/excalidraw/excalidraw/pull/5839)
72
+
73
+ - Refetch errored/pending images on collab room init load [#5833](https://github.com/excalidraw/excalidraw/pull/5833)
74
+
75
+ - Stop deleting whole line when no point select in line editor [#5676](https://github.com/excalidraw/excalidraw/pull/5676)
76
+
77
+ - Editor redesign 🔥 [#5780](https://github.com/excalidraw/excalidraw/pull/5780)
78
+
79
+ ### Fixes
80
+
81
+ - Mobile tools positioning [#6107](https://github.com/excalidraw/excalidraw/pull/6107)
82
+
83
+ - Renamed folder MainMenu->main-menu and support rest props [#6103](https://github.com/excalidraw/excalidraw/pull/6103)
84
+
85
+ - Use position absolute for mobile misc tools [#6099](https://github.com/excalidraw/excalidraw/pull/6099)
86
+
87
+ - React.memo resolvers not accounting for all props [#6042](https://github.com/excalidraw/excalidraw/pull/6042)
88
+
89
+ - Image horizontal flip fix + improved tests [#5799](https://github.com/excalidraw/excalidraw/pull/5799)
90
+
91
+ - Png-exporting does not preserve angles correctly for flipped images [#6085](https://github.com/excalidraw/excalidraw/pull/6085)
92
+
93
+ - Stale appState of MainMenu defaultItems rendered from Actions [#6074](https://github.com/excalidraw/excalidraw/pull/6074)
94
+
95
+ - HelpDialog [#6072](https://github.com/excalidraw/excalidraw/pull/6072)
96
+
97
+ - Show error message on collab save failure [#6063](https://github.com/excalidraw/excalidraw/pull/6063)
98
+
99
+ - Remove ga from docker build [#6059](https://github.com/excalidraw/excalidraw/pull/6059)
100
+
101
+ - Use displayName since name gets stripped off when uglifying/minifiyng in production [#6036](https://github.com/excalidraw/excalidraw/pull/6036)
102
+
103
+ - Remove background from wysiwyg when editing arrow label [#6033](https://github.com/excalidraw/excalidraw/pull/6033)
104
+
105
+ - Use canvas measureText to calculate width in measureText [#6030](https://github.com/excalidraw/excalidraw/pull/6030)
106
+
107
+ - Restoring deleted bindings [#6029](https://github.com/excalidraw/excalidraw/pull/6029)
108
+
109
+ - ColorPicker getColor [#5949](https://github.com/excalidraw/excalidraw/pull/5949)
110
+
111
+ - Don't push whitespace to next line when exceeding max width during wrapping and make sure to use same width of text editor on DOM when measuring dimensions [#5996](https://github.com/excalidraw/excalidraw/pull/5996)
112
+
113
+ - Showing `grabbing` cursor when holding `spacebar` [#6015](https://github.com/excalidraw/excalidraw/pull/6015)
114
+
115
+ - Resize sometimes throwing on missing null-checks [#6013](https://github.com/excalidraw/excalidraw/pull/6013)
116
+
117
+ - PWA not working after CRA@5 update [#6012](https://github.com/excalidraw/excalidraw/pull/6012)
118
+
119
+ - Not properly restoring element stroke and bg colors [#6002](https://github.com/excalidraw/excalidraw/pull/6002)
120
+
121
+ - Avatar outline on safari & center [#5997](https://github.com/excalidraw/excalidraw/pull/5997)
122
+
123
+ - Chart pasting not working due to removing tab characters [#5987](https://github.com/excalidraw/excalidraw/pull/5987)
124
+
125
+ - Apply the right type of roundness when pasting styles [#5979](https://github.com/excalidraw/excalidraw/pull/5979)
126
+
127
+ - Remove editor onpaste handler [#5971](https://github.com/excalidraw/excalidraw/pull/5971)
128
+
129
+ - Remove blank space [#5950](https://github.com/excalidraw/excalidraw/pull/5950)
130
+
131
+ - Galego and Kurdî missing in languages plus two locale typos [#5954](https://github.com/excalidraw/excalidraw/pull/5954)
132
+
133
+ - `ExcalidrawArrowElement` rather than `ExcalidrawArrowEleement` [#5955](https://github.com/excalidraw/excalidraw/pull/5955)
134
+
135
+ - RenderFooter styling [#5962](https://github.com/excalidraw/excalidraw/pull/5962)
136
+
137
+ - Repair element bindings on restore [#5956](https://github.com/excalidraw/excalidraw/pull/5956)
138
+
139
+ - Don't allow whitespaces for bound text [#5939](https://github.com/excalidraw/excalidraw/pull/5939)
140
+
141
+ - Bindings do not survive history serialization [#5942](https://github.com/excalidraw/excalidraw/pull/5942)
142
+
143
+ - Dedupe boundElement ids when container duplicated with alt+drag [#5938](https://github.com/excalidraw/excalidraw/pull/5938)
144
+
145
+ - Scale font correctly when using shift [#5935](https://github.com/excalidraw/excalidraw/pull/5935)
146
+
147
+ - Always bind to container selected by user [#5880](https://github.com/excalidraw/excalidraw/pull/5880)
148
+
149
+ - Fonts not rendered on init if `loadingdone` not fired [#5923](https://github.com/excalidraw/excalidraw/pull/5923)
150
+
151
+ - Stop replacing `del` word with `Delete` [#5897](https://github.com/excalidraw/excalidraw/pull/5897)
152
+
153
+ - Remove legacy React.render() from the editor [#5893](https://github.com/excalidraw/excalidraw/pull/5893)
154
+
155
+ - Allow adding text via enter only for text containers [#5891](https://github.com/excalidraw/excalidraw/pull/5891)
156
+
157
+ - Stop font `loadingdone` loop when rendering element SVGs [#5883](https://github.com/excalidraw/excalidraw/pull/5883)
158
+
159
+ - Refresh text dimensions only after font load done [#5878](https://github.com/excalidraw/excalidraw/pull/5878)
160
+
161
+ - Correctly paste contents parsed by `JSON.parse()` as text. [#5868](https://github.com/excalidraw/excalidraw/pull/5868)
162
+
163
+ - SVG element attributes in icons.tsx [#5871](https://github.com/excalidraw/excalidraw/pull/5871)
164
+
165
+ - Merge existing text with new when pasted [#5856](https://github.com/excalidraw/excalidraw/pull/5856)
166
+
167
+ - Disable FAST_REFRESH to fix live reload [#5852](https://github.com/excalidraw/excalidraw/pull/5852)
168
+
169
+ - Paste clipboard contents into unbound text elements [#5849](https://github.com/excalidraw/excalidraw/pull/5849)
170
+
171
+ - Compute dimensions of container correctly when text pasted on container [#5845](https://github.com/excalidraw/excalidraw/pull/5845)
172
+
173
+ - Line editor points rendering below elements [#5781](https://github.com/excalidraw/excalidraw/pull/5781)
174
+
175
+ - Syncing 1-point lines to remote clients [#5677](https://github.com/excalidraw/excalidraw/pull/5677)
176
+
177
+ - Incorrectly selecting linear elements on creation while tool-locked [#5785](https://github.com/excalidraw/excalidraw/pull/5785)
178
+
179
+ - Corrected typo in toggle theme shortcut [#5813](https://github.com/excalidraw/excalidraw/pull/5813)
180
+
181
+ - Hide canvas-modifying UI in view mode [#5815](https://github.com/excalidraw/excalidraw/pull/5815)
182
+
183
+ - Fix vertical/horizntal centering icons [#5812](https://github.com/excalidraw/excalidraw/pull/5812)
184
+
185
+ - Consistent use of ZOOM_STEP [#5801](https://github.com/excalidraw/excalidraw/pull/5801)
186
+
187
+ - Multiple elements resizing regressions [#5586](https://github.com/excalidraw/excalidraw/pull/5586)
188
+
189
+ - Changelog typo [#5795](https://github.com/excalidraw/excalidraw/pull/5795)
190
+
191
+ ### Refactor
192
+
193
+ - Remove unnecessary code [#5933](https://github.com/excalidraw/excalidraw/pull/5933)
194
+
195
+ ### Build
196
+
197
+ - Move release scripts to use release branch [#5958](https://github.com/excalidraw/excalidraw/pull/5958)
198
+
199
+ - Stops ignoring .env files from docker context so env variables get set during react app build. [#5809](https://github.com/excalidraw/excalidraw/pull/5809)
200
+
201
+ ---
202
+
14
203
  ## 0.13.0 (2022-10-27)
15
204
 
16
205
  ### Excalidraw API
package/README.md CHANGED
@@ -138,9 +138,6 @@ export default function App() {
138
138
  console.log("Elements :", elements, "State : ", state)
139
139
  }
140
140
  onPointerUpdate={(payload) => console.log(payload)}
141
- onCollabButtonClick={() =>
142
- window.alert("You clicked on collab button")
143
- }
144
141
  viewModeEnabled={viewModeEnabled}
145
142
  zenModeEnabled={zenModeEnabled}
146
143
  gridModeEnabled={gridModeEnabled}
@@ -331,7 +328,6 @@ const App = () => {
331
328
  onChange: (elements, state) =>
332
329
  console.log("Elements :", elements, "State : ", state),
333
330
  onPointerUpdate: (payload) => console.log(payload),
334
- onCollabButtonClick: () => window.alert("You clicked on collab button"),
335
331
  viewModeEnabled: viewModeEnabled,
336
332
  zenModeEnabled: zenModeEnabled,
337
333
  gridModeEnabled: gridModeEnabled,
@@ -376,10 +372,380 @@ Most notably, you can customize the primary colors, by overriding these variable
376
372
 
377
373
  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
374
 
379
- ### Does this package support collaboration ?
375
+ ### Does this package support collaboration?
380
376
 
381
377
  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
378
 
379
+ ### Component API
380
+
381
+ #### Footer
382
+
383
+ Earlier we were using `renderFooter` prop to render custom footer which was removed in [#5970](https://github.com/excalidraw/excalidraw/pull/5970). Now you can pass a `Footer` component instead to render the custom UI for footer.
384
+
385
+ You will need to import the `Footer` component from the package and wrap your component with the Footer component. The `Footer` should a valid React Node.
386
+
387
+ **Usage**
388
+
389
+ ```js
390
+ import { Footer } from "@excalidraw/excalidraw";
391
+
392
+ const CustomFooter = () => <button> custom button</button>;
393
+ const App = () => {
394
+ return (
395
+ <Excalidraw>
396
+ <Footer>
397
+ <CustomFooter />
398
+ </Footer>
399
+ </Excalidraw>
400
+ );
401
+ };
402
+ ```
403
+
404
+ Footer is only rendered in the desktop view.
405
+
406
+ In the mobile view you can render it inside the [MainMenu](#mainmenu) (later we will expose other ways to customize the UI). You can use the [`useDevice`](#useDevice) hook to check the type of device, this will be available only inside the `children` of `Excalidraw` component.
407
+
408
+ ```js
409
+ import { useDevice, Footer } from "@excalidraw/excalidraw";
410
+
411
+ const MobileFooter = () => {
412
+ const device = useDevice();
413
+ if (device.isMobile) {
414
+ return (
415
+ <Footer>
416
+ <button
417
+ className="custom-footer"
418
+ onClick={() => alert("This is custom footer in mobile menu")}
419
+ >
420
+ {" "}
421
+ custom footer{" "}
422
+ </button>
423
+ </Footer>
424
+ );
425
+ }
426
+ return null;
427
+ };
428
+
429
+ const App = () => {
430
+ <Excalidraw>
431
+ <MainMenu>
432
+ <MainMenu.Item onSelect={() => window.alert("Item1")}>
433
+ Item1
434
+ </MainMenu.Item>
435
+ <MainMenu.Item onSelect={() => window.alert("Item2")}>
436
+ Item2
437
+ </MainMenu.Item>
438
+ <MobileFooter />
439
+ </MainMenu>
440
+ </Excalidraw>;
441
+ };
442
+ ```
443
+
444
+ You can visit the [example](https://ehlz3.csb.app/) for working demo.
445
+
446
+ #### MainMenu
447
+
448
+ By default Excalidraw will render the `MainMenu` with default options. If you want to customise the `MainMenu`, you can pass the `MainMenu` component with the list options. You can visit [codesandbox example](https://ehlz3.csb.app/) for a working demo.
449
+
450
+ **Usage**
451
+
452
+ ```js
453
+ import { MainMenu } from "@excalidraw/excalidraw";
454
+ const App = () => {
455
+ <Excalidraw>
456
+ <MainMenu>
457
+ <MainMenu.Item onSelect={() => window.alert("Item1")}>
458
+ Item1
459
+ </MainMenu.Item>
460
+ <MainMenu.Item onSelect={() => window.alert("Item2")}>
461
+ Item2
462
+ </MainMenu.Item>
463
+ </MainMenu>
464
+ </Excalidraw>;
465
+ };
466
+ ```
467
+
468
+ **MainMenu**
469
+
470
+ This is the `MainMenu` component which you need to import to render the menu with custom options.
471
+
472
+ **MainMenu.Item**
473
+
474
+ Use this component to render a menu item.
475
+
476
+ | Prop | Type | Required | Default | Description |
477
+ | --- | --- | --- | --- | --- |
478
+ | `onSelect` | `Function` | Yes | `undefined` | The handler is triggered when the item is selected. |
479
+ | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
480
+ | `icon` | `JSX.Element` | No | `undefined` | The icon used in the menu item |
481
+ | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
482
+
483
+ **MainMenu.ItemLink**
484
+
485
+ To render an external link in a menu item, you can use this component.
486
+
487
+ **Usage**
488
+
489
+ ```js
490
+ import { MainMenu } from "@excalidraw/excalidraw";
491
+ const App = () => (
492
+ <Excalidraw>
493
+ <MainMenu>
494
+ <MainMenu.ItemLink href="https://google.com">Google</MainMenu.ItemLink>
495
+ <MainMenu.ItemLink href="https://excalidraw.com">
496
+ Excalidraw
497
+ </MainMenu.ItemLink>
498
+ </MainMenu>
499
+ </Excalidraw>;
500
+ );
501
+ ```
502
+
503
+ | Prop | Type | Required | Default | Description |
504
+ | --- | --- | --- | --- | --- |
505
+ | `href` | `string` | Yes | `undefined` | The `href` attribute to be added to the `anchor` element. |
506
+ | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
507
+ | `icon` | `JSX.Element` | No | `undefined` | The icon used in the menu item |
508
+ | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
509
+
510
+ **MainMenu.ItemCustom**
511
+
512
+ To render a custom item, you can use `MainMenu.ItemCustom`.
513
+
514
+ **Usage**
515
+
516
+ ```js
517
+ import { MainMenu } from "@excalidraw/excalidraw";
518
+ const App = () => (
519
+ <Excalidraw>
520
+ <MainMenu>
521
+ <MainMenu.ItemCustom>
522
+ <button
523
+ style={{ height: "2rem" }}
524
+ onClick={() => window.alert("custom menu item")}
525
+ >
526
+ {" "}
527
+ custom item
528
+ </button>
529
+ </MainMenu.ItemCustom>
530
+ </MainMenu>
531
+ </Excalidraw>;
532
+ );
533
+ ```
534
+
535
+ | Prop | Type | Required | Default | Description |
536
+ | --- | --- | --- | --- | --- |
537
+ | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
538
+
539
+ **MainMenu.DefaultItems**
540
+
541
+ For the items which are shown in the menu in [excalidraw.com](https://excalidraw.com), you can use `MainMenu.DefaultItems`
542
+
543
+ ```js
544
+ import { MainMenu } from "@excalidraw/excalidraw";
545
+ const App = () => (
546
+ <Excalidraw>
547
+ <MainMenu>
548
+ <MainMenu.DefaultItems.Socials/>
549
+ <MainMenu.DefaultItems.Export/>
550
+ <MainMenu.Item onSelect={() => window.alert("Item1")}> Item1 </MainMenu.Item>
551
+ <MainMenu.Item onSelect={() => window.alert("Item2")}> Item 2 </>
552
+ </MainMenu>
553
+ </Excalidraw>
554
+ )
555
+ ```
556
+
557
+ Here is a [complete list](https://github.com/excalidraw/excalidraw/blob/master/src/components/mainMenu/DefaultItems.tsx) of the default items.
558
+
559
+ **MainMenu.Group**
560
+
561
+ To Group item in the main menu, you can use `MainMenu.Group`
562
+
563
+ ```js
564
+ import { MainMenu } from "@excalidraw/excalidraw";
565
+ const App = () => (
566
+ <Excalidraw>
567
+ <MainMenu>
568
+ <MainMenu.Group title="Excalidraw items">
569
+ <MainMenu.DefaultItems.Socials/>
570
+ <MainMenu.DefaultItems.Export/>
571
+ </MainMenu.Group>
572
+ <MainMenu.Group title="custom items">
573
+ <MainMenu.Item onSelect={() => window.alert("Item1")}> Item1 </MainMenu.Item>
574
+ <MainMenu.Item onSelect={() => window.alert("Item2")}> Item 2 </>
575
+ </MainMenu.Group>
576
+ </MainMenu>
577
+ </Excalidraw>
578
+ )
579
+ ```
580
+
581
+ | Prop | Type | Required | Default | Description |
582
+ | --- | --- | --- | --- | --- |
583
+ | `children ` | `React.ReactNode` | Yes | `undefined` | The content of the `MainMenu.Group` |
584
+
585
+ ### WelcomeScreen
586
+
587
+ When the canvas is empty, Excalidraw shows a welcome "splash" screen with a logo, a few quick action items, and hints explaining what some of the UI buttons do. You can customize the welcome screen by rendering the `WelcomeScreen` component inside your Excalidraw instance.
588
+
589
+ You can also disable the welcome screen altogether by setting `UIOptions.welcomeScreen` to `false`.
590
+
591
+ **Usage**
592
+
593
+ ```jsx
594
+ import { WelcomScreen } from "@excalidraw/excalidraw";
595
+ const App = () => (
596
+ <Excalidraw>
597
+ <WelcomeScreen>
598
+ <WelcomeScreen.Center>
599
+ <WelcomeScreen.Center.Heading>
600
+ Your data are autosaved to the cloud.
601
+ </WelcomeScreen.Center.Heading>
602
+ <WelcomeScreen.Center.Menu>
603
+ <WelcomeScreen.Center.MenuItem
604
+ onClick={() => console.log("clicked!")}
605
+ >
606
+ Click me!
607
+ </WelcomeScreen.Center.MenuItem>
608
+ <WelcomeScreen.Center.MenuItemLink href="https://github.com/excalidraw/excalidraw">
609
+ Excalidraw GitHub
610
+ </WelcomeScreen.Center.MenuItemLink>
611
+ <WelcomeScreen.Center.MenuItemHelp />
612
+ </WelcomeScreen.Center.Menu>
613
+ </WelcomeScreen.Center>
614
+ </WelcomeScreen>
615
+ </Excalidraw>
616
+ );
617
+ ```
618
+
619
+ To disable the WelcomeScreen:
620
+
621
+ ```jsx
622
+ import { WelcomScreen } from "@excalidraw/excalidraw";
623
+ const App = () => <Excalidraw UIOptions={{ welcomeScreen: false }} />;
624
+ ```
625
+
626
+ **WelcomeScreen**
627
+
628
+ If you render the `<WelcomeScreen>` component, you are responsible for rendering the content.
629
+
630
+ There are 2 main parts: 1) welcome screen center component, and 2) welcome screen hints.
631
+
632
+ ![WelcomeScreen overview](./welcome-screen-overview.png)
633
+
634
+ **WelcomeScreen.Center**
635
+
636
+ This is the center piece of the welcome screen, containing the logo, heading, and menu. All three sub-components are optional, and you can render whatever you wish into the center component.
637
+
638
+ **WelcomeScreen.Center.Logo**
639
+
640
+ By default renders the Excalidraw logo and name. Supply `children` to customize.
641
+
642
+ **WelcomeScreen.Center.Heading**
643
+
644
+ Supply `children` to change the default message.
645
+
646
+ **WelcomeScreen.Center.Menu**
647
+
648
+ Wrapper component for the menu items. You can build your menu using the `<WelcomeScreen.Center.MenuItem>` and `<WelcomeScreen.Center.MenuItemLink>` components, render your own, or render one of the default menu items.
649
+
650
+ The default menu items are:
651
+
652
+ - `<WelcomeScreen.Center.MenuItemHelp/>` - opens the help dialog.
653
+ - `<WelcomeScreen.Center.MenuItemLoadScene/>` - open the load file dialog.
654
+ - `<WelcomeScreen.Center.MenuItemLiveCollaborationTrigger/>` - intended to open the live collaboration dialog. Works similarly to [`<LiveCollaborationTrigger>`](#LiveCollaborationTrigger) and you must supply `onSelect()` handler to integrate with your collaboration implementation.
655
+
656
+ **Usage**
657
+
658
+ ```jsx
659
+ import { WelcomScreen } from "@excalidraw/excalidraw";
660
+ const App = () => (
661
+ <Excalidraw>
662
+ <WelcomeScreen>
663
+ <WelcomeScreen.Center>
664
+ <WelcomeScreen.Center.Menu>
665
+ <WelcomeScreen.Center.MenuItem
666
+ onClick={() => console.log("clicked!")}
667
+ >
668
+ Click me!
669
+ </WelcomeScreen.Center.MenuItem>
670
+ <WelcomeScreen.Center.MenuItemLink href="https://github.com/excalidraw/excalidraw">
671
+ Excalidraw GitHub
672
+ </WelcomeScreen.Center.MenuItemLink>
673
+ <WelcomeScreen.Center.MenuItemHelp />
674
+ </WelcomeScreen.Center.Menu>
675
+ </WelcomeScreen.Center>
676
+ </WelcomeScreen>
677
+ </Excalidraw>
678
+ );
679
+ ```
680
+
681
+ **WelcomeScreen.Center.MenuItem**
682
+
683
+ Use this component to render a menu item.
684
+
685
+ | Prop | Type | Required | Default | Description |
686
+ | --- | --- | --- | --- | --- |
687
+ | `onSelect` | `Function` | Yes | | The handler is triggered when the item is selected. |
688
+ | `children` | `React.ReactNode` | Yes | | The content of the menu item |
689
+ | `icon` | `JSX.Element` | No | | The icon used in the menu item |
690
+ | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
691
+
692
+ **WelcomeScreen.Center.MenuItemLink**
693
+
694
+ To render an external link in a menu item, you can use this component.
695
+
696
+ | Prop | Type | Required | Default | Description |
697
+ | --- | --- | --- | --- | --- |
698
+ | `href` | `string` | Yes | | The `href` attribute to be added to the `anchor` element. |
699
+ | `children` | `React.ReactNode` | Yes | | The content of the menu item |
700
+ | `icon` | `JSX.Element` | No | | The icon used in the menu item |
701
+ | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
702
+
703
+ **WelcomeScreen.Hints**
704
+
705
+ These subcomponents render the UI hints. Text of each hint can be customized by supplying `children`.
706
+
707
+ **WelcomeScreen.Hints.Menu**
708
+
709
+ Hint for the main menu. Supply `children` to customize the hint text.
710
+
711
+ **WelcomeScreen.Hints.Toolbar**
712
+
713
+ Hint for the toolbar. Supply `children` to customize the hint text.
714
+
715
+ **WelcomeScreen.Hints.Help**
716
+
717
+ Hint for the help dialog. Supply `children` to customize the hint text.
718
+
719
+ ### LiveCollaborationTrigger
720
+
721
+ If you implement live collaboration support and want to expose the same UI button as on excalidraw.com, you can render the `<LiveCollaborationTrigger>` component using the [renderTopRightUI](#rendertoprightui) prop. You'll need to supply `onSelect()` to handle opening of your collaboration dialog, but the button will display current `appState.collaborators` count for you.
722
+
723
+ | Prop | Type | Required | Default | Description |
724
+ | --- | --- | --- | --- | --- |
725
+ | `onSelect` | `() => any` | Yes | | Handler called when the user click on the button |
726
+ | `isCollaborating` | `boolean` | Yes | false | Whether live collaboration session is in effect. Modifies button style. |
727
+
728
+ **Usage**
729
+
730
+ ```jsx
731
+ import { LiveCollaborationTrigger } from "@excalidraw/excalidraw";
732
+ const App = () => (
733
+ <Excalidraw
734
+ renderTopRightUI={(isMobile) => {
735
+ if (isMobile) {
736
+ return null;
737
+ }
738
+ return (
739
+ <LiveCollaborationTrigger
740
+ isCollaborating={isCollaborating}
741
+ onSelect={() => setCollabDialogShown(true)}
742
+ />
743
+ );
744
+ }}
745
+ />
746
+ );
747
+ ```
748
+
383
749
  ### Props
384
750
 
385
751
  | Name | Type | Default | Description |
@@ -387,12 +753,10 @@ No, Excalidraw package doesn't come with collaboration built in, since the imple
387
753
  | [`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. |
388
754
  | [`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
755
  | [`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 |
390
- | [`onCollabButtonClick`](#onCollabButtonClick) | Function | | Callback to be triggered when the collab button is clicked |
391
756
  | [`isCollaborating`](#isCollaborating) | `boolean` | | This implies if the app is in collaboration mode |
392
757
  | [`onPointerUpdate`](#onPointerUpdate) | Function | | Callback triggered when mouse pointer is updated. |
393
758
  | [`langCode`](#langCode) | string | `en` | Language code string |
394
759
  | [`renderTopRightUI`](#renderTopRightUI) | Function | | Function that renders custom UI in top right corner |
395
- | [`renderFooter `](#renderFooter) | Function | | Function that renders custom UI footer |
396
760
  | [`renderCustomStats`](#renderCustomStats) | Function | | Function that can be used to render custom stats on the stats dialog. |
397
761
  | [`renderSIdebar`](#renderSIdebar) | Function | | Render function that renders custom sidebar. |
398
762
  | [`viewModeEnabled`](#viewModeEnabled) | boolean | | This implies if the app is in view mode. |
@@ -562,10 +926,6 @@ You can use this function to update the library. It accepts the below attributes
562
926
 
563
927
  Adds supplied files data to the `appState.files` cache on top of existing files present in the cache.
564
928
 
565
- #### `onCollabButtonClick`
566
-
567
- This callback is triggered when clicked on the collab button in excalidraw. If not supplied, the collab dialog button is not rendered.
568
-
569
929
  #### `isCollaborating`
570
930
 
571
931
  This prop indicates if the app is in collaboration mode.
@@ -613,14 +973,6 @@ import { defaultLang, languages } from "@excalidraw/excalidraw";
613
973
 
614
974
  A function returning JSX to render custom UI in the top right corner of the app.
615
975
 
616
- #### `renderFooter`
617
-
618
- <pre>
619
- (isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX | null
620
- </pre>
621
-
622
- 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).
623
-
624
976
  #### `renderCustomStats`
625
977
 
626
978
  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.
@@ -1353,6 +1705,52 @@ viewportCoordsToSceneCoords({clientX: number, clientY: number}, appState: <a hre
1353
1705
 
1354
1706
  This function returns equivalent scene coords for the provided viewport coords in params.
1355
1707
 
1708
+ #### useDevice
1709
+
1710
+ This hook can be used to check the type of device which is being used. It can only be used inside the `children` of `Excalidraw` component
1711
+
1712
+ ```js
1713
+ import { useDevice, Footer } from "@excalidraw/excalidraw";
1714
+
1715
+ const MobileFooter = () => {
1716
+ const device = useDevice();
1717
+ if (device.isMobile) {
1718
+ return (
1719
+ <Footer>
1720
+ <button
1721
+ className="custom-footer"
1722
+ onClick={() => alert("This is custom footer in mobile menu")}
1723
+ >
1724
+ {" "}
1725
+ custom footer{" "}
1726
+ </button>
1727
+ </Footer>
1728
+ );
1729
+ }
1730
+ return null;
1731
+
1732
+ };
1733
+ const App = () => {
1734
+ <Excalidraw>
1735
+ <MainMenu>
1736
+ <MainMenu.Item> Item1 </MainMenu.Item>
1737
+ <MainMenu.Item> Item 2 </>
1738
+ <MobileFooter/>
1739
+ </MainMenu>
1740
+ </Excalidraw>
1741
+ }
1742
+
1743
+ ```
1744
+
1745
+ The `device` has the following `attributes`
1746
+
1747
+ | Name | Type | Description |
1748
+ | --- | --- | --- |
1749
+ | `isSmScreen` | `boolean` | Set to `true` when the device small screen is small (Width < `640px` ) |
1750
+ | `isMobile` | `boolean` | Set to `true` when the device is `mobile` |
1751
+ | `isTouchScreen` | `boolean` | Set to `true` for `touch` devices |
1752
+ | `canDeviceFitSidebar` | `boolean` | Implies whether there is enough space to fit the `sidebar` |
1753
+
1356
1754
  ### Exported constants
1357
1755
 
1358
1756
  #### `FONT_FAMILY`