@tldraw/commenting 5.7.0-next.c1f7f00fa975 → 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.
- package/commenting.css +277 -275
- package/dist-cjs/canvas/canvas-events.js +25 -1
- package/dist-cjs/canvas/canvas-events.js.map +2 -2
- package/dist-cjs/canvas/comment-tool.js +29 -28
- package/dist-cjs/canvas/comment-tool.js.map +2 -2
- package/dist-cjs/canvas/comments-filter-menu.js +55 -38
- package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
- package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overlay.js +1 -0
- package/dist-cjs/canvas/comments-overlay.js.map +2 -2
- package/dist-cjs/canvas/comments-sidebar.js +15 -3
- package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
- package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
- package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
- package/dist-cjs/canvas/options.js.map +2 -2
- package/dist-cjs/canvas/pending-composer.js +133 -8
- package/dist-cjs/canvas/pending-composer.js.map +2 -2
- package/dist-cjs/canvas/region-box.js +150 -35
- package/dist-cjs/canvas/region-box.js.map +3 -3
- package/dist-cjs/canvas/thread-pin.js +20 -4
- package/dist-cjs/canvas/thread-pin.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +130 -57
- package/dist-cjs/canvas/thread-view.js.map +2 -2
- package/dist-cjs/index.d.ts +39 -11
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/ui/byline.js +2 -2
- package/dist-cjs/ui/byline.js.map +2 -2
- package/dist-cjs/ui/comment-card.js +3 -1
- package/dist-cjs/ui/comment-card.js.map +2 -2
- package/dist-cjs/ui/comment-extensions.js +4 -1
- package/dist-cjs/ui/comment-extensions.js.map +2 -2
- package/dist-cjs/ui/comments-list.js +6 -7
- package/dist-cjs/ui/comments-list.js.map +2 -2
- package/dist-cjs/ui/icons.js +4 -4
- package/dist-cjs/ui/icons.js.map +2 -2
- package/dist-cjs/ui/reaction-picker.js +2 -2
- package/dist-cjs/ui/reaction-picker.js.map +1 -1
- package/dist-cjs/ui/send-button.js.map +1 -1
- package/dist-esm/canvas/canvas-events.mjs +25 -1
- package/dist-esm/canvas/canvas-events.mjs.map +2 -2
- package/dist-esm/canvas/comment-tool.mjs +30 -29
- package/dist-esm/canvas/comment-tool.mjs.map +2 -2
- package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
- package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
- package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overlay.mjs +1 -0
- package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
- package/dist-esm/canvas/comments-sidebar.mjs +16 -4
- package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
- package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
- package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
- package/dist-esm/canvas/options.mjs.map +2 -2
- package/dist-esm/canvas/pending-composer.mjs +143 -9
- package/dist-esm/canvas/pending-composer.mjs.map +2 -2
- package/dist-esm/canvas/region-box.mjs +161 -38
- package/dist-esm/canvas/region-box.mjs.map +3 -3
- package/dist-esm/canvas/thread-pin.mjs +22 -6
- package/dist-esm/canvas/thread-pin.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +140 -58
- package/dist-esm/canvas/thread-view.mjs.map +2 -2
- package/dist-esm/index.d.mts +39 -11
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/ui/byline.mjs +2 -2
- package/dist-esm/ui/byline.mjs.map +2 -2
- package/dist-esm/ui/comment-card.mjs +3 -1
- package/dist-esm/ui/comment-card.mjs.map +2 -2
- package/dist-esm/ui/comment-extensions.mjs +11 -2
- package/dist-esm/ui/comment-extensions.mjs.map +2 -2
- package/dist-esm/ui/comments-list.mjs +6 -7
- package/dist-esm/ui/comments-list.mjs.map +2 -2
- package/dist-esm/ui/icons.mjs +4 -4
- package/dist-esm/ui/icons.mjs.map +2 -2
- package/dist-esm/ui/reaction-picker.mjs +2 -2
- package/dist-esm/ui/reaction-picker.mjs.map +1 -1
- package/dist-esm/ui/send-button.mjs.map +1 -1
- package/package.json +5 -5
- package/src/canvas/canvas-events.ts +39 -2
- package/src/canvas/canvas.css +73 -38
- package/src/canvas/comment-render.test.ts +8 -1
- package/src/canvas/comment-tool.test.ts +34 -44
- package/src/canvas/comment-tool.tsx +51 -55
- package/src/canvas/comments-filter-menu.tsx +19 -6
- package/src/canvas/comments-overflow-menu.tsx +12 -18
- package/src/canvas/comments-overlay.tsx +5 -2
- package/src/canvas/comments-sidebar.tsx +20 -5
- package/src/canvas/comments-visibility-toggle.tsx +1 -1
- package/src/canvas/options.ts +21 -2
- package/src/canvas/pending-composer.tsx +182 -17
- package/src/canvas/region-box.tsx +192 -42
- package/src/canvas/thread-pin.tsx +28 -6
- package/src/canvas/thread-view.test.ts +39 -0
- package/src/canvas/thread-view.tsx +185 -70
- package/src/ui/byline.tsx +5 -2
- package/src/ui/comment-card.tsx +7 -1
- package/src/ui/comment-extensions.ts +18 -5
- package/src/ui/comments-list.tsx +23 -17
- package/src/ui/comments.css +175 -201
- package/src/ui/icons.tsx +5 -5
- package/src/ui/reaction-picker.tsx +2 -2
- package/src/ui/send-button.tsx +2 -2
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
@@ -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
|
-
|
|
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-
|
|
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
|
-
|
|
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
|
-
<
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
267
|
+
author,
|
|
204
268
|
body,
|
|
205
|
-
date
|
|
269
|
+
date,
|
|
206
270
|
you: comment.authorId === props.currentUserId,
|
|
207
|
-
edited
|
|
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
|
-
|
|
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,32 @@ 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
|
+
// Clear the reply before the document-level Escape handler closes the thread, so reopening
|
|
427
|
+
// it doesn't restore the discarded draft. Let the event continue to that handler.
|
|
428
|
+
const replyRef = useRef(reply)
|
|
429
|
+
replyRef.current = reply
|
|
430
|
+
useEffect(() => {
|
|
431
|
+
const win = container.ownerDocument.defaultView
|
|
432
|
+
if (!win) return
|
|
433
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
434
|
+
if (e.key !== 'Escape' || isMentionPickerOpen()) return
|
|
435
|
+
const target = e.target as HTMLElement | null
|
|
436
|
+
if (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return
|
|
437
|
+
if (target.closest('.tlui-cmt-editing')) return
|
|
438
|
+
if (isCommentEmpty(replyRef.current)) return
|
|
439
|
+
setReply(EMPTY_COMMENT)
|
|
440
|
+
clearCommentDraft(replyDraftSlot(thread.id))
|
|
441
|
+
}
|
|
442
|
+
win.addEventListener('keydown', onKeyDown, true)
|
|
443
|
+
return () => win.removeEventListener('keydown', onKeyDown, true)
|
|
444
|
+
}, [container, thread.id])
|
|
345
445
|
// Resolved when the composer closes rather than held as an element: the card unmounts while the
|
|
346
446
|
// composer stands in its place, so the node captured on the way in is gone by the way out.
|
|
347
447
|
const editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)
|
|
448
|
+
// Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a
|
|
449
|
+
// click on Save. See the focus hand-back below.
|
|
450
|
+
const editEndedByKeyboard = useRef(false)
|
|
348
451
|
|
|
349
452
|
// Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor
|
|
350
453
|
// container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.
|
|
@@ -395,8 +498,12 @@ export const ThreadView = memo(function ThreadView({
|
|
|
395
498
|
if (editingId !== null) return
|
|
396
499
|
const resolve = editReturnFocus.current
|
|
397
500
|
editReturnFocus.current = null
|
|
398
|
-
// Runs after React has swapped the card back in, so the target is mounted again by now.
|
|
399
|
-
|
|
501
|
+
// Runs after React has swapped the card back in, so the target is mounted again by now. Shown
|
|
502
|
+
// as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after
|
|
503
|
+
// a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a
|
|
504
|
+
// keyboard user would otherwise be left on an invisible ⋯ button with no ring.
|
|
505
|
+
resolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })
|
|
506
|
+
editEndedByKeyboard.current = false
|
|
400
507
|
}, [editingId])
|
|
401
508
|
|
|
402
509
|
// Reported as one batch so the host can record the receipts in a single write. The write flips
|
|
@@ -473,7 +580,11 @@ export const ThreadView = memo(function ThreadView({
|
|
|
473
580
|
return (
|
|
474
581
|
<div
|
|
475
582
|
className="tlui-cmt-editing"
|
|
583
|
+
onPointerDown={() => {
|
|
584
|
+
editEndedByKeyboard.current = false
|
|
585
|
+
}}
|
|
476
586
|
onKeyDown={(e) => {
|
|
587
|
+
editEndedByKeyboard.current = true
|
|
477
588
|
if (e.key === 'Escape') {
|
|
478
589
|
setEditingId(null)
|
|
479
590
|
e.stopPropagation()
|
|
@@ -482,6 +593,7 @@ export const ThreadView = memo(function ThreadView({
|
|
|
482
593
|
>
|
|
483
594
|
<CommentComposer
|
|
484
595
|
author={card.author}
|
|
596
|
+
leading={card.renderAvatar?.(card.author)}
|
|
485
597
|
placeholder={msg(messages.commentsEditPlaceholder)}
|
|
486
598
|
value={editText}
|
|
487
599
|
onChange={setEditText}
|
|
@@ -510,25 +622,25 @@ export const ThreadView = memo(function ThreadView({
|
|
|
510
622
|
actions={
|
|
511
623
|
canComment && (
|
|
512
624
|
<>
|
|
625
|
+
<CommentReactionPicker comment={comment} currentUserId={currentUserId} />
|
|
513
626
|
{(permissions?.edit || permissions?.delete) && (
|
|
514
627
|
<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
628
|
+
<TldrawUiDropdownMenuGroup>
|
|
629
|
+
{permissions?.edit && (
|
|
630
|
+
<MenuItem
|
|
631
|
+
label={msg(messages.commentsEdit)}
|
|
632
|
+
onClick={() => startEdit(comment, { fromMoreMenu: true })}
|
|
633
|
+
/>
|
|
634
|
+
)}
|
|
635
|
+
{permissions?.delete && (
|
|
636
|
+
<MenuItem
|
|
637
|
+
label={msg(messages.actionDelete)}
|
|
638
|
+
onClick={() => deleteComment(editor, comment)}
|
|
639
|
+
/>
|
|
640
|
+
)}
|
|
641
|
+
</TldrawUiDropdownMenuGroup>
|
|
528
642
|
</MoreOptionsMenu>
|
|
529
643
|
)}
|
|
530
|
-
{/* Last so react is always the rightmost pill. */}
|
|
531
|
-
<CommentReactionPicker comment={comment} currentUserId={currentUserId} />
|
|
532
644
|
</>
|
|
533
645
|
)
|
|
534
646
|
}
|
|
@@ -543,43 +655,42 @@ export const ThreadView = memo(function ThreadView({
|
|
|
543
655
|
<>
|
|
544
656
|
{/* Host verbs — assign, link a ticket — sit ahead of the built-in actions. */}
|
|
545
657
|
{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
658
|
{canComment && currentUserId && (
|
|
564
659
|
<TldrawUiButton
|
|
565
660
|
type="icon"
|
|
566
661
|
tooltip={resolveLabel}
|
|
567
662
|
title={resolveLabel}
|
|
568
|
-
className="tlui-cmt-
|
|
663
|
+
className="tlui-cmt-icon-btn"
|
|
569
664
|
onClick={toggleResolve}
|
|
570
665
|
>
|
|
571
666
|
<TldrawUiIcon icon="check" label={resolveLabel} small />
|
|
572
667
|
</TldrawUiButton>
|
|
573
668
|
)}
|
|
574
|
-
<
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
669
|
+
<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>
|
|
670
|
+
{(threadHref !== undefined || canDeleteThread) && (
|
|
671
|
+
<TldrawUiDropdownMenuGroup>
|
|
672
|
+
{/* A link is a read affordance: offered to anyone who can see the thread,
|
|
673
|
+
including a viewer who can't comment. `noClose` keeps the menu up so the
|
|
674
|
+
item can confirm the copy in place. */}
|
|
675
|
+
{threadHref !== undefined && (
|
|
676
|
+
<MenuItem
|
|
677
|
+
label={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}
|
|
678
|
+
noClose
|
|
679
|
+
onClick={copyThreadLink}
|
|
680
|
+
/>
|
|
681
|
+
)}
|
|
682
|
+
{canDeleteThread && (
|
|
683
|
+
<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />
|
|
684
|
+
)}
|
|
685
|
+
</TldrawUiDropdownMenuGroup>
|
|
686
|
+
)}
|
|
687
|
+
<TldrawUiDropdownMenuGroup>
|
|
688
|
+
<MenuItem
|
|
689
|
+
label={msg(messages.commentsClose)}
|
|
690
|
+
onClick={() => openThreadId.set(editor, null)}
|
|
691
|
+
/>
|
|
692
|
+
</TldrawUiDropdownMenuGroup>
|
|
693
|
+
</MoreOptionsMenu>
|
|
583
694
|
</>
|
|
584
695
|
)
|
|
585
696
|
|
|
@@ -600,6 +711,10 @@ export const ThreadView = memo(function ThreadView({
|
|
|
600
711
|
canReply
|
|
601
712
|
? {
|
|
602
713
|
author: me ?? UNKNOWN_COMMENT_AUTHOR,
|
|
714
|
+
leading: avatarRenderer(
|
|
715
|
+
options.components,
|
|
716
|
+
currentUserId
|
|
717
|
+
)?.(me ?? UNKNOWN_COMMENT_AUTHOR),
|
|
603
718
|
placeholder: msg(messages.commentsReplyPlaceholder),
|
|
604
719
|
sendLabel: msg(messages.commentsSend),
|
|
605
720
|
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">
|
package/src/ui/comment-card.tsx
CHANGED
|
@@ -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 {
|
|
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
|
|
5
|
-
* both the comment composer and comment display. Comments support paragraphs,
|
|
6
|
-
* links, code, and highlight
|
|
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('')
|
package/src/ui/comments-list.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
)
|