@tldraw/commenting 5.7.0-next.d597a258777e → 5.7.0-next.f64b0c9050e1

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 (102) hide show
  1. package/commenting.css +277 -275
  2. package/dist-cjs/canvas/canvas-events.js +25 -1
  3. package/dist-cjs/canvas/canvas-events.js.map +2 -2
  4. package/dist-cjs/canvas/comment-tool.js +29 -28
  5. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  6. package/dist-cjs/canvas/comments-filter-menu.js +55 -38
  7. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  8. package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
  9. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  10. package/dist-cjs/canvas/comments-overlay.js +1 -0
  11. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  12. package/dist-cjs/canvas/comments-sidebar.js +15 -3
  13. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  14. package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
  15. package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
  16. package/dist-cjs/canvas/options.js.map +2 -2
  17. package/dist-cjs/canvas/pending-composer.js +133 -8
  18. package/dist-cjs/canvas/pending-composer.js.map +2 -2
  19. package/dist-cjs/canvas/region-box.js +150 -35
  20. package/dist-cjs/canvas/region-box.js.map +3 -3
  21. package/dist-cjs/canvas/thread-pin.js +20 -4
  22. package/dist-cjs/canvas/thread-pin.js.map +2 -2
  23. package/dist-cjs/canvas/thread-view.js +130 -57
  24. package/dist-cjs/canvas/thread-view.js.map +2 -2
  25. package/dist-cjs/index.d.ts +39 -11
  26. package/dist-cjs/index.js +1 -1
  27. package/dist-cjs/ui/byline.js +2 -2
  28. package/dist-cjs/ui/byline.js.map +2 -2
  29. package/dist-cjs/ui/comment-card.js +3 -1
  30. package/dist-cjs/ui/comment-card.js.map +2 -2
  31. package/dist-cjs/ui/comment-extensions.js +4 -1
  32. package/dist-cjs/ui/comment-extensions.js.map +2 -2
  33. package/dist-cjs/ui/comments-list.js +6 -7
  34. package/dist-cjs/ui/comments-list.js.map +2 -2
  35. package/dist-cjs/ui/icons.js +4 -4
  36. package/dist-cjs/ui/icons.js.map +2 -2
  37. package/dist-cjs/ui/reaction-picker.js +2 -2
  38. package/dist-cjs/ui/reaction-picker.js.map +1 -1
  39. package/dist-cjs/ui/send-button.js.map +1 -1
  40. package/dist-esm/canvas/canvas-events.mjs +25 -1
  41. package/dist-esm/canvas/canvas-events.mjs.map +2 -2
  42. package/dist-esm/canvas/comment-tool.mjs +30 -29
  43. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  44. package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
  45. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  46. package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
  47. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  48. package/dist-esm/canvas/comments-overlay.mjs +1 -0
  49. package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
  50. package/dist-esm/canvas/comments-sidebar.mjs +16 -4
  51. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  52. package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
  53. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
  54. package/dist-esm/canvas/options.mjs.map +2 -2
  55. package/dist-esm/canvas/pending-composer.mjs +143 -9
  56. package/dist-esm/canvas/pending-composer.mjs.map +2 -2
  57. package/dist-esm/canvas/region-box.mjs +161 -38
  58. package/dist-esm/canvas/region-box.mjs.map +3 -3
  59. package/dist-esm/canvas/thread-pin.mjs +22 -6
  60. package/dist-esm/canvas/thread-pin.mjs.map +2 -2
  61. package/dist-esm/canvas/thread-view.mjs +140 -58
  62. package/dist-esm/canvas/thread-view.mjs.map +2 -2
  63. package/dist-esm/index.d.mts +39 -11
  64. package/dist-esm/index.mjs +1 -1
  65. package/dist-esm/ui/byline.mjs +2 -2
  66. package/dist-esm/ui/byline.mjs.map +2 -2
  67. package/dist-esm/ui/comment-card.mjs +3 -1
  68. package/dist-esm/ui/comment-card.mjs.map +2 -2
  69. package/dist-esm/ui/comment-extensions.mjs +11 -2
  70. package/dist-esm/ui/comment-extensions.mjs.map +2 -2
  71. package/dist-esm/ui/comments-list.mjs +6 -7
  72. package/dist-esm/ui/comments-list.mjs.map +2 -2
  73. package/dist-esm/ui/icons.mjs +4 -4
  74. package/dist-esm/ui/icons.mjs.map +2 -2
  75. package/dist-esm/ui/reaction-picker.mjs +2 -2
  76. package/dist-esm/ui/reaction-picker.mjs.map +1 -1
  77. package/dist-esm/ui/send-button.mjs.map +1 -1
  78. package/package.json +5 -5
  79. package/src/canvas/canvas-events.ts +39 -2
  80. package/src/canvas/canvas.css +73 -38
  81. package/src/canvas/comment-render.test.ts +8 -1
  82. package/src/canvas/comment-tool.test.ts +34 -44
  83. package/src/canvas/comment-tool.tsx +51 -55
  84. package/src/canvas/comments-filter-menu.tsx +19 -6
  85. package/src/canvas/comments-overflow-menu.tsx +12 -18
  86. package/src/canvas/comments-overlay.tsx +5 -2
  87. package/src/canvas/comments-sidebar.tsx +20 -5
  88. package/src/canvas/comments-visibility-toggle.tsx +1 -1
  89. package/src/canvas/options.ts +21 -2
  90. package/src/canvas/pending-composer.tsx +182 -17
  91. package/src/canvas/region-box.tsx +192 -42
  92. package/src/canvas/thread-pin.tsx +28 -6
  93. package/src/canvas/thread-view.test.ts +39 -0
  94. package/src/canvas/thread-view.tsx +185 -70
  95. package/src/ui/byline.tsx +5 -2
  96. package/src/ui/comment-card.tsx +7 -1
  97. package/src/ui/comment-extensions.ts +18 -5
  98. package/src/ui/comments-list.tsx +23 -17
  99. package/src/ui/comments.css +175 -201
  100. package/src/ui/icons.tsx +5 -5
  101. package/src/ui/reaction-picker.tsx +2 -2
  102. package/src/ui/send-button.tsx +2 -2
@@ -1,5 +1,14 @@
1
- import { type PointerEvent as ReactPointerEvent, useRef } from 'react'
2
- import { type BoxModel, Editor, useValue, VecLike } from 'tldraw'
1
+ import { type PointerEvent as ReactPointerEvent, useEffect, useRef } from 'react'
2
+ import {
3
+ type BoxModel,
4
+ Editor,
5
+ getCursor,
6
+ getPerfectDashProps,
7
+ usePassThroughWheelEvents,
8
+ useValue,
9
+ VecLike,
10
+ } from 'tldraw'
11
+ import { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from './canvas-events'
3
12
  import { regionDraft } from './state'
4
13
 
5
14
  /** A region's dashed box. Purely visual — a region moves by its pin and resizes from its corner
@@ -16,7 +25,39 @@ export function RegionBox({ editor, box }: { editor: Editor; box: BoxModel }) {
16
25
  },
17
26
  [editor, box.x, box.y, box.w, box.h]
18
27
  )
19
- return <div className="tlui-cmt-canvas-region" style={rect} />
28
+ const { width: w, height: h } = rect
29
+ // The group outline's dashes: drawn per side with perfect dashes (so every side starts and ends
30
+ // on a dash), at the 1px dash scale and 1.5px stroke the editor's selection outline uses.
31
+ const sides = [
32
+ [0, 0, w, 0],
33
+ [w, 0, w, h],
34
+ [w, h, 0, h],
35
+ [0, h, 0, 0],
36
+ ]
37
+ return (
38
+ <div className="tlui-cmt-canvas-region" style={rect}>
39
+ <svg className="tlui-cmt-canvas-region__outline" width={w} height={h} aria-hidden="true">
40
+ {sides.map(([x1, y1, x2, y2], i) => {
41
+ const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(
42
+ Math.hypot(x2 - x1, y2 - y1),
43
+ 1,
44
+ { style: 'dashed', lengthRatio: 4 }
45
+ )
46
+ return (
47
+ <line
48
+ key={i}
49
+ x1={x1}
50
+ y1={y1}
51
+ x2={x2}
52
+ y2={y2}
53
+ strokeDasharray={strokeDasharray}
54
+ strokeDashoffset={strokeDashoffset}
55
+ />
56
+ )
57
+ })}
58
+ </svg>
59
+ </div>
60
+ )
20
61
  }
21
62
 
22
63
  /** The live region being dragged out by the comment tool, or nothing when not dragging. */
@@ -26,15 +67,13 @@ export function RegionDraftBox({ editor }: { editor: Editor }) {
26
67
  return <RegionBox editor={editor} box={box} />
27
68
  }
28
69
 
29
- // A resize handle's normalized 0–1 spot on the box, and its cursor. An axis at 0.5 is *not*
30
- // controlled by that handle — the resize math reads the spot rather than special-casing corners.
70
+ // A corner resize handle: its normalized 0–1 spot on the box, and its cursor.
31
71
  export interface RegionHandle {
32
72
  x: number
33
73
  y: number
34
- cursor: string
74
+ cursor: 'nwse-resize' | 'nesw-resize'
35
75
  }
36
76
 
37
- // The four corners, each resizing both axes.
38
77
  export const REGION_CORNERS: readonly RegionHandle[] = [
39
78
  { x: 0, y: 0, cursor: 'nwse-resize' },
40
79
  { x: 1, y: 0, cursor: 'nesw-resize' },
@@ -46,24 +85,56 @@ export const REGION_CORNERS: readonly RegionHandle[] = [
46
85
  // the handles (which sit on the edge) are comfortably reachable.
47
86
  export const REGION_HANDLE_MARGIN_PX = 12
48
87
 
49
- /** Resize `box` by dragging `handle` to `cursor` (page coords). Each controlled axis spans from the
50
- * handle's fixed opposite edge to the cursor (normalized, so dragging past it flips); an axis the
51
- * handle doesn't control (a midpoint, at 0.5) keeps its original position and size. */
88
+ /** Resize `box` by dragging corner `handle` to `cursor` (page coords): the box spans from the
89
+ * opposite corner to the cursor, normalized so dragging past that corner flips it. */
52
90
  function resizeRegion(box: BoxModel, handle: RegionHandle, cursor: VecLike): BoxModel {
53
- const controlsX = handle.x !== 0.5
54
- const controlsY = handle.y !== 0.5
55
91
  const fixedX = box.x + (1 - handle.x) * box.w
56
92
  const fixedY = box.y + (1 - handle.y) * box.h
57
93
  return {
58
- x: controlsX ? Math.min(fixedX, cursor.x) : box.x,
59
- y: controlsY ? Math.min(fixedY, cursor.y) : box.y,
60
- w: controlsX ? Math.abs(cursor.x - fixedX) : box.w,
61
- h: controlsY ? Math.abs(cursor.y - fixedY) : box.h,
94
+ x: Math.min(fixedX, cursor.x),
95
+ y: Math.min(fixedY, cursor.y),
96
+ w: Math.abs(cursor.x - fixedX),
97
+ h: Math.abs(cursor.y - fixedY),
98
+ }
99
+ }
100
+
101
+ /**
102
+ * The selection's corner-handle sizing (`SelectionForegroundOverlayUtil`), in screen px for a box
103
+ * `w`×`h` px on screen, so a region's corners look and hit exactly like a shape's resize corners.
104
+ * Keep in step with that util: the constants are its, not tuned here.
105
+ */
106
+ export function selectionCornerSizing(w: number, h: number, isCoarsePointer: boolean) {
107
+ const handleSize = 8
108
+ const mobileHandleMultiplier = isCoarsePointer ? 1.75 : 1
109
+ const hitTargetSize = 6 * mobileHandleMultiplier
110
+ const isSmallX = w < handleSize * 4
111
+ const isSmallY = h < handleSize * 4
112
+ const hitTargetSizeX =
113
+ (isSmallX ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75)
114
+ const hitTargetSizeY =
115
+ (isSmallY ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75)
116
+ const isTinyX = w < handleSize * 2
117
+ const isTinyY = h < handleSize * 2
118
+ return {
119
+ // The corner hit square's full side: the util's `cornerHitHalfSize`, doubled.
120
+ hitSize: Math.max(hitTargetSizeX, hitTargetSizeY) * 1.5 * 2,
121
+ hideAlternateCorners: isTinyX || isTinyY,
122
+ showOnlyOneCorner: isTinyX && isTinyY,
62
123
  }
63
124
  }
64
125
 
65
- /** Draggable handles that resize a region — corners (both axes) or edges (one axis), per the resize
66
- * option. Previews live, commits on release. */
126
+ // The selection hides the top-right and bottom-left corners on a tiny box, and the bottom-right too
127
+ // when it's tiny both ways (top-left always shows).
128
+ function isHiddenCorner(
129
+ h: RegionHandle,
130
+ sizing: ReturnType<typeof selectionCornerSizing>
131
+ ): boolean {
132
+ if (h.x === 0 && h.y === 0) return false
133
+ if (h.x === 1 && h.y === 1) return sizing.showOnlyOneCorner
134
+ return sizing.hideAlternateCorners
135
+ }
136
+
137
+ /** Draggable corner handles that resize a region. Previews live, commits on release. */
67
138
  export function RegionResizeHandles({
68
139
  editor,
69
140
  box,
@@ -79,46 +150,125 @@ export function RegionResizeHandles({
79
150
  }) {
80
151
  // The box at pointer-down, captured so the box prop reflowing under the live preview doesn't move
81
152
  // the fixed edges mid-drag.
82
- const boxRef = useRef<BoxModel | null>(null)
83
- const points = useValue(
84
- 'region handle points',
85
- () =>
86
- handles.map((h) => {
87
- const p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })
88
- return { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }
89
- }),
153
+ const dragRef = useRef<{
154
+ box: BoxModel
155
+ handle: RegionHandle
156
+ clientX: number
157
+ clientY: number
158
+ endDrag(): void
159
+ } | null>(null)
160
+ const wheelRef = useRef<HTMLDivElement>(null)
161
+ usePassThroughWheelEvents(wheelRef)
162
+ // Unmounting mid-resize gets no pointer up to end the drag.
163
+ useEffect(() => () => dragRef.current?.endDrag(), [])
164
+ const layout = useValue(
165
+ 'region handle layout',
166
+ () => {
167
+ const zoom = editor.getZoomLevel()
168
+ const sizing = selectionCornerSizing(
169
+ box.w * zoom,
170
+ box.h * zoom,
171
+ editor.getInstanceState().isCoarsePointer
172
+ )
173
+ const dragged = dragRef.current?.handle
174
+ const points = handles
175
+ // The corner being dragged stays, even as the box shrinks to a size that hides it:
176
+ // unmounting it would drop its pointer capture and strand the resize.
177
+ .filter((h) => (h.x === dragged?.x && h.y === dragged?.y) || !isHiddenCorner(h, sizing))
178
+ .map((h) => {
179
+ const p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })
180
+ return { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }
181
+ })
182
+ // tldraw's own resize cursors (the editor's, in the theme's cursor colour), not the
183
+ // browser's native ones.
184
+ const { cursor: cursorColor } = editor.getCurrentTheme().colors[editor.getColorMode()]
185
+ const cursors = {
186
+ 'nwse-resize': getCursor('nwse-resize', 0, cursorColor),
187
+ 'nesw-resize': getCursor('nesw-resize', 0, cursorColor),
188
+ }
189
+ return { points, hitSize: sizing.hitSize, cursors }
190
+ },
90
191
  [editor, box.x, box.y, box.w, box.h, handles]
91
192
  )
92
- const startResize = (e: ReactPointerEvent<HTMLDivElement>) => {
193
+ const { points, hitSize, cursors } = layout
194
+ const resized = () => {
195
+ const drag = dragRef.current!
196
+ return resizeRegion(
197
+ drag.box,
198
+ drag.handle,
199
+ editor.screenToPage({ x: drag.clientX, y: drag.clientY })
200
+ )
201
+ }
202
+ const startResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {
203
+ // A middle/right-button or space-held press is a camera pan, not a resize.
204
+ if (isCanvasPanGesture(editor, e)) {
205
+ forwardPointerEventToCanvas(editor.getContainer(), e)
206
+ return
207
+ }
93
208
  e.stopPropagation()
94
- boxRef.current = box
209
+ dragRef.current?.endDrag()
210
+ dragRef.current = {
211
+ box,
212
+ handle: h,
213
+ clientX: e.clientX,
214
+ clientY: e.clientY,
215
+ endDrag: startCommentDrag(editor, {
216
+ cursor: h.cursor,
217
+ onCameraMove: () => {
218
+ if (dragRef.current) onPreview(resized())
219
+ },
220
+ }),
221
+ }
95
222
  e.currentTarget.setPointerCapture(e.pointerId)
96
223
  }
97
- const resizedTo = (h: RegionHandle, e: ReactPointerEvent<HTMLDivElement>): BoxModel =>
98
- resizeRegion(boxRef.current!, h, editor.screenToPage({ x: e.clientX, y: e.clientY }))
99
- const onResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {
100
- if (boxRef.current) onPreview(resizedTo(h, e))
224
+ const onResize = (e: ReactPointerEvent<HTMLDivElement>) => {
225
+ const drag = dragRef.current
226
+ if (!drag) return
227
+ drag.clientX = e.clientX
228
+ drag.clientY = e.clientY
229
+ onPreview(resized())
101
230
  }
102
- const endResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {
103
- if (!boxRef.current) return
104
- const bounds = resizedTo(h, e)
105
- boxRef.current = null
231
+ const endResize = (e: ReactPointerEvent<HTMLDivElement>) => {
232
+ const drag = dragRef.current
233
+ if (!drag) return
234
+ drag.clientX = e.clientX
235
+ drag.clientY = e.clientY
236
+ const bounds = resized()
237
+ dragRef.current = null
238
+ drag.endDrag()
106
239
  if (e.currentTarget.hasPointerCapture(e.pointerId))
107
240
  e.currentTarget.releasePointerCapture(e.pointerId)
108
241
  onCommit(bounds)
109
242
  }
243
+ // A cancelled pointer abandons the resize: the region snaps back to its stored bounds.
244
+ const cancelResize = () => {
245
+ const drag = dragRef.current
246
+ if (!drag) return
247
+ dragRef.current = null
248
+ drag.endDrag()
249
+ onPreview(null)
250
+ }
110
251
  return (
111
- <>
252
+ // A wheel over a handle (even mid-resize) scrolls the canvas, like everywhere else on it.
253
+ <div ref={wheelRef} className="tlui-cmt-canvas-region-handles">
112
254
  {points.map((h) => (
113
255
  <div
114
256
  key={h.key}
115
257
  className="tlui-cmt-canvas-region-handle"
116
- style={{ left: h.left, top: h.top, cursor: h.cursor }}
117
- onPointerDown={startResize}
118
- onPointerMove={onResize(h)}
119
- onPointerUp={endResize(h)}
258
+ style={{
259
+ left: h.left,
260
+ top: h.top,
261
+ width: hitSize,
262
+ height: hitSize,
263
+ cursor: cursors[h.cursor],
264
+ }}
265
+ onPointerDown={startResize(h)}
266
+ onPointerMove={onResize}
267
+ onPointerUp={endResize}
268
+ onPointerCancel={cancelResize}
269
+ onLostPointerCapture={cancelResize}
120
270
  />
121
271
  ))}
122
- </>
272
+ </div>
123
273
  )
124
274
  }
@@ -18,7 +18,7 @@ import {
18
18
  useValue,
19
19
  } from 'tldraw'
20
20
  import { CommentPin } from '../ui/comment-pin'
21
- import { forwardPointerEventToCanvas, isCanvasPanGesture } from './canvas-events'
21
+ import { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from './canvas-events'
22
22
  import { commitCommentMutation } from './comment-mutations'
23
23
  import { UNKNOWN_COMMENT_AUTHOR } from './comment-render'
24
24
  import { type CommentingContext } from './context'
@@ -45,7 +45,7 @@ import {
45
45
  regionWithPinAt,
46
46
  shapeAnchorAt,
47
47
  } from './thread-state'
48
- import { POPOVER_OFFSET, ThreadPopover, ThreadView } from './thread-view'
48
+ import { avatarRenderer, POPOVER_OFFSET, ThreadPopover, ThreadView } from './thread-view'
49
49
 
50
50
  const messages = defineMessages({
51
51
  commentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },
@@ -129,6 +129,9 @@ export const ThreadPin = memo(function ThreadPin({
129
129
  // cursor's delta (like RegionBox's move) instead of snapping the anchor to the cursor.
130
130
  offsetX: number
131
131
  offsetY: number
132
+ clientX: number
133
+ clientY: number
134
+ endDrag?(): void
132
135
  } | null>(null)
133
136
  const markerRef = useRef<HTMLButtonElement>(null)
134
137
  // Wheel pass-through sits on the marker (which is never scrollable), not the layer root —
@@ -140,7 +143,9 @@ export const ThreadPin = memo(function ThreadPin({
140
143
  // clear the hint here or it stays on the shape indefinitely.
141
144
  useEffect(() => {
142
145
  return () => {
143
- if (dragRef.current) editor.setHintingShapes([])
146
+ if (!dragRef.current) return
147
+ editor.setHintingShapes([])
148
+ dragRef.current.endDrag?.()
144
149
  }
145
150
  }, [editor])
146
151
 
@@ -199,10 +204,13 @@ export const ThreadPin = memo(function ThreadPin({
199
204
 
200
205
  const PinContent = options.components.PinContent
201
206
  const threadAuthor = resolveAuthor(thread.createdBy)
207
+ const pinAuthor = threadAuthor ?? UNKNOWN_COMMENT_AUTHOR
202
208
  const pinContent = PinContent ? (
203
209
  <PinContent thread={thread} comments={comments} />
204
210
  ) : (
205
- <Avatar author={threadAuthor ?? UNKNOWN_COMMENT_AUTHOR} />
211
+ (avatarRenderer(options.components, thread.createdBy)?.(pinAuthor) ?? (
212
+ <Avatar author={pinAuthor} />
213
+ ))
206
214
  )
207
215
  const pinLabel = msg(
208
216
  thread.resolved ? messages.commentsPinLabelResolved : messages.commentsPinLabel,
@@ -236,6 +244,8 @@ export const ThreadPin = memo(function ThreadPin({
236
244
  dragRef.current = {
237
245
  startX: e.clientX,
238
246
  startY: e.clientY,
247
+ clientX: e.clientX,
248
+ clientY: e.clientY,
239
249
  moved: false,
240
250
  offsetX: anchorPage ? anchorPage.x - grabPage.x : 0,
241
251
  offsetY: anchorPage ? anchorPage.y - grabPage.y : 0,
@@ -249,8 +259,19 @@ export const ThreadPin = memo(function ThreadPin({
249
259
  // press stays a click (`moved` never sets, so release toggles the popover and never commits).
250
260
  if (!canComment) return
251
261
  if (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return
252
- drag.moved = true
253
- const cursorPage = editor.screenToPage({ x: e.clientX, y: e.clientY })
262
+ drag.clientX = e.clientX
263
+ drag.clientY = e.clientY
264
+ if (!drag.moved) {
265
+ drag.moved = true
266
+ drag.endDrag = startCommentDrag(editor, { cursor: 'move', onCameraMove: dragToPointer })
267
+ }
268
+ dragToPointer()
269
+ }
270
+ // Place the pin under the drag's last pointer position, at the current camera.
271
+ const dragToPointer = () => {
272
+ const drag = dragRef.current
273
+ if (!drag) return
274
+ const cursorPage = editor.screenToPage({ x: drag.clientX, y: drag.clientY })
254
275
  const pagePoint = { x: cursorPage.x + drag.offsetX, y: cursorPage.y + drag.offsetY }
255
276
  setDragPagePoint(pagePoint)
256
277
  // Hint the shape the pin would re-anchor to on drop — the same hit-test endDrag resolves
@@ -264,6 +285,7 @@ export const ThreadPin = memo(function ThreadPin({
264
285
  const takeDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {
265
286
  const drag = dragRef.current
266
287
  dragRef.current = null
288
+ drag?.endDrag?.()
267
289
  if (e.currentTarget.hasPointerCapture(e.pointerId)) {
268
290
  e.currentTarget.releasePointerCapture(e.pointerId)
269
291
  }
@@ -1,4 +1,5 @@
1
1
  import type { CommentAuthor } from '@tldraw/mentions'
2
+ import { isValidElement, type ReactElement } from 'react'
2
3
  import type { TLComment } from 'tldraw'
3
4
  import { describe, expect, it } from 'vitest'
4
5
  import { absoluteThreadLink, toCardProps } from './thread-view'
@@ -41,6 +42,44 @@ describe('toCardProps', () => {
41
42
  expect(card.you).toBe(false)
42
43
  expect(card.author).not.toBe(AUTHOR)
43
44
  })
45
+
46
+ it('leaves the byline and avatar to the card when no slots are set', () => {
47
+ const card = toCardProps(comment(), context, {}, resolveName)
48
+ expect(card.byline).toBeUndefined()
49
+ expect(card.renderAvatar).toBeUndefined()
50
+ })
51
+
52
+ it('renders the Avatar slot for the author, with the id they were resolved from', () => {
53
+ const Avatar = () => null
54
+ const card = toCardProps(comment(), context, { Avatar }, resolveName)
55
+ const avatar = card.renderAvatar?.(AUTHOR) as ReactElement<Record<string, unknown>>
56
+ expect(avatar.type).toBe(Avatar)
57
+ expect(avatar.props).toEqual({ author: AUTHOR, authorId: 'user:1' })
58
+ })
59
+
60
+ it('renders the CommentByline slot with the byline props and the comment record', () => {
61
+ const CommentByline = () => null
62
+ const record = comment({ editedAt: Date.parse('2026-07-30T13:00:00.000Z') })
63
+ const card = toCardProps(record, context, { CommentByline }, resolveName)
64
+ expect(isValidElement(card.byline)).toBe(true)
65
+ const byline = card.byline as ReactElement<Record<string, unknown>>
66
+ expect(byline.type).toBe(CommentByline)
67
+ expect(byline.props).toEqual({
68
+ author: AUTHOR,
69
+ date: '2026-07-30T12:00:00.000Z',
70
+ edited: true,
71
+ renderAvatar: undefined,
72
+ comment: record,
73
+ })
74
+ })
75
+
76
+ it('hands the CommentByline slot the Avatar slot, so a spread into Byline keeps it', () => {
77
+ const Avatar = () => null
78
+ const CommentByline = () => null
79
+ const card = toCardProps(comment(), context, { Avatar, CommentByline }, resolveName)
80
+ const byline = card.byline as ReactElement<Record<string, unknown>>
81
+ expect(byline.props.renderAvatar).toBe(card.renderAvatar)
82
+ })
44
83
  })
45
84
 
46
85
  describe('absoluteThreadLink', () => {