tldraw 3.16.0-canary.5dac57cf9465 → 3.16.0-canary.5f82fb812214

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 (330) hide show
  1. package/dist-cjs/index.d.ts +170 -7
  2. package/dist-cjs/index.js +13 -1
  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/elbow/ElbowArrowDebug.js +3 -3
  13. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  14. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
  15. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
  16. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +1 -1
  17. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +1 -1
  18. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +18 -12
  19. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js +1 -1
  21. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js.map +2 -2
  22. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +2 -2
  23. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  24. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
  25. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
  26. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
  27. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  28. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +6 -3
  29. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +2 -2
  30. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
  31. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  32. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
  33. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  34. package/dist-cjs/lib/shapes/shared/ShapeFill.js +4 -4
  35. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  36. package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
  37. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +2 -2
  38. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  39. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  40. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  41. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +25 -1
  42. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  43. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js +12 -0
  44. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  45. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  46. package/dist-cjs/lib/ui/TldrawUi.js +27 -12
  47. package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
  48. package/dist-cjs/lib/ui/assetUrls.js +13 -10
  49. package/dist-cjs/lib/ui/assetUrls.js.map +2 -2
  50. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +10 -2
  51. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  52. package/dist-cjs/lib/ui/components/{FollowingIndicator.js → DefaultFollowingIndicator.js} +6 -6
  53. package/dist-cjs/lib/ui/components/DefaultFollowingIndicator.js.map +7 -0
  54. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +6 -6
  55. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +1 -1
  56. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  57. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  58. package/dist-cjs/lib/ui/components/MobileStylePanel.js +5 -3
  59. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  60. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js +1 -1
  61. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +2 -2
  62. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +3 -2
  63. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  64. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +39 -10
  65. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  66. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +66 -22
  67. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
  68. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js +15 -3
  69. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js.map +2 -2
  70. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +3 -3
  71. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  72. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +188 -78
  73. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
  74. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js +1 -1
  75. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +2 -2
  76. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +10 -1
  77. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  78. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +17 -4
  79. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  80. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +15 -3
  81. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  82. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +159 -160
  83. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  84. package/dist-cjs/lib/ui/components/primitives/layout.js +30 -5
  85. package/dist-cjs/lib/ui/components/primitives/layout.js.map +2 -2
  86. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  87. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +25 -12
  88. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  89. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +154 -19
  90. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  91. package/dist-cjs/lib/ui/context/actions.js +16 -2
  92. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  93. package/dist-cjs/lib/ui/context/components.js +2 -0
  94. package/dist-cjs/lib/ui/context/components.js.map +2 -2
  95. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  96. package/dist-cjs/lib/ui/hooks/useTools.js +94 -9
  97. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  98. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  99. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +2 -0
  100. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  101. package/dist-cjs/lib/ui/kbd-utils.js +9 -3
  102. package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
  103. package/dist-cjs/lib/ui/version.js +3 -3
  104. package/dist-cjs/lib/ui/version.js.map +1 -1
  105. package/dist-esm/index.d.mts +170 -7
  106. package/dist-esm/index.mjs +20 -3
  107. package/dist-esm/index.mjs.map +2 -2
  108. package/dist-esm/lib/Tldraw.mjs +14 -4
  109. package/dist-esm/lib/Tldraw.mjs.map +2 -2
  110. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  111. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  112. package/dist-esm/lib/defaultExternalContentHandlers.mjs +5 -4
  113. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  114. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
  115. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  116. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  117. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  118. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
  119. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  120. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  121. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  122. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +19 -12
  123. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  124. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  125. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  126. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -2
  127. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  128. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
  129. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
  130. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
  131. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  132. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +6 -3
  133. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +2 -2
  134. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
  135. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  136. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -4
  137. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  138. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +5 -4
  139. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  140. package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
  141. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +3 -2
  142. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  143. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  144. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  145. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +26 -1
  146. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  147. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +13 -0
  148. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  149. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  150. package/dist-esm/lib/ui/TldrawUi.mjs +29 -14
  151. package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
  152. package/dist-esm/lib/ui/assetUrls.mjs +13 -10
  153. package/dist-esm/lib/ui/assetUrls.mjs.map +2 -2
  154. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +10 -2
  155. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  156. package/dist-esm/lib/ui/components/{FollowingIndicator.mjs → DefaultFollowingIndicator.mjs} +3 -3
  157. package/dist-esm/lib/ui/components/DefaultFollowingIndicator.mjs.map +7 -0
  158. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +6 -6
  159. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +1 -1
  160. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  161. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  162. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +6 -3
  163. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  164. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs +1 -1
  165. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +2 -2
  166. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +3 -2
  167. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  168. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +39 -10
  169. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  170. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +56 -22
  171. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
  172. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs +15 -3
  173. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs.map +2 -2
  174. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
  175. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  176. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -80
  177. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
  178. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +2 -1
  179. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +2 -2
  180. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +10 -1
  181. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  182. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +17 -4
  183. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  184. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +16 -4
  185. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  186. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +168 -162
  187. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  188. package/dist-esm/lib/ui/components/primitives/layout.mjs +31 -6
  189. package/dist-esm/lib/ui/components/primitives/layout.mjs.map +2 -2
  190. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  191. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +25 -12
  192. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  193. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +162 -21
  194. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  195. package/dist-esm/lib/ui/context/actions.mjs +16 -2
  196. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  197. package/dist-esm/lib/ui/context/components.mjs +2 -0
  198. package/dist-esm/lib/ui/context/components.mjs.map +2 -2
  199. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  200. package/dist-esm/lib/ui/hooks/useTools.mjs +102 -10
  201. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  202. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +2 -0
  203. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  204. package/dist-esm/lib/ui/kbd-utils.mjs +9 -3
  205. package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
  206. package/dist-esm/lib/ui/version.mjs +3 -3
  207. package/dist-esm/lib/ui/version.mjs.map +1 -1
  208. package/package.json +11 -34
  209. package/src/index.ts +13 -1
  210. package/src/lib/Tldraw.tsx +15 -2
  211. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  212. package/src/lib/defaultExternalContentHandlers.ts +12 -4
  213. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +2 -1
  214. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +4 -3
  215. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +7 -6
  216. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
  217. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  218. package/src/lib/shapes/draw/DrawShapeTool.test.ts +0 -5
  219. package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
  220. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  221. package/src/lib/shapes/frame/FrameShapeUtil.tsx +29 -14
  222. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  223. package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -2
  224. package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
  225. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
  226. package/src/lib/shapes/image/ImageShapeUtil.tsx +6 -3
  227. package/src/lib/shapes/line/LineShapeUtil.test.tsx +4 -3
  228. package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
  229. package/src/lib/shapes/line/__snapshots__/LineShapeUtil.test.tsx.snap +2 -2
  230. package/src/lib/shapes/note/NoteShapeUtil.tsx +9 -4
  231. package/src/lib/shapes/shared/ShapeFill.tsx +5 -4
  232. package/src/lib/shapes/shared/freehand/svg.ts +2 -0
  233. package/src/lib/shapes/text/TextShapeTool.test.ts +6 -5
  234. package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
  235. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  236. package/src/lib/tools/EraserTool/childStates/Erasing.ts +34 -1
  237. package/src/lib/tools/EraserTool/childStates/Pointing.ts +20 -0
  238. package/src/lib/tools/SelectTool/childStates/Translating.ts +0 -1
  239. package/src/lib/ui/TldrawUi.tsx +33 -12
  240. package/src/lib/ui/assetUrls.ts +13 -10
  241. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +13 -2
  242. package/src/lib/ui/components/{FollowingIndicator.tsx → DefaultFollowingIndicator.tsx} +2 -1
  243. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +6 -6
  244. package/src/lib/ui/components/Minimap/MinimapManager.ts +4 -4
  245. package/src/lib/ui/components/MobileStylePanel.tsx +9 -6
  246. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +1 -1
  247. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +4 -3
  248. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +33 -16
  249. package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +55 -24
  250. package/src/lib/ui/components/Toolbar/DefaultVideoToolbarContent.tsx +12 -4
  251. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +5 -5
  252. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +208 -56
  253. package/src/lib/ui/components/primitives/TldrawUiButtonPicker.tsx +3 -2
  254. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +6 -1
  255. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +50 -30
  256. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +22 -5
  257. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +202 -184
  258. package/src/lib/ui/components/primitives/layout.tsx +79 -5
  259. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  260. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +29 -16
  261. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +221 -18
  262. package/src/lib/ui/context/actions.tsx +16 -2
  263. package/src/lib/ui/context/components.tsx +3 -0
  264. package/src/lib/ui/context/events.tsx +2 -1
  265. package/src/lib/ui/hooks/useTools.tsx +140 -10
  266. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +2 -0
  267. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +2 -0
  268. package/src/lib/ui/kbd-utils.ts +10 -3
  269. package/src/lib/ui/version.ts +3 -3
  270. package/src/lib/ui.css +349 -243
  271. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +5 -5
  272. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +4 -4
  273. package/src/test/A11y.test.tsx +3 -2
  274. package/src/test/ClickManager.test.ts +7 -6
  275. package/src/test/Editor.test.tsx +20 -19
  276. package/src/test/EraserTool.test.ts +184 -13
  277. package/src/test/HandTool.test.ts +10 -9
  278. package/src/test/HighlightShape.test.ts +2 -1
  279. package/src/test/SelectTool.test.ts +3 -2
  280. package/src/test/TLUserPreferences.test.ts +4 -3
  281. package/src/test/TestEditor.ts +13 -15
  282. package/src/test/TldrawEditor.test.tsx +11 -10
  283. package/src/test/ZoomTool.test.ts +7 -6
  284. package/src/test/__snapshots__/drawing.test.ts.snap +2 -2
  285. package/src/test/__snapshots__/groups.test.tsx.snap +6 -6
  286. package/src/test/__snapshots__/resizing.test.ts.snap +2 -2
  287. package/src/test/arrows-megabus.test.tsx +5 -4
  288. package/src/test/bindings.test.tsx +24 -37
  289. package/src/test/bookmark-shapes.test.ts +1 -8
  290. package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +23 -7
  291. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +8 -8
  292. package/src/test/commands/__snapshots__/zoomToFit.test.ts.snap +2 -2
  293. package/src/test/commands/alignShapes.test.tsx +25 -24
  294. package/src/test/commands/animationSpeed.test.ts +2 -1
  295. package/src/test/commands/centerOnPoint.test.ts +3 -2
  296. package/src/test/commands/clipboard.test.ts +3 -2
  297. package/src/test/commands/createShapes.test.ts +2 -1
  298. package/src/test/commands/deleteShapes.test.ts +2 -1
  299. package/src/test/commands/distributeShapes.test.tsx +11 -10
  300. package/src/test/commands/getSvgString.test.ts +2 -1
  301. package/src/test/commands/packShapes.test.ts +5 -4
  302. package/src/test/commands/resizeShape.test.ts +2 -1
  303. package/src/test/commands/rotateShapes.test.ts +7 -6
  304. package/src/test/commands/setCamera.test.ts +4 -3
  305. package/src/test/commands/setCurrentPage.test.ts +3 -2
  306. package/src/test/commands/stackShapes.test.ts +11 -10
  307. package/src/test/commands/stretch.test.tsx +13 -12
  308. package/src/test/createDeepLink.test.tsx +2 -1
  309. package/src/test/cropping.test.ts +3 -2
  310. package/src/test/custom-clipping.test.ts +436 -0
  311. package/src/test/drawing.test.ts +2 -1
  312. package/src/test/flipShapes.test.ts +4 -3
  313. package/src/test/frames.test.ts +25 -24
  314. package/src/test/getCulledShapes.test.tsx +3 -2
  315. package/src/test/groups.test.tsx +1 -1
  316. package/src/test/handleDeepLink.test.tsx +2 -1
  317. package/src/test/maxShapes.test.ts +3 -2
  318. package/src/test/modifiers.test.ts +5 -4
  319. package/src/test/navigation.test.ts +12 -11
  320. package/src/test/panning.test.ts +2 -1
  321. package/src/test/perf/perf.test.ts +2 -1
  322. package/src/test/registerDeepLinkListener.test.tsx +10 -9
  323. package/src/test/resizing.test.ts +39 -38
  324. package/src/test/select.test.tsx +4 -3
  325. package/src/test/selection-omnibus.test.ts +11 -10
  326. package/src/test/shapeutils.test.ts +4 -3
  327. package/src/test/translating.test.ts +9 -8
  328. package/tldraw.css +650 -533
  329. package/dist-cjs/lib/ui/components/FollowingIndicator.js.map +0 -7
  330. package/dist-esm/lib/ui/components/FollowingIndicator.mjs.map +0 -7
@@ -32,9 +32,11 @@ __export(TldrawUiSlider_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(TldrawUiSlider_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_editor = require("@tldraw/editor");
35
36
  var import_radix_ui = require("radix-ui");
36
37
  var import_react = __toESM(require("react"));
37
38
  var import_useTranslation = require("../../hooks/useTranslation/useTranslation");
39
+ var import_TldrawUiTooltip = require("./TldrawUiTooltip");
38
40
  const TldrawUiSlider = import_react.default.forwardRef(function Slider({
39
41
  onHistoryMark,
40
42
  title,
@@ -47,6 +49,7 @@ const TldrawUiSlider = import_react.default.forwardRef(function Slider({
47
49
  ariaValueModifier = 1
48
50
  }, ref) {
49
51
  const msg = (0, import_useTranslation.useTranslation)();
52
+ const [titleAndLabel, setTitleAndLabel] = (0, import_react.useState)("");
50
53
  const [tabIndex, setTabIndex] = (0, import_react.useState)(-1);
51
54
  (0, import_react.useEffect)(() => {
52
55
  setTabIndex(0);
@@ -58,14 +61,25 @@ const TldrawUiSlider = import_react.default.forwardRef(function Slider({
58
61
  [onValueChange]
59
62
  );
60
63
  const handlePointerDown = (0, import_react.useCallback)(() => {
64
+ import_TldrawUiTooltip.tooltipManager.hideAllTooltips();
61
65
  onHistoryMark("click slider");
62
66
  }, [onHistoryMark]);
67
+ (0, import_react.useEffect)(() => {
68
+ const timeout = import_editor.tltime.setTimeout(
69
+ "set title and label",
70
+ () => {
71
+ setTitleAndLabel(title + " \u2014 " + msg(label));
72
+ },
73
+ 0
74
+ );
75
+ return () => clearTimeout(timeout);
76
+ }, [label, msg, title]);
63
77
  const handleKeyEvent = (0, import_react.useCallback)((event) => {
64
78
  if (event.key === "Tab") {
65
79
  event.stopPropagation();
66
80
  }
67
81
  }, []);
68
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tlui-slider__container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tlui-slider__container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiTooltip.TldrawUiTooltip, { content: titleAndLabel, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
69
83
  import_radix_ui.Slider.Root,
70
84
  {
71
85
  "data-testid": testId,
@@ -79,7 +93,6 @@ const TldrawUiSlider = import_react.default.forwardRef(function Slider({
79
93
  onValueChange: handleValueChange,
80
94
  onKeyDownCapture: handleKeyEvent,
81
95
  onKeyUpCapture: handleKeyEvent,
82
- title: title + " \u2014 " + msg(label),
83
96
  children: [
84
97
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Slider.Track, { className: "tlui-slider__track", dir: "ltr", children: value !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Slider.Range, { className: "tlui-slider__range", dir: "ltr" }) }),
85
98
  value !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -88,7 +101,7 @@ const TldrawUiSlider = import_react.default.forwardRef(function Slider({
88
101
  "aria-valuemin": (min ?? 0) * ariaValueModifier,
89
102
  "aria-valuenow": value * ariaValueModifier,
90
103
  "aria-valuemax": steps * ariaValueModifier,
91
- "aria-label": title + " \u2014 " + msg(label),
104
+ "aria-label": titleAndLabel,
92
105
  className: "tlui-slider__thumb",
93
106
  dir: "ltr",
94
107
  ref,
@@ -97,6 +110,6 @@ const TldrawUiSlider = import_react.default.forwardRef(function Slider({
97
110
  )
98
111
  ]
99
112
  }
100
- ) });
113
+ ) }) });
101
114
  });
102
115
  //# sourceMappingURL=TldrawUiSlider.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/primitives/TldrawUiSlider.tsx"],
4
- "sourcesContent": ["import { Slider as _Slider } from 'radix-ui'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { TLUiTranslationKey } from '../../hooks/useTranslation/TLUiTranslationKey'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\n\n/** @public */\nexport interface TLUiSliderProps {\n\tmin?: number\n\tsteps: number\n\tvalue: number | null\n\tlabel: string\n\ttitle: string\n\tonValueChange(value: number): void\n\tonHistoryMark(id: string): void\n\t'data-testid'?: string\n\tariaValueModifier?: number\n}\n\n/** @public @react */\nexport const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(function Slider(\n\t{\n\t\tonHistoryMark,\n\t\ttitle,\n\t\tmin,\n\t\tsteps,\n\t\tvalue,\n\t\tlabel,\n\t\tonValueChange,\n\t\t['data-testid']: testId,\n\t\tariaValueModifier = 1,\n\t}: TLUiSliderProps,\n\tref\n) {\n\tconst msg = useTranslation()\n\n\t// XXX: Radix starts out our slider with a tabIndex of 0\n\t// This causes some tab focusing issues, most prevelant in MobileStylePanel,\n\t// where it grabs the focus. This works around it.\n\tconst [tabIndex, setTabIndex] = useState(-1)\n\tuseEffect(() => {\n\t\tsetTabIndex(0)\n\t}, [])\n\n\tconst handleValueChange = useCallback(\n\t\t(value: number[]) => {\n\t\t\tonValueChange(value[0])\n\t\t},\n\t\t[onValueChange]\n\t)\n\n\tconst handlePointerDown = useCallback(() => {\n\t\tonHistoryMark('click slider')\n\t}, [onHistoryMark])\n\n\t// N.B. Annoying. For a11y purposes, we need Tab to work.\n\t// For some reason, Radix has some custom behavior here\n\t// that interferes with tabbing past the slider and then\n\t// you get stuck in the slider.\n\tconst handleKeyEvent = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key === 'Tab') {\n\t\t\tevent.stopPropagation()\n\t\t}\n\t}, [])\n\n\treturn (\n\t\t<div className=\"tlui-slider__container\">\n\t\t\t<_Slider.Root\n\t\t\t\tdata-testid={testId}\n\t\t\t\tclassName=\"tlui-slider\"\n\t\t\t\tdir=\"ltr\"\n\t\t\t\tmin={min ?? 0}\n\t\t\t\tmax={steps}\n\t\t\t\tstep={1}\n\t\t\t\tvalue={value !== null ? [value] : undefined}\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\tonKeyDownCapture={handleKeyEvent}\n\t\t\t\tonKeyUpCapture={handleKeyEvent}\n\t\t\t\ttitle={title + ' \u2014 ' + msg(label as TLUiTranslationKey)}\n\t\t\t>\n\t\t\t\t<_Slider.Track className=\"tlui-slider__track\" dir=\"ltr\">\n\t\t\t\t\t{value !== null && <_Slider.Range className=\"tlui-slider__range\" dir=\"ltr\" />}\n\t\t\t\t</_Slider.Track>\n\t\t\t\t{value !== null && (\n\t\t\t\t\t<_Slider.Thumb\n\t\t\t\t\t\taria-valuemin={(min ?? 0) * ariaValueModifier}\n\t\t\t\t\t\taria-valuenow={value * ariaValueModifier}\n\t\t\t\t\t\taria-valuemax={steps * ariaValueModifier}\n\t\t\t\t\t\taria-label={title + ' \u2014 ' + msg(label as TLUiTranslationKey)}\n\t\t\t\t\t\tclassName=\"tlui-slider__thumb\"\n\t\t\t\t\t\tdir=\"ltr\"\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\ttabIndex={tabIndex}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</_Slider.Root>\n\t\t</div>\n\t)\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkEG;AAlEH,sBAAkC;AAClC,mBAAwD;AAExD,4BAA+B;AAgBxB,MAAM,iBAAiB,aAAAA,QAAM,WAA4C,SAAS,OACxF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,CAAC,aAAa,GAAG;AAAA,EACjB,oBAAoB;AACrB,GACA,KACC;AACD,QAAM,UAAM,sCAAe;AAK3B,QAAM,CAAC,UAAU,WAAW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A;AAAA,EAEF,GACD;AAEF,CAAC;",
4
+ "sourcesContent": ["import { tltime } from '@tldraw/editor'\nimport { Slider as _Slider } from 'radix-ui'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { TLUiTranslationKey } from '../../hooks/useTranslation/TLUiTranslationKey'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiTooltip, tooltipManager } from './TldrawUiTooltip'\n\n/** @public */\nexport interface TLUiSliderProps {\n\tmin?: number\n\tsteps: number\n\tvalue: number | null\n\tlabel: string\n\ttitle: string\n\tonValueChange(value: number): void\n\tonHistoryMark(id: string): void\n\t'data-testid'?: string\n\tariaValueModifier?: number\n}\n\n/** @public @react */\nexport const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(function Slider(\n\t{\n\t\tonHistoryMark,\n\t\ttitle,\n\t\tmin,\n\t\tsteps,\n\t\tvalue,\n\t\tlabel,\n\t\tonValueChange,\n\t\t['data-testid']: testId,\n\t\tariaValueModifier = 1,\n\t}: TLUiSliderProps,\n\tref\n) {\n\tconst msg = useTranslation()\n\tconst [titleAndLabel, setTitleAndLabel] = useState('')\n\n\t// XXX: Radix starts out our slider with a tabIndex of 0\n\t// This causes some tab focusing issues, most prevelant in MobileStylePanel,\n\t// where it grabs the focus. This works around it.\n\tconst [tabIndex, setTabIndex] = useState(-1)\n\tuseEffect(() => {\n\t\tsetTabIndex(0)\n\t}, [])\n\n\tconst handleValueChange = useCallback(\n\t\t(value: number[]) => {\n\t\t\tonValueChange(value[0])\n\t\t},\n\t\t[onValueChange]\n\t)\n\n\tconst handlePointerDown = useCallback(() => {\n\t\ttooltipManager.hideAllTooltips()\n\t\tonHistoryMark('click slider')\n\t}, [onHistoryMark])\n\n\t// N.B. This is a bit silly. The Radix slider auto-focuses which\n\t// triggers TldrawUiTooltip handleFocus when we dbl-click to edit an image,\n\t// which in turn makes the tooltip display prematurely.\n\t// This makes it wait until we've focused to show the tooltip.\n\tuseEffect(() => {\n\t\tconst timeout = tltime.setTimeout(\n\t\t\t'set title and label',\n\t\t\t() => {\n\t\t\t\tsetTitleAndLabel(title + ' \u2014 ' + msg(label as TLUiTranslationKey))\n\t\t\t},\n\t\t\t0\n\t\t)\n\t\treturn () => clearTimeout(timeout)\n\t}, [label, msg, title])\n\n\t// N.B. Annoying. For a11y purposes, we need Tab to work.\n\t// For some reason, Radix has some custom behavior here\n\t// that interferes with tabbing past the slider and then\n\t// you get stuck in the slider.\n\tconst handleKeyEvent = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key === 'Tab') {\n\t\t\tevent.stopPropagation()\n\t\t}\n\t}, [])\n\n\treturn (\n\t\t<div className=\"tlui-slider__container\">\n\t\t\t<TldrawUiTooltip content={titleAndLabel}>\n\t\t\t\t<_Slider.Root\n\t\t\t\t\tdata-testid={testId}\n\t\t\t\t\tclassName=\"tlui-slider\"\n\t\t\t\t\tdir=\"ltr\"\n\t\t\t\t\tmin={min ?? 0}\n\t\t\t\t\tmax={steps}\n\t\t\t\t\tstep={1}\n\t\t\t\t\tvalue={value !== null ? [value] : undefined}\n\t\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\t\tonKeyDownCapture={handleKeyEvent}\n\t\t\t\t\tonKeyUpCapture={handleKeyEvent}\n\t\t\t\t>\n\t\t\t\t\t<_Slider.Track className=\"tlui-slider__track\" dir=\"ltr\">\n\t\t\t\t\t\t{value !== null && <_Slider.Range className=\"tlui-slider__range\" dir=\"ltr\" />}\n\t\t\t\t\t</_Slider.Track>\n\t\t\t\t\t{value !== null && (\n\t\t\t\t\t\t<_Slider.Thumb\n\t\t\t\t\t\t\taria-valuemin={(min ?? 0) * ariaValueModifier}\n\t\t\t\t\t\t\taria-valuenow={value * ariaValueModifier}\n\t\t\t\t\t\t\taria-valuemax={steps * ariaValueModifier}\n\t\t\t\t\t\t\taria-label={titleAndLabel}\n\t\t\t\t\t\t\tclassName=\"tlui-slider__thumb\"\n\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AiB,0BAAY,CAAC,UAA+B;AAClE,QAAI,MAAM,QAAQ,OAAO;AACxB,YAAM,gBAAgB;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAC;AAEL,SACC,4CAAC,SAAI,WAAU,0BACd,sDAAC,0CAAgB,SAAS,eACzB;AAAA,IAAC,gBAAAC,OAAQ;AAAA,IAAR;AAAA,MACA,eAAa;AAAA,MACb,WAAU;AAAA,MACV,KAAI;AAAA,MACJ,KAAK,OAAO;AAAA,MACZ,KAAK;AAAA,MACL,MAAM;AAAA,MACN,OAAO,UAAU,OAAO,CAAC,KAAK,IAAI;AAAA,MAClC,eAAe;AAAA,MACf,eAAe;AAAA,MACf,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAEhB;AAAA,oDAAC,gBAAAA,OAAQ,OAAR,EAAc,WAAU,sBAAqB,KAAI,OAChD,oBAAU,QAAQ,4CAAC,gBAAAA,OAAQ,OAAR,EAAc,WAAU,sBAAqB,KAAI,OAAM,GAC5E;AAAA,QACC,UAAU,QACV;AAAA,UAAC,gBAAAA,OAAQ;AAAA,UAAR;AAAA,YACA,kBAAgB,OAAO,KAAK;AAAA,YAC5B,iBAAe,QAAQ;AAAA,YACvB,iBAAe,QAAQ;AAAA,YACvB,cAAY;AAAA,YACZ,WAAU;AAAA,YACV,KAAI;AAAA,YACJ;AAAA,YACA;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF,GACD,GACD;AAEF,CAAC;",
6
6
  "names": ["React", "value", "_Slider"]
7
7
  }
@@ -40,10 +40,22 @@ var import_radix_ui = require("radix-ui");
40
40
  var import_react = __toESM(require("react"));
41
41
  var import_layout = require("./layout");
42
42
  var import_TldrawUiTooltip = require("./TldrawUiTooltip");
43
+ const LayoutByOrientation = {
44
+ horizontal: import_layout.TldrawUiRow,
45
+ vertical: import_layout.TldrawUiColumn,
46
+ grid: import_layout.TldrawUiGrid
47
+ };
43
48
  const TldrawUiToolbar = import_react.default.forwardRef(
44
- ({ children, className, label, orientation = "horizontal", ...props }, ref) => {
45
- const Layout = orientation === "grid" ? import_layout.TldrawUiGrid : import_layout.TldrawUiRow;
46
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
+ ({
50
+ children,
51
+ className,
52
+ label,
53
+ orientation = "horizontal",
54
+ tooltipSide,
55
+ ...props
56
+ }, ref) => {
57
+ const Layout = LayoutByOrientation[orientation];
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, { asChild: true, tooltipSide, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
47
59
  import_radix_ui.Toolbar.Root,
48
60
  {
49
61
  ref,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/primitives/TldrawUiToolbar.tsx"],
4
- "sourcesContent": ["import classnames from 'classnames'\nimport { Toolbar as _Toolbar } from 'radix-ui'\nimport React from 'react'\nimport { TldrawUiGrid, TldrawUiRow } from './layout'\nimport { TldrawUiTooltip } from './TldrawUiTooltip'\n\n/** @public */\nexport interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdir?: 'ltr' | 'rtl'\n\tlabel: string\n\torientation?: 'horizontal' | 'grid'\n}\n\n/** @public @react */\nexport const TldrawUiToolbar = React.forwardRef<HTMLDivElement, TLUiToolbarProps>(\n\t({ children, className, label, orientation = 'horizontal', ...props }: TLUiToolbarProps, ref) => {\n\t\tconst Layout = orientation === 'grid' ? TldrawUiGrid : TldrawUiRow\n\t\treturn (\n\t\t\t<Layout asChild>\n\t\t\t\t<_Toolbar.Root\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...props}\n\t\t\t\t\tclassName={classnames('tlui-toolbar', className)}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\torientation={orientation === 'grid' ? 'horizontal' : orientation}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</_Toolbar.Root>\n\t\t\t</Layout>\n\t\t)\n\t}\n)\n\n/** @public */\nexport interface TLUiToolbarButtonProps extends React.HTMLAttributes<HTMLButtonElement> {\n\tasChild?: boolean\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdisabled?: boolean\n\tisActive?: boolean\n\ttype: 'icon' | 'tool' | 'menu'\n\ttooltip?: string\n}\n\n/** @public @react */\nexport const TldrawUiToolbarButton = React.forwardRef<HTMLButtonElement, TLUiToolbarButtonProps>(\n\t({ asChild, children, type, isActive, tooltip, ...props }: TLUiToolbarButtonProps, ref) => {\n\t\tconst button = (\n\t\t\t<_Toolbar.Button\n\t\t\t\tref={ref}\n\t\t\t\tasChild={asChild}\n\t\t\t\tdraggable={false}\n\t\t\t\tdata-isactive={isActive}\n\t\t\t\t{...props}\n\t\t\t\t// The tooltip takes care of this.\n\t\t\t\ttitle={undefined}\n\t\t\t\tclassName={classnames('tlui-button', `tlui-button__${type}`, props.className)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</_Toolbar.Button>\n\t\t)\n\n\t\tconst tooltipContent = tooltip || props.title\n\n\t\treturn <TldrawUiTooltip content={tooltipContent}>{button}</TldrawUiTooltip>\n\t}\n)\n\n/** @public */\nexport interface TLUiToolbarToggleGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdir?: 'ltr' | 'rtl'\n\tvalue: any\n\t// TODO: fix up this type later\n\tdefaultValue?: any\n\ttype: 'single' | 'multiple'\n}\n\n/** @public @react */\nexport const TldrawUiToolbarToggleGroup = ({\n\tchildren,\n\tclassName,\n\ttype,\n\t...props\n}: TLUiToolbarToggleGroupProps) => {\n\treturn (\n\t\t<_Toolbar.ToggleGroup\n\t\t\ttype={type}\n\t\t\t{...props}\n\t\t\t// TODO: this fixes a bug in Radix until they fix it.\n\t\t\t// https://github.com/radix-ui/primitives/issues/3188\n\t\t\t// https://github.com/radix-ui/primitives/pull/3189\n\t\t\trole=\"radiogroup\"\n\t\t\tclassName={classnames('tlui-toolbar-toggle-group', className)}\n\t\t>\n\t\t\t{children}\n\t\t</_Toolbar.ToggleGroup>\n\t)\n}\n\n/** @public */\nexport interface TLUiToolbarToggleItemProps extends React.HTMLAttributes<HTMLButtonElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\ttype: 'icon' | 'tool'\n\tvalue: string\n\ttooltip?: string\n}\n\n/** @public @react */\nexport const TldrawUiToolbarToggleItem = ({\n\tchildren,\n\tclassName,\n\ttype,\n\tvalue,\n\ttooltip,\n\t...props\n}: TLUiToolbarToggleItemProps) => {\n\tconst toggleItem = (\n\t\t<_Toolbar.ToggleItem\n\t\t\t{...props}\n\t\t\t// The tooltip takes care of this.\n\t\t\ttitle={undefined}\n\t\t\tclassName={classnames(\n\t\t\t\t'tlui-button',\n\t\t\t\t`tlui-button__${type}`,\n\t\t\t\t'tlui-toolbar-toggle-group-item',\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tvalue={value}\n\t\t>\n\t\t\t{children}\n\t\t</_Toolbar.ToggleItem>\n\t)\n\n\tconst tooltipContent = tooltip || props.title\n\n\treturn <TldrawUiTooltip content={tooltipContent}>{toggleItem}</TldrawUiTooltip>\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AArBJ,wBAAuB;AACvB,sBAAoC;AACpC,mBAAkB;AAClB,oBAA0C;AAC1C,6BAAgC;AAYzB,MAAM,kBAAkB,aAAAA,QAAM;AAAA,EACpC,CAAC,EAAE,UAAU,WAAW,OAAO,cAAc,cAAc,GAAG,MAAM,GAAqB,QAAQ;AAChG,UAAM,SAAS,gBAAgB,SAAS,6BAAe;AACvD,WACC,4CAAC,UAAO,SAAO,MACd;AAAA,MAAC,gBAAAC,QAAS;AAAA,MAAT;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,eAAW,k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AW,MAAM;AAExC,SAAO,4CAAC,0CAAgB,SAAS,gBAAiB,sBAAW;AAC9D;",
4
+ "sourcesContent": ["import classnames from 'classnames'\nimport { Toolbar as _Toolbar } from 'radix-ui'\nimport React from 'react'\nimport { TldrawUiColumn, TldrawUiGrid, TldrawUiRow } from './layout'\nimport { TldrawUiTooltip } from './TldrawUiTooltip'\n\n/** @public */\nexport interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdir?: 'ltr' | 'rtl'\n\tlabel: string\n\torientation?: 'horizontal' | 'vertical' | 'grid'\n\ttooltipSide?: 'top' | 'right' | 'bottom' | 'left'\n}\n\nconst LayoutByOrientation = {\n\thorizontal: TldrawUiRow,\n\tvertical: TldrawUiColumn,\n\tgrid: TldrawUiGrid,\n}\n\n/** @public @react */\nexport const TldrawUiToolbar = React.forwardRef<HTMLDivElement, TLUiToolbarProps>(\n\t(\n\t\t{\n\t\t\tchildren,\n\t\t\tclassName,\n\t\t\tlabel,\n\t\t\torientation = 'horizontal',\n\t\t\ttooltipSide,\n\t\t\t...props\n\t\t}: TLUiToolbarProps,\n\t\tref\n\t) => {\n\t\tconst Layout = LayoutByOrientation[orientation]\n\t\treturn (\n\t\t\t<Layout asChild tooltipSide={tooltipSide}>\n\t\t\t\t<_Toolbar.Root\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...props}\n\t\t\t\t\tclassName={classnames('tlui-toolbar', className)}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\torientation={orientation === 'grid' ? 'horizontal' : orientation}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</_Toolbar.Root>\n\t\t\t</Layout>\n\t\t)\n\t}\n)\n\n/** @public */\nexport interface TLUiToolbarButtonProps extends React.HTMLAttributes<HTMLButtonElement> {\n\tasChild?: boolean\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdisabled?: boolean\n\tisActive?: boolean\n\ttype: 'icon' | 'tool' | 'menu'\n\ttooltip?: string\n}\n\n/** @public @react */\nexport const TldrawUiToolbarButton = React.forwardRef<HTMLButtonElement, TLUiToolbarButtonProps>(\n\t({ asChild, children, type, isActive, tooltip, ...props }: TLUiToolbarButtonProps, ref) => {\n\t\tconst button = (\n\t\t\t<_Toolbar.Button\n\t\t\t\tref={ref}\n\t\t\t\tasChild={asChild}\n\t\t\t\tdraggable={false}\n\t\t\t\tdata-isactive={isActive}\n\t\t\t\t{...props}\n\t\t\t\t// The tooltip takes care of this.\n\t\t\t\ttitle={undefined}\n\t\t\t\tclassName={classnames('tlui-button', `tlui-button__${type}`, props.className)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</_Toolbar.Button>\n\t\t)\n\n\t\tconst tooltipContent = tooltip || props.title\n\n\t\treturn <TldrawUiTooltip content={tooltipContent}>{button}</TldrawUiTooltip>\n\t}\n)\n\n/** @public */\nexport interface TLUiToolbarToggleGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tdir?: 'ltr' | 'rtl'\n\tvalue: any\n\t// TODO: fix up this type later\n\tdefaultValue?: any\n\ttype: 'single' | 'multiple'\n}\n\n/** @public @react */\nexport const TldrawUiToolbarToggleGroup = ({\n\tchildren,\n\tclassName,\n\ttype,\n\t...props\n}: TLUiToolbarToggleGroupProps) => {\n\treturn (\n\t\t<_Toolbar.ToggleGroup\n\t\t\ttype={type}\n\t\t\t{...props}\n\t\t\t// TODO: this fixes a bug in Radix until they fix it.\n\t\t\t// https://github.com/radix-ui/primitives/issues/3188\n\t\t\t// https://github.com/radix-ui/primitives/pull/3189\n\t\t\trole=\"radiogroup\"\n\t\t\tclassName={classnames('tlui-toolbar-toggle-group', className)}\n\t\t>\n\t\t\t{children}\n\t\t</_Toolbar.ToggleGroup>\n\t)\n}\n\n/** @public */\nexport interface TLUiToolbarToggleItemProps extends React.HTMLAttributes<HTMLButtonElement> {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\ttype: 'icon' | 'tool'\n\tvalue: string\n\ttooltip?: string\n}\n\n/** @public @react */\nexport const TldrawUiToolbarToggleItem = ({\n\tchildren,\n\tclassName,\n\ttype,\n\tvalue,\n\ttooltip,\n\t...props\n}: TLUiToolbarToggleItemProps) => {\n\tconst toggleItem = (\n\t\t<_Toolbar.ToggleItem\n\t\t\t{...props}\n\t\t\t// The tooltip takes care of this.\n\t\t\ttitle={undefined}\n\t\t\tclassName={classnames(\n\t\t\t\t'tlui-button',\n\t\t\t\t`tlui-button__${type}`,\n\t\t\t\t'tlui-toolbar-toggle-group-item',\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tvalue={value}\n\t\t>\n\t\t\t{children}\n\t\t</_Toolbar.ToggleItem>\n\t)\n\n\tconst tooltipContent = tooltip || props.title\n\n\treturn <TldrawUiTooltip content={tooltipContent}>{toggleItem}</TldrawUiTooltip>\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCI;AAtCJ,wBAAuB;AACvB,sBAAoC;AACpC,mBAAkB;AAClB,oBAA0D;AAC1D,6BAAgC;AAYhC,MAAM,sBAAsB;AAAA,EAC3B,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,MAAM;AACP;AAGO,MAAM,kBAAkB,aAAAA,QAAM;AAAA,EACpC,CACC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,GAAG;AAAA,EACJ,GACA,QACI;AACJ,UAAM,SAAS,oBAAoB,WAAW;AAC9C,WACC,4CAAC,UAAO,SAAO,MAAC,aACf;AAAA,MAAC,gBAAAC,QAAS;AAAA,MAAT;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,eAAW,kBAAAC,SAAW,gBAAgB,SAAS;AAAA,QAC/C,cAAY;AAAA,QACZ,aAAa,gBAAgB,SAAS,eAAe;AAAA,QAEpD;AAAA;AAA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
@@ -29,74 +29,75 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var TldrawUiTooltip_exports = {};
30
30
  __export(TldrawUiTooltip_exports, {
31
31
  TldrawUiTooltip: () => TldrawUiTooltip,
32
- TldrawUiTooltipProvider: () => TldrawUiTooltipProvider
32
+ TldrawUiTooltipProvider: () => TldrawUiTooltipProvider,
33
+ tooltipManager: () => tooltipManager
33
34
  });
34
35
  module.exports = __toCommonJS(TldrawUiTooltip_exports);
35
36
  var import_jsx_runtime = require("react/jsx-runtime");
36
37
  var import_editor = require("@tldraw/editor");
37
38
  var import_radix_ui = require("radix-ui");
38
39
  var import_react = __toESM(require("react"));
39
- var import_usePrefersReducedMotion = require("../../../shapes/shared/usePrefersReducedMotion");
40
+ var import_layout = require("./layout");
40
41
  const DEFAULT_TOOLTIP_DELAY_MS = 700;
41
42
  class TooltipManager {
42
43
  static instance = null;
43
- currentTooltipId = null;
44
- currentContent = "";
45
- currentSide = "bottom";
46
- currentSideOffset = 5;
44
+ currentTooltip = (0, import_editor.atom)("current tooltip", null);
47
45
  destroyTimeoutId = null;
48
- subscribers = /* @__PURE__ */ new Set();
49
- activeElement = null;
50
- editor = null;
51
46
  static getInstance() {
52
47
  if (!TooltipManager.instance) {
53
48
  TooltipManager.instance = new TooltipManager();
54
49
  }
55
50
  return TooltipManager.instance;
56
51
  }
57
- setEditor(editor) {
58
- this.editor = editor;
59
- }
60
- subscribe(callback) {
61
- this.subscribers.add(callback);
62
- return () => this.subscribers.delete(callback);
63
- }
64
- notify() {
65
- this.subscribers.forEach((callback) => callback());
66
- }
67
- showTooltip(tooltipId, content, element, side = "bottom", sideOffset = 5) {
52
+ showTooltip(tooltipId, content, targetElement, side, sideOffset, showOnMobile, delayDuration) {
68
53
  if (this.destroyTimeoutId) {
69
54
  clearTimeout(this.destroyTimeoutId);
70
55
  this.destroyTimeoutId = null;
71
56
  }
72
- this.currentTooltipId = tooltipId;
73
- this.currentContent = content;
74
- this.currentSide = side;
75
- this.currentSideOffset = sideOffset;
76
- this.activeElement = element;
77
- this.notify();
57
+ this.currentTooltip.set({
58
+ id: tooltipId,
59
+ content,
60
+ side,
61
+ sideOffset,
62
+ showOnMobile,
63
+ targetElement,
64
+ delayDuration
65
+ });
78
66
  }
79
- hideTooltip(tooltipId) {
80
- if (this.currentTooltipId === tooltipId) {
81
- if (this.editor) {
82
- this.destroyTimeoutId = this.editor.timers.setTimeout(() => {
83
- this.currentTooltipId = null;
84
- this.currentContent = "";
85
- this.activeElement = null;
86
- this.destroyTimeoutId = null;
87
- this.notify();
88
- }, 300);
67
+ hideTooltip(editor, tooltipId, instant = false) {
68
+ const hide = () => {
69
+ if (this.currentTooltip.get()?.id === tooltipId) {
70
+ this.currentTooltip.set(null);
71
+ this.destroyTimeoutId = null;
89
72
  }
73
+ };
74
+ if (editor && !instant) {
75
+ this.destroyTimeoutId = editor.timers.setTimeout(hide, 300);
76
+ } else {
77
+ hide();
90
78
  }
91
79
  }
80
+ hideAllTooltips() {
81
+ this.currentTooltip.set(null);
82
+ this.destroyTimeoutId = null;
83
+ }
92
84
  getCurrentTooltipData() {
93
- return {
94
- id: this.currentTooltipId,
95
- content: this.currentContent,
96
- side: this.currentSide,
97
- sideOffset: this.currentSideOffset,
98
- element: this.activeElement
99
- };
85
+ const currentTooltip = this.currentTooltip.get();
86
+ if (!currentTooltip) return null;
87
+ if (!this.supportsHover() && !currentTooltip.showOnMobile) return null;
88
+ return currentTooltip;
89
+ }
90
+ supportsHoverAtom = null;
91
+ supportsHover() {
92
+ if (!this.supportsHoverAtom) {
93
+ const mediaQuery = window.matchMedia("(hover: hover)");
94
+ const supportsHover = (0, import_editor.atom)("has hover", mediaQuery.matches);
95
+ this.supportsHoverAtom = supportsHover;
96
+ mediaQuery.addEventListener("change", (e) => {
97
+ supportsHover.set(e.matches);
98
+ });
99
+ }
100
+ return this.supportsHoverAtom.get();
100
101
  }
101
102
  }
102
103
  const tooltipManager = TooltipManager.getInstance();
@@ -108,45 +109,19 @@ function TldrawUiTooltipProvider({ children }) {
108
109
  ] }) });
109
110
  }
110
111
  function TooltipSingleton() {
111
- const editor = (0, import_editor.useMaybeEditor)();
112
- const [, forceUpdate] = (0, import_react.useState)({});
113
112
  const [isOpen, setIsOpen] = (0, import_react.useState)(false);
114
113
  const triggerRef = (0, import_react.useRef)(null);
115
- const previousPositionRef = (0, import_react.useRef)(null);
116
- const prefersReducedMotion = (0, import_usePrefersReducedMotion.usePrefersReducedMotion)();
117
- const [shouldAnimate, setShouldAnimate] = (0, import_react.useState)(false);
118
114
  const isFirstShowRef = (0, import_react.useRef)(true);
119
- const showTimeoutRef = (0, import_react.useRef)(null);
120
- (0, import_react.useEffect)(() => {
121
- tooltipManager.setEditor(editor);
122
- }, [editor]);
115
+ const currentTooltip = (0, import_editor.useValue)(
116
+ "current tooltip",
117
+ () => tooltipManager.getCurrentTooltipData(),
118
+ []
119
+ );
123
120
  (0, import_react.useEffect)(() => {
124
- const unsubscribe = tooltipManager.subscribe(() => {
125
- forceUpdate({});
126
- });
127
- return unsubscribe;
128
- }, []);
129
- const tooltipData = tooltipManager.getCurrentTooltipData();
130
- (0, import_react.useEffect)(() => {
131
- const shouldBeOpen = Boolean(tooltipData.id && tooltipData.element);
132
- if (showTimeoutRef.current) {
133
- clearTimeout(showTimeoutRef.current);
134
- showTimeoutRef.current = null;
135
- }
136
- if (shouldBeOpen && tooltipData.element && triggerRef.current) {
137
- const activeRect = tooltipData.element.getBoundingClientRect();
121
+ let timer = null;
122
+ if (currentTooltip && triggerRef.current) {
123
+ const activeRect = currentTooltip.targetElement.getBoundingClientRect();
138
124
  const trigger = triggerRef.current;
139
- const newPosition = {
140
- x: activeRect.left + activeRect.width / 2,
141
- y: activeRect.top + activeRect.height / 2
142
- };
143
- let shouldAnimateCheck = false;
144
- if (previousPositionRef.current) {
145
- const isNearPrevious = import_editor.Vec.DistMin(previousPositionRef.current, newPosition, 200);
146
- shouldAnimateCheck = !prefersReducedMotion && isNearPrevious && Math.abs(newPosition.y - previousPositionRef.current.y) < 50;
147
- }
148
- setShouldAnimate(isFirstShowRef.current ? false : shouldAnimateCheck);
149
- previousPositionRef.current = newPosition;
150
125
  trigger.style.position = "fixed";
151
126
  trigger.style.left = `${activeRect.left}px`;
152
127
  trigger.style.top = `${activeRect.top}px`;
@@ -154,22 +129,25 @@ function TooltipSingleton() {
154
129
  trigger.style.height = `${activeRect.height}px`;
155
130
  trigger.style.pointerEvents = "none";
156
131
  trigger.style.zIndex = "9999";
157
- if (isFirstShowRef.current && editor) {
158
- showTimeoutRef.current = editor.timers.setTimeout(() => {
132
+ if (isFirstShowRef.current) {
133
+ timer = setTimeout(() => {
159
134
  setIsOpen(true);
160
135
  isFirstShowRef.current = false;
161
- }, editor.options.tooltipDelayMs);
136
+ }, currentTooltip.delayDuration);
162
137
  } else {
163
138
  setIsOpen(true);
164
139
  }
165
- } else if (!shouldBeOpen) {
140
+ } else {
166
141
  setIsOpen(false);
167
- previousPositionRef.current = null;
168
- setShouldAnimate(false);
169
142
  isFirstShowRef.current = true;
170
143
  }
171
- }, [tooltipData.id, tooltipData.element, editor, prefersReducedMotion]);
172
- if (!tooltipData.id) {
144
+ return () => {
145
+ if (timer !== null) {
146
+ clearTimeout(timer);
147
+ }
148
+ };
149
+ }, [currentTooltip]);
150
+ if (!currentTooltip) {
173
151
  return null;
174
152
  }
175
153
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_radix_ui.Tooltip.Root, { open: isOpen, delayDuration: 0, children: [
@@ -178,90 +156,111 @@ function TooltipSingleton() {
178
156
  import_radix_ui.Tooltip.Content,
179
157
  {
180
158
  className: "tlui-tooltip",
181
- "data-should-animate": shouldAnimate,
182
- side: tooltipData.side,
183
- sideOffset: tooltipData.sideOffset,
159
+ side: currentTooltip.side,
160
+ sideOffset: currentTooltip.sideOffset,
184
161
  avoidCollisions: true,
185
162
  collisionPadding: 8,
186
163
  dir: "ltr",
187
164
  children: [
188
- tooltipData.content,
165
+ currentTooltip.content,
189
166
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Tooltip.Arrow, { className: "tlui-tooltip__arrow" })
190
167
  ]
191
168
  }
192
169
  )
193
170
  ] });
194
171
  }
195
- function TldrawUiTooltip({
196
- children,
197
- content,
198
- side = "bottom",
199
- sideOffset = 5,
200
- disabled = false
201
- }) {
202
- const editor = (0, import_editor.useMaybeEditor)();
203
- const tooltipId = (0, import_react.useRef)((0, import_editor.uniqueId)());
204
- const hasProvider = (0, import_react.useContext)(TooltipSingletonContext);
205
- if (disabled || !content) {
206
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
207
- }
208
- if (!hasProvider) {
209
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
210
- import_radix_ui.Tooltip.Root,
211
- {
212
- delayDuration: editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS,
213
- disableHoverableContent: true,
214
- children: [
215
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Tooltip.Trigger, { asChild: true, children }),
216
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
217
- import_radix_ui.Tooltip.Content,
218
- {
219
- className: "tlui-tooltip",
220
- side,
221
- sideOffset,
222
- avoidCollisions: true,
223
- collisionPadding: 8,
224
- dir: "ltr",
225
- children: [
226
- content,
227
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Tooltip.Arrow, { className: "tlui-tooltip__arrow" })
228
- ]
229
- }
230
- )
231
- ]
232
- }
233
- );
172
+ const TldrawUiTooltip = (0, import_react.forwardRef)(
173
+ ({
174
+ children,
175
+ content,
176
+ side,
177
+ sideOffset = 5,
178
+ disabled = false,
179
+ showOnMobile = false,
180
+ delayDuration
181
+ }, ref) => {
182
+ const editor = (0, import_editor.useMaybeEditor)();
183
+ const tooltipId = (0, import_react.useRef)((0, import_editor.uniqueId)());
184
+ const hasProvider = (0, import_react.useContext)(TooltipSingletonContext);
185
+ const orientationCtx = (0, import_layout.useTldrawUiOrientation)();
186
+ const sideToUse = side ?? orientationCtx.tooltipSide;
187
+ const camera = (0, import_editor.useValue)("camera", () => editor?.getCamera(), []);
188
+ (0, import_react.useEffect)(() => {
189
+ const currentTooltipId = tooltipId.current;
190
+ return () => {
191
+ if (hasProvider) {
192
+ tooltipManager.hideTooltip(editor, currentTooltipId, true);
193
+ }
194
+ };
195
+ }, [editor, hasProvider]);
196
+ (0, import_react.useEffect)(() => {
197
+ tooltipManager.hideTooltip(editor, tooltipId.current, true);
198
+ }, [editor, camera]);
199
+ if (disabled || !content) {
200
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
201
+ }
202
+ const delayDurationToUse = delayDuration ?? (editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS);
203
+ if (!hasProvider) {
204
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_radix_ui.Tooltip.Root, { delayDuration: delayDurationToUse, disableHoverableContent: true, children: [
205
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Tooltip.Trigger, { asChild: true, ref, children }),
206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
207
+ import_radix_ui.Tooltip.Content,
208
+ {
209
+ className: "tlui-tooltip",
210
+ side: sideToUse,
211
+ sideOffset,
212
+ avoidCollisions: true,
213
+ collisionPadding: 8,
214
+ dir: "ltr",
215
+ children: [
216
+ content,
217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Tooltip.Arrow, { className: "tlui-tooltip__arrow" })
218
+ ]
219
+ }
220
+ )
221
+ ] });
222
+ }
223
+ const child = import_react.default.Children.only(children);
224
+ (0, import_editor.assert)(import_react.default.isValidElement(child), "TldrawUiTooltip children must be a single element");
225
+ const handleMouseEnter = (event) => {
226
+ child.props.onMouseEnter?.(event);
227
+ tooltipManager.showTooltip(
228
+ tooltipId.current,
229
+ content,
230
+ event.currentTarget,
231
+ sideToUse,
232
+ sideOffset,
233
+ showOnMobile,
234
+ delayDurationToUse
235
+ );
236
+ };
237
+ const handleMouseLeave = (event) => {
238
+ child.props.onMouseLeave?.(event);
239
+ tooltipManager.hideTooltip(editor, tooltipId.current);
240
+ };
241
+ const handleFocus = (event) => {
242
+ child.props.onFocus?.(event);
243
+ tooltipManager.showTooltip(
244
+ tooltipId.current,
245
+ content,
246
+ event.currentTarget,
247
+ sideToUse,
248
+ sideOffset,
249
+ showOnMobile,
250
+ delayDurationToUse
251
+ );
252
+ };
253
+ const handleBlur = (event) => {
254
+ child.props.onBlur?.(event);
255
+ tooltipManager.hideTooltip(editor, tooltipId.current);
256
+ };
257
+ const childrenWithHandlers = import_react.default.cloneElement(children, {
258
+ onMouseEnter: handleMouseEnter,
259
+ onMouseLeave: handleMouseLeave,
260
+ onFocus: handleFocus,
261
+ onBlur: handleBlur
262
+ });
263
+ return childrenWithHandlers;
234
264
  }
235
- const handleMouseEnter = (event) => {
236
- tooltipManager.showTooltip(
237
- tooltipId.current,
238
- content,
239
- event.currentTarget,
240
- side,
241
- sideOffset
242
- );
243
- };
244
- const handleMouseLeave = () => {
245
- tooltipManager.hideTooltip(tooltipId.current);
246
- };
247
- const handleFocus = (event) => {
248
- tooltipManager.showTooltip(
249
- tooltipId.current,
250
- content,
251
- event.currentTarget,
252
- side,
253
- sideOffset
254
- );
255
- };
256
- const handleBlur = () => {
257
- tooltipManager.hideTooltip(tooltipId.current);
258
- };
259
- const childrenWithHandlers = import_react.default.cloneElement(children, {
260
- onMouseEnter: handleMouseEnter,
261
- onMouseLeave: handleMouseLeave,
262
- onFocus: handleFocus,
263
- onBlur: handleBlur
264
- });
265
- return childrenWithHandlers;
266
- }
265
+ );
267
266
  //# sourceMappingURL=TldrawUiTooltip.js.map