@tldraw/editor 5.2.0-next.a6104dd18d03 → 5.2.0-next.b0c9cf86de67

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 (89) hide show
  1. package/README.md +6 -0
  2. package/dist-cjs/index.d.ts +42 -4
  3. package/dist-cjs/index.js +2 -1
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/components/MenuClickCapture.js +8 -5
  6. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  7. package/dist-cjs/lib/editor/Editor.js +74 -41
  8. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +2 -2
  10. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +24 -2
  12. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  13. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +14 -3
  14. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
  15. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -2
  16. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +7 -3
  18. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +0 -1
  20. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +15 -2
  22. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  23. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +3 -0
  24. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
  25. package/dist-cjs/lib/hooks/useCanvasEvents.js +14 -7
  26. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  27. package/dist-cjs/lib/hooks/usePresence.js.map +2 -2
  28. package/dist-cjs/lib/utils/getPointerInfo.js +2 -1
  29. package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
  30. package/dist-cjs/lib/utils/pointer.js +32 -0
  31. package/dist-cjs/lib/utils/pointer.js.map +7 -0
  32. package/dist-cjs/version.js +3 -3
  33. package/dist-cjs/version.js.map +1 -1
  34. package/dist-esm/index.d.mts +42 -4
  35. package/dist-esm/index.mjs +4 -2
  36. package/dist-esm/index.mjs.map +2 -2
  37. package/dist-esm/lib/components/MenuClickCapture.mjs +8 -5
  38. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  39. package/dist-esm/lib/editor/Editor.mjs +74 -41
  40. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  41. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +2 -2
  42. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
  43. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +24 -2
  44. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  45. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +14 -3
  46. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
  47. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -2
  48. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  49. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +7 -3
  50. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  51. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +0 -1
  52. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
  53. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +15 -2
  54. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  55. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +3 -0
  56. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
  57. package/dist-esm/lib/hooks/useCanvasEvents.mjs +14 -7
  58. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  59. package/dist-esm/lib/hooks/usePresence.mjs.map +2 -2
  60. package/dist-esm/lib/utils/getPointerInfo.mjs +2 -1
  61. package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
  62. package/dist-esm/lib/utils/pointer.mjs +12 -0
  63. package/dist-esm/lib/utils/pointer.mjs.map +7 -0
  64. package/dist-esm/version.mjs +3 -3
  65. package/dist-esm/version.mjs.map +1 -1
  66. package/editor.css +3 -3
  67. package/package.json +7 -7
  68. package/src/index.ts +1 -0
  69. package/src/lib/components/MenuClickCapture.tsx +8 -4
  70. package/src/lib/editor/Editor.ts +91 -50
  71. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +31 -18
  72. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +2 -2
  73. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +32 -0
  74. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +34 -4
  75. package/src/lib/editor/managers/InputsManager/InputsManager.test.ts +61 -0
  76. package/src/lib/editor/managers/InputsManager/InputsManager.ts +16 -4
  77. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +9 -2
  78. package/src/lib/editor/managers/TextManager/TextManager.ts +17 -2
  79. package/src/lib/editor/managers/TickManager/TickManager.test.ts +0 -40
  80. package/src/lib/editor/managers/TickManager/TickManager.ts +0 -1
  81. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +12 -2
  82. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +27 -2
  83. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -0
  84. package/src/lib/hooks/useCanvasEvents.ts +19 -12
  85. package/src/lib/hooks/usePresence.ts +2 -2
  86. package/src/lib/utils/getPointerInfo.ts +2 -1
  87. package/src/lib/utils/pointer.test.ts +48 -0
  88. package/src/lib/utils/pointer.ts +18 -0
  89. package/src/version.ts +3 -3
@@ -1,6 +1,7 @@
1
1
  import { atom, computed, unsafe__withoutCapture } from '@tldraw/state'
2
2
  import { AtomSet } from '@tldraw/store'
3
3
  import { TLINSTANCE_ID, TLPOINTER_ID } from '@tldraw/tlschema'
4
+ import { bind } from '@tldraw/utils'
4
5
  import { INTERNAL_POINTER_IDS } from '../../../constants'
5
6
  import { Vec } from '../../../primitives/Vec'
6
7
  import { isAccelKey } from '../../../utils/keyboard'
@@ -12,7 +13,19 @@ const POINTER_VELOCITY_REFERENCE_SMOOTHING = 0.5
12
13
 
13
14
  /** @public */
14
15
  export class InputsManager {
15
- constructor(private readonly editor: Editor) {}
16
+ constructor(private readonly editor: Editor) {
17
+ this.editor.on('frame', this._onFrame)
18
+ }
19
+
20
+ /** @internal */
21
+ dispose() {
22
+ this.editor.off('frame', this._onFrame)
23
+ }
24
+
25
+ @bind
26
+ private _onFrame(elapsed: number) {
27
+ this.updatePointerVelocity(elapsed)
28
+ }
16
29
 
17
30
  private _originPagePoint = atom<Vec>('originPagePoint', new Vec())
18
31
  /**
@@ -120,8 +133,7 @@ export class InputsManager {
120
133
  }
121
134
 
122
135
  /**
123
- * Normally you shouldn't need to set the pointer velocity directly, this is set by the tick manager.
124
- * However, this is currently used in tests to fake pointer velocity.
136
+ * Normally you shouldn't need to set the pointer velocity directly. Used in tests to fake pointer velocity.
125
137
  * @param pointerVelocity - The pointer velocity.
126
138
  * @internal
127
139
  */
@@ -460,7 +472,7 @@ export class InputsManager {
460
472
  private _velocityPrevPoint = new Vec()
461
473
 
462
474
  /**
463
- * Update the pointer velocity based on elapsed time. Called by the tick manager.
475
+ * Update the pointer velocity based on elapsed time. Called each frame.
464
476
  * @param elapsed - The time elapsed since the last tick in milliseconds.
465
477
  * @internal
466
478
  */
@@ -46,6 +46,10 @@ export class SpatialIndexManager {
46
46
 
47
47
  private createSpatialIndexComputed() {
48
48
  const shapeHistory = this.editor.store.query.filterHistory('shape')
49
+ // Binding changes can move a shape's derived bounds (e.g. creating or
50
+ // deleting an arrow binding relocates the arrow's body) without
51
+ // touching any shape record, so they must also invalidate the index.
52
+ const bindingHistory = this.editor.store.query.filterHistory('binding')
49
53
 
50
54
  return computed<number>('spatialIndex', (_prevValue, lastComputedEpoch) => {
51
55
  if (isUninitialized(_prevValue)) {
@@ -53,8 +57,9 @@ export class SpatialIndexManager {
53
57
  }
54
58
 
55
59
  const shapeDiff = shapeHistory.getDiffSince(lastComputedEpoch)
60
+ const bindingDiff = bindingHistory.getDiffSince(lastComputedEpoch)
56
61
 
57
- if (shapeDiff === RESET_VALUE) {
62
+ if (shapeDiff === RESET_VALUE || bindingDiff === RESET_VALUE) {
58
63
  return this.rebuildAndBumpEpoch()
59
64
  }
60
65
 
@@ -63,8 +68,10 @@ export class SpatialIndexManager {
63
68
  return this.rebuildAndBumpEpoch()
64
69
  }
65
70
 
66
- if (shapeDiff.length === 0) return this._boundsEpoch
71
+ if (shapeDiff.length === 0 && bindingDiff.length === 0) return this._boundsEpoch
67
72
 
73
+ // A binding-only diff passes an empty shape diff: step 1 is a no-op
74
+ // and the step-2 sweep re-checks the indexed bounds of every shape.
68
75
  if (this.processIncrementalUpdate(shapeDiff)) {
69
76
  this._boundsEpoch++
70
77
  }
@@ -2,6 +2,21 @@ import { BoxModel, TLDefaultHorizontalAlignStyle } from '@tldraw/tlschema'
2
2
  import { objectMapKeys } from '@tldraw/utils'
3
3
  import type { Editor } from '../../Editor'
4
4
 
5
+ /**
6
+ * The whole-pixel line-height for a given font size and tldraw's unitless line-height
7
+ * multiplier. tldraw's theme stores line-height as a multiplier (e.g. 1.35); resolving it
8
+ * to a whole pixel keeps line spacing identical across rendering engines, which otherwise
9
+ * disagree on fractional line boxes (WebKit snaps them to whole pixels, Blink keeps the
10
+ * fraction) and let multi-line text drift apart. Apply it everywhere line-height is used —
11
+ * measurement, on-canvas render, and export — so geometry and rendering agree.
12
+ * See https://github.com/tldraw/tldraw/issues/8970.
13
+ *
14
+ * @public
15
+ */
16
+ export function resolveLineHeightPx(fontSize: number, lineHeight: number): number {
17
+ return Math.round(fontSize * lineHeight)
18
+ }
19
+
5
20
  const fixNewLines = /\r?\n|\r/g
6
21
 
7
22
  function normalizeTextForDom(text: string) {
@@ -154,7 +169,7 @@ export class TextManager {
154
169
  'font-style': opts.fontStyle,
155
170
  'font-weight': opts.fontWeight,
156
171
  'font-size': opts.fontSize + 'px',
157
- 'line-height': opts.lineHeight.toString(),
172
+ 'line-height': `${resolveLineHeightPx(opts.fontSize, opts.lineHeight)}px`,
158
173
  padding: opts.padding,
159
174
  'max-width': opts.maxWidth ? opts.maxWidth + 'px' : undefined,
160
175
  'min-width': opts.minWidth ? opts.minWidth + 'px' : undefined,
@@ -382,7 +397,7 @@ export class TextManager {
382
397
  'font-style': opts.fontStyle,
383
398
  'font-weight': opts.fontWeight,
384
399
  'font-size': opts.fontSize + 'px',
385
- 'line-height': opts.lineHeight.toString(),
400
+ 'line-height': `${resolveLineHeightPx(opts.fontSize, opts.lineHeight)}px`,
386
401
  width: `${elementWidth}px`,
387
402
  height: 'min-content',
388
403
  'text-align': textAlignmentsForLtr[opts.textAlign],
@@ -1,5 +1,4 @@
1
1
  import { Mock, Mocked, vi } from 'vitest'
2
- import { Vec } from '../../../primitives/Vec'
3
2
  import { Editor } from '../../Editor'
4
3
  import { TickManager } from './TickManager'
5
4
 
@@ -21,17 +20,6 @@ describe('TickManager', () => {
21
20
  let tickManager: TickManager
22
21
  let mockEmit: Mock
23
22
  let mockDisposablesAdd: Mock
24
- let mockInputs: {
25
- _currentScreenPoint: Vec
26
- getCurrentScreenPoint(): Vec
27
- currentScreenPoint: Vec
28
- setCurrentScreenPoint(value: Vec): void
29
- _pointerVelocity: Vec
30
- getPointerVelocity(): Vec
31
- pointerVelocity: Vec
32
- setPointerVelocity(value: Vec): void
33
- updatePointerVelocity(elapsed: number): void
34
- }
35
23
 
36
24
  beforeEach(() => {
37
25
  vi.clearAllMocks()
@@ -52,39 +40,11 @@ describe('TickManager', () => {
52
40
  mockEmit = vi.fn()
53
41
  mockDisposablesAdd = vi.fn()
54
42
 
55
- // Create a mock inputs object with getters and setters
56
- mockInputs = {
57
- _currentScreenPoint: new Vec(100, 100),
58
- getCurrentScreenPoint() {
59
- return this._currentScreenPoint
60
- },
61
- get currentScreenPoint() {
62
- return this.getCurrentScreenPoint()
63
- },
64
- setCurrentScreenPoint(value: Vec) {
65
- this._currentScreenPoint = value
66
- },
67
- _pointerVelocity: new Vec(0, 0),
68
- getPointerVelocity() {
69
- return this._pointerVelocity
70
- },
71
- get pointerVelocity() {
72
- return this.getPointerVelocity()
73
- },
74
- setPointerVelocity(value: Vec) {
75
- this._pointerVelocity = value
76
- },
77
- updatePointerVelocity(_elapsed: number) {
78
- // Mock implementation - no-op for tests
79
- },
80
- }
81
-
82
43
  editor = {
83
44
  emit: mockEmit,
84
45
  disposables: {
85
46
  add: mockDisposablesAdd,
86
47
  },
87
- inputs: mockInputs as unknown as Editor['inputs'],
88
48
  } as unknown as Mocked<Editor>
89
49
 
90
50
  tickManager = new TickManager(editor)
@@ -40,7 +40,6 @@ export class TickManager {
40
40
  const elapsed = now - this.now
41
41
  this.now = now
42
42
 
43
- this.editor.inputs.updatePointerVelocity(elapsed)
44
43
  this.editor.emit('frame', elapsed)
45
44
  this.editor.emit('tick', elapsed)
46
45
  this.cancelRaf = throttleToNextFrame(this.tick)
@@ -1,4 +1,5 @@
1
1
  import { atom } from '@tldraw/state'
2
+ import { createUserId } from '@tldraw/tlschema'
2
3
  import { Mocked, vi } from 'vitest'
3
4
  import { TLCurrentUser } from '../../../config/createTLCurrentUser'
4
5
  import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
@@ -296,8 +297,17 @@ describe('UserPreferencesManager', () => {
296
297
  userPreferencesManager = new UserPreferencesManager(mockUser, 'light')
297
298
  })
298
299
 
299
- describe('getId', () => {
300
- it('should return user id', () => {
300
+ describe('getExternalId / getRecordId', () => {
301
+ it('should return the raw external user id', () => {
302
+ expect(userPreferencesManager.getExternalId()).toBe(mockUserPreferences.id)
303
+ })
304
+
305
+ it('should return the prefixed record id', () => {
306
+ expect(userPreferencesManager.getRecordId()).toBe(createUserId(mockUserPreferences.id))
307
+ })
308
+
309
+ it('getId() still returns the external id', () => {
310
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
301
311
  expect(userPreferencesManager.getId()).toBe(mockUserPreferences.id)
302
312
  })
303
313
  })
@@ -1,4 +1,5 @@
1
1
  import { atom, computed } from '@tldraw/state'
2
+ import { createUserId, TLUserId } from '@tldraw/tlschema'
2
3
  import { TLCurrentUser } from '../../../config/createTLCurrentUser'
3
4
  import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
4
5
  import { getGlobalWindow } from '../../../utils/dom'
@@ -39,7 +40,7 @@ export class UserPreferencesManager {
39
40
  }
40
41
  @computed getUserPreferences() {
41
42
  return {
42
- id: this.getId(),
43
+ id: this.getExternalId(),
43
44
  name: this.getName(),
44
45
  locale: this.getLocale(),
45
46
  color: this.getColor(),
@@ -89,10 +90,34 @@ export class UserPreferencesManager {
89
90
  )
90
91
  }
91
92
 
92
- @computed getId() {
93
+ /**
94
+ * The current user's raw, app-provided id — the value set in the user's
95
+ * {@link @tldraw/editor#TLUserPreferences}. Use this when you need the id your application
96
+ * assigned to the user. To compare against or look up store records, use
97
+ * {@link UserPreferencesManager.getRecordId} instead.
98
+ */
99
+ @computed getExternalId(): string {
93
100
  return this.user.userPreferences.get().id
94
101
  }
95
102
 
103
+ /**
104
+ * @deprecated Use {@link UserPreferencesManager.getExternalId} for the raw app-provided id, or
105
+ * {@link UserPreferencesManager.getRecordId} for the prefixed `TLUserId` record id.
106
+ */
107
+ @computed getId() {
108
+ return this.getExternalId()
109
+ }
110
+
111
+ /**
112
+ * The current user's id as a tldraw {@link @tldraw/tlschema#TLUserId} record id (prefixed
113
+ * with `user:`). Use this when comparing against or looking up store records, such as a
114
+ * presence record's `userId` or `followingUserId`. For the raw, app-provided id, use
115
+ * {@link UserPreferencesManager.getExternalId}.
116
+ */
117
+ @computed getRecordId(): TLUserId {
118
+ return createUserId(this.getExternalId())
119
+ }
120
+
96
121
  @computed getName() {
97
122
  return this.user.userPreferences.get().name?.trim() ?? defaultUserPreferences.name
98
123
  }
@@ -77,6 +77,10 @@ export class Pointing extends StateNode {
77
77
  this.cancel()
78
78
  }
79
79
 
80
+ override onLongPress() {
81
+ if (this.editor.getInstanceState().isCoarsePointer) this.cancel()
82
+ }
83
+
80
84
  complete() {
81
85
  const originPagePoint = this.editor.inputs.getOriginPagePoint()
82
86
 
@@ -8,6 +8,7 @@ import {
8
8
  setPointerCapture,
9
9
  } from '../utils/dom'
10
10
  import { getPointerInfo } from '../utils/getPointerInfo'
11
+ import { getPointerEventButton, isSecondaryClickEvent } from '../utils/pointer'
11
12
  import { useEditor } from './useEditor'
12
13
 
13
14
  export function useCanvasEvents() {
@@ -17,12 +18,16 @@ export function useCanvasEvents() {
17
18
 
18
19
  const events = useMemo(
19
20
  function canvasEvents() {
21
+ let isSecondaryClickPointerDown = false
22
+
20
23
  function onPointerDown(e: React.PointerEvent) {
21
24
  if (editor.wasEventAlreadyHandled(e)) return
25
+ const button = getPointerEventButton(e)
26
+ isSecondaryClickPointerDown = button === 2
22
27
 
23
28
  // With right-click panning disabled, fire right_click on press and let the
24
29
  // native contextmenu through so the menu opens at the pointer-down location.
25
- if (e.button === 2 && !editor.options.rightClickPanning) {
30
+ if (button === 2 && !editor.options.rightClickPanning) {
26
31
  editor.dispatch({
27
32
  type: 'pointer',
28
33
  target: 'canvas',
@@ -32,7 +37,7 @@ export function useCanvasEvents() {
32
37
  return
33
38
  }
34
39
 
35
- if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
40
+ if (button !== 0 && button !== 1 && button !== 2 && button !== 5) return
36
41
 
37
42
  setPointerCapture(e.currentTarget, e)
38
43
 
@@ -46,12 +51,13 @@ export function useCanvasEvents() {
46
51
 
47
52
  function onPointerUp(e: React.PointerEvent) {
48
53
  if (editor.wasEventAlreadyHandled(e)) return
49
- if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
54
+ const button = isSecondaryClickPointerDown ? 2 : getPointerEventButton(e)
55
+ if (button !== 0 && button !== 1 && button !== 2 && button !== 5) return
50
56
 
51
57
  const rightClickPanning = editor.options.rightClickPanning
52
58
  // Check before dispatch (which resets isPanning)
53
59
  const wasRightClickPanning =
54
- rightClickPanning && e.button === 2 && editor.inputs.getIsPanning()
60
+ rightClickPanning && button === 2 && editor.inputs.getIsPanning()
55
61
 
56
62
  releasePointerCapture(e.currentTarget, e)
57
63
 
@@ -60,10 +66,11 @@ export function useCanvasEvents() {
60
66
  target: 'canvas',
61
67
  name: 'pointer_up',
62
68
  ...getPointerInfo(editor, e),
69
+ button,
63
70
  })
64
71
 
65
72
  // Static right-click: fire contextmenu at the pointer-up location
66
- if (rightClickPanning && e.button === 2 && !wasRightClickPanning) {
73
+ if (rightClickPanning && button === 2 && !wasRightClickPanning) {
67
74
  const contextMenuEvent = new PointerEvent('contextmenu', {
68
75
  bubbles: true,
69
76
  clientX: e.clientX,
@@ -76,6 +83,7 @@ export function useCanvasEvents() {
76
83
  })
77
84
  e.currentTarget.dispatchEvent(contextMenuEvent)
78
85
  }
86
+ isSecondaryClickPointerDown = false
79
87
  }
80
88
 
81
89
  function onPointerEnter(e: React.PointerEvent) {
@@ -171,16 +179,15 @@ export function useCanvasEvents() {
171
179
  // Synthetic events — our own dispatch from onPointerUp, or tests using
172
180
  // fireEvent.contextMenu — pass through so Radix can open the menu.
173
181
  if (!e.nativeEvent.isTrusted) return
174
- // Only suppress the native browser contextmenu when it follows a real
175
- // right-click (button=2 with no ctrl modifier). For those, our pointer
176
- // handling has already decided what to do (either we'll dispatch a
177
- // synthetic contextmenu on pointerup to open the menu at the release
178
- // position, or we panned and don't want a menu at all).
182
+ // Only suppress the native browser contextmenu when it follows a
183
+ // secondary click. For those, our pointer handling has already
184
+ // decided what to do (either we'll dispatch a synthetic contextmenu on
185
+ // pointerup to open the menu at the release position, or we panned and
186
+ // don't want a menu at all).
179
187
  //
180
188
  // Other contextmenu sources must reach Radix so the menu opens:
181
- // - ctrl+click on macOS (button=0, or button=2 with ctrlKey=true)
182
189
  // - long-press on touch devices (button=0, pointerType=touch)
183
- if (e.button !== 2 || e.ctrlKey) return
190
+ if (!isSecondaryClickEvent(e)) return
184
191
  preventDefault(e)
185
192
  }
186
193
 
@@ -1,5 +1,5 @@
1
1
  import { useValue } from '@tldraw/state-react'
2
- import { TLInstancePresence } from '@tldraw/tlschema'
2
+ import { TLInstancePresence, TLUserId } from '@tldraw/tlschema'
3
3
  import { useEditor } from './useEditor'
4
4
 
5
5
  // TODO: maybe move this to a computed property on the App class?
@@ -7,7 +7,7 @@ import { useEditor } from './useEditor'
7
7
  * @returns The latest presence of the user matching userId
8
8
  * @public
9
9
  */
10
- export function usePresence(userId: string): TLInstancePresence | null {
10
+ export function usePresence(userId: TLUserId): TLInstancePresence | null {
11
11
  const editor = useEditor()
12
12
 
13
13
  const latestPresence = useValue(
@@ -1,6 +1,7 @@
1
1
  import type React from 'react'
2
2
  import { Editor } from '../editor/Editor'
3
3
  import { isAccelKey } from './keyboard'
4
+ import { getPointerEventButton } from './pointer'
4
5
 
5
6
  /** @public */
6
7
  export function getPointerInfo(editor: Editor, e: React.PointerEvent | PointerEvent) {
@@ -18,7 +19,7 @@ export function getPointerInfo(editor: Editor, e: React.PointerEvent | PointerEv
18
19
  metaKey: e.metaKey,
19
20
  accelKey: isAccelKey(e),
20
21
  pointerId: e.pointerId,
21
- button: e.button,
22
+ button: getPointerEventButton(e),
22
23
  isPen: e.pointerType === 'pen',
23
24
  }
24
25
  }
@@ -0,0 +1,48 @@
1
+ import { tlenv } from '../globals/environment'
2
+ import { TestEditor } from '../test/TestEditor'
3
+ import { getPointerInfo } from './getPointerInfo'
4
+ import { isSecondaryClickEvent } from './pointer'
5
+
6
+ const originalIsDarwin = tlenv.isDarwin
7
+
8
+ afterEach(() => {
9
+ tlenv.isDarwin = originalIsDarwin
10
+ })
11
+
12
+ describe('isSecondaryClickEvent', () => {
13
+ it('treats ctrl + left-click as a secondary click on macOS', () => {
14
+ tlenv.isDarwin = true
15
+ expect(isSecondaryClickEvent({ button: 0, ctrlKey: true, metaKey: false })).toBe(true)
16
+ })
17
+
18
+ it('does not treat ctrl + left-click as a secondary click off macOS', () => {
19
+ tlenv.isDarwin = false
20
+ expect(isSecondaryClickEvent({ button: 0, ctrlKey: true, metaKey: false })).toBe(false)
21
+ })
22
+ })
23
+
24
+ describe('ctrl + left-click on macOS fires as a right-click (regression)', () => {
25
+ // Regression test for https://github.com/tldraw/tldraw/issues/8217
26
+ // On macOS, a ctrl + left-click should be treated as a right-click
27
+ let editor: TestEditor
28
+
29
+ beforeEach(() => {
30
+ editor = new TestEditor()
31
+ })
32
+
33
+ afterEach(() => {
34
+ editor.dispose()
35
+ })
36
+
37
+ it('reports button 2 in the dispatched pointer info on macOS', () => {
38
+ tlenv.isDarwin = true
39
+ const event = new PointerEvent('pointerdown', { button: 0, ctrlKey: true })
40
+ expect(getPointerInfo(editor, event).button).toBe(2)
41
+ })
42
+
43
+ it('stays button 0 for the same gesture off macOS', () => {
44
+ tlenv.isDarwin = false
45
+ const event = new PointerEvent('pointerdown', { button: 0, ctrlKey: true })
46
+ expect(getPointerInfo(editor, event).button).toBe(0)
47
+ })
48
+ })
@@ -0,0 +1,18 @@
1
+ import { tlenv } from '../globals/environment'
2
+
3
+ /** @internal */
4
+ interface PointerLike {
5
+ button: number
6
+ ctrlKey: boolean
7
+ metaKey: boolean
8
+ }
9
+
10
+ /** @internal */
11
+ export function isSecondaryClickEvent(e: PointerLike) {
12
+ return e.button === 2 || (tlenv.isDarwin && e.button === 0 && e.ctrlKey && !e.metaKey)
13
+ }
14
+
15
+ /** @internal */
16
+ export function getPointerEventButton(e: PointerLike) {
17
+ return isSecondaryClickEvent(e) ? 2 : e.button
18
+ }
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '5.2.0-next.a6104dd18d03'
4
+ export const version = '5.2.0-next.b0c9cf86de67'
5
5
  export const publishDates = {
6
6
  major: '2026-05-06T16:28:18.473Z',
7
- minor: '2026-06-11T16:27:00.231Z',
8
- patch: '2026-06-11T16:27:00.231Z',
7
+ minor: '2026-06-18T14:05:14.199Z',
8
+ patch: '2026-06-18T14:05:14.199Z',
9
9
  }