tldraw 3.16.0-canary.efdec30fc411 → 3.16.0-canary.f20b7a478e22

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 (466) hide show
  1. package/dist-cjs/index.d.ts +275 -110
  2. package/dist-cjs/index.js +36 -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 +15 -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/elbow/ElbowArrowDebug.js +3 -3
  15. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  16. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +4 -4
  17. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
  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 +20 -13
  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/frame/components/FrameLabelInput.js +2 -2
  27. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js.map +2 -2
  28. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +3 -2
  29. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  30. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
  31. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
  32. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
  33. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  34. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +6 -3
  35. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +2 -2
  36. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
  37. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  38. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +6 -5
  39. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  40. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +4 -4
  41. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js.map +2 -2
  42. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -3
  43. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  44. package/dist-cjs/lib/shapes/shared/ShapeFill.js +4 -4
  45. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  46. package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
  47. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js +3 -4
  48. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  49. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js +0 -2
  50. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js.map +2 -2
  51. package/dist-cjs/lib/shapes/text/PlainTextArea.js +2 -2
  52. package/dist-cjs/lib/shapes/text/PlainTextArea.js.map +2 -2
  53. package/dist-cjs/lib/shapes/text/RichTextArea.js +3 -3
  54. package/dist-cjs/lib/shapes/text/RichTextArea.js.map +2 -2
  55. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +2 -2
  56. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  57. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  58. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  59. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +25 -1
  60. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  61. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js +12 -0
  62. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  63. package/dist-cjs/lib/ui/TldrawUi.js +27 -12
  64. package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
  65. package/dist-cjs/lib/ui/assetUrls.js +13 -10
  66. package/dist-cjs/lib/ui/assetUrls.js.map +2 -2
  67. package/dist-cjs/lib/ui/components/A11y.js +1 -1
  68. package/dist-cjs/lib/ui/components/A11y.js.map +2 -2
  69. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +10 -2
  70. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  71. package/dist-cjs/lib/ui/components/{FollowingIndicator.js → DefaultFollowingIndicator.js} +6 -6
  72. package/dist-cjs/lib/ui/components/DefaultFollowingIndicator.js.map +7 -0
  73. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +6 -6
  74. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +1 -1
  75. package/dist-cjs/lib/ui/components/LanguageMenu.js +1 -0
  76. package/dist-cjs/lib/ui/components/LanguageMenu.js.map +2 -2
  77. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +1 -0
  78. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js.map +2 -2
  79. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  80. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  81. package/dist-cjs/lib/ui/components/MobileStylePanel.js +5 -3
  82. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  83. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +1 -1
  84. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  85. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +9 -4
  86. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js.map +2 -2
  87. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +255 -316
  88. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  89. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js +147 -0
  90. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +7 -0
  91. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js +68 -0
  92. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js.map +7 -0
  93. package/dist-cjs/lib/ui/components/StylePanel/{DoubleDropdownPicker.js → StylePanelDoubleDropdownPicker.js} +23 -22
  94. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +7 -0
  95. package/dist-cjs/lib/ui/components/StylePanel/{DropdownPicker.js → StylePanelDropdownPicker.js} +24 -21
  96. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +7 -0
  97. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js +28 -0
  98. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js.map +7 -0
  99. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +2 -0
  100. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  101. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +39 -10
  102. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  103. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +66 -22
  104. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
  105. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js +15 -3
  106. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js.map +2 -2
  107. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +2 -1
  108. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  109. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +188 -78
  110. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
  111. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +6 -2
  112. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  113. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +11 -2
  114. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  115. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +5 -3
  116. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js.map +2 -2
  117. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +18 -5
  118. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  119. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +18 -3
  120. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  121. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +187 -165
  122. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  123. package/dist-cjs/lib/ui/components/primitives/layout.js +30 -5
  124. package/dist-cjs/lib/ui/components/primitives/layout.js.map +2 -2
  125. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js +3 -0
  126. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
  127. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  128. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +25 -12
  129. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  130. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +8 -24
  131. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  132. package/dist-cjs/lib/ui/context/actions.js +29 -10
  133. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  134. package/dist-cjs/lib/ui/context/components.js +2 -0
  135. package/dist-cjs/lib/ui/context/components.js.map +2 -2
  136. package/dist-cjs/lib/ui/context/events.js.map +1 -1
  137. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +1 -1
  138. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
  139. package/dist-cjs/lib/ui/hooks/useExportAs.js +3 -2
  140. package/dist-cjs/lib/ui/hooks/useExportAs.js.map +2 -2
  141. package/dist-cjs/lib/ui/hooks/useTools.js +22 -4
  142. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  143. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  144. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +6 -2
  145. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  146. package/dist-cjs/lib/ui/kbd-utils.js +9 -3
  147. package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
  148. package/dist-cjs/lib/ui/version.js +3 -3
  149. package/dist-cjs/lib/ui/version.js.map +1 -1
  150. package/dist-cjs/lib/utils/export/copyAs.js +1 -2
  151. package/dist-cjs/lib/utils/export/copyAs.js.map +2 -2
  152. package/dist-cjs/lib/utils/export/export.js +0 -20
  153. package/dist-cjs/lib/utils/export/export.js.map +2 -2
  154. package/dist-cjs/lib/utils/export/exportAs.js +1 -2
  155. package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
  156. package/dist-esm/index.d.mts +275 -110
  157. package/dist-esm/index.mjs +68 -30
  158. package/dist-esm/index.mjs.map +2 -2
  159. package/dist-esm/lib/Tldraw.mjs +14 -4
  160. package/dist-esm/lib/Tldraw.mjs.map +2 -2
  161. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  162. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  163. package/dist-esm/lib/defaultExternalContentHandlers.mjs +15 -4
  164. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  165. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
  166. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  167. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +6 -0
  168. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +3 -3
  169. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  170. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  171. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +5 -5
  172. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
  173. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
  174. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  175. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  176. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  177. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +21 -13
  178. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  179. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  180. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  181. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs +3 -3
  182. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs.map +2 -2
  183. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +4 -2
  184. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  185. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
  186. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
  187. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
  188. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  189. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +6 -3
  190. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +2 -2
  191. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
  192. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  193. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +7 -5
  194. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  195. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs +5 -5
  196. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs.map +2 -2
  197. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +1 -3
  198. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  199. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +5 -4
  200. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  201. package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
  202. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs +4 -5
  203. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  204. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs +0 -2
  205. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs.map +2 -2
  206. package/dist-esm/lib/shapes/text/PlainTextArea.mjs +3 -3
  207. package/dist-esm/lib/shapes/text/PlainTextArea.mjs.map +2 -2
  208. package/dist-esm/lib/shapes/text/RichTextArea.mjs +3 -4
  209. package/dist-esm/lib/shapes/text/RichTextArea.mjs.map +2 -2
  210. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +3 -2
  211. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  212. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  213. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  214. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +26 -1
  215. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  216. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +13 -0
  217. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  218. package/dist-esm/lib/ui/TldrawUi.mjs +29 -14
  219. package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
  220. package/dist-esm/lib/ui/assetUrls.mjs +13 -10
  221. package/dist-esm/lib/ui/assetUrls.mjs.map +2 -2
  222. package/dist-esm/lib/ui/components/A11y.mjs +2 -2
  223. package/dist-esm/lib/ui/components/A11y.mjs.map +2 -2
  224. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +10 -2
  225. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  226. package/dist-esm/lib/ui/components/{FollowingIndicator.mjs → DefaultFollowingIndicator.mjs} +3 -3
  227. package/dist-esm/lib/ui/components/DefaultFollowingIndicator.mjs.map +7 -0
  228. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +6 -6
  229. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +1 -1
  230. package/dist-esm/lib/ui/components/LanguageMenu.mjs +1 -0
  231. package/dist-esm/lib/ui/components/LanguageMenu.mjs.map +2 -2
  232. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs +1 -0
  233. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs.map +2 -2
  234. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  235. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  236. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +6 -3
  237. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  238. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +2 -2
  239. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  240. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs +14 -5
  241. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs.map +2 -2
  242. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +257 -320
  243. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  244. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +135 -0
  245. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +7 -0
  246. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs +48 -0
  247. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs.map +7 -0
  248. package/dist-esm/lib/ui/components/StylePanel/{DoubleDropdownPicker.mjs → StylePanelDoubleDropdownPicker.mjs} +20 -19
  249. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +7 -0
  250. package/dist-esm/lib/ui/components/StylePanel/{DropdownPicker.mjs → StylePanelDropdownPicker.mjs} +21 -18
  251. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +7 -0
  252. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs +8 -0
  253. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs.map +7 -0
  254. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +2 -0
  255. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  256. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +39 -10
  257. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  258. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +56 -22
  259. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
  260. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs +15 -3
  261. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs.map +2 -2
  262. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +2 -1
  263. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  264. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -80
  265. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
  266. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +6 -2
  267. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  268. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +12 -3
  269. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  270. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs +6 -4
  271. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs.map +2 -2
  272. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +18 -5
  273. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  274. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +19 -4
  275. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  276. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +197 -167
  277. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  278. package/dist-esm/lib/ui/components/primitives/layout.mjs +31 -6
  279. package/dist-esm/lib/ui/components/primitives/layout.mjs.map +2 -2
  280. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs +3 -0
  281. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
  282. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  283. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +25 -12
  284. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  285. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +8 -24
  286. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  287. package/dist-esm/lib/ui/context/actions.mjs +29 -10
  288. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  289. package/dist-esm/lib/ui/context/components.mjs +2 -0
  290. package/dist-esm/lib/ui/context/components.mjs.map +2 -2
  291. package/dist-esm/lib/ui/context/events.mjs.map +1 -1
  292. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +2 -2
  293. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
  294. package/dist-esm/lib/ui/hooks/useExportAs.mjs +3 -2
  295. package/dist-esm/lib/ui/hooks/useExportAs.mjs.map +2 -2
  296. package/dist-esm/lib/ui/hooks/useTools.mjs +23 -4
  297. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  298. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +6 -2
  299. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  300. package/dist-esm/lib/ui/kbd-utils.mjs +9 -3
  301. package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
  302. package/dist-esm/lib/ui/version.mjs +3 -3
  303. package/dist-esm/lib/ui/version.mjs.map +1 -1
  304. package/dist-esm/lib/utils/export/copyAs.mjs +1 -2
  305. package/dist-esm/lib/utils/export/copyAs.mjs.map +2 -2
  306. package/dist-esm/lib/utils/export/export.mjs +0 -20
  307. package/dist-esm/lib/utils/export/export.mjs.map +2 -2
  308. package/dist-esm/lib/utils/export/exportAs.mjs +1 -2
  309. package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
  310. package/package.json +11 -34
  311. package/src/index.ts +49 -22
  312. package/src/lib/Tldraw.tsx +15 -2
  313. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  314. package/src/lib/defaultExternalContentHandlers.ts +26 -4
  315. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +2 -1
  316. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +6 -5
  317. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +48 -6
  318. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
  319. package/src/lib/shapes/arrow/arrowLabel.ts +8 -0
  320. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  321. package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +5 -5
  322. package/src/lib/shapes/draw/DrawShapeTool.test.ts +0 -5
  323. package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
  324. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  325. package/src/lib/shapes/frame/FrameShapeUtil.tsx +30 -14
  326. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  327. package/src/lib/shapes/frame/components/FrameLabelInput.tsx +3 -3
  328. package/src/lib/shapes/geo/GeoShapeUtil.tsx +4 -2
  329. package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
  330. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
  331. package/src/lib/shapes/image/ImageShapeUtil.tsx +6 -3
  332. package/src/lib/shapes/line/LineShapeUtil.test.tsx +4 -3
  333. package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
  334. package/src/lib/shapes/line/__snapshots__/LineShapeUtil.test.tsx.snap +2 -2
  335. package/src/lib/shapes/note/NoteShapeUtil.tsx +10 -4
  336. package/src/lib/shapes/shared/HyperlinkButton.tsx +5 -5
  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 +5 -9
  341. package/src/lib/shapes/shared/useImageOrVideoAsset.ts +0 -7
  342. package/src/lib/shapes/text/PlainTextArea.tsx +3 -3
  343. package/src/lib/shapes/text/RichTextArea.tsx +3 -4
  344. package/src/lib/shapes/text/TextShapeTool.test.ts +6 -5
  345. package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
  346. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  347. package/src/lib/tools/EraserTool/childStates/Erasing.ts +34 -1
  348. package/src/lib/tools/EraserTool/childStates/Pointing.ts +20 -0
  349. package/src/lib/ui/TldrawUi.tsx +33 -12
  350. package/src/lib/ui/assetUrls.ts +13 -10
  351. package/src/lib/ui/components/A11y.tsx +2 -2
  352. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +13 -2
  353. package/src/lib/ui/components/{FollowingIndicator.tsx → DefaultFollowingIndicator.tsx} +2 -1
  354. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +6 -6
  355. package/src/lib/ui/components/LanguageMenu.tsx +1 -0
  356. package/src/lib/ui/components/Minimap/DefaultMinimap.tsx +1 -0
  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/PageMenu/DefaultPageMenu.tsx +2 -2
  360. package/src/lib/ui/components/StylePanel/DefaultStylePanel.tsx +27 -13
  361. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +260 -381
  362. package/src/lib/ui/components/{primitives/TldrawUiButtonPicker.tsx → StylePanel/StylePanelButtonPicker.tsx} +72 -51
  363. package/src/lib/ui/components/StylePanel/StylePanelContext.tsx +63 -0
  364. package/src/lib/ui/components/StylePanel/{DoubleDropdownPicker.tsx → StylePanelDoubleDropdownPicker.tsx} +28 -19
  365. package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +119 -0
  366. package/src/lib/ui/components/StylePanel/StylePanelSubheading.tsx +9 -0
  367. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +2 -0
  368. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +33 -16
  369. package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +55 -24
  370. package/src/lib/ui/components/Toolbar/DefaultVideoToolbarContent.tsx +12 -4
  371. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +1 -0
  372. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +208 -56
  373. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +9 -2
  374. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +8 -3
  375. package/src/lib/ui/components/primitives/TldrawUiInput.tsx +6 -3
  376. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +52 -32
  377. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +27 -6
  378. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +232 -185
  379. package/src/lib/ui/components/primitives/layout.tsx +79 -5
  380. package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +4 -0
  381. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  382. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +29 -16
  383. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +11 -24
  384. package/src/lib/ui/context/actions.tsx +36 -10
  385. package/src/lib/ui/context/components.tsx +3 -0
  386. package/src/lib/ui/context/events.tsx +1 -1
  387. package/src/lib/ui/hooks/useClipboardEvents.ts +2 -2
  388. package/src/lib/ui/hooks/useExportAs.ts +3 -2
  389. package/src/lib/ui/hooks/useTools.tsx +26 -4
  390. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +4 -0
  391. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +6 -2
  392. package/src/lib/ui/kbd-utils.ts +10 -3
  393. package/src/lib/ui/version.ts +3 -3
  394. package/src/lib/ui.css +375 -245
  395. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +5 -5
  396. package/src/lib/utils/export/copyAs.ts +1 -24
  397. package/src/lib/utils/export/export.ts +0 -36
  398. package/src/lib/utils/export/exportAs.ts +1 -32
  399. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +4 -4
  400. package/src/test/A11y.test.tsx +3 -2
  401. package/src/test/ClickManager.test.ts +7 -6
  402. package/src/test/Editor.test.tsx +20 -19
  403. package/src/test/EraserTool.test.ts +184 -13
  404. package/src/test/HandTool.test.ts +10 -9
  405. package/src/test/HighlightShape.test.ts +2 -1
  406. package/src/test/SelectTool.test.ts +3 -2
  407. package/src/test/TLUserPreferences.test.ts +4 -3
  408. package/src/test/TestEditor.ts +13 -15
  409. package/src/test/TldrawEditor.test.tsx +11 -10
  410. package/src/test/ZoomTool.test.ts +7 -6
  411. package/src/test/__snapshots__/drawing.test.ts.snap +2 -2
  412. package/src/test/__snapshots__/groups.test.tsx.snap +6 -6
  413. package/src/test/__snapshots__/resizing.test.ts.snap +2 -2
  414. package/src/test/arrows-megabus.test.tsx +5 -4
  415. package/src/test/bindings.test.tsx +24 -37
  416. package/src/test/bookmark-shapes.test.ts +1 -8
  417. package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +23 -7
  418. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +8 -8
  419. package/src/test/commands/__snapshots__/zoomToFit.test.ts.snap +2 -2
  420. package/src/test/commands/alignShapes.test.tsx +25 -24
  421. package/src/test/commands/animationSpeed.test.ts +2 -1
  422. package/src/test/commands/centerOnPoint.test.ts +3 -2
  423. package/src/test/commands/clipboard.test.ts +3 -2
  424. package/src/test/commands/createShapes.test.ts +2 -1
  425. package/src/test/commands/deleteShapes.test.ts +2 -1
  426. package/src/test/commands/distributeShapes.test.tsx +11 -10
  427. package/src/test/commands/getSvgString.test.ts +2 -1
  428. package/src/test/commands/packShapes.test.ts +5 -4
  429. package/src/test/commands/resizeShape.test.ts +2 -1
  430. package/src/test/commands/rotateShapes.test.ts +7 -6
  431. package/src/test/commands/setCamera.test.ts +4 -3
  432. package/src/test/commands/setCurrentPage.test.ts +3 -2
  433. package/src/test/commands/stackShapes.test.ts +11 -10
  434. package/src/test/commands/stretch.test.tsx +13 -12
  435. package/src/test/createDeepLink.test.tsx +2 -1
  436. package/src/test/cropping.test.ts +3 -2
  437. package/src/test/custom-clipping.test.ts +436 -0
  438. package/src/test/drawing.test.ts +2 -1
  439. package/src/test/flipShapes.test.ts +4 -3
  440. package/src/test/frames.test.ts +25 -24
  441. package/src/test/getCulledShapes.test.tsx +74 -4
  442. package/src/test/groups.test.tsx +1 -1
  443. package/src/test/handleDeepLink.test.tsx +2 -1
  444. package/src/test/maxShapes.test.ts +3 -2
  445. package/src/test/modifiers.test.ts +5 -4
  446. package/src/test/navigation.test.ts +12 -11
  447. package/src/test/panning.test.ts +2 -1
  448. package/src/test/perf/perf.test.ts +2 -1
  449. package/src/test/registerDeepLinkListener.test.tsx +10 -9
  450. package/src/test/resizing.test.ts +39 -38
  451. package/src/test/select.test.tsx +4 -3
  452. package/src/test/selection-omnibus.test.ts +11 -10
  453. package/src/test/shapeutils.test.ts +4 -3
  454. package/src/test/translating.test.ts +9 -8
  455. package/tldraw.css +683 -537
  456. package/dist-cjs/lib/ui/components/FollowingIndicator.js.map +0 -7
  457. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +0 -7
  458. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +0 -7
  459. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js +0 -131
  460. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +0 -7
  461. package/dist-esm/lib/ui/components/FollowingIndicator.mjs.map +0 -7
  462. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +0 -7
  463. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +0 -7
  464. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +0 -114
  465. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +0 -7
  466. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +0 -110
@@ -59,52 +59,130 @@ const NUMBERED_SHORTCUT_KEYS = {
59
59
  "9": 8,
60
60
  "0": 9
61
61
  };
62
- function OverflowingToolbar({ children }) {
62
+ function OverflowingToolbar({
63
+ children,
64
+ orientation,
65
+ sizingParentClassName,
66
+ minItems,
67
+ minSizePx,
68
+ maxItems,
69
+ maxSizePx
70
+ }) {
63
71
  const editor = (0, import_editor.useEditor)();
64
72
  const id = (0, import_editor.useUniqueSafeId)();
65
73
  const breakpoint = (0, import_breakpoints.useBreakpoint)();
66
74
  const msg = (0, import_useTranslation.useTranslation)();
67
75
  const rButtons = (0, import_react.useRef)([]);
68
76
  const [isOpen, setIsOpen] = (0, import_react.useState)(false);
69
- const overflowIndex = Math.min(8, 5 + breakpoint);
70
- const [totalItems, setTotalItems] = (0, import_react.useState)(0);
71
77
  const mainToolsRef = (0, import_react.useRef)(null);
78
+ const [overflowTools, setOverflowTools] = (0, import_react.useState)(null);
72
79
  const [lastActiveOverflowItem, setLastActiveOverflowItem] = (0, import_react.useState)(null);
73
- const css = (0, import_react.useMemo)(() => {
74
- const activeCss = lastActiveOverflowItem ? `:not([data-value="${lastActiveOverflowItem}"])` : "";
75
- return `
76
- #${id}_main > *:nth-of-type(n + ${overflowIndex + (lastActiveOverflowItem ? 1 : 2)}):not([data-radix-popper-content-wrapper])${activeCss} {
77
- display: none;
78
- }
79
- #${id}_more > *:nth-of-type(-n + ${overflowIndex}):not([data-radix-popper-content-wrapper]) {
80
- display: none;
81
- }
82
- `;
83
- }, [lastActiveOverflowItem, id, overflowIndex]);
80
+ const [shouldShowOverflow, setShouldShowOverflow] = (0, import_react.useState)(false);
84
81
  const onDomUpdate = (0, import_editor.useEvent)(() => {
85
82
  if (!mainToolsRef.current) return;
86
- const children2 = Array.from(mainToolsRef.current.children);
87
- setTotalItems(children2.length);
88
- const lastActiveElementIdx = children2.findIndex(
89
- (el) => el.getAttribute("data-value") === lastActiveOverflowItem
90
- );
91
- if (lastActiveElementIdx <= overflowIndex) {
92
- setLastActiveOverflowItem(null);
83
+ const sizeProp = orientation === "horizontal" ? "offsetWidth" : "offsetHeight";
84
+ const mainItems = collectItems(mainToolsRef.current.children);
85
+ const overflowItems = overflowTools ? collectItems(overflowTools.children) : null;
86
+ function collectItems(collection) {
87
+ const items = [];
88
+ for (const child of collection) {
89
+ if (child.classList.contains("tlui-main-toolbar__group")) {
90
+ items.push({
91
+ type: "group",
92
+ items: collectItems(child.children),
93
+ element: child
94
+ });
95
+ } else if (!child.hasAttribute("data-radix-popper-content-wrapper")) {
96
+ items.push({ type: "item", element: child });
97
+ }
98
+ }
99
+ return items;
93
100
  }
94
- const activeElementIdx = Array.from(mainToolsRef.current.children).findIndex(
95
- (el) => el.getAttribute("aria-pressed") === "true"
101
+ const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
102
+ const size = sizingParent[sizeProp];
103
+ const itemsToShow = Math.floor(
104
+ (0, import_editor.modulate)(size, [minSizePx, maxSizePx], [minItems, maxItems], true)
96
105
  );
97
- if (activeElementIdx === -1) return;
98
- if (activeElementIdx >= overflowIndex) {
99
- setLastActiveOverflowItem(children2[activeElementIdx].getAttribute("data-value"));
100
- }
101
- rButtons.current = Array.from(mainToolsRef.current?.children ?? []).filter(
102
- (el) => {
103
- if (!(el instanceof HTMLElement)) return false;
104
- if (el.tagName.toLowerCase() !== "button") return false;
105
- return !!(el.offsetWidth || el.offsetHeight);
106
+ let mainItemCount = 0;
107
+ let newActiveOverflowItem = null;
108
+ let shouldInvalidateLastActiveOverflowItem = false;
109
+ const numberedButtons = [];
110
+ function visitItems(mainItems2, overflowItems2) {
111
+ if (overflowItems2) (0, import_editor.assert)(mainItems2.length === overflowItems2.length);
112
+ let didShowAnyInMain = false;
113
+ let didShowAnyInOverflow2 = false;
114
+ for (let i = 0; i < mainItems2.length; i++) {
115
+ const mainItem = mainItems2[i];
116
+ const overflowItem = overflowItems2?.[i];
117
+ if (mainItem.type === "item") {
118
+ const isLastActiveOverflowItem = mainItem.element.getAttribute("data-value") === lastActiveOverflowItem;
119
+ let shouldShowInMain;
120
+ if (lastActiveOverflowItem) {
121
+ shouldShowInMain = mainItemCount < itemsToShow || isLastActiveOverflowItem;
122
+ } else {
123
+ shouldShowInMain = mainItemCount <= itemsToShow;
124
+ }
125
+ const shouldShowInOverflow = mainItemCount >= itemsToShow;
126
+ didShowAnyInMain ||= shouldShowInMain;
127
+ didShowAnyInOverflow2 ||= shouldShowInOverflow;
128
+ setAttribute(
129
+ mainItem.element,
130
+ "data-toolbar-visible",
131
+ shouldShowInMain ? "true" : "false"
132
+ );
133
+ if (overflowItem) {
134
+ (0, import_editor.assert)(overflowItem.type === "item");
135
+ setAttribute(
136
+ overflowItem.element,
137
+ "data-toolbar-visible",
138
+ shouldShowInOverflow ? "true" : "false"
139
+ );
140
+ }
141
+ if (shouldShowInOverflow && mainItem.element.getAttribute("aria-pressed") === "true") {
142
+ newActiveOverflowItem = mainItem.element.getAttribute("data-value");
143
+ }
144
+ if (shouldShowInMain && mainItem.element.tagName === "BUTTON") {
145
+ numberedButtons.push(mainItem.element);
146
+ }
147
+ if (!shouldShowInOverflow && isLastActiveOverflowItem) {
148
+ shouldInvalidateLastActiveOverflowItem = true;
149
+ }
150
+ mainItemCount++;
151
+ } else {
152
+ let result, overflowGroup;
153
+ if (overflowItem) {
154
+ (0, import_editor.assert)(overflowItem.type === "group");
155
+ overflowGroup = overflowItem;
156
+ result = visitItems(mainItem.items, overflowGroup.items);
157
+ } else {
158
+ result = visitItems(mainItem.items, null);
159
+ }
160
+ didShowAnyInMain ||= result.didShowAnyInMain;
161
+ didShowAnyInOverflow2 ||= result.didShowAnyInOverflow;
162
+ setAttribute(
163
+ mainItem.element,
164
+ "data-toolbar-visible",
165
+ result.didShowAnyInMain ? "true" : "false"
166
+ );
167
+ if (overflowGroup) {
168
+ setAttribute(
169
+ overflowGroup.element,
170
+ "data-toolbar-visible",
171
+ result.didShowAnyInOverflow ? "true" : "false"
172
+ );
173
+ }
174
+ }
106
175
  }
107
- );
176
+ return { didShowAnyInMain, didShowAnyInOverflow: didShowAnyInOverflow2 };
177
+ }
178
+ const { didShowAnyInOverflow } = visitItems(mainItems, overflowItems);
179
+ setShouldShowOverflow(didShowAnyInOverflow);
180
+ if (newActiveOverflowItem) {
181
+ setLastActiveOverflowItem(newActiveOverflowItem);
182
+ } else if (shouldInvalidateLastActiveOverflowItem) {
183
+ setLastActiveOverflowItem(null);
184
+ }
185
+ rButtons.current = numberedButtons;
108
186
  });
109
187
  (0, import_react.useLayoutEffect)(() => {
110
188
  onDomUpdate();
@@ -115,20 +193,26 @@ function OverflowingToolbar({ children }) {
115
193
  mutationObserver.observe(mainToolsRef.current, {
116
194
  childList: true,
117
195
  subtree: true,
118
- attributeFilter: ["data-value", "aria-pressed"]
196
+ attributes: true,
197
+ characterData: true
119
198
  });
199
+ const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
200
+ const resizeObserver = new ResizeObserver(onDomUpdate);
201
+ resizeObserver.observe(sizingParent);
120
202
  return () => {
121
203
  mutationObserver.disconnect();
204
+ resizeObserver.disconnect();
122
205
  };
123
- }, [onDomUpdate]);
206
+ }, [onDomUpdate, sizingParentClassName]);
124
207
  (0, import_react.useEffect)(() => {
125
208
  if (!editor.options.enableToolbarKeyboardShortcuts) return;
126
209
  function handleKeyDown(event) {
127
210
  if ((0, import_useKeyboardShortcuts.areShortcutsDisabled)(editor) || (0, import_editor.activeElementShouldCaptureKeys)(
128
211
  true
129
212
  /* allow buttons */
130
- ))
213
+ )) {
131
214
  return;
215
+ }
132
216
  if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
133
217
  const index = NUMBERED_SHORTCUT_KEYS[event.key];
134
218
  if (typeof index === "number") {
@@ -142,50 +226,76 @@ function OverflowingToolbar({ children }) {
142
226
  };
143
227
  }, [editor]);
144
228
  const popoverId = "toolbar overflow";
145
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
146
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { nonce: editor.options.nonce, children: css }),
147
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
148
- import_TldrawUiToolbar.TldrawUiToolbar,
149
- {
150
- orientation: "horizontal",
151
- className: (0, import_classnames.default)("tlui-main-toolbar__tools", {
152
- "tlui-main-toolbar__tools__mobile": breakpoint < import_constants.PORTRAIT_BREAKPOINT.TABLET_SM
153
- }),
154
- label: msg("tool-panel.title"),
155
- children: [
156
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_layout.TldrawUiRow, { id: `${id}_main`, ref: mainToolsRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "toolbar", sourceId: "toolbar", children }) }),
157
- totalItems > overflowIndex + 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IsInOverflowContext.Provider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiPopover.TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
158
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
- import_TldrawUiToolbar.TldrawUiToolbarButton,
160
- {
161
- title: msg("tool-panel.more"),
162
- type: "tool",
163
- className: "tlui-main-toolbar__overflow",
164
- "data-testid": "tools.more-button",
165
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: "chevron-up" })
166
- }
167
- ) }),
168
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverContent, { side: "top", align: "center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
- import_TldrawUiToolbar.TldrawUiToolbar,
170
- {
171
- orientation: "grid",
172
- "data-testid": "tools.more-content",
173
- label: msg("tool-panel.more"),
174
- id: `${id}_more`,
175
- onClick: () => {
176
- import_editor.tlmenus.deleteOpenMenu(popoverId, editor.contextId);
177
- setIsOpen(false);
178
- },
179
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "toolbar-overflow", sourceId: "toolbar", children })
180
- }
181
- ) })
182
- ] }) })
183
- ]
184
- }
185
- )
186
- ] });
229
+ const Layout = orientation === "horizontal" ? import_layout.TldrawUiRow : import_layout.TldrawUiColumn;
230
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
231
+ import_TldrawUiToolbar.TldrawUiToolbar,
232
+ {
233
+ orientation,
234
+ className: (0, import_classnames.default)("tlui-main-toolbar__tools", {
235
+ "tlui-main-toolbar__tools__mobile": breakpoint < import_constants.PORTRAIT_BREAKPOINT.TABLET_SM
236
+ }),
237
+ label: msg("tool-panel.title"),
238
+ children: [
239
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, { id: `${id}_main`, ref: mainToolsRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "toolbar", sourceId: "toolbar", children }) }),
240
+ shouldShowOverflow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IsInOverflowContext.Provider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiPopover.TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
241
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
+ import_TldrawUiToolbar.TldrawUiToolbarButton,
243
+ {
244
+ title: msg("tool-panel.more"),
245
+ type: "tool",
246
+ className: "tlui-main-toolbar__overflow",
247
+ "data-testid": "tools.more-button",
248
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
249
+ import_TldrawUiButtonIcon.TldrawUiButtonIcon,
250
+ {
251
+ icon: orientation === "horizontal" ? "chevron-up" : "chevron-right"
252
+ }
253
+ )
254
+ }
255
+ ) }),
256
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
257
+ import_TldrawUiPopover.TldrawUiPopoverContent,
258
+ {
259
+ side: orientation === "horizontal" ? "top" : "right",
260
+ align: orientation === "horizontal" ? "center" : "end",
261
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
262
+ import_TldrawUiToolbar.TldrawUiToolbar,
263
+ {
264
+ orientation: "grid",
265
+ className: "tlui-main-toolbar__overflow-content",
266
+ ref: setOverflowTools,
267
+ "data-testid": "tools.more-content",
268
+ label: msg("tool-panel.more"),
269
+ id: `${id}_more`,
270
+ onClick: () => {
271
+ import_editor.tlmenus.deleteOpenMenu(popoverId, editor.contextId);
272
+ setIsOpen(false);
273
+ },
274
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "toolbar-overflow", sourceId: "toolbar", children })
275
+ }
276
+ )
277
+ }
278
+ )
279
+ ] }) })
280
+ ]
281
+ }
282
+ ) });
187
283
  }
188
284
  const isActiveTLUiToolItem = (item, activeToolId, geoState) => {
189
285
  return item.meta?.geo ? activeToolId === "geo" && geoState === item.meta?.geo : activeToolId === item.id;
190
286
  };
287
+ function findParentWithClassName(startingElement, className) {
288
+ let element = startingElement;
289
+ while (element) {
290
+ if (element.classList.contains(className)) {
291
+ return element;
292
+ }
293
+ element = element.parentElement;
294
+ }
295
+ throw new Error("Could not find parent with class name " + className);
296
+ }
297
+ function setAttribute(element, name, value) {
298
+ if (element.getAttribute(name) === value) return;
299
+ element.setAttribute(name, value);
300
+ }
191
301
  //# sourceMappingURL=OverflowingToolbar.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/OverflowingToolbar.tsx"],
4
- "sourcesContent": ["import {\n\tactiveElementShouldCaptureKeys,\n\tpreventDefault,\n\ttlmenus,\n\tuseEditor,\n\tuseEvent,\n\tuseUniqueSafeId,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { createContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { areShortcutsDisabled } from '../../hooks/useKeyboardShortcuts'\nimport { TLUiToolItem } from '../../hooks/useTools'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport {\n\tTldrawUiPopover,\n\tTldrawUiPopoverContent,\n\tTldrawUiPopoverTrigger,\n} from '../primitives/TldrawUiPopover'\nimport { TldrawUiToolbar, TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'\nimport { TldrawUiRow } from '../primitives/layout'\nimport { TldrawUiMenuContextProvider } from '../primitives/menus/TldrawUiMenuContext'\n\nexport const IsInOverflowContext = createContext(false)\n\nconst NUMBERED_SHORTCUT_KEYS: Record<string, number> = {\n\t'1': 0,\n\t'2': 1,\n\t'3': 2,\n\t'4': 3,\n\t'5': 4,\n\t'6': 5,\n\t'7': 6,\n\t'8': 7,\n\t'9': 8,\n\t'0': 9,\n}\n\n/** @public */\nexport interface OverflowingToolbarProps {\n\tchildren: React.ReactNode\n}\n\n/** @public @react */\nexport function OverflowingToolbar({ children }: OverflowingToolbarProps) {\n\tconst editor = useEditor()\n\tconst id = useUniqueSafeId()\n\tconst breakpoint = useBreakpoint()\n\tconst msg = useTranslation()\n\tconst rButtons = useRef<HTMLElement[]>([])\n\tconst [isOpen, setIsOpen] = useState(false)\n\n\tconst overflowIndex = Math.min(8, 5 + breakpoint)\n\n\tconst [totalItems, setTotalItems] = useState(0)\n\tconst mainToolsRef = useRef<HTMLDivElement>(null)\n\tconst [lastActiveOverflowItem, setLastActiveOverflowItem] = useState<string | null>(null)\n\n\tconst css = useMemo(() => {\n\t\tconst activeCss = lastActiveOverflowItem ? `:not([data-value=\"${lastActiveOverflowItem}\"])` : ''\n\n\t\treturn `\n\t\t\t#${id}_main > *:nth-of-type(n + ${overflowIndex + (lastActiveOverflowItem ? 1 : 2)}):not([data-radix-popper-content-wrapper])${activeCss} {\n\t\t\t\tdisplay: none;\n\t\t\t}\n\t\t\t#${id}_more > *:nth-of-type(-n + ${overflowIndex}):not([data-radix-popper-content-wrapper]) {\n\t\t\t\tdisplay: none;\n\t\t\t}\n `\n\t}, [lastActiveOverflowItem, id, overflowIndex])\n\n\tconst onDomUpdate = useEvent(() => {\n\t\tif (!mainToolsRef.current) return\n\n\t\tconst children = Array.from(mainToolsRef.current.children)\n\t\tsetTotalItems(children.length)\n\n\t\t// If the last active overflow item is no longer in the overflow, clear it\n\t\tconst lastActiveElementIdx = children.findIndex(\n\t\t\t(el) => el.getAttribute('data-value') === lastActiveOverflowItem\n\t\t)\n\t\tif (lastActiveElementIdx <= overflowIndex) {\n\t\t\tsetLastActiveOverflowItem(null)\n\t\t}\n\n\t\t// But if there's a new active item...\n\t\tconst activeElementIdx = Array.from(mainToolsRef.current.children).findIndex(\n\t\t\t(el) => el.getAttribute('aria-pressed') === 'true'\n\t\t)\n\t\tif (activeElementIdx === -1) return\n\n\t\t// ...and it's in the overflow, set it as the last active overflow item\n\t\tif (activeElementIdx >= overflowIndex) {\n\t\t\tsetLastActiveOverflowItem(children[activeElementIdx].getAttribute('data-value'))\n\t\t}\n\n\t\t// Save the buttons that are actually visible\n\t\trButtons.current = Array.from(mainToolsRef.current?.children ?? []).filter(\n\t\t\t(el): el is HTMLElement => {\n\t\t\t\t// only count html elements...\n\t\t\t\tif (!(el instanceof HTMLElement)) return false\n\n\t\t\t\t// ...that are buttons...\n\t\t\t\tif (el.tagName.toLowerCase() !== 'button') return false\n\n\t\t\t\t// ...that are actually visible\n\t\t\t\treturn !!(el.offsetWidth || el.offsetHeight)\n\t\t\t}\n\t\t)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tonDomUpdate()\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tif (!mainToolsRef.current) return\n\n\t\tconst mutationObserver = new MutationObserver(onDomUpdate)\n\t\tmutationObserver.observe(mainToolsRef.current, {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t\tattributeFilter: ['data-value', 'aria-pressed'],\n\t\t})\n\n\t\treturn () => {\n\t\t\tmutationObserver.disconnect()\n\t\t}\n\t}, [onDomUpdate])\n\n\tuseEffect(() => {\n\t\tif (!editor.options.enableToolbarKeyboardShortcuts) return\n\n\t\tfunction handleKeyDown(event: KeyboardEvent) {\n\t\t\tif (areShortcutsDisabled(editor) || activeElementShouldCaptureKeys(true /* allow buttons */))\n\t\t\t\treturn\n\t\t\t// no accelerator keys\n\t\t\tif (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return\n\t\t\tconst index = NUMBERED_SHORTCUT_KEYS[event.key]\n\t\t\tif (typeof index === 'number') {\n\t\t\t\tpreventDefault(event)\n\t\t\t\trButtons.current[index]?.click()\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('keydown', handleKeyDown)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('keydown', handleKeyDown)\n\t\t}\n\t}, [editor])\n\n\tconst popoverId = 'toolbar overflow'\n\treturn (\n\t\t<>\n\t\t\t<style nonce={editor.options.nonce}>{css}</style>\n\t\t\t<TldrawUiToolbar\n\t\t\t\torientation=\"horizontal\"\n\t\t\t\tclassName={classNames('tlui-main-toolbar__tools', {\n\t\t\t\t\t'tlui-main-toolbar__tools__mobile': breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM,\n\t\t\t\t})}\n\t\t\t\tlabel={msg('tool-panel.title')}\n\t\t\t>\n\t\t\t\t<TldrawUiRow id={`${id}_main`} ref={mainToolsRef}>\n\t\t\t\t\t<TldrawUiMenuContextProvider type=\"toolbar\" sourceId=\"toolbar\">\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</TldrawUiMenuContextProvider>\n\t\t\t\t</TldrawUiRow>\n\t\t\t\t{/* There is a +1 because if the menu is just one item, it's not necessary. */}\n\t\t\t\t{totalItems > overflowIndex + 1 && (\n\t\t\t\t\t<IsInOverflowContext.Provider value={true}>\n\t\t\t\t\t\t<TldrawUiPopover id={popoverId} open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t\t\t\t<TldrawUiPopoverTrigger>\n\t\t\t\t\t\t\t\t<TldrawUiToolbarButton\n\t\t\t\t\t\t\t\t\ttitle={msg('tool-panel.more')}\n\t\t\t\t\t\t\t\t\ttype=\"tool\"\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-main-toolbar__overflow\"\n\t\t\t\t\t\t\t\t\tdata-testid=\"tools.more-button\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TldrawUiButtonIcon icon=\"chevron-up\" />\n\t\t\t\t\t\t\t\t</TldrawUiToolbarButton>\n\t\t\t\t\t\t\t</TldrawUiPopoverTrigger>\n\t\t\t\t\t\t\t<TldrawUiPopoverContent side=\"top\" align=\"center\">\n\t\t\t\t\t\t\t\t<TldrawUiToolbar\n\t\t\t\t\t\t\t\t\torientation=\"grid\"\n\t\t\t\t\t\t\t\t\tdata-testid=\"tools.more-content\"\n\t\t\t\t\t\t\t\t\tlabel={msg('tool-panel.more')}\n\t\t\t\t\t\t\t\t\tid={`${id}_more`}\n\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\ttlmenus.deleteOpenMenu(popoverId, editor.contextId)\n\t\t\t\t\t\t\t\t\t\tsetIsOpen(false)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TldrawUiMenuContextProvider type=\"toolbar-overflow\" sourceId=\"toolbar\">\n\t\t\t\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t\t\t\t</TldrawUiMenuContextProvider>\n\t\t\t\t\t\t\t\t</TldrawUiToolbar>\n\t\t\t\t\t\t\t</TldrawUiPopoverContent>\n\t\t\t\t\t\t</TldrawUiPopover>\n\t\t\t\t\t</IsInOverflowContext.Provider>\n\t\t\t\t)}\n\t\t\t</TldrawUiToolbar>\n\t\t</>\n\t)\n}\n\nexport const isActiveTLUiToolItem = (\n\titem: TLUiToolItem,\n\tactiveToolId: string | undefined,\n\tgeoState: string | null | undefined\n) => {\n\treturn item.meta?.geo\n\t\t? activeToolId === 'geo' && geoState === item.meta?.geo\n\t\t: activeToolId === item.id\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2JE;AA3JF,oBAOO;AACP,wBAAuB;AACvB,mBAAqF;AACrF,uBAAoC;AACpC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oBAAmB,UAAS,WAC5D,UACF;AAAA;AAAA,YACD,GACD;AAAA,aACD,GACD;AAAA;AAAA;AAAA,IAEF;AAAA,KACD;AAEF;AAEO,MAAM,uBAAuB,CACnC,MACA,cACA,aACI;AACJ,SAAO,KAAK,MAAM,MACf,iBAAiB,SAAS,aAAa,KAAK,MAAM,MAClD,iBAAiB,KAAK;AAC1B;",
6
- "names": ["children", "classNames"]
4
+ "sourcesContent": ["import {\n\tactiveElementShouldCaptureKeys,\n\tassert,\n\tmodulate,\n\tpreventDefault,\n\ttlmenus,\n\tuseEditor,\n\tuseEvent,\n\tuseUniqueSafeId,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { createContext, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { areShortcutsDisabled } from '../../hooks/useKeyboardShortcuts'\nimport { TLUiToolItem } from '../../hooks/useTools'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport {\n\tTldrawUiPopover,\n\tTldrawUiPopoverContent,\n\tTldrawUiPopoverTrigger,\n} from '../primitives/TldrawUiPopover'\nimport { TldrawUiToolbar, TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'\nimport { TldrawUiColumn, TldrawUiRow } from '../primitives/layout'\nimport { TldrawUiMenuContextProvider } from '../primitives/menus/TldrawUiMenuContext'\n\nexport const IsInOverflowContext = createContext(false)\n\nconst NUMBERED_SHORTCUT_KEYS: Record<string, number> = {\n\t'1': 0,\n\t'2': 1,\n\t'3': 2,\n\t'4': 3,\n\t'5': 4,\n\t'6': 5,\n\t'7': 6,\n\t'8': 7,\n\t'9': 8,\n\t'0': 9,\n}\n\n/** @public */\nexport interface OverflowingToolbarProps {\n\tchildren: React.ReactNode\n\torientation: 'horizontal' | 'vertical'\n\tsizingParentClassName: string\n\tminItems: number\n\tminSizePx: number\n\tmaxItems: number\n\tmaxSizePx: number\n}\n\n/** @public @react */\nexport function OverflowingToolbar({\n\tchildren,\n\torientation,\n\tsizingParentClassName,\n\tminItems,\n\tminSizePx,\n\tmaxItems,\n\tmaxSizePx,\n}: OverflowingToolbarProps) {\n\tconst editor = useEditor()\n\tconst id = useUniqueSafeId()\n\tconst breakpoint = useBreakpoint()\n\tconst msg = useTranslation()\n\tconst rButtons = useRef<HTMLElement[]>([])\n\tconst [isOpen, setIsOpen] = useState(false)\n\n\tconst mainToolsRef = useRef<HTMLDivElement>(null)\n\n\t// we have to use state instead of a ref here so that we get\n\t// an update when the overflow popover mounts / unmounts\n\tconst [overflowTools, setOverflowTools] = useState<HTMLDivElement | null>(null)\n\tconst [lastActiveOverflowItem, setLastActiveOverflowItem] = useState<string | null>(null)\n\tconst [shouldShowOverflow, setShouldShowOverflow] = useState(false)\n\n\tconst onDomUpdate = useEvent(() => {\n\t\tif (!mainToolsRef.current) return\n\n\t\t// whenever we get an update, we need to re-calculate the number of items to show and update\n\t\t// the component accordingly.\n\t\tconst sizeProp = orientation === 'horizontal' ? 'offsetWidth' : 'offsetHeight'\n\n\t\t// toolbars can contain both single items and groups. we need to keep track of both.\n\t\ttype Items = (\n\t\t\t| { type: 'item'; element: HTMLElement }\n\t\t\t| { type: 'group'; items: Items; element: HTMLElement }\n\t\t)[]\n\n\t\t// walk through the dom and collect items so we can calculate what to show/hide\n\t\tconst mainItems = collectItems(mainToolsRef.current.children)\n\t\tconst overflowItems = overflowTools ? collectItems(overflowTools.children) : null\n\t\tfunction collectItems(collection: HTMLCollection) {\n\t\t\tconst items: Items = []\n\t\t\tfor (const child of collection) {\n\t\t\t\tif (child.classList.contains('tlui-main-toolbar__group')) {\n\t\t\t\t\titems.push({\n\t\t\t\t\t\ttype: 'group',\n\t\t\t\t\t\titems: collectItems(child.children),\n\t\t\t\t\t\telement: child as HTMLElement,\n\t\t\t\t\t})\n\t\t\t\t} else if (!child.hasAttribute('data-radix-popper-content-wrapper')) {\n\t\t\t\t\titems.push({ type: 'item', element: child as HTMLElement })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn items\n\t\t}\n\n\t\t// the number of items to show is based on the space available to the toolbar.\n\t\tconst sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName)\n\t\tconst size = sizingParent[sizeProp]\n\t\tconst itemsToShow = Math.floor(\n\t\t\tmodulate(size, [minSizePx, maxSizePx], [minItems, maxItems], true)\n\t\t)\n\n\t\t// now we know how many items to show, we need to walk through the items we found and show /\n\t\t// hide them accordingly. We need to keep track of:\n\t\t// the number of item's we've shown in the main content so far\n\t\tlet mainItemCount = 0\n\t\t// the item that is currently active in the overflow content (if any)\n\t\tlet newActiveOverflowItem: string | null = null\n\t\t// whether the last active overflow item is actually still in the overflow content\n\t\tlet shouldInvalidateLastActiveOverflowItem = false\n\t\t// the buttons visible in the main content\n\t\tconst numberedButtons: HTMLButtonElement[] = []\n\t\tfunction visitItems(\n\t\t\tmainItems: Items,\n\t\t\toverflowItems: Items | null\n\t\t): {\n\t\t\t// for each group of items we visit, we need to know whether we showed anything in\n\t\t\t// either section\n\t\t\tdidShowAnyInMain: boolean\n\t\t\tdidShowAnyInOverflow: boolean\n\t\t} {\n\t\t\tif (overflowItems) assert(mainItems.length === overflowItems.length)\n\n\t\t\tlet didShowAnyInMain = false\n\t\t\tlet didShowAnyInOverflow = false\n\n\t\t\tfor (let i = 0; i < mainItems.length; i++) {\n\t\t\t\tconst mainItem = mainItems[i]\n\t\t\t\tconst overflowItem = overflowItems?.[i]\n\n\t\t\t\tif (mainItem.type === 'item') {\n\t\t\t\t\tconst isLastActiveOverflowItem =\n\t\t\t\t\t\tmainItem.element.getAttribute('data-value') === lastActiveOverflowItem\n\n\t\t\t\t\t// for single items, we show them in main if we have space, or if they're the\n\t\t\t\t\t// last-used item from the overflow.\n\t\t\t\t\tlet shouldShowInMain\n\t\t\t\t\tif (lastActiveOverflowItem) {\n\t\t\t\t\t\tshouldShowInMain = mainItemCount < itemsToShow || isLastActiveOverflowItem\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// we use <= here because if there is no last active overflow item, we want\n\t\t\t\t\t\t// to show at least one item in the main toolbar.\n\t\t\t\t\t\tshouldShowInMain = mainItemCount <= itemsToShow\n\t\t\t\t\t}\n\t\t\t\t\tconst shouldShowInOverflow = mainItemCount >= itemsToShow\n\n\t\t\t\t\tdidShowAnyInMain ||= shouldShowInMain\n\t\t\t\t\tdidShowAnyInOverflow ||= shouldShowInOverflow\n\n\t\t\t\t\tsetAttribute(\n\t\t\t\t\t\tmainItem.element,\n\t\t\t\t\t\t'data-toolbar-visible',\n\t\t\t\t\t\tshouldShowInMain ? 'true' : 'false'\n\t\t\t\t\t)\n\t\t\t\t\tif (overflowItem) {\n\t\t\t\t\t\tassert(overflowItem.type === 'item')\n\t\t\t\t\t\tsetAttribute(\n\t\t\t\t\t\t\toverflowItem.element,\n\t\t\t\t\t\t\t'data-toolbar-visible',\n\t\t\t\t\t\t\tshouldShowInOverflow ? 'true' : 'false'\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (shouldShowInOverflow && mainItem.element.getAttribute('aria-pressed') === 'true') {\n\t\t\t\t\t\tnewActiveOverflowItem = mainItem.element.getAttribute('data-value')\n\t\t\t\t\t}\n\t\t\t\t\tif (shouldShowInMain && mainItem.element.tagName === 'BUTTON') {\n\t\t\t\t\t\tnumberedButtons.push(mainItem.element as HTMLButtonElement)\n\t\t\t\t\t}\n\t\t\t\t\tif (!shouldShowInOverflow && isLastActiveOverflowItem) {\n\t\t\t\t\t\tshouldInvalidateLastActiveOverflowItem = true\n\t\t\t\t\t}\n\t\t\t\t\tmainItemCount++\n\t\t\t\t} else {\n\t\t\t\t\t// for groups, we show them in main if we have space, or if they're the\n\t\t\t\t\t// last-used item from the overflow.\n\t\t\t\t\tlet result, overflowGroup\n\t\t\t\t\tif (overflowItem) {\n\t\t\t\t\t\tassert(overflowItem.type === 'group')\n\t\t\t\t\t\toverflowGroup = overflowItem\n\t\t\t\t\t\tresult = visitItems(mainItem.items, overflowGroup.items)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult = visitItems(mainItem.items, null)\n\t\t\t\t\t}\n\n\t\t\t\t\tdidShowAnyInMain ||= result.didShowAnyInMain\n\t\t\t\t\tdidShowAnyInOverflow ||= result.didShowAnyInOverflow\n\n\t\t\t\t\tsetAttribute(\n\t\t\t\t\t\tmainItem.element,\n\t\t\t\t\t\t'data-toolbar-visible',\n\t\t\t\t\t\tresult.didShowAnyInMain ? 'true' : 'false'\n\t\t\t\t\t)\n\t\t\t\t\tif (overflowGroup) {\n\t\t\t\t\t\tsetAttribute(\n\t\t\t\t\t\t\toverflowGroup.element,\n\t\t\t\t\t\t\t'data-toolbar-visible',\n\t\t\t\t\t\t\tresult.didShowAnyInOverflow ? 'true' : 'false'\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { didShowAnyInMain, didShowAnyInOverflow }\n\t\t}\n\n\t\tconst { didShowAnyInOverflow } = visitItems(mainItems, overflowItems)\n\t\tsetShouldShowOverflow(didShowAnyInOverflow)\n\t\tif (newActiveOverflowItem) {\n\t\t\tsetLastActiveOverflowItem(newActiveOverflowItem)\n\t\t} else if (shouldInvalidateLastActiveOverflowItem) {\n\t\t\tsetLastActiveOverflowItem(null)\n\t\t}\n\n\t\trButtons.current = numberedButtons\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tonDomUpdate()\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tif (!mainToolsRef.current) return\n\n\t\tconst mutationObserver = new MutationObserver(onDomUpdate)\n\t\tmutationObserver.observe(mainToolsRef.current, {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t\tattributes: true,\n\t\t\tcharacterData: true,\n\t\t})\n\n\t\tconst sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName)\n\t\tconst resizeObserver = new ResizeObserver(onDomUpdate)\n\t\tresizeObserver.observe(sizingParent)\n\n\t\treturn () => {\n\t\t\tmutationObserver.disconnect()\n\t\t\tresizeObserver.disconnect()\n\t\t}\n\t}, [onDomUpdate, sizingParentClassName])\n\n\tuseEffect(() => {\n\t\tif (!editor.options.enableToolbarKeyboardShortcuts) return\n\n\t\tfunction handleKeyDown(event: KeyboardEvent) {\n\t\t\tif (\n\t\t\t\tareShortcutsDisabled(editor) ||\n\t\t\t\tactiveElementShouldCaptureKeys(true /* allow buttons */)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// no accelerator keys\n\t\t\tif (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return\n\t\t\tconst index = NUMBERED_SHORTCUT_KEYS[event.key]\n\t\t\tif (typeof index === 'number') {\n\t\t\t\tpreventDefault(event)\n\t\t\t\trButtons.current[index]?.click()\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('keydown', handleKeyDown)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('keydown', handleKeyDown)\n\t\t}\n\t}, [editor])\n\n\tconst popoverId = 'toolbar overflow'\n\n\tconst Layout = orientation === 'horizontal' ? TldrawUiRow : TldrawUiColumn\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiToolbar\n\t\t\t\torientation={orientation}\n\t\t\t\tclassName={classNames('tlui-main-toolbar__tools', {\n\t\t\t\t\t'tlui-main-toolbar__tools__mobile': breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM,\n\t\t\t\t})}\n\t\t\t\tlabel={msg('tool-panel.title')}\n\t\t\t>\n\t\t\t\t<Layout id={`${id}_main`} ref={mainToolsRef}>\n\t\t\t\t\t<TldrawUiMenuContextProvider type=\"toolbar\" sourceId=\"toolbar\">\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</TldrawUiMenuContextProvider>\n\t\t\t\t</Layout>\n\t\t\t\t{shouldShowOverflow && (\n\t\t\t\t\t<IsInOverflowContext.Provider value={true}>\n\t\t\t\t\t\t<TldrawUiPopover id={popoverId} open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t\t\t\t<TldrawUiPopoverTrigger>\n\t\t\t\t\t\t\t\t<TldrawUiToolbarButton\n\t\t\t\t\t\t\t\t\ttitle={msg('tool-panel.more')}\n\t\t\t\t\t\t\t\t\ttype=\"tool\"\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-main-toolbar__overflow\"\n\t\t\t\t\t\t\t\t\tdata-testid=\"tools.more-button\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TldrawUiButtonIcon\n\t\t\t\t\t\t\t\t\t\ticon={orientation === 'horizontal' ? 'chevron-up' : 'chevron-right'}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</TldrawUiToolbarButton>\n\t\t\t\t\t\t\t</TldrawUiPopoverTrigger>\n\t\t\t\t\t\t\t<TldrawUiPopoverContent\n\t\t\t\t\t\t\t\tside={orientation === 'horizontal' ? 'top' : 'right'}\n\t\t\t\t\t\t\t\talign={orientation === 'horizontal' ? 'center' : 'end'}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<TldrawUiToolbar\n\t\t\t\t\t\t\t\t\torientation=\"grid\"\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-main-toolbar__overflow-content\"\n\t\t\t\t\t\t\t\t\tref={setOverflowTools}\n\t\t\t\t\t\t\t\t\tdata-testid=\"tools.more-content\"\n\t\t\t\t\t\t\t\t\tlabel={msg('tool-panel.more')}\n\t\t\t\t\t\t\t\t\tid={`${id}_more`}\n\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\ttlmenus.deleteOpenMenu(popoverId, editor.contextId)\n\t\t\t\t\t\t\t\t\t\tsetIsOpen(false)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TldrawUiMenuContextProvider type=\"toolbar-overflow\" sourceId=\"toolbar\">\n\t\t\t\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t\t\t\t</TldrawUiMenuContextProvider>\n\t\t\t\t\t\t\t\t</TldrawUiToolbar>\n\t\t\t\t\t\t\t</TldrawUiPopoverContent>\n\t\t\t\t\t\t</TldrawUiPopover>\n\t\t\t\t\t</IsInOverflowContext.Provider>\n\t\t\t\t)}\n\t\t\t</TldrawUiToolbar>\n\t\t</>\n\t)\n}\n\nexport const isActiveTLUiToolItem = (\n\titem: TLUiToolItem,\n\tactiveToolId: string | undefined,\n\tgeoState: string | null | undefined\n) => {\n\treturn item.meta?.geo\n\t\t? activeToolId === 'geo' && geoState === item.meta?.geo\n\t\t: activeToolId === item.id\n}\n\nfunction findParentWithClassName(startingElement: HTMLElement, className: string): HTMLElement {\n\tlet element: HTMLElement | null = startingElement\n\twhile (element) {\n\t\tif (element.classList.contains(className)) {\n\t\t\treturn element\n\t\t}\n\t\telement = element.parentElement\n\t}\n\tthrow new Error('Could not find parent with class name ' + className)\n}\n\nfunction setAttribute(element: HTMLElement, name: string, value: string) {\n\tif (element.getAttribute(name) === value) return\n\telement.setAttribute(name, value)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8RE;AA9RF,oBASO;AACP,wBAAuB;AACvB,mBAA4E;AAC5E,uBAAoC;AACpC,yBAA8B;AAC9B,kCAAqC;AAErC,4BAA+B;AAC/B,gCAAmC;AACnC,6BAIO;AACP,6BAAuD;AACvD,oBAA4C;AAC5C,iCAA4C;AAErC,MAAM,0BAAsB,4BAAc,KAAK;AAEtD,MAAM,yBAAiD;AAAA,EACtD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAcO,SAAS,mBAAmB;AAAA,EAClC;AAAA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,WAAU;AAAA,kBACV,KAAK;AAAA,kBACL,eAAY;AAAA,kBACZ,OAAO,IAAI,iBAAiB;AAAA,kBAC5B,IAAI,GAAG,EAAE;AAAA,kBACT,SAAS,MAAM;AACd,0CAAQ,eAAe,WAAW,OAAO,SAAS;AAClD,8BAAU,KAAK;AAAA,kBAChB;AAAA,kBAEA,sDAAC,0DAA4B,MAAK,oBAAmB,UAAS,WAC5D,UACF;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA,WACD,GACD;AAAA;AAAA;AAAA,EAEF,GACD;AAEF;AAEO,MAAM,uBAAuB,CACnC,MACA,cACA,aACI;AACJ,SAAO,KAAK,MAAM,MACf,iBAAiB,SAAS,aAAa,KAAK,MAAM,MAClD,iBAAiB,KAAK;AAC1B;AAEA,SAAS,wBAAwB,iBAA8B,WAAgC;AAC9F,MAAI,UAA8B;AAClC,SAAO,SAAS;AACf,QAAI,QAAQ,UAAU,SAAS,SAAS,GAAG;AAC1C,aAAO;AAAA,IACR;AACA,cAAU,QAAQ;AAAA,EACnB;AACA,QAAM,IAAI,MAAM,2CAA2C,SAAS;AACrE;AAEA,SAAS,aAAa,SAAsB,MAAc,OAAe;AACxE,MAAI,QAAQ,aAAa,IAAI,MAAM,MAAO;AAC1C,UAAQ,aAAa,MAAM,KAAK;AACjC;",
6
+ "names": ["mainItems", "overflowItems", "didShowAnyInOverflow", "classNames"]
7
7
  }
@@ -35,8 +35,10 @@ var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_editor = require("@tldraw/editor");
36
36
  var import_classnames = __toESM(require("classnames"));
37
37
  var import_constants = require("../../constants");
38
+ var import_actions = require("../../context/actions");
38
39
  var import_breakpoints = require("../../context/breakpoints");
39
40
  var import_useTranslation = require("../../hooks/useTranslation/useTranslation");
41
+ var import_kbd_utils = require("../../kbd-utils");
40
42
  var import_TldrawUiButton = require("../primitives/Button/TldrawUiButton");
41
43
  var import_TldrawUiButtonIcon = require("../primitives/Button/TldrawUiButtonIcon");
42
44
  var import_TldrawUiTooltip = require("../primitives/TldrawUiTooltip");
@@ -44,16 +46,18 @@ function ToggleToolLockedButton({ activeToolId }) {
44
46
  const editor = (0, import_editor.useEditor)();
45
47
  const breakpoint = (0, import_breakpoints.useBreakpoint)();
46
48
  const msg = (0, import_useTranslation.useTranslation)();
49
+ const actions = (0, import_actions.useActions)();
47
50
  const isToolLocked = (0, import_editor.useValue)("is tool locked", () => editor.getInstanceState().isToolLocked, [
48
51
  editor
49
52
  ]);
50
53
  const tool = (0, import_editor.useValue)("current tool", () => editor.getCurrentTool(), [editor]);
51
54
  if (!activeToolId || !tool.isLockable) return null;
52
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiTooltip.TldrawUiTooltip, { content: msg("action.toggle-tool-lock"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
55
+ const toggleLockAction = actions["toggle-tool-lock"];
56
+ const tooltipContent = toggleLockAction?.kbd ? `${msg("action.toggle-tool-lock")} ${(0, import_kbd_utils.kbdStr)(toggleLockAction.kbd)}` : msg("action.toggle-tool-lock");
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiTooltip.TldrawUiTooltip, { content: tooltipContent, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
53
58
  import_TldrawUiButton.TldrawUiButton,
54
59
  {
55
60
  type: "normal",
56
- title: msg("action.toggle-tool-lock"),
57
61
  "data-testid": "tool-lock",
58
62
  className: (0, import_classnames.default)("tlui-main-toolbar__lock-button", {
59
63
  "tlui-main-toolbar__lock-button__mobile": breakpoint < import_constants.PORTRAIT_BREAKPOINT.TABLET_SM
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx"],
4
- "sourcesContent": ["import { useEditor, useValue } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiTooltip } from '../primitives/TldrawUiTooltip'\n\n/** @public */\nexport interface ToggleToolLockedButtonProps {\n\tactiveToolId?: string\n}\n\n/** @public @react */\nexport function ToggleToolLockedButton({ activeToolId }: ToggleToolLockedButtonProps) {\n\tconst editor = useEditor()\n\tconst breakpoint = useBreakpoint()\n\tconst msg = useTranslation()\n\n\tconst isToolLocked = useValue('is tool locked', () => editor.getInstanceState().isToolLocked, [\n\t\teditor,\n\t])\n\tconst tool = useValue('current tool', () => editor.getCurrentTool(), [editor])\n\n\tif (!activeToolId || !tool.isLockable) return null\n\n\treturn (\n\t\t<TldrawUiTooltip content={msg('action.toggle-tool-lock')}>\n\t\t\t<TldrawUiButton\n\t\t\t\ttype=\"normal\"\n\t\t\t\ttitle={msg('action.toggle-tool-lock')}\n\t\t\t\tdata-testid=\"tool-lock\"\n\t\t\t\tclassName={classNames('tlui-main-toolbar__lock-button', {\n\t\t\t\t\t'tlui-main-toolbar__lock-button__mobile': breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM,\n\t\t\t\t})}\n\t\t\t\tonClick={() => editor.updateInstanceState({ isToolLocked: !isToolLocked })}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon icon={isToolLocked ? 'lock' : 'unlock'} small />\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiTooltip>\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCI;AAtCJ,oBAAoC;AACpC,wBAAuB;AACvB,uBAAoC;AACpC,yBAA8B;AAC9B,4BAA+B;AAC/B,4BAA+B;AAC/B,gCAAmC;AACnC,6BAAgC;AAQzB,SAAS,uBAAuB,EAAE,aAAa,GAAgC;AACrF,QAAM,aAAS,yBAAU;AACzB,QAAM,iBAAa,kCAAc;AACjC,QAAM,UAAM,sCAAe;AAE3B,QAAM,mBAAe,wBAAS,kBAAkB,MAAM,OAAO,iBAAiB,EAAE,cAAc;AAAA,IAC7F;AAAA,EACD,CAAC;AACD,QAAM,WAAO,wBAAS,gBAAgB,MAAM,OAAO,eAAe,GAAG,CAAC,MAAM,CAAC;AAE7E,MAAI,CAAC,gBAAgB,CAAC,KAAK,WAAY,QAAO;AAE9C,SACC,4CAAC,0CAAgB,SAAS,IAAI,yBAAyB,GACtD;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,IAAI,yBAAyB;AAAA,MACpC,eAAY;AAAA,MACZ,eAAW,kBAAAA,SAAW,kCAAkC;AAAA,QACvD,0CAA0C,aAAa,qCAAoB;AAAA,MAC5E,CAAC;AAAA,MACD,SAAS,MAAM,OAAO,oBAAoB,EAAE,cAAc,CAAC,aAAa,CAAC;AAAA,MAEzE,sDAAC,gDAAmB,MAAM,eAAe,SAAS,UAAU,OAAK,MAAC;AAAA;AAAA,EACnE,GACD;AAEF;",
4
+ "sourcesContent": ["import { useEditor, useValue } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useActions } from '../../context/actions'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { kbdStr } from '../../kbd-utils'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiTooltip } from '../primitives/TldrawUiTooltip'\n\n/** @public */\nexport interface ToggleToolLockedButtonProps {\n\tactiveToolId?: string\n}\n\n/** @public @react */\nexport function ToggleToolLockedButton({ activeToolId }: ToggleToolLockedButtonProps) {\n\tconst editor = useEditor()\n\tconst breakpoint = useBreakpoint()\n\tconst msg = useTranslation()\n\tconst actions = useActions()\n\n\tconst isToolLocked = useValue('is tool locked', () => editor.getInstanceState().isToolLocked, [\n\t\teditor,\n\t])\n\tconst tool = useValue('current tool', () => editor.getCurrentTool(), [editor])\n\n\tif (!activeToolId || !tool.isLockable) return null\n\n\tconst toggleLockAction = actions['toggle-tool-lock']\n\tconst tooltipContent = toggleLockAction?.kbd\n\t\t? `${msg('action.toggle-tool-lock')} ${kbdStr(toggleLockAction.kbd)}`\n\t\t: msg('action.toggle-tool-lock')\n\n\treturn (\n\t\t<TldrawUiTooltip content={tooltipContent}>\n\t\t\t<TldrawUiButton\n\t\t\t\ttype=\"normal\"\n\t\t\t\tdata-testid=\"tool-lock\"\n\t\t\t\tclassName={classNames('tlui-main-toolbar__lock-button', {\n\t\t\t\t\t'tlui-main-toolbar__lock-button__mobile': breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM,\n\t\t\t\t})}\n\t\t\t\tonClick={() => editor.updateInstanceState({ isToolLocked: !isToolLocked })}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon icon={isToolLocked ? 'lock' : 'unlock'} small />\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiTooltip>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6CI;AA7CJ,oBAAoC;AACpC,wBAAuB;AACvB,uBAAoC;AACpC,qBAA2B;AAC3B,yBAA8B;AAC9B,4BAA+B;AAC/B,uBAAuB;AACvB,4BAA+B;AAC/B,gCAAmC;AACnC,6BAAgC;AAQzB,SAAS,uBAAuB,EAAE,aAAa,GAAgC;AACrF,QAAM,aAAS,yBAAU;AACzB,QAAM,iBAAa,kCAAc;AACjC,QAAM,UAAM,sCAAe;AAC3B,QAAM,cAAU,2BAAW;AAE3B,QAAM,mBAAe,wBAAS,kBAAkB,MAAM,OAAO,iBAAiB,EAAE,cAAc;AAAA,IAC7F;AAAA,EACD,CAAC;AACD,QAAM,WAAO,wBAAS,gBAAgB,MAAM,OAAO,eAAe,GAAG,CAAC,MAAM,CAAC;AAE7E,MAAI,CAAC,gBAAgB,CAAC,KAAK,WAAY,QAAO;AAE9C,QAAM,mBAAmB,QAAQ,kBAAkB;AACnD,QAAM,iBAAiB,kBAAkB,MACtC,GAAG,IAAI,yBAAyB,CAAC,QAAI,yBAAO,iBAAiB,GAAG,CAAC,KACjE,IAAI,yBAAyB;AAEhC,SACC,4CAAC,0CAAgB,SAAS,gBACzB;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,eAAY;AAAA,MACZ,eAAW,kBAAAA,SAAW,kCAAkC;AAAA,QACvD,0CAA0C,aAAa,qCAAoB;AAAA,MAC5E,CAAC;AAAA,MACD,SAAS,MAAM,OAAO,oBAAoB,EAAE,cAAc,CAAC,aAAa,CAAC;AAAA,MAEzE,sDAAC,gDAAmB,MAAM,eAAe,SAAS,UAAU,OAAK,MAAC;AAAA;AAAA,EACnE,GACD;AAEF;",
6
6
  "names": ["classNames"]
7
7
  }
@@ -138,8 +138,17 @@ const TldrawUiContextualToolbar = ({
138
138
  "data-visible": false,
139
139
  "data-testid": "contextual-toolbar",
140
140
  className: (0, import_classnames.default)("tlui-contextual-toolbar", className),
141
- onPointerDown: import_editor.stopEventPropagation,
142
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiToolbar.TldrawUiToolbar, { orientation: "horizontal", className: "tlui-menu", label, children })
141
+ onPointerDown: import_editor.markEventAsHandled,
142
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
143
+ import_TldrawUiToolbar.TldrawUiToolbar,
144
+ {
145
+ orientation: "horizontal",
146
+ className: "tlui-menu",
147
+ label,
148
+ tooltipSide: "top",
149
+ children
150
+ }
151
+ )
143
152
  }
144
153
  );
145
154
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx"],
4
- "sourcesContent": ["import {\n\tassert,\n\tBox,\n\tclamp,\n\tEditor,\n\treact,\n\tstopEventPropagation,\n\tuseAtom,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tusePassThroughWheelEvents,\n\tuseValue,\n\tVec,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport React, { RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { flushSync } from 'react-dom'\nimport { TldrawUiToolbar } from './TldrawUiToolbar'\n\nconst MOVE_TIMEOUT = 150\nconst HIDE_VISIBILITY_TIMEOUT = 16\nconst SHOW_VISIBILITY_TIMEOUT = 16\nconst MIN_DISTANCE_TO_REPOSITION_SQUARED = 16 ** 2\nconst TOOLBAR_GAP = 8\nconst SCREEN_MARGIN = 16\nconst HIDE_TOOLBAR_WHEN_CAMERA_IS_MOVING = false\nconst LEFT_ALIGN_TOOLBAR = false\n\n/** @public */\nexport interface TLUiContextualToolbarProps {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tisMousingDown?: boolean\n\tgetSelectionBounds(): Box | undefined\n\tchangeOnlyWhenYChanges?: boolean\n\tlabel: string\n}\n\n/**\n * A generic floating toolbar that can be used for things\n * like rich text editing, image toolbars, etc.\n *\n * @public @react\n */\nexport const TldrawUiContextualToolbar = ({\n\tchildren,\n\tclassName,\n\tisMousingDown,\n\tgetSelectionBounds,\n\tchangeOnlyWhenYChanges = false,\n\tlabel,\n}: TLUiContextualToolbarProps) => {\n\tconst editor = useEditor()\n\tconst toolbarRef = useRef<HTMLDivElement>(null)\n\n\tusePassThroughWheelEvents(toolbarRef as RefObject<HTMLDivElement>)\n\tusePassThroughMouseOverEvents(toolbarRef as RefObject<HTMLDivElement>)\n\n\tconst { isVisible, isInteractive, hide, show, position, move } =\n\t\tuseToolbarVisibilityStateMachine(changeOnlyWhenYChanges)\n\n\t// annoying react stuff: we don't want the toolbar position function to depend on the react state so we'll double with a ref\n\tconst rCouldShowToolbar = useRef(false)\n\tconst [hasValidToolbarPosition, setHasValidToolbarPosition] = useState(false)\n\n\tconst contentSizeUpdateCounter = useAtom('content size update counter', 0)\n\n\tuseEffect(() => {\n\t\tassert(toolbarRef.current)\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\tcontentSizeUpdateCounter.update((n) => n + 1)\n\t\t})\n\t\tobserver.observe(toolbarRef.current)\n\t\treturn () => observer.disconnect()\n\t}, [contentSizeUpdateCounter])\n\n\tuseEffect(() => {\n\t\tlet lastContentSizeUpdateCounter = contentSizeUpdateCounter.get()\n\t\treturn react('toolbar position', function updateToolbarPositionAndDisplay() {\n\t\t\tconst toolbarElm = toolbarRef.current\n\t\t\tif (!toolbarElm) return\n\n\t\t\tconst nextContentSizeUpdateCounter = contentSizeUpdateCounter.get()\n\n\t\t\t// capture / force this to update when...\n\t\t\teditor.getCamera() // the camera moves\n\t\t\tcontentSizeUpdateCounter.get() // the toolbar size changes\n\t\t\t// undefined here means that we can't show the toolbar due to an incompatible position\n\t\t\tconst position = getToolbarScreenPosition(editor, toolbarElm, getSelectionBounds)\n\n\t\t\t// todo: when the toolbar is hidden due to the selection being off screen, it should be hidden immediately\n\t\t\t// rather than waiting for the position to settle. This is different than when the position changes due to\n\t\t\t// a change in the user's selection.\n\t\t\tif (!position) {\n\t\t\t\tif (rCouldShowToolbar.current) {\n\t\t\t\t\t// If we don't have a position, then we're not showing the toolbar\n\t\t\t\t\trCouldShowToolbar.current = false\n\t\t\t\t\tsetHasValidToolbarPosition(false)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// If the camera state is moving, we want to immediately update the position\n\t\t\t\t// todo: consider hiding the toolbar while the camera is moving\n\t\t\t\tconst cameraState = editor.getCameraState()\n\t\t\t\tif (cameraState === 'moving') {\n\t\t\t\t\t// ...if we wanted this to avoid prematurely updating any positions, we'd need\n\t\t\t\t\t// to have the last updated position in page space, so that we could convert\n\t\t\t\t\t// it to screen space and update it here\n\t\t\t\t\tconst elm = toolbarRef.current\n\t\t\t\t\telm.style.setProperty('transform', `translate(${position.x}px, ${position.y}px)`)\n\t\t\t\t} else {\n\t\t\t\t\tconst moveImmediately = lastContentSizeUpdateCounter !== nextContentSizeUpdateCounter\n\t\t\t\t\t// Schedule a move to its next location\n\t\t\t\t\tmove(position.x, position.y, moveImmediately)\n\t\t\t\t}\n\n\t\t\t\t// Finally, if the toolbar was previously hidden, show it again\n\t\t\t\tif (!rCouldShowToolbar.current) {\n\t\t\t\t\trCouldShowToolbar.current = true\n\t\t\t\t\tsetHasValidToolbarPosition(true)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlastContentSizeUpdateCounter = nextContentSizeUpdateCounter\n\t\t})\n\t}, [editor, getSelectionBounds, contentSizeUpdateCounter, move])\n\n\tconst cameraState = useValue('camera state', () => editor.getCameraState(), [editor])\n\n\t// Send the hide or show events based on whether the user is clicking\n\t// and whether the toolbar's position is valid\n\tuseEffect(() => {\n\t\tif (cameraState === 'moving' && HIDE_TOOLBAR_WHEN_CAMERA_IS_MOVING) {\n\t\t\thide(true)\n\t\t\treturn\n\t\t}\n\n\t\tif (isMousingDown || !hasValidToolbarPosition) {\n\t\t\thide()\n\t\t\treturn\n\t\t}\n\n\t\tshow()\n\t}, [hasValidToolbarPosition, cameraState, isMousingDown, show, hide])\n\n\t// When the visibility changes, update the toolbar's visibility\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.dataset.visible = `${isVisible}`\n\t}, [isVisible, position])\n\n\t// When the position changes, update the toolbar's position on screen\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.style.setProperty('transform', `translate(${position.x}px, ${position.y}px)`)\n\t}, [position])\n\n\t// When the interactivity changes, update the toolbar's interactivity\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.dataset.interactive = `${isInteractive}`\n\t}, [isInteractive])\n\n\treturn (\n\t\t<div\n\t\t\tref={toolbarRef}\n\t\t\tdata-interactive={false}\n\t\t\tdata-visible={false}\n\t\t\tdata-testid=\"contextual-toolbar\"\n\t\t\tclassName={classNames('tlui-contextual-toolbar', className)}\n\t\t\tonPointerDown={stopEventPropagation}\n\t\t>\n\t\t\t<TldrawUiToolbar orientation=\"horizontal\" className=\"tlui-menu\" label={label}>\n\t\t\t\t{children}\n\t\t\t</TldrawUiToolbar>\n\t\t</div>\n\t)\n}\n\n// For convenience, let's work just with boxes here\n/** @internal */\nexport function rectToBox(rect: DOMRect): Box {\n\treturn new Box(rect.x, rect.y, rect.width, rect.height)\n}\n\nexport function getToolbarScreenPosition(\n\teditor: Editor,\n\ttoolbarElm: HTMLElement,\n\tgetSelectionBounds: () => Box | undefined\n) {\n\tconst selectionBounds = getSelectionBounds()?.clone()\n\tif (!selectionBounds) return\n\n\t// Offset the selection bounds by the viewport screen bounds (if the editor is scrolled or inset, etc)\n\tconst vsb = editor.getViewportScreenBounds()\n\tselectionBounds.x -= vsb.x\n\tselectionBounds.y -= vsb.y\n\n\t// If the selection bounds are too far off of the screen, don't show the toolbar\n\tif (\n\t\tselectionBounds.midY < SCREEN_MARGIN ||\n\t\tselectionBounds.midY > vsb.h - SCREEN_MARGIN ||\n\t\tselectionBounds.midX < SCREEN_MARGIN ||\n\t\tselectionBounds.midX > vsb.w - SCREEN_MARGIN\n\t) {\n\t\treturn\n\t}\n\n\t// Get the toolbar's screen rect as a box. Do this after we verify that there is at least one selection.\n\tconst toolbarBounds = rectToBox(toolbarElm.getBoundingClientRect())\n\n\t// Chance these are NaN? Rare case.\n\tif (!toolbarBounds.width || !toolbarBounds.height) return\n\n\t// Thrashy, only do this if we're showing the toolbar\n\t// ! this might not be needed, the container never scrolls\n\tconst { scrollLeft, scrollTop } = editor.getContainer()\n\n\t// We want to position the toolbar so that it is centered over the selection\n\t// except in the cases where it would extend off the edge of the screen.\n\n\t// Start by placing the top left corner of the toolbar so that the\n\t// toolbar would be centered above the section bounds, bumped up by the\n\n\tlet x = LEFT_ALIGN_TOOLBAR ? selectionBounds.x : selectionBounds.midX - toolbarBounds.w / 2\n\tlet y = selectionBounds.y - toolbarBounds.h - TOOLBAR_GAP\n\n\t// Clamp the position on screen.\n\tx = clamp(x, SCREEN_MARGIN, vsb.w - toolbarBounds.w - SCREEN_MARGIN)\n\ty = clamp(y, SCREEN_MARGIN, vsb.h - toolbarBounds.h - SCREEN_MARGIN)\n\n\t// Offset the position by the container's scroll position\n\tx += scrollLeft\n\ty += scrollTop\n\n\t// Round the position to the nearest pixel\n\tx = Math.round(x)\n\ty = Math.round(y)\n\n\treturn { x, y }\n}\n\nfunction sufficientlyDistant(curr: Vec, next: Vec, changeOnlyWhenYChanges: boolean) {\n\tif (changeOnlyWhenYChanges) {\n\t\treturn Vec.Sub(next, curr).y ** 2 >= MIN_DISTANCE_TO_REPOSITION_SQUARED\n\t}\n\treturn Vec.Len2(Vec.Sub(next, curr)) >= MIN_DISTANCE_TO_REPOSITION_SQUARED\n}\n\nexport function useToolbarVisibilityStateMachine(changeOnlyWhenYChanges: boolean) {\n\tconst editor = useEditor()\n\n\tconst rState = useRef<\n\t\t{ name: 'hidden' } | { name: 'showing' } | { name: 'shown' } | { name: 'hiding' }\n\t>({ name: 'hidden' })\n\n\t// The toolbar should only be interactive when in the 'shown' state\n\tconst [isInteractive, setIsInteractive] = useState(false)\n\n\t// The toolbar is visible in the 'shown' and 'hiding' states\n\tconst [isVisible, setIsVisible] = useState(false)\n\n\t// The position is updated when entering the 'shown' state or when moving while in the 'shown' state\n\tconst [position, setPosition] = useState({ x: -1000, y: -1000 })\n\n\t// The toolbar's current position\n\tconst rCurrPosition = useRef(new Vec(-1000, -1000))\n\n\t// The toolbar's proposed next position\n\tconst rNextPosition = useRef(new Vec(-1000, -1000))\n\n\t// A timeout needs to be completed before the toolbar is shown or hidden\n\tconst rStableVisibilityTimeout = useRef<any>(-1)\n\n\t// A timeout needs to be completed before the toolbar's position changes moved\n\tconst rStablePositionTimeout = useRef<any>(-1)\n\n\t/**\n\t * Send the 'move' event whenever something happens that would cause the toolbar's position to change.\n\t * Any update here will cause\n\t * If the state is 'shown', it will start a new timeout that will update the toolbar's position after it completes.\n\t */\n\tconst move = useCallback(\n\t\t(x: number, y: number, immediate = false) => {\n\t\t\t// Update the next proposed position\n\t\t\trNextPosition.current.x = x\n\t\t\trNextPosition.current.y = y\n\n\t\t\t// If the toolbar is not yet visible, don't do anything\n\t\t\tif (rState.current.name === 'hidden' || rState.current.name === 'showing') return\n\n\t\t\t// If showing or hiding, cancel the position timeout and start a new one.\n\t\t\t// When the timeout ends, if we're in the 'shown' state and the position has changed sufficiently\n\t\t\t// from the last visible position, update the position.\n\t\t\tclearTimeout(rStablePositionTimeout.current)\n\n\t\t\tconst flushMove = () => {\n\t\t\t\tif (\n\t\t\t\t\trState.current.name === 'shown' &&\n\t\t\t\t\tsufficientlyDistant(rNextPosition.current, rCurrPosition.current, changeOnlyWhenYChanges)\n\t\t\t\t) {\n\t\t\t\t\tconst { x, y } = rNextPosition.current\n\t\t\t\t\trCurrPosition.current = new Vec(x, y)\n\t\t\t\t\tif (immediate) {\n\t\t\t\t\t\tflushSync(() => setPosition({ x, y }))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetPosition({ x, y })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (immediate) {\n\t\t\t\tflushMove()\n\t\t\t} else {\n\t\t\t\trStablePositionTimeout.current = editor.timers.setTimeout(flushMove, MOVE_TIMEOUT)\n\t\t\t}\n\t\t},\n\t\t[editor, changeOnlyWhenYChanges]\n\t)\n\n\t/**\n\t * Send the hide event whenever a change occurs that would cause the toolbar to become invisible.\n\t * If the state is 'shown', it will enter 'hiding' and then 'hidden' after a timeout completes.\n\t * If the state is 'showing', it will cancel the visibility timeout and enter 'hidden' immediately.\n\t */\n\tconst hide = useCallback(\n\t\t(immediate = false) => {\n\t\t\tswitch (rState.current.name) {\n\t\t\t\tcase 'showing': {\n\t\t\t\t\tclearTimeout(rStableVisibilityTimeout.current)\n\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'shown': {\n\t\t\t\t\trState.current = { name: 'hiding' }\n\t\t\t\t\tsetIsInteractive(false) // when leaving shown, turn back on interactions\n\n\t\t\t\t\tif (immediate) {\n\t\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\t\tsetIsVisible(false)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trStableVisibilityTimeout.current = editor.timers.setTimeout(() => {\n\t\t\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\t\t\tsetIsVisible(false)\n\t\t\t\t\t\t}, HIDE_VISIBILITY_TIMEOUT)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t/**\n\t * Send the show event whenever a change occurs that would cause the toolbar to become visible.\n\t * If the state is 'hidden', it will enter 'showing' and then 'shown' after a timeout completes.\n\t * If the state is 'hiding', it will cancel the visibility timeout and enter 'shown' immediately.\n\t */\n\tconst show = useCallback(() => {\n\t\tswitch (rState.current.name) {\n\t\t\tcase 'hidden': {\n\t\t\t\trState.current = { name: 'showing' }\n\t\t\t\trStableVisibilityTimeout.current = editor.timers.setTimeout(() => {\n\t\t\t\t\t// position\n\t\t\t\t\tconst { x, y } = rNextPosition.current\n\t\t\t\t\trCurrPosition.current = new Vec(x, y)\n\t\t\t\t\tsetPosition({ x, y })\n\n\t\t\t\t\trState.current = { name: 'shown' }\n\t\t\t\t\tsetIsVisible(true)\n\t\t\t\t\tsetIsInteractive(true)\n\t\t\t\t}, SHOW_VISIBILITY_TIMEOUT)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'hiding': {\n\t\t\t\t// Go back to shown immediately\n\t\t\t\tclearTimeout(rStableVisibilityTimeout.current)\n\t\t\t\trState.current = { name: 'shown' }\n\t\t\t\tsetIsInteractive(true) // when entering shown, turn back on interactions\n\t\t\t\tmove(rNextPosition.current.x, rNextPosition.current.y)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\t// noop\n\t\t\t}\n\t\t}\n\t}, [editor, move])\n\n\treturn { isVisible, isInteractive, show, hide, move, position }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8KG;AA9KH,oBAaO;AACP,wBAAuB;AACvB,mBAA4F;AAC5F,uBAA0B;AAC1B,6BAAgC;AAEhC,MAAM,eAAe;AACrB,MAAM,0BAA0B;AAChC,MAAM,0BAA0B;AAChC,MAAM,qCAAqC,MAAM;AACjD,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,qCAAqC;AAC3C,MAAM,qBAAqB;AAkBpB,MAAM,4BAA4B,CAAC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,yBAAyB;AAAA,EACzB;AACD,MAAkC;AACjC,QAAM,aAAS,yBAAU;AACzB,QAAM,iBAAa,qBAAuB,IAAI;AAE9C,+CAA0B,UAAuC;AACjE,mDAA8B,UAAuC;AAErE,QAAM,EAAE,WAAW,eAAe,MAAM,MAAM,UAAU,KAAK,IAC5D,iCAAiC,sBAAsB;AAGxD,QAAM,wBAAoB,qBAAO,KAAK;AACtC,QAAM,CAAC,yBAAyB,0BAA0B,QAAI,uBAAS,KAAK;AAE5E,QAAM,+BAA2B,uBAAQ,+BAA+B,CAAC;AAEzE,8BAAU,MAAM;AACf,8BAAO,WAAW,OAAO;AACzB,UAAM,WAAW,IAAI,eAAe,MAAM;AACzC,+BAAyB,OAAO,CAAC,MAAM,IAAI,CAAC;AAAA,IAC7C,CAAC;AACD,aAAS,QAAQ,WAAW,OAAO;AACnC,WAAO,MAAM,SAAS,WAAW;AAAA,EAClC,GAAG,CAAC,wBAAwB,CAAC;AAE7B,8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AC5B,KAAK,UAAU;AACd,eAAO,UAAU,EAAE,MAAM,UAAU;AACnC,iCAAyB,UAAU,OAAO,OAAO,WAAW,MAAM;AAEjE,gBAAM,EAAE,GAAG,EAAE,IAAI,cAAc;AAC/B,wBAAc,UAAU,IAAI,kBAAI,GAAG,CAAC;AACpC,sBAAY,EAAE,GAAG,EAAE,CAAC;AAEpB,iBAAO,UAAU,EAAE,MAAM,QAAQ;AACjC,uBAAa,IAAI;AACjB,2BAAiB,IAAI;AAAA,QACtB,GAAG,uBAAuB;AAC1B;AAAA,MACD;AAAA,MACA,KAAK,UAAU;AAEd,qBAAa,yBAAyB,OAAO;AAC7C,eAAO,UAAU,EAAE,MAAM,QAAQ;AACjC,yBAAiB,IAAI;AACrB,aAAK,cAAc,QAAQ,GAAG,cAAc,QAAQ,CAAC;AACrD;AAAA,MACD;AAAA,MACA,SAAS;AAAA,MAET;AAAA,IACD;AAAA,EACD,GAAG,CAAC,QAAQ,IAAI,CAAC;AAEjB,SAAO,EAAE,WAAW,eAAe,MAAM,MAAM,MAAM,SAAS;AAC/D;",
4
+ "sourcesContent": ["import {\n\tassert,\n\tBox,\n\tclamp,\n\tEditor,\n\tmarkEventAsHandled,\n\treact,\n\tuseAtom,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tusePassThroughWheelEvents,\n\tuseValue,\n\tVec,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport React, { RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { flushSync } from 'react-dom'\nimport { TldrawUiToolbar } from './TldrawUiToolbar'\n\nconst MOVE_TIMEOUT = 150\nconst HIDE_VISIBILITY_TIMEOUT = 16\nconst SHOW_VISIBILITY_TIMEOUT = 16\nconst MIN_DISTANCE_TO_REPOSITION_SQUARED = 16 ** 2\nconst TOOLBAR_GAP = 8\nconst SCREEN_MARGIN = 16\nconst HIDE_TOOLBAR_WHEN_CAMERA_IS_MOVING = false\nconst LEFT_ALIGN_TOOLBAR = false\n\n/** @public */\nexport interface TLUiContextualToolbarProps {\n\tchildren?: React.ReactNode\n\tclassName?: string\n\tisMousingDown?: boolean\n\tgetSelectionBounds(): Box | undefined\n\tchangeOnlyWhenYChanges?: boolean\n\tlabel: string\n}\n\n/**\n * A generic floating toolbar that can be used for things\n * like rich text editing, image toolbars, etc.\n *\n * @public @react\n */\nexport const TldrawUiContextualToolbar = ({\n\tchildren,\n\tclassName,\n\tisMousingDown,\n\tgetSelectionBounds,\n\tchangeOnlyWhenYChanges = false,\n\tlabel,\n}: TLUiContextualToolbarProps) => {\n\tconst editor = useEditor()\n\tconst toolbarRef = useRef<HTMLDivElement>(null)\n\n\tusePassThroughWheelEvents(toolbarRef as RefObject<HTMLDivElement>)\n\tusePassThroughMouseOverEvents(toolbarRef as RefObject<HTMLDivElement>)\n\n\tconst { isVisible, isInteractive, hide, show, position, move } =\n\t\tuseToolbarVisibilityStateMachine(changeOnlyWhenYChanges)\n\n\t// annoying react stuff: we don't want the toolbar position function to depend on the react state so we'll double with a ref\n\tconst rCouldShowToolbar = useRef(false)\n\tconst [hasValidToolbarPosition, setHasValidToolbarPosition] = useState(false)\n\n\tconst contentSizeUpdateCounter = useAtom('content size update counter', 0)\n\n\tuseEffect(() => {\n\t\tassert(toolbarRef.current)\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\tcontentSizeUpdateCounter.update((n) => n + 1)\n\t\t})\n\t\tobserver.observe(toolbarRef.current)\n\t\treturn () => observer.disconnect()\n\t}, [contentSizeUpdateCounter])\n\n\tuseEffect(() => {\n\t\tlet lastContentSizeUpdateCounter = contentSizeUpdateCounter.get()\n\t\treturn react('toolbar position', function updateToolbarPositionAndDisplay() {\n\t\t\tconst toolbarElm = toolbarRef.current\n\t\t\tif (!toolbarElm) return\n\n\t\t\tconst nextContentSizeUpdateCounter = contentSizeUpdateCounter.get()\n\n\t\t\t// capture / force this to update when...\n\t\t\teditor.getCamera() // the camera moves\n\t\t\tcontentSizeUpdateCounter.get() // the toolbar size changes\n\t\t\t// undefined here means that we can't show the toolbar due to an incompatible position\n\t\t\tconst position = getToolbarScreenPosition(editor, toolbarElm, getSelectionBounds)\n\n\t\t\t// todo: when the toolbar is hidden due to the selection being off screen, it should be hidden immediately\n\t\t\t// rather than waiting for the position to settle. This is different than when the position changes due to\n\t\t\t// a change in the user's selection.\n\t\t\tif (!position) {\n\t\t\t\tif (rCouldShowToolbar.current) {\n\t\t\t\t\t// If we don't have a position, then we're not showing the toolbar\n\t\t\t\t\trCouldShowToolbar.current = false\n\t\t\t\t\tsetHasValidToolbarPosition(false)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// If the camera state is moving, we want to immediately update the position\n\t\t\t\t// todo: consider hiding the toolbar while the camera is moving\n\t\t\t\tconst cameraState = editor.getCameraState()\n\t\t\t\tif (cameraState === 'moving') {\n\t\t\t\t\t// ...if we wanted this to avoid prematurely updating any positions, we'd need\n\t\t\t\t\t// to have the last updated position in page space, so that we could convert\n\t\t\t\t\t// it to screen space and update it here\n\t\t\t\t\tconst elm = toolbarRef.current\n\t\t\t\t\telm.style.setProperty('transform', `translate(${position.x}px, ${position.y}px)`)\n\t\t\t\t} else {\n\t\t\t\t\tconst moveImmediately = lastContentSizeUpdateCounter !== nextContentSizeUpdateCounter\n\t\t\t\t\t// Schedule a move to its next location\n\t\t\t\t\tmove(position.x, position.y, moveImmediately)\n\t\t\t\t}\n\n\t\t\t\t// Finally, if the toolbar was previously hidden, show it again\n\t\t\t\tif (!rCouldShowToolbar.current) {\n\t\t\t\t\trCouldShowToolbar.current = true\n\t\t\t\t\tsetHasValidToolbarPosition(true)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlastContentSizeUpdateCounter = nextContentSizeUpdateCounter\n\t\t})\n\t}, [editor, getSelectionBounds, contentSizeUpdateCounter, move])\n\n\tconst cameraState = useValue('camera state', () => editor.getCameraState(), [editor])\n\n\t// Send the hide or show events based on whether the user is clicking\n\t// and whether the toolbar's position is valid\n\tuseEffect(() => {\n\t\tif (cameraState === 'moving' && HIDE_TOOLBAR_WHEN_CAMERA_IS_MOVING) {\n\t\t\thide(true)\n\t\t\treturn\n\t\t}\n\n\t\tif (isMousingDown || !hasValidToolbarPosition) {\n\t\t\thide()\n\t\t\treturn\n\t\t}\n\n\t\tshow()\n\t}, [hasValidToolbarPosition, cameraState, isMousingDown, show, hide])\n\n\t// When the visibility changes, update the toolbar's visibility\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.dataset.visible = `${isVisible}`\n\t}, [isVisible, position])\n\n\t// When the position changes, update the toolbar's position on screen\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.style.setProperty('transform', `translate(${position.x}px, ${position.y}px)`)\n\t}, [position])\n\n\t// When the interactivity changes, update the toolbar's interactivity\n\tuseLayoutEffect(() => {\n\t\tconst elm = toolbarRef.current\n\t\tif (!elm) return\n\t\telm.dataset.interactive = `${isInteractive}`\n\t}, [isInteractive])\n\n\treturn (\n\t\t<div\n\t\t\tref={toolbarRef}\n\t\t\tdata-interactive={false}\n\t\t\tdata-visible={false}\n\t\t\tdata-testid=\"contextual-toolbar\"\n\t\t\tclassName={classNames('tlui-contextual-toolbar', className)}\n\t\t\tonPointerDown={markEventAsHandled}\n\t\t>\n\t\t\t<TldrawUiToolbar\n\t\t\t\torientation=\"horizontal\"\n\t\t\t\tclassName=\"tlui-menu\"\n\t\t\t\tlabel={label}\n\t\t\t\ttooltipSide=\"top\"\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</TldrawUiToolbar>\n\t\t</div>\n\t)\n}\n\n// For convenience, let's work just with boxes here\n/** @internal */\nexport function rectToBox(rect: DOMRect): Box {\n\treturn new Box(rect.x, rect.y, rect.width, rect.height)\n}\n\nexport function getToolbarScreenPosition(\n\teditor: Editor,\n\ttoolbarElm: HTMLElement,\n\tgetSelectionBounds: () => Box | undefined\n) {\n\tconst selectionBounds = getSelectionBounds()?.clone()\n\tif (!selectionBounds) return\n\n\t// Offset the selection bounds by the viewport screen bounds (if the editor is scrolled or inset, etc)\n\tconst vsb = editor.getViewportScreenBounds()\n\tselectionBounds.x -= vsb.x\n\tselectionBounds.y -= vsb.y\n\n\t// If the selection bounds are too far off of the screen, don't show the toolbar\n\tif (\n\t\tselectionBounds.midY < SCREEN_MARGIN ||\n\t\tselectionBounds.midY > vsb.h - SCREEN_MARGIN ||\n\t\tselectionBounds.midX < SCREEN_MARGIN ||\n\t\tselectionBounds.midX > vsb.w - SCREEN_MARGIN\n\t) {\n\t\treturn\n\t}\n\n\t// Get the toolbar's screen rect as a box. Do this after we verify that there is at least one selection.\n\tconst toolbarBounds = rectToBox(toolbarElm.getBoundingClientRect())\n\n\t// Chance these are NaN? Rare case.\n\tif (!toolbarBounds.width || !toolbarBounds.height) return\n\n\t// Thrashy, only do this if we're showing the toolbar\n\t// ! this might not be needed, the container never scrolls\n\tconst { scrollLeft, scrollTop } = editor.getContainer()\n\n\t// We want to position the toolbar so that it is centered over the selection\n\t// except in the cases where it would extend off the edge of the screen.\n\n\t// Start by placing the top left corner of the toolbar so that the\n\t// toolbar would be centered above the section bounds, bumped up by the\n\n\tlet x = LEFT_ALIGN_TOOLBAR ? selectionBounds.x : selectionBounds.midX - toolbarBounds.w / 2\n\tlet y = selectionBounds.y - toolbarBounds.h - TOOLBAR_GAP\n\n\t// Clamp the position on screen.\n\tx = clamp(x, SCREEN_MARGIN, vsb.w - toolbarBounds.w - SCREEN_MARGIN)\n\ty = clamp(y, SCREEN_MARGIN, vsb.h - toolbarBounds.h - SCREEN_MARGIN)\n\n\t// Offset the position by the container's scroll position\n\tx += scrollLeft\n\ty += scrollTop\n\n\t// Round the position to the nearest pixel\n\tx = Math.round(x)\n\ty = Math.round(y)\n\n\treturn { x, y }\n}\n\nfunction sufficientlyDistant(curr: Vec, next: Vec, changeOnlyWhenYChanges: boolean) {\n\tif (changeOnlyWhenYChanges) {\n\t\treturn Vec.Sub(next, curr).y ** 2 >= MIN_DISTANCE_TO_REPOSITION_SQUARED\n\t}\n\treturn Vec.Len2(Vec.Sub(next, curr)) >= MIN_DISTANCE_TO_REPOSITION_SQUARED\n}\n\nexport function useToolbarVisibilityStateMachine(changeOnlyWhenYChanges: boolean) {\n\tconst editor = useEditor()\n\n\tconst rState = useRef<\n\t\t{ name: 'hidden' } | { name: 'showing' } | { name: 'shown' } | { name: 'hiding' }\n\t>({ name: 'hidden' })\n\n\t// The toolbar should only be interactive when in the 'shown' state\n\tconst [isInteractive, setIsInteractive] = useState(false)\n\n\t// The toolbar is visible in the 'shown' and 'hiding' states\n\tconst [isVisible, setIsVisible] = useState(false)\n\n\t// The position is updated when entering the 'shown' state or when moving while in the 'shown' state\n\tconst [position, setPosition] = useState({ x: -1000, y: -1000 })\n\n\t// The toolbar's current position\n\tconst rCurrPosition = useRef(new Vec(-1000, -1000))\n\n\t// The toolbar's proposed next position\n\tconst rNextPosition = useRef(new Vec(-1000, -1000))\n\n\t// A timeout needs to be completed before the toolbar is shown or hidden\n\tconst rStableVisibilityTimeout = useRef<any>(-1)\n\n\t// A timeout needs to be completed before the toolbar's position changes moved\n\tconst rStablePositionTimeout = useRef<any>(-1)\n\n\t/**\n\t * Send the 'move' event whenever something happens that would cause the toolbar's position to change.\n\t * Any update here will cause\n\t * If the state is 'shown', it will start a new timeout that will update the toolbar's position after it completes.\n\t */\n\tconst move = useCallback(\n\t\t(x: number, y: number, immediate = false) => {\n\t\t\t// Update the next proposed position\n\t\t\trNextPosition.current.x = x\n\t\t\trNextPosition.current.y = y\n\n\t\t\t// If the toolbar is not yet visible, don't do anything\n\t\t\tif (rState.current.name === 'hidden' || rState.current.name === 'showing') return\n\n\t\t\t// If showing or hiding, cancel the position timeout and start a new one.\n\t\t\t// When the timeout ends, if we're in the 'shown' state and the position has changed sufficiently\n\t\t\t// from the last visible position, update the position.\n\t\t\tclearTimeout(rStablePositionTimeout.current)\n\n\t\t\tconst flushMove = () => {\n\t\t\t\tif (\n\t\t\t\t\trState.current.name === 'shown' &&\n\t\t\t\t\tsufficientlyDistant(rNextPosition.current, rCurrPosition.current, changeOnlyWhenYChanges)\n\t\t\t\t) {\n\t\t\t\t\tconst { x, y } = rNextPosition.current\n\t\t\t\t\trCurrPosition.current = new Vec(x, y)\n\t\t\t\t\tif (immediate) {\n\t\t\t\t\t\tflushSync(() => setPosition({ x, y }))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetPosition({ x, y })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (immediate) {\n\t\t\t\tflushMove()\n\t\t\t} else {\n\t\t\t\trStablePositionTimeout.current = editor.timers.setTimeout(flushMove, MOVE_TIMEOUT)\n\t\t\t}\n\t\t},\n\t\t[editor, changeOnlyWhenYChanges]\n\t)\n\n\t/**\n\t * Send the hide event whenever a change occurs that would cause the toolbar to become invisible.\n\t * If the state is 'shown', it will enter 'hiding' and then 'hidden' after a timeout completes.\n\t * If the state is 'showing', it will cancel the visibility timeout and enter 'hidden' immediately.\n\t */\n\tconst hide = useCallback(\n\t\t(immediate = false) => {\n\t\t\tswitch (rState.current.name) {\n\t\t\t\tcase 'showing': {\n\t\t\t\t\tclearTimeout(rStableVisibilityTimeout.current)\n\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'shown': {\n\t\t\t\t\trState.current = { name: 'hiding' }\n\t\t\t\t\tsetIsInteractive(false) // when leaving shown, turn back on interactions\n\n\t\t\t\t\tif (immediate) {\n\t\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\t\tsetIsVisible(false)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trStableVisibilityTimeout.current = editor.timers.setTimeout(() => {\n\t\t\t\t\t\t\trState.current = { name: 'hidden' }\n\t\t\t\t\t\t\tsetIsVisible(false)\n\t\t\t\t\t\t}, HIDE_VISIBILITY_TIMEOUT)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t/**\n\t * Send the show event whenever a change occurs that would cause the toolbar to become visible.\n\t * If the state is 'hidden', it will enter 'showing' and then 'shown' after a timeout completes.\n\t * If the state is 'hiding', it will cancel the visibility timeout and enter 'shown' immediately.\n\t */\n\tconst show = useCallback(() => {\n\t\tswitch (rState.current.name) {\n\t\t\tcase 'hidden': {\n\t\t\t\trState.current = { name: 'showing' }\n\t\t\t\trStableVisibilityTimeout.current = editor.timers.setTimeout(() => {\n\t\t\t\t\t// position\n\t\t\t\t\tconst { x, y } = rNextPosition.current\n\t\t\t\t\trCurrPosition.current = new Vec(x, y)\n\t\t\t\t\tsetPosition({ x, y })\n\n\t\t\t\t\trState.current = { name: 'shown' }\n\t\t\t\t\tsetIsVisible(true)\n\t\t\t\t\tsetIsInteractive(true)\n\t\t\t\t}, SHOW_VISIBILITY_TIMEOUT)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'hiding': {\n\t\t\t\t// Go back to shown immediately\n\t\t\t\tclearTimeout(rStableVisibilityTimeout.current)\n\t\t\t\trState.current = { name: 'shown' }\n\t\t\t\tsetIsInteractive(true) // when entering shown, turn back on interactions\n\t\t\t\tmove(rNextPosition.current.x, rNextPosition.current.y)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\t// noop\n\t\t\t}\n\t\t}\n\t}, [editor, move])\n\n\treturn { isVisible, isInteractive, show, hide, move, position }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8KG;AA9KH,oBAaO;AACP,wBAAuB;AACvB,mBAA4F;AAC5F,uBAA0B;AAC1B,6BAAgC;AAEhC,MAAM,eAAe;AACrB,MAAM,0BAA0B;AAChC,MAAM,0BAA0B;AAChC,M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