tldraw 3.16.0-next.c30b1b5e551a → 3.16.0-next.e57e478c23e0

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 (469) hide show
  1. package/dist-cjs/index.d.ts +353 -105
  2. package/dist-cjs/index.js +46 -14
  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/canvas/TldrawScribble.js +1 -1
  7. package/dist-cjs/lib/canvas/TldrawScribble.js.map +2 -2
  8. package/dist-cjs/lib/defaultExternalContentHandlers.js +5 -4
  9. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  10. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -3
  11. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/shapes/arrow/arrowLabel.js +6 -0
  13. package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +3 -3
  14. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js +1 -1
  15. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
  16. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js +3 -3
  17. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  18. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
  19. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +1 -1
  21. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +1 -1
  22. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +18 -12
  23. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  24. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js +1 -1
  25. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js.map +2 -2
  26. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +2 -2
  27. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  28. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
  29. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
  30. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
  31. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  32. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +6 -3
  33. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +2 -2
  34. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
  35. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  36. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
  37. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  38. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -3
  39. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  40. package/dist-cjs/lib/shapes/shared/ShapeFill.js +4 -4
  41. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  42. package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
  43. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js +0 -2
  44. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  45. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js +0 -2
  46. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js.map +2 -2
  47. package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js +10 -1
  48. package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js.map +2 -2
  49. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +2 -2
  50. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  51. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  52. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  53. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +25 -1
  54. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  55. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js +12 -0
  56. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  57. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  58. package/dist-cjs/lib/ui/TldrawUi.js +27 -12
  59. package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
  60. package/dist-cjs/lib/ui/assetUrls.js +13 -10
  61. package/dist-cjs/lib/ui/assetUrls.js.map +2 -2
  62. package/dist-cjs/lib/ui/components/AccessibilityMenu.js +35 -0
  63. package/dist-cjs/lib/ui/components/AccessibilityMenu.js.map +7 -0
  64. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +12 -3
  65. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  66. package/dist-cjs/lib/ui/components/{FollowingIndicator.js → DefaultFollowingIndicator.js} +6 -6
  67. package/dist-cjs/lib/ui/components/DefaultFollowingIndicator.js.map +7 -0
  68. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js +3 -2
  69. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js.map +2 -2
  70. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +6 -6
  71. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +1 -1
  72. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js +3 -3
  73. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js.map +2 -2
  74. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  75. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  76. package/dist-cjs/lib/ui/components/MobileStylePanel.js +5 -3
  77. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  78. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +1 -1
  79. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
  80. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +2 -1
  81. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  82. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js +3 -2
  83. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js.map +2 -2
  84. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +2 -2
  85. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js.map +2 -2
  86. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +11 -4
  87. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js.map +2 -2
  88. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +249 -279
  89. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  90. package/dist-cjs/lib/ui/components/{primitives/TldrawUiButtonPicker.js → StylePanel/StylePanelButtonPicker.js} +52 -56
  91. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +7 -0
  92. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js +68 -0
  93. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js.map +7 -0
  94. package/dist-cjs/lib/ui/components/StylePanel/{DoubleDropdownPicker.js → StylePanelDoubleDropdownPicker.js} +26 -25
  95. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +7 -0
  96. package/dist-cjs/lib/ui/components/StylePanel/{DropdownPicker.js → StylePanelDropdownPicker.js} +47 -43
  97. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +7 -0
  98. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js +28 -0
  99. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js.map +7 -0
  100. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +3 -2
  101. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  102. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +39 -10
  103. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  104. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +66 -21
  105. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
  106. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js +15 -3
  107. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js.map +2 -2
  108. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +3 -3
  109. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  110. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +189 -80
  111. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
  112. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +5 -4
  113. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  114. package/dist-cjs/lib/ui/components/menu-items.js +6 -0
  115. package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
  116. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +10 -1
  117. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  118. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +3 -2
  119. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js.map +3 -3
  120. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +17 -4
  121. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  122. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +32 -7
  123. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  124. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +269 -0
  125. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +7 -0
  126. package/dist-cjs/lib/ui/components/primitives/layout.js +76 -0
  127. package/dist-cjs/lib/ui/components/primitives/layout.js.map +7 -0
  128. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  129. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +25 -12
  130. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  131. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +154 -20
  132. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  133. package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js +3 -2
  134. package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js.map +2 -2
  135. package/dist-cjs/lib/ui/context/actions.js +38 -10
  136. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  137. package/dist-cjs/lib/ui/context/components.js +2 -0
  138. package/dist-cjs/lib/ui/context/components.js.map +2 -2
  139. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  140. package/dist-cjs/lib/ui/hooks/useExportAs.js +3 -2
  141. package/dist-cjs/lib/ui/hooks/useExportAs.js.map +2 -2
  142. package/dist-cjs/lib/ui/hooks/useTools.js +94 -9
  143. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  144. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  145. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +5 -0
  146. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  147. package/dist-cjs/lib/ui/kbd-utils.js +9 -3
  148. package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
  149. package/dist-cjs/lib/ui/version.js +3 -3
  150. package/dist-cjs/lib/ui/version.js.map +1 -1
  151. package/dist-cjs/lib/utils/export/copyAs.js +1 -2
  152. package/dist-cjs/lib/utils/export/copyAs.js.map +2 -2
  153. package/dist-cjs/lib/utils/export/export.js +0 -20
  154. package/dist-cjs/lib/utils/export/export.js.map +2 -2
  155. package/dist-cjs/lib/utils/export/exportAs.js +1 -2
  156. package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
  157. package/dist-esm/index.d.mts +353 -105
  158. package/dist-esm/index.mjs +85 -29
  159. package/dist-esm/index.mjs.map +2 -2
  160. package/dist-esm/lib/Tldraw.mjs +14 -4
  161. package/dist-esm/lib/Tldraw.mjs.map +2 -2
  162. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  163. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  164. package/dist-esm/lib/defaultExternalContentHandlers.mjs +5 -4
  165. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  166. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
  167. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  168. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +6 -0
  169. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +3 -3
  170. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs +1 -1
  171. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
  172. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  173. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  174. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
  175. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  176. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  177. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  178. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +19 -12
  179. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  180. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  181. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  182. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -2
  183. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  184. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
  185. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
  186. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
  187. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  188. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +6 -3
  189. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +2 -2
  190. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
  191. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  192. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -4
  193. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  194. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +1 -3
  195. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  196. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +5 -4
  197. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  198. package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
  199. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs +0 -2
  200. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  201. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs +0 -2
  202. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs.map +2 -2
  203. package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs +10 -1
  204. package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs.map +2 -2
  205. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +3 -2
  206. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  207. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  208. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  209. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +26 -1
  210. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  211. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +13 -0
  212. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  213. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  214. package/dist-esm/lib/ui/TldrawUi.mjs +29 -14
  215. package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
  216. package/dist-esm/lib/ui/assetUrls.mjs +13 -10
  217. package/dist-esm/lib/ui/assetUrls.mjs.map +2 -2
  218. package/dist-esm/lib/ui/components/AccessibilityMenu.mjs +19 -0
  219. package/dist-esm/lib/ui/components/AccessibilityMenu.mjs.map +7 -0
  220. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +12 -3
  221. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  222. package/dist-esm/lib/ui/components/{FollowingIndicator.mjs → DefaultFollowingIndicator.mjs} +3 -3
  223. package/dist-esm/lib/ui/components/DefaultFollowingIndicator.mjs.map +7 -0
  224. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs +3 -2
  225. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs.map +2 -2
  226. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +6 -6
  227. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +1 -1
  228. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs +3 -5
  229. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs.map +2 -2
  230. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  231. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  232. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +6 -3
  233. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  234. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +1 -1
  235. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
  236. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +2 -1
  237. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  238. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs +3 -2
  239. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs.map +2 -2
  240. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs +2 -2
  241. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs.map +2 -2
  242. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs +16 -5
  243. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs.map +2 -2
  244. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +251 -283
  245. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  246. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +126 -0
  247. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +7 -0
  248. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs +48 -0
  249. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs.map +7 -0
  250. package/dist-esm/lib/ui/components/StylePanel/{DoubleDropdownPicker.mjs → StylePanelDoubleDropdownPicker.mjs} +23 -22
  251. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +7 -0
  252. package/dist-esm/lib/ui/components/StylePanel/{DropdownPicker.mjs → StylePanelDropdownPicker.mjs} +44 -40
  253. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +7 -0
  254. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs +8 -0
  255. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs.map +7 -0
  256. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +3 -2
  257. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  258. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +39 -10
  259. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  260. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +56 -21
  261. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
  262. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs +15 -3
  263. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs.map +2 -2
  264. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
  265. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  266. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -81
  267. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
  268. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +5 -4
  269. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  270. package/dist-esm/lib/ui/components/menu-items.mjs +6 -0
  271. package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
  272. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +10 -1
  273. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  274. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs +3 -2
  275. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs.map +2 -2
  276. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +17 -4
  277. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  278. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +32 -7
  279. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  280. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +246 -0
  281. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +7 -0
  282. package/dist-esm/lib/ui/components/primitives/layout.mjs +46 -0
  283. package/dist-esm/lib/ui/components/primitives/layout.mjs.map +7 -0
  284. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  285. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +25 -12
  286. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  287. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +162 -22
  288. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  289. package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs +3 -2
  290. package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs.map +2 -2
  291. package/dist-esm/lib/ui/context/actions.mjs +38 -10
  292. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  293. package/dist-esm/lib/ui/context/components.mjs +2 -0
  294. package/dist-esm/lib/ui/context/components.mjs.map +2 -2
  295. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  296. package/dist-esm/lib/ui/hooks/useExportAs.mjs +3 -2
  297. package/dist-esm/lib/ui/hooks/useExportAs.mjs.map +2 -2
  298. package/dist-esm/lib/ui/hooks/useTools.mjs +102 -10
  299. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  300. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +5 -0
  301. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  302. package/dist-esm/lib/ui/kbd-utils.mjs +9 -3
  303. package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
  304. package/dist-esm/lib/ui/version.mjs +3 -3
  305. package/dist-esm/lib/ui/version.mjs.map +1 -1
  306. package/dist-esm/lib/utils/export/copyAs.mjs +1 -2
  307. package/dist-esm/lib/utils/export/copyAs.mjs.map +2 -2
  308. package/dist-esm/lib/utils/export/export.mjs +0 -20
  309. package/dist-esm/lib/utils/export/export.mjs.map +2 -2
  310. package/dist-esm/lib/utils/export/exportAs.mjs +1 -2
  311. package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
  312. package/package.json +11 -34
  313. package/src/index.ts +64 -22
  314. package/src/lib/Tldraw.tsx +15 -2
  315. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  316. package/src/lib/defaultExternalContentHandlers.ts +12 -4
  317. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +2 -1
  318. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +4 -3
  319. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +7 -6
  320. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
  321. package/src/lib/shapes/arrow/arrowLabel.ts +8 -0
  322. package/src/lib/shapes/arrow/arrowTargetState.ts +2 -1
  323. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  324. package/src/lib/shapes/draw/DrawShapeTool.test.ts +0 -5
  325. package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
  326. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  327. package/src/lib/shapes/frame/FrameShapeUtil.tsx +29 -14
  328. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  329. package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -2
  330. package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
  331. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
  332. package/src/lib/shapes/image/ImageShapeUtil.tsx +6 -3
  333. package/src/lib/shapes/line/LineShapeUtil.test.tsx +4 -3
  334. package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
  335. package/src/lib/shapes/line/__snapshots__/LineShapeUtil.test.tsx.snap +2 -2
  336. package/src/lib/shapes/note/NoteShapeUtil.tsx +9 -4
  337. package/src/lib/shapes/shared/PlainTextLabel.tsx +0 -6
  338. package/src/lib/shapes/shared/ShapeFill.tsx +5 -4
  339. package/src/lib/shapes/shared/freehand/svg.ts +2 -0
  340. package/src/lib/shapes/shared/useEditablePlainText.ts +0 -6
  341. package/src/lib/shapes/shared/useImageOrVideoAsset.ts +0 -7
  342. package/src/lib/shapes/shared/usePrefersReducedMotion.tsx +11 -1
  343. package/src/lib/shapes/text/TextShapeTool.test.ts +6 -5
  344. package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
  345. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  346. package/src/lib/tools/EraserTool/childStates/Erasing.ts +34 -1
  347. package/src/lib/tools/EraserTool/childStates/Pointing.ts +20 -0
  348. package/src/lib/tools/SelectTool/childStates/Translating.ts +0 -1
  349. package/src/lib/ui/TldrawUi.tsx +33 -12
  350. package/src/lib/ui/assetUrls.ts +13 -10
  351. package/src/lib/ui/components/AccessibilityMenu.tsx +20 -0
  352. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +15 -3
  353. package/src/lib/ui/components/{FollowingIndicator.tsx → DefaultFollowingIndicator.tsx} +2 -1
  354. package/src/lib/ui/components/DefaultMenuPanel.tsx +4 -3
  355. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +6 -6
  356. package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +4 -4
  357. package/src/lib/ui/components/Minimap/MinimapManager.ts +4 -4
  358. package/src/lib/ui/components/MobileStylePanel.tsx +9 -6
  359. package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +1 -1
  360. package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +3 -2
  361. package/src/lib/ui/components/SharePanel/PeopleMenuItem.tsx +4 -3
  362. package/src/lib/ui/components/SharePanel/UserPresenceColorPicker.tsx +3 -3
  363. package/src/lib/ui/components/StylePanel/DefaultStylePanel.tsx +28 -12
  364. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +261 -343
  365. package/src/lib/ui/components/{primitives/TldrawUiButtonPicker.tsx → StylePanel/StylePanelButtonPicker.tsx} +66 -50
  366. package/src/lib/ui/components/StylePanel/StylePanelContext.tsx +63 -0
  367. package/src/lib/ui/components/StylePanel/{DoubleDropdownPicker.tsx → StylePanelDoubleDropdownPicker.tsx} +31 -22
  368. package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +119 -0
  369. package/src/lib/ui/components/StylePanel/StylePanelSubheading.tsx +9 -0
  370. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +4 -3
  371. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +33 -16
  372. package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +55 -23
  373. package/src/lib/ui/components/Toolbar/DefaultVideoToolbarContent.tsx +12 -4
  374. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +5 -5
  375. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +212 -61
  376. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +14 -11
  377. package/src/lib/ui/components/menu-items.tsx +8 -0
  378. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +6 -1
  379. package/src/lib/ui/components/primitives/TldrawUiPopover.tsx +4 -2
  380. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +50 -30
  381. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +54 -12
  382. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +335 -0
  383. package/src/lib/ui/components/primitives/layout.tsx +107 -0
  384. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  385. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +29 -16
  386. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +221 -19
  387. package/src/lib/ui/context/TldrawUiContextProvider.tsx +23 -20
  388. package/src/lib/ui/context/actions.tsx +38 -10
  389. package/src/lib/ui/context/components.tsx +3 -0
  390. package/src/lib/ui/context/events.tsx +3 -1
  391. package/src/lib/ui/hooks/useExportAs.ts +3 -2
  392. package/src/lib/ui/hooks/useTools.tsx +140 -10
  393. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +5 -0
  394. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +5 -0
  395. package/src/lib/ui/kbd-utils.ts +10 -3
  396. package/src/lib/ui/version.ts +3 -3
  397. package/src/lib/ui.css +424 -293
  398. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +5 -5
  399. package/src/lib/utils/export/copyAs.ts +1 -24
  400. package/src/lib/utils/export/export.ts +0 -36
  401. package/src/lib/utils/export/exportAs.ts +1 -32
  402. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +4 -4
  403. package/src/test/A11y.test.tsx +3 -2
  404. package/src/test/ClickManager.test.ts +7 -6
  405. package/src/test/Editor.test.tsx +20 -19
  406. package/src/test/EraserTool.test.ts +184 -13
  407. package/src/test/HandTool.test.ts +10 -9
  408. package/src/test/HighlightShape.test.ts +2 -1
  409. package/src/test/SelectTool.test.ts +3 -2
  410. package/src/test/TLUserPreferences.test.ts +4 -3
  411. package/src/test/TestEditor.ts +13 -15
  412. package/src/test/TldrawEditor.test.tsx +11 -10
  413. package/src/test/ZoomTool.test.ts +7 -6
  414. package/src/test/__snapshots__/drawing.test.ts.snap +2 -2
  415. package/src/test/__snapshots__/groups.test.tsx.snap +6 -6
  416. package/src/test/__snapshots__/resizing.test.ts.snap +2 -2
  417. package/src/test/arrows-megabus.test.tsx +17 -10
  418. package/src/test/bindings.test.tsx +24 -37
  419. package/src/test/bookmark-shapes.test.ts +1 -8
  420. package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +23 -7
  421. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +8 -8
  422. package/src/test/commands/__snapshots__/zoomToFit.test.ts.snap +2 -2
  423. package/src/test/commands/alignShapes.test.tsx +25 -24
  424. package/src/test/commands/animationSpeed.test.ts +2 -1
  425. package/src/test/commands/centerOnPoint.test.ts +3 -2
  426. package/src/test/commands/clipboard.test.ts +3 -2
  427. package/src/test/commands/createShapes.test.ts +2 -1
  428. package/src/test/commands/deleteShapes.test.ts +2 -1
  429. package/src/test/commands/distributeShapes.test.tsx +11 -10
  430. package/src/test/commands/getSvgString.test.ts +2 -1
  431. package/src/test/commands/packShapes.test.ts +5 -4
  432. package/src/test/commands/resizeShape.test.ts +2 -1
  433. package/src/test/commands/rotateShapes.test.ts +7 -6
  434. package/src/test/commands/setCamera.test.ts +4 -3
  435. package/src/test/commands/setCurrentPage.test.ts +3 -2
  436. package/src/test/commands/stackShapes.test.ts +11 -10
  437. package/src/test/commands/stretch.test.tsx +13 -12
  438. package/src/test/createDeepLink.test.tsx +2 -1
  439. package/src/test/cropping.test.ts +3 -2
  440. package/src/test/custom-clipping.test.ts +436 -0
  441. package/src/test/drawing.test.ts +2 -1
  442. package/src/test/flipShapes.test.ts +4 -3
  443. package/src/test/frames.test.ts +25 -24
  444. package/src/test/getCulledShapes.test.tsx +3 -2
  445. package/src/test/groups.test.tsx +1 -1
  446. package/src/test/handleDeepLink.test.tsx +2 -1
  447. package/src/test/inner-outer-margin.test.ts +315 -0
  448. package/src/test/maxShapes.test.ts +3 -2
  449. package/src/test/modifiers.test.ts +5 -4
  450. package/src/test/navigation.test.ts +12 -11
  451. package/src/test/panning.test.ts +2 -1
  452. package/src/test/perf/perf.test.ts +2 -1
  453. package/src/test/registerDeepLinkListener.test.tsx +10 -9
  454. package/src/test/resizing.test.ts +39 -38
  455. package/src/test/select.test.tsx +4 -3
  456. package/src/test/selection-omnibus.test.ts +11 -10
  457. package/src/test/shapeutils.test.ts +4 -3
  458. package/src/test/translating.test.ts +9 -8
  459. package/tldraw.css +725 -581
  460. package/dist-cjs/lib/ui/components/FollowingIndicator.js.map +0 -7
  461. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +0 -7
  462. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +0 -7
  463. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +0 -7
  464. package/dist-esm/lib/ui/components/FollowingIndicator.mjs.map +0 -7
  465. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +0 -7
  466. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +0 -7
  467. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +0 -115
  468. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +0 -7
  469. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +0 -109
@@ -1,7 +1,9 @@
1
+ import { tltime } from '@tldraw/editor'
1
2
  import { Slider as _Slider } from 'radix-ui'
2
3
  import React, { useCallback, useEffect, useState } from 'react'
3
4
  import { TLUiTranslationKey } from '../../hooks/useTranslation/TLUiTranslationKey'
4
5
  import { useTranslation } from '../../hooks/useTranslation/useTranslation'
6
+ import { TldrawUiTooltip, tooltipManager } from './TldrawUiTooltip'
5
7
 
6
8
  /** @public */
7
9
  export interface TLUiSliderProps {
@@ -32,6 +34,7 @@ export const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(
32
34
  ref
33
35
  ) {
34
36
  const msg = useTranslation()
37
+ const [titleAndLabel, setTitleAndLabel] = useState('')
35
38
 
36
39
  // XXX: Radix starts out our slider with a tabIndex of 0
37
40
  // This causes some tab focusing issues, most prevelant in MobileStylePanel,
@@ -49,9 +52,25 @@ export const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(
49
52
  )
50
53
 
51
54
  const handlePointerDown = useCallback(() => {
55
+ tooltipManager.hideAllTooltips()
52
56
  onHistoryMark('click slider')
53
57
  }, [onHistoryMark])
54
58
 
59
+ // N.B. This is a bit silly. The Radix slider auto-focuses which
60
+ // triggers TldrawUiTooltip handleFocus when we dbl-click to edit an image,
61
+ // which in turn makes the tooltip display prematurely.
62
+ // This makes it wait until we've focused to show the tooltip.
63
+ useEffect(() => {
64
+ const timeout = tltime.setTimeout(
65
+ 'set title and label',
66
+ () => {
67
+ setTitleAndLabel(title + ' — ' + msg(label as TLUiTranslationKey))
68
+ },
69
+ 0
70
+ )
71
+ return () => clearTimeout(timeout)
72
+ }, [label, msg, title])
73
+
55
74
  // N.B. Annoying. For a11y purposes, we need Tab to work.
56
75
  // For some reason, Radix has some custom behavior here
57
76
  // that interferes with tabbing past the slider and then
@@ -64,36 +83,37 @@ export const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(
64
83
 
65
84
  return (
66
85
  <div className="tlui-slider__container">
67
- <_Slider.Root
68
- data-testid={testId}
69
- className="tlui-slider"
70
- dir="ltr"
71
- min={min ?? 0}
72
- max={steps}
73
- step={1}
74
- value={value !== null ? [value] : undefined}
75
- onPointerDown={handlePointerDown}
76
- onValueChange={handleValueChange}
77
- onKeyDownCapture={handleKeyEvent}
78
- onKeyUpCapture={handleKeyEvent}
79
- title={title + ' — ' + msg(label as TLUiTranslationKey)}
80
- >
81
- <_Slider.Track className="tlui-slider__track" dir="ltr">
82
- {value !== null && <_Slider.Range className="tlui-slider__range" dir="ltr" />}
83
- </_Slider.Track>
84
- {value !== null && (
85
- <_Slider.Thumb
86
- aria-valuemin={(min ?? 0) * ariaValueModifier}
87
- aria-valuenow={value * ariaValueModifier}
88
- aria-valuemax={steps * ariaValueModifier}
89
- aria-label={title + ' — ' + msg(label as TLUiTranslationKey)}
90
- className="tlui-slider__thumb"
91
- dir="ltr"
92
- ref={ref}
93
- tabIndex={tabIndex}
94
- />
95
- )}
96
- </_Slider.Root>
86
+ <TldrawUiTooltip content={titleAndLabel}>
87
+ <_Slider.Root
88
+ data-testid={testId}
89
+ className="tlui-slider"
90
+ dir="ltr"
91
+ min={min ?? 0}
92
+ max={steps}
93
+ step={1}
94
+ value={value !== null ? [value] : undefined}
95
+ onPointerDown={handlePointerDown}
96
+ onValueChange={handleValueChange}
97
+ onKeyDownCapture={handleKeyEvent}
98
+ onKeyUpCapture={handleKeyEvent}
99
+ >
100
+ <_Slider.Track className="tlui-slider__track" dir="ltr">
101
+ {value !== null && <_Slider.Range className="tlui-slider__range" dir="ltr" />}
102
+ </_Slider.Track>
103
+ {value !== null && (
104
+ <_Slider.Thumb
105
+ aria-valuemin={(min ?? 0) * ariaValueModifier}
106
+ aria-valuenow={value * ariaValueModifier}
107
+ aria-valuemax={steps * ariaValueModifier}
108
+ aria-label={titleAndLabel}
109
+ className="tlui-slider__thumb"
110
+ dir="ltr"
111
+ ref={ref}
112
+ tabIndex={tabIndex}
113
+ />
114
+ )}
115
+ </_Slider.Root>
116
+ </TldrawUiTooltip>
97
117
  </div>
98
118
  )
99
119
  })
@@ -1,6 +1,8 @@
1
1
  import classnames from 'classnames'
2
2
  import { Toolbar as _Toolbar } from 'radix-ui'
3
3
  import React from 'react'
4
+ import { TldrawUiColumn, TldrawUiGrid, TldrawUiRow } from './layout'
5
+ import { TldrawUiTooltip } from './TldrawUiTooltip'
4
6
 
5
7
  /** @public */
6
8
  export interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -8,20 +10,42 @@ export interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {
8
10
  className?: string
9
11
  dir?: 'ltr' | 'rtl'
10
12
  label: string
13
+ orientation?: 'horizontal' | 'vertical' | 'grid'
14
+ tooltipSide?: 'top' | 'right' | 'bottom' | 'left'
15
+ }
16
+
17
+ const LayoutByOrientation = {
18
+ horizontal: TldrawUiRow,
19
+ vertical: TldrawUiColumn,
20
+ grid: TldrawUiGrid,
11
21
  }
12
22
 
13
23
  /** @public @react */
14
24
  export const TldrawUiToolbar = React.forwardRef<HTMLDivElement, TLUiToolbarProps>(
15
- ({ children, className, label, ...props }: TLUiToolbarProps, ref) => {
25
+ (
26
+ {
27
+ children,
28
+ className,
29
+ label,
30
+ orientation = 'horizontal',
31
+ tooltipSide,
32
+ ...props
33
+ }: TLUiToolbarProps,
34
+ ref
35
+ ) => {
36
+ const Layout = LayoutByOrientation[orientation]
16
37
  return (
17
- <_Toolbar.Root
18
- ref={ref}
19
- {...props}
20
- className={classnames('tlui-toolbar-container', className)}
21
- aria-label={label}
22
- >
23
- {children}
24
- </_Toolbar.Root>
38
+ <Layout asChild tooltipSide={tooltipSide}>
39
+ <_Toolbar.Root
40
+ ref={ref}
41
+ {...props}
42
+ className={classnames('tlui-toolbar', className)}
43
+ aria-label={label}
44
+ orientation={orientation === 'grid' ? 'horizontal' : orientation}
45
+ >
46
+ {children}
47
+ </_Toolbar.Root>
48
+ </Layout>
25
49
  )
26
50
  }
27
51
  )
@@ -34,23 +58,30 @@ export interface TLUiToolbarButtonProps extends React.HTMLAttributes<HTMLButtonE
34
58
  disabled?: boolean
35
59
  isActive?: boolean
36
60
  type: 'icon' | 'tool' | 'menu'
61
+ tooltip?: string
37
62
  }
38
63
 
39
64
  /** @public @react */
40
65
  export const TldrawUiToolbarButton = React.forwardRef<HTMLButtonElement, TLUiToolbarButtonProps>(
41
- ({ asChild, children, type, isActive, ...props }: TLUiToolbarButtonProps, ref) => {
42
- return (
66
+ ({ asChild, children, type, isActive, tooltip, ...props }: TLUiToolbarButtonProps, ref) => {
67
+ const button = (
43
68
  <_Toolbar.Button
44
69
  ref={ref}
45
70
  asChild={asChild}
46
71
  draggable={false}
47
72
  data-isactive={isActive}
48
73
  {...props}
74
+ // The tooltip takes care of this.
75
+ title={undefined}
49
76
  className={classnames('tlui-button', `tlui-button__${type}`, props.className)}
50
77
  >
51
78
  {children}
52
79
  </_Toolbar.Button>
53
80
  )
81
+
82
+ const tooltipContent = tooltip || props.title
83
+
84
+ return <TldrawUiTooltip content={tooltipContent}>{button}</TldrawUiTooltip>
54
85
  }
55
86
  )
56
87
 
@@ -63,6 +94,7 @@ export interface TLUiToolbarToggleGroupProps extends React.HTMLAttributes<HTMLDi
63
94
  // TODO: fix up this type later
64
95
  defaultValue?: any
65
96
  type: 'single' | 'multiple'
97
+ asChild?: boolean
66
98
  }
67
99
 
68
100
  /** @public @react */
@@ -70,10 +102,12 @@ export const TldrawUiToolbarToggleGroup = ({
70
102
  children,
71
103
  className,
72
104
  type,
105
+ asChild,
73
106
  ...props
74
107
  }: TLUiToolbarToggleGroupProps) => {
75
108
  return (
76
109
  <_Toolbar.ToggleGroup
110
+ asChild={asChild}
77
111
  type={type}
78
112
  {...props}
79
113
  // TODO: this fixes a bug in Radix until they fix it.
@@ -93,6 +127,7 @@ export interface TLUiToolbarToggleItemProps extends React.HTMLAttributes<HTMLBut
93
127
  className?: string
94
128
  type: 'icon' | 'tool'
95
129
  value: string
130
+ tooltip?: string
96
131
  }
97
132
 
98
133
  /** @public @react */
@@ -101,11 +136,14 @@ export const TldrawUiToolbarToggleItem = ({
101
136
  className,
102
137
  type,
103
138
  value,
139
+ tooltip,
104
140
  ...props
105
141
  }: TLUiToolbarToggleItemProps) => {
106
- return (
142
+ const toggleItem = (
107
143
  <_Toolbar.ToggleItem
108
144
  {...props}
145
+ // The tooltip takes care of this.
146
+ title={undefined}
109
147
  className={classnames(
110
148
  'tlui-button',
111
149
  `tlui-button__${type}`,
@@ -117,4 +155,8 @@ export const TldrawUiToolbarToggleItem = ({
117
155
  {children}
118
156
  </_Toolbar.ToggleItem>
119
157
  )
158
+
159
+ const tooltipContent = tooltip || props.title
160
+
161
+ return <TldrawUiTooltip content={tooltipContent}>{toggleItem}</TldrawUiTooltip>
120
162
  }
@@ -0,0 +1,335 @@
1
+ import { assert, Atom, atom, Editor, uniqueId, useMaybeEditor, useValue } from '@tldraw/editor'
2
+ import { Tooltip as _Tooltip } from 'radix-ui'
3
+ import React, {
4
+ createContext,
5
+ forwardRef,
6
+ ReactNode,
7
+ useContext,
8
+ useEffect,
9
+ useRef,
10
+ useState,
11
+ } from 'react'
12
+ import { useTldrawUiOrientation } from './layout'
13
+
14
+ const DEFAULT_TOOLTIP_DELAY_MS = 700
15
+
16
+ /** @public */
17
+ export interface TldrawUiTooltipProps {
18
+ children: React.ReactNode
19
+ content?: string | React.ReactNode
20
+ side?: 'top' | 'right' | 'bottom' | 'left'
21
+ sideOffset?: number
22
+ disabled?: boolean
23
+ showOnMobile?: boolean
24
+ delayDuration?: number
25
+ }
26
+
27
+ // Singleton tooltip manager
28
+ class TooltipManager {
29
+ private static instance: TooltipManager | null = null
30
+ private currentTooltip = atom<{
31
+ id: string
32
+ content: ReactNode
33
+ side: 'top' | 'right' | 'bottom' | 'left'
34
+ sideOffset: number
35
+ showOnMobile: boolean
36
+ targetElement: HTMLElement
37
+ delayDuration: number
38
+ } | null>('current tooltip', null)
39
+ private destroyTimeoutId: number | null = null
40
+
41
+ static getInstance(): TooltipManager {
42
+ if (!TooltipManager.instance) {
43
+ TooltipManager.instance = new TooltipManager()
44
+ }
45
+ return TooltipManager.instance
46
+ }
47
+
48
+ showTooltip(
49
+ tooltipId: string,
50
+ content: string | React.ReactNode,
51
+ targetElement: HTMLElement,
52
+ side: 'top' | 'right' | 'bottom' | 'left',
53
+ sideOffset: number,
54
+ showOnMobile: boolean,
55
+ delayDuration: number
56
+ ) {
57
+ // Clear any existing destroy timeout
58
+ if (this.destroyTimeoutId) {
59
+ clearTimeout(this.destroyTimeoutId)
60
+ this.destroyTimeoutId = null
61
+ }
62
+
63
+ // Update current tooltip
64
+ this.currentTooltip.set({
65
+ id: tooltipId,
66
+ content,
67
+ side,
68
+ sideOffset,
69
+ showOnMobile,
70
+ targetElement,
71
+ delayDuration,
72
+ })
73
+ }
74
+
75
+ hideTooltip(editor: Editor | null, tooltipId: string, instant: boolean = false) {
76
+ const hide = () => {
77
+ // Only hide if this is the current tooltip
78
+ if (this.currentTooltip.get()?.id === tooltipId) {
79
+ this.currentTooltip.set(null)
80
+ this.destroyTimeoutId = null
81
+ }
82
+ }
83
+
84
+ if (editor && !instant) {
85
+ // Start destroy timeout (1 second)
86
+ this.destroyTimeoutId = editor.timers.setTimeout(hide, 300)
87
+ } else {
88
+ hide()
89
+ }
90
+ }
91
+
92
+ hideAllTooltips() {
93
+ this.currentTooltip.set(null)
94
+ this.destroyTimeoutId = null
95
+ }
96
+
97
+ getCurrentTooltipData() {
98
+ const currentTooltip = this.currentTooltip.get()
99
+ if (!currentTooltip) return null
100
+ if (!this.supportsHover() && !currentTooltip.showOnMobile) return null
101
+ return currentTooltip
102
+ }
103
+
104
+ private supportsHoverAtom: Atom<boolean> | null = null
105
+ supportsHover() {
106
+ if (!this.supportsHoverAtom) {
107
+ const mediaQuery = window.matchMedia('(hover: hover)')
108
+ const supportsHover = atom('has hover', mediaQuery.matches)
109
+ this.supportsHoverAtom = supportsHover
110
+ mediaQuery.addEventListener('change', (e) => {
111
+ supportsHover.set(e.matches)
112
+ })
113
+ }
114
+ return this.supportsHoverAtom.get()
115
+ }
116
+ }
117
+
118
+ export const tooltipManager = TooltipManager.getInstance()
119
+
120
+ // Context for the tooltip singleton
121
+ const TooltipSingletonContext = createContext<boolean>(false)
122
+
123
+ /** @public */
124
+ export interface TldrawUiTooltipProviderProps {
125
+ children: React.ReactNode
126
+ }
127
+
128
+ /** @public @react */
129
+ export function TldrawUiTooltipProvider({ children }: TldrawUiTooltipProviderProps) {
130
+ return (
131
+ <_Tooltip.Provider skipDelayDuration={700}>
132
+ <TooltipSingletonContext.Provider value={true}>
133
+ {children}
134
+ <TooltipSingleton />
135
+ </TooltipSingletonContext.Provider>
136
+ </_Tooltip.Provider>
137
+ )
138
+ }
139
+
140
+ // The singleton tooltip component that renders once
141
+ function TooltipSingleton() {
142
+ const [isOpen, setIsOpen] = useState(false)
143
+ const triggerRef = useRef<HTMLDivElement>(null)
144
+ const isFirstShowRef = useRef(true)
145
+ const editor = useMaybeEditor()
146
+
147
+ const currentTooltip = useValue(
148
+ 'current tooltip',
149
+ () => tooltipManager.getCurrentTooltipData(),
150
+ []
151
+ )
152
+
153
+ const cameraState = useValue('camera state', () => editor?.getCameraState(), [editor])
154
+
155
+ // Hide tooltip when camera is moving (panning/zooming)
156
+ useEffect(() => {
157
+ if (cameraState === 'moving' && isOpen && currentTooltip) {
158
+ tooltipManager.hideTooltip(editor, currentTooltip.id, true)
159
+ }
160
+ }, [cameraState, isOpen, currentTooltip, editor])
161
+
162
+ // Update open state and trigger position
163
+ useEffect(() => {
164
+ let timer: ReturnType<typeof setTimeout> | null = null
165
+ if (currentTooltip && triggerRef.current) {
166
+ // Position the invisible trigger element over the active element
167
+ const activeRect = currentTooltip.targetElement.getBoundingClientRect()
168
+ const trigger = triggerRef.current
169
+
170
+ trigger.style.position = 'fixed'
171
+ trigger.style.left = `${activeRect.left}px`
172
+ trigger.style.top = `${activeRect.top}px`
173
+ trigger.style.width = `${activeRect.width}px`
174
+ trigger.style.height = `${activeRect.height}px`
175
+ trigger.style.pointerEvents = 'none'
176
+ trigger.style.zIndex = '9999'
177
+
178
+ // Handle delay for first show
179
+ if (isFirstShowRef.current) {
180
+ // eslint-disable-next-line no-restricted-globals
181
+ timer = setTimeout(() => {
182
+ setIsOpen(true)
183
+ isFirstShowRef.current = false
184
+ }, currentTooltip.delayDuration)
185
+ } else {
186
+ // Subsequent tooltips show immediately
187
+ setIsOpen(true)
188
+ }
189
+ } else {
190
+ // Hide tooltip immediately
191
+ setIsOpen(false)
192
+ // Reset first show state after tooltip is hidden
193
+ isFirstShowRef.current = true
194
+ }
195
+
196
+ return () => {
197
+ if (timer !== null) {
198
+ clearTimeout(timer)
199
+ }
200
+ }
201
+ }, [currentTooltip])
202
+
203
+ if (!currentTooltip) {
204
+ return null
205
+ }
206
+
207
+ return (
208
+ <_Tooltip.Root open={isOpen} delayDuration={0}>
209
+ <_Tooltip.Trigger asChild>
210
+ <div ref={triggerRef} />
211
+ </_Tooltip.Trigger>
212
+ <_Tooltip.Content
213
+ className="tlui-tooltip"
214
+ side={currentTooltip.side}
215
+ sideOffset={currentTooltip.sideOffset}
216
+ avoidCollisions
217
+ collisionPadding={8}
218
+ dir="ltr"
219
+ >
220
+ {currentTooltip.content}
221
+ <_Tooltip.Arrow className="tlui-tooltip__arrow" />
222
+ </_Tooltip.Content>
223
+ </_Tooltip.Root>
224
+ )
225
+ }
226
+
227
+ /** @public @react */
228
+ export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProps>(
229
+ (
230
+ {
231
+ children,
232
+ content,
233
+ side,
234
+ sideOffset = 5,
235
+ disabled = false,
236
+ showOnMobile = false,
237
+ delayDuration,
238
+ },
239
+ ref
240
+ ) => {
241
+ const editor = useMaybeEditor()
242
+ const tooltipId = useRef<string>(uniqueId())
243
+ const hasProvider = useContext(TooltipSingletonContext)
244
+
245
+ const orientationCtx = useTldrawUiOrientation()
246
+ const sideToUse = side ?? orientationCtx.tooltipSide
247
+
248
+ useEffect(() => {
249
+ const currentTooltipId = tooltipId.current
250
+ return () => {
251
+ if (hasProvider) {
252
+ tooltipManager.hideTooltip(editor, currentTooltipId, true)
253
+ }
254
+ }
255
+ }, [editor, hasProvider])
256
+
257
+ // Don't show tooltip if disabled, no content, or UI labels are disabled
258
+ if (disabled || !content) {
259
+ return <>{children}</>
260
+ }
261
+
262
+ const delayDurationToUse =
263
+ delayDuration ?? (editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS)
264
+
265
+ // Fallback to old behavior if no provider
266
+ if (!hasProvider) {
267
+ return (
268
+ <_Tooltip.Root delayDuration={delayDurationToUse} disableHoverableContent>
269
+ <_Tooltip.Trigger asChild ref={ref}>
270
+ {children}
271
+ </_Tooltip.Trigger>
272
+ <_Tooltip.Content
273
+ className="tlui-tooltip"
274
+ side={sideToUse}
275
+ sideOffset={sideOffset}
276
+ avoidCollisions
277
+ collisionPadding={8}
278
+ dir="ltr"
279
+ >
280
+ {content}
281
+ <_Tooltip.Arrow className="tlui-tooltip__arrow" />
282
+ </_Tooltip.Content>
283
+ </_Tooltip.Root>
284
+ )
285
+ }
286
+
287
+ const child = React.Children.only(children)
288
+ assert(React.isValidElement(child), 'TldrawUiTooltip children must be a single element')
289
+
290
+ const handleMouseEnter = (event: React.MouseEvent<HTMLElement>) => {
291
+ child.props.onMouseEnter?.(event)
292
+ tooltipManager.showTooltip(
293
+ tooltipId.current,
294
+ content,
295
+ event.currentTarget as HTMLElement,
296
+ sideToUse,
297
+ sideOffset,
298
+ showOnMobile,
299
+ delayDurationToUse
300
+ )
301
+ }
302
+
303
+ const handleMouseLeave = (event: React.MouseEvent<HTMLElement>) => {
304
+ child.props.onMouseLeave?.(event)
305
+ tooltipManager.hideTooltip(editor, tooltipId.current)
306
+ }
307
+
308
+ const handleFocus = (event: React.FocusEvent<HTMLElement>) => {
309
+ child.props.onFocus?.(event)
310
+ tooltipManager.showTooltip(
311
+ tooltipId.current,
312
+ content,
313
+ event.currentTarget as HTMLElement,
314
+ sideToUse,
315
+ sideOffset,
316
+ showOnMobile,
317
+ delayDurationToUse
318
+ )
319
+ }
320
+
321
+ const handleBlur = (event: React.FocusEvent<HTMLElement>) => {
322
+ child.props.onBlur?.(event)
323
+ tooltipManager.hideTooltip(editor, tooltipId.current)
324
+ }
325
+
326
+ const childrenWithHandlers = React.cloneElement(children as React.ReactElement, {
327
+ onMouseEnter: handleMouseEnter,
328
+ onMouseLeave: handleMouseLeave,
329
+ onFocus: handleFocus,
330
+ onBlur: handleBlur,
331
+ })
332
+
333
+ return childrenWithHandlers
334
+ }
335
+ )
@@ -0,0 +1,107 @@
1
+ import classNames from 'classnames'
2
+ import { Slot } from 'radix-ui'
3
+ import { HTMLAttributes, ReactNode, createContext, forwardRef, useContext } from 'react'
4
+
5
+ /** @public */
6
+ export interface TldrawUiOrientationContext {
7
+ orientation: 'horizontal' | 'vertical'
8
+ tooltipSide: 'top' | 'right' | 'bottom' | 'left'
9
+ }
10
+
11
+ const TldrawUiOrientationContext = createContext<TldrawUiOrientationContext>({
12
+ orientation: 'horizontal',
13
+ tooltipSide: 'bottom',
14
+ })
15
+
16
+ /** @public */
17
+ export interface TldrawUiOrientationProviderProps {
18
+ children: ReactNode
19
+ orientation: 'horizontal' | 'vertical'
20
+ tooltipSide?: 'top' | 'right' | 'bottom' | 'left'
21
+ }
22
+ /** @public @react */
23
+ export function TldrawUiOrientationProvider({
24
+ children,
25
+ orientation,
26
+ tooltipSide,
27
+ }: TldrawUiOrientationProviderProps) {
28
+ const prevContext = useTldrawUiOrientation()
29
+ // generally, we want tooltip side to cascade down through the layout - apart from when the
30
+ // orientation changes. If the tooltip side is "bottom", and then I include some vertical layout
31
+ // elements, keeping the tooltip side as bottom will cause the tooltip to overlap elements
32
+ // stacked on top of each other. In the absence of a tooltip side, we pick a default side based
33
+ // on the orientation whenever the orientation changes.
34
+ const tooltipSideToUse =
35
+ tooltipSide ??
36
+ (orientation === prevContext.orientation
37
+ ? prevContext.tooltipSide
38
+ : orientation === 'horizontal'
39
+ ? 'bottom'
40
+ : 'right')
41
+
42
+ return (
43
+ <TldrawUiOrientationContext.Provider value={{ orientation, tooltipSide: tooltipSideToUse }}>
44
+ {children}
45
+ </TldrawUiOrientationContext.Provider>
46
+ )
47
+ }
48
+
49
+ /** @public */
50
+ export function useTldrawUiOrientation() {
51
+ return useContext(TldrawUiOrientationContext)
52
+ }
53
+
54
+ /** @public */
55
+ export interface TLUiLayoutProps extends HTMLAttributes<HTMLDivElement> {
56
+ children: ReactNode
57
+ tooltipSide?: 'top' | 'right' | 'bottom' | 'left'
58
+ asChild?: boolean
59
+ }
60
+
61
+ /**
62
+ * A row, usually of UI controls like buttons, select dropdown, checkboxes, etc.
63
+ *
64
+ * @public @react
65
+ */
66
+ export const TldrawUiRow = forwardRef<HTMLDivElement, TLUiLayoutProps>(
67
+ ({ asChild, className, tooltipSide, ...props }, ref) => {
68
+ const Component = asChild ? Slot.Root : 'div'
69
+ return (
70
+ <TldrawUiOrientationProvider orientation="horizontal" tooltipSide={tooltipSide}>
71
+ <Component ref={ref} className={classNames('tlui-row', className)} {...props} />
72
+ </TldrawUiOrientationProvider>
73
+ )
74
+ }
75
+ )
76
+
77
+ /**
78
+ * A column, usually of UI controls like buttons, select dropdown, checkboxes, etc.
79
+ *
80
+ * @public @react
81
+ */
82
+ export const TldrawUiColumn = forwardRef<HTMLDivElement, TLUiLayoutProps>(
83
+ ({ asChild, className, tooltipSide, ...props }, ref) => {
84
+ const Component = asChild ? Slot.Root : 'div'
85
+ return (
86
+ <TldrawUiOrientationProvider orientation="vertical" tooltipSide={tooltipSide}>
87
+ <Component ref={ref} className={classNames('tlui-column', className)} {...props} />
88
+ </TldrawUiOrientationProvider>
89
+ )
90
+ }
91
+ )
92
+
93
+ /**
94
+ * A tight grid 4 elements wide, usually of UI controls like buttons, select dropdown, checkboxes,
95
+ * etc.
96
+ *
97
+ * @public @react */
98
+ export const TldrawUiGrid = forwardRef<HTMLDivElement, TLUiLayoutProps>(
99
+ ({ asChild, className, tooltipSide, ...props }, ref) => {
100
+ const Component = asChild ? Slot.Root : 'div'
101
+ return (
102
+ <TldrawUiOrientationProvider orientation="horizontal" tooltipSide={tooltipSide}>
103
+ <Component ref={ref} className={classNames('tlui-grid', className)} {...props} />
104
+ </TldrawUiOrientationProvider>
105
+ )
106
+ }
107
+ )
@@ -3,7 +3,6 @@ import { TLUiEventSource } from '../../../context/events'
3
3
 
4
4
  /** @public */
5
5
  export type TLUiMenuContextType =
6
- | 'panel'
7
6
  | 'menu'
8
7
  | 'small-icons'
9
8
  | 'context-menu'