tldraw 3.16.0-next.34fddf633325 → 3.16.0-next.b88d494af370

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 (229) hide show
  1. package/dist-cjs/index.d.ts +102 -5
  2. package/dist-cjs/index.js +8 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/canvas/TldrawScribble.js +1 -1
  5. package/dist-cjs/lib/canvas/TldrawScribble.js.map +2 -2
  6. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -3
  7. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  8. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js +3 -3
  9. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  10. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
  11. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +1 -1
  13. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +1 -1
  14. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +12 -12
  15. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  16. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js +1 -1
  17. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js.map +2 -2
  18. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +2 -2
  19. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
  21. package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
  22. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
  23. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  24. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +3 -3
  25. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +1 -1
  26. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
  27. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  28. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
  29. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  30. package/dist-cjs/lib/shapes/shared/ShapeFill.js +4 -4
  31. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  32. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +2 -2
  33. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  34. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  35. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  36. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  37. package/dist-cjs/lib/ui/TldrawUi.js +14 -0
  38. package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
  39. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +12 -3
  40. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  41. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js +3 -2
  42. package/dist-cjs/lib/ui/components/DefaultMenuPanel.js.map +2 -2
  43. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  44. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  45. package/dist-cjs/lib/ui/components/MobileStylePanel.js +5 -3
  46. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  47. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +1 -1
  48. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
  49. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +2 -1
  50. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  51. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js +3 -2
  52. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js.map +2 -2
  53. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +2 -2
  54. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js.map +2 -2
  55. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +14 -14
  56. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  57. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js +3 -3
  58. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +2 -2
  59. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js +26 -25
  60. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +3 -3
  61. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +1 -1
  62. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  63. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +66 -21
  64. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
  65. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +189 -80
  66. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
  67. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +2 -2
  68. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  69. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js +5 -16
  70. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +3 -3
  71. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +1 -1
  72. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  73. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +3 -2
  74. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js.map +3 -3
  75. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +19 -4
  76. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  77. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +153 -152
  78. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  79. package/dist-cjs/lib/ui/components/primitives/layout.js +76 -0
  80. package/dist-cjs/lib/ui/components/primitives/layout.js.map +7 -0
  81. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  82. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +25 -12
  83. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  84. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +153 -20
  85. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  86. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  87. package/dist-cjs/lib/ui/hooks/useTools.js +94 -9
  88. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  89. package/dist-cjs/lib/ui/version.js +3 -3
  90. package/dist-cjs/lib/ui/version.js.map +1 -1
  91. package/dist-esm/index.d.mts +102 -5
  92. package/dist-esm/index.mjs +15 -1
  93. package/dist-esm/index.mjs.map +2 -2
  94. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  95. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  96. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
  97. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  98. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  99. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  100. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
  101. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  102. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  103. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  104. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +13 -12
  105. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  106. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  107. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  108. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -2
  109. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  110. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
  111. package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
  112. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
  113. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  114. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +3 -3
  115. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +1 -1
  116. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
  117. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  118. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -4
  119. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  120. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +5 -4
  121. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  122. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +3 -2
  123. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  124. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  125. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  126. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  127. package/dist-esm/lib/ui/TldrawUi.mjs +16 -2
  128. package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
  129. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +12 -3
  130. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  131. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs +3 -2
  132. package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs.map +2 -2
  133. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  134. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  135. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +6 -3
  136. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  137. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +1 -1
  138. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
  139. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +2 -1
  140. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  141. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs +3 -2
  142. package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs.map +2 -2
  143. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs +2 -2
  144. package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs.map +2 -2
  145. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +14 -14
  146. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  147. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs +3 -3
  148. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +2 -2
  149. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs +26 -25
  150. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +2 -2
  151. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +1 -1
  152. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  153. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +56 -21
  154. package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
  155. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -81
  156. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
  157. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +2 -2
  158. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  159. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +6 -6
  160. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +2 -2
  161. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +1 -1
  162. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  163. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs +3 -2
  164. package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs.map +2 -2
  165. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +19 -4
  166. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  167. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +162 -154
  168. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  169. package/dist-esm/lib/ui/components/primitives/layout.mjs +46 -0
  170. package/dist-esm/lib/ui/components/primitives/layout.mjs.map +7 -0
  171. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  172. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +25 -12
  173. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  174. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +161 -22
  175. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  176. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  177. package/dist-esm/lib/ui/hooks/useTools.mjs +102 -10
  178. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  179. package/dist-esm/lib/ui/version.mjs +3 -3
  180. package/dist-esm/lib/ui/version.mjs.map +1 -1
  181. package/package.json +3 -3
  182. package/src/index.ts +12 -0
  183. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  184. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
  185. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  186. package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
  187. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  188. package/src/lib/shapes/frame/FrameShapeUtil.tsx +21 -14
  189. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  190. package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -2
  191. package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
  192. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
  193. package/src/lib/shapes/image/ImageShapeUtil.tsx +3 -3
  194. package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
  195. package/src/lib/shapes/note/NoteShapeUtil.tsx +9 -4
  196. package/src/lib/shapes/shared/ShapeFill.tsx +5 -4
  197. package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
  198. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  199. package/src/lib/tools/SelectTool/childStates/Translating.ts +0 -1
  200. package/src/lib/ui/TldrawUi.tsx +17 -2
  201. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +15 -3
  202. package/src/lib/ui/components/DefaultMenuPanel.tsx +4 -3
  203. package/src/lib/ui/components/Minimap/MinimapManager.ts +4 -4
  204. package/src/lib/ui/components/MobileStylePanel.tsx +9 -6
  205. package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +1 -1
  206. package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +3 -2
  207. package/src/lib/ui/components/SharePanel/PeopleMenuItem.tsx +4 -3
  208. package/src/lib/ui/components/SharePanel/UserPresenceColorPicker.tsx +3 -3
  209. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +39 -43
  210. package/src/lib/ui/components/StylePanel/DoubleDropdownPicker.tsx +3 -3
  211. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +7 -6
  212. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +1 -1
  213. package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +55 -23
  214. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +212 -61
  215. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +2 -2
  216. package/src/lib/ui/components/primitives/TldrawUiButtonPicker.tsx +40 -37
  217. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +1 -1
  218. package/src/lib/ui/components/primitives/TldrawUiPopover.tsx +4 -2
  219. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +32 -9
  220. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +186 -172
  221. package/src/lib/ui/components/primitives/layout.tsx +107 -0
  222. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  223. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +29 -16
  224. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +220 -19
  225. package/src/lib/ui/context/events.tsx +1 -0
  226. package/src/lib/ui/hooks/useTools.tsx +140 -10
  227. package/src/lib/ui/version.ts +3 -3
  228. package/src/lib/ui.css +363 -305
  229. package/tldraw.css +656 -595
@@ -1,5 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEditor, usePassThroughWheelEvents, useValue } from "@tldraw/editor";
3
+ import classNames from "classnames";
3
4
  import { memo, useRef } from "react";
4
5
  import { PORTRAIT_BREAKPOINT } from "../../constants.mjs";
5
6
  import { useBreakpoint } from "../../context/breakpoints.mjs";
@@ -7,11 +8,19 @@ import { useTldrawUiComponents } from "../../context/components.mjs";
7
8
  import { useReadonly } from "../../hooks/useReadonly.mjs";
8
9
  import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs";
9
10
  import { MobileStylePanel } from "../MobileStylePanel.mjs";
11
+ import { TldrawUiOrientationProvider } from "../primitives/layout.mjs";
10
12
  import { TldrawUiToolbar } from "../primitives/TldrawUiToolbar.mjs";
11
13
  import { DefaultToolbarContent } from "./DefaultToolbarContent.mjs";
12
14
  import { OverflowingToolbar } from "./OverflowingToolbar.mjs";
13
15
  import { ToggleToolLockedButton } from "./ToggleToolLockedButton.mjs";
14
- const DefaultToolbar = memo(function DefaultToolbar2({ children }) {
16
+ const DefaultToolbar = memo(function DefaultToolbar2({
17
+ children,
18
+ orientation = "horizontal",
19
+ minItems = 4,
20
+ minSizePx = 310,
21
+ maxItems = 8,
22
+ maxSizePx = 470
23
+ }) {
15
24
  const editor = useEditor();
16
25
  const msg = useTranslation();
17
26
  const breakpoint = useBreakpoint();
@@ -21,26 +30,52 @@ const DefaultToolbar = memo(function DefaultToolbar2({ children }) {
21
30
  usePassThroughWheelEvents(ref);
22
31
  const { ActionsMenu, QuickActions } = useTldrawUiComponents();
23
32
  const showQuickActions = editor.options.actionShortcutsLocation === "menu" ? false : editor.options.actionShortcutsLocation === "toolbar" ? true : breakpoint < PORTRAIT_BREAKPOINT.TABLET;
24
- return /* @__PURE__ */ jsx("div", { ref, className: "tlui-toolbar", children: /* @__PURE__ */ jsxs("div", { className: "tlui-toolbar__inner", children: [
25
- /* @__PURE__ */ jsxs("div", { className: "tlui-toolbar__left", children: [
26
- !isReadonlyMode && /* @__PURE__ */ jsxs("div", { className: "tlui-toolbar__extras", children: [
27
- showQuickActions && /* @__PURE__ */ jsxs(
28
- TldrawUiToolbar,
29
- {
30
- className: "tlui-toolbar__extras__controls tlui-buttons__horizontal",
31
- label: msg("actions-menu.title"),
32
- children: [
33
- QuickActions && /* @__PURE__ */ jsx(QuickActions, {}),
34
- ActionsMenu && /* @__PURE__ */ jsx(ActionsMenu, {})
35
- ]
36
- }
37
- ),
38
- /* @__PURE__ */ jsx(ToggleToolLockedButton, { activeToolId })
39
- ] }),
40
- /* @__PURE__ */ jsx(OverflowingToolbar, { children: children ?? /* @__PURE__ */ jsx(DefaultToolbarContent, {}) })
41
- ] }),
42
- breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && /* @__PURE__ */ jsx("div", { className: "tlui-toolbar__tools", children: /* @__PURE__ */ jsx(MobileStylePanel, {}) })
43
- ] }) });
33
+ return /* @__PURE__ */ jsx(
34
+ TldrawUiOrientationProvider,
35
+ {
36
+ orientation,
37
+ tooltipSide: orientation === "horizontal" ? "top" : "right",
38
+ children: /* @__PURE__ */ jsx(
39
+ "div",
40
+ {
41
+ ref,
42
+ className: classNames("tlui-main-toolbar", `tlui-main-toolbar--${orientation}`),
43
+ children: /* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__inner", children: [
44
+ /* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__left", children: [
45
+ !isReadonlyMode && /* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__extras", children: [
46
+ showQuickActions && /* @__PURE__ */ jsxs(
47
+ TldrawUiToolbar,
48
+ {
49
+ orientation,
50
+ className: "tlui-main-toolbar__extras__controls",
51
+ label: msg("actions-menu.title"),
52
+ children: [
53
+ QuickActions && /* @__PURE__ */ jsx(QuickActions, {}),
54
+ ActionsMenu && /* @__PURE__ */ jsx(ActionsMenu, {})
55
+ ]
56
+ }
57
+ ),
58
+ /* @__PURE__ */ jsx(ToggleToolLockedButton, { activeToolId })
59
+ ] }),
60
+ /* @__PURE__ */ jsx(
61
+ OverflowingToolbar,
62
+ {
63
+ orientation,
64
+ sizingParentClassName: "tlui-main-toolbar",
65
+ minItems,
66
+ maxItems,
67
+ minSizePx,
68
+ maxSizePx,
69
+ children: children ?? /* @__PURE__ */ jsx(DefaultToolbarContent, {})
70
+ }
71
+ )
72
+ ] }),
73
+ breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && /* @__PURE__ */ jsx("div", { className: "tlui-main-toolbar__tools tlui-main-toolbar__mobile-style-panel", children: /* @__PURE__ */ jsx(MobileStylePanel, {}) })
74
+ ] })
75
+ }
76
+ )
77
+ }
78
+ );
44
79
  });
45
80
  export {
46
81
  DefaultToolbar
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/DefaultToolbar.tsx"],
4
- "sourcesContent": ["import { useEditor, usePassThroughWheelEvents, useValue } from '@tldraw/editor'\nimport { ReactNode, memo, useRef } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTldrawUiComponents } from '../../context/components'\nimport { useReadonly } from '../../hooks/useReadonly'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { MobileStylePanel } from '../MobileStylePanel'\nimport { TldrawUiToolbar } from '../primitives/TldrawUiToolbar'\nimport { DefaultToolbarContent } from './DefaultToolbarContent'\nimport { OverflowingToolbar } from './OverflowingToolbar'\nimport { ToggleToolLockedButton } from './ToggleToolLockedButton'\n\n/** @public */\nexport interface DefaultToolbarProps {\n\tchildren?: ReactNode\n}\n\n/**\n * The default toolbar for the editor. `children` defaults to the `DefaultToolbarContent` component.\n * Depending on the screen size, the children will overflow into a drop-down menu, with the most\n * recently active item from the overflow being shown in the main toolbar.\n *\n * @public\n * @react\n */\nexport const DefaultToolbar = memo(function DefaultToolbar({ children }: DefaultToolbarProps) {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst breakpoint = useBreakpoint()\n\tconst isReadonlyMode = useReadonly()\n\tconst activeToolId = useValue('current tool id', () => editor.getCurrentToolId(), [editor])\n\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\n\tconst { ActionsMenu, QuickActions } = useTldrawUiComponents()\n\n\tconst showQuickActions =\n\t\teditor.options.actionShortcutsLocation === 'menu'\n\t\t\t? false\n\t\t\t: editor.options.actionShortcutsLocation === 'toolbar'\n\t\t\t\t? true\n\t\t\t\t: breakpoint < PORTRAIT_BREAKPOINT.TABLET\n\n\treturn (\n\t\t<div ref={ref} className=\"tlui-toolbar\">\n\t\t\t<div className=\"tlui-toolbar__inner\">\n\t\t\t\t<div className=\"tlui-toolbar__left\">\n\t\t\t\t\t{!isReadonlyMode && (\n\t\t\t\t\t\t<div className=\"tlui-toolbar__extras\">\n\t\t\t\t\t\t\t{showQuickActions && (\n\t\t\t\t\t\t\t\t<TldrawUiToolbar\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-toolbar__extras__controls tlui-buttons__horizontal\"\n\t\t\t\t\t\t\t\t\tlabel={msg('actions-menu.title')}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{QuickActions && <QuickActions />}\n\t\t\t\t\t\t\t\t\t{ActionsMenu && <ActionsMenu />}\n\t\t\t\t\t\t\t\t</TldrawUiToolbar>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t<ToggleToolLockedButton activeToolId={activeToolId} />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t<OverflowingToolbar>{children ?? <DefaultToolbarContent />}</OverflowingToolbar>\n\t\t\t\t</div>\n\t\t\t\t{breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && (\n\t\t\t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rD;AAAA,MAED,oBAAC,sBAAoB,sBAAY,oBAAC,yBAAsB,GAAG;AAAA,OAC5D;AAAA,IACC,aAAa,oBAAoB,aAAa,CAAC,kBAC/C,oBAAC,SAAI,WAAU,uBACd,8BAAC,oBAAiB,GACnB;AAAA,KAEF,GACD;AAEF,CAAC;",
4
+ "sourcesContent": ["import { useEditor, usePassThroughWheelEvents, useValue } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { ReactNode, memo, useRef } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTldrawUiComponents } from '../../context/components'\nimport { useReadonly } from '../../hooks/useReadonly'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { MobileStylePanel } from '../MobileStylePanel'\nimport { TldrawUiOrientationProvider } from '../primitives/layout'\nimport { TldrawUiToolbar } from '../primitives/TldrawUiToolbar'\nimport { DefaultToolbarContent } from './DefaultToolbarContent'\nimport { OverflowingToolbar } from './OverflowingToolbar'\nimport { ToggleToolLockedButton } from './ToggleToolLockedButton'\n\n/** @public */\nexport interface DefaultToolbarProps {\n\tchildren?: ReactNode\n\torientation?: 'horizontal' | 'vertical'\n\tminItems?: number\n\tminSizePx?: number\n\tmaxItems?: number\n\tmaxSizePx?: number\n}\n\n/**\n * The default toolbar for the editor. `children` defaults to the `DefaultToolbarContent` component.\n * Depending on the screen size, the children will overflow into a drop-down menu, with the most\n * recently active item from the overflow being shown in the main toolbar.\n *\n * @public\n * @react\n */\nexport const DefaultToolbar = memo(function DefaultToolbar({\n\tchildren,\n\torientation = 'horizontal',\n\tminItems = 4,\n\tminSizePx = 310,\n\tmaxItems = 8,\n\tmaxSizePx = 470,\n}: DefaultToolbarProps) {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst breakpoint = useBreakpoint()\n\tconst isReadonlyMode = useReadonly()\n\tconst activeToolId = useValue('current tool id', () => editor.getCurrentToolId(), [editor])\n\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\n\tconst { ActionsMenu, QuickActions } = useTldrawUiComponents()\n\n\tconst showQuickActions =\n\t\teditor.options.actionShortcutsLocation === 'menu'\n\t\t\t? false\n\t\t\t: editor.options.actionShortcutsLocation === 'toolbar'\n\t\t\t\t? true\n\t\t\t\t: breakpoint < PORTRAIT_BREAKPOINT.TABLET\n\n\treturn (\n\t\t<TldrawUiOrientationProvider\n\t\t\torientation={orientation}\n\t\t\ttooltipSide={orientation === 'horizontal' ? 'top' : 'right'}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={classNames('tlui-main-toolbar', `tlui-main-toolbar--${orientation}`)}\n\t\t\t>\n\t\t\t\t<div className=\"tlui-main-toolbar__inner\">\n\t\t\t\t\t<div className=\"tlui-main-toolbar__left\">\n\t\t\t\t\t\t{!isReadonlyMode && (\n\t\t\t\t\t\t\t<div className=\"tlui-main-toolbar__extras\">\n\t\t\t\t\t\t\t\t{showQuickActions && (\n\t\t\t\t\t\t\t\t\t<TldrawUiToolbar\n\t\t\t\t\t\t\t\t\t\torientation={orientation}\n\t\t\t\t\t\t\t\t\t\tclassName=\"tlui-main-toolbar__extras__controls\"\n\t\t\t\t\t\t\t\t\t\tlabel={msg('actions-menu.title')}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{QuickActions && <QuickActions />}\n\t\t\t\t\t\t\t\t\t\t{ActionsMenu && <ActionsMenu />}\n\t\t\t\t\t\t\t\t\t</TldrawUiToolbar>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t<ToggleToolLockedButton activeToolId={activeToolId} />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<OverflowingToolbar\n\t\t\t\t\t\t\torientation={orientation}\n\t\t\t\t\t\t\tsizingParentClassName=\"tlui-main-toolbar\"\n\t\t\t\t\t\t\tminItems={minItems}\n\t\t\t\t\t\t\tmaxItems={maxItems}\n\t\t\t\t\t\t\tminSizePx={minSizePx}\n\t\t\t\t\t\t\tmaxSizePx={maxSizePx}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{children ?? <DefaultToolbarContent />}\n\t\t\t\t\t\t</OverflowingToolbar>\n\t\t\t\t\t</div>\n\t\t\t\t\t{breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && (\n\t\t\t\t\t\t<div className=\"tlui-main-toolbar__tools tlui-main-toolbar__mobile-style-panel\">\n\t\t\t\t\t\t\t<MobileStylePanel />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</TldrawUiOrientationProvider>\n\t)\n})\n"],
5
+ "mappings": "AAyES,SAKkB,KALlB;AAzET,SAAS,WAAW,2BAA2B,gBAAgB;AAC/D,OAAO,gBAAgB;AACvB,SAAoB,MAAM,cAAc;AACxC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,mCAAmC;AAC5C,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAoBhC,MAAM,iBAAiB,KAAK,SAASA,gBAAe;AAAA,EAC1D;AAAA,EACA,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AACb,GAAwB;AACvB,QAAM,SAAS,UAAU;AACzB,QAAM,MAAM,eAAe;AAC3B,QAAM,aAAa,cAAc;AACjC,QAAM,iBAAiB,YAAY;AACnC,QAAM,eAAe,SAAS,mBAAmB,MAAM,OAAO,iBAAiB,GAAG,CAAC,MAAM,CAAC;AAE1F,QAAM,MAAM,OAAuB,IAAI;AACvC,4BAA0B,GAAG;AAE7B,QAAM,EAAE,aAAa,aAAa,IAAI,sBAAsB;AAE5D,QAAM,mBACL,OAAO,QAAQ,4BAA4B,SACxC,QACA,OAAO,QAAQ,4BAA4B,YAC1C,OACA,aAAa,oBAAoB;AAEtC,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,aAAa,gBAAgB,eAAe,QAAQ;AAAA,MAEpD;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA,WAAW,WAAW,qBAAqB,sBAAsB,WAAW,EAAE;AAAA,UAE9E,+BAAC,SAAI,WAAU,4BACd;AAAA,iCAAC,SAAI,WAAU,2BACb;AAAA,eAAC,kBACD,qBAAC,SAAI,WAAU,6BACb;AAAA,oCACA;AAAA,kBAAC;AAAA;AAAA,oBACA;AAAA,oBACA,WAAU;AAAA,oBACV,OAAO,IAAI,oBAAoB;AAAA,oBAE9B;AAAA,sCAAgB,oBAAC,gBAAa;AAAA,sBAC9B,eAAe,oBAAC,eAAY;AAAA;AAAA;AAAA,gBAC9B;AAAA,gBAED,oBAAC,0BAAuB,cAA4B;AAAA,iBACrD;AAAA,cAED;AAAA,gBAAC;AAAA;AAAA,kBACA;AAAA,kBACA,uBAAsB;AAAA,kBACtB;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBAEC,sBAAY,oBAAC,yBAAsB;AAAA;AAAA,cACrC;AAAA,eACD;AAAA,YACC,aAAa,oBAAoB,aAAa,CAAC,kBAC/C,oBAAC,SAAI,WAAU,kEACd,8BAAC,oBAAiB,GACnB;AAAA,aAEF;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF,CAAC;",
6
6
  "names": ["DefaultToolbar"]
7
7
  }
@@ -1,6 +1,8 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import {
3
3
  activeElementShouldCaptureKeys,
4
+ assert,
5
+ modulate,
4
6
  preventDefault,
5
7
  tlmenus,
6
8
  useEditor,
@@ -8,7 +10,7 @@ import {
8
10
  useUniqueSafeId
9
11
  } from "@tldraw/editor";
10
12
  import classNames from "classnames";
11
- import { createContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
13
+ import { createContext, useEffect, useLayoutEffect, useRef, useState } from "react";
12
14
  import { PORTRAIT_BREAKPOINT } from "../../constants.mjs";
13
15
  import { useBreakpoint } from "../../context/breakpoints.mjs";
14
16
  import { areShortcutsDisabled } from "../../hooks/useKeyboardShortcuts.mjs";
@@ -20,6 +22,7 @@ import {
20
22
  TldrawUiPopoverTrigger
21
23
  } from "../primitives/TldrawUiPopover.mjs";
22
24
  import { TldrawUiToolbar, TldrawUiToolbarButton } from "../primitives/TldrawUiToolbar.mjs";
25
+ import { TldrawUiColumn, TldrawUiRow } from "../primitives/layout.mjs";
23
26
  import { TldrawUiMenuContextProvider } from "../primitives/menus/TldrawUiMenuContext.mjs";
24
27
  const IsInOverflowContext = createContext(false);
25
28
  const NUMBERED_SHORTCUT_KEYS = {
@@ -34,55 +37,130 @@ const NUMBERED_SHORTCUT_KEYS = {
34
37
  "9": 8,
35
38
  "0": 9
36
39
  };
37
- function OverflowingToolbar({ children }) {
40
+ function OverflowingToolbar({
41
+ children,
42
+ orientation,
43
+ sizingParentClassName,
44
+ minItems,
45
+ minSizePx,
46
+ maxItems,
47
+ maxSizePx
48
+ }) {
38
49
  const editor = useEditor();
39
50
  const id = useUniqueSafeId();
40
51
  const breakpoint = useBreakpoint();
41
52
  const msg = useTranslation();
42
53
  const rButtons = useRef([]);
43
54
  const [isOpen, setIsOpen] = useState(false);
44
- const overflowIndex = Math.min(8, 5 + breakpoint);
45
- const [totalItems, setTotalItems] = useState(0);
46
55
  const mainToolsRef = useRef(null);
56
+ const [overflowTools, setOverflowTools] = useState(null);
47
57
  const [lastActiveOverflowItem, setLastActiveOverflowItem] = useState(null);
48
- const css = useMemo(() => {
49
- const activeCss = lastActiveOverflowItem ? `:not([data-value="${lastActiveOverflowItem}"])` : "";
50
- return `
51
- #${id}_main > *:nth-of-type(n + ${overflowIndex + (lastActiveOverflowItem ? 1 : 2)}):not([data-radix-popper-content-wrapper])${activeCss} {
52
- display: none;
53
- }
54
- #${id}_more > *:nth-of-type(-n + ${overflowIndex}):not([data-radix-popper-content-wrapper]) {
55
- display: none;
56
- }
57
- #${id}_more > *:nth-of-type(-n + ${overflowIndex + 4}):not([data-radix-popper-content-wrapper]) {
58
- margin-top: 0;
59
- }
60
- `;
61
- }, [lastActiveOverflowItem, id, overflowIndex]);
58
+ const [shouldShowOverflow, setShouldShowOverflow] = useState(false);
62
59
  const onDomUpdate = useEvent(() => {
63
60
  if (!mainToolsRef.current) return;
64
- const children2 = Array.from(mainToolsRef.current.children);
65
- setTotalItems(children2.length);
66
- const lastActiveElementIdx = children2.findIndex(
67
- (el) => el.getAttribute("data-value") === lastActiveOverflowItem
68
- );
69
- if (lastActiveElementIdx <= overflowIndex) {
70
- setLastActiveOverflowItem(null);
61
+ const sizeProp = orientation === "horizontal" ? "offsetWidth" : "offsetHeight";
62
+ const mainItems = collectItems(mainToolsRef.current.children);
63
+ const overflowItems = overflowTools ? collectItems(overflowTools.children) : null;
64
+ function collectItems(collection) {
65
+ const items = [];
66
+ for (const child of collection) {
67
+ if (child.classList.contains("tlui-main-toolbar__group")) {
68
+ items.push({
69
+ type: "group",
70
+ items: collectItems(child.children),
71
+ element: child
72
+ });
73
+ } else {
74
+ items.push({ type: "item", element: child });
75
+ }
76
+ }
77
+ return items;
71
78
  }
72
- const activeElementIdx = Array.from(mainToolsRef.current.children).findIndex(
73
- (el) => el.getAttribute("aria-pressed") === "true"
79
+ const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
80
+ const size = sizingParent[sizeProp];
81
+ const itemsToShow = Math.floor(
82
+ modulate(size, [minSizePx, maxSizePx], [minItems, maxItems], true)
74
83
  );
75
- if (activeElementIdx === -1) return;
76
- if (activeElementIdx >= overflowIndex) {
77
- setLastActiveOverflowItem(children2[activeElementIdx].getAttribute("data-value"));
78
- }
79
- rButtons.current = Array.from(mainToolsRef.current?.children ?? []).filter(
80
- (el) => {
81
- if (!(el instanceof HTMLElement)) return false;
82
- if (el.tagName.toLowerCase() !== "button") return false;
83
- return !!(el.offsetWidth || el.offsetHeight);
84
+ let mainItemCount = 0;
85
+ let newActiveOverflowItem = null;
86
+ let shouldInvalidateLastActiveOverflowItem = false;
87
+ const numberedButtons = [];
88
+ function visitItems(mainItems2, overflowItems2) {
89
+ if (overflowItems2) assert(mainItems2.length === overflowItems2.length);
90
+ let didShowAnyInMain = false;
91
+ let didShowAnyInOverflow2 = false;
92
+ for (let i = 0; i < mainItems2.length; i++) {
93
+ const mainItem = mainItems2[i];
94
+ const overflowItem = overflowItems2?.[i];
95
+ if (mainItem.type === "item") {
96
+ const isLastActiveOverflowItem = mainItem.element.getAttribute("data-value") === lastActiveOverflowItem;
97
+ let shouldShowInMain;
98
+ if (lastActiveOverflowItem) {
99
+ shouldShowInMain = mainItemCount < itemsToShow || isLastActiveOverflowItem;
100
+ } else {
101
+ shouldShowInMain = mainItemCount <= itemsToShow;
102
+ }
103
+ const shouldShowInOverflow = mainItemCount >= itemsToShow;
104
+ didShowAnyInMain ||= shouldShowInMain;
105
+ didShowAnyInOverflow2 ||= shouldShowInOverflow;
106
+ setAttribute(
107
+ mainItem.element,
108
+ "data-toolbar-visible",
109
+ shouldShowInMain ? "true" : "false"
110
+ );
111
+ if (overflowItem) {
112
+ assert(overflowItem.type === "item");
113
+ setAttribute(
114
+ overflowItem.element,
115
+ "data-toolbar-visible",
116
+ shouldShowInOverflow ? "true" : "false"
117
+ );
118
+ }
119
+ if (shouldShowInOverflow && mainItem.element.getAttribute("aria-pressed") === "true") {
120
+ newActiveOverflowItem = mainItem.element.getAttribute("data-value");
121
+ }
122
+ if (shouldShowInMain && mainItem.element.tagName === "BUTTON") {
123
+ numberedButtons.push(mainItem.element);
124
+ }
125
+ if (!shouldShowInOverflow && isLastActiveOverflowItem) {
126
+ shouldInvalidateLastActiveOverflowItem = true;
127
+ }
128
+ mainItemCount++;
129
+ } else {
130
+ let result, overflowGroup;
131
+ if (overflowItem) {
132
+ assert(overflowItem.type === "group");
133
+ overflowGroup = overflowItem;
134
+ result = visitItems(mainItem.items, overflowGroup.items);
135
+ } else {
136
+ result = visitItems(mainItem.items, null);
137
+ }
138
+ didShowAnyInMain ||= result.didShowAnyInMain;
139
+ didShowAnyInOverflow2 ||= result.didShowAnyInOverflow;
140
+ setAttribute(
141
+ mainItem.element,
142
+ "data-toolbar-visible",
143
+ result.didShowAnyInMain ? "true" : "false"
144
+ );
145
+ if (overflowGroup) {
146
+ setAttribute(
147
+ overflowGroup.element,
148
+ "data-toolbar-visible",
149
+ result.didShowAnyInOverflow ? "true" : "false"
150
+ );
151
+ }
152
+ }
84
153
  }
85
- );
154
+ return { didShowAnyInMain, didShowAnyInOverflow: didShowAnyInOverflow2 };
155
+ }
156
+ const { didShowAnyInOverflow } = visitItems(mainItems, overflowItems);
157
+ setShouldShowOverflow(didShowAnyInOverflow);
158
+ if (newActiveOverflowItem) {
159
+ setLastActiveOverflowItem(newActiveOverflowItem);
160
+ } else if (shouldInvalidateLastActiveOverflowItem) {
161
+ setLastActiveOverflowItem(null);
162
+ }
163
+ rButtons.current = numberedButtons;
86
164
  });
87
165
  useLayoutEffect(() => {
88
166
  onDomUpdate();
@@ -93,20 +171,26 @@ function OverflowingToolbar({ children }) {
93
171
  mutationObserver.observe(mainToolsRef.current, {
94
172
  childList: true,
95
173
  subtree: true,
96
- attributeFilter: ["data-value", "aria-pressed"]
174
+ attributes: true,
175
+ characterData: true
97
176
  });
177
+ const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
178
+ const resizeObserver = new ResizeObserver(onDomUpdate);
179
+ resizeObserver.observe(sizingParent);
98
180
  return () => {
99
181
  mutationObserver.disconnect();
182
+ resizeObserver.disconnect();
100
183
  };
101
- }, [onDomUpdate]);
184
+ }, [onDomUpdate, sizingParentClassName]);
102
185
  useEffect(() => {
103
186
  if (!editor.options.enableToolbarKeyboardShortcuts) return;
104
187
  function handleKeyDown(event) {
105
188
  if (areShortcutsDisabled(editor) || activeElementShouldCaptureKeys(
106
189
  true
107
190
  /* allow buttons */
108
- ))
191
+ )) {
109
192
  return;
193
+ }
110
194
  if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
111
195
  const index = NUMBERED_SHORTCUT_KEYS[event.key];
112
196
  if (typeof index === "number") {
@@ -120,51 +204,78 @@ function OverflowingToolbar({ children }) {
120
204
  };
121
205
  }, [editor]);
122
206
  const popoverId = "toolbar overflow";
123
- return /* @__PURE__ */ jsxs(Fragment, { children: [
124
- /* @__PURE__ */ jsx("style", { nonce: editor.options.nonce, children: css }),
125
- /* @__PURE__ */ jsxs(
126
- TldrawUiToolbar,
127
- {
128
- className: classNames("tlui-toolbar__tools", {
129
- "tlui-toolbar__tools__mobile": breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM
130
- }),
131
- label: msg("tool-panel.title"),
132
- children: [
133
- /* @__PURE__ */ jsx("div", { id: `${id}_main`, ref: mainToolsRef, className: "tlui-toolbar__tools__list", children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar", sourceId: "toolbar", children }) }),
134
- totalItems > overflowIndex + 1 && /* @__PURE__ */ jsx(IsInOverflowContext.Provider, { value: true, children: /* @__PURE__ */ jsxs(TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
135
- /* @__PURE__ */ jsx(TldrawUiPopoverTrigger, { children: /* @__PURE__ */ jsx(
136
- TldrawUiToolbarButton,
137
- {
138
- title: msg("tool-panel.more"),
139
- type: "tool",
140
- className: "tlui-toolbar__overflow",
141
- "data-testid": "tools.more-button",
142
- children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: "chevron-up" })
143
- }
144
- ) }),
145
- /* @__PURE__ */ jsx(TldrawUiPopoverContent, { side: "top", align: "center", children: /* @__PURE__ */ jsx(
146
- TldrawUiToolbar,
147
- {
148
- className: "tlui-buttons__grid",
149
- "data-testid": "tools.more-content",
150
- label: msg("tool-panel.more"),
151
- id: `${id}_more`,
152
- onClick: () => {
153
- tlmenus.deleteOpenMenu(popoverId, editor.contextId);
154
- setIsOpen(false);
155
- },
156
- children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar-overflow", sourceId: "toolbar", children })
157
- }
158
- ) })
159
- ] }) })
160
- ]
161
- }
162
- )
163
- ] });
207
+ const Layout = orientation === "horizontal" ? TldrawUiRow : TldrawUiColumn;
208
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
209
+ TldrawUiToolbar,
210
+ {
211
+ orientation,
212
+ className: classNames("tlui-main-toolbar__tools", {
213
+ "tlui-main-toolbar__tools__mobile": breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM
214
+ }),
215
+ label: msg("tool-panel.title"),
216
+ children: [
217
+ /* @__PURE__ */ jsx(Layout, { id: `${id}_main`, ref: mainToolsRef, children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar", sourceId: "toolbar", children }) }),
218
+ shouldShowOverflow && /* @__PURE__ */ jsx(IsInOverflowContext.Provider, { value: true, children: /* @__PURE__ */ jsxs(TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
219
+ /* @__PURE__ */ jsx(TldrawUiPopoverTrigger, { children: /* @__PURE__ */ jsx(
220
+ TldrawUiToolbarButton,
221
+ {
222
+ title: msg("tool-panel.more"),
223
+ type: "tool",
224
+ className: "tlui-main-toolbar__overflow",
225
+ "data-testid": "tools.more-button",
226
+ children: /* @__PURE__ */ jsx(
227
+ TldrawUiButtonIcon,
228
+ {
229
+ icon: orientation === "horizontal" ? "chevron-up" : "chevron-right"
230
+ }
231
+ )
232
+ }
233
+ ) }),
234
+ /* @__PURE__ */ jsx(
235
+ TldrawUiPopoverContent,
236
+ {
237
+ side: orientation === "horizontal" ? "top" : "right",
238
+ align: orientation === "horizontal" ? "center" : "end",
239
+ children: /* @__PURE__ */ jsx(
240
+ TldrawUiToolbar,
241
+ {
242
+ orientation: "grid",
243
+ className: "tlui-main-toolbar__overflow-content",
244
+ ref: setOverflowTools,
245
+ "data-testid": "tools.more-content",
246
+ label: msg("tool-panel.more"),
247
+ id: `${id}_more`,
248
+ onClick: () => {
249
+ tlmenus.deleteOpenMenu(popoverId, editor.contextId);
250
+ setIsOpen(false);
251
+ },
252
+ children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar-overflow", sourceId: "toolbar", children })
253
+ }
254
+ )
255
+ }
256
+ )
257
+ ] }) })
258
+ ]
259
+ }
260
+ ) });
164
261
  }
165
262
  const isActiveTLUiToolItem = (item, activeToolId, geoState) => {
166
263
  return item.meta?.geo ? activeToolId === "geo" && geoState === item.meta?.geo : activeToolId === item.id;
167
264
  };
265
+ function findParentWithClassName(startingElement, className) {
266
+ let element = startingElement;
267
+ while (element) {
268
+ if (element.classList.contains(className)) {
269
+ return element;
270
+ }
271
+ element = element.parentElement;
272
+ }
273
+ throw new Error("Could not find parent with class name " + className);
274
+ }
275
+ function setAttribute(element, name, value) {
276
+ if (element.getAttribute(name) === value) return;
277
+ element.setAttribute(name, value);
278
+ }
168
279
  export {
169
280
  IsInOverflowContext,
170
281
  OverflowingToolbar,
@@ -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 { 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\t\t\t#${id}_more > *:nth-of-type(-n + ${overflowIndex + 4}):not([data-radix-popper-content-wrapper]) {\n\t\t\t\tmargin-top: 0;\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\tclassName={classNames('tlui-toolbar__tools', {\n\t\t\t\t\t'tlui-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<div id={`${id}_main`} ref={mainToolsRef} className=\"tlui-toolbar__tools__list\">\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</div>\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-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\tclassName=\"tlui-buttons__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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,cAAa;AAAA;AAAA,YACvC,GACD;AAAA,YACA,oBAAC,0BAAuB,MAAK,OAAM,OAAM,UACxC;AAAA,cAAC;AAAA;AAAA,gBACA,WAAU;AAAA,gBACV,eAAY;AAAA,gBACZ,OAAO,IAAI,iBAAiB;AAAA,gBAC5B,IAAI,GAAG,EAAE;AAAA,gBACT,SAAS,MAAM;AACd,0BAAQ,eAAe,WAAW,OAAO,SAAS;AAClD,4BAAU,KAAK;AAAA,gBAChB;AAAA,gBAEA,8BAAC,+BAA4B,MAAK,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"]
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 {\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": "AA8RE,mBASG,KAMC,YAfJ;AA9RF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,gBAAgB;AACvB,SAAS,eAAe,WAAW,iBAAiB,QAAQ,gBAAgB;AAC5E,SAAS,2BAA2B;AACpC,SAAS,q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", "overflowItems", "didShowAnyInOverflow"]
7
7
  }
@@ -22,8 +22,8 @@ function ToggleToolLockedButton({ activeToolId }) {
22
22
  type: "normal",
23
23
  title: msg("action.toggle-tool-lock"),
24
24
  "data-testid": "tool-lock",
25
- className: classNames("tlui-toolbar__lock-button", {
26
- "tlui-toolbar__lock-button__mobile": breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM
25
+ className: classNames("tlui-main-toolbar__lock-button", {
26
+ "tlui-main-toolbar__lock-button__mobile": breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM
27
27
  }),
28
28
  onClick: () => editor.updateInstanceState({ isToolLocked: !isToolLocked }),
29
29
  children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: isToolLocked ? "lock" : "unlock", small: true })
@@ -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-toolbar__lock-button', {\n\t\t\t\t\t'tlui-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": "AAsCI;AAtCJ,SAAS,WAAW,gBAAgB;AACpC,OAAO,gBAAgB;AACvB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAQzB,SAAS,uBAAuB,EAAE,aAAa,GAAgC;AACrF,QAAM,SAAS,UAAU;AACzB,QAAM,aAAa,cAAc;AACjC,QAAM,MAAM,eAAe;AAE3B,QAAM,eAAe,SAAS,kBAAkB,MAAM,OAAO,iBAAiB,EAAE,cAAc;AAAA,IAC7F;AAAA,EACD,CAAC;AACD,QAAM,OAAO,SAAS,gBAAgB,MAAM,OAAO,eAAe,GAAG,CAAC,MAAM,CAAC;AAE7E,MAAI,CAAC,gBAAgB,CAAC,KAAK,WAAY,QAAO;AAE9C,SACC,oBAAC,mBAAgB,SAAS,IAAI,yBAAyB,GACtD;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,IAAI,yBAAyB;AAAA,MACpC,eAAY;AAAA,MACZ,WAAW,WAAW,6BAA6B;AAAA,QAClD,qCAAqC,aAAa,oBAAoB;AAAA,MACvE,CAAC;AAAA,MACD,SAAS,MAAM,OAAO,oBAAoB,EAAE,cAAc,CAAC,aAAa,CAAC;AAAA,MAEzE,8BAAC,sBAAmB,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 { 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": "AAsCI;AAtCJ,SAAS,WAAW,gBAAgB;AACpC,OAAO,gBAAgB;AACvB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAQzB,SAAS,uBAAuB,EAAE,aAAa,GAAgC;AACrF,QAAM,SAAS,UAAU;AACzB,QAAM,aAAa,cAAc;AACjC,QAAM,MAAM,eAAe;AAE3B,QAAM,eAAe,SAAS,kBAAkB,MAAM,OAAO,iBAAiB,EAAE,cAAc;AAAA,IAC7F;AAAA,EACD,CAAC;AACD,QAAM,OAAO,SAAS,gBAAgB,MAAM,OAAO,eAAe,GAAG,CAAC,MAAM,CAAC;AAE7E,MAAI,CAAC,gBAAgB,CAAC,KAAK,WAAY,QAAO;AAE9C,SACC,oBAAC,mBAAgB,SAAS,IAAI,yBAAyB,GACtD;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,IAAI,yBAAyB;AAAA,MACpC,eAAY;AAAA,MACZ,WAAW,WAAW,kCAAkC;AAAA,QACvD,0CAA0C,aAAa,oBAAoB;AAAA,MAC5E,CAAC;AAAA,MACD,SAAS,MAAM,OAAO,oBAAoB,EAAE,cAAc,CAAC,aAAa,CAAC;AAAA,MAEzE,8BAAC,sBAAmB,MAAM,eAAe,SAAS,UAAU,OAAK,MAAC;AAAA;AAAA,EACnE,GACD;AAEF;",
6
6
  "names": []
7
7
  }