tldraw 3.16.0-canary.62bc202550a3 → 3.16.0-canary.647d8c899f30

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 (180) hide show
  1. package/dist-cjs/index.d.ts +15 -9
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/defaultExternalContentHandlers.js +10 -0
  4. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  5. package/dist-cjs/lib/shapes/arrow/arrow-types.js.map +1 -1
  6. package/dist-cjs/lib/shapes/arrow/arrowLabel.js +6 -0
  7. package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +3 -3
  8. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js +3 -2
  9. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
  10. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +4 -4
  11. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +2 -1
  13. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js +8 -2
  15. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js.map +2 -2
  16. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +1 -0
  17. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  18. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +2 -1
  19. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +4 -4
  21. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js.map +2 -2
  22. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js +3 -3
  23. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  24. package/dist-cjs/lib/shapes/text/PlainTextArea.js +3 -2
  25. package/dist-cjs/lib/shapes/text/PlainTextArea.js.map +2 -2
  26. package/dist-cjs/lib/shapes/text/RichTextArea.js +3 -3
  27. package/dist-cjs/lib/shapes/text/RichTextArea.js.map +2 -2
  28. package/dist-cjs/lib/ui/components/A11y.js +1 -1
  29. package/dist-cjs/lib/ui/components/A11y.js.map +2 -2
  30. package/dist-cjs/lib/ui/components/LanguageMenu.js +1 -0
  31. package/dist-cjs/lib/ui/components/LanguageMenu.js.map +2 -2
  32. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +2 -1
  33. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js.map +2 -2
  34. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +1 -1
  35. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  36. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js +11 -2
  37. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +2 -2
  38. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +3 -2
  39. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  40. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +5 -4
  41. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  42. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +1 -1
  43. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +2 -2
  44. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +6 -2
  45. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  46. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +1 -1
  47. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  48. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +5 -3
  49. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js.map +2 -2
  50. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +1 -1
  51. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  52. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +1 -0
  53. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  54. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +40 -3
  55. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  56. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js +3 -0
  57. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
  58. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +8 -8
  59. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  60. package/dist-cjs/lib/ui/context/actions.js +6 -0
  61. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  62. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +1 -1
  63. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
  64. package/dist-cjs/lib/ui/hooks/useTools.js +1 -1
  65. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  66. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  67. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +4 -2
  68. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  69. package/dist-cjs/lib/ui/version.js +3 -3
  70. package/dist-cjs/lib/ui/version.js.map +1 -1
  71. package/dist-esm/index.d.mts +15 -9
  72. package/dist-esm/index.mjs +1 -1
  73. package/dist-esm/lib/defaultExternalContentHandlers.mjs +10 -0
  74. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  75. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +6 -0
  76. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +3 -3
  77. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs +3 -2
  78. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
  79. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +4 -5
  80. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
  81. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +2 -1
  82. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  83. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs +9 -3
  84. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs.map +2 -2
  85. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +1 -0
  86. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  87. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +2 -1
  88. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  89. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs +5 -5
  90. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs.map +2 -2
  91. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs +3 -4
  92. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  93. package/dist-esm/lib/shapes/text/PlainTextArea.mjs +4 -3
  94. package/dist-esm/lib/shapes/text/PlainTextArea.mjs.map +2 -2
  95. package/dist-esm/lib/shapes/text/RichTextArea.mjs +3 -4
  96. package/dist-esm/lib/shapes/text/RichTextArea.mjs.map +2 -2
  97. package/dist-esm/lib/ui/components/A11y.mjs +1 -2
  98. package/dist-esm/lib/ui/components/A11y.mjs.map +2 -2
  99. package/dist-esm/lib/ui/components/LanguageMenu.mjs +1 -0
  100. package/dist-esm/lib/ui/components/LanguageMenu.mjs.map +2 -2
  101. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs +2 -1
  102. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs.map +2 -2
  103. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +1 -2
  104. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  105. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +11 -2
  106. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +2 -2
  107. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +3 -2
  108. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  109. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +5 -4
  110. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  111. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +1 -1
  112. package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +2 -2
  113. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +6 -2
  114. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  115. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +1 -2
  116. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  117. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs +6 -4
  118. package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs.map +2 -2
  119. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +1 -1
  120. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  121. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +1 -0
  122. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  123. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +41 -3
  124. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  125. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs +3 -0
  126. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
  127. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +8 -8
  128. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  129. package/dist-esm/lib/ui/context/actions.mjs +6 -0
  130. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  131. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +1 -2
  132. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
  133. package/dist-esm/lib/ui/hooks/useTools.mjs +1 -1
  134. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  135. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +4 -2
  136. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  137. package/dist-esm/lib/ui/version.mjs +3 -3
  138. package/dist-esm/lib/ui/version.mjs.map +1 -1
  139. package/package.json +3 -3
  140. package/src/lib/defaultExternalContentHandlers.ts +14 -0
  141. package/src/lib/shapes/arrow/ArrowShapeOptions.test.ts +83 -13
  142. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +2 -2
  143. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +41 -0
  144. package/src/lib/shapes/arrow/arrow-types.ts +3 -5
  145. package/src/lib/shapes/arrow/arrowLabel.ts +8 -0
  146. package/src/lib/shapes/arrow/arrowTargetState.ts +4 -3
  147. package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +4 -5
  148. package/src/lib/shapes/frame/FrameShapeUtil.tsx +1 -0
  149. package/src/lib/shapes/frame/components/FrameLabelInput.tsx +10 -3
  150. package/src/lib/shapes/geo/GeoShapeUtil.tsx +1 -0
  151. package/src/lib/shapes/note/NoteShapeUtil.tsx +1 -0
  152. package/src/lib/shapes/shared/HyperlinkButton.tsx +5 -5
  153. package/src/lib/shapes/shared/useEditablePlainText.ts +3 -4
  154. package/src/lib/shapes/text/PlainTextArea.tsx +4 -3
  155. package/src/lib/shapes/text/RichTextArea.tsx +3 -4
  156. package/src/lib/ui/components/A11y.tsx +1 -2
  157. package/src/lib/ui/components/LanguageMenu.tsx +1 -0
  158. package/src/lib/ui/components/Minimap/DefaultMinimap.tsx +2 -1
  159. package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +1 -2
  160. package/src/lib/ui/components/StylePanel/StylePanelButtonPicker.tsx +9 -2
  161. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +4 -3
  162. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +6 -5
  163. package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +1 -1
  164. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +9 -2
  165. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +1 -2
  166. package/src/lib/ui/components/primitives/TldrawUiInput.tsx +6 -3
  167. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +2 -2
  168. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +2 -1
  169. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +57 -13
  170. package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +4 -0
  171. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +9 -9
  172. package/src/lib/ui/context/actions.tsx +13 -0
  173. package/src/lib/ui/hooks/useClipboardEvents.ts +1 -2
  174. package/src/lib/ui/hooks/useTools.tsx +1 -1
  175. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +2 -0
  176. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +4 -2
  177. package/src/lib/ui/version.ts +3 -3
  178. package/src/lib/ui.css +10 -0
  179. package/src/test/getCulledShapes.test.tsx +71 -2
  180. package/tldraw.css +18 -3
@@ -901,8 +901,22 @@ export function notifyIfFileNotAllowed(file: File, options: TLDefaultExternalCon
901
901
  }
902
902
 
903
903
  if (file.size > maxAssetSize) {
904
+ const formatBytes = (bytes: number): string => {
905
+ if (bytes === 0) return '0 bytes'
906
+
907
+ const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
908
+ const base = 1024
909
+ const unitIndex = Math.floor(Math.log(bytes) / Math.log(base))
910
+
911
+ const value = bytes / Math.pow(base, unitIndex)
912
+ const formatted = value % 1 === 0 ? value.toString() : value.toFixed(1)
913
+
914
+ return `${formatted} ${units[unitIndex]}`
915
+ }
916
+
904
917
  toasts.addToast({
905
918
  title: msg('assets.files.size-too-big'),
919
+ description: msg('assets.files.maximum-size').replace('{size}', formatBytes(maxAssetSize)),
906
920
  severity: 'error',
907
921
  })
908
922
  return false
@@ -47,13 +47,21 @@ describe('ArrowShapeOptions', () => {
47
47
  it('should have correct default shouldBeExact behavior (alt key)', () => {
48
48
  const util = editor.getShapeUtil<ArrowShapeUtil>('arrow')
49
49
 
50
- // Test without alt key
50
+ // Test without alt key, not precise
51
51
  editor.inputs.altKey = false
52
- expect(util.options.shouldBeExact(editor)).toBe(false)
52
+ expect(util.options.shouldBeExact(editor, false)).toBe(false)
53
53
 
54
- // Test with alt key
54
+ // Test without alt key, precise
55
+ editor.inputs.altKey = false
56
+ expect(util.options.shouldBeExact(editor, true)).toBe(false)
57
+
58
+ // Test with alt key, not precise
59
+ editor.inputs.altKey = true
60
+ expect(util.options.shouldBeExact(editor, false)).toBe(true)
61
+
62
+ // Test with alt key, precise
55
63
  editor.inputs.altKey = true
56
- expect(util.options.shouldBeExact(editor)).toBe(true)
64
+ expect(util.options.shouldBeExact(editor, true)).toBe(true)
57
65
  })
58
66
 
59
67
  it('should have correct default shouldIgnoreTargets behavior (ctrl key)', () => {
@@ -186,7 +194,7 @@ describe('ArrowShapeOptions', () => {
186
194
  class CustomArrowShapeUtil extends ArrowShapeUtil {
187
195
  override options = {
188
196
  ...baseUtil.options,
189
- shouldBeExact: (editor: any) => editor.inputs.shiftKey, // Use shift instead of alt
197
+ shouldBeExact: (editor: any, _isPrecise: boolean) => editor.inputs.shiftKey, // Use shift instead of alt
190
198
  }
191
199
  }
192
200
 
@@ -195,12 +203,14 @@ describe('ArrowShapeOptions', () => {
195
203
  // Test with shift key
196
204
  editor.inputs.shiftKey = true
197
205
  editor.inputs.altKey = false
198
- expect(customUtil.options.shouldBeExact(editor)).toBe(true)
206
+ expect(customUtil.options.shouldBeExact(editor, false)).toBe(true)
207
+ expect(customUtil.options.shouldBeExact(editor, true)).toBe(true)
199
208
 
200
209
  // Test without shift key
201
210
  editor.inputs.shiftKey = false
202
211
  editor.inputs.altKey = true // Alt key should not matter for custom implementation
203
- expect(customUtil.options.shouldBeExact(editor)).toBe(false)
212
+ expect(customUtil.options.shouldBeExact(editor, false)).toBe(false)
213
+ expect(customUtil.options.shouldBeExact(editor, true)).toBe(false)
204
214
  })
205
215
 
206
216
  it('should allow customizing shouldIgnoreTargets behavior', () => {
@@ -232,9 +242,9 @@ describe('ArrowShapeOptions', () => {
232
242
  class CustomArrowShapeUtil extends ArrowShapeUtil {
233
243
  override options = {
234
244
  ...baseUtil.options,
235
- shouldBeExact: (editor: any) => {
236
- // Custom logic: exact when both alt and shift are pressed
237
- return editor.inputs.altKey && editor.inputs.shiftKey
245
+ shouldBeExact: (editor: any, isPrecise: boolean) => {
246
+ // Custom logic: exact when both alt and shift are pressed, and only if precise
247
+ return editor.inputs.altKey && editor.inputs.shiftKey && isPrecise
238
248
  },
239
249
  shouldIgnoreTargets: (editor: any) => {
240
250
  // Custom logic: ignore targets when any modifier key is pressed
@@ -245,15 +255,20 @@ describe('ArrowShapeOptions', () => {
245
255
 
246
256
  const customUtil = new CustomArrowShapeUtil(editor)
247
257
 
248
- // Test shouldBeExact with both keys
258
+ // Test shouldBeExact with both keys and precise
249
259
  editor.inputs.altKey = true
250
260
  editor.inputs.shiftKey = true
251
- expect(customUtil.options.shouldBeExact(editor)).toBe(true)
261
+ expect(customUtil.options.shouldBeExact(editor, true)).toBe(true)
262
+
263
+ // Test shouldBeExact with both keys but not precise
264
+ editor.inputs.altKey = true
265
+ editor.inputs.shiftKey = true
266
+ expect(customUtil.options.shouldBeExact(editor, false)).toBe(false)
252
267
 
253
268
  // Test shouldBeExact with only one key
254
269
  editor.inputs.altKey = true
255
270
  editor.inputs.shiftKey = false
256
- expect(customUtil.options.shouldBeExact(editor)).toBe(false)
271
+ expect(customUtil.options.shouldBeExact(editor, true)).toBe(false)
257
272
 
258
273
  // Test shouldIgnoreTargets with any key
259
274
  editor.inputs.altKey = false
@@ -283,6 +298,61 @@ describe('ArrowShapeOptions', () => {
283
298
  expect(editor.getCurrentToolId()).toBe('arrow')
284
299
  })
285
300
 
301
+ it('should allow custom shouldBeExact logic based on isPrecise - example from arrow precise-exact', () => {
302
+ // This replicates the logic from the arrows-precise-exact example
303
+ const baseUtil = editor.getShapeUtil<ArrowShapeUtil>('arrow')
304
+ class ExampleArrowShapeUtil extends ArrowShapeUtil {
305
+ override options = {
306
+ ...baseUtil.options,
307
+ shouldBeExact: (_editor: any, isPrecise: boolean) => isPrecise,
308
+ }
309
+ }
310
+
311
+ // Replace the util temporarily for testing
312
+ const customUtil = new ExampleArrowShapeUtil(editor)
313
+ const originalShouldBeExact = baseUtil.options.shouldBeExact
314
+ baseUtil.options.shouldBeExact = customUtil.options.shouldBeExact
315
+
316
+ try {
317
+ editor.setCurrentTool('arrow')
318
+ editor.inputs.ctrlKey = false // Allow binding
319
+
320
+ // Set up fast pointer velocity to ensure precise remains false
321
+ editor.inputs.pointerVelocity = { x: 2, y: 2, len: () => 2.8 } as any
322
+
323
+ const targetState = updateArrowTargetState({
324
+ editor,
325
+ pointInPageSpace: { x: 150, y: 150 },
326
+ arrow: undefined,
327
+ isPrecise: true, // Input precise
328
+ currentBinding: undefined,
329
+ oppositeBinding: undefined,
330
+ })
331
+
332
+ // With the custom logic, precise arrows should be exact
333
+ expect(targetState?.isExact).toBe(true)
334
+ expect(targetState?.isPrecise).toBe(true)
335
+
336
+ // Test with non-precise movement (and fast velocity to avoid auto-precise)
337
+ const nonPreciseTargetState = updateArrowTargetState({
338
+ editor,
339
+ pointInPageSpace: { x: 150, y: 150 },
340
+ arrow: undefined,
341
+ isPrecise: false, // Not precise
342
+ currentBinding: undefined,
343
+ oppositeBinding: undefined,
344
+ })
345
+
346
+ // Non-precise arrows should not be exact with this custom logic,
347
+ // but they might still become precise due to internal logic
348
+ // The key test is that shouldBeExact gets the final computed precise value
349
+ expect(nonPreciseTargetState).toBeDefined()
350
+ } finally {
351
+ // Restore original function
352
+ baseUtil.options.shouldBeExact = originalShouldBeExact
353
+ }
354
+ })
355
+
286
356
  it('should respect shouldIgnoreTargets when starting arrow creation', () => {
287
357
  editor.setCurrentTool('arrow')
288
358
 
@@ -569,12 +569,12 @@ describe('reparenting issue', () => {
569
569
  const arrow1BoundIndex = editor.getShape(arrow1Id)!.index
570
570
  const arrow2BoundIndex = editor.getShape(arrow2Id)!.index
571
571
  expect(arrow1BoundIndex).toBe('a1V')
572
- expect(arrow2BoundIndex).toBe('a1F')
572
+ expect(arrow2BoundIndex).toBe('a1G')
573
573
 
574
574
  // nudge everything around and make sure we all stay in the right order
575
575
  editor.selectAll().nudgeShapes(editor.getSelectedShapeIds(), { x: -1, y: 0 })
576
576
  expect(editor.getShape(arrow1Id)!.index).toBe('a1V')
577
- expect(editor.getShape(arrow2Id)!.index).toBe('a1F')
577
+ expect(editor.getShape(arrow2Id)!.index).toBe('a1G')
578
578
  })
579
579
  })
580
580
 
@@ -579,3 +579,44 @@ describe("an arrow's parents", () => {
579
579
  })
580
580
  })
581
581
  })
582
+
583
+ describe('Arrow export bounds', () => {
584
+ it('excludes labels from shape bounds for export', () => {
585
+ editor.selectAll().deleteShapes(editor.getSelectedShapeIds())
586
+
587
+ // Create shapes for the arrow to bind to
588
+ editor.createShapes([
589
+ { id: ids.box1, type: 'geo', x: 100, y: 100, props: { w: 100, h: 100 } },
590
+ { id: ids.box2, type: 'geo', x: 300, y: 100, props: { w: 100, h: 100 } },
591
+ ])
592
+
593
+ // Create an arrow with a label
594
+ editor.createShapes([
595
+ {
596
+ id: ids.arrow1,
597
+ type: 'arrow',
598
+ x: 0,
599
+ y: 0,
600
+ props: {
601
+ start: { x: 0, y: 0 },
602
+ end: { x: 0, y: 100 },
603
+ richText: toRichText('Test Label'),
604
+ },
605
+ },
606
+ ])
607
+
608
+ // Get the page bounds (should exclude labels due to excludeFromShapeBounds flag)
609
+ const pageBounds = editor.getShapePageBounds(ids.arrow1)
610
+ expect(pageBounds).toBeDefined()
611
+
612
+ // The bounds should be smaller than if labels were included
613
+ // Since the arrow has a label that's excluded, the bounds should be minimal
614
+ expect(pageBounds!.width).toBeLessThan(200) // Should not include label width
615
+ expect(pageBounds!.height).toBeLessThan(200) // Should not include label height
616
+
617
+ // Verify that the arrow has a label (which should be excluded from shape bounds)
618
+ const arrow = editor.getShape(ids.arrow1) as TLArrowShape
619
+ expect(arrow.props.richText).toBeDefined()
620
+ expect(arrow.props.richText).not.toBeNull()
621
+ })
622
+ })
@@ -81,7 +81,7 @@ export interface ArrowShapeOptions {
81
81
  */
82
82
  readonly hoverPreciseTimeout: number
83
83
  /**
84
- * When pointing at a shape using the arrow tool or draggin an arrow terminal handle, how long
84
+ * When pointing at a shape using the arrow tool or dragging an arrow terminal handle, how long
85
85
  * should we wait before we assume the user is targeting precisely instead of imprecisely.
86
86
  */
87
87
  readonly pointingPreciseTimeout: number
@@ -90,13 +90,11 @@ export interface ArrowShapeOptions {
90
90
  * When creating an arrow, should it stop exactly at the pointer, or should
91
91
  * it stop at the edge of the target shape.
92
92
  */
93
- // eslint-disable-next-line @typescript-eslint/method-signature-style
94
- readonly shouldBeExact: (editor: Editor) => boolean
93
+ shouldBeExact(editor: Editor, isPrecise: boolean): boolean
95
94
  /**
96
95
  * When creating an arrow, should it bind to the target shape.
97
96
  */
98
- // eslint-disable-next-line @typescript-eslint/method-signature-style
99
- readonly shouldIgnoreTargets: (editor: Editor) => boolean
97
+ shouldIgnoreTargets(editor: Editor): boolean
100
98
  }
101
99
 
102
100
  /** @public */
@@ -227,6 +227,14 @@ interface ArrowheadInfo {
227
227
  hasEndArrowhead: boolean
228
228
  }
229
229
  export function getArrowLabelPosition(editor: Editor, shape: TLArrowShape) {
230
+ const isEditing = editor.getEditingShapeId() === shape.id
231
+ if (!isEditing && isEmptyRichText(shape.props.richText)) {
232
+ // Short-circuit for empty labels.
233
+ const bodyGeom = getArrowBodyGeometry(editor, shape)
234
+ const labelCenter = bodyGeom.interpolateAlongEdge(0.5)
235
+ return { box: Box.FromCenter(labelCenter, new Vec(0, 0)), debugGeom: [] }
236
+ }
237
+
230
238
  const debugGeom: Geometry2d[] = []
231
239
  const info = getArrowInfo(editor, shape)!
232
240
 
@@ -87,8 +87,6 @@ export function updateArrowTargetState({
87
87
  return null
88
88
  }
89
89
 
90
- const isExact = util.options.shouldBeExact(editor)
91
-
92
90
  const arrowKind = arrow ? arrow.props.kind : editor.getStyleForNextShape(ArrowShapeKindStyle)
93
91
 
94
92
  const target = editor.getShapeAtPoint(pointInPageSpace, {
@@ -165,7 +163,7 @@ export function updateArrowTargetState({
165
163
  }
166
164
  }
167
165
 
168
- let precise = isPrecise || isExact
166
+ let precise = isPrecise
169
167
 
170
168
  if (!precise) {
171
169
  // If we're switching to a new bound shape, then precise only if moving slowly
@@ -186,6 +184,9 @@ export function updateArrowTargetState({
186
184
  }
187
185
  }
188
186
 
187
+ const isExact = util.options.shouldBeExact(editor, precise)
188
+ if (isExact) precise = true
189
+
189
190
  const shouldSnapCenter = !isExact && precise && targetGeometryInTargetSpace.isClosed
190
191
  // const shouldSnapEdges = !isExact && (precise || !targetGeometryInTargetSpace.isClosed)
191
192
  const shouldSnapEdges =
@@ -13,7 +13,6 @@ import {
13
13
  debounce,
14
14
  getHashForString,
15
15
  lerp,
16
- stopEventPropagation,
17
16
  tlenv,
18
17
  toDomPrecision,
19
18
  useEditor,
@@ -132,9 +131,9 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
132
131
  const [isFaviconValid, setIsFaviconValid] = useState(true)
133
132
  const onFaviconError = () => setIsFaviconValid(false)
134
133
 
135
- const useStopPropagationOnShiftKey = useCallback<PointerEventHandler>(
134
+ const markAsHandledOnShiftKey = useCallback<PointerEventHandler>(
136
135
  (e) => {
137
- if (!editor.inputs.shiftKey) stopEventPropagation(e)
136
+ if (!editor.inputs.shiftKey) editor.markEventAsHandled(e)
138
137
  },
139
138
  [editor]
140
139
  )
@@ -182,8 +181,8 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
182
181
  target="_blank"
183
182
  rel="noopener noreferrer"
184
183
  draggable={false}
185
- onPointerDown={useStopPropagationOnShiftKey}
186
- onPointerUp={useStopPropagationOnShiftKey}
184
+ onPointerDown={markAsHandledOnShiftKey}
185
+ onPointerUp={markAsHandledOnShiftKey}
187
186
  >
188
187
  {isFaviconValid && asset?.props.favicon ? (
189
188
  <img
@@ -196,6 +196,7 @@ export class FrameShapeUtil extends BaseBoxShapeUtil<TLFrameShape> {
196
196
  height,
197
197
  isFilled: true,
198
198
  isLabel: true,
199
+ excludeFromShapeBounds: true,
199
200
  }),
200
201
  ],
201
202
  })
@@ -1,4 +1,4 @@
1
- import { TLFrameShape, TLShapeId, stopEventPropagation, useEditor } from '@tldraw/editor'
1
+ import { TLFrameShape, TLShapeId, useEditor } from '@tldraw/editor'
2
2
  import { forwardRef, useCallback } from 'react'
3
3
  import { defaultEmptyAs } from '../FrameShapeUtil'
4
4
 
@@ -8,12 +8,19 @@ export const FrameLabelInput = forwardRef<
8
8
  >(({ id, name, isEditing }, ref) => {
9
9
  const editor = useEditor()
10
10
 
11
+ const handlePointerDown = useCallback(
12
+ (e: React.PointerEvent) => {
13
+ if (isEditing) editor.markEventAsHandled(e)
14
+ },
15
+ [editor, isEditing]
16
+ )
17
+
11
18
  const handleKeyDown = useCallback(
12
19
  (e: React.KeyboardEvent<HTMLInputElement>) => {
13
20
  if (e.key === 'Enter' && !e.nativeEvent.isComposing) {
14
21
  // need to prevent the enter keydown making it's way up to the Idle state
15
22
  // and sending us back into edit mode
16
- stopEventPropagation(e)
23
+ editor.markEventAsHandled(e)
17
24
  e.currentTarget.blur()
18
25
  editor.setEditingShape(null)
19
26
  }
@@ -74,7 +81,7 @@ export const FrameLabelInput = forwardRef<
74
81
  onKeyDown={handleKeyDown}
75
82
  onBlur={handleBlur}
76
83
  onChange={handleChange}
77
- onPointerDown={isEditing ? stopEventPropagation : undefined}
84
+ onPointerDown={handlePointerDown}
78
85
  draggable={false}
79
86
  />
80
87
  {defaultEmptyAs(name, 'Frame') + String.fromCharCode(8203)}
@@ -126,6 +126,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil<TLGeoShape> {
126
126
  height: unscaledLabelHeight * shape.props.scale,
127
127
  isFilled: true,
128
128
  isLabel: true,
129
+ excludeFromShapeBounds: true,
129
130
  isEmptyLabel: isEmptyRichText(shape.props.richText),
130
131
  }),
131
132
  ],
@@ -147,6 +147,7 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
147
147
  height: lh,
148
148
  isFilled: true,
149
149
  isLabel: true,
150
+ excludeFromShapeBounds: true,
150
151
  }),
151
152
  ],
152
153
  })
@@ -1,4 +1,4 @@
1
- import { stopEventPropagation, useEditor, useValue } from '@tldraw/editor'
1
+ import { useEditor, useValue } from '@tldraw/editor'
2
2
  import classNames from 'classnames'
3
3
  import { PointerEventHandler, useCallback } from 'react'
4
4
 
@@ -8,9 +8,9 @@ const LINK_ICON =
8
8
  export function HyperlinkButton({ url }: { url: string }) {
9
9
  const editor = useEditor()
10
10
  const hideButton = useValue('zoomLevel', () => editor.getZoomLevel() < 0.32, [editor])
11
- const useStopPropagationOnShiftKey = useCallback<PointerEventHandler>(
11
+ const markAsHandledOnShiftKey = useCallback<PointerEventHandler>(
12
12
  (e) => {
13
- if (!editor.inputs.shiftKey) stopEventPropagation(e)
13
+ if (!editor.inputs.shiftKey) editor.markEventAsHandled(e)
14
14
  },
15
15
  [editor]
16
16
  )
@@ -22,8 +22,8 @@ export function HyperlinkButton({ url }: { url: string }) {
22
22
  href={url}
23
23
  target="_blank"
24
24
  rel="noopener noreferrer"
25
- onPointerDown={useStopPropagationOnShiftKey}
26
- onPointerUp={useStopPropagationOnShiftKey}
25
+ onPointerDown={markAsHandledOnShiftKey}
26
+ onPointerUp={markAsHandledOnShiftKey}
27
27
  title={url}
28
28
  draggable={false}
29
29
  >
@@ -5,7 +5,6 @@ import {
5
5
  getPointerInfo,
6
6
  noop,
7
7
  preventDefault,
8
- stopEventPropagation,
9
8
  tlenv,
10
9
  useEditor,
11
10
  useValue,
@@ -129,14 +128,14 @@ export function useEditableTextCommon(shapeId: TLShapeId) {
129
128
  // partially if we didn't dispatch/stop below.
130
129
 
131
130
  editor.dispatch({
132
- ...getPointerInfo(e),
131
+ ...getPointerInfo(editor, e),
133
132
  type: 'pointer',
134
133
  name: 'pointer_down',
135
134
  target: 'shape',
136
135
  shape: editor.getShape(shapeId)!,
137
136
  })
138
137
 
139
- stopEventPropagation(e) // we need to prevent blurring the input
138
+ e.stopPropagation() // we need to prevent blurring the input
140
139
  },
141
140
  [editor, shapeId]
142
141
  )
@@ -161,7 +160,7 @@ export function useEditableTextCommon(shapeId: TLShapeId) {
161
160
  handleFocus: noop,
162
161
  handleBlur: noop,
163
162
  handleInputPointerDown,
164
- handleDoubleClick: stopEventPropagation,
163
+ handleDoubleClick: editor.markEventAsHandled,
165
164
  handlePaste,
166
165
  isEditing,
167
166
  isReadyForEditing,
@@ -1,4 +1,4 @@
1
- import { preventDefault, stopEventPropagation } from '@tldraw/editor'
1
+ import { preventDefault, useEditor } from '@tldraw/editor'
2
2
  import React from 'react'
3
3
  import { TextAreaProps } from './RichTextArea'
4
4
 
@@ -21,6 +21,7 @@ export const PlainTextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps
21
21
  },
22
22
  ref
23
23
  ) {
24
+ const editor = useEditor()
24
25
  const onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
25
26
  handleChange({ plaintext: e.target.value })
26
27
  }
@@ -46,8 +47,8 @@ export const PlainTextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps
46
47
  onChange={onChange}
47
48
  onKeyDown={(e) => handleKeyDown(e.nativeEvent)}
48
49
  onBlur={handleBlur}
49
- onTouchEnd={stopEventPropagation}
50
- onContextMenu={isEditing ? stopEventPropagation : undefined}
50
+ onTouchEnd={editor.markEventAsHandled}
51
+ onContextMenu={isEditing ? (e) => e.stopPropagation() : undefined}
51
52
  onPointerDown={handleInputPointerDown}
52
53
  onPaste={handlePaste}
53
54
  onDoubleClick={handleDoubleClick}
@@ -10,7 +10,6 @@ import {
10
10
  TLRichText,
11
11
  TLShapeId,
12
12
  preventDefault,
13
- stopEventPropagation,
14
13
  useEditor,
15
14
  useEvent,
16
15
  useUniqueSafeId,
@@ -233,13 +232,13 @@ export const RichTextArea = React.forwardRef<HTMLDivElement, TextAreaProps>(func
233
232
  tabIndex={-1}
234
233
  data-testid="rich-text-area"
235
234
  className="tl-rich-text tl-text tl-text-input"
236
- onContextMenu={isEditing ? stopEventPropagation : undefined}
235
+ onContextMenu={isEditing ? (e) => e.stopPropagation() : undefined}
237
236
  // N.B. When PointerStateExtension was introduced, this was moved there.
238
237
  // However, that caused selecting over list items to break.
239
238
  // The handleDOMEvents in TipTap don't seem to support the pointerDownCapture event.
240
- onPointerDownCapture={stopEventPropagation}
239
+ onPointerDownCapture={(e) => e.stopPropagation()}
241
240
  // This onTouchEnd is important for Android to be able to change selection on text.
242
- onTouchEnd={stopEventPropagation}
241
+ onTouchEnd={(e) => e.stopPropagation()}
243
242
  // On FF, there's a behavior where dragging a selection will grab that selection into
244
243
  // the drag event. However, once the drag is over, and you select away from the textarea,
245
244
  // starting a drag over the textarea will restart a selection drag instead of a shape drag.
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  debugFlags,
3
3
  Editor,
4
- stopEventPropagation,
5
4
  TLGeoShape,
6
5
  TLShapeId,
7
6
  unsafe__withoutCapture,
@@ -23,7 +22,7 @@ export function SkipToMainContent() {
23
22
 
24
23
  const handleNavigateToFirstShape = useCallback(
25
24
  (e: MouseEvent | KeyboardEvent) => {
26
- stopEventPropagation(e)
25
+ editor.markEventAsHandled(e)
27
26
  button.current?.blur()
28
27
  const shapes = editor.getCurrentPageShapesInReadingOrder()
29
28
  if (!shapes.length) return
@@ -18,6 +18,7 @@ export function LanguageMenu() {
18
18
  {LANGUAGES.map(({ locale, label }) => (
19
19
  <TldrawUiMenuCheckboxItem
20
20
  id={`language-${locale}`}
21
+ lang={locale}
21
22
  key={locale}
22
23
  title={locale}
23
24
  label={label}
@@ -159,7 +159,7 @@ export function DefaultMinimap() {
159
159
  type: 'pointer',
160
160
  target: 'canvas',
161
161
  name: 'pointer_move',
162
- ...getPointerInfo(e),
162
+ ...getPointerInfo(editor, e),
163
163
  point: screenPoint,
164
164
  isPen: editor.getInstanceState().isPenMode,
165
165
  }
@@ -204,6 +204,7 @@ export function DefaultMinimap() {
204
204
  <canvas
205
205
  role="img"
206
206
  aria-label={msg('navigation-zone.minimap')}
207
+ data-testid="minimap.canvas"
207
208
  ref={rCanvas}
208
209
  className="tlui-minimap__canvas"
209
210
  onDoubleClick={onDoubleClick}
@@ -3,7 +3,6 @@ import {
3
3
  TLPageId,
4
4
  releasePointerCapture,
5
5
  setPointerCapture,
6
- stopEventPropagation,
7
6
  tlenv,
8
7
  useEditor,
9
8
  useValue,
@@ -451,7 +450,7 @@ export const DefaultPageMenu = memo(function DefaultPageMenu() {
451
450
  if (e.key === 'Enter') {
452
451
  if (page.id === currentPage.id) {
453
452
  toggleEditing()
454
- stopEventPropagation(e)
453
+ editor.markEventAsHandled(e)
455
454
  }
456
455
  }
457
456
  }}
@@ -137,6 +137,7 @@ export const StylePanelButtonPicker = memo(function StylePanelButtonPicker<T ext
137
137
  >
138
138
  <Layout>
139
139
  {items.map((item) => {
140
+ const isActive = value.type === 'shared' && value.value === item.value
140
141
  const label =
141
142
  title + ' — ' + msg(`${uiType}-style.${item.value}` as TLUiTranslationKey)
142
143
  return (
@@ -145,10 +146,16 @@ export const StylePanelButtonPicker = memo(function StylePanelButtonPicker<T ext
145
146
  key={item.value}
146
147
  data-id={item.value}
147
148
  data-testid={`style.${uiType}.${item.value}`}
148
- aria-label={label}
149
+ aria-label={label + (isActive ? ` (${msg('style-panel.selected')})` : '')}
150
+ tooltip={
151
+ <>
152
+ <div>{label}</div>
153
+ {isActive ? <div>({msg('style-panel.selected')})</div> : null}
154
+ </>
155
+ }
149
156
  value={item.value}
150
157
  data-state={value.type === 'shared' && value.value === item.value ? 'on' : 'off'}
151
- data-isactive={value.type === 'shared' && value.value === item.value}
158
+ data-isactive={isActive}
152
159
  title={label}
153
160
  style={
154
161
  style === (DefaultColorStyle as StyleProp<unknown>)
@@ -2,9 +2,9 @@ import { preventDefault, TLShape, TLShapeId, useEditor } from '@tldraw/editor'
2
2
  import { useCallback, useEffect, useRef, useState } from 'react'
3
3
  import { useUiEvents } from '../../context/events'
4
4
  import { useTranslation } from '../../hooks/useTranslation/useTranslation'
5
+ import { TldrawUiButton } from '../primitives/Button/TldrawUiButton'
5
6
  import { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'
6
7
  import { TldrawUiInput } from '../primitives/TldrawUiInput'
7
- import { TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'
8
8
 
9
9
  /** @public */
10
10
  export interface AltTextEditorProps {
@@ -70,13 +70,14 @@ export function AltTextEditor({ shapeId, onClose, source }: AltTextEditorProps)
70
70
  data-testid="media-toolbar.alt-text-input"
71
71
  value={altText}
72
72
  placeholder={msg('tool.media-alt-text-desc')}
73
+ aria-label={msg('tool.media-alt-text-desc')}
73
74
  onValueChange={handleValueChange}
74
75
  onComplete={handleComplete}
75
76
  onCancel={handleAltTextCancel}
76
77
  disabled={isReadonly}
77
78
  />
78
79
  {!isReadonly && (
79
- <TldrawUiToolbarButton
80
+ <TldrawUiButton
80
81
  title={msg('tool.media-alt-text-confirm')}
81
82
  data-testid="tool.media-alt-text-confirm"
82
83
  type="icon"
@@ -84,7 +85,7 @@ export function AltTextEditor({ shapeId, onClose, source }: AltTextEditorProps)
84
85
  onClick={handleConfirm}
85
86
  >
86
87
  <TldrawUiButtonIcon small icon="check" />
87
- </TldrawUiToolbarButton>
88
+ </TldrawUiButton>
88
89
  )}
89
90
  </>
90
91
  )