@tldraw/commenting 5.7.0-canary.f455f8677efe → 5.7.0-canary.f58edb2cdca7
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 +137 -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 +132 -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 +147 -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 +142 -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 +76 -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 +186 -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 +188 -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 +172 -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,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
|
-
|
|
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
|
|
@@ -473,7 +583,11 @@ export const ThreadView = memo(function ThreadView({
|
|
|
473
583
|
return (
|
|
474
584
|
<div
|
|
475
585
|
className="tlui-cmt-editing"
|
|
586
|
+
onPointerDown={() => {
|
|
587
|
+
editEndedByKeyboard.current = false
|
|
588
|
+
}}
|
|
476
589
|
onKeyDown={(e) => {
|
|
590
|
+
editEndedByKeyboard.current = true
|
|
477
591
|
if (e.key === 'Escape') {
|
|
478
592
|
setEditingId(null)
|
|
479
593
|
e.stopPropagation()
|
|
@@ -482,6 +596,7 @@ export const ThreadView = memo(function ThreadView({
|
|
|
482
596
|
>
|
|
483
597
|
<CommentComposer
|
|
484
598
|
author={card.author}
|
|
599
|
+
leading={card.renderAvatar?.(card.author)}
|
|
485
600
|
placeholder={msg(messages.commentsEditPlaceholder)}
|
|
486
601
|
value={editText}
|
|
487
602
|
onChange={setEditText}
|
|
@@ -510,25 +625,25 @@ export const ThreadView = memo(function ThreadView({
|
|
|
510
625
|
actions={
|
|
511
626
|
canComment && (
|
|
512
627
|
<>
|
|
628
|
+
<CommentReactionPicker comment={comment} currentUserId={currentUserId} />
|
|
513
629
|
{(permissions?.edit || permissions?.delete) && (
|
|
514
630
|
<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
631
|
+
<TldrawUiDropdownMenuGroup>
|
|
632
|
+
{permissions?.edit && (
|
|
633
|
+
<MenuItem
|
|
634
|
+
label={msg(messages.commentsEdit)}
|
|
635
|
+
onClick={() => startEdit(comment, { fromMoreMenu: true })}
|
|
636
|
+
/>
|
|
637
|
+
)}
|
|
638
|
+
{permissions?.delete && (
|
|
639
|
+
<MenuItem
|
|
640
|
+
label={msg(messages.actionDelete)}
|
|
641
|
+
onClick={() => deleteComment(editor, comment)}
|
|
642
|
+
/>
|
|
643
|
+
)}
|
|
644
|
+
</TldrawUiDropdownMenuGroup>
|
|
528
645
|
</MoreOptionsMenu>
|
|
529
646
|
)}
|
|
530
|
-
{/* Last so react is always the rightmost pill. */}
|
|
531
|
-
<CommentReactionPicker comment={comment} currentUserId={currentUserId} />
|
|
532
647
|
</>
|
|
533
648
|
)
|
|
534
649
|
}
|
|
@@ -543,43 +658,42 @@ export const ThreadView = memo(function ThreadView({
|
|
|
543
658
|
<>
|
|
544
659
|
{/* Host verbs — assign, link a ticket — sit ahead of the built-in actions. */}
|
|
545
660
|
{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
661
|
{canComment && currentUserId && (
|
|
564
662
|
<TldrawUiButton
|
|
565
663
|
type="icon"
|
|
566
664
|
tooltip={resolveLabel}
|
|
567
665
|
title={resolveLabel}
|
|
568
|
-
className="tlui-cmt-
|
|
666
|
+
className="tlui-cmt-icon-btn"
|
|
569
667
|
onClick={toggleResolve}
|
|
570
668
|
>
|
|
571
669
|
<TldrawUiIcon icon="check" label={resolveLabel} small />
|
|
572
670
|
</TldrawUiButton>
|
|
573
671
|
)}
|
|
574
|
-
<
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
672
|
+
<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>
|
|
673
|
+
{(threadHref !== undefined || canDeleteThread) && (
|
|
674
|
+
<TldrawUiDropdownMenuGroup>
|
|
675
|
+
{/* A link is a read affordance: offered to anyone who can see the thread,
|
|
676
|
+
including a viewer who can't comment. `noClose` keeps the menu up so the
|
|
677
|
+
item can confirm the copy in place. */}
|
|
678
|
+
{threadHref !== undefined && (
|
|
679
|
+
<MenuItem
|
|
680
|
+
label={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}
|
|
681
|
+
noClose
|
|
682
|
+
onClick={copyThreadLink}
|
|
683
|
+
/>
|
|
684
|
+
)}
|
|
685
|
+
{canDeleteThread && (
|
|
686
|
+
<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />
|
|
687
|
+
)}
|
|
688
|
+
</TldrawUiDropdownMenuGroup>
|
|
689
|
+
)}
|
|
690
|
+
<TldrawUiDropdownMenuGroup>
|
|
691
|
+
<MenuItem
|
|
692
|
+
label={msg(messages.commentsClose)}
|
|
693
|
+
onClick={() => openThreadId.set(editor, null)}
|
|
694
|
+
/>
|
|
695
|
+
</TldrawUiDropdownMenuGroup>
|
|
696
|
+
</MoreOptionsMenu>
|
|
583
697
|
</>
|
|
584
698
|
)
|
|
585
699
|
|
|
@@ -600,6 +714,10 @@ export const ThreadView = memo(function ThreadView({
|
|
|
600
714
|
canReply
|
|
601
715
|
? {
|
|
602
716
|
author: me ?? UNKNOWN_COMMENT_AUTHOR,
|
|
717
|
+
leading: avatarRenderer(
|
|
718
|
+
options.components,
|
|
719
|
+
currentUserId
|
|
720
|
+
)?.(me ?? UNKNOWN_COMMENT_AUTHOR),
|
|
603
721
|
placeholder: msg(messages.commentsReplyPlaceholder),
|
|
604
722
|
sendLabel: msg(messages.commentsSend),
|
|
605
723
|
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
|
)
|