@tldraw/commenting 5.7.0-canary.fd4a9d669e63 → 5.7.0-internal.5fe8922939ec

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 (111) hide show
  1. package/commenting.css +280 -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-mutations.js +5 -0
  5. package/dist-cjs/canvas/comment-mutations.js.map +2 -2
  6. package/dist-cjs/canvas/comment-tool.js +29 -28
  7. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  8. package/dist-cjs/canvas/comments-filter-menu.js +55 -38
  9. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  10. package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
  11. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  12. package/dist-cjs/canvas/comments-overlay.js +1 -0
  13. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  14. package/dist-cjs/canvas/comments-sidebar.js +15 -3
  15. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  16. package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
  17. package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
  18. package/dist-cjs/canvas/options.js +12 -0
  19. package/dist-cjs/canvas/options.js.map +2 -2
  20. package/dist-cjs/canvas/pending-composer.js +139 -9
  21. package/dist-cjs/canvas/pending-composer.js.map +2 -2
  22. package/dist-cjs/canvas/region-box.js +150 -35
  23. package/dist-cjs/canvas/region-box.js.map +3 -3
  24. package/dist-cjs/canvas/thread-pin.js +20 -4
  25. package/dist-cjs/canvas/thread-pin.js.map +2 -2
  26. package/dist-cjs/canvas/thread-view.js +134 -58
  27. package/dist-cjs/canvas/thread-view.js.map +2 -2
  28. package/dist-cjs/index.d.ts +46 -12
  29. package/dist-cjs/index.js +1 -1
  30. package/dist-cjs/ui/byline.js +2 -2
  31. package/dist-cjs/ui/byline.js.map +2 -2
  32. package/dist-cjs/ui/comment-card.js +3 -1
  33. package/dist-cjs/ui/comment-card.js.map +2 -2
  34. package/dist-cjs/ui/comment-extensions.js +4 -1
  35. package/dist-cjs/ui/comment-extensions.js.map +2 -2
  36. package/dist-cjs/ui/comments-list.js +6 -7
  37. package/dist-cjs/ui/comments-list.js.map +2 -2
  38. package/dist-cjs/ui/icons.js +4 -4
  39. package/dist-cjs/ui/icons.js.map +2 -2
  40. package/dist-cjs/ui/reaction-picker.js +2 -2
  41. package/dist-cjs/ui/reaction-picker.js.map +1 -1
  42. package/dist-cjs/ui/send-button.js.map +1 -1
  43. package/dist-esm/canvas/canvas-events.mjs +25 -1
  44. package/dist-esm/canvas/canvas-events.mjs.map +2 -2
  45. package/dist-esm/canvas/comment-mutations.mjs +5 -0
  46. package/dist-esm/canvas/comment-mutations.mjs.map +2 -2
  47. package/dist-esm/canvas/comment-tool.mjs +30 -29
  48. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  49. package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
  50. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  51. package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
  52. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  53. package/dist-esm/canvas/comments-overlay.mjs +1 -0
  54. package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
  55. package/dist-esm/canvas/comments-sidebar.mjs +16 -4
  56. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  57. package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
  58. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
  59. package/dist-esm/canvas/options.mjs +12 -0
  60. package/dist-esm/canvas/options.mjs.map +2 -2
  61. package/dist-esm/canvas/pending-composer.mjs +150 -11
  62. package/dist-esm/canvas/pending-composer.mjs.map +2 -2
  63. package/dist-esm/canvas/region-box.mjs +161 -38
  64. package/dist-esm/canvas/region-box.mjs.map +3 -3
  65. package/dist-esm/canvas/thread-pin.mjs +22 -6
  66. package/dist-esm/canvas/thread-pin.mjs.map +2 -2
  67. package/dist-esm/canvas/thread-view.mjs +145 -60
  68. package/dist-esm/canvas/thread-view.mjs.map +2 -2
  69. package/dist-esm/index.d.mts +46 -12
  70. package/dist-esm/index.mjs +1 -1
  71. package/dist-esm/ui/byline.mjs +2 -2
  72. package/dist-esm/ui/byline.mjs.map +2 -2
  73. package/dist-esm/ui/comment-card.mjs +3 -1
  74. package/dist-esm/ui/comment-card.mjs.map +2 -2
  75. package/dist-esm/ui/comment-extensions.mjs +11 -2
  76. package/dist-esm/ui/comment-extensions.mjs.map +2 -2
  77. package/dist-esm/ui/comments-list.mjs +6 -7
  78. package/dist-esm/ui/comments-list.mjs.map +2 -2
  79. package/dist-esm/ui/icons.mjs +4 -4
  80. package/dist-esm/ui/icons.mjs.map +2 -2
  81. package/dist-esm/ui/reaction-picker.mjs +2 -2
  82. package/dist-esm/ui/reaction-picker.mjs.map +1 -1
  83. package/dist-esm/ui/send-button.mjs.map +1 -1
  84. package/package.json +5 -5
  85. package/src/canvas/canvas-events.ts +39 -2
  86. package/src/canvas/canvas.css +76 -38
  87. package/src/canvas/comment-mutations.test.ts +51 -0
  88. package/src/canvas/comment-mutations.ts +14 -0
  89. package/src/canvas/comment-render.test.ts +8 -1
  90. package/src/canvas/comment-tool.test.ts +34 -44
  91. package/src/canvas/comment-tool.tsx +51 -55
  92. package/src/canvas/comments-filter-menu.tsx +19 -6
  93. package/src/canvas/comments-overflow-menu.tsx +12 -18
  94. package/src/canvas/comments-overlay.tsx +5 -2
  95. package/src/canvas/comments-sidebar.tsx +20 -5
  96. package/src/canvas/comments-visibility-toggle.tsx +1 -1
  97. package/src/canvas/options.test.ts +23 -1
  98. package/src/canvas/options.ts +41 -3
  99. package/src/canvas/pending-composer.tsx +190 -19
  100. package/src/canvas/region-box.tsx +192 -42
  101. package/src/canvas/thread-pin.tsx +28 -6
  102. package/src/canvas/thread-view.test.ts +39 -0
  103. package/src/canvas/thread-view.tsx +192 -72
  104. package/src/ui/byline.tsx +5 -2
  105. package/src/ui/comment-card.tsx +7 -1
  106. package/src/ui/comment-extensions.ts +18 -5
  107. package/src/ui/comments-list.tsx +23 -17
  108. package/src/ui/comments.css +175 -201
  109. package/src/ui/icons.tsx +5 -5
  110. package/src/ui/reaction-picker.tsx +2 -2
  111. package/src/ui/send-button.tsx +2 -2
@@ -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', () => {
@@ -1,4 +1,14 @@
1
- import { memo, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'
1
+ import { type CommentAuthor, isMentionPickerOpen } from '@tldraw/mentions'
2
+ import {
3
+ memo,
4
+ ReactNode,
5
+ useCallback,
6
+ useEffect,
7
+ useLayoutEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from 'react'
2
12
  import {
3
13
  createComment,
4
14
  defineMessages,
@@ -7,6 +17,7 @@ import {
7
17
  TLComment,
8
18
  TLCommentThread,
9
19
  TldrawUiButton,
20
+ TldrawUiButtonLabel,
10
21
  TldrawUiDropdownMenuContent,
11
22
  TldrawUiDropdownMenuGroup,
12
23
  TldrawUiDropdownMenuItem,
@@ -31,7 +42,7 @@ import {
31
42
  saveCommentDraft,
32
43
  } from './comment-drafts'
33
44
  import {
34
- commitCommentMutation,
45
+ commitCommentPost,
35
46
  deleteComment,
36
47
  deleteThread,
37
48
  editComment,
@@ -56,7 +67,7 @@ const messages = defineMessages({
56
67
  actionDelete: { id: 'action.delete', defaultMessage: 'Delete' },
57
68
  commentsCopyLink: { id: 'comments.copy-link', defaultMessage: 'Copy link' },
58
69
  commentsDelete: { id: 'comments.delete', defaultMessage: 'Delete thread' },
59
- commentsDismiss: { id: 'comments.dismiss', defaultMessage: 'Dismiss' },
70
+ commentsClose: { id: 'comments.close', defaultMessage: 'Close' },
60
71
  commentsEdit: { id: 'comments.edit', defaultMessage: 'Edit' },
61
72
  commentsEditPlaceholder: {
62
73
  id: 'comments.edit-placeholder',
@@ -69,6 +80,8 @@ const messages = defineMessages({
69
80
  commentsResolve: { id: 'comments.resolve', defaultMessage: 'Resolve' },
70
81
  commentsResolvedBy: { id: 'comments.resolved-by', defaultMessage: 'Resolved by {name}' },
71
82
  commentsSave: { id: 'comments.save', defaultMessage: 'Save' },
83
+ commentsSeeLess: { id: 'comments.see-less', defaultMessage: 'See less' },
84
+ commentsSeeMore: { id: 'comments.see-more', defaultMessage: 'See more' },
72
85
  commentsSend: { id: 'comments.send', defaultMessage: 'Send' },
73
86
  commentsThreadTitle: { id: 'comments.thread-title', defaultMessage: 'Comment' },
74
87
  commentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },
@@ -76,6 +89,51 @@ const messages = defineMessages({
76
89
 
77
90
  const stop = (e: { stopPropagation(): void }) => e.stopPropagation()
78
91
 
92
+ /**
93
+ * A comment body clamped to 10 lines (see `.tlui-cmt-collapsible--collapsed`), with a See more /
94
+ * See less toggle when it's longer. Overflow is measured rather than estimated from the text, so it
95
+ * holds for any body (including a host's `CommentBody` slot) and re-checks as the panel resizes.
96
+ */
97
+ function CollapsibleBody({ children }: { children: ReactNode }) {
98
+ const msg = useTranslation()
99
+ const ref = useRef<HTMLDivElement>(null)
100
+ const [expanded, setExpanded] = useState(false)
101
+ const [overflows, setOverflows] = useState(false)
102
+ useLayoutEffect(() => {
103
+ const el = ref.current
104
+ // Expanded, nothing is clipped to measure; keep the collapsed reading so See less stays.
105
+ if (!el || expanded) return
106
+ const measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)
107
+ measure()
108
+ const observer = new ResizeObserver(measure)
109
+ observer.observe(el)
110
+ for (const child of Array.from(el.children)) observer.observe(child)
111
+ return () => observer.disconnect()
112
+ }, [expanded, children])
113
+ return (
114
+ <>
115
+ <div
116
+ ref={ref}
117
+ className={['tlui-cmt-collapsible', !expanded && 'tlui-cmt-collapsible--collapsed']
118
+ .filter(Boolean)
119
+ .join(' ')}
120
+ >
121
+ {children}
122
+ </div>
123
+ {overflows && (
124
+ <button
125
+ type="button"
126
+ className="tlui-cmt-see-more"
127
+ aria-expanded={expanded}
128
+ onClick={() => setExpanded((v) => !v)}
129
+ >
130
+ {msg(expanded ? messages.commentsSeeLess : messages.commentsSeeMore)}
131
+ </button>
132
+ )}
133
+ </>
134
+ )
135
+ }
136
+
79
137
  /** The "⋯" dropdown used for both a comment's and the thread's actions. */
80
138
  function MoreOptionsMenu({
81
139
  id,
@@ -95,20 +153,14 @@ function MoreOptionsMenu({
95
153
  type="icon"
96
154
  tooltip={msg(messages.commentsMoreOptions)}
97
155
  title={msg(messages.commentsMoreOptions)}
98
- className="tlui-cmt-thread__action"
156
+ className="tlui-cmt-icon-btn"
99
157
  data-cmt-more-for={moreFor}
100
158
  >
101
159
  <TldrawUiIcon icon="dots-vertical" label={msg(messages.commentsMoreOptions)} small />
102
160
  </TldrawUiButton>
103
161
  </TldrawUiDropdownMenuTrigger>
104
- <TldrawUiDropdownMenuContent
105
- className="tlui-cmt-menu"
106
- side="bottom"
107
- align="start"
108
- alignOffset={0}
109
- sideOffset={4}
110
- >
111
- <TldrawUiDropdownMenuGroup>{children}</TldrawUiDropdownMenuGroup>
162
+ <TldrawUiDropdownMenuContent side="bottom" align="end" alignOffset={-6} sideOffset={0}>
163
+ {children}
112
164
  </TldrawUiDropdownMenuContent>
113
165
  </TldrawUiDropdownMenuRoot>
114
166
  )
@@ -116,24 +168,18 @@ function MoreOptionsMenu({
116
168
 
117
169
  function MenuItem({
118
170
  label,
119
- danger,
120
171
  noClose,
121
172
  onClick,
122
173
  }: {
123
174
  label: string
124
- danger?: boolean
125
175
  noClose?: boolean
126
176
  onClick(): void
127
177
  }) {
128
178
  return (
129
179
  <TldrawUiDropdownMenuItem noClose={noClose}>
130
- <button
131
- type="button"
132
- className={danger ? 'tlui-cmt-menu-item tlui-cmt-menu-item--danger' : 'tlui-cmt-menu-item'}
133
- onClick={onClick}
134
- >
135
- <span>{label}</span>
136
- </button>
180
+ <TldrawUiButton type="menu" onClick={onClick}>
181
+ <TldrawUiButtonLabel>{label}</TldrawUiButtonLabel>
182
+ </TldrawUiButton>
137
183
  </TldrawUiDropdownMenuItem>
138
184
  )
139
185
  }
@@ -185,6 +231,19 @@ function useCopyLink(href: string | undefined) {
185
231
  return [copied, copy] as const
186
232
  }
187
233
 
234
+ /**
235
+ * The `Avatar` component slot as a `renderAvatar` callback for the presentational components, bound
236
+ * to the id the avatar stands for. Undefined without an override, so they draw their own default.
237
+ */
238
+ export function avatarRenderer(
239
+ components: CommentingComponents,
240
+ authorId: string | null
241
+ ): ((author: CommentAuthor) => ReactNode) | undefined {
242
+ const Avatar = components.Avatar
243
+ if (!Avatar) return undefined
244
+ return (author) => <Avatar author={author} authorId={authorId} />
245
+ }
246
+
188
247
  export function toCardProps(
189
248
  comment: TLComment,
190
249
  props: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'>,
@@ -199,12 +258,27 @@ export function toCardProps(
199
258
  ) : (
200
259
  <CommentBody richText={comment.body} resolveName={resolveName} />
201
260
  )
261
+ const author = props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR
262
+ const date = new Date(comment.createdAt).toISOString()
263
+ const edited = comment.editedAt != null
264
+ const renderAvatar = avatarRenderer(components, comment.authorId)
265
+ const Byline = components.CommentByline
202
266
  return {
203
- author: props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR,
267
+ author,
204
268
  body,
205
- date: new Date(comment.createdAt).toISOString(),
269
+ date,
206
270
  you: comment.authorId === props.currentUserId,
207
- edited: comment.editedAt != null,
271
+ edited,
272
+ renderAvatar,
273
+ byline: Byline ? (
274
+ <Byline
275
+ author={author}
276
+ date={date}
277
+ edited={edited}
278
+ renderAvatar={renderAvatar}
279
+ comment={comment}
280
+ />
281
+ ) : undefined,
208
282
  }
209
283
  }
210
284
 
@@ -299,9 +373,15 @@ export const ThreadView = memo(function ThreadView({
299
373
  // re-allocate a date string and body element per comment.
300
374
  const cards = useMemo(
301
375
  () =>
302
- comments.map((c) =>
303
- toCardProps(c, { currentUserId, resolveAuthor }, options.components, resolveName)
304
- ),
376
+ comments.map((c) => {
377
+ const card = toCardProps(
378
+ c,
379
+ { currentUserId, resolveAuthor },
380
+ options.components,
381
+ resolveName
382
+ )
383
+ return { ...card, body: <CollapsibleBody>{card.body}</CollapsibleBody> }
384
+ }),
305
385
  [comments, currentUserId, resolveAuthor, options.components, resolveName]
306
386
  )
307
387
  const me = currentUserId ? resolveAuthor(currentUserId) : undefined
@@ -342,9 +422,35 @@ export const ThreadView = memo(function ThreadView({
342
422
  const [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)
343
423
  const canReply = canComment && !thread.resolved
344
424
  const container = useContainer()
425
+
426
+ // Escape in a reply box with text clears the text and keeps the thread open; an empty one falls
427
+ // through to the layer's Escape, which closes the thread. On the window, in the capture phase,
428
+ // so it runs ahead of that document-level handler.
429
+ const replyRef = useRef(reply)
430
+ replyRef.current = reply
431
+ useEffect(() => {
432
+ const win = container.ownerDocument.defaultView
433
+ if (!win) return
434
+ const onKeyDown = (e: KeyboardEvent) => {
435
+ if (e.key !== 'Escape' || isMentionPickerOpen()) return
436
+ const target = e.target as HTMLElement | null
437
+ if (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return
438
+ if (target.closest('.tlui-cmt-editing')) return
439
+ if (isCommentEmpty(replyRef.current)) return
440
+ setReply(EMPTY_COMMENT)
441
+ clearCommentDraft(replyDraftSlot(thread.id))
442
+ e.preventDefault()
443
+ e.stopPropagation()
444
+ }
445
+ win.addEventListener('keydown', onKeyDown, true)
446
+ return () => win.removeEventListener('keydown', onKeyDown, true)
447
+ }, [container, thread.id])
345
448
  // Resolved when the composer closes rather than held as an element: the card unmounts while the
346
449
  // composer stands in its place, so the node captured on the way in is gone by the way out.
347
450
  const editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)
451
+ // Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a
452
+ // click on Save. See the focus hand-back below.
453
+ const editEndedByKeyboard = useRef(false)
348
454
 
349
455
  // Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor
350
456
  // container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.
@@ -395,8 +501,12 @@ export const ThreadView = memo(function ThreadView({
395
501
  if (editingId !== null) return
396
502
  const resolve = editReturnFocus.current
397
503
  editReturnFocus.current = null
398
- // Runs after React has swapped the card back in, so the target is mounted again by now.
399
- resolve?.()?.focus()
504
+ // Runs after React has swapped the card back in, so the target is mounted again by now. Shown
505
+ // as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after
506
+ // a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a
507
+ // keyboard user would otherwise be left on an invisible ⋯ button with no ring.
508
+ resolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })
509
+ editEndedByKeyboard.current = false
400
510
  }, [editingId])
401
511
 
402
512
  // Reported as one batch so the host can record the receipts in a single write. The write flips
@@ -411,7 +521,7 @@ export const ThreadView = memo(function ThreadView({
411
521
 
412
522
  const postReply = () => {
413
523
  if (isCommentEmpty(reply) || !currentUserId) return
414
- const comment = commitCommentMutation(editor, ({ put }) => {
524
+ const comment = commitCommentPost(editor, ({ put }) => {
415
525
  const comment = createComment({
416
526
  threadId: thread.id,
417
527
  pageId: thread.pageId,
@@ -421,6 +531,8 @@ export const ThreadView = memo(function ThreadView({
421
531
  put([comment])
422
532
  return comment
423
533
  })
534
+ // refused: keep the draft; the editor has emitted 'refused'
535
+ if (!comment) return
424
536
  setReply(EMPTY_COMMENT)
425
537
  clearCommentDraft(replyDraftSlot(thread.id))
426
538
  // The host's callback is its own operation, not part of the post's history scope. It runs
@@ -473,7 +585,11 @@ export const ThreadView = memo(function ThreadView({
473
585
  return (
474
586
  <div
475
587
  className="tlui-cmt-editing"
588
+ onPointerDown={() => {
589
+ editEndedByKeyboard.current = false
590
+ }}
476
591
  onKeyDown={(e) => {
592
+ editEndedByKeyboard.current = true
477
593
  if (e.key === 'Escape') {
478
594
  setEditingId(null)
479
595
  e.stopPropagation()
@@ -482,6 +598,7 @@ export const ThreadView = memo(function ThreadView({
482
598
  >
483
599
  <CommentComposer
484
600
  author={card.author}
601
+ leading={card.renderAvatar?.(card.author)}
485
602
  placeholder={msg(messages.commentsEditPlaceholder)}
486
603
  value={editText}
487
604
  onChange={setEditText}
@@ -510,25 +627,25 @@ export const ThreadView = memo(function ThreadView({
510
627
  actions={
511
628
  canComment && (
512
629
  <>
630
+ <CommentReactionPicker comment={comment} currentUserId={currentUserId} />
513
631
  {(permissions?.edit || permissions?.delete) && (
514
632
  <MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>
515
- {permissions?.edit && (
516
- <MenuItem
517
- label={msg(messages.commentsEdit)}
518
- onClick={() => startEdit(comment, { fromMoreMenu: true })}
519
- />
520
- )}
521
- {permissions?.delete && (
522
- <MenuItem
523
- label={msg(messages.actionDelete)}
524
- danger
525
- onClick={() => deleteComment(editor, comment)}
526
- />
527
- )}
633
+ <TldrawUiDropdownMenuGroup>
634
+ {permissions?.edit && (
635
+ <MenuItem
636
+ label={msg(messages.commentsEdit)}
637
+ onClick={() => startEdit(comment, { fromMoreMenu: true })}
638
+ />
639
+ )}
640
+ {permissions?.delete && (
641
+ <MenuItem
642
+ label={msg(messages.actionDelete)}
643
+ onClick={() => deleteComment(editor, comment)}
644
+ />
645
+ )}
646
+ </TldrawUiDropdownMenuGroup>
528
647
  </MoreOptionsMenu>
529
648
  )}
530
- {/* Last so react is always the rightmost pill. */}
531
- <CommentReactionPicker comment={comment} currentUserId={currentUserId} />
532
649
  </>
533
650
  )
534
651
  }
@@ -543,43 +660,42 @@ export const ThreadView = memo(function ThreadView({
543
660
  <>
544
661
  {/* Host verbs — assign, link a ticket — sit ahead of the built-in actions. */}
545
662
  {ThreadActions && <ThreadActions thread={thread} comments={comments} />}
546
- {(threadHref !== undefined || canDeleteThread) && (
547
- <MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>
548
- {/* A link is a read affordance: offered to anyone who can see the thread,
549
- including a viewer who can't comment. `noClose` keeps the menu up so the
550
- item can confirm the copy in place. */}
551
- {threadHref !== undefined && (
552
- <MenuItem
553
- label={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}
554
- noClose
555
- onClick={copyThreadLink}
556
- />
557
- )}
558
- {canDeleteThread && (
559
- <MenuItem label={msg(messages.commentsDelete)} danger onClick={removeThread} />
560
- )}
561
- </MoreOptionsMenu>
562
- )}
563
663
  {canComment && currentUserId && (
564
664
  <TldrawUiButton
565
665
  type="icon"
566
666
  tooltip={resolveLabel}
567
667
  title={resolveLabel}
568
- className="tlui-cmt-thread__action"
668
+ className="tlui-cmt-icon-btn"
569
669
  onClick={toggleResolve}
570
670
  >
571
671
  <TldrawUiIcon icon="check" label={resolveLabel} small />
572
672
  </TldrawUiButton>
573
673
  )}
574
- <TldrawUiButton
575
- type="icon"
576
- tooltip={msg(messages.commentsDismiss)}
577
- title={msg(messages.commentsDismiss)}
578
- className="tlui-cmt-thread__action"
579
- onClick={() => openThreadId.set(editor, null)}
580
- >
581
- <TldrawUiIcon icon="cross-2" label={msg(messages.commentsDismiss)} small />
582
- </TldrawUiButton>
674
+ <MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>
675
+ {(threadHref !== undefined || canDeleteThread) && (
676
+ <TldrawUiDropdownMenuGroup>
677
+ {/* A link is a read affordance: offered to anyone who can see the thread,
678
+ including a viewer who can't comment. `noClose` keeps the menu up so the
679
+ item can confirm the copy in place. */}
680
+ {threadHref !== undefined && (
681
+ <MenuItem
682
+ label={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}
683
+ noClose
684
+ onClick={copyThreadLink}
685
+ />
686
+ )}
687
+ {canDeleteThread && (
688
+ <MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />
689
+ )}
690
+ </TldrawUiDropdownMenuGroup>
691
+ )}
692
+ <TldrawUiDropdownMenuGroup>
693
+ <MenuItem
694
+ label={msg(messages.commentsClose)}
695
+ onClick={() => openThreadId.set(editor, null)}
696
+ />
697
+ </TldrawUiDropdownMenuGroup>
698
+ </MoreOptionsMenu>
583
699
  </>
584
700
  )
585
701
 
@@ -600,6 +716,10 @@ export const ThreadView = memo(function ThreadView({
600
716
  canReply
601
717
  ? {
602
718
  author: me ?? UNKNOWN_COMMENT_AUTHOR,
719
+ leading: avatarRenderer(
720
+ options.components,
721
+ currentUserId
722
+ )?.(me ?? UNKNOWN_COMMENT_AUTHOR),
603
723
  placeholder: msg(messages.commentsReplyPlaceholder),
604
724
  sendLabel: msg(messages.commentsSend),
605
725
  value: reply,
package/src/ui/byline.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Avatar, type CommentAuthor } from '@tldraw/mentions'
2
+ import { type ReactNode } from 'react'
2
3
  import { TldrawUiTooltip, useCurrentTranslation } from 'tldraw'
3
4
  import { formatFullDateTime, formatRelativeTime } from './format-time'
4
5
 
@@ -9,6 +10,8 @@ export interface BylineProps {
9
10
  date: string
10
11
  /** Shows an "edited" marker when the comment has been edited. */
11
12
  edited?: boolean
13
+ /** Draws the author's avatar. Defaults to `<Avatar>`. */
14
+ renderAvatar?(author: CommentAuthor): ReactNode
12
15
  }
13
16
 
14
17
  /**
@@ -16,13 +19,13 @@ export interface BylineProps {
16
19
  * shows the full date and time in a tooltip.
17
20
  * @public @react
18
21
  */
19
- export function Byline({ author, date, edited }: BylineProps) {
22
+ export function Byline({ author, date, edited, renderAvatar }: BylineProps) {
20
23
  // The relative time is the one piece of a byline that isn't the host's data, so it follows the
21
24
  // same translation context as every other string in the UI rather than a prop of its own.
22
25
  const { locale } = useCurrentTranslation()
23
26
  return (
24
27
  <div className="tlui-cmt-head">
25
- <Avatar author={author} />
28
+ {renderAvatar ? renderAvatar(author) : <Avatar author={author} />}
26
29
  <span className="tlui-cmt-author">{author.name}</span>
27
30
  <TldrawUiTooltip content={formatFullDateTime(date, locale)}>
28
31
  <span className="tlui-cmt-time">
@@ -13,6 +13,10 @@ export interface CommentCardProps {
13
13
  you: boolean
14
14
  /** Whether the comment has been edited (shows an "edited" marker). */
15
15
  edited?: boolean
16
+ /** Replaces the default `<Byline>` built from `author`, `date`, and `edited`. */
17
+ byline?: ReactNode
18
+ /** Draws the default byline's avatar. Defaults to `<Avatar>`. */
19
+ renderAvatar?(author: CommentAuthor): ReactNode
16
20
  /** Hover-revealed controls at the card's top-right (e.g. an edit affordance). */
17
21
  actions?: ReactNode
18
22
  /** Content under the body, aligned with it rather than the avatar (e.g. a `<Reactions>` row). */
@@ -26,12 +30,14 @@ export function CommentCard({
26
30
  date,
27
31
  you,
28
32
  edited,
33
+ byline,
34
+ renderAvatar,
29
35
  actions,
30
36
  footer,
31
37
  }: CommentCardProps) {
32
38
  return (
33
39
  <div className={you ? 'tlui-cmt-card tlui-cmt-card--you' : 'tlui-cmt-card'}>
34
- <Byline author={author} date={date} edited={edited} />
40
+ {byline ?? <Byline author={author} date={date} edited={edited} renderAvatar={renderAvatar} />}
35
41
  <div className="tlui-cmt-body">
36
42
  {body}
37
43
  {footer}
@@ -1,12 +1,25 @@
1
- import { getTipTapDefaultExtensions, TLRichText, toRichText } from 'tldraw'
1
+ import {
2
+ getTipTapDefaultExtensions,
3
+ TaskItem,
4
+ TaskItemToggleExtension,
5
+ TaskList,
6
+ TLRichText,
7
+ toRichText,
8
+ } from 'tldraw'
9
+
10
+ // A posted comment is static HTML with nothing to write a click back to, so a checkbox there would
11
+ // toggle on screen and snap back.
12
+ const TASK_EXTENSION_NAMES = new Set([TaskList.name, TaskItem.name, TaskItemToggleExtension.name])
2
13
 
3
14
  /**
4
- * tldraw's default rich-text extension set, minus headings — the deliberately limited set used for
5
- * both the comment composer and comment display. Comments support paragraphs, bold, italic, lists,
6
- * links, code, and highlight, but not headings. Built from tldraw's shared factory so the config
15
+ * tldraw's default rich-text extension set, minus headings and task lists — the deliberately
16
+ * limited set used for both the comment composer and comment display. Comments support paragraphs,
17
+ * bold, italic, lists, links, code, and highlight. Built from tldraw's shared factory so the config
7
18
  * stays in lockstep with the text shape's defaults rather than drifting from a copy.
8
19
  */
9
- export const commentTipTapExtensions = getTipTapDefaultExtensions({ heading: false })
20
+ export const commentTipTapExtensions = getTipTapDefaultExtensions({ heading: false }).filter(
21
+ (extension) => !TASK_EXTENSION_NAMES.has(extension.name)
22
+ )
10
23
 
11
24
  /** An empty comment document — the seed value for a fresh composer and its post-submit reset. */
12
25
  export const EMPTY_COMMENT: TLRichText = toRichText('')
@@ -1,4 +1,4 @@
1
- import { Avatar, type CommentAuthor } from '@tldraw/mentions'
1
+ import { type CommentAuthor } from '@tldraw/mentions'
2
2
  import { Fragment, MouseEvent, ReactNode } from 'react'
3
3
  import { useTranslation } from 'tldraw'
4
4
  import { Byline } from './byline'
@@ -24,6 +24,8 @@ export interface CommentListItemProps {
24
24
  /** Tallied reactions for the row (a thread's, or a single comment's when the row is one
25
25
  * comment), shown as inert pills under the preview. Omit to hide. */
26
26
  reactions?: ReactionSummary[]
27
+ /** Draws the author's avatar. Defaults to `<Avatar>`. */
28
+ renderAvatar?(author: CommentAuthor): ReactNode
27
29
  /**
28
30
  * Link target for the item. When set, the row renders as an anchor so browser affordances
29
31
  * (ctrl/cmd-click, middle-click) open it in a new tab; a plain click still calls `onSelect`.
@@ -122,6 +124,7 @@ export function CommentListItem({
122
124
  selected,
123
125
  reactions,
124
126
  href,
127
+ renderAvatar,
125
128
  resolvedLabel = 'Resolved',
126
129
  onSelect,
127
130
  }: CommentListItemRenderProps) {
@@ -143,23 +146,26 @@ export function CommentListItem({
143
146
  data-resolved={resolved || undefined}
144
147
  onClick={handleClick}
145
148
  >
146
- <Avatar author={author} />
147
149
  <div className="tlui-cmt-list__item-body">
148
- <Byline author={author} date={date} />
149
- <div className="tlui-cmt-list__item-preview">{preview}</div>
150
- {reactions && <Reactions reactions={reactions} canReact={false} enableHoverList={false} />}
151
- {(resolved || page !== undefined || replies) && (
152
- <div className="tlui-cmt-list__item-meta">
153
- {resolved && (
154
- <span className="tlui-cmt-list__item-resolved">
155
- <CheckIcon />
156
- {resolvedLabel}
157
- </span>
158
- )}
159
- {page !== undefined && <span className="tlui-cmt-list__item-page">{page}</span>}
160
- {replies && <span className="tlui-cmt-list__item-replies">{replies}</span>}
161
- </div>
162
- )}
150
+ <Byline author={author} date={date} renderAvatar={renderAvatar} />
151
+ <div className="tlui-cmt-body">
152
+ <div className="tlui-cmt-list__item-preview">{preview}</div>
153
+ {reactions && (
154
+ <Reactions reactions={reactions} canReact={false} enableHoverList={false} />
155
+ )}
156
+ {(resolved || page !== undefined || replies) && (
157
+ <div className="tlui-cmt-list__item-meta">
158
+ {resolved && (
159
+ <span className="tlui-cmt-list__item-resolved">
160
+ <CheckIcon />
161
+ {resolvedLabel}
162
+ </span>
163
+ )}
164
+ {page !== undefined && <span className="tlui-cmt-list__item-page">{page}</span>}
165
+ {replies && <span className="tlui-cmt-list__item-replies">{replies}</span>}
166
+ </div>
167
+ )}
168
+ </div>
163
169
  </div>
164
170
  </Tag>
165
171
  )