tldraw 3.16.0-canary.cf24aedcd577 → 3.16.0-canary.d98fc0b9bd6a

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 (184) hide show
  1. package/dist-cjs/index.d.ts +74 -1
  2. package/dist-cjs/index.js +5 -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/elbow/ElbowArrowDebug.js +3 -3
  7. package/dist-cjs/lib/shapes/arrow/elbow/ElbowArrowDebug.js.map +1 -1
  8. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +1 -1
  9. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +1 -1
  10. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +4 -4
  11. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js +1 -1
  13. package/dist-cjs/lib/shapes/frame/components/FrameHeading.js.map +2 -2
  14. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +3 -3
  15. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +1 -1
  16. package/dist-cjs/lib/shapes/shared/ShapeFill.js +1 -1
  17. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  18. package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
  19. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -3
  20. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +1 -1
  21. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +25 -1
  22. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  23. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js +12 -0
  24. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  25. package/dist-cjs/lib/ui/assetUrls.js +13 -10
  26. package/dist-cjs/lib/ui/assetUrls.js.map +2 -2
  27. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +1 -1
  28. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +1 -1
  29. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +4 -4
  30. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  31. package/dist-cjs/lib/ui/components/MobileStylePanel.js +1 -1
  32. package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
  33. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +1 -1
  34. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  35. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +68 -91
  36. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  37. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuContext.js.map +2 -2
  38. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +0 -10
  39. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
  40. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +3 -19
  41. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  42. package/dist-cjs/lib/ui/context/actions.js +16 -2
  43. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  44. package/dist-cjs/lib/ui/hooks/useTools.js +21 -3
  45. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  46. package/dist-cjs/lib/ui/version.js +3 -3
  47. package/dist-cjs/lib/ui/version.js.map +1 -1
  48. package/dist-esm/index.d.mts +74 -1
  49. package/dist-esm/index.mjs +5 -1
  50. package/dist-esm/index.mjs.map +2 -2
  51. package/dist-esm/lib/canvas/TldrawScribble.mjs +1 -1
  52. package/dist-esm/lib/canvas/TldrawScribble.mjs.map +2 -2
  53. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs +3 -3
  54. package/dist-esm/lib/shapes/arrow/elbow/ElbowArrowDebug.mjs.map +1 -1
  55. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +1 -1
  56. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +1 -1
  57. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +4 -4
  58. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  59. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs +1 -1
  60. package/dist-esm/lib/shapes/frame/components/FrameHeading.mjs.map +2 -2
  61. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +3 -3
  62. package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +1 -1
  63. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +1 -1
  64. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  65. package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
  66. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -3
  67. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +1 -1
  68. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +26 -1
  69. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  70. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +13 -0
  71. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  72. package/dist-esm/lib/ui/assetUrls.mjs +13 -10
  73. package/dist-esm/lib/ui/assetUrls.mjs.map +2 -2
  74. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +1 -1
  75. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +1 -1
  76. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +4 -4
  77. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  78. package/dist-esm/lib/ui/components/MobileStylePanel.mjs +1 -1
  79. package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
  80. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +1 -1
  81. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  82. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +77 -93
  83. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  84. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuContext.mjs.map +2 -2
  85. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +0 -10
  86. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
  87. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +3 -19
  88. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  89. package/dist-esm/lib/ui/context/actions.mjs +16 -2
  90. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  91. package/dist-esm/lib/ui/hooks/useTools.mjs +22 -3
  92. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  93. package/dist-esm/lib/ui/version.mjs +3 -3
  94. package/dist-esm/lib/ui/version.mjs.map +1 -1
  95. package/package.json +11 -34
  96. package/src/index.ts +3 -0
  97. package/src/lib/canvas/TldrawScribble.tsx +1 -1
  98. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +2 -1
  99. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +4 -3
  100. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +7 -6
  101. package/src/lib/shapes/arrow/elbow/ElbowArrowDebug.tsx +3 -3
  102. package/src/lib/shapes/draw/DrawShapeTool.test.ts +0 -5
  103. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  104. package/src/lib/shapes/frame/FrameShapeUtil.tsx +12 -4
  105. package/src/lib/shapes/frame/components/FrameHeading.tsx +1 -1
  106. package/src/lib/shapes/image/ImageShapeUtil.tsx +3 -3
  107. package/src/lib/shapes/line/LineShapeUtil.test.tsx +4 -3
  108. package/src/lib/shapes/line/__snapshots__/LineShapeUtil.test.tsx.snap +2 -2
  109. package/src/lib/shapes/shared/ShapeFill.tsx +1 -1
  110. package/src/lib/shapes/shared/freehand/svg.ts +2 -0
  111. package/src/lib/shapes/text/TextShapeTool.test.ts +6 -5
  112. package/src/lib/shapes/video/VideoShapeUtil.tsx +3 -3
  113. package/src/lib/tools/EraserTool/childStates/Erasing.ts +34 -1
  114. package/src/lib/tools/EraserTool/childStates/Pointing.ts +20 -0
  115. package/src/lib/ui/assetUrls.ts +13 -10
  116. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +1 -1
  117. package/src/lib/ui/components/Minimap/MinimapManager.ts +4 -4
  118. package/src/lib/ui/components/MobileStylePanel.tsx +1 -1
  119. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +1 -1
  120. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +98 -114
  121. package/src/lib/ui/components/primitives/menus/TldrawUiMenuContext.tsx +0 -1
  122. package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +0 -10
  123. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +5 -18
  124. package/src/lib/ui/context/actions.tsx +16 -2
  125. package/src/lib/ui/hooks/useTools.tsx +25 -3
  126. package/src/lib/ui/version.ts +3 -3
  127. package/src/lib/ui.css +227 -228
  128. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +5 -5
  129. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +4 -4
  130. package/src/test/A11y.test.tsx +3 -2
  131. package/src/test/ClickManager.test.ts +7 -6
  132. package/src/test/Editor.test.tsx +20 -19
  133. package/src/test/EraserTool.test.ts +184 -13
  134. package/src/test/HandTool.test.ts +10 -9
  135. package/src/test/HighlightShape.test.ts +2 -1
  136. package/src/test/SelectTool.test.ts +3 -2
  137. package/src/test/TLUserPreferences.test.ts +4 -3
  138. package/src/test/TestEditor.ts +13 -15
  139. package/src/test/TldrawEditor.test.tsx +11 -10
  140. package/src/test/ZoomTool.test.ts +7 -6
  141. package/src/test/__snapshots__/drawing.test.ts.snap +2 -2
  142. package/src/test/__snapshots__/groups.test.tsx.snap +6 -6
  143. package/src/test/__snapshots__/resizing.test.ts.snap +2 -2
  144. package/src/test/arrows-megabus.test.tsx +5 -4
  145. package/src/test/bindings.test.tsx +24 -37
  146. package/src/test/bookmark-shapes.test.ts +1 -8
  147. package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +23 -7
  148. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +8 -8
  149. package/src/test/commands/__snapshots__/zoomToFit.test.ts.snap +2 -2
  150. package/src/test/commands/alignShapes.test.tsx +25 -24
  151. package/src/test/commands/animationSpeed.test.ts +2 -1
  152. package/src/test/commands/centerOnPoint.test.ts +3 -2
  153. package/src/test/commands/clipboard.test.ts +3 -2
  154. package/src/test/commands/createShapes.test.ts +2 -1
  155. package/src/test/commands/deleteShapes.test.ts +2 -1
  156. package/src/test/commands/distributeShapes.test.tsx +11 -10
  157. package/src/test/commands/getSvgString.test.ts +2 -1
  158. package/src/test/commands/packShapes.test.ts +5 -4
  159. package/src/test/commands/resizeShape.test.ts +2 -1
  160. package/src/test/commands/rotateShapes.test.ts +7 -6
  161. package/src/test/commands/setCamera.test.ts +4 -3
  162. package/src/test/commands/setCurrentPage.test.ts +3 -2
  163. package/src/test/commands/stackShapes.test.ts +11 -10
  164. package/src/test/commands/stretch.test.tsx +13 -12
  165. package/src/test/createDeepLink.test.tsx +2 -1
  166. package/src/test/cropping.test.ts +3 -2
  167. package/src/test/drawing.test.ts +2 -1
  168. package/src/test/flipShapes.test.ts +4 -3
  169. package/src/test/frames.test.ts +25 -24
  170. package/src/test/getCulledShapes.test.tsx +3 -2
  171. package/src/test/groups.test.tsx +1 -1
  172. package/src/test/handleDeepLink.test.tsx +2 -1
  173. package/src/test/maxShapes.test.ts +3 -2
  174. package/src/test/modifiers.test.ts +5 -4
  175. package/src/test/navigation.test.ts +12 -11
  176. package/src/test/panning.test.ts +2 -1
  177. package/src/test/perf/perf.test.ts +2 -1
  178. package/src/test/registerDeepLinkListener.test.tsx +10 -9
  179. package/src/test/resizing.test.ts +39 -38
  180. package/src/test/select.test.tsx +4 -3
  181. package/src/test/selection-omnibus.test.ts +11 -10
  182. package/src/test/shapeutils.test.ts +4 -3
  183. package/src/test/translating.test.ts +9 -8
  184. package/tldraw.css +520 -518
@@ -4,6 +4,7 @@ import {
4
4
  TLGroupShape,
5
5
  TLPointerEventInfo,
6
6
  TLShapeId,
7
+ isAccelKey,
7
8
  pointInPolygon,
8
9
  } from '@tldraw/editor'
9
10
 
@@ -15,7 +16,15 @@ export class Erasing extends StateNode {
15
16
  private markId = ''
16
17
  private excludedShapeIds = new Set<TLShapeId>()
17
18
 
19
+ _isHoldingAccelKey = false
20
+ _firstErasingShapeId: TLShapeId | null = null
21
+ _erasingShapeIds: TLShapeId[] = []
22
+
18
23
  override onEnter(info: TLPointerEventInfo) {
24
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
25
+ this._firstErasingShapeId = this.editor.getErasingShapeIds()[0] // the first one should be the first one we hit... is it?
26
+ this._erasingShapeIds = this.editor.getErasingShapeIds()
27
+
19
28
  this.markId = this.editor.markHistoryStoppingPoint('erase scribble begin')
20
29
  this.info = info
21
30
 
@@ -76,6 +85,16 @@ export class Erasing extends StateNode {
76
85
  this.complete()
77
86
  }
78
87
 
88
+ override onKeyUp() {
89
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
90
+ this.update()
91
+ }
92
+
93
+ override onKeyDown() {
94
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
95
+ this.update()
96
+ }
97
+
79
98
  update() {
80
99
  const { editor, excludedShapeIds } = this
81
100
  const erasingShapeIds = editor.getErasingShapeIds()
@@ -87,6 +106,7 @@ export class Erasing extends StateNode {
87
106
 
88
107
  this.pushPointToScribble()
89
108
 
109
+ // Otherwise, erasing shapes are all the shapes that were hit before plus any new shapes that are hit
90
110
  const erasing = new Set<TLShapeId>(erasingShapeIds)
91
111
  const minDist = this.editor.options.hitTestMargin / zoomLevel
92
112
 
@@ -121,18 +141,31 @@ export class Erasing extends StateNode {
121
141
  if (geometry.hitTestLineSegment(A, B, minDist)) {
122
142
  erasing.add(editor.getOutermostSelectableShape(shape).id)
123
143
  }
144
+
145
+ this._erasingShapeIds = [...erasing]
146
+ }
147
+
148
+ // If the user is holding the meta / ctrl key, we should only erase the first shape we hit
149
+ if (this._isHoldingAccelKey && this._firstErasingShapeId) {
150
+ const erasingShapeId = this._firstErasingShapeId
151
+ if (erasingShapeId && this.editor.getShape(erasingShapeId)) {
152
+ editor.setErasingShapes([erasingShapeId])
153
+ }
154
+ return
124
155
  }
125
156
 
126
157
  // Remove the hit shapes, except if they're in the list of excluded shapes
127
158
  // (these excluded shapes will be any frames or groups the pointer was inside of
128
159
  // when the user started erasing)
129
- this.editor.setErasingShapes([...erasing].filter((id) => !excludedShapeIds.has(id)))
160
+ this.editor.setErasingShapes(this._erasingShapeIds.filter((id) => !excludedShapeIds.has(id)))
130
161
  }
131
162
 
132
163
  complete() {
133
164
  const { editor } = this
134
165
  editor.deleteShapes(editor.getCurrentPageState().erasingShapeIds)
135
166
  this.parent.transition('idle')
167
+ this._erasingShapeIds = []
168
+ this._firstErasingShapeId = null
136
169
  }
137
170
 
138
171
  cancel() {
@@ -1,4 +1,5 @@
1
1
  import {
2
+ isAccelKey,
2
3
  StateNode,
3
4
  TLFrameShape,
4
5
  TLGroupShape,
@@ -9,7 +10,11 @@ import {
9
10
  export class Pointing extends StateNode {
10
11
  static override id = 'pointing'
11
12
 
13
+ _isHoldingAccelKey = false
14
+
12
15
  override onEnter() {
16
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
17
+
13
18
  const zoomLevel = this.editor.getZoomLevel()
14
19
  const currentPageShapesSorted = this.editor.getCurrentPageRenderingShapesSorted()
15
20
  const {
@@ -45,12 +50,25 @@ export class Pointing extends StateNode {
45
50
  }
46
51
 
47
52
  erasing.add(hitShape.id)
53
+
54
+ // If the user is holding the meta / ctrl key, stop after the first shape
55
+ if (this._isHoldingAccelKey) {
56
+ break
57
+ }
48
58
  }
49
59
  }
50
60
 
51
61
  this.editor.setErasingShapes([...erasing])
52
62
  }
53
63
 
64
+ override onKeyUp() {
65
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
66
+ }
67
+
68
+ override onKeyDown() {
69
+ this._isHoldingAccelKey = isAccelKey(this.editor.inputs)
70
+ }
71
+
54
72
  override onLongPress(info: TLPointerEventInfo) {
55
73
  this.startErasing(info)
56
74
  }
@@ -62,6 +80,8 @@ export class Pointing extends StateNode {
62
80
  }
63
81
 
64
82
  override onPointerMove(info: TLPointerEventInfo) {
83
+ if (this._isHoldingAccelKey) return
84
+
65
85
  if (this.editor.inputs.isDragging) {
66
86
  this.startErasing(info)
67
87
  }
@@ -1,4 +1,5 @@
1
1
  import { LANGUAGES, RecursivePartial, getDefaultCdnBaseUrl } from '@tldraw/editor'
2
+ import { useMemo } from 'react'
2
3
  import { DEFAULT_EMBED_DEFINITIONS } from '../defaultEmbedDefinitions'
3
4
  import { TLEditorAssetUrls, defaultEditorAssetUrls } from '../utils/static-assets/assetUrls'
4
5
  import { TLUiIconType, iconTypes } from './icon-types'
@@ -41,15 +42,17 @@ export function setDefaultUiAssetUrls(urls: TLUiAssetUrls) {
41
42
  export function useDefaultUiAssetUrlsWithOverrides(
42
43
  overrides?: TLUiAssetUrlOverrides
43
44
  ): TLUiAssetUrls {
44
- if (!overrides) return defaultUiAssetUrls
45
+ return useMemo(() => {
46
+ if (!overrides) return defaultUiAssetUrls
45
47
 
46
- return {
47
- fonts: Object.assign({ ...defaultUiAssetUrls.fonts }, { ...overrides?.fonts }),
48
- icons: Object.assign({ ...defaultUiAssetUrls.icons }, { ...overrides?.icons }),
49
- embedIcons: Object.assign({ ...defaultUiAssetUrls.embedIcons }, { ...overrides?.embedIcons }),
50
- translations: Object.assign(
51
- { ...defaultUiAssetUrls.translations },
52
- { ...overrides?.translations }
53
- ),
54
- }
48
+ return {
49
+ fonts: Object.assign({ ...defaultUiAssetUrls.fonts }, { ...overrides?.fonts }),
50
+ icons: Object.assign({ ...defaultUiAssetUrls.icons }, { ...overrides?.icons }),
51
+ embedIcons: Object.assign({ ...defaultUiAssetUrls.embedIcons }, { ...overrides?.embedIcons }),
52
+ translations: Object.assign(
53
+ { ...defaultUiAssetUrls.translations },
54
+ { ...overrides?.translations }
55
+ ),
56
+ }
57
+ }, [overrides])
55
58
  }
@@ -123,7 +123,7 @@ export function DefaultKeyboardShortcutsDialogContent() {
123
123
  <TldrawUiMenuItem
124
124
  id="text-header"
125
125
  label="tool.rich-text-header"
126
- kbd="cmd+shift+[[1-6]]"
126
+ kbd="cmd+alt+[[1-6]]"
127
127
  onSelect={() => {
128
128
  /* do nothing */
129
129
  }}
@@ -46,10 +46,10 @@ export class MinimapManager {
46
46
  const style = getComputedStyle(this.editor.getContainer())
47
47
 
48
48
  return {
49
- shapeFill: getRgba(style.getPropertyValue('--color-text-3').trim()),
50
- selectFill: getRgba(style.getPropertyValue('--color-selected').trim()),
51
- viewportFill: getRgba(style.getPropertyValue('--color-muted-1').trim()),
52
- background: getRgba(style.getPropertyValue('--color-low').trim()),
49
+ shapeFill: getRgba(style.getPropertyValue('--tl-color-text-3').trim()),
50
+ selectFill: getRgba(style.getPropertyValue('--tl-color-selected').trim()),
51
+ viewportFill: getRgba(style.getPropertyValue('--tl-color-muted-1').trim()),
52
+ background: getRgba(style.getPropertyValue('--tl-color-low').trim()),
53
53
  }
54
54
  }
55
55
 
@@ -57,7 +57,7 @@ export function MobileStylePanel() {
57
57
  type="tool"
58
58
  data-testid="mobile-styles.button"
59
59
  style={{
60
- color: disableStylePanel ? 'var(--color-muted-1)' : currentColor,
60
+ color: disableStylePanel ? 'var(--tl-color-muted-1)' : currentColor,
61
61
  }}
62
62
  title={msg('style-panel.title')}
63
63
  disabled={disableStylePanel}
@@ -272,7 +272,7 @@ export const DefaultImageToolbarContent = track(function DefaultImageToolbarCont
272
272
  type="icon"
273
273
  onClick={onManipulatingEnd}
274
274
  data-testid="tool.image-confirm"
275
- style={{ borderLeft: '1px solid var(--color-divider)', marginLeft: '2px' }}
275
+ style={{ borderLeft: '1px solid var(--tl-color-divider)', marginLeft: '2px' }}
276
276
  >
277
277
  <TldrawUiButtonIcon small icon="check" />
278
278
  </TldrawUiButton>
@@ -1,7 +1,14 @@
1
- import { assert, Editor, uniqueId, useMaybeEditor, Vec } from '@tldraw/editor'
1
+ import { assert, Atom, atom, Editor, uniqueId, useMaybeEditor, useValue } from '@tldraw/editor'
2
2
  import { Tooltip as _Tooltip } from 'radix-ui'
3
- import React, { createContext, forwardRef, useContext, useEffect, useRef, useState } from 'react'
4
- import { usePrefersReducedMotion } from '../../../shapes/shared/usePrefersReducedMotion'
3
+ import React, {
4
+ createContext,
5
+ forwardRef,
6
+ ReactNode,
7
+ useContext,
8
+ useEffect,
9
+ useRef,
10
+ useState,
11
+ } from 'react'
5
12
  import { useTldrawUiOrientation } from './layout'
6
13
 
7
14
  const DEFAULT_TOOLTIP_DELAY_MS = 700
@@ -13,19 +20,23 @@ export interface TldrawUiTooltipProps {
13
20
  side?: 'top' | 'right' | 'bottom' | 'left'
14
21
  sideOffset?: number
15
22
  disabled?: boolean
23
+ showOnMobile?: boolean
24
+ delayDuration?: number
16
25
  }
17
26
 
18
27
  // Singleton tooltip manager
19
28
  class TooltipManager {
20
29
  private static instance: TooltipManager | null = null
21
- private currentTooltipId: string | null = null
22
- private currentContent: string | React.ReactNode = ''
23
- private currentSide: 'top' | 'right' | 'bottom' | 'left' = 'bottom'
24
- private currentSideOffset: number = 5
30
+ private currentTooltip = atom<{
31
+ id: string
32
+ content: ReactNode
33
+ side: 'top' | 'right' | 'bottom' | 'left'
34
+ sideOffset: number
35
+ showOnMobile: boolean
36
+ targetElement: HTMLElement
37
+ delayDuration: number | undefined
38
+ } | null>('current tooltip', null)
25
39
  private destroyTimeoutId: number | null = null
26
- private subscribers: Set<() => void> = new Set()
27
- private activeElement: HTMLElement | null = null
28
- private editor: Editor | null = null
29
40
 
30
41
  static getInstance(): TooltipManager {
31
42
  if (!TooltipManager.instance) {
@@ -34,25 +45,14 @@ class TooltipManager {
34
45
  return TooltipManager.instance
35
46
  }
36
47
 
37
- setEditor(editor: Editor | null) {
38
- this.editor = editor
39
- }
40
-
41
- subscribe(callback: () => void): () => void {
42
- this.subscribers.add(callback)
43
- return () => this.subscribers.delete(callback)
44
- }
45
-
46
- private notify() {
47
- this.subscribers.forEach((callback) => callback())
48
- }
49
-
50
48
  showTooltip(
51
49
  tooltipId: string,
52
50
  content: string | React.ReactNode,
53
- element: HTMLElement,
54
- side: 'top' | 'right' | 'bottom' | 'left' = 'bottom',
55
- sideOffset: number = 5
51
+ targetElement: HTMLElement,
52
+ side: 'top' | 'right' | 'bottom' | 'left',
53
+ sideOffset: number,
54
+ showOnMobile: boolean,
55
+ delayDuration: number | undefined
56
56
  ) {
57
57
  // Clear any existing destroy timeout
58
58
  if (this.destroyTimeoutId) {
@@ -61,51 +61,57 @@ class TooltipManager {
61
61
  }
62
62
 
63
63
  // Update current tooltip
64
- this.currentTooltipId = tooltipId
65
- this.currentContent = content
66
- this.currentSide = side
67
- this.currentSideOffset = sideOffset
68
- this.activeElement = element
69
-
70
- this.notify()
64
+ this.currentTooltip.set({
65
+ id: tooltipId,
66
+ content,
67
+ side,
68
+ sideOffset,
69
+ showOnMobile,
70
+ targetElement,
71
+ delayDuration,
72
+ })
71
73
  }
72
74
 
73
- hideTooltip(tooltipId: string, instant: boolean = false) {
75
+ hideTooltip(editor: Editor | null, tooltipId: string, instant: boolean = false) {
74
76
  const hide = () => {
75
77
  // Only hide if this is the current tooltip
76
- if (this.currentTooltipId === tooltipId) {
77
- this.currentTooltipId = null
78
- this.currentContent = ''
79
- this.activeElement = null
78
+ if (this.currentTooltip.get()?.id === tooltipId) {
79
+ this.currentTooltip.set(null)
80
80
  this.destroyTimeoutId = null
81
- this.notify()
82
81
  }
83
82
  }
84
83
 
85
- if (instant) {
86
- hide()
87
- } else if (this.editor) {
84
+ if (editor && !instant) {
88
85
  // Start destroy timeout (1 second)
89
- this.destroyTimeoutId = this.editor.timers.setTimeout(hide, 300)
86
+ this.destroyTimeoutId = editor.timers.setTimeout(hide, 300)
87
+ } else {
88
+ hide()
90
89
  }
91
90
  }
92
91
 
93
92
  hideAllTooltips() {
94
- this.currentTooltipId = null
95
- this.currentContent = ''
96
- this.activeElement = null
93
+ this.currentTooltip.set(null)
97
94
  this.destroyTimeoutId = null
98
- this.notify()
99
95
  }
100
96
 
101
97
  getCurrentTooltipData() {
102
- return {
103
- id: this.currentTooltipId,
104
- content: this.currentContent,
105
- side: this.currentSide,
106
- sideOffset: this.currentSideOffset,
107
- element: this.activeElement,
98
+ const currentTooltip = this.currentTooltip.get()
99
+ if (!currentTooltip) return null
100
+ if (!this.supportsHover() && !currentTooltip.showOnMobile) return null
101
+ return currentTooltip
102
+ }
103
+
104
+ private supportsHoverAtom: Atom<boolean> | null = null
105
+ supportsHover() {
106
+ if (!this.supportsHoverAtom) {
107
+ const mediaQuery = window.matchMedia('(hover: hover)')
108
+ const supportsHover = atom('has hover', mediaQuery.matches)
109
+ this.supportsHoverAtom = supportsHover
110
+ mediaQuery.addEventListener('change', (e) => {
111
+ supportsHover.set(e.matches)
112
+ })
108
113
  }
114
+ return this.supportsHoverAtom.get()
109
115
  }
110
116
  }
111
117
 
@@ -134,65 +140,30 @@ export function TldrawUiTooltipProvider({ children }: TldrawUiTooltipProviderPro
134
140
  // The singleton tooltip component that renders once
135
141
  function TooltipSingleton() {
136
142
  const editor = useMaybeEditor()
137
- const [, forceUpdate] = useState({})
138
143
  const [isOpen, setIsOpen] = useState(false)
139
144
  const triggerRef = useRef<HTMLDivElement>(null)
140
- const previousPositionRef = useRef<{ x: number; y: number } | null>(null)
141
- const prefersReducedMotion = usePrefersReducedMotion()
142
- const [shouldAnimate, setShouldAnimate] = useState(false)
143
145
  const isFirstShowRef = useRef(true)
144
146
  const showTimeoutRef = useRef<number | null>(null)
145
147
 
146
- // Set editor in tooltip manager
147
- useEffect(() => {
148
- tooltipManager.setEditor(editor)
149
- }, [editor])
150
-
151
- // Subscribe to tooltip manager updates
152
- useEffect(() => {
153
- const unsubscribe = tooltipManager.subscribe(() => {
154
- forceUpdate({})
155
- })
156
- return unsubscribe
157
- }, [])
158
-
159
- const tooltipData = tooltipManager.getCurrentTooltipData()
148
+ const currentTooltip = useValue(
149
+ 'current tooltip',
150
+ () => tooltipManager.getCurrentTooltipData(),
151
+ []
152
+ )
160
153
 
161
154
  // Update open state and trigger position
162
155
  useEffect(() => {
163
- const shouldBeOpen = Boolean(tooltipData.id && tooltipData.element)
164
-
165
156
  // Clear any existing show timeout
166
157
  if (showTimeoutRef.current) {
167
158
  clearTimeout(showTimeoutRef.current)
168
159
  showTimeoutRef.current = null
169
160
  }
170
161
 
171
- if (shouldBeOpen && tooltipData.element && triggerRef.current) {
162
+ if (currentTooltip && triggerRef.current) {
172
163
  // Position the invisible trigger element over the active element
173
- const activeRect = tooltipData.element.getBoundingClientRect()
164
+ const activeRect = currentTooltip.targetElement.getBoundingClientRect()
174
165
  const trigger = triggerRef.current
175
166
 
176
- const newPosition = {
177
- x: activeRect.left + activeRect.width / 2,
178
- y: activeRect.top + activeRect.height / 2,
179
- }
180
-
181
- // Determine if we should animate
182
- let shouldAnimateCheck = false
183
- if (previousPositionRef.current) {
184
- const isNearPrevious = Vec.DistMin(previousPositionRef.current, newPosition, 200)
185
- // Only animate if the distance is less than 200px (nearby tooltips)
186
- shouldAnimateCheck =
187
- !prefersReducedMotion &&
188
- isNearPrevious &&
189
- Math.abs(newPosition.y - previousPositionRef.current.y) < 50
190
- }
191
- // Don't animate on initial show (previousPositionRef.current is null)
192
-
193
- setShouldAnimate(isFirstShowRef.current ? false : shouldAnimateCheck)
194
- previousPositionRef.current = newPosition
195
-
196
167
  trigger.style.position = 'fixed'
197
168
  trigger.style.left = `${activeRect.left}px`
198
169
  trigger.style.top = `${activeRect.top}px`
@@ -206,23 +177,20 @@ function TooltipSingleton() {
206
177
  showTimeoutRef.current = editor.timers.setTimeout(() => {
207
178
  setIsOpen(true)
208
179
  isFirstShowRef.current = false
209
- }, editor.options.tooltipDelayMs)
180
+ }, currentTooltip.delayDuration ?? editor.options.tooltipDelayMs)
210
181
  } else {
211
182
  // Subsequent tooltips show immediately
212
183
  setIsOpen(true)
213
184
  }
214
- } else if (!shouldBeOpen) {
185
+ } else {
215
186
  // Hide tooltip immediately
216
187
  setIsOpen(false)
217
- // Reset position tracking when tooltip closes
218
- previousPositionRef.current = null
219
- setShouldAnimate(false)
220
188
  // Reset first show state after tooltip is hidden
221
189
  isFirstShowRef.current = true
222
190
  }
223
- }, [tooltipData.id, tooltipData.element, editor, prefersReducedMotion])
191
+ }, [editor, currentTooltip])
224
192
 
225
- if (!tooltipData.id) {
193
+ if (!currentTooltip) {
226
194
  return null
227
195
  }
228
196
 
@@ -233,14 +201,13 @@ function TooltipSingleton() {
233
201
  </_Tooltip.Trigger>
234
202
  <_Tooltip.Content
235
203
  className="tlui-tooltip"
236
- data-should-animate={shouldAnimate}
237
- side={tooltipData.side}
238
- sideOffset={tooltipData.sideOffset}
204
+ side={currentTooltip.side}
205
+ sideOffset={currentTooltip.sideOffset}
239
206
  avoidCollisions
240
207
  collisionPadding={8}
241
208
  dir="ltr"
242
209
  >
243
- {tooltipData.content}
210
+ {currentTooltip.content}
244
211
  <_Tooltip.Arrow className="tlui-tooltip__arrow" />
245
212
  </_Tooltip.Content>
246
213
  </_Tooltip.Root>
@@ -249,7 +216,18 @@ function TooltipSingleton() {
249
216
 
250
217
  /** @public @react */
251
218
  export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProps>(
252
- ({ children, content, side, sideOffset = 5, disabled = false }, ref) => {
219
+ (
220
+ {
221
+ children,
222
+ content,
223
+ side,
224
+ sideOffset = 5,
225
+ disabled = false,
226
+ showOnMobile = false,
227
+ delayDuration,
228
+ },
229
+ ref
230
+ ) => {
253
231
  const editor = useMaybeEditor()
254
232
  const tooltipId = useRef<string>(uniqueId())
255
233
  const hasProvider = useContext(TooltipSingletonContext)
@@ -261,10 +239,10 @@ export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProp
261
239
  const currentTooltipId = tooltipId.current
262
240
  return () => {
263
241
  if (hasProvider) {
264
- tooltipManager.hideTooltip(currentTooltipId, true)
242
+ tooltipManager.hideTooltip(editor, currentTooltipId, true)
265
243
  }
266
244
  }
267
- }, [hasProvider])
245
+ }, [editor, hasProvider])
268
246
 
269
247
  // Don't show tooltip if disabled, no content, or UI labels are disabled
270
248
  if (disabled || !content) {
@@ -275,7 +253,9 @@ export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProp
275
253
  if (!hasProvider) {
276
254
  return (
277
255
  <_Tooltip.Root
278
- delayDuration={editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS}
256
+ delayDuration={
257
+ delayDuration ?? (editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS)
258
+ }
279
259
  disableHoverableContent
280
260
  >
281
261
  <_Tooltip.Trigger asChild ref={ref}>
@@ -306,13 +286,15 @@ export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProp
306
286
  content,
307
287
  event.currentTarget as HTMLElement,
308
288
  sideToUse,
309
- sideOffset
289
+ sideOffset,
290
+ showOnMobile,
291
+ delayDuration
310
292
  )
311
293
  }
312
294
 
313
295
  const handleMouseLeave = (event: React.MouseEvent<HTMLElement>) => {
314
296
  child.props.onMouseLeave?.(event)
315
- tooltipManager.hideTooltip(tooltipId.current)
297
+ tooltipManager.hideTooltip(editor, tooltipId.current)
316
298
  }
317
299
 
318
300
  const handleFocus = (event: React.FocusEvent<HTMLElement>) => {
@@ -322,13 +304,15 @@ export const TldrawUiTooltip = forwardRef<HTMLButtonElement, TldrawUiTooltipProp
322
304
  content,
323
305
  event.currentTarget as HTMLElement,
324
306
  sideToUse,
325
- sideOffset
307
+ sideOffset,
308
+ showOnMobile,
309
+ delayDuration
326
310
  )
327
311
  }
328
312
 
329
313
  const handleBlur = (event: React.FocusEvent<HTMLElement>) => {
330
314
  child.props.onBlur?.(event)
331
- tooltipManager.hideTooltip(tooltipId.current)
315
+ tooltipManager.hideTooltip(editor, tooltipId.current)
332
316
  }
333
317
 
334
318
  const childrenWithHandlers = React.cloneElement(children as React.ReactElement, {
@@ -3,7 +3,6 @@ import { TLUiEventSource } from '../../../context/events'
3
3
 
4
4
  /** @public */
5
5
  export type TLUiMenuContextType =
6
- | 'panel'
7
6
  | 'menu'
8
7
  | 'small-icons'
9
8
  | 'context-menu'
@@ -27,16 +27,6 @@ export function TldrawUiMenuGroup({ id, label, className, children }: TLUiMenuGr
27
27
  const labelStr = labelToUse ? msg(labelToUse as TLUiTranslationKey) : undefined
28
28
 
29
29
  switch (menu.type) {
30
- case 'panel': {
31
- return (
32
- <div
33
- className={classNames('tlui-menu__group', className)}
34
- data-testid={`${menu.sourceId}-group.${id}`}
35
- >
36
- {children}
37
- </div>
38
- )
39
- }
40
30
  case 'menu': {
41
31
  return (
42
32
  <TldrawUiDropdownMenuGroup
@@ -120,7 +120,6 @@ export function TldrawUiMenuItem<
120
120
  type="menu"
121
121
  data-testid={`${sourceId}.${id}`}
122
122
  disabled={disabled}
123
- title={titleStr}
124
123
  onClick={(e) => {
125
124
  if (noClose) {
126
125
  preventDefault(e)
@@ -146,7 +145,6 @@ export function TldrawUiMenuItem<
146
145
  return (
147
146
  <_ContextMenu.Item
148
147
  dir="ltr"
149
- title={titleStr}
150
148
  draggable={false}
151
149
  className="tlui-button tlui-button__menu"
152
150
  data-testid={`${sourceId}.${id}`}
@@ -168,20 +166,6 @@ export function TldrawUiMenuItem<
168
166
  </_ContextMenu.Item>
169
167
  )
170
168
  }
171
- case 'panel': {
172
- return (
173
- <TldrawUiButton
174
- data-testid={`${sourceId}.${id}`}
175
- type="menu"
176
- title={titleStr}
177
- disabled={disabled}
178
- onClick={() => onSelect(sourceId)}
179
- >
180
- <TldrawUiButtonLabel>{labelStr}</TldrawUiButtonLabel>
181
- {spinner ? <Spinner /> : icon && <TldrawUiButtonIcon icon={icon} />}
182
- </TldrawUiButton>
183
- )
184
- }
185
169
  case 'small-icons':
186
170
  case 'icons': {
187
171
  return (
@@ -332,8 +316,8 @@ function useDraggableEvents(
332
316
  if (
333
317
  distanceSq >
334
318
  (editor.getInstanceState().isCoarsePointer
335
- ? editor.options.coarseDragDistanceSquared
336
- : editor.options.dragDistanceSquared)
319
+ ? editor.options.uiCoarseDragDistanceSquared
320
+ : editor.options.uiDragDistanceSquared)
337
321
  ) {
338
322
  const screenSpaceStart = state.screenSpaceStart
339
323
  state = {
@@ -342,6 +326,8 @@ function useDraggableEvents(
342
326
  }
343
327
 
344
328
  editor.run(() => {
329
+ editor.setCurrentTool('select')
330
+
345
331
  // Set origin point
346
332
  editor.dispatch({
347
333
  type: 'pointer',
@@ -364,6 +350,7 @@ function useDraggableEvents(
364
350
  })
365
351
 
366
352
  tooltipManager.hideAllTooltips()
353
+ editor.getContainer().focus()
367
354
  })
368
355
  }
369
356
  }