@dwelle/excalidraw 0.4.0-587f6c0 → 0.4.0-5b8c704

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 (50) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +172 -0
  3. package/dist/excalidraw.development.js +173 -85
  4. package/dist/excalidraw.production.min.js +1 -1
  5. package/package.json +1 -1
  6. package/types/actions/actionAddToLibrary.d.ts +3 -3
  7. package/types/actions/actionBoundText.d.ts +1 -1
  8. package/types/actions/actionCanvas.d.ts +8 -8
  9. package/types/actions/actionClipboard.d.ts +5 -5
  10. package/types/actions/actionDeleteSelected.d.ts +3 -3
  11. package/types/actions/actionExport.d.ts +9 -9
  12. package/types/actions/actionFinalize.d.ts +2 -2
  13. package/types/actions/actionLinearEditor.d.ts +1 -1
  14. package/types/actions/actionMenu.d.ts +2 -2
  15. package/types/actions/actionProperties.d.ts +13 -13
  16. package/types/actions/actionStyles.d.ts +1 -1
  17. package/types/actions/actionToggleGridMode.d.ts +1 -1
  18. package/types/actions/actionToggleLock.d.ts +1 -1
  19. package/types/actions/actionToggleStats.d.ts +1 -1
  20. package/types/actions/actionToggleViewMode.d.ts +1 -1
  21. package/types/actions/actionToggleZenMode.d.ts +1 -1
  22. package/types/components/App.d.ts +5 -46
  23. package/types/components/JSONExportDialog.d.ts +4 -2
  24. package/types/components/LibraryMenuHeaderContent.d.ts +23 -0
  25. package/types/components/MobileMenu.d.ts +5 -7
  26. package/types/components/UserList.d.ts +0 -2
  27. package/types/components/WelcomeScreen.d.ts +60 -8
  28. package/types/components/dropdownMenu/DropdownMenu.d.ts +53 -0
  29. package/types/components/dropdownMenu/DropdownMenuContent.d.ts +11 -0
  30. package/types/components/dropdownMenu/DropdownMenuGroup.d.ts +11 -0
  31. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +15 -0
  32. package/types/components/dropdownMenu/DropdownMenuSeparator.d.ts +5 -0
  33. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +9 -0
  34. package/types/components/dropdownMenu/dropdownMenuUtils.d.ts +3 -0
  35. package/types/components/footer/Footer.d.ts +3 -3
  36. package/types/components/footer/FooterCenter.d.ts +1 -0
  37. package/types/components/mainMenu/DefaultItems.d.ts +44 -0
  38. package/types/components/mainMenu/MainMenu.d.ts +67 -0
  39. package/types/constants.d.ts +0 -4
  40. package/types/element/Hyperlink.d.ts +1 -1
  41. package/types/element/linearElementEditor.d.ts +2 -2
  42. package/types/element/textElement.d.ts +1 -0
  43. package/types/keys.d.ts +2 -0
  44. package/types/packages/excalidraw/example/CustomFooter.d.ts +5 -0
  45. package/types/packages/excalidraw/example/MobileFooter.d.ts +5 -0
  46. package/types/packages/excalidraw/index.d.ts +5 -0
  47. package/types/types.d.ts +14 -2
  48. package/types/components/MenuItem.d.ts +0 -11
  49. package/types/components/MenuUtils.d.ts +0 -1
  50. package/types/components/WelcomeScreenDecor.d.ts +0 -6
package/CHANGELOG.md CHANGED
@@ -15,6 +15,8 @@ Please add the latest change on the top under the correct section.
15
15
 
16
16
  ### Features
17
17
 
18
+ - 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)
19
+
18
20
  - Render Footer as a component instead of render prop [#5970](https://github.com/excalidraw/excalidraw/pull/5970). You can read more about its usage [here](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#Footer)
19
21
 
20
22
  #### BREAKING CHANGE
package/README.md CHANGED
@@ -405,6 +405,131 @@ const App = () => {
405
405
  };
406
406
  ```
407
407
 
408
+ This will only for `Desktop` devices.
409
+
410
+ For `mobile` you will need to render it inside the [MainMenu](#mainmenu). You can use the [`useDevice`](#useDevice) hook to check the type of device, this will be available only inside the `children` of `Excalidraw` component.
411
+
412
+ ```js
413
+ import { useDevice, Footer } from "@excalidraw/excalidraw";
414
+
415
+ const MobileFooter = ({
416
+ }) => {
417
+ const device = useDevice();
418
+ if (device.isMobile) {
419
+ return (
420
+ <Footer>
421
+ <button
422
+ className="custom-footer"
423
+ onClick={() => alert("This is custom footer in mobile menu")}
424
+ >
425
+ {" "}
426
+ custom footer{" "}
427
+ </button>
428
+ </Footer>
429
+ );
430
+ }
431
+ return null;
432
+
433
+ };
434
+ const App = () => {
435
+ <Excalidraw>
436
+ <MainMenu>
437
+ <MainMenu.Item> Item1 </MainMenu.Item>
438
+ <MainMenu.Item> Item 2 </>
439
+ <MobileFooter/>
440
+ </MainMenu>
441
+ </Excalidraw>
442
+ }
443
+
444
+ ```
445
+
446
+ You can visit the[ example](https://ehlz3.csb.app/) for working demo.
447
+
448
+ #### MainMenu
449
+
450
+ 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.
451
+
452
+ **Usage**
453
+
454
+ ```js
455
+ import { MainMenu } from "@excalidraw/excalidraw";
456
+ const App = () => {
457
+ <Excalidraw>
458
+ <MainMenu>
459
+ <MainMenu.Item> Item1 </MainMenu.Item>
460
+ <MainMenu.Item> Item 2 </>
461
+ </MainMenu>
462
+ </Excalidraw>
463
+ }
464
+ ```
465
+
466
+ **MainMenu**
467
+
468
+ This is the `MainMenu` component which you need to import to render the menu with custom options.
469
+
470
+ **MainMenu.Item**
471
+
472
+ To render an item, its recommended to use `MainMenu.Item`
473
+
474
+ | Prop | Type | Default | Description |
475
+ | --- | --- | --- | --- |
476
+ | `icon` | `JSX.Element` | `undefined` | The icon used in the menu item |
477
+ | `shortcut` | `string` | `undefined` | The shortcut to be shown for the menu item |
478
+ | `children` | `React.ReactNode` | `undefined` | The content of the menu item |
479
+ | `onClick` | `Function` | `undefined` | The click handler will be triggered when clicked on menu item. If passed the item is rendered as a button. |
480
+ | `className` | `string` | "" | The class names to be added to the menu item |
481
+ | `link` | `string` | `undefined` | If `link` is passed the item is rendered as an anchor element. |
482
+ | `style` | `React.CSSProperties` | `undefined` | The inline styles to be added to the menu item |
483
+
484
+ **MainMenu.DefaultItems**
485
+
486
+ For the items which are shown in the menu in [excalidraw.com](https://excalidraw.com), you can use `MainMenu.DefaultItems`
487
+
488
+ ```js
489
+ import { MainMenu } from "@excalidraw/excalidraw";
490
+ const App = () => {
491
+ <Excalidraw>
492
+ <MainMenu>
493
+ <MainMenu.DefaultItems.Socials/>
494
+ <MainMenu.DefaultItems.Export/>
495
+ <MainMenu.Item> Item1 </MainMenu.Item>
496
+ <MainMenu.Item> Item 2 </>
497
+ </MainMenu>
498
+ </Excalidraw>
499
+ }
500
+ ```
501
+
502
+ Here is a [complete list](https://github.com/excalidraw/excalidraw/blob/master/src/components/mainMenu/DefaultItems.tsx) of the default items.
503
+
504
+ **MainMenu.Group**
505
+
506
+ To Group item in the main menu, you can use `MainMenu.Group`
507
+
508
+ ```js
509
+ import { MainMenu } from "@excalidraw/excalidraw";
510
+ const App = () => {
511
+ <Excalidraw>
512
+ <MainMenu>
513
+ <MainMenu.Group title="Excalidraw items">
514
+ <MainMenu.DefaultItems.Socials/>
515
+ <MainMenu.DefaultItems.Export/>
516
+ </MainMenu.Group>
517
+ <MainMenu.Group title="custom items">
518
+ <MainMenu.Item> Item1 </MainMenu.Item>
519
+ <MainMenu.Item> Item 2 </>
520
+ </MainMenu.Group>
521
+ </MainMenu>
522
+ </Excalidraw>
523
+ }
524
+ ```
525
+
526
+ | Prop | Type | Default | Description |
527
+ | --- | --- | --- | --- |
528
+ | `title` | `string` | `undefined` | The `title` for the grouped items |
529
+ | `className` | `string` | "" | The `classname` to be added to the group |
530
+ | `style` | `React.CSsSProperties` | `undefined` | The inline `styles` to be added to the group |
531
+ | `children ` | `React.ReactNode` | `undefined` | The content of the `Menu Group` |
532
+
408
533
  ### Props
409
534
 
410
535
  | Name | Type | Default | Description |
@@ -1369,6 +1494,53 @@ viewportCoordsToSceneCoords({clientX: number, clientY: number}, appState: <a hre
1369
1494
 
1370
1495
  This function returns equivalent scene coords for the provided viewport coords in params.
1371
1496
 
1497
+ #### useDevice
1498
+
1499
+ 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
1500
+
1501
+ ```js
1502
+ import { useDevice, Footer } from "@excalidraw/excalidraw";
1503
+
1504
+ const MobileFooter = ({
1505
+ }) => {
1506
+ const device = useDevice();
1507
+ if (device.isMobile) {
1508
+ return (
1509
+ <Footer>
1510
+ <button
1511
+ className="custom-footer"
1512
+ onClick={() => alert("This is custom footer in mobile menu")}
1513
+ >
1514
+ {" "}
1515
+ custom footer{" "}
1516
+ </button>
1517
+ </Footer>
1518
+ );
1519
+ }
1520
+ return null;
1521
+
1522
+ };
1523
+ const App = () => {
1524
+ <Excalidraw>
1525
+ <MainMenu>
1526
+ <MainMenu.Item> Item1 </MainMenu.Item>
1527
+ <MainMenu.Item> Item 2 </>
1528
+ <MobileFooter/>
1529
+ </MainMenu>
1530
+ </Excalidraw>
1531
+ }
1532
+
1533
+ ```
1534
+
1535
+ The `device` has the following `attributes`
1536
+
1537
+ | Name | Type | Description |
1538
+ | --- | --- | --- |
1539
+ | `isSmScreen` | `boolean` | Set to `true` when the device small screen is small (Width < `640px` ) |
1540
+ | `isMobile` | `boolean` | Set to `true` when the device is `mobile` |
1541
+ | `isTouchScreen` | `boolean` | Set to `true` for `touch` devices |
1542
+ | `canDeviceFitSidebar` | `boolean` | Implies whether there is enough space to fit the `sidebar` |
1543
+
1372
1544
  ### Exported constants
1373
1545
 
1374
1546
  #### `FONT_FAMILY`