@zsviczian/excalidraw 0.13.0-obsidian-1 → 0.14.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 +418 -20
- package/dist/excalidraw.development.js +571 -1154
- package/dist/excalidraw.production.min.js +1 -1
- package/dist/excalidraw.production.min.js.LICENSE.txt +0 -102
- package/package.json +1 -1
- package/types/actions/actionAddToLibrary.d.ts +21 -9
- package/types/actions/actionAlign.d.ts +6 -18
- package/types/actions/actionBoundText.d.ts +9 -5
- package/types/actions/actionCanvas.d.ts +83 -55
- package/types/actions/actionClipboard.d.ts +63 -16
- package/types/actions/actionDeleteSelected.d.ts +31 -12
- package/types/actions/actionDistribute.d.ts +2 -6
- package/types/actions/actionDuplicateSelection.d.ts +1 -3
- package/types/actions/actionExport.d.ts +79 -58
- package/types/actions/actionFinalize.d.ts +15 -9
- package/types/actions/actionFlip.d.ts +2 -2
- package/types/actions/actionGroup.d.ts +4 -8
- package/types/actions/actionLinearEditor.d.ts +8 -4
- package/types/actions/actionMenu.d.ts +24 -17
- package/types/actions/actionNavigate.d.ts +2 -3
- package/types/actions/actionProperties.d.ts +106 -80
- package/types/actions/actionStyles.d.ts +7 -3
- package/types/actions/actionToggleGridMode.d.ts +9 -3
- package/types/actions/actionToggleLock.d.ts +7 -3
- package/types/actions/actionToggleStats.d.ts +8 -3
- package/types/actions/actionToggleViewMode.d.ts +9 -3
- package/types/actions/actionToggleZenMode.d.ts +9 -3
- package/types/actions/actionZindex.d.ts +4 -12
- package/types/actions/manager.d.ts +2 -1
- package/types/actions/types.d.ts +6 -5
- package/types/appState.d.ts +8 -9
- package/types/clipboard.d.ts +6 -1
- package/types/components/App.d.ts +8 -51
- package/types/components/Button.d.ts +15 -0
- package/types/components/CollabButton.d.ts +1 -2
- package/types/components/ContextMenu.d.ts +8 -21
- package/types/components/JSONExportDialog.d.ts +3 -1
- package/types/components/LayerUI.d.ts +2 -3
- package/types/components/LibraryMenuHeaderContent.d.ts +23 -0
- package/types/components/MobileMenu.d.ts +4 -6
- package/types/components/UserList.d.ts +0 -2
- package/types/components/dropdownMenu/DropdownMenu.d.ts +64 -0
- package/types/components/dropdownMenu/DropdownMenuContent.d.ts +11 -0
- package/types/components/dropdownMenu/DropdownMenuGroup.d.ts +11 -0
- package/types/components/dropdownMenu/DropdownMenuItem.d.ts +13 -0
- package/types/components/dropdownMenu/DropdownMenuItemContent.d.ts +6 -0
- package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +6 -0
- package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +12 -0
- package/types/components/dropdownMenu/DropdownMenuSeparator.d.ts +5 -0
- package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +9 -0
- package/types/components/dropdownMenu/dropdownMenuUtils.d.ts +3 -0
- package/types/components/footer/Footer.d.ts +13 -0
- package/types/components/footer/FooterCenter.d.ts +8 -0
- package/types/components/icons.d.ts +1 -1
- package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +10 -0
- package/types/components/main-menu/DefaultItems.d.ts +44 -0
- package/types/components/main-menu/MainMenu.d.ts +55 -0
- package/types/components/mainMenu/DefaultItems.d.ts +44 -0
- package/types/components/mainMenu/MainMenu.d.ts +63 -0
- package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +58 -0
- package/types/components/welcome-screen/WelcomeScreen.Hints.d.ts +19 -0
- package/types/components/welcome-screen/WelcomeScreen.d.ts +85 -0
- package/types/constants.d.ts +6 -7
- package/types/element/Hyperlink.d.ts +9 -7
- package/types/element/bounds.d.ts +3 -2
- package/types/element/linearElementEditor.d.ts +38 -6
- package/types/element/newElement.d.ts +2 -2
- package/types/element/resizeElements.d.ts +0 -1
- package/types/element/textElement.d.ts +24 -2
- package/types/element/textWysiwyg.d.ts +6 -1
- package/types/element/transformHandles.d.ts +2 -3
- package/types/element/typeChecks.d.ts +10 -1
- package/types/element/types.d.ts +11 -4
- package/types/excalidraw-app/data/index.d.ts +13 -9
- package/types/excalidraw-app/data/localStorage.d.ts +13 -9
- package/types/keys.d.ts +2 -0
- package/types/math.d.ts +2 -1
- package/types/packages/excalidraw/example/CustomFooter.d.ts +5 -0
- package/types/packages/excalidraw/example/MobileFooter.d.ts +5 -0
- package/types/packages/excalidraw/index.d.ts +10 -0
- package/types/renderer/easingFunctions.d.ts +6 -0
- package/types/renderer/renderElement.d.ts +4 -3
- package/types/scene/Fonts.d.ts +21 -0
- package/types/scene/Scene.d.ts +15 -0
- package/types/scene/comparisons.d.ts +2 -3
- package/types/scene/index.d.ts +1 -1
- package/types/types.d.ts +43 -22
- package/types/utils.d.ts +17 -0
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
|
+

|
|
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) | [`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 |
|
|
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. |
|
|
@@ -563,10 +927,6 @@ You can use this function to update the library. It accepts the below attributes
|
|
|
563
927
|
|
|
564
928
|
Adds supplied files data to the `appState.files` cache on top of existing files present in the cache.
|
|
565
929
|
|
|
566
|
-
#### `onCollabButtonClick`
|
|
567
|
-
|
|
568
|
-
This callback is triggered when clicked on the collab button in excalidraw. If not supplied, the collab dialog button is not rendered.
|
|
569
|
-
|
|
570
930
|
#### `isCollaborating`
|
|
571
931
|
|
|
572
932
|
This prop indicates if the app is in collaboration mode.
|
|
@@ -614,14 +974,6 @@ import { defaultLang, languages } from "@excalidraw/excalidraw";
|
|
|
614
974
|
|
|
615
975
|
A function returning JSX to render custom UI in the top right corner of the app.
|
|
616
976
|
|
|
617
|
-
#### `renderFooter`
|
|
618
|
-
|
|
619
|
-
<pre>
|
|
620
|
-
(isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX | null
|
|
621
|
-
</pre>
|
|
622
|
-
|
|
623
|
-
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).
|
|
624
|
-
|
|
625
977
|
#### `renderCustomStats`
|
|
626
978
|
|
|
627
979
|
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.
|
|
@@ -933,7 +1285,7 @@ This function will make sure all properties of element is correctly set and if a
|
|
|
933
1285
|
|
|
934
1286
|
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.
|
|
935
1287
|
|
|
936
|
-
Parameter `refreshDimensions` indicates whether we should also recalculate text element dimensions. Defaults to `
|
|
1288
|
+
Parameter `refreshDimensions` indicates whether we should also recalculate text element dimensions. Defaults to `false`. 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
1289
|
|
|
938
1290
|
#### `restore`
|
|
939
1291
|
|
|
@@ -1354,6 +1706,52 @@ viewportCoordsToSceneCoords({clientX: number, clientY: number}, appState: <a hre
|
|
|
1354
1706
|
|
|
1355
1707
|
This function returns equivalent scene coords for the provided viewport coords in params.
|
|
1356
1708
|
|
|
1709
|
+
#### useDevice
|
|
1710
|
+
|
|
1711
|
+
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
|
|
1712
|
+
|
|
1713
|
+
```js
|
|
1714
|
+
import { useDevice, Footer } from "@excalidraw/excalidraw";
|
|
1715
|
+
|
|
1716
|
+
const MobileFooter = () => {
|
|
1717
|
+
const device = useDevice();
|
|
1718
|
+
if (device.isMobile) {
|
|
1719
|
+
return (
|
|
1720
|
+
<Footer>
|
|
1721
|
+
<button
|
|
1722
|
+
className="custom-footer"
|
|
1723
|
+
onClick={() => alert("This is custom footer in mobile menu")}
|
|
1724
|
+
>
|
|
1725
|
+
{" "}
|
|
1726
|
+
custom footer{" "}
|
|
1727
|
+
</button>
|
|
1728
|
+
</Footer>
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1731
|
+
return null;
|
|
1732
|
+
|
|
1733
|
+
};
|
|
1734
|
+
const App = () => {
|
|
1735
|
+
<Excalidraw>
|
|
1736
|
+
<MainMenu>
|
|
1737
|
+
<MainMenu.Item> Item1 </MainMenu.Item>
|
|
1738
|
+
<MainMenu.Item> Item 2 </>
|
|
1739
|
+
<MobileFooter/>
|
|
1740
|
+
</MainMenu>
|
|
1741
|
+
</Excalidraw>
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
The `device` has the following `attributes`
|
|
1747
|
+
|
|
1748
|
+
| Name | Type | Description |
|
|
1749
|
+
| --- | --- | --- |
|
|
1750
|
+
| `isSmScreen` | `boolean` | Set to `true` when the device small screen is small (Width < `640px` ) |
|
|
1751
|
+
| `isMobile` | `boolean` | Set to `true` when the device is `mobile` |
|
|
1752
|
+
| `isTouchScreen` | `boolean` | Set to `true` for `touch` devices |
|
|
1753
|
+
| `canDeviceFitSidebar` | `boolean` | Implies whether there is enough space to fit the `sidebar` |
|
|
1754
|
+
|
|
1357
1755
|
### Exported constants
|
|
1358
1756
|
|
|
1359
1757
|
#### `FONT_FAMILY`
|