tldraw 3.16.0-internal.a478398270c6 → 3.16.0-internal.f8b97f0c414f

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 (656) hide show
  1. package/dist-cjs/index.d.ts +471 -130
  2. package/dist-cjs/index.js +58 -15
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/Tldraw.js +12 -2
  5. package/dist-cjs/lib/Tldraw.js.map +2 -2
  6. package/dist-cjs/lib/TldrawImage.js +5 -2
  7. package/dist-cjs/lib/TldrawImage.js.map +3 -3
  8. package/dist-cjs/lib/canvas/TldrawCropHandles.js +1 -1
  9. package/dist-cjs/lib/canvas/TldrawCropHandles.js.map +2 -2
  10. package/dist-cjs/lib/canvas/TldrawHandles.js +1 -1
  11. package/dist-cjs/lib/canvas/TldrawHandles.js.map +2 -2
  12. package/dist-cjs/lib/canvas/TldrawOverlays.js +1 -1
  13. package/dist-cjs/lib/canvas/TldrawOverlays.js.map +2 -2
  14. package/dist-cjs/lib/canvas/TldrawScribble.js +1 -1
  15. package/dist-cjs/lib/canvas/TldrawScribble.js.map +2 -2
  16. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +279 -271
  17. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
  18. package/dist-cjs/lib/defaultExternalContentHandlers.js +6 -4
  19. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  20. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +27 -44
  21. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  22. package/dist-cjs/lib/shapes/arrow/arrowLabel.js +22 -4
  23. package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +3 -3
  24. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js +1 -1
  25. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
  26. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js +3 -3
  27. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  28. package/dist-cjs/lib/shapes/arrow/elbow/elbowArrowSnapLines.js.map +1 -1
  29. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +3 -0
  30. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
  31. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +4 -4
  32. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
  33. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -6
  34. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
  35. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +1 -1
  36. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +1 -1
  37. package/dist-cjs/lib/shapes/frame/FrameShapeTool.js.map +1 -1
  38. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +25 -18
  39. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  40. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js +1 -1
  41. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js.map +2 -2
  42. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js +2 -2
  43. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js.map +2 -2
  44. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +3 -2
  45. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  46. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
  47. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
  48. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -4
  49. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  50. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +6 -3
  51. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +2 -2
  52. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +20 -5
  53. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  54. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +8 -6
  55. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  56. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +4 -4
  57. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js.map +2 -2
  58. package/dist-cjs/lib/shapes/shared/PathBuilder.js +21 -3
  59. package/dist-cjs/lib/shapes/shared/PathBuilder.js.map +2 -2
  60. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +2 -3
  61. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  62. package/dist-cjs/lib/shapes/shared/RichTextLabel.js +5 -2
  63. package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
  64. package/dist-cjs/lib/shapes/shared/ShapeFill.js +4 -4
  65. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  66. package/dist-cjs/lib/shapes/shared/SvgTextLabel.js +4 -3
  67. package/dist-cjs/lib/shapes/shared/SvgTextLabel.js.map +2 -2
  68. package/dist-cjs/lib/shapes/shared/crop.js +1 -0
  69. package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
  70. package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
  71. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js +3 -4
  72. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  73. package/dist-cjs/lib/shapes/shared/useEditableRichText.js.map +2 -2
  74. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js +0 -2
  75. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js.map +2 -2
  76. package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js +10 -1
  77. package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js.map +2 -2
  78. package/dist-cjs/lib/shapes/text/PlainTextArea.js +2 -2
  79. package/dist-cjs/lib/shapes/text/PlainTextArea.js.map +2 -2
  80. package/dist-cjs/lib/shapes/text/RichTextArea.js +3 -3
  81. package/dist-cjs/lib/shapes/text/RichTextArea.js.map +2 -2
  82. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +7 -13
  83. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  84. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  85. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  86. package/dist-cjs/lib/styles.js.map +2 -2
  87. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +25 -1
  88. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  89. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js +12 -0
  90. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  91. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCrop.js +7 -1
  92. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCrop.js.map +2 -2
  93. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +43 -22
  94. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  95. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -15
  96. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  97. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +5 -0
  98. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
  99. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +8 -0
  100. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
  101. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +8 -0
  102. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
  103. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +8 -0
  104. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  105. package/dist-cjs/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.js.map +2 -2
  106. package/dist-cjs/lib/ui/TldrawUi.js +27 -12
  107. package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
  108. package/dist-cjs/lib/ui/components/A11y.js +15 -13
  109. package/dist-cjs/lib/ui/components/A11y.js.map +2 -2
  110. package/dist-cjs/lib/ui/components/AccessibilityMenu.js +35 -0
  111. package/dist-cjs/lib/ui/components/AccessibilityMenu.js.map +7 -0
  112. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +12 -3
  113. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  114. package/dist-cjs/lib/ui/components/{FollowingIndicator.js → DefaultFollowingIndicator.js} +6 -6
  115. package/dist-cjs/lib/ui/components/DefaultFollowingIndicator.js.map +7 -0
  116. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js +3 -2
  117. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js.map +2 -2
  118. package/dist-cjs/lib/ui/components/EditLinkDialog.js +11 -1
  119. package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
  120. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +57 -7
  121. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +2 -2
  122. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js +3 -2
  123. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js.map +2 -2
  124. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  125. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  126. package/dist-cjs/lib/ui/components/MobileStylePanel.js +5 -3
  127. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  128. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +4 -5
  129. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
  130. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +3 -2
  131. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  132. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js +3 -2
  133. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js.map +2 -2
  134. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +2 -2
  135. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js.map +2 -2
  136. package/dist-cjs/lib/ui/components/Spinner.js +2 -25
  137. package/dist-cjs/lib/ui/components/Spinner.js.map +2 -2
  138. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +11 -4
  139. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js.map +2 -2
  140. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +249 -278
  141. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  142. package/dist-cjs/lib/ui/components/{primitives/TldrawUiButtonPicker.js → StylePanel/StylePanelButtonPicker.js} +52 -54
  143. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +7 -0
  144. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js +68 -0
  145. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js.map +7 -0
  146. package/dist-cjs/lib/ui/components/StylePanel/{DoubleDropdownPicker.js → StylePanelDoubleDropdownPicker.js} +26 -25
  147. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +7 -0
  148. package/dist-cjs/lib/ui/components/StylePanel/{DropdownPicker.js → StylePanelDropdownPicker.js} +47 -43
  149. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +7 -0
  150. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js +28 -0
  151. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js.map +7 -0
  152. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +3 -2
  153. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  154. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbar.js +21 -7
  155. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbar.js.map +3 -3
  156. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +39 -10
  157. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  158. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +66 -21
  159. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
  160. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js +15 -3
  161. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js.map +2 -2
  162. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +3 -3
  163. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  164. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +189 -80
  165. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
  166. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +5 -4
  167. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  168. package/dist-cjs/lib/ui/components/menu-items.js +22 -0
  169. package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
  170. package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButtonIcon.js.map +2 -2
  171. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +11 -2
  172. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  173. package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js +1 -1
  174. package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js.map +2 -2
  175. package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +35 -1
  176. package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js.map +2 -2
  177. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +2 -2
  178. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js.map +2 -2
  179. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +3 -2
  180. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js.map +3 -3
  181. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +23 -6
  182. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  183. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +33 -7
  184. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  185. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +294 -0
  186. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +7 -0
  187. package/dist-cjs/lib/ui/components/primitives/layout.js +76 -0
  188. package/dist-cjs/lib/ui/components/primitives/layout.js.map +7 -0
  189. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
  190. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  191. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +25 -12
  192. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  193. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +154 -22
  194. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  195. package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js +3 -2
  196. package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js.map +2 -2
  197. package/dist-cjs/lib/ui/context/actions.js +79 -17
  198. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  199. package/dist-cjs/lib/ui/context/components.js +2 -0
  200. package/dist-cjs/lib/ui/context/components.js.map +2 -2
  201. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  202. package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
  203. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +1 -1
  204. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
  205. package/dist-cjs/lib/ui/hooks/useExportAs.js +3 -2
  206. package/dist-cjs/lib/ui/hooks/useExportAs.js.map +2 -2
  207. package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +2 -2
  208. package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js.map +2 -2
  209. package/dist-cjs/lib/ui/hooks/useTools.js +94 -9
  210. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  211. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  212. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +13 -0
  213. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  214. package/dist-cjs/lib/ui/kbd-utils.js +11 -4
  215. package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
  216. package/dist-cjs/lib/ui/version.js +3 -3
  217. package/dist-cjs/lib/ui/version.js.map +1 -1
  218. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js +1 -1
  219. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
  220. package/dist-cjs/lib/utils/export/copyAs.js +1 -2
  221. package/dist-cjs/lib/utils/export/copyAs.js.map +2 -2
  222. package/dist-cjs/lib/utils/export/export.js +0 -20
  223. package/dist-cjs/lib/utils/export/export.js.map +2 -2
  224. package/dist-cjs/lib/utils/export/exportAs.js +1 -2
  225. package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
  226. package/dist-cjs/lib/utils/tldr/buildFromV1Document.js +3 -2
  227. package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
  228. package/dist-esm/index.d.mts +471 -130
  229. package/dist-esm/index.mjs +107 -32
  230. package/dist-esm/index.mjs.map +2 -2
  231. package/dist-esm/lib/Tldraw.mjs +14 -4
  232. package/dist-esm/lib/Tldraw.mjs.map +2 -2
  233. package/dist-esm/lib/TldrawImage.mjs +5 -2
  234. package/dist-esm/lib/TldrawImage.mjs.map +2 -2
  235. package/dist-esm/lib/canvas/TldrawCropHandles.mjs +1 -1
  236. package/dist-esm/lib/canvas/TldrawCropHandles.mjs.map +2 -2
  237. package/dist-esm/lib/canvas/TldrawHandles.mjs +1 -1
  238. package/dist-esm/lib/canvas/TldrawHandles.mjs.map +2 -2
  239. package/dist-esm/lib/canvas/TldrawOverlays.mjs +1 -1
  240. package/dist-esm/lib/canvas/TldrawOverlays.mjs.map +2 -2
  241. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  242. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  243. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs +279 -271
  244. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
  245. package/dist-esm/lib/defaultExternalContentHandlers.mjs +6 -4
  246. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  247. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +30 -44
  248. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  249. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +25 -5
  250. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +3 -3
  251. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs +1 -1
  252. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
  253. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  254. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  255. package/dist-esm/lib/shapes/arrow/elbow/elbowArrowSnapLines.mjs.map +1 -1
  256. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +3 -0
  257. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
  258. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +5 -5
  259. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
  260. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -6
  261. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  262. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  263. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  264. package/dist-esm/lib/shapes/frame/FrameShapeTool.mjs.map +1 -1
  265. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +26 -18
  266. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  267. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  268. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  269. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs +3 -3
  270. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs.map +2 -2
  271. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +4 -2
  272. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  273. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
  274. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
  275. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -4
  276. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  277. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +6 -3
  278. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +2 -2
  279. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +21 -5
  280. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  281. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +9 -6
  282. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  283. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs +5 -5
  284. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs.map +2 -2
  285. package/dist-esm/lib/shapes/shared/PathBuilder.mjs +22 -3
  286. package/dist-esm/lib/shapes/shared/PathBuilder.mjs.map +2 -2
  287. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +2 -3
  288. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  289. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +5 -2
  290. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
  291. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +5 -4
  292. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  293. package/dist-esm/lib/shapes/shared/SvgTextLabel.mjs +4 -3
  294. package/dist-esm/lib/shapes/shared/SvgTextLabel.mjs.map +2 -2
  295. package/dist-esm/lib/shapes/shared/crop.mjs +1 -0
  296. package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
  297. package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
  298. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs +4 -5
  299. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  300. package/dist-esm/lib/shapes/shared/useEditableRichText.mjs.map +2 -2
  301. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs +0 -2
  302. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs.map +2 -2
  303. package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs +10 -1
  304. package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs.map +2 -2
  305. package/dist-esm/lib/shapes/text/PlainTextArea.mjs +3 -3
  306. package/dist-esm/lib/shapes/text/PlainTextArea.mjs.map +2 -2
  307. package/dist-esm/lib/shapes/text/RichTextArea.mjs +3 -4
  308. package/dist-esm/lib/shapes/text/RichTextArea.mjs.map +2 -2
  309. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +8 -13
  310. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  311. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  312. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  313. package/dist-esm/lib/styles.mjs.map +2 -2
  314. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +26 -1
  315. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  316. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +13 -0
  317. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  318. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCrop.mjs +7 -1
  319. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCrop.mjs.map +2 -2
  320. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +43 -22
  321. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  322. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -15
  323. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  324. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +5 -0
  325. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
  326. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +8 -0
  327. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
  328. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +8 -0
  329. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
  330. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +8 -0
  331. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  332. package/dist-esm/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.mjs.map +2 -2
  333. package/dist-esm/lib/ui/TldrawUi.mjs +29 -14
  334. package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
  335. package/dist-esm/lib/ui/components/A11y.mjs +16 -14
  336. package/dist-esm/lib/ui/components/A11y.mjs.map +2 -2
  337. package/dist-esm/lib/ui/components/AccessibilityMenu.mjs +19 -0
  338. package/dist-esm/lib/ui/components/AccessibilityMenu.mjs.map +7 -0
  339. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +12 -3
  340. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  341. package/dist-esm/lib/ui/components/{FollowingIndicator.mjs → DefaultFollowingIndicator.mjs} +3 -3
  342. package/dist-esm/lib/ui/components/DefaultFollowingIndicator.mjs.map +7 -0
  343. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs +3 -2
  344. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs.map +2 -2
  345. package/dist-esm/lib/ui/components/EditLinkDialog.mjs +11 -1
  346. package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
  347. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +57 -7
  348. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +2 -2
  349. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs +3 -3
  350. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs.map +2 -2
  351. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  352. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  353. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +6 -3
  354. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  355. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +4 -5
  356. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
  357. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +4 -3
  358. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  359. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs +3 -2
  360. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs.map +2 -2
  361. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs +2 -2
  362. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs.map +2 -2
  363. package/dist-esm/lib/ui/components/Spinner.mjs +3 -26
  364. package/dist-esm/lib/ui/components/Spinner.mjs.map +2 -2
  365. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs +16 -5
  366. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs.map +2 -2
  367. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +251 -282
  368. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  369. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +126 -0
  370. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +7 -0
  371. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs +48 -0
  372. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs.map +7 -0
  373. package/dist-esm/lib/ui/components/StylePanel/{DoubleDropdownPicker.mjs → StylePanelDoubleDropdownPicker.mjs} +23 -22
  374. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +7 -0
  375. package/dist-esm/lib/ui/components/StylePanel/{DropdownPicker.mjs → StylePanelDropdownPicker.mjs} +44 -40
  376. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +7 -0
  377. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs +8 -0
  378. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs.map +7 -0
  379. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +3 -2
  380. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  381. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbar.mjs +23 -9
  382. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbar.mjs.map +3 -3
  383. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +39 -10
  384. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  385. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +56 -21
  386. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
  387. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs +15 -3
  388. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs.map +2 -2
  389. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
  390. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  391. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -81
  392. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
  393. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +5 -4
  394. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  395. package/dist-esm/lib/ui/components/menu-items.mjs +22 -0
  396. package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
  397. package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButtonIcon.mjs.map +2 -2
  398. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +12 -3
  399. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  400. package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs +1 -1
  401. package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs.map +2 -2
  402. package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs +36 -2
  403. package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs.map +2 -2
  404. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs +3 -3
  405. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs.map +2 -2
  406. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs +3 -2
  407. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs.map +2 -2
  408. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +23 -6
  409. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  410. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +33 -7
  411. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  412. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +272 -0
  413. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +7 -0
  414. package/dist-esm/lib/ui/components/primitives/layout.mjs +46 -0
  415. package/dist-esm/lib/ui/components/primitives/layout.mjs.map +7 -0
  416. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
  417. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  418. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +25 -12
  419. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  420. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +162 -24
  421. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  422. package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs +3 -2
  423. package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs.map +2 -2
  424. package/dist-esm/lib/ui/context/actions.mjs +79 -17
  425. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  426. package/dist-esm/lib/ui/context/components.mjs +2 -0
  427. package/dist-esm/lib/ui/context/components.mjs.map +2 -2
  428. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  429. package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
  430. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +2 -2
  431. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
  432. package/dist-esm/lib/ui/hooks/useExportAs.mjs +3 -2
  433. package/dist-esm/lib/ui/hooks/useExportAs.mjs.map +2 -2
  434. package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs +2 -2
  435. package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs.map +2 -2
  436. package/dist-esm/lib/ui/hooks/useTools.mjs +102 -10
  437. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  438. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +13 -0
  439. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  440. package/dist-esm/lib/ui/kbd-utils.mjs +11 -4
  441. package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
  442. package/dist-esm/lib/ui/version.mjs +3 -3
  443. package/dist-esm/lib/ui/version.mjs.map +1 -1
  444. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +1 -1
  445. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
  446. package/dist-esm/lib/utils/export/copyAs.mjs +1 -2
  447. package/dist-esm/lib/utils/export/copyAs.mjs.map +2 -2
  448. package/dist-esm/lib/utils/export/export.mjs +0 -20
  449. package/dist-esm/lib/utils/export/export.mjs.map +2 -2
  450. package/dist-esm/lib/utils/export/exportAs.mjs +1 -2
  451. package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
  452. package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs +3 -2
  453. package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
  454. package/package.json +12 -34
  455. package/src/index.ts +80 -24
  456. package/src/lib/Tldraw.tsx +15 -2
  457. package/src/lib/TldrawImage.tsx +6 -2
  458. package/src/lib/canvas/TldrawCropHandles.tsx +3 -1
  459. package/src/lib/canvas/TldrawHandles.tsx +5 -1
  460. package/src/lib/canvas/TldrawOverlays.tsx +1 -1
  461. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  462. package/src/lib/canvas/TldrawSelectionForeground.tsx +5 -1
  463. package/src/lib/defaultExternalContentHandlers.ts +14 -5
  464. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +2 -1
  465. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +6 -5
  466. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +53 -11
  467. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +30 -46
  468. package/src/lib/shapes/arrow/arrowLabel.ts +31 -3
  469. package/src/lib/shapes/arrow/arrowTargetState.ts +3 -2
  470. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  471. package/src/lib/shapes/arrow/elbow/elbowArrowSnapLines.tsx +2 -2
  472. package/src/lib/shapes/arrow/toolStates/Pointing.tsx +3 -0
  473. package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +5 -5
  474. package/src/lib/shapes/draw/DrawShapeTool.test.ts +0 -5
  475. package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -7
  476. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  477. package/src/lib/shapes/frame/FrameShapeTool.ts +1 -1
  478. package/src/lib/shapes/frame/FrameShapeUtil.tsx +35 -21
  479. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  480. package/src/lib/shapes/frame/components/FrameLabelInput.tsx +3 -3
  481. package/src/lib/shapes/geo/GeoShapeUtil.tsx +4 -2
  482. package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
  483. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -4
  484. package/src/lib/shapes/image/ImageShapeUtil.tsx +6 -3
  485. package/src/lib/shapes/line/LineShapeUtil.test.tsx +8 -7
  486. package/src/lib/shapes/line/LineShapeUtil.tsx +25 -6
  487. package/src/lib/shapes/line/__snapshots__/LineShapeUtil.test.tsx.snap +2 -2
  488. package/src/lib/shapes/note/NoteShapeTool.test.ts +2 -1
  489. package/src/lib/shapes/note/NoteShapeUtil.tsx +11 -4
  490. package/src/lib/shapes/shared/HyperlinkButton.tsx +5 -5
  491. package/src/lib/shapes/shared/PathBuilder.test.tsx +1 -1
  492. package/src/lib/shapes/shared/PathBuilder.tsx +35 -1
  493. package/src/lib/shapes/shared/PlainTextLabel.tsx +3 -7
  494. package/src/lib/shapes/shared/RichTextLabel.tsx +6 -1
  495. package/src/lib/shapes/shared/ShapeFill.tsx +5 -4
  496. package/src/lib/shapes/shared/SvgTextLabel.tsx +4 -2
  497. package/src/lib/shapes/shared/crop.ts +1 -0
  498. package/src/lib/shapes/shared/freehand/svg.ts +2 -0
  499. package/src/lib/shapes/shared/useEditablePlainText.ts +12 -12
  500. package/src/lib/shapes/shared/useEditableRichText.ts +7 -3
  501. package/src/lib/shapes/shared/useImageOrVideoAsset.ts +0 -7
  502. package/src/lib/shapes/shared/usePrefersReducedMotion.tsx +11 -1
  503. package/src/lib/shapes/text/PlainTextArea.tsx +3 -3
  504. package/src/lib/shapes/text/RichTextArea.tsx +3 -4
  505. package/src/lib/shapes/text/TextShapeTool.test.ts +6 -5
  506. package/src/lib/shapes/text/TextShapeUtil.tsx +8 -14
  507. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  508. package/src/lib/styles.tsx +3 -1
  509. package/src/lib/tools/EraserTool/childStates/Erasing.ts +34 -1
  510. package/src/lib/tools/EraserTool/childStates/Pointing.ts +20 -0
  511. package/src/lib/tools/SelectTool/childStates/Crop/children/PointingCrop.ts +8 -1
  512. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +54 -30
  513. package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -24
  514. package/src/lib/tools/SelectTool/childStates/PointingShape.ts +7 -0
  515. package/src/lib/tools/SelectTool/childStates/Resizing.ts +12 -1
  516. package/src/lib/tools/SelectTool/childStates/Rotating.ts +11 -0
  517. package/src/lib/tools/SelectTool/childStates/Translating.ts +11 -1
  518. package/src/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.ts +1 -0
  519. package/src/lib/ui/TldrawUi.tsx +33 -12
  520. package/src/lib/ui/components/A11y.tsx +17 -15
  521. package/src/lib/ui/components/AccessibilityMenu.tsx +20 -0
  522. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +15 -3
  523. package/src/lib/ui/components/{FollowingIndicator.tsx → DefaultFollowingIndicator.tsx} +2 -1
  524. package/src/lib/ui/components/DefaultMenuPanel.tsx +4 -3
  525. package/src/lib/ui/components/EditLinkDialog.tsx +16 -6
  526. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +46 -6
  527. package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +4 -2
  528. package/src/lib/ui/components/Minimap/MinimapManager.ts +4 -4
  529. package/src/lib/ui/components/MobileStylePanel.tsx +9 -6
  530. package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +4 -5
  531. package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +5 -4
  532. package/src/lib/ui/components/SharePanel/PeopleMenuItem.tsx +4 -3
  533. package/src/lib/ui/components/SharePanel/UserPresenceColorPicker.tsx +3 -3
  534. package/src/lib/ui/components/Spinner.tsx +2 -24
  535. package/src/lib/ui/components/StylePanel/DefaultStylePanel.tsx +28 -12
  536. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +261 -342
  537. package/src/lib/ui/components/{primitives/TldrawUiButtonPicker.tsx → StylePanel/StylePanelButtonPicker.tsx} +66 -48
  538. package/src/lib/ui/components/StylePanel/StylePanelContext.tsx +63 -0
  539. package/src/lib/ui/components/StylePanel/{DoubleDropdownPicker.tsx → StylePanelDoubleDropdownPicker.tsx} +31 -22
  540. package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +119 -0
  541. package/src/lib/ui/components/StylePanel/StylePanelSubheading.tsx +9 -0
  542. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +5 -4
  543. package/src/lib/ui/components/Toolbar/DefaultImageToolbar.tsx +25 -9
  544. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +33 -16
  545. package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +55 -23
  546. package/src/lib/ui/components/Toolbar/DefaultVideoToolbarContent.tsx +12 -4
  547. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +5 -5
  548. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +212 -61
  549. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +17 -12
  550. package/src/lib/ui/components/menu-items.tsx +25 -0
  551. package/src/lib/ui/components/primitives/Button/TldrawUiButtonIcon.tsx +2 -2
  552. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +8 -3
  553. package/src/lib/ui/components/primitives/TldrawUiDialog.tsx +1 -1
  554. package/src/lib/ui/components/primitives/TldrawUiIcon.tsx +41 -3
  555. package/src/lib/ui/components/primitives/TldrawUiInput.tsx +3 -3
  556. package/src/lib/ui/components/primitives/TldrawUiPopover.tsx +4 -2
  557. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +54 -29
  558. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +59 -12
  559. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +365 -0
  560. package/src/lib/ui/components/primitives/layout.tsx +107 -0
  561. package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +2 -2
  562. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  563. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +29 -16
  564. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +224 -23
  565. package/src/lib/ui/context/TldrawUiContextProvider.tsx +23 -20
  566. package/src/lib/ui/context/actions.tsx +81 -18
  567. package/src/lib/ui/context/components.tsx +3 -0
  568. package/src/lib/ui/context/events.tsx +7 -3
  569. package/src/lib/ui/hooks/menu-hooks.ts +1 -0
  570. package/src/lib/ui/hooks/useClipboardEvents.ts +2 -2
  571. package/src/lib/ui/hooks/useExportAs.ts +3 -2
  572. package/src/lib/ui/hooks/useKeyboardShortcuts.ts +3 -2
  573. package/src/lib/ui/hooks/useTools.tsx +142 -11
  574. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +13 -0
  575. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +13 -0
  576. package/src/lib/ui/kbd-utils.ts +12 -4
  577. package/src/lib/ui/version.ts +3 -3
  578. package/src/lib/ui.css +432 -315
  579. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +21 -7
  580. package/src/lib/utils/excalidraw/putExcalidrawContent.ts +7 -7
  581. package/src/lib/utils/export/copyAs.ts +1 -24
  582. package/src/lib/utils/export/export.ts +0 -36
  583. package/src/lib/utils/export/exportAs.ts +1 -32
  584. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +28 -7
  585. package/src/lib/utils/tldr/buildFromV1Document.ts +2 -1
  586. package/src/test/A11y.test.tsx +3 -2
  587. package/src/test/ClickManager.test.ts +7 -6
  588. package/src/test/Editor.test.tsx +56 -28
  589. package/src/test/EraserTool.test.ts +184 -13
  590. package/src/test/HandTool.test.ts +10 -9
  591. package/src/test/HighlightShape.test.ts +2 -1
  592. package/src/test/SelectTool.test.ts +40 -13
  593. package/src/test/TLUserPreferences.test.ts +4 -3
  594. package/src/test/TestEditor.ts +13 -15
  595. package/src/test/TldrawEditor.test.tsx +26 -19
  596. package/src/test/ZoomTool.test.ts +7 -6
  597. package/src/test/__snapshots__/drawing.test.ts.snap +2 -2
  598. package/src/test/__snapshots__/groups.test.tsx.snap +6 -6
  599. package/src/test/__snapshots__/resizing.test.ts.snap +2 -2
  600. package/src/test/arrows-megabus.test.tsx +17 -10
  601. package/src/test/bindings.test.tsx +24 -37
  602. package/src/test/bookmark-shapes.test.ts +1 -8
  603. package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +23 -7
  604. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +8 -8
  605. package/src/test/commands/__snapshots__/zoomToFit.test.ts.snap +2 -2
  606. package/src/test/commands/alignShapes.test.tsx +25 -24
  607. package/src/test/commands/animationSpeed.test.ts +2 -1
  608. package/src/test/commands/centerOnPoint.test.ts +3 -2
  609. package/src/test/commands/clipboard.test.ts +3 -2
  610. package/src/test/commands/createShapes.test.ts +2 -1
  611. package/src/test/commands/deletePage.test.ts +84 -1
  612. package/src/test/commands/deleteShapes.test.ts +2 -1
  613. package/src/test/commands/distributeShapes.test.tsx +11 -10
  614. package/src/test/commands/getSvgString.test.ts +2 -1
  615. package/src/test/commands/packShapes.test.ts +5 -4
  616. package/src/test/commands/putContent.test.ts +1 -0
  617. package/src/test/commands/resizeShape.test.ts +2 -1
  618. package/src/test/commands/rotateShapes.test.ts +7 -6
  619. package/src/test/commands/setCamera.test.ts +4 -3
  620. package/src/test/commands/setCurrentPage.test.ts +3 -2
  621. package/src/test/commands/stackShapes.test.ts +11 -10
  622. package/src/test/commands/stretch.test.tsx +13 -12
  623. package/src/test/commands/updateShapes.test.ts +9 -5
  624. package/src/test/createDeepLink.test.tsx +2 -1
  625. package/src/test/cropping.test.ts +3 -2
  626. package/src/test/custom-clipping.test.ts +442 -0
  627. package/src/test/customSnapping.test.tsx +55 -41
  628. package/src/test/drawing.test.ts +2 -1
  629. package/src/test/flipShapes.test.ts +4 -3
  630. package/src/test/frames.test.ts +25 -24
  631. package/src/test/getCulledShapes.test.tsx +80 -4
  632. package/src/test/groups.test.tsx +6 -4
  633. package/src/test/handleDeepLink.test.tsx +2 -1
  634. package/src/test/inner-outer-margin.test.ts +315 -0
  635. package/src/test/maxShapes.test.ts +3 -2
  636. package/src/test/modifiers.test.ts +5 -4
  637. package/src/test/navigation.test.ts +264 -9
  638. package/src/test/panning.test.ts +2 -1
  639. package/src/test/perf/perf.test.ts +2 -1
  640. package/src/test/registerDeepLinkListener.test.tsx +10 -9
  641. package/src/test/resizing.test.ts +39 -38
  642. package/src/test/select.test.tsx +4 -3
  643. package/src/test/selection-omnibus.test.ts +11 -10
  644. package/src/test/shapeutils.test.ts +398 -48
  645. package/src/test/translating.test.ts +12 -11
  646. package/tldraw.css +759 -630
  647. package/dist-cjs/lib/ui/components/FollowingIndicator.js.map +0 -7
  648. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +0 -7
  649. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +0 -7
  650. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +0 -7
  651. package/dist-esm/lib/ui/components/FollowingIndicator.mjs.map +0 -7
  652. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +0 -7
  653. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +0 -7
  654. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +0 -113
  655. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +0 -7
  656. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +0 -109
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/ui/hooks/menu-hooks.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tTLArrowShape,\n\tTLDrawShape,\n\tTLGroupShape,\n\tTLImageShape,\n\tTLLineShape,\n\tTLTextShape,\n\tuseEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport { getArrowBindings } from '../../shapes/arrow/shared'\n\nfunction shapesWithUnboundArrows(editor: Editor) {\n\tconst selectedShapeIds = editor.getSelectedShapeIds()\n\tconst selectedShapes = selectedShapeIds.map((id) => {\n\t\treturn editor.getShape(id)\n\t})\n\n\treturn selectedShapes.filter((shape) => {\n\t\tif (!shape) return false\n\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\tif (bindings.start || bindings.end) return false\n\t\t}\n\t\treturn true\n\t})\n}\n\n/** @internal */\nexport const useThreeStackableItems = () => {\n\tconst editor = useEditor()\n\treturn useValue('threeStackableItems', () => shapesWithUnboundArrows(editor).length > 2, [editor])\n}\n\n/** @internal */\nexport const useIsInSelectState = () => {\n\tconst editor = useEditor()\n\treturn useValue('isInSelectState', () => editor.isIn('select'), [editor])\n}\n\n/** @internal */\nexport const useAllowGroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allow group',\n\t\t() => {\n\t\t\t// We can't group arrows that are bound to shapes that aren't selected\n\t\t\t// if more than one shape has an arrow bound to it, allow group\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\n\t\t\tif (selectedShapes.length < 2) return false\n\n\t\t\tfor (const shape of selectedShapes) {\n\t\t\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\t\t\tif (bindings.start) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.start!.toId)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (bindings.end) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.end!.toId)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @internal */\nexport const useAllowUngroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allowUngroup',\n\t\t() => editor.getSelectedShapeIds().some((id) => editor.getShape(id)?.type === 'group'),\n\t\t[editor]\n\t)\n}\n\nexport const showMenuPaste =\n\ttypeof window !== 'undefined' &&\n\t'navigator' in window &&\n\tBoolean(navigator.clipboard) &&\n\tBoolean(navigator.clipboard.read)\n\n/**\n * Returns true if the number of LOCKED OR UNLOCKED selected shapes is at least min or at most max.\n */\nexport function useAnySelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor.getSelectedShapes().length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, min, max]\n\t)\n}\n\n/**\n * Returns true if the number of UNLOCKED selected shapes is at least min or at most max.\n */\nexport function useUnlockedSelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor\n\t\t\t\t.getSelectedShapes()\n\t\t\t\t.filter((s) => !editor.isShapeOrAncestorLocked(s)).length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useShowAutoSizeToggle() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'showAutoSizeToggle',\n\t\t() => {\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\t\t\treturn (\n\t\t\t\tselectedShapes.length === 1 &&\n\t\t\t\teditor.isShapeOfType<TLTextShape>(selectedShapes[0], 'text') &&\n\t\t\t\tselectedShapes[0].props.autoSize === false\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useHasLinkShapeSelected() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'hasLinkShapeSelected',\n\t\t() => {\n\t\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\t\treturn !!(\n\t\t\t\tonlySelectedShape &&\n\t\t\t\tonlySelectedShape.type !== 'embed' &&\n\t\t\t\t'url' in onlySelectedShape.props &&\n\t\t\t\t!onlySelectedShape.isLocked\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useOnlyFlippableShape() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'onlyFlippableShape',\n\t\t() => {\n\t\t\tconst shape = editor.getOnlySelectedShape()\n\t\t\treturn (\n\t\t\t\tshape &&\n\t\t\t\t(editor.isShapeOfType<TLGroupShape>(shape, 'group') ||\n\t\t\t\t\teditor.isShapeOfType<TLImageShape>(shape, 'image') ||\n\t\t\t\t\teditor.isShapeOfType<TLArrowShape>(shape, 'arrow') ||\n\t\t\t\t\teditor.isShapeOfType<TLLineShape>(shape, 'line') ||\n\t\t\t\t\teditor.isShapeOfType<TLDrawShape>(shape, 'draw'))\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @public */\nexport function useCanRedo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanRedo', () => editor.getCanRedo(), [editor])\n}\n\n/** @public */\nexport function useCanUndo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanUndo', () => editor.getCanUndo(), [editor])\n}\n"],
5
- "mappings": "AAAA;AAAA,EAQC;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB,QAAgB;AAChD,QAAM,mBAAmB,OAAO,oBAAoB;AACpD,QAAM,iBAAiB,iBAAiB,IAAI,CAAC,OAAO;AACnD,WAAO,OAAO,SAAS,EAAE;AAAA,EAC1B,CAAC;AAED,SAAO,eAAe,OAAO,CAAC,UAAU;AACvC,QAAI,CAAC,MAAO,QAAO;AACnB,QAAI,OAAO,cAA4B,OAAO,OAAO,GAAG;AACvD,YAAM,WAAW,iBAAiB,QAAQ,KAAK;AAC/C,UAAI,SAAS,SAAS,SAAS,IAAK,QAAO;AAAA,IAC5C;AACA,WAAO;AAAA,EACR,CAAC;AACF;AAGO,MAAM,yBAAyB,MAAM;AAC3C,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,uBAAuB,MAAM,wBAAwB,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,CAAC;AAClG;AAGO,MAAM,qBAAqB,MAAM;AACvC,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,mBAAmB,MAAM,OAAO,KAAK,QAAQ,GAAG,CAAC,MAAM,CAAC;AACzE;AAGO,MAAM,gBAAgB,MAAM;AAClC,QAAM,SAAS,UAAU;AACzB,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AAGL,YAAM,iBAAiB,OAAO,kBAAkB;AAEhD,UAAI,eAAe,SAAS,EAAG,QAAO;AAEtC,iBAAW,SAAS,gBAAgB;AACnC,YAAI,OAAO,cAA4B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,MAAM;AAAA,IAElD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AACD;AAGO,SAAS,aAAa;AAC5B,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,cAAc,MAAM,OAAO,WAAW,GAAG,CAAC,MAAM,CAAC;AAClE;AAGO,SAAS,aAAa;AAC5B,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,cAAc,MAAM,OAAO,WAAW,GAAG,CAAC,MAAM,CAAC;AAClE;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tTLArrowShape,\n\tTLDrawShape,\n\tTLGroupShape,\n\tTLImageShape,\n\tTLLineShape,\n\tTLTextShape,\n\tuseEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport { getArrowBindings } from '../../shapes/arrow/shared'\n\nfunction shapesWithUnboundArrows(editor: Editor) {\n\tconst selectedShapeIds = editor.getSelectedShapeIds()\n\tconst selectedShapes = selectedShapeIds.map((id) => {\n\t\treturn editor.getShape(id)\n\t})\n\n\treturn selectedShapes.filter((shape) => {\n\t\tif (!shape) return false\n\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\tif (bindings.start || bindings.end) return false\n\t\t}\n\t\treturn true\n\t})\n}\n\n/** @internal */\nexport const useThreeStackableItems = () => {\n\tconst editor = useEditor()\n\treturn useValue('threeStackableItems', () => shapesWithUnboundArrows(editor).length > 2, [editor])\n}\n\n/** @internal */\nexport const useIsInSelectState = () => {\n\tconst editor = useEditor()\n\treturn useValue('isInSelectState', () => editor.isIn('select'), [editor])\n}\n\n/** @internal */\nexport const useAllowGroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allow group',\n\t\t() => {\n\t\t\t// We can't group arrows that are bound to shapes that aren't selected\n\t\t\t// if more than one shape has an arrow bound to it, allow group\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\n\t\t\tif (selectedShapes.length < 2) return false\n\n\t\t\tfor (const shape of selectedShapes) {\n\t\t\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\t\t\tif (bindings.start) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.start!.toId)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (bindings.end) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.end!.toId)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @internal */\nexport const useAllowUngroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allowUngroup',\n\t\t() => editor.getSelectedShapeIds().some((id) => editor.getShape(id)?.type === 'group'),\n\t\t[editor]\n\t)\n}\n\nexport const showMenuPaste =\n\ttypeof window !== 'undefined' &&\n\t'navigator' in window &&\n\tBoolean(navigator.clipboard) &&\n\tBoolean(navigator.clipboard.read)\n\n/**\n * Returns true if the number of LOCKED OR UNLOCKED selected shapes is at least min or at most max.\n */\nexport function useAnySelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor.getSelectedShapes().length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, min, max]\n\t)\n}\n\n/**\n * Returns true if the number of UNLOCKED selected shapes is at least min or at most max.\n * @public\n */\nexport function useUnlockedSelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor\n\t\t\t\t.getSelectedShapes()\n\t\t\t\t.filter((s) => !editor.isShapeOrAncestorLocked(s)).length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useShowAutoSizeToggle() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'showAutoSizeToggle',\n\t\t() => {\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\t\t\treturn (\n\t\t\t\tselectedShapes.length === 1 &&\n\t\t\t\teditor.isShapeOfType<TLTextShape>(selectedShapes[0], 'text') &&\n\t\t\t\tselectedShapes[0].props.autoSize === false\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useHasLinkShapeSelected() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'hasLinkShapeSelected',\n\t\t() => {\n\t\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\t\treturn !!(\n\t\t\t\tonlySelectedShape &&\n\t\t\t\tonlySelectedShape.type !== 'embed' &&\n\t\t\t\t'url' in onlySelectedShape.props &&\n\t\t\t\t!onlySelectedShape.isLocked\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useOnlyFlippableShape() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'onlyFlippableShape',\n\t\t() => {\n\t\t\tconst shape = editor.getOnlySelectedShape()\n\t\t\treturn (\n\t\t\t\tshape &&\n\t\t\t\t(editor.isShapeOfType<TLGroupShape>(shape, 'group') ||\n\t\t\t\t\teditor.isShapeOfType<TLImageShape>(shape, 'image') ||\n\t\t\t\t\teditor.isShapeOfType<TLArrowShape>(shape, 'arrow') ||\n\t\t\t\t\teditor.isShapeOfType<TLLineShape>(shape, 'line') ||\n\t\t\t\t\teditor.isShapeOfType<TLDrawShape>(shape, 'draw'))\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @public */\nexport function useCanRedo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanRedo', () => editor.getCanRedo(), [editor])\n}\n\n/** @public */\nexport function useCanUndo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanUndo', () => editor.getCanUndo(), [editor])\n}\n"],
5
+ "mappings": "AAAA;AAAA,EAQC;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB,QAAgB;AAChD,QAAM,mBAAmB,OAAO,oBAAoB;AACpD,QAAM,iBAAiB,iBAAiB,IAAI,CAAC,OAAO;AACnD,WAAO,OAAO,SAAS,EAAE;AAAA,EAC1B,CAAC;AAED,SAAO,eAAe,OAAO,CAAC,UAAU;AACvC,QAAI,CAAC,MAAO,QAAO;AACnB,QAAI,OAAO,cAA4B,OAAO,OAAO,GAAG;AACvD,YAAM,WAAW,iBAAiB,QAAQ,KAAK;AAC/C,UAAI,SAAS,SAAS,SAAS,IAAK,QAAO;AAAA,IAC5C;AACA,WAAO;AAAA,EACR,CAAC;AACF;AAGO,MAAM,yBAAyB,MAAM;AAC3C,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,uBAAuB,MAAM,wBAAwB,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,CAAC;AAClG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AC3B,CAAC,kBAAkB;AAAA,IAErB;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AACD;AAEO,SAAS,wBAAwB;AACvC,QAAM,SAAS,UAAU;AACzB,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AACL,YAAM,QAAQ,OAAO,qBAAqB;AAC1C,aACC,UACC,OAAO,cAA4B,OAAO,OAAO,KACjD,OAAO,cAA4B,OAAO,OAAO,KACjD,OAAO,cAA4B,OAAO,OAAO,KACjD,OAAO,cAA2B,OAAO,MAAM,KAC/C,OAAO,cAA2B,OAAO,MAAM;AAAA,IAElD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AACD;AAGO,SAAS,aAAa;AAC5B,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,cAAc,MAAM,OAAO,WAAW,GAAG,CAAC,MAAM,CAAC;AAClE;AAGO,SAAS,aAAa;AAC5B,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,cAAc,MAAM,OAAO,WAAW,GAAG,CAAC,MAAM,CAAC;AAClE;",
6
6
  "names": []
7
7
  }
@@ -3,8 +3,8 @@ import {
3
3
  assert,
4
4
  compact,
5
5
  isDefined,
6
+ markEventAsHandled,
6
7
  preventDefault,
7
- stopEventPropagation,
8
8
  uniq,
9
9
  useEditor,
10
10
  useMaybeEditor,
@@ -492,7 +492,7 @@ function useNativeClipboardEvents() {
492
492
  };
493
493
  const paste = (e) => {
494
494
  if (disablingMiddleClickPaste) {
495
- stopEventPropagation(e);
495
+ markEventAsHandled(e);
496
496
  return;
497
497
  }
498
498
  if (editor.getEditingShapeId() !== null || areShortcutsDisabled(editor)) return;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/ui/hooks/useClipboardEvents.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tFileHelpers,\n\tTLExternalContentSource,\n\tVec,\n\tVecLike,\n\tassert,\n\tcompact,\n\tisDefined,\n\tpreventDefault,\n\tstopEventPropagation,\n\tuniq,\n\tuseEditor,\n\tuseMaybeEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport lz from 'lz-string'\nimport { useCallback, useEffect } from 'react'\nimport { TLDRAW_CUSTOM_PNG_MIME_TYPE, getCanonicalClipboardReadType } from '../../utils/clipboard'\nimport { TLUiEventSource, useUiEvents } from '../context/events'\nimport { pasteFiles } from './clipboard/pasteFiles'\nimport { pasteUrl } from './clipboard/pasteUrl'\n\n// Expected paste mime types. The earlier in this array they appear, the higher preference we give\n// them. For example, we prefer the `web image/png+tldraw` type to plain `image/png` as it does not\n// strip some of the extra metadata we write into it.\nconst expectedPasteFileMimeTypes = [\n\tTLDRAW_CUSTOM_PNG_MIME_TYPE,\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/svg+xml',\n] satisfies string[]\n\n/**\n * Strip HTML tags from a string.\n * @param html - The HTML to strip.\n * @internal\n */\nfunction stripHtml(html: string) {\n\t// See <https://github.com/developit/preact-markup/blob/4788b8d61b4e24f83688710746ee36e7464f7bbc/src/parse-markup.js#L60-L69>\n\tconst doc = document.implementation.createHTMLDocument('')\n\tdoc.documentElement.innerHTML = html.trim()\n\treturn doc.body.textContent || doc.body.innerText || ''\n}\n\n/** @public */\nexport const isValidHttpURL = (url: string) => {\n\ttry {\n\t\tconst u = new URL(url)\n\t\treturn u.protocol === 'http:' || u.protocol === 'https:'\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/** @public */\nconst getValidHttpURLList = (url: string) => {\n\tconst urls = url.split(/[\\n\\s]/)\n\tfor (const url of urls) {\n\t\ttry {\n\t\t\tconst u = new URL(url)\n\t\t\tif (!(u.protocol === 'http:' || u.protocol === 'https:')) {\n\t\t\t\treturn\n\t\t\t}\n\t\t} catch {\n\t\t\treturn\n\t\t}\n\t}\n\treturn uniq(urls)\n}\n\n/** @public */\nconst isSvgText = (text: string) => {\n\treturn /^<svg/.test(text)\n}\n\nconst INPUTS = ['input', 'select', 'textarea']\n\n/**\n * Get whether to disallow clipboard events.\n *\n * @internal\n */\nfunction areShortcutsDisabled(editor: Editor) {\n\tconst { activeElement } = document\n\n\treturn (\n\t\teditor.menus.hasAnyOpenMenus() ||\n\t\t(activeElement &&\n\t\t\t((activeElement as HTMLElement).isContentEditable ||\n\t\t\t\tINPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1))\n\t)\n}\n\n/**\n * Handle text pasted into the editor.\n * @param editor - The editor instance.\n * @param data - The text to paste.\n * @param point - The point at which to paste the text.\n * @internal\n */\nconst handleText = (\n\teditor: Editor,\n\tdata: string,\n\tpoint?: VecLike,\n\tsources?: TLExternalContentSource[]\n) => {\n\tconst validUrlList = getValidHttpURLList(data)\n\tif (validUrlList) {\n\t\tfor (const url of validUrlList) {\n\t\t\tpasteUrl(editor, url, point)\n\t\t}\n\t} else if (isValidHttpURL(data)) {\n\t\tpasteUrl(editor, data, point)\n\t} else if (isSvgText(data)) {\n\t\teditor.markHistoryStoppingPoint('paste')\n\t\teditor.putExternalContent({\n\t\t\ttype: 'svg-text',\n\t\t\ttext: data,\n\t\t\tpoint,\n\t\t\tsources,\n\t\t})\n\t} else {\n\t\teditor.markHistoryStoppingPoint('paste')\n\t\teditor.putExternalContent({\n\t\t\ttype: 'text',\n\t\t\ttext: data,\n\t\t\tpoint,\n\t\t\tsources,\n\t\t})\n\t}\n}\n\n/**\n * Something found on the clipboard, either through the event's clipboard data or the browser's clipboard API.\n * @internal\n */\ntype ClipboardThing =\n\t| {\n\t\t\ttype: 'file'\n\t\t\tsource: Promise<File | null>\n\t }\n\t| {\n\t\t\ttype: 'blob'\n\t\t\tsource: Promise<Blob | null>\n\t }\n\t| {\n\t\t\ttype: 'url'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: 'html'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: 'text'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: string\n\t\t\tsource: Promise<string>\n\t }\n\n/**\n * Handle a paste using event clipboard data. This is the \"original\"\n * paste method that uses the clipboard data from the paste event.\n * https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboardData\n *\n * @param editor - The editor\n * @param clipboardData - The clipboard data\n * @param point - The point to paste at\n * @internal\n */\nconst handlePasteFromEventClipboardData = async (\n\teditor: Editor,\n\tclipboardData: DataTransfer,\n\tpoint?: VecLike\n) => {\n\t// Do not paste while in any editing state\n\tif (editor.getEditingShapeId() !== null) return\n\n\tif (!clipboardData) {\n\t\tthrow Error('No clipboard data')\n\t}\n\n\tconst things: ClipboardThing[] = []\n\n\tfor (const item of Object.values(clipboardData.items)) {\n\t\tswitch (item.kind) {\n\t\t\tcase 'file': {\n\t\t\t\t// files are always blobs\n\t\t\t\tthings.push({\n\t\t\t\t\ttype: 'file',\n\t\t\t\t\tsource: new Promise((r) => r(item.getAsFile())) as Promise<File | null>,\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'string': {\n\t\t\t\t// strings can be text or html\n\t\t\t\tif (item.type === 'text/html') {\n\t\t\t\t\tthings.push({\n\t\t\t\t\t\ttype: 'html',\n\t\t\t\t\t\tsource: new Promise((r) => item.getAsString(r)) as Promise<string>,\n\t\t\t\t\t})\n\t\t\t\t} else if (item.type === 'text/plain') {\n\t\t\t\t\tthings.push({\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\tsource: new Promise((r) => item.getAsString(r)) as Promise<string>,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthings.push({ type: item.type, source: new Promise((r) => item.getAsString(r)) })\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\thandleClipboardThings(editor, things, point)\n}\n\n/**\n * Handle a paste using items retrieved from the Clipboard API.\n * https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem\n *\n * @param editor - The editor\n * @param clipboardItems - The clipboard items to handle\n * @param point - The point to paste at\n * @internal\n */\nconst handlePasteFromClipboardApi = async ({\n\teditor,\n\tclipboardItems,\n\tpoint,\n\tfallbackFiles,\n}: {\n\teditor: Editor\n\tclipboardItems: ClipboardItem[]\n\tpoint?: VecLike\n\tfallbackFiles?: File[]\n}) => {\n\t// We need to populate the array of clipboard things\n\t// based on the ClipboardItems from the Clipboard API.\n\t// This is done in a different way than when using\n\t// the clipboard data from the paste event.\n\n\tconst things: ClipboardThing[] = []\n\n\tfor (const item of clipboardItems) {\n\t\tfor (const type of expectedPasteFileMimeTypes) {\n\t\t\tif (item.types.includes(type)) {\n\t\t\t\tconst blobPromise = item\n\t\t\t\t\t.getType(type)\n\t\t\t\t\t.then((blob) => FileHelpers.rewriteMimeType(blob, getCanonicalClipboardReadType(type)))\n\t\t\t\tthings.push({\n\t\t\t\t\ttype: 'blob',\n\t\t\t\t\tsource: blobPromise,\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (item.types.includes('text/html')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'html',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/html')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\n\t\tif (item.types.includes('text/uri-list')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'url',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/uri-list')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\n\t\tif (item.types.includes('text/plain')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'text',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/plain')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\t}\n\n\tif (fallbackFiles?.length && things.length === 1 && things[0].type === 'text') {\n\t\tthings.pop()\n\t\tthings.push(\n\t\t\t...fallbackFiles.map((f): ClipboardThing => ({ type: 'file', source: Promise.resolve(f) }))\n\t\t)\n\t} else if (fallbackFiles?.length && things.length === 0) {\n\t\t// Files pasted in Safari from your computer don't have types, so we need to use the fallback files directly\n\t\t// if they're available. This only works if pasted keyboard shortcuts. Pasting from the menu in Safari seems to never\n\t\t// let you access files that are copied from your computer.\n\t\tthings.push(\n\t\t\t...fallbackFiles.map((f): ClipboardThing => ({ type: 'file', source: Promise.resolve(f) }))\n\t\t)\n\t}\n\n\treturn await handleClipboardThings(editor, things, point)\n}\n\nasync function handleClipboardThings(editor: Editor, things: ClipboardThing[], point?: VecLike) {\n\t// 1. Handle files\n\t//\n\t// We need to handle files separately because if we want them to\n\t// be placed next to each other, we need to create them all at once.\n\n\tconst files = things.filter(\n\t\t(t) => (t.type === 'file' || t.type === 'blob') && t.source !== null\n\t) as Extract<ClipboardThing, { type: 'file' } | { type: 'blob' }>[]\n\n\t// Just paste the files, nothing else\n\tif (files.length) {\n\t\tif (files.length > editor.options.maxFilesAtOnce) {\n\t\t\tthrow Error('Too many files')\n\t\t}\n\t\tconst fileBlobs = compact(await Promise.all(files.map((t) => t.source)))\n\t\treturn await pasteFiles(editor, fileBlobs, point)\n\t}\n\n\t// 2. Generate clipboard results for non-file things\n\t//\n\t// Getting the source from the items is async, however they must be accessed syncronously;\n\t// we can't await them in a loop. So we'll map them to promises and await them all at once,\n\t// then make decisions based on what we find.\n\n\tconst results = await Promise.all<TLExternalContentSource>(\n\t\tthings\n\t\t\t.filter((t) => t.type !== 'file')\n\t\t\t.map(\n\t\t\t\t(t) =>\n\t\t\t\t\tnew Promise((r) => {\n\t\t\t\t\t\tconst thing = t as Exclude<ClipboardThing, { type: 'file' } | { type: 'blob' }>\n\n\t\t\t\t\t\tif (thing.type === 'file') {\n\t\t\t\t\t\t\tr({ type: 'error', data: null, reason: 'unexpected file' })\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthing.source.then((text) => {\n\t\t\t\t\t\t\t// first, see if we can find tldraw content, which is JSON inside of an html comment\n\t\t\t\t\t\t\tconst tldrawHtmlComment = text.match(/<div data-tldraw[^>]*>(.*)<\\/div>/)?.[1]\n\n\t\t\t\t\t\t\tif (tldrawHtmlComment) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t// First try parsing as plain JSON (version 2/3 formats)\n\t\t\t\t\t\t\t\t\tlet json\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tjson = JSON.parse(tldrawHtmlComment)\n\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t// Fall back to LZ decompression (legacy format)\n\t\t\t\t\t\t\t\t\t\tconst jsonComment = lz.decompressFromBase64(tldrawHtmlComment)\n\t\t\t\t\t\t\t\t\t\tif (jsonComment === null) {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\treason: `found tldraw data comment but could not parse`,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tjson = JSON.parse(jsonComment)\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tif (json.type !== 'application/tldraw') {\n\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\treason: `found tldraw data comment but JSON was of a different type: ${json.type}`,\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Handle versioned clipboard format\n\t\t\t\t\t\t\t\t\tif (json.version === 3) {\n\t\t\t\t\t\t\t\t\t\t// Version 3: Assets are plain, decompress only other data\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tconst otherData = JSON.parse(\n\t\t\t\t\t\t\t\t\t\t\t\tlz.decompressFromBase64(json.data.otherCompressed) || '{}'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst reconstructedData = {\n\t\t\t\t\t\t\t\t\t\t\t\tassets: json.data.assets || [],\n\t\t\t\t\t\t\t\t\t\t\t\t...otherData,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: reconstructedData })\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\t\treason: `failed to decompress version 2 clipboard data: ${error}`,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (json.version === 2) {\n\t\t\t\t\t\t\t\t\t\t// Version 2: Everything is plain, this had issues with encoding... :-/\n\t\t\t\t\t\t\t\t\t\t// TODO: nix this support after some time.\n\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: json.data })\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// Version 1 or no version: Legacy format\n\t\t\t\t\t\t\t\t\t\tif (typeof json.data === 'string') {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\t\t\t\t\t\t'found tldraw json but data was a string instead of a TLClipboardModel object',\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: json.data })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\tdata: tldrawHtmlComment,\n\t\t\t\t\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\t\t\t\t'found tldraw json but data was a string instead of a TLClipboardModel object',\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tif (thing.type === 'html') {\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'html' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (thing.type === 'url') {\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'url' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// if we have not found a tldraw comment, Otherwise, try to parse the text as JSON directly.\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(text)\n\t\t\t\t\t\t\t\t\tif (json.type === 'excalidraw/clipboard') {\n\t\t\t\t\t\t\t\t\t\t// If the clipboard contains content copied from excalidraw, then paste that\n\t\t\t\t\t\t\t\t\t\tr({ type: 'excalidraw', data: json })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'json' })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t// If we could not parse the text as JSON, then it's just text\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'text' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tr({ type: 'error', data: text, reason: 'unhandled case' })\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t)\n\t)\n\n\t// 3.\n\t//\n\t// Now that we know what kind of stuff we're dealing with, we can actual create some content.\n\t// There are priorities here, so order matters: we've already handled images and files, which\n\t// take first priority; then we want to handle tldraw content, then excalidraw content, then\n\t// html content, then links, and finally text content.\n\n\t// Try to paste tldraw content\n\tfor (const result of results) {\n\t\tif (result.type === 'tldraw') {\n\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\teditor.putExternalContent({ type: 'tldraw', content: result.data, point })\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Try to paste excalidraw content\n\tfor (const result of results) {\n\t\tif (result.type === 'excalidraw') {\n\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\teditor.putExternalContent({ type: 'excalidraw', content: result.data, point })\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Try to paste html content\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'html') {\n\t\t\t// try to find a link\n\t\t\tconst rootNode = new DOMParser().parseFromString(result.data, 'text/html')\n\t\t\tconst bodyNode = rootNode.querySelector('body')\n\n\t\t\t// Edge on Windows 11 home appears to paste a link as a single <a/> in\n\t\t\t// the HTML document. If we're pasting a single like tag we'll just\n\t\t\t// assume the user meant to paste the URL.\n\t\t\tconst isHtmlSingleLink =\n\t\t\t\tbodyNode &&\n\t\t\t\tArray.from(bodyNode.children).filter((el) => el.nodeType === 1).length === 1 &&\n\t\t\t\tbodyNode.firstElementChild &&\n\t\t\t\tbodyNode.firstElementChild.tagName === 'A' &&\n\t\t\t\tbodyNode.firstElementChild.hasAttribute('href') &&\n\t\t\t\tbodyNode.firstElementChild.getAttribute('href') !== ''\n\n\t\t\tif (isHtmlSingleLink) {\n\t\t\t\tconst href = bodyNode.firstElementChild.getAttribute('href')!\n\t\t\t\thandleText(editor, href, point, results)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// If the html is NOT a link, and we have NO OTHER texty content, then paste the html as text\n\t\t\tif (!results.some((r) => r.type === 'text' && r.subtype !== 'html') && result.data.trim()) {\n\t\t\t\tconst html = stripHtml(result.data) ?? ''\n\t\t\t\tif (html) {\n\t\t\t\t\thandleText(editor, stripHtml(result.data), point, results)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the html is NOT a link, and we have other texty content, then paste the html as a text shape\n\t\t\tif (results.some((r) => r.type === 'text' && r.subtype !== 'html')) {\n\t\t\t\tconst html = stripHtml(result.data) ?? ''\n\t\t\t\tif (html) {\n\t\t\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\t\t\teditor.putExternalContent({\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: html,\n\t\t\t\t\t\thtml: result.data,\n\t\t\t\t\t\tpoint,\n\t\t\t\t\t\tsources: results,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Allow you to paste YouTube or Google Maps embeds, for example.\n\t\tif (result.type === 'text' && result.subtype === 'text' && result.data.startsWith('<iframe ')) {\n\t\t\t// try to find an iframe\n\t\t\tconst rootNode = new DOMParser().parseFromString(result.data, 'text/html')\n\t\t\tconst bodyNode = rootNode.querySelector('body')\n\n\t\t\tconst isSingleIframe =\n\t\t\t\tbodyNode &&\n\t\t\t\tArray.from(bodyNode.children).filter((el) => el.nodeType === 1).length === 1 &&\n\t\t\t\tbodyNode.firstElementChild &&\n\t\t\t\tbodyNode.firstElementChild.tagName === 'IFRAME' &&\n\t\t\t\tbodyNode.firstElementChild.hasAttribute('src') &&\n\t\t\t\tbodyNode.firstElementChild.getAttribute('src') !== ''\n\n\t\t\tif (isSingleIframe) {\n\t\t\t\tconst src = bodyNode.firstElementChild.getAttribute('src')!\n\t\t\t\thandleText(editor, src, point, results)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\t// Try to paste a link\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'url') {\n\t\t\tpasteUrl(editor, result.data, point, results)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Finally, if we haven't bailed on anything yet, we can paste text content\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'text' && result.data.trim()) {\n\t\t\t// The clipboard may include multiple text items, but we only want to paste the first one\n\t\t\thandleText(editor, result.data, point, results)\n\t\t\treturn\n\t\t}\n\t}\n}\n\n/**\n * When the user copies, write the contents to local storage and to the clipboard\n *\n * @param editor - The editor instance.\n * @public\n */\nconst handleNativeOrMenuCopy = async (editor: Editor) => {\n\tconst content = await editor.resolveAssetsInContent(\n\t\teditor.getContentFromCurrentPage(editor.getSelectedShapeIds())\n\t)\n\tif (!content) {\n\t\tif (navigator && navigator.clipboard) {\n\t\t\tnavigator.clipboard.writeText('')\n\t\t}\n\t\treturn\n\t}\n\n\t// Use versioned clipboard format for better compression\n\t// Version 3: Don't compress assets, only compress other data\n\tconst { assets, ...otherData } = content\n\tconst clipboardData = {\n\t\ttype: 'application/tldraw',\n\t\tkind: 'content',\n\t\tversion: 3,\n\t\tdata: {\n\t\t\tassets: assets || [], // Plain JSON, no compression\n\t\t\totherCompressed: lz.compressToBase64(JSON.stringify(otherData)), // Only compress non-asset data\n\t\t},\n\t}\n\n\t// Don't compress the final structure - just use plain JSON\n\tconst stringifiedClipboard = JSON.stringify(clipboardData)\n\n\tif (typeof navigator === 'undefined') {\n\t\treturn\n\t} else {\n\t\t// Extract the text from the clipboard\n\t\tconst textItems = content.shapes\n\t\t\t.map((shape) => {\n\t\t\t\tconst util = editor.getShapeUtil(shape)\n\t\t\t\treturn util.getText(shape)\n\t\t\t})\n\t\t\t.filter(isDefined)\n\n\t\tif (navigator.clipboard?.write) {\n\t\t\tconst htmlBlob = new Blob([`<div data-tldraw>${stringifiedClipboard}</div>`], {\n\t\t\t\ttype: 'text/html',\n\t\t\t})\n\n\t\t\tlet textContent = textItems.join(' ')\n\n\t\t\t// This is a bug in chrome android where it won't paste content if\n\t\t\t// the text/plain content is \"\" so we need to always add an empty\n\t\t\t// space \uD83E\uDD2C\n\t\t\tif (textContent === '') {\n\t\t\t\ttextContent = ' '\n\t\t\t}\n\n\t\t\tnavigator.clipboard.write([\n\t\t\t\tnew ClipboardItem({\n\t\t\t\t\t'text/html': htmlBlob,\n\t\t\t\t\t// What is this second blob used for?\n\t\t\t\t\t'text/plain': new Blob([textContent], { type: 'text/plain' }),\n\t\t\t\t}),\n\t\t\t])\n\t\t} else if (navigator.clipboard.writeText) {\n\t\t\tnavigator.clipboard.writeText(`<div data-tldraw>${stringifiedClipboard}</div>`)\n\t\t}\n\t}\n}\n\n/** @public */\nexport function useMenuClipboardEvents() {\n\tconst editor = useMaybeEditor()\n\tconst trackEvent = useUiEvents()\n\n\tconst copy = useCallback(\n\t\tasync function onCopy(source: TLUiEventSource) {\n\t\t\tassert(editor, 'editor is required for copy')\n\t\t\tif (editor.getSelectedShapeIds().length === 0) return\n\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\ttrackEvent('copy', { source })\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\tconst cut = useCallback(\n\t\tasync function onCut(source: TLUiEventSource) {\n\t\t\tif (!editor) return\n\t\t\tif (editor.getSelectedShapeIds().length === 0) return\n\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\teditor.deleteShapes(editor.getSelectedShapeIds())\n\t\t\ttrackEvent('cut', { source })\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\tconst paste = useCallback(\n\t\tasync function onPaste(\n\t\t\tdata: DataTransfer | ClipboardItem[],\n\t\t\tsource: TLUiEventSource,\n\t\t\tpoint?: VecLike\n\t\t) {\n\t\t\tif (!editor) return\n\t\t\t// If we're editing a shape, or we are focusing an editable input, then\n\t\t\t// we would want the user's paste interaction to go to that element or\n\t\t\t// input instead; e.g. when pasting text into a text shape's content\n\t\t\tif (editor.getEditingShapeId() !== null) return\n\n\t\t\tif (Array.isArray(data) && data[0] instanceof ClipboardItem) {\n\t\t\t\thandlePasteFromClipboardApi({ editor, clipboardItems: data, point })\n\t\t\t\ttrackEvent('paste', { source: 'menu' })\n\t\t\t} else {\n\t\t\t\t// Read it first and then recurse, kind of weird\n\t\t\t\tnavigator.clipboard.read().then((clipboardItems) => {\n\t\t\t\t\tpaste(clipboardItems, source, point)\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\treturn {\n\t\tcopy,\n\t\tcut,\n\t\tpaste,\n\t}\n}\n\n/** @public */\nexport function useNativeClipboardEvents() {\n\tconst editor = useEditor()\n\tconst trackEvent = useUiEvents()\n\n\tconst appIsFocused = useValue('editor.isFocused', () => editor.getInstanceState().isFocused, [\n\t\teditor,\n\t])\n\n\tuseEffect(() => {\n\t\tif (!appIsFocused) return\n\t\tconst copy = async (e: ClipboardEvent) => {\n\t\t\tif (\n\t\t\t\teditor.getSelectedShapeIds().length === 0 ||\n\t\t\t\teditor.getEditingShapeId() !== null ||\n\t\t\t\tareShortcutsDisabled(editor)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\ttrackEvent('copy', { source: 'kbd' })\n\t\t}\n\n\t\tasync function cut(e: ClipboardEvent) {\n\t\t\tif (\n\t\t\t\teditor.getSelectedShapeIds().length === 0 ||\n\t\t\t\teditor.getEditingShapeId() !== null ||\n\t\t\t\tareShortcutsDisabled(editor)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tpreventDefault(e)\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\teditor.deleteShapes(editor.getSelectedShapeIds())\n\t\t\ttrackEvent('cut', { source: 'kbd' })\n\t\t}\n\n\t\tlet disablingMiddleClickPaste = false\n\t\tconst pointerUpHandler = (e: PointerEvent) => {\n\t\t\tif (e.button === 1) {\n\t\t\t\t// middle mouse button\n\t\t\t\tdisablingMiddleClickPaste = true\n\t\t\t\teditor.timers.requestAnimationFrame(() => {\n\t\t\t\t\tdisablingMiddleClickPaste = false\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tconst paste = (e: ClipboardEvent) => {\n\t\t\tif (disablingMiddleClickPaste) {\n\t\t\t\tstopEventPropagation(e)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// If we're editing a shape, or we are focusing an editable input, then\n\t\t\t// we would want the user's paste interaction to go to that element or\n\t\t\t// input instead; e.g. when pasting text into a text shape's content\n\t\t\tif (editor.getEditingShapeId() !== null || areShortcutsDisabled(editor)) return\n\n\t\t\t// Where should the shapes go?\n\t\t\tlet point: Vec | undefined = undefined\n\t\t\tlet pasteAtCursor = false\n\n\t\t\t// | Shiftkey | Paste at cursor mode | Paste at point? |\n\t\t\t// | N \t\t| N | N \t\t\t\t |\n\t\t\t// | Y \t\t| N | Y \t\t\t\t |\n\t\t\t// | N \t\t| Y | Y \t\t\t\t |\n\t\t\t// | Y \t\t| Y | N \t\t\t\t |\n\t\t\tif (editor.inputs.shiftKey) pasteAtCursor = true\n\t\t\tif (editor.user.getIsPasteAtCursorMode()) pasteAtCursor = !pasteAtCursor\n\t\t\tif (pasteAtCursor) point = editor.inputs.currentPagePoint\n\n\t\t\tconst pasteFromEvent = () => {\n\t\t\t\tif (e.clipboardData) {\n\t\t\t\t\thandlePasteFromEventClipboardData(editor, e.clipboardData, point)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if we can read from the clipboard API, we want to try using that first. that allows\n\t\t\t// us to access most things, and doesn't strip out metadata added to tldraw's own\n\t\t\t// copy-as-png features - so copied shapes come back in at the correct size.\n\t\t\tif (navigator.clipboard?.read) {\n\t\t\t\t// We can't read files from the filesystem using the clipboard API though - they'll\n\t\t\t\t// just come in as the file names instead. So we'll use the clipboard event's files\n\t\t\t\t// as a fallback - if we only got text, but do have files, we use those instead.\n\t\t\t\tconst fallbackFiles = Array.from(e.clipboardData?.files || [])\n\t\t\t\tnavigator.clipboard.read().then(\n\t\t\t\t\t(clipboardItems) => {\n\t\t\t\t\t\tif (Array.isArray(clipboardItems) && clipboardItems[0] instanceof ClipboardItem) {\n\t\t\t\t\t\t\thandlePasteFromClipboardApi({ editor, clipboardItems, point, fallbackFiles })\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\t// if reading from the clipboard fails, try to use the event clipboard data\n\t\t\t\t\t\tpasteFromEvent()\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tpasteFromEvent()\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\ttrackEvent('paste', { source: 'kbd' })\n\t\t}\n\n\t\tdocument.addEventListener('copy', copy)\n\t\tdocument.addEventListener('cut', cut)\n\t\tdocument.addEventListener('paste', paste)\n\t\tdocument.addEventListener('pointerup', pointerUpHandler)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('copy', copy)\n\t\t\tdocument.removeEventListener('cut', cut)\n\t\t\tdocument.removeEventListener('paste', paste)\n\t\t\tdocument.removeEventListener('pointerup', pointerUpHandler)\n\t\t}\n\t}, [editor, trackEvent, appIsFocused])\n}\n"],
5
- "mappings": "AAAA;AAAA,EAEC;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,QAAQ;AACf,SAAS,aAAa,iBAAiB;AACvC,SAAS,6BAA6B,qCAAqC;AAC3E,SAA0B,mBAAmB;AAC7C,SAAS,kBAAkB;AA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B,aAAa,gBAAgB;AAEvD,WAAO,MAAM;AACZ,eAAS,oBAAoB,QAAQ,IAAI;AACzC,eAAS,oBAAoB,OAAO,GAAG;AACvC,eAAS,oBAAoB,SAAS,KAAK;AAC3C,eAAS,oBAAoB,aAAa,gBAAgB;AAAA,IAC3D;AAAA,EACD,GAAG,CAAC,QAAQ,YAAY,YAAY,CAAC;AACtC;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tFileHelpers,\n\tTLExternalContentSource,\n\tVec,\n\tVecLike,\n\tassert,\n\tcompact,\n\tisDefined,\n\tmarkEventAsHandled,\n\tpreventDefault,\n\tuniq,\n\tuseEditor,\n\tuseMaybeEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport lz from 'lz-string'\nimport { useCallback, useEffect } from 'react'\nimport { TLDRAW_CUSTOM_PNG_MIME_TYPE, getCanonicalClipboardReadType } from '../../utils/clipboard'\nimport { TLUiEventSource, useUiEvents } from '../context/events'\nimport { pasteFiles } from './clipboard/pasteFiles'\nimport { pasteUrl } from './clipboard/pasteUrl'\n\n// Expected paste mime types. The earlier in this array they appear, the higher preference we give\n// them. For example, we prefer the `web image/png+tldraw` type to plain `image/png` as it does not\n// strip some of the extra metadata we write into it.\nconst expectedPasteFileMimeTypes = [\n\tTLDRAW_CUSTOM_PNG_MIME_TYPE,\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/svg+xml',\n] satisfies string[]\n\n/**\n * Strip HTML tags from a string.\n * @param html - The HTML to strip.\n * @internal\n */\nfunction stripHtml(html: string) {\n\t// See <https://github.com/developit/preact-markup/blob/4788b8d61b4e24f83688710746ee36e7464f7bbc/src/parse-markup.js#L60-L69>\n\tconst doc = document.implementation.createHTMLDocument('')\n\tdoc.documentElement.innerHTML = html.trim()\n\treturn doc.body.textContent || doc.body.innerText || ''\n}\n\n/** @public */\nexport const isValidHttpURL = (url: string) => {\n\ttry {\n\t\tconst u = new URL(url)\n\t\treturn u.protocol === 'http:' || u.protocol === 'https:'\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/** @public */\nconst getValidHttpURLList = (url: string) => {\n\tconst urls = url.split(/[\\n\\s]/)\n\tfor (const url of urls) {\n\t\ttry {\n\t\t\tconst u = new URL(url)\n\t\t\tif (!(u.protocol === 'http:' || u.protocol === 'https:')) {\n\t\t\t\treturn\n\t\t\t}\n\t\t} catch {\n\t\t\treturn\n\t\t}\n\t}\n\treturn uniq(urls)\n}\n\n/** @public */\nconst isSvgText = (text: string) => {\n\treturn /^<svg/.test(text)\n}\n\nconst INPUTS = ['input', 'select', 'textarea']\n\n/**\n * Get whether to disallow clipboard events.\n *\n * @internal\n */\nfunction areShortcutsDisabled(editor: Editor) {\n\tconst { activeElement } = document\n\n\treturn (\n\t\teditor.menus.hasAnyOpenMenus() ||\n\t\t(activeElement &&\n\t\t\t((activeElement as HTMLElement).isContentEditable ||\n\t\t\t\tINPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1))\n\t)\n}\n\n/**\n * Handle text pasted into the editor.\n * @param editor - The editor instance.\n * @param data - The text to paste.\n * @param point - The point at which to paste the text.\n * @internal\n */\nconst handleText = (\n\teditor: Editor,\n\tdata: string,\n\tpoint?: VecLike,\n\tsources?: TLExternalContentSource[]\n) => {\n\tconst validUrlList = getValidHttpURLList(data)\n\tif (validUrlList) {\n\t\tfor (const url of validUrlList) {\n\t\t\tpasteUrl(editor, url, point)\n\t\t}\n\t} else if (isValidHttpURL(data)) {\n\t\tpasteUrl(editor, data, point)\n\t} else if (isSvgText(data)) {\n\t\teditor.markHistoryStoppingPoint('paste')\n\t\teditor.putExternalContent({\n\t\t\ttype: 'svg-text',\n\t\t\ttext: data,\n\t\t\tpoint,\n\t\t\tsources,\n\t\t})\n\t} else {\n\t\teditor.markHistoryStoppingPoint('paste')\n\t\teditor.putExternalContent({\n\t\t\ttype: 'text',\n\t\t\ttext: data,\n\t\t\tpoint,\n\t\t\tsources,\n\t\t})\n\t}\n}\n\n/**\n * Something found on the clipboard, either through the event's clipboard data or the browser's clipboard API.\n * @internal\n */\ntype ClipboardThing =\n\t| {\n\t\t\ttype: 'file'\n\t\t\tsource: Promise<File | null>\n\t }\n\t| {\n\t\t\ttype: 'blob'\n\t\t\tsource: Promise<Blob | null>\n\t }\n\t| {\n\t\t\ttype: 'url'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: 'html'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: 'text'\n\t\t\tsource: Promise<string>\n\t }\n\t| {\n\t\t\ttype: string\n\t\t\tsource: Promise<string>\n\t }\n\n/**\n * Handle a paste using event clipboard data. This is the \"original\"\n * paste method that uses the clipboard data from the paste event.\n * https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboardData\n *\n * @param editor - The editor\n * @param clipboardData - The clipboard data\n * @param point - The point to paste at\n * @internal\n */\nconst handlePasteFromEventClipboardData = async (\n\teditor: Editor,\n\tclipboardData: DataTransfer,\n\tpoint?: VecLike\n) => {\n\t// Do not paste while in any editing state\n\tif (editor.getEditingShapeId() !== null) return\n\n\tif (!clipboardData) {\n\t\tthrow Error('No clipboard data')\n\t}\n\n\tconst things: ClipboardThing[] = []\n\n\tfor (const item of Object.values(clipboardData.items)) {\n\t\tswitch (item.kind) {\n\t\t\tcase 'file': {\n\t\t\t\t// files are always blobs\n\t\t\t\tthings.push({\n\t\t\t\t\ttype: 'file',\n\t\t\t\t\tsource: new Promise((r) => r(item.getAsFile())) as Promise<File | null>,\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'string': {\n\t\t\t\t// strings can be text or html\n\t\t\t\tif (item.type === 'text/html') {\n\t\t\t\t\tthings.push({\n\t\t\t\t\t\ttype: 'html',\n\t\t\t\t\t\tsource: new Promise((r) => item.getAsString(r)) as Promise<string>,\n\t\t\t\t\t})\n\t\t\t\t} else if (item.type === 'text/plain') {\n\t\t\t\t\tthings.push({\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\tsource: new Promise((r) => item.getAsString(r)) as Promise<string>,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthings.push({ type: item.type, source: new Promise((r) => item.getAsString(r)) })\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\thandleClipboardThings(editor, things, point)\n}\n\n/**\n * Handle a paste using items retrieved from the Clipboard API.\n * https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem\n *\n * @param editor - The editor\n * @param clipboardItems - The clipboard items to handle\n * @param point - The point to paste at\n * @internal\n */\nconst handlePasteFromClipboardApi = async ({\n\teditor,\n\tclipboardItems,\n\tpoint,\n\tfallbackFiles,\n}: {\n\teditor: Editor\n\tclipboardItems: ClipboardItem[]\n\tpoint?: VecLike\n\tfallbackFiles?: File[]\n}) => {\n\t// We need to populate the array of clipboard things\n\t// based on the ClipboardItems from the Clipboard API.\n\t// This is done in a different way than when using\n\t// the clipboard data from the paste event.\n\n\tconst things: ClipboardThing[] = []\n\n\tfor (const item of clipboardItems) {\n\t\tfor (const type of expectedPasteFileMimeTypes) {\n\t\t\tif (item.types.includes(type)) {\n\t\t\t\tconst blobPromise = item\n\t\t\t\t\t.getType(type)\n\t\t\t\t\t.then((blob) => FileHelpers.rewriteMimeType(blob, getCanonicalClipboardReadType(type)))\n\t\t\t\tthings.push({\n\t\t\t\t\ttype: 'blob',\n\t\t\t\t\tsource: blobPromise,\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (item.types.includes('text/html')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'html',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/html')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\n\t\tif (item.types.includes('text/uri-list')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'url',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/uri-list')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\n\t\tif (item.types.includes('text/plain')) {\n\t\t\tthings.push({\n\t\t\t\ttype: 'text',\n\t\t\t\tsource: (async () => {\n\t\t\t\t\tconst blob = await item.getType('text/plain')\n\t\t\t\t\treturn await FileHelpers.blobToText(blob)\n\t\t\t\t})(),\n\t\t\t})\n\t\t}\n\t}\n\n\tif (fallbackFiles?.length && things.length === 1 && things[0].type === 'text') {\n\t\tthings.pop()\n\t\tthings.push(\n\t\t\t...fallbackFiles.map((f): ClipboardThing => ({ type: 'file', source: Promise.resolve(f) }))\n\t\t)\n\t} else if (fallbackFiles?.length && things.length === 0) {\n\t\t// Files pasted in Safari from your computer don't have types, so we need to use the fallback files directly\n\t\t// if they're available. This only works if pasted keyboard shortcuts. Pasting from the menu in Safari seems to never\n\t\t// let you access files that are copied from your computer.\n\t\tthings.push(\n\t\t\t...fallbackFiles.map((f): ClipboardThing => ({ type: 'file', source: Promise.resolve(f) }))\n\t\t)\n\t}\n\n\treturn await handleClipboardThings(editor, things, point)\n}\n\nasync function handleClipboardThings(editor: Editor, things: ClipboardThing[], point?: VecLike) {\n\t// 1. Handle files\n\t//\n\t// We need to handle files separately because if we want them to\n\t// be placed next to each other, we need to create them all at once.\n\n\tconst files = things.filter(\n\t\t(t) => (t.type === 'file' || t.type === 'blob') && t.source !== null\n\t) as Extract<ClipboardThing, { type: 'file' } | { type: 'blob' }>[]\n\n\t// Just paste the files, nothing else\n\tif (files.length) {\n\t\tif (files.length > editor.options.maxFilesAtOnce) {\n\t\t\tthrow Error('Too many files')\n\t\t}\n\t\tconst fileBlobs = compact(await Promise.all(files.map((t) => t.source)))\n\t\treturn await pasteFiles(editor, fileBlobs, point)\n\t}\n\n\t// 2. Generate clipboard results for non-file things\n\t//\n\t// Getting the source from the items is async, however they must be accessed syncronously;\n\t// we can't await them in a loop. So we'll map them to promises and await them all at once,\n\t// then make decisions based on what we find.\n\n\tconst results = await Promise.all<TLExternalContentSource>(\n\t\tthings\n\t\t\t.filter((t) => t.type !== 'file')\n\t\t\t.map(\n\t\t\t\t(t) =>\n\t\t\t\t\tnew Promise((r) => {\n\t\t\t\t\t\tconst thing = t as Exclude<ClipboardThing, { type: 'file' } | { type: 'blob' }>\n\n\t\t\t\t\t\tif (thing.type === 'file') {\n\t\t\t\t\t\t\tr({ type: 'error', data: null, reason: 'unexpected file' })\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthing.source.then((text) => {\n\t\t\t\t\t\t\t// first, see if we can find tldraw content, which is JSON inside of an html comment\n\t\t\t\t\t\t\tconst tldrawHtmlComment = text.match(/<div data-tldraw[^>]*>(.*)<\\/div>/)?.[1]\n\n\t\t\t\t\t\t\tif (tldrawHtmlComment) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t// First try parsing as plain JSON (version 2/3 formats)\n\t\t\t\t\t\t\t\t\tlet json\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tjson = JSON.parse(tldrawHtmlComment)\n\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t// Fall back to LZ decompression (legacy format)\n\t\t\t\t\t\t\t\t\t\tconst jsonComment = lz.decompressFromBase64(tldrawHtmlComment)\n\t\t\t\t\t\t\t\t\t\tif (jsonComment === null) {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\treason: `found tldraw data comment but could not parse`,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tjson = JSON.parse(jsonComment)\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tif (json.type !== 'application/tldraw') {\n\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\treason: `found tldraw data comment but JSON was of a different type: ${json.type}`,\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Handle versioned clipboard format\n\t\t\t\t\t\t\t\t\tif (json.version === 3) {\n\t\t\t\t\t\t\t\t\t\t// Version 3: Assets are plain, decompress only other data\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tconst otherData = JSON.parse(\n\t\t\t\t\t\t\t\t\t\t\t\tlz.decompressFromBase64(json.data.otherCompressed) || '{}'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst reconstructedData = {\n\t\t\t\t\t\t\t\t\t\t\t\tassets: json.data.assets || [],\n\t\t\t\t\t\t\t\t\t\t\t\t...otherData,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: reconstructedData })\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\t\treason: `failed to decompress version 2 clipboard data: ${error}`,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (json.version === 2) {\n\t\t\t\t\t\t\t\t\t\t// Version 2: Everything is plain, this had issues with encoding... :-/\n\t\t\t\t\t\t\t\t\t\t// TODO: nix this support after some time.\n\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: json.data })\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// Version 1 or no version: Legacy format\n\t\t\t\t\t\t\t\t\t\tif (typeof json.data === 'string') {\n\t\t\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\t\t\tdata: json,\n\t\t\t\t\t\t\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\t\t\t\t\t\t'found tldraw json but data was a string instead of a TLClipboardModel object',\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tr({ type: 'tldraw', data: json.data })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tr({\n\t\t\t\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\t\t\t\tdata: tldrawHtmlComment,\n\t\t\t\t\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\t\t\t\t'found tldraw json but data was a string instead of a TLClipboardModel object',\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tif (thing.type === 'html') {\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'html' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (thing.type === 'url') {\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'url' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// if we have not found a tldraw comment, Otherwise, try to parse the text as JSON directly.\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(text)\n\t\t\t\t\t\t\t\t\tif (json.type === 'excalidraw/clipboard') {\n\t\t\t\t\t\t\t\t\t\t// If the clipboard contains content copied from excalidraw, then paste that\n\t\t\t\t\t\t\t\t\t\tr({ type: 'excalidraw', data: json })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'json' })\n\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t// If we could not parse the text as JSON, then it's just text\n\t\t\t\t\t\t\t\t\tr({ type: 'text', data: text, subtype: 'text' })\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tr({ type: 'error', data: text, reason: 'unhandled case' })\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t)\n\t)\n\n\t// 3.\n\t//\n\t// Now that we know what kind of stuff we're dealing with, we can actual create some content.\n\t// There are priorities here, so order matters: we've already handled images and files, which\n\t// take first priority; then we want to handle tldraw content, then excalidraw content, then\n\t// html content, then links, and finally text content.\n\n\t// Try to paste tldraw content\n\tfor (const result of results) {\n\t\tif (result.type === 'tldraw') {\n\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\teditor.putExternalContent({ type: 'tldraw', content: result.data, point })\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Try to paste excalidraw content\n\tfor (const result of results) {\n\t\tif (result.type === 'excalidraw') {\n\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\teditor.putExternalContent({ type: 'excalidraw', content: result.data, point })\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Try to paste html content\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'html') {\n\t\t\t// try to find a link\n\t\t\tconst rootNode = new DOMParser().parseFromString(result.data, 'text/html')\n\t\t\tconst bodyNode = rootNode.querySelector('body')\n\n\t\t\t// Edge on Windows 11 home appears to paste a link as a single <a/> in\n\t\t\t// the HTML document. If we're pasting a single like tag we'll just\n\t\t\t// assume the user meant to paste the URL.\n\t\t\tconst isHtmlSingleLink =\n\t\t\t\tbodyNode &&\n\t\t\t\tArray.from(bodyNode.children).filter((el) => el.nodeType === 1).length === 1 &&\n\t\t\t\tbodyNode.firstElementChild &&\n\t\t\t\tbodyNode.firstElementChild.tagName === 'A' &&\n\t\t\t\tbodyNode.firstElementChild.hasAttribute('href') &&\n\t\t\t\tbodyNode.firstElementChild.getAttribute('href') !== ''\n\n\t\t\tif (isHtmlSingleLink) {\n\t\t\t\tconst href = bodyNode.firstElementChild.getAttribute('href')!\n\t\t\t\thandleText(editor, href, point, results)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// If the html is NOT a link, and we have NO OTHER texty content, then paste the html as text\n\t\t\tif (!results.some((r) => r.type === 'text' && r.subtype !== 'html') && result.data.trim()) {\n\t\t\t\tconst html = stripHtml(result.data) ?? ''\n\t\t\t\tif (html) {\n\t\t\t\t\thandleText(editor, stripHtml(result.data), point, results)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the html is NOT a link, and we have other texty content, then paste the html as a text shape\n\t\t\tif (results.some((r) => r.type === 'text' && r.subtype !== 'html')) {\n\t\t\t\tconst html = stripHtml(result.data) ?? ''\n\t\t\t\tif (html) {\n\t\t\t\t\teditor.markHistoryStoppingPoint('paste')\n\t\t\t\t\teditor.putExternalContent({\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: html,\n\t\t\t\t\t\thtml: result.data,\n\t\t\t\t\t\tpoint,\n\t\t\t\t\t\tsources: results,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Allow you to paste YouTube or Google Maps embeds, for example.\n\t\tif (result.type === 'text' && result.subtype === 'text' && result.data.startsWith('<iframe ')) {\n\t\t\t// try to find an iframe\n\t\t\tconst rootNode = new DOMParser().parseFromString(result.data, 'text/html')\n\t\t\tconst bodyNode = rootNode.querySelector('body')\n\n\t\t\tconst isSingleIframe =\n\t\t\t\tbodyNode &&\n\t\t\t\tArray.from(bodyNode.children).filter((el) => el.nodeType === 1).length === 1 &&\n\t\t\t\tbodyNode.firstElementChild &&\n\t\t\t\tbodyNode.firstElementChild.tagName === 'IFRAME' &&\n\t\t\t\tbodyNode.firstElementChild.hasAttribute('src') &&\n\t\t\t\tbodyNode.firstElementChild.getAttribute('src') !== ''\n\n\t\t\tif (isSingleIframe) {\n\t\t\t\tconst src = bodyNode.firstElementChild.getAttribute('src')!\n\t\t\t\thandleText(editor, src, point, results)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\t// Try to paste a link\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'url') {\n\t\t\tpasteUrl(editor, result.data, point, results)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Finally, if we haven't bailed on anything yet, we can paste text content\n\tfor (const result of results) {\n\t\tif (result.type === 'text' && result.subtype === 'text' && result.data.trim()) {\n\t\t\t// The clipboard may include multiple text items, but we only want to paste the first one\n\t\t\thandleText(editor, result.data, point, results)\n\t\t\treturn\n\t\t}\n\t}\n}\n\n/**\n * When the user copies, write the contents to local storage and to the clipboard\n *\n * @param editor - The editor instance.\n * @public\n */\nconst handleNativeOrMenuCopy = async (editor: Editor) => {\n\tconst content = await editor.resolveAssetsInContent(\n\t\teditor.getContentFromCurrentPage(editor.getSelectedShapeIds())\n\t)\n\tif (!content) {\n\t\tif (navigator && navigator.clipboard) {\n\t\t\tnavigator.clipboard.writeText('')\n\t\t}\n\t\treturn\n\t}\n\n\t// Use versioned clipboard format for better compression\n\t// Version 3: Don't compress assets, only compress other data\n\tconst { assets, ...otherData } = content\n\tconst clipboardData = {\n\t\ttype: 'application/tldraw',\n\t\tkind: 'content',\n\t\tversion: 3,\n\t\tdata: {\n\t\t\tassets: assets || [], // Plain JSON, no compression\n\t\t\totherCompressed: lz.compressToBase64(JSON.stringify(otherData)), // Only compress non-asset data\n\t\t},\n\t}\n\n\t// Don't compress the final structure - just use plain JSON\n\tconst stringifiedClipboard = JSON.stringify(clipboardData)\n\n\tif (typeof navigator === 'undefined') {\n\t\treturn\n\t} else {\n\t\t// Extract the text from the clipboard\n\t\tconst textItems = content.shapes\n\t\t\t.map((shape) => {\n\t\t\t\tconst util = editor.getShapeUtil(shape)\n\t\t\t\treturn util.getText(shape)\n\t\t\t})\n\t\t\t.filter(isDefined)\n\n\t\tif (navigator.clipboard?.write) {\n\t\t\tconst htmlBlob = new Blob([`<div data-tldraw>${stringifiedClipboard}</div>`], {\n\t\t\t\ttype: 'text/html',\n\t\t\t})\n\n\t\t\tlet textContent = textItems.join(' ')\n\n\t\t\t// This is a bug in chrome android where it won't paste content if\n\t\t\t// the text/plain content is \"\" so we need to always add an empty\n\t\t\t// space \uD83E\uDD2C\n\t\t\tif (textContent === '') {\n\t\t\t\ttextContent = ' '\n\t\t\t}\n\n\t\t\tnavigator.clipboard.write([\n\t\t\t\tnew ClipboardItem({\n\t\t\t\t\t'text/html': htmlBlob,\n\t\t\t\t\t// What is this second blob used for?\n\t\t\t\t\t'text/plain': new Blob([textContent], { type: 'text/plain' }),\n\t\t\t\t}),\n\t\t\t])\n\t\t} else if (navigator.clipboard.writeText) {\n\t\t\tnavigator.clipboard.writeText(`<div data-tldraw>${stringifiedClipboard}</div>`)\n\t\t}\n\t}\n}\n\n/** @public */\nexport function useMenuClipboardEvents() {\n\tconst editor = useMaybeEditor()\n\tconst trackEvent = useUiEvents()\n\n\tconst copy = useCallback(\n\t\tasync function onCopy(source: TLUiEventSource) {\n\t\t\tassert(editor, 'editor is required for copy')\n\t\t\tif (editor.getSelectedShapeIds().length === 0) return\n\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\ttrackEvent('copy', { source })\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\tconst cut = useCallback(\n\t\tasync function onCut(source: TLUiEventSource) {\n\t\t\tif (!editor) return\n\t\t\tif (editor.getSelectedShapeIds().length === 0) return\n\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\teditor.deleteShapes(editor.getSelectedShapeIds())\n\t\t\ttrackEvent('cut', { source })\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\tconst paste = useCallback(\n\t\tasync function onPaste(\n\t\t\tdata: DataTransfer | ClipboardItem[],\n\t\t\tsource: TLUiEventSource,\n\t\t\tpoint?: VecLike\n\t\t) {\n\t\t\tif (!editor) return\n\t\t\t// If we're editing a shape, or we are focusing an editable input, then\n\t\t\t// we would want the user's paste interaction to go to that element or\n\t\t\t// input instead; e.g. when pasting text into a text shape's content\n\t\t\tif (editor.getEditingShapeId() !== null) return\n\n\t\t\tif (Array.isArray(data) && data[0] instanceof ClipboardItem) {\n\t\t\t\thandlePasteFromClipboardApi({ editor, clipboardItems: data, point })\n\t\t\t\ttrackEvent('paste', { source: 'menu' })\n\t\t\t} else {\n\t\t\t\t// Read it first and then recurse, kind of weird\n\t\t\t\tnavigator.clipboard.read().then((clipboardItems) => {\n\t\t\t\t\tpaste(clipboardItems, source, point)\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\t[editor, trackEvent]\n\t)\n\n\treturn {\n\t\tcopy,\n\t\tcut,\n\t\tpaste,\n\t}\n}\n\n/** @public */\nexport function useNativeClipboardEvents() {\n\tconst editor = useEditor()\n\tconst trackEvent = useUiEvents()\n\n\tconst appIsFocused = useValue('editor.isFocused', () => editor.getInstanceState().isFocused, [\n\t\teditor,\n\t])\n\n\tuseEffect(() => {\n\t\tif (!appIsFocused) return\n\t\tconst copy = async (e: ClipboardEvent) => {\n\t\t\tif (\n\t\t\t\teditor.getSelectedShapeIds().length === 0 ||\n\t\t\t\teditor.getEditingShapeId() !== null ||\n\t\t\t\tareShortcutsDisabled(editor)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\ttrackEvent('copy', { source: 'kbd' })\n\t\t}\n\n\t\tasync function cut(e: ClipboardEvent) {\n\t\t\tif (\n\t\t\t\teditor.getSelectedShapeIds().length === 0 ||\n\t\t\t\teditor.getEditingShapeId() !== null ||\n\t\t\t\tareShortcutsDisabled(editor)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tpreventDefault(e)\n\t\t\tawait handleNativeOrMenuCopy(editor)\n\t\t\teditor.deleteShapes(editor.getSelectedShapeIds())\n\t\t\ttrackEvent('cut', { source: 'kbd' })\n\t\t}\n\n\t\tlet disablingMiddleClickPaste = false\n\t\tconst pointerUpHandler = (e: PointerEvent) => {\n\t\t\tif (e.button === 1) {\n\t\t\t\t// middle mouse button\n\t\t\t\tdisablingMiddleClickPaste = true\n\t\t\t\teditor.timers.requestAnimationFrame(() => {\n\t\t\t\t\tdisablingMiddleClickPaste = false\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tconst paste = (e: ClipboardEvent) => {\n\t\t\tif (disablingMiddleClickPaste) {\n\t\t\t\tmarkEventAsHandled(e)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// If we're editing a shape, or we are focusing an editable input, then\n\t\t\t// we would want the user's paste interaction to go to that element or\n\t\t\t// input instead; e.g. when pasting text into a text shape's content\n\t\t\tif (editor.getEditingShapeId() !== null || areShortcutsDisabled(editor)) return\n\n\t\t\t// Where should the shapes go?\n\t\t\tlet point: Vec | undefined = undefined\n\t\t\tlet pasteAtCursor = false\n\n\t\t\t// | Shiftkey | Paste at cursor mode | Paste at point? |\n\t\t\t// | N \t\t| N | N \t\t\t\t |\n\t\t\t// | Y \t\t| N | Y \t\t\t\t |\n\t\t\t// | N \t\t| Y | Y \t\t\t\t |\n\t\t\t// | Y \t\t| Y | N \t\t\t\t |\n\t\t\tif (editor.inputs.shiftKey) pasteAtCursor = true\n\t\t\tif (editor.user.getIsPasteAtCursorMode()) pasteAtCursor = !pasteAtCursor\n\t\t\tif (pasteAtCursor) point = editor.inputs.currentPagePoint\n\n\t\t\tconst pasteFromEvent = () => {\n\t\t\t\tif (e.clipboardData) {\n\t\t\t\t\thandlePasteFromEventClipboardData(editor, e.clipboardData, point)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if we can read from the clipboard API, we want to try using that first. that allows\n\t\t\t// us to access most things, and doesn't strip out metadata added to tldraw's own\n\t\t\t// copy-as-png features - so copied shapes come back in at the correct size.\n\t\t\tif (navigator.clipboard?.read) {\n\t\t\t\t// We can't read files from the filesystem using the clipboard API though - they'll\n\t\t\t\t// just come in as the file names instead. So we'll use the clipboard event's files\n\t\t\t\t// as a fallback - if we only got text, but do have files, we use those instead.\n\t\t\t\tconst fallbackFiles = Array.from(e.clipboardData?.files || [])\n\t\t\t\tnavigator.clipboard.read().then(\n\t\t\t\t\t(clipboardItems) => {\n\t\t\t\t\t\tif (Array.isArray(clipboardItems) && clipboardItems[0] instanceof ClipboardItem) {\n\t\t\t\t\t\t\thandlePasteFromClipboardApi({ editor, clipboardItems, point, fallbackFiles })\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\t// if reading from the clipboard fails, try to use the event clipboard data\n\t\t\t\t\t\tpasteFromEvent()\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tpasteFromEvent()\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\ttrackEvent('paste', { source: 'kbd' })\n\t\t}\n\n\t\tdocument.addEventListener('copy', copy)\n\t\tdocument.addEventListener('cut', cut)\n\t\tdocument.addEventListener('paste', paste)\n\t\tdocument.addEventListener('pointerup', pointerUpHandler)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('copy', copy)\n\t\t\tdocument.removeEventListener('cut', cut)\n\t\t\tdocument.removeEventListener('paste', paste)\n\t\t\tdocument.removeEventListener('pointerup', pointerUpHandler)\n\t\t}\n\t}, [editor, trackEvent, appIsFocused])\n}\n"],
5
+ "mappings": "AAAA;AAAA,EAEC;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,QAAQ;AACf,SAAS,aAAa,iBAAiB;AACvC,SAAS,6BAA6B,qCAAqC;AAC3E,SAA0B,mBAAmB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAKzB,MAAM,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAOA,SAAS,UAAU,MAAc;AAEhC,QAAM,MAAM,SAAS,eAAe,mBAAmB,EAAE;AACzD,MAAI,gBAAgB,YAAY,KAAK,KAAK;AAC1C,SAAO,IAAI,KAAK,eAAe,IAAI,KAAK,aAAa;AACtD;AAGO,MAAM,iBAAiB,CAAC,QAAgB;AAC9C,MAAI;AACH,UAAM,IAAI,IAAI,IAAI,GAAG;AACrB,WAAO,EAAE,aAAa,WAAW,EAAE,aAAa;AAAA,EACjD,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAGA,MAAM,sBAAsB,CAAC,QAAgB;AAC5C,QAAM,OAAO,IAAI,MAAM,QAAQ;AAC/B,aAAWA,QAAO,MAAM;AACvB,QAAI;AACH,YAAM,IAAI,IAAI,IAAIA,IAAG;AACrB,UAAI,EAAE,EAAE,aAAa,WAAW,EAAE,aAAa,WAAW;AACzD;AAAA,MACD;AAAA,IACD,QAAQ;AACP;AAAA,IACD;AAAA,EACD;AACA,SAAO,KAAK,IAAI;AACjB;AAGA,MAAM,YAAY,CAAC,SAAiB;AACnC,SAAO,QAAQ,KAAK,IAAI;AACzB;AAEA,MAAM,SAAS,CAAC,SAAS,UAAU,UAAU;AAO7C,SAA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e,CAAC,aAAa,eAAe;AAChF,0CAA4B,EAAE,QAAQ,gBAAgB,OAAO,cAAc,CAAC;AAAA,YAC7E;AAAA,UACD;AAAA,UACA,MAAM;AAEL,2BAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD,OAAO;AACN,uBAAe;AAAA,MAChB;AAEA,qBAAe,CAAC;AAChB,iBAAW,SAAS,EAAE,QAAQ,MAAM,CAAC;AAAA,IACtC;AAEA,aAAS,iBAAiB,QAAQ,IAAI;AACtC,aAAS,iBAAiB,OAAO,GAAG;AACpC,aAAS,iBAAiB,SAAS,KAAK;AACxC,aAAS,iBAAiB,aAAa,gBAAgB;AAEvD,WAAO,MAAM;AACZ,eAAS,oBAAoB,QAAQ,IAAI;AACzC,eAAS,oBAAoB,OAAO,GAAG;AACvC,eAAS,oBAAoB,SAAS,KAAK;AAC3C,eAAS,oBAAoB,aAAa,gBAAgB;AAAA,IAC3D;AAAA,EACD,GAAG,CAAC,QAAQ,YAAY,YAAY,CAAC;AACtC;",
6
6
  "names": ["url"]
7
7
  }
@@ -8,12 +8,13 @@ function useExportAs() {
8
8
  const { addToast } = useToasts();
9
9
  const msg = useTranslation();
10
10
  return useCallback(
11
- (ids, format = "png", name) => {
11
+ (ids, opts = {}) => {
12
12
  assert(editor, "useExportAs: editor is required");
13
+ const { format = "png", name, scale = 1 } = opts;
13
14
  exportAs(editor, ids, {
14
15
  format,
15
16
  name,
16
- scale: 1
17
+ scale
17
18
  }).catch((e) => {
18
19
  console.error(e.message);
19
20
  addToast({
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/ui/hooks/useExportAs.ts"],
4
- "sourcesContent": ["import { TLExportType, TLShapeId, assert, useMaybeEditor } from '@tldraw/editor'\nimport { useCallback } from 'react'\nimport { exportAs } from '../../utils/export/exportAs'\nimport { useToasts } from '../context/toasts'\nimport { useTranslation } from './useTranslation/useTranslation'\n\n/** @public */\nexport function useExportAs() {\n\tconst editor = useMaybeEditor()\n\tconst { addToast } = useToasts()\n\tconst msg = useTranslation()\n\n\treturn useCallback(\n\t\t(ids: TLShapeId[], format: TLExportType = 'png', name: string | undefined) => {\n\t\t\tassert(editor, 'useExportAs: editor is required')\n\t\t\texportAs(editor, ids, {\n\t\t\t\tformat,\n\t\t\t\tname,\n\t\t\t\tscale: 1,\n\t\t\t}).catch((e) => {\n\t\t\t\tconsole.error(e.message)\n\t\t\t\taddToast({\n\t\t\t\t\tid: 'export-fail',\n\t\t\t\t\ttitle: msg('toast.error.export-fail.title'),\n\t\t\t\t\tdescription: msg('toast.error.export-fail.desc'),\n\t\t\t\t\tseverity: 'error',\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t\t[editor, addToast, msg]\n\t)\n}\n"],
5
- "mappings": "AAAA,SAAkC,QAAQ,sBAAsB;AAChE,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAGxB,SAAS,cAAc;AAC7B,QAAM,SAAS,eAAe;AAC9B,QAAM,EAAE,SAAS,IAAI,UAAU;AAC/B,QAAM,MAAM,eAAe;AAE3B,SAAO;AAAA,IACN,CAAC,KAAkB,SAAuB,OAAO,SAA6B;AAC7E,aAAO,QAAQ,iCAAiC;AAChD,eAAS,QAAQ,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA,OAAO;AAAA,MACR,CAAC,EAAE,MAAM,CAAC,MAAM;AACf,gBAAQ,MAAM,EAAE,OAAO;AACvB,iBAAS;AAAA,UACR,IAAI;AAAA,UACJ,OAAO,IAAI,+BAA+B;AAAA,UAC1C,aAAa,IAAI,8BAA8B;AAAA,UAC/C,UAAU;AAAA,QACX,CAAC;AAAA,MACF,CAAC;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,UAAU,GAAG;AAAA,EACvB;AACD;",
4
+ "sourcesContent": ["import { TLExportType, TLShapeId, assert, useMaybeEditor } from '@tldraw/editor'\nimport { useCallback } from 'react'\nimport { exportAs } from '../../utils/export/exportAs'\nimport { useToasts } from '../context/toasts'\nimport { useTranslation } from './useTranslation/useTranslation'\n\n/** @public */\nexport function useExportAs() {\n\tconst editor = useMaybeEditor()\n\tconst { addToast } = useToasts()\n\tconst msg = useTranslation()\n\n\treturn useCallback(\n\t\t(ids: TLShapeId[], opts: { format?: TLExportType; name?: string; scale?: number } = {}) => {\n\t\t\tassert(editor, 'useExportAs: editor is required')\n\t\t\tconst { format = 'png', name, scale = 1 } = opts\n\t\t\texportAs(editor, ids, {\n\t\t\t\tformat,\n\t\t\t\tname,\n\t\t\t\tscale,\n\t\t\t}).catch((e) => {\n\t\t\t\tconsole.error(e.message)\n\t\t\t\taddToast({\n\t\t\t\t\tid: 'export-fail',\n\t\t\t\t\ttitle: msg('toast.error.export-fail.title'),\n\t\t\t\t\tdescription: msg('toast.error.export-fail.desc'),\n\t\t\t\t\tseverity: 'error',\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t\t[editor, addToast, msg]\n\t)\n}\n"],
5
+ "mappings": "AAAA,SAAkC,QAAQ,sBAAsB;AAChE,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAGxB,SAAS,cAAc;AAC7B,QAAM,SAAS,eAAe;AAC9B,QAAM,EAAE,SAAS,IAAI,UAAU;AAC/B,QAAM,MAAM,eAAe;AAE3B,SAAO;AAAA,IACN,CAAC,KAAkB,OAAiE,CAAC,MAAM;AAC1F,aAAO,QAAQ,iCAAiC;AAChD,YAAM,EAAE,SAAS,OAAO,MAAM,QAAQ,EAAE,IAAI;AAC5C,eAAS,QAAQ,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAC,EAAE,MAAM,CAAC,MAAM;AACf,gBAAQ,MAAM,EAAE,OAAO;AACvB,iBAAS;AAAA,UACR,IAAI;AAAA,UACJ,OAAO,IAAI,+BAA+B;AAAA,UAC1C,aAAa,IAAI,8BAA8B;AAAA,UAC/C,UAAU;AAAA,QACX,CAAC;AAAA,MACF,CAAC;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,UAAU,GAAG;AAAA,EACvB;AACD;",
6
6
  "names": []
7
7
  }
@@ -48,7 +48,7 @@ function useKeyboardShortcuts() {
48
48
  if (isReadonlyMode && !action.readonlyOk) continue;
49
49
  if (SKIP_KBDS.includes(action.id)) continue;
50
50
  hot(getHotkeysStringFromKbd(action.kbd), (event) => {
51
- if (areShortcutsDisabled(editor)) return;
51
+ if (areShortcutsDisabled(editor) && !action.isRequiredA11yAction) return;
52
52
  preventDefault(event);
53
53
  action.onSelect("kbd");
54
54
  });
@@ -115,7 +115,7 @@ function useKeyboardShortcuts() {
115
115
  }, [actions, tools, isReadonlyMode, editor, isFocused]);
116
116
  }
117
117
  function areShortcutsDisabled(editor) {
118
- return editor.menus.hasAnyOpenMenus() || editor.getEditingShapeId() !== null || editor.getCrashingError();
118
+ return editor.menus.hasAnyOpenMenus() || editor.getEditingShapeId() !== null || editor.getCrashingError() || !editor.user.getAreKeyboardShortcutsEnabled();
119
119
  }
120
120
  function getHotkeysStringFromKbd(kbd) {
121
121
  return getKeys(kbd).map((kbd2) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/ui/hooks/useKeyboardShortcuts.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tTLPointerEventInfo,\n\tisAccelKey,\n\tpreventDefault,\n\tuseEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport hotkeys from 'hotkeys-js'\nimport { useEffect } from 'react'\nimport { useActions } from '../context/actions'\nimport { useReadonly } from './useReadonly'\nimport { useTools } from './useTools'\n\nconst SKIP_KBDS = [\n\t// we set these in useNativeClipboardEvents instead\n\t'copy',\n\t'cut',\n\t'paste',\n\t// There's also an upload asset action, so we don't want to set the kbd twice\n\t'asset',\n]\n\n/** @public */\nexport function useKeyboardShortcuts() {\n\tconst editor = useEditor()\n\n\tconst isReadonlyMode = useReadonly()\n\tconst actions = useActions()\n\tconst tools = useTools()\n\tconst isFocused = useValue('is focused', () => editor.getInstanceState().isFocused, [editor])\n\tuseEffect(() => {\n\t\tif (!isFocused) return\n\n\t\tconst disposables = new Array<() => void>()\n\t\tconst container = editor.getContainer()\n\n\t\tconst hot = (keys: string, callback: (event: KeyboardEvent) => void) => {\n\t\t\thotkeys(keys, { element: container.ownerDocument.body }, callback)\n\t\t\tdisposables.push(() => {\n\t\t\t\thotkeys.unbind(keys, callback)\n\t\t\t})\n\t\t}\n\n\t\tconst hotUp = (keys: string, callback: (event: KeyboardEvent) => void) => {\n\t\t\thotkeys(\n\t\t\t\tkeys,\n\t\t\t\t{ element: container.ownerDocument.body, keyup: true, keydown: false },\n\t\t\t\tcallback\n\t\t\t)\n\t\t\tdisposables.push(() => {\n\t\t\t\thotkeys.unbind(keys, callback)\n\t\t\t})\n\t\t}\n\n\t\t// Add hotkeys for actions and tools.\n\t\t// Except those that in SKIP_KBDS!\n\t\tfor (const action of Object.values(actions)) {\n\t\t\tif (!action.kbd) continue\n\t\t\tif (isReadonlyMode && !action.readonlyOk) continue\n\t\t\tif (SKIP_KBDS.includes(action.id)) continue\n\n\t\t\thot(getHotkeysStringFromKbd(action.kbd), (event) => {\n\t\t\t\tif (areShortcutsDisabled(editor)) return\n\t\t\t\tpreventDefault(event)\n\t\t\t\taction.onSelect('kbd')\n\t\t\t})\n\t\t}\n\n\t\tfor (const tool of Object.values(tools)) {\n\t\t\tif (!tool.kbd || (!tool.readonlyOk && editor.getIsReadonly())) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (SKIP_KBDS.includes(tool.id)) continue\n\n\t\t\thot(getHotkeysStringFromKbd(tool.kbd), (event) => {\n\t\t\t\tif (areShortcutsDisabled(editor)) return\n\t\t\t\tpreventDefault(event)\n\t\t\t\ttool.onSelect('kbd')\n\t\t\t})\n\t\t}\n\n\t\thot(',', (e) => {\n\t\t\t// Skip if shortcuts are disabled\n\t\t\tif (areShortcutsDisabled(editor)) return\n\n\t\t\t// Don't press again if already pressed\n\t\t\tif (editor.inputs.keys.has('Comma')) return\n\n\t\t\tpreventDefault(e) // prevent whatever would normally happen\n\t\t\teditor.focus() // Focus if not already focused\n\n\t\t\teditor.inputs.keys.add('Comma')\n\n\t\t\tconst { x, y, z } = editor.inputs.currentPagePoint\n\t\t\tconst screenpoints = editor.pageToScreen({ x, y })\n\n\t\t\tconst info: TLPointerEventInfo = {\n\t\t\t\ttype: 'pointer',\n\t\t\t\tname: 'pointer_down',\n\t\t\t\tpoint: { x: screenpoints.x, y: screenpoints.y, z },\n\t\t\t\tshiftKey: e.shiftKey,\n\t\t\t\taltKey: e.altKey,\n\t\t\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\t\t\tmetaKey: e.metaKey,\n\t\t\t\taccelKey: isAccelKey(e),\n\t\t\t\tpointerId: 0,\n\t\t\t\tbutton: 0,\n\t\t\t\tisPen: editor.getInstanceState().isPenMode,\n\t\t\t\ttarget: 'canvas',\n\t\t\t}\n\n\t\t\teditor.dispatch(info)\n\t\t})\n\n\t\thotUp(',', (e) => {\n\t\t\tif (areShortcutsDisabled(editor)) return\n\t\t\tif (!editor.inputs.keys.has('Comma')) return\n\n\t\t\teditor.inputs.keys.delete('Comma')\n\n\t\t\tconst { x, y, z } = editor.inputs.currentScreenPoint\n\t\t\tconst info: TLPointerEventInfo = {\n\t\t\t\ttype: 'pointer',\n\t\t\t\tname: 'pointer_up',\n\t\t\t\tpoint: { x, y, z },\n\t\t\t\tshiftKey: e.shiftKey,\n\t\t\t\taltKey: e.altKey,\n\t\t\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\t\t\tmetaKey: e.metaKey,\n\t\t\t\taccelKey: isAccelKey(e),\n\t\t\t\tpointerId: 0,\n\t\t\t\tbutton: 0,\n\t\t\t\tisPen: editor.getInstanceState().isPenMode,\n\t\t\t\ttarget: 'canvas',\n\t\t\t}\n\n\t\t\teditor.dispatch(info)\n\t\t})\n\n\t\treturn () => {\n\t\t\tdisposables.forEach((d) => d())\n\t\t}\n\t}, [actions, tools, isReadonlyMode, editor, isFocused])\n}\n\nexport function areShortcutsDisabled(editor: Editor) {\n\treturn (\n\t\teditor.menus.hasAnyOpenMenus() ||\n\t\teditor.getEditingShapeId() !== null ||\n\t\teditor.getCrashingError()\n\t)\n}\n\n// The \"raw\" kbd here will look something like \"a\" or a combination of keys \"del,backspace\".\n// We need to first split them up by comma, then parse each key to ensure backwards compatibility\n// with the old kbd format. We used to have symbols to denote cmd/alt/shift,\n// using ! for shift, $ for cmd, and ? for alt.\nfunction getHotkeysStringFromKbd(kbd: string) {\n\treturn getKeys(kbd)\n\t\t.map((kbd) => {\n\t\t\tlet str = ''\n\n\t\t\tconst shift = kbd.includes('!')\n\t\t\tconst alt = kbd.includes('?')\n\t\t\tconst cmd = kbd.includes('$')\n\n\t\t\t// remove the modifiers; the remaining string are the actual key\n\t\t\tconst k = kbd.replace(/[!?$]/g, '')\n\n\t\t\tif (shift && alt && cmd) {\n\t\t\t\tstr = `cmd+shift+alt+${k},ctrl+shift+alt+${k}`\n\t\t\t} else if (shift && cmd) {\n\t\t\t\tstr = `cmd+shift+${k},ctrl+shift+${k}`\n\t\t\t} else if (alt && cmd) {\n\t\t\t\tstr = `cmd+alt+${k},ctrl+alt+${k}`\n\t\t\t} else if (alt && shift) {\n\t\t\t\tstr = `shift+alt+${k}`\n\t\t\t} else if (shift) {\n\t\t\t\tstr = `shift+${k}`\n\t\t\t} else if (alt) {\n\t\t\t\tstr = `alt+${k}`\n\t\t\t} else if (cmd) {\n\t\t\t\tstr = `cmd+${k},ctrl+${k}`\n\t\t\t} else {\n\t\t\t\tstr = k\n\t\t\t}\n\n\t\t\treturn str\n\t\t})\n\t\t.join(',')\n}\n\n// Logic to split kbd string from hotkeys-js util.\nfunction getKeys(key: string) {\n\tif (typeof key !== 'string') key = ''\n\tkey = key.replace(/\\s/g, '')\n\tconst keys = key.split(',')\n\tlet index = keys.lastInd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rC,WAAW,OAAO,KAAK;AACtB,YAAM,WAAW,CAAC,aAAa,CAAC;AAAA,IACjC,WAAW,OAAO,OAAO;AACxB,YAAM,aAAa,CAAC;AAAA,IACrB,WAAW,OAAO;AACjB,YAAM,SAAS,CAAC;AAAA,IACjB,WAAW,KAAK;AACf,YAAM,OAAO,CAAC;AAAA,IACf,WAAW,KAAK;AACf,YAAM,OAAO,CAAC,SAAS,CAAC;AAAA,IACzB,OAAO;AACN,YAAM;AAAA,IACP;AAEA,WAAO;AAAA,EACR,CAAC,EACA,KAAK,GAAG;AACX;AAGA,SAAS,QAAQ,KAAa;AAC7B,MAAI,OAAO,QAAQ,SAAU,OAAM;AACnC,QAAM,IAAI,QAAQ,OAAO,EAAE;AAC3B,QAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,MAAI,QAAQ,KAAK,YAAY,EAAE;AAE/B,SAAO,SAAS,KAAK;AACpB,SAAK,QAAQ,CAAC,KAAK;AACnB,SAAK,OAAO,OAAO,CAAC;AACpB,YAAQ,KAAK,YAAY,EAAE;AAAA,EAC5B;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tTLPointerEventInfo,\n\tisAccelKey,\n\tpreventDefault,\n\tuseEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport hotkeys from 'hotkeys-js'\nimport { useEffect } from 'react'\nimport { useActions } from '../context/actions'\nimport { useReadonly } from './useReadonly'\nimport { useTools } from './useTools'\n\nconst SKIP_KBDS = [\n\t// we set these in useNativeClipboardEvents instead\n\t'copy',\n\t'cut',\n\t'paste',\n\t// There's also an upload asset action, so we don't want to set the kbd twice\n\t'asset',\n]\n\n/** @public */\nexport function useKeyboardShortcuts() {\n\tconst editor = useEditor()\n\n\tconst isReadonlyMode = useReadonly()\n\tconst actions = useActions()\n\tconst tools = useTools()\n\tconst isFocused = useValue('is focused', () => editor.getInstanceState().isFocused, [editor])\n\tuseEffect(() => {\n\t\tif (!isFocused) return\n\n\t\tconst disposables = new Array<() => void>()\n\t\tconst container = editor.getContainer()\n\n\t\tconst hot = (keys: string, callback: (event: KeyboardEvent) => void) => {\n\t\t\thotkeys(keys, { element: container.ownerDocument.body }, callback)\n\t\t\tdisposables.push(() => {\n\t\t\t\thotkeys.unbind(keys, callback)\n\t\t\t})\n\t\t}\n\n\t\tconst hotUp = (keys: string, callback: (event: KeyboardEvent) => void) => {\n\t\t\thotkeys(\n\t\t\t\tkeys,\n\t\t\t\t{ element: container.ownerDocument.body, keyup: true, keydown: false },\n\t\t\t\tcallback\n\t\t\t)\n\t\t\tdisposables.push(() => {\n\t\t\t\thotkeys.unbind(keys, callback)\n\t\t\t})\n\t\t}\n\n\t\t// Add hotkeys for actions and tools.\n\t\t// Except those that in SKIP_KBDS!\n\t\tfor (const action of Object.values(actions)) {\n\t\t\tif (!action.kbd) continue\n\t\t\tif (isReadonlyMode && !action.readonlyOk) continue\n\t\t\tif (SKIP_KBDS.includes(action.id)) continue\n\n\t\t\thot(getHotkeysStringFromKbd(action.kbd), (event) => {\n\t\t\t\tif (areShortcutsDisabled(editor) && !action.isRequiredA11yAction) return\n\t\t\t\tpreventDefault(event)\n\t\t\t\taction.onSelect('kbd')\n\t\t\t})\n\t\t}\n\n\t\tfor (const tool of Object.values(tools)) {\n\t\t\tif (!tool.kbd || (!tool.readonlyOk && editor.getIsReadonly())) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (SKIP_KBDS.includes(tool.id)) continue\n\n\t\t\thot(getHotkeysStringFromKbd(tool.kbd), (event) => {\n\t\t\t\tif (areShortcutsDisabled(editor)) return\n\t\t\t\tpreventDefault(event)\n\t\t\t\ttool.onSelect('kbd')\n\t\t\t})\n\t\t}\n\n\t\thot(',', (e) => {\n\t\t\t// Skip if shortcuts are disabled\n\t\t\tif (areShortcutsDisabled(editor)) return\n\n\t\t\t// Don't press again if already pressed\n\t\t\tif (editor.inputs.keys.has('Comma')) return\n\n\t\t\tpreventDefault(e) // prevent whatever would normally happen\n\t\t\teditor.focus() // Focus if not already focused\n\n\t\t\teditor.inputs.keys.add('Comma')\n\n\t\t\tconst { x, y, z } = editor.inputs.currentPagePoint\n\t\t\tconst screenpoints = editor.pageToScreen({ x, y })\n\n\t\t\tconst info: TLPointerEventInfo = {\n\t\t\t\ttype: 'pointer',\n\t\t\t\tname: 'pointer_down',\n\t\t\t\tpoint: { x: screenpoints.x, y: screenpoints.y, z },\n\t\t\t\tshiftKey: e.shiftKey,\n\t\t\t\taltKey: e.altKey,\n\t\t\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\t\t\tmetaKey: e.metaKey,\n\t\t\t\taccelKey: isAccelKey(e),\n\t\t\t\tpointerId: 0,\n\t\t\t\tbutton: 0,\n\t\t\t\tisPen: editor.getInstanceState().isPenMode,\n\t\t\t\ttarget: 'canvas',\n\t\t\t}\n\n\t\t\teditor.dispatch(info)\n\t\t})\n\n\t\thotUp(',', (e) => {\n\t\t\tif (areShortcutsDisabled(editor)) return\n\t\t\tif (!editor.inputs.keys.has('Comma')) return\n\n\t\t\teditor.inputs.keys.delete('Comma')\n\n\t\t\tconst { x, y, z } = editor.inputs.currentScreenPoint\n\t\t\tconst info: TLPointerEventInfo = {\n\t\t\t\ttype: 'pointer',\n\t\t\t\tname: 'pointer_up',\n\t\t\t\tpoint: { x, y, z },\n\t\t\t\tshiftKey: e.shiftKey,\n\t\t\t\taltKey: e.altKey,\n\t\t\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\t\t\tmetaKey: e.metaKey,\n\t\t\t\taccelKey: isAccelKey(e),\n\t\t\t\tpointerId: 0,\n\t\t\t\tbutton: 0,\n\t\t\t\tisPen: editor.getInstanceState().isPenMode,\n\t\t\t\ttarget: 'canvas',\n\t\t\t}\n\n\t\t\teditor.dispatch(info)\n\t\t})\n\n\t\treturn () => {\n\t\t\tdisposables.forEach((d) => d())\n\t\t}\n\t}, [actions, tools, isReadonlyMode, editor, isFocused])\n}\n\nexport function areShortcutsDisabled(editor: Editor) {\n\treturn (\n\t\teditor.menus.hasAnyOpenMenus() ||\n\t\teditor.getEditingShapeId() !== null ||\n\t\teditor.getCrashingError() ||\n\t\t!editor.user.getAreKeyboardShortcutsEnabled()\n\t)\n}\n\n// The \"raw\" kbd here will look something like \"a\" or a combination of keys \"del,backspace\".\n// We need to first split them up by comma, then parse each key to ensure backwards compatibility\n// with the old kbd format. We used to have symbols to denote cmd/alt/shift,\n// using ! for shift, $ for cmd, and ? for alt.\nfunction getHotkeysStringFromKbd(kbd: string) {\n\treturn getKeys(kbd)\n\t\t.map((kbd) => {\n\t\t\tlet str = ''\n\n\t\t\tconst shift = kbd.includes('!')\n\t\t\tconst alt = kbd.includes('?')\n\t\t\tconst cmd = kbd.includes('$')\n\n\t\t\t// remove the modifiers; the remaining string are the actual key\n\t\t\tconst k = kbd.replace(/[!?$]/g, '')\n\n\t\t\tif (shift && alt && cmd) {\n\t\t\t\tstr = `cmd+shift+alt+${k},ctrl+shift+alt+${k}`\n\t\t\t} else if (shift && cmd) {\n\t\t\t\tstr = `cmd+shift+${k},ctrl+shift+${k}`\n\t\t\t} else if (alt && cmd) {\n\t\t\t\tstr = `cmd+alt+${k},ctrl+alt+${k}`\n\t\t\t} else if (alt && shift) {\n\t\t\t\tstr = `shift+alt+${k}`\n\t\t\t} else if (shift) {\n\t\t\t\tstr = `shift+${k}`\n\t\t\t} else if (alt) {\n\t\t\t\tstr = `alt+${k}`\n\t\t\t} else if (cmd) {\n\t\t\t\tstr = `cmd+${k},ctrl+${k}`\n\t\t\t} else {\n\t\t\t\tstr = k\n\t\t\t}\n\n\t\t\treturn str\n\t\t})\n\t\t.join(',')\n}\n\n// Logic to split kbd string from hotkeys-js util.\nfunction getKeys(key: string) {\n\tif (typeof key !== 'string') key = ''\n\tkey = key.replace(/\\s/g, '')\n\tconst keys = key.split(',')\n\tlet index = keys.lastIndexOf('')\n\n\tfor (; index >= 0; ) {\n\t\tkeys[index - 1] += ','\n\t\tkeys.splice(index, 1)\n\t\tindex = keys.lastInd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W,CAAC,aAAa,CAAC;AAAA,IACjC,WAAW,OAAO,OAAO;AACxB,YAAM,aAAa,CAAC;AAAA,IACrB,WAAW,OAAO;AACjB,YAAM,SAAS,CAAC;AAAA,IACjB,WAAW,KAAK;AACf,YAAM,OAAO,CAAC;AAAA,IACf,WAAW,KAAK;AACf,YAAM,OAAO,CAAC,SAAS,CAAC;AAAA,IACzB,OAAO;AACN,YAAM;AAAA,IACP;AAEA,WAAO;AAAA,EACR,CAAC,EACA,KAAK,GAAG;AACX;AAGA,SAAS,QAAQ,KAAa;AAC7B,MAAI,OAAO,QAAQ,SAAU,OAAM;AACnC,QAAM,IAAI,QAAQ,OAAO,EAAE;AAC3B,QAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,MAAI,QAAQ,KAAK,YAAY,EAAE;AAE/B,SAAO,SAAS,KAAK;AACpB,SAAK,QAAQ,CAAC,KAAK;AACnB,SAAK,OAAO,OAAO,CAAC;AACpB,YAAQ,KAAK,YAAY,EAAE;AAAA,EAC5B;AAEA,SAAO;AACR;",
6
6
  "names": ["kbd"]
7
7
  }
@@ -1,5 +1,12 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { GeoShapeGeoStyle, useMaybeEditor } from "@tldraw/editor";
2
+ import {
3
+ assertExists,
4
+ createShapeId,
5
+ GeoShapeGeoStyle,
6
+ getIndicesBetween,
7
+ toRichText,
8
+ useMaybeEditor
9
+ } from "@tldraw/editor";
3
10
  import * as React from "react";
4
11
  import { EmbedDialog } from "../components/EmbedDialog.mjs";
5
12
  import { useA11y } from "../context/a11y.mjs";
@@ -70,20 +77,26 @@ function ToolsProvider({ overrides, children }) {
70
77
  onToolSelect(source, this);
71
78
  }
72
79
  },
73
- ...[...GeoShapeGeoStyle.values].map((id) => ({
74
- id,
75
- label: `tool.${id}`,
80
+ ...[...GeoShapeGeoStyle.values].map((geo) => ({
81
+ id: geo,
82
+ label: `tool.${geo}`,
76
83
  meta: {
77
- geo: id
84
+ geo
78
85
  },
79
- kbd: id === "rectangle" ? "r" : id === "ellipse" ? "o" : void 0,
80
- icon: "geo-" + id,
86
+ kbd: geo === "rectangle" ? "r" : geo === "ellipse" ? "o" : void 0,
87
+ icon: "geo-" + geo,
81
88
  onSelect(source) {
82
89
  editor.run(() => {
83
- editor.setStyleForNextShapes(GeoShapeGeoStyle, id);
90
+ editor.setStyleForNextShapes(GeoShapeGeoStyle, geo);
84
91
  editor.setCurrentTool("geo");
85
- onToolSelect(source, this, `geo-${id}`);
92
+ onToolSelect(source, this, `geo-${geo}`);
86
93
  });
94
+ },
95
+ onDragStart(source, info) {
96
+ onDragFromToolbarToCreateShape(editor, info, {
97
+ createShape: (id) => editor.createShape({ id, type: "geo", props: { w: 200, h: 200, geo } })
98
+ });
99
+ trackEvent("drag-tool", { source, id: "geo" });
87
100
  }
88
101
  })),
89
102
  {
@@ -94,6 +107,16 @@ function ToolsProvider({ overrides, children }) {
94
107
  onSelect(source) {
95
108
  editor.setCurrentTool("arrow");
96
109
  onToolSelect(source, this);
110
+ },
111
+ onDragStart(source, info) {
112
+ onDragFromToolbarToCreateShape(editor, info, {
113
+ createShape: (id) => editor.createShape({
114
+ id,
115
+ type: "arrow",
116
+ props: { start: { x: 0, y: 200 }, end: { x: 200, y: 0 } }
117
+ })
118
+ });
119
+ trackEvent("drag-tool", { source, id: "arrow" });
97
120
  }
98
121
  },
99
122
  {
@@ -104,6 +127,24 @@ function ToolsProvider({ overrides, children }) {
104
127
  onSelect(source) {
105
128
  editor.setCurrentTool("line");
106
129
  onToolSelect(source, this);
130
+ },
131
+ onDragStart(source, info) {
132
+ onDragFromToolbarToCreateShape(editor, info, {
133
+ createShape: (id) => {
134
+ const [start, end] = getIndicesBetween(null, null, 2);
135
+ editor.createShape({
136
+ id,
137
+ type: "line",
138
+ props: {
139
+ points: {
140
+ [start]: { id: start, index: start, x: 0, y: 200 },
141
+ [end]: { id: end, index: end, x: 200, y: 0 }
142
+ }
143
+ }
144
+ });
145
+ }
146
+ });
147
+ trackEvent("drag-tool", { source, id: "line" });
107
148
  }
108
149
  },
109
150
  {
@@ -114,6 +155,12 @@ function ToolsProvider({ overrides, children }) {
114
155
  onSelect(source) {
115
156
  editor.setCurrentTool("frame");
116
157
  onToolSelect(source, this);
158
+ },
159
+ onDragStart(source, info) {
160
+ onDragFromToolbarToCreateShape(editor, info, {
161
+ createShape: (id) => editor.createShape({ id, type: "frame" })
162
+ });
163
+ trackEvent("drag-tool", { source, id: "frame" });
117
164
  }
118
165
  },
119
166
  {
@@ -124,6 +171,16 @@ function ToolsProvider({ overrides, children }) {
124
171
  onSelect(source) {
125
172
  editor.setCurrentTool("text");
126
173
  onToolSelect(source, this);
174
+ },
175
+ onDragStart(source, info) {
176
+ onDragFromToolbarToCreateShape(editor, info, {
177
+ createShape: (id) => editor.createShape({ id, type: "text", props: { richText: toRichText("Text") } }),
178
+ onDragEnd: (id) => {
179
+ editor.setEditingShape(id);
180
+ editor.emit("select-all-text", { shapeId: id });
181
+ }
182
+ });
183
+ trackEvent("drag-tool", { source, id: "text" });
127
184
  }
128
185
  },
129
186
  {
@@ -144,6 +201,16 @@ function ToolsProvider({ overrides, children }) {
144
201
  onSelect(source) {
145
202
  editor.setCurrentTool("note");
146
203
  onToolSelect(source, this);
204
+ },
205
+ onDragStart(source, info) {
206
+ onDragFromToolbarToCreateShape(editor, info, {
207
+ createShape: (id) => editor.createShape({ id, type: "note" }),
208
+ onDragEnd: (id) => {
209
+ editor.setEditingShape(id);
210
+ editor.emit("select-all-text", { shapeId: id });
211
+ }
212
+ });
213
+ trackEvent("drag-tool", { source, id: "note" });
147
214
  }
148
215
  },
149
216
  {
@@ -184,7 +251,7 @@ function ToolsProvider({ overrides, children }) {
184
251
  return overrides(editor, tools2, helpers);
185
252
  }
186
253
  return tools2;
187
- }, [overrides, editor, helpers, onToolSelect]);
254
+ }, [overrides, editor, helpers, onToolSelect, trackEvent]);
188
255
  return /* @__PURE__ */ jsx(ToolsContext.Provider, { value: tools, children });
189
256
  }
190
257
  function useTools() {
@@ -194,9 +261,34 @@ function useTools() {
194
261
  }
195
262
  return ctx;
196
263
  }
264
+ function onDragFromToolbarToCreateShape(editor, info, opts) {
265
+ const { x, y } = editor.inputs.currentPagePoint;
266
+ const stoppingPoint = editor.markHistoryStoppingPoint("drag shape tool");
267
+ editor.setCurrentTool("select.translating");
268
+ const id = createShapeId();
269
+ opts.createShape(id);
270
+ const shape = assertExists(editor.getShape(id), "Shape not found");
271
+ const { w, h } = editor.getShapePageBounds(id);
272
+ editor.updateShape({ id, type: shape.type, x: x - w / 2, y: y - h / 2 });
273
+ editor.select(id);
274
+ editor.setCurrentTool("select.translating", {
275
+ ...info,
276
+ target: "shape",
277
+ shape: editor.getShape(id),
278
+ isCreating: true,
279
+ creatingMarkId: stoppingPoint,
280
+ onCreate() {
281
+ editor.setCurrentTool("select.idle");
282
+ editor.select(id);
283
+ opts.onDragEnd?.(id);
284
+ }
285
+ });
286
+ editor.getCurrentTool().setCurrentToolIdMask(shape.type);
287
+ }
197
288
  export {
198
289
  ToolsContext,
199
290
  ToolsProvider,
291
+ onDragFromToolbarToCreateShape,
200
292
  useTools
201
293
  };
202
294
  //# sourceMappingURL=useTools.mjs.map