@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.
- package/commenting.css +280 -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-mutations.js +5 -0
- package/dist-cjs/canvas/comment-mutations.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 +12 -0
- package/dist-cjs/canvas/options.js.map +2 -2
- package/dist-cjs/canvas/pending-composer.js +139 -9
- 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 +134 -58
- package/dist-cjs/canvas/thread-view.js.map +2 -2
- package/dist-cjs/index.d.ts +46 -12
- 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-mutations.mjs +5 -0
- package/dist-esm/canvas/comment-mutations.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 +12 -0
- package/dist-esm/canvas/options.mjs.map +2 -2
- package/dist-esm/canvas/pending-composer.mjs +150 -11
- 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 +145 -60
- package/dist-esm/canvas/thread-view.mjs.map +2 -2
- package/dist-esm/index.d.mts +46 -12
- 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-mutations.test.ts +51 -0
- package/src/canvas/comment-mutations.ts +14 -0
- 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.test.ts +23 -1
- package/src/canvas/options.ts +41 -3
- package/src/canvas/pending-composer.tsx +190 -19
- 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 +192 -72
- 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
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
defineMessages,
|
|
10
10
|
} from 'tldraw'
|
|
11
11
|
import { type CommentingOptions, defaultCommentingOptions, getCommentingOptions } from './options'
|
|
12
|
-
import {
|
|
12
|
+
import { pendingComment, regionDraft } from './state'
|
|
13
13
|
import { commentTargetShapeAt, regionPinPoint, shapeAnchorAt } from './thread-state'
|
|
14
14
|
|
|
15
15
|
/** A comment being placed but not yet posted: where its composer sits and what it will anchor
|
|
@@ -54,8 +54,8 @@ export function regionBetween(a: VecLike, b: VecLike): BoxModel {
|
|
|
54
54
|
* release — like placing a sticky note — settling on a point, or on a shape when released over one.
|
|
55
55
|
* With region comments enabled, dragging past the threshold draws a region rectangle instead.
|
|
56
56
|
* Placement only opens a composer; the records are created when the comment is posted. The tool
|
|
57
|
-
* stays active
|
|
58
|
-
*
|
|
57
|
+
* stays active after a placement, so comments can be placed one after another. Escape closes an
|
|
58
|
+
* open composer first, then returns to the select tool.
|
|
59
59
|
* @public
|
|
60
60
|
*/
|
|
61
61
|
export class CommentTool extends StateNode {
|
|
@@ -94,27 +94,37 @@ export class CommentTool extends StateNode {
|
|
|
94
94
|
|
|
95
95
|
override onEnter() {
|
|
96
96
|
this.editor.setCursor({ type: 'comment', rotation: 0 })
|
|
97
|
-
// Placing comments is canvas-focused — the thread list gets out of the way while the tool is
|
|
98
|
-
// active. Reopened via its own control (a button), never by leaving the tool.
|
|
99
|
-
commentsSidebarOpen.set(this.editor, false)
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
override onExit() {
|
|
103
|
-
// Drop the hover hint painted while pointing at shapes (see CommentIdle)
|
|
104
|
-
// when the next tool takes over.
|
|
105
|
-
//
|
|
100
|
+
// Drop the hover hint painted while pointing at shapes (see CommentIdle) and any unfinished
|
|
101
|
+
// region draft. The cursor resets when the next tool takes over. An open composer outlives
|
|
102
|
+
// the tool.
|
|
106
103
|
this.editor.setHintingShapes([])
|
|
107
|
-
pendingComment.set(this.editor, null)
|
|
108
104
|
regionDraft.set(this.editor, null)
|
|
109
105
|
}
|
|
110
106
|
|
|
111
|
-
// Escape
|
|
107
|
+
// Escape (the editor dispatches `cancel`) steps back one level: an open composer closes and the
|
|
108
|
+
// tool stays; with none open, the tool returns to select. Mid-placement it also drops the
|
|
109
|
+
// composer that's following the pointer: this handler runs before the child state's, and
|
|
110
|
+
// leaving the tool skips the child's own cancel.
|
|
112
111
|
override onCancel() {
|
|
112
|
+
if (this.getCurrent()?.id === 'idle' && pendingComment.get(this.editor)) {
|
|
113
|
+
pendingComment.set(this.editor, null)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
if (this.getCurrent()?.id !== 'idle') pendingComment.set(this.editor, null)
|
|
113
117
|
this.editor.setCurrentTool('select')
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
/** The pending placement a release at `point` resolves to: anchored to the shape under it, or a
|
|
122
|
+
* bare point. Shared by the tool's click placement and the composer's drag handle. */
|
|
123
|
+
export function pendingCommentAt(
|
|
124
|
+
editor: Editor,
|
|
125
|
+
point: VecLike,
|
|
126
|
+
altKey = editor.inputs.getAltKey()
|
|
127
|
+
): PendingComment {
|
|
118
128
|
const hit = commentTargetShapeAt(editor, point)
|
|
119
129
|
const anchor: TLCommentAnchor = hit
|
|
120
130
|
? shapeAnchorAt(
|
|
@@ -124,7 +134,7 @@ function pendingCommentAt(editor: Editor, point: VecLike): PendingComment {
|
|
|
124
134
|
getCommentingOptions(editor).shouldBePrecise(editor, {
|
|
125
135
|
shapeId: hit.id,
|
|
126
136
|
point,
|
|
127
|
-
altKey
|
|
137
|
+
altKey,
|
|
128
138
|
})
|
|
129
139
|
)
|
|
130
140
|
: { type: 'point', x: point.x, y: point.y }
|
|
@@ -133,9 +143,9 @@ function pendingCommentAt(editor: Editor, point: VecLike): PendingComment {
|
|
|
133
143
|
|
|
134
144
|
/**
|
|
135
145
|
* Open the comment composer at a page point, anchored as a comment tool click there would be. Use
|
|
136
|
-
* it to start a comment from outside the tool, such as a context menu item.
|
|
137
|
-
*
|
|
138
|
-
*
|
|
146
|
+
* it to start a comment from outside the tool, such as a context menu item. It leaves the select
|
|
147
|
+
* tool active with the composer open. It doesn't check `canComment`: a
|
|
148
|
+
* viewer who can't comment sees the `ComposerFallback` slot instead.
|
|
139
149
|
*
|
|
140
150
|
* @example
|
|
141
151
|
* ```tsx
|
|
@@ -144,12 +154,15 @@ function pendingCommentAt(editor: Editor, point: VecLike): PendingComment {
|
|
|
144
154
|
* @public
|
|
145
155
|
*/
|
|
146
156
|
export function startCommentAt(editor: Editor, point: VecLike) {
|
|
147
|
-
editor.setCurrentTool('
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
editor.setCurrentTool('select')
|
|
158
|
+
pendingComment.set(editor, pendingCommentAt(editor, point))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** End a placement: the composer stays open at `pending` and the tool goes back to idle, ready
|
|
162
|
+
* for the next one. */
|
|
163
|
+
function finishPlacement(state: StateNode, pending: PendingComment) {
|
|
164
|
+
pendingComment.set(state.editor, pending)
|
|
165
|
+
state.parent.transition('idle')
|
|
153
166
|
}
|
|
154
167
|
|
|
155
168
|
/** Hint the shape a comment placed at the pointer would anchor to, using the same hit-test as the
|
|
@@ -164,11 +177,10 @@ class CommentIdle extends StateNode {
|
|
|
164
177
|
static override id = 'idle'
|
|
165
178
|
|
|
166
179
|
override onEnter() {
|
|
167
|
-
// Back to hovering: restore the pin cursor (a
|
|
180
|
+
// Back to hovering: restore the pin cursor (a cancelled placement may have changed it).
|
|
168
181
|
this.editor.setCursor({ type: 'comment', rotation: 0 })
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// never reach the canvas. Point placements keep the hint: it previews the next click.
|
|
182
|
+
// After a region placement its composer is still open here. A shape outline under its pin
|
|
183
|
+
// corner would imply a shape anchor the region never uses.
|
|
172
184
|
if (pendingComment.get(this.editor)?.anchor.type === 'region') {
|
|
173
185
|
this.editor.setHintingShapes([])
|
|
174
186
|
} else {
|
|
@@ -181,12 +193,6 @@ class CommentIdle extends StateNode {
|
|
|
181
193
|
}
|
|
182
194
|
|
|
183
195
|
override onPointerDown() {
|
|
184
|
-
// A press away from an open composer cancels the placement rather than moving it. The
|
|
185
|
-
// tool's onExit drops the draft composer; its text survives in the draft store.
|
|
186
|
-
if (pendingComment.get(this.editor)) {
|
|
187
|
-
this.editor.setCurrentTool('select')
|
|
188
|
-
return
|
|
189
|
-
}
|
|
190
196
|
this.parent.transition('pointing')
|
|
191
197
|
}
|
|
192
198
|
}
|
|
@@ -199,8 +205,8 @@ class CommentPointing extends StateNode {
|
|
|
199
205
|
// on release), and let it trail the pointer while dragging — like placing a sticky note. The
|
|
200
206
|
// anchor is a bare point for now; it's resolved (shape or point) on pointer up.
|
|
201
207
|
const { editor } = this
|
|
202
|
-
//
|
|
203
|
-
//
|
|
208
|
+
// The composer opens under the pointer and stands in for it, so the cursor hides; it becomes
|
|
209
|
+
// `move` once a drag starts.
|
|
204
210
|
editor.setCursor({ type: 'none', rotation: 0 })
|
|
205
211
|
const point = editor.inputs.getCurrentPagePoint()
|
|
206
212
|
pendingComment.set(editor, {
|
|
@@ -219,6 +225,9 @@ class CommentPointing extends StateNode {
|
|
|
219
225
|
}
|
|
220
226
|
// Otherwise the composer trails the pointer — keep hinting the shape a release here would
|
|
221
227
|
// anchor to, like the idle hover does.
|
|
228
|
+
if (editor.inputs.getIsDragging() && editor.getInstanceState().cursor.type !== 'move') {
|
|
229
|
+
editor.setCursor({ type: 'move', rotation: 0 })
|
|
230
|
+
}
|
|
222
231
|
updateAnchorHint(editor)
|
|
223
232
|
const point = editor.inputs.getCurrentPagePoint()
|
|
224
233
|
pendingComment.update(editor, (p) => (p ? { ...p, point: { x: point.x, y: point.y } } : p))
|
|
@@ -228,25 +237,18 @@ class CommentPointing extends StateNode {
|
|
|
228
237
|
override onPointerUp() {
|
|
229
238
|
const { editor } = this
|
|
230
239
|
const point = editor.inputs.getCurrentPagePoint()
|
|
231
|
-
|
|
232
|
-
// Stay in the tool while the composer is open — the interaction isn't over until the
|
|
233
|
-
// comment is posted or dismissed, and staying keeps the surrounding UI (style panel,
|
|
234
|
-
// sidebar) from churning mid-placement.
|
|
235
|
-
this.parent.transition('idle')
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
override onCancel() {
|
|
239
|
-
this.cancel()
|
|
240
|
+
finishPlacement(this, pendingCommentAt(editor, point))
|
|
240
241
|
}
|
|
241
242
|
|
|
242
243
|
override onInterrupt() {
|
|
243
244
|
this.cancel()
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
// Abandon the follow composer if placement is interrupted (
|
|
247
|
-
// tool's
|
|
247
|
+
// Abandon the follow composer if placement is interrupted (focus loss, etc.). Its text survives
|
|
248
|
+
// in the draft store. Escape is the tool's own onCancel, which runs first.
|
|
248
249
|
private cancel() {
|
|
249
|
-
this.editor
|
|
250
|
+
pendingComment.set(this.editor, null)
|
|
251
|
+
this.parent.transition('idle')
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
254
|
|
|
@@ -276,16 +278,10 @@ class CommentDragging extends StateNode {
|
|
|
276
278
|
// The pin lives on the corner the drag released on — drag up-left, pin top-left.
|
|
277
279
|
const pin = { x: current.x >= origin.x ? 1 : 0, y: current.y >= origin.y ? 1 : 0 }
|
|
278
280
|
regionDraft.set(editor, null)
|
|
279
|
-
|
|
281
|
+
finishPlacement(this, {
|
|
280
282
|
anchor: { type: 'region', ...region, pinX: pin.x, pinY: pin.y },
|
|
281
283
|
point: regionPinPoint(region, pin),
|
|
282
284
|
})
|
|
283
|
-
// Same as the point placement: the tool stays active while the composer is open.
|
|
284
|
-
this.parent.transition('idle')
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
override onCancel() {
|
|
288
|
-
this.cancel()
|
|
289
285
|
}
|
|
290
286
|
|
|
291
287
|
override onInterrupt() {
|
|
@@ -300,9 +296,9 @@ class CommentDragging extends StateNode {
|
|
|
300
296
|
)
|
|
301
297
|
}
|
|
302
298
|
|
|
303
|
-
// The tool's onExit drops the region draft.
|
|
304
299
|
private cancel() {
|
|
305
|
-
this.editor
|
|
300
|
+
regionDraft.set(this.editor, null)
|
|
301
|
+
this.parent.transition('idle')
|
|
306
302
|
}
|
|
307
303
|
}
|
|
308
304
|
|
|
@@ -7,20 +7,22 @@ import {
|
|
|
7
7
|
TldrawUiMenuCheckboxItem,
|
|
8
8
|
TldrawUiMenuContextProvider,
|
|
9
9
|
TldrawUiMenuGroup,
|
|
10
|
+
TldrawUiMenuItem,
|
|
10
11
|
useEditor,
|
|
11
12
|
useTranslation,
|
|
12
13
|
useValue,
|
|
13
14
|
} from 'tldraw'
|
|
14
15
|
import { MoreMenuIcon } from '../ui/icons'
|
|
15
16
|
import { SidebarFilters } from './sidebar-filters'
|
|
16
|
-
import { sidebarFilters } from './state'
|
|
17
|
+
import { commentsSidebarOpen, sidebarFilters } from './state'
|
|
17
18
|
|
|
18
19
|
const messages = defineMessages({
|
|
20
|
+
commentsClose: { id: 'comments.close', defaultMessage: 'Close' },
|
|
19
21
|
commentsFilter: { id: 'comments.filter', defaultMessage: 'Filter comments' },
|
|
20
22
|
commentsOnlyMyComments: { id: 'comments.only-my-comments', defaultMessage: 'Only my comments' },
|
|
21
23
|
commentsOnlyUnread: { id: 'comments.only-unread', defaultMessage: 'Only unread' },
|
|
22
24
|
commentsShowAllPages: { id: 'comments.show-all-pages', defaultMessage: 'Show all pages' },
|
|
23
|
-
commentsShowResolved: { id: 'comments.show-resolved', defaultMessage: 'Show resolved
|
|
25
|
+
commentsShowResolved: { id: 'comments.show-resolved', defaultMessage: 'Show resolved' },
|
|
24
26
|
})
|
|
25
27
|
|
|
26
28
|
/** @public */
|
|
@@ -51,17 +53,16 @@ export function CommentsFilterMenu({
|
|
|
51
53
|
type="icon"
|
|
52
54
|
tooltip={msg(messages.commentsFilter)}
|
|
53
55
|
title={msg(messages.commentsFilter)}
|
|
54
|
-
className="tlui-cmt-
|
|
56
|
+
className="tlui-cmt-icon-btn"
|
|
55
57
|
>
|
|
56
58
|
<MoreMenuIcon />
|
|
57
59
|
</TldrawUiButton>
|
|
58
60
|
</TldrawUiDropdownMenuTrigger>
|
|
59
|
-
|
|
60
|
-
the extra padding would set this menu apart from the canvas menus it should match. */}
|
|
61
|
-
<TldrawUiDropdownMenuContent side="bottom" align="end" alignOffset={0}>
|
|
61
|
+
<TldrawUiDropdownMenuContent side="bottom" align="end" alignOffset={-6} sideOffset={0}>
|
|
62
62
|
<TldrawUiMenuContextProvider type="menu" sourceId="menu">
|
|
63
63
|
<TldrawUiMenuGroup id="comments-filter">
|
|
64
64
|
<TldrawUiMenuCheckboxItem
|
|
65
|
+
toggle
|
|
65
66
|
id="show-all-pages"
|
|
66
67
|
label={messages.commentsShowAllPages.id}
|
|
67
68
|
checked={!filters.onlyCurrentPage}
|
|
@@ -69,6 +70,7 @@ export function CommentsFilterMenu({
|
|
|
69
70
|
/>
|
|
70
71
|
{canFilterByAuthor && (
|
|
71
72
|
<TldrawUiMenuCheckboxItem
|
|
73
|
+
toggle
|
|
72
74
|
id="only-my-comments"
|
|
73
75
|
label={messages.commentsOnlyMyComments.id}
|
|
74
76
|
checked={filters.onlyMine}
|
|
@@ -77,6 +79,7 @@ export function CommentsFilterMenu({
|
|
|
77
79
|
)}
|
|
78
80
|
{canFilterByUnread && (
|
|
79
81
|
<TldrawUiMenuCheckboxItem
|
|
82
|
+
toggle
|
|
80
83
|
id="only-unread"
|
|
81
84
|
label={messages.commentsOnlyUnread.id}
|
|
82
85
|
checked={filters.onlyUnread}
|
|
@@ -84,12 +87,22 @@ export function CommentsFilterMenu({
|
|
|
84
87
|
/>
|
|
85
88
|
)}
|
|
86
89
|
<TldrawUiMenuCheckboxItem
|
|
90
|
+
toggle
|
|
87
91
|
id="show-resolved"
|
|
88
92
|
label={messages.commentsShowResolved.id}
|
|
89
93
|
checked={filters.showResolved}
|
|
90
94
|
onSelect={() => toggle('showResolved')}
|
|
91
95
|
/>
|
|
92
96
|
</TldrawUiMenuGroup>
|
|
97
|
+
<TldrawUiMenuGroup id="comments-close">
|
|
98
|
+
<TldrawUiMenuItem
|
|
99
|
+
id="close-comments"
|
|
100
|
+
label={messages.commentsClose.id}
|
|
101
|
+
onSelect={() => {
|
|
102
|
+
commentsSidebarOpen.set(editor, false)
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
</TldrawUiMenuGroup>
|
|
93
106
|
</TldrawUiMenuContextProvider>
|
|
94
107
|
</TldrawUiDropdownMenuContent>
|
|
95
108
|
</TldrawUiDropdownMenuRoot>
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineMessages,
|
|
3
3
|
TldrawUiButton,
|
|
4
|
+
TldrawUiButtonLabel,
|
|
4
5
|
TldrawUiDropdownMenuContent,
|
|
5
6
|
TldrawUiDropdownMenuGroup,
|
|
6
7
|
TldrawUiDropdownMenuItem,
|
|
7
8
|
TldrawUiDropdownMenuRoot,
|
|
8
9
|
TldrawUiDropdownMenuTrigger,
|
|
9
10
|
TldrawUiIcon,
|
|
11
|
+
TldrawUiKbd,
|
|
10
12
|
useEditor,
|
|
11
13
|
useTranslation,
|
|
12
14
|
useValue,
|
|
@@ -19,8 +21,8 @@ const messages = defineMessages({
|
|
|
19
21
|
commentsShow: { id: 'comments.show', defaultMessage: 'Show comments' },
|
|
20
22
|
})
|
|
21
23
|
|
|
22
|
-
//
|
|
23
|
-
const HIDE_SHORTCUT = '
|
|
24
|
+
// tldraw's kbd notation (`!` = shift), rendered per platform by TldrawUiKbd.
|
|
25
|
+
const HIDE_SHORTCUT = '!c'
|
|
24
26
|
|
|
25
27
|
/** The overflow (⋯) dropdown in the sidebar header. For now it holds the hide/show-comments
|
|
26
28
|
* toggle; it's the home for later comment-wide controls (notifications, mark all as read).
|
|
@@ -37,28 +39,20 @@ export function CommentsOverflowMenu() {
|
|
|
37
39
|
type="icon"
|
|
38
40
|
tooltip={msg(messages.commentsMoreOptions)}
|
|
39
41
|
title={msg(messages.commentsMoreOptions)}
|
|
40
|
-
className="tlui-cmt-
|
|
42
|
+
className="tlui-cmt-icon-btn"
|
|
41
43
|
>
|
|
42
44
|
<TldrawUiIcon icon="dots-vertical" label={msg(messages.commentsMoreOptions)} small />
|
|
43
45
|
</TldrawUiButton>
|
|
44
46
|
</TldrawUiDropdownMenuTrigger>
|
|
45
|
-
<TldrawUiDropdownMenuContent
|
|
46
|
-
className="tlui-cmt-menu"
|
|
47
|
-
side="bottom"
|
|
48
|
-
align="end"
|
|
49
|
-
alignOffset={0}
|
|
50
|
-
sideOffset={4}
|
|
51
|
-
>
|
|
47
|
+
<TldrawUiDropdownMenuContent side="bottom" align="end" alignOffset={0} sideOffset={0}>
|
|
52
48
|
<TldrawUiDropdownMenuGroup>
|
|
53
49
|
<TldrawUiDropdownMenuItem>
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<span className="tlui-cmt-menu-item__shortcut">{HIDE_SHORTCUT}</span>
|
|
61
|
-
</button>
|
|
50
|
+
<TldrawUiButton type="menu" onClick={() => toggleCommentsHidden(editor)}>
|
|
51
|
+
<TldrawUiButtonLabel>
|
|
52
|
+
{hidden ? msg(messages.commentsShow) : msg(messages.commentsHide)}
|
|
53
|
+
</TldrawUiButtonLabel>
|
|
54
|
+
<TldrawUiKbd>{HIDE_SHORTCUT}</TldrawUiKbd>
|
|
55
|
+
</TldrawUiButton>
|
|
62
56
|
</TldrawUiDropdownMenuItem>
|
|
63
57
|
</TldrawUiDropdownMenuGroup>
|
|
64
58
|
</TldrawUiDropdownMenuContent>
|
|
@@ -86,8 +86,8 @@ function CanvasCommentsLayer(props: CommentingContext) {
|
|
|
86
86
|
const canComment = useCanComment(props.currentUserId)
|
|
87
87
|
// Nothing renders a pending comment when composing is blocked and there's no fallback slot, and
|
|
88
88
|
// the dismiss handlers live inside PendingComposer — so clear the atom rather than strand it,
|
|
89
|
-
// and leave the tool too: it
|
|
90
|
-
//
|
|
89
|
+
// and leave the tool too: it stays active after a placement, so every click would be a
|
|
90
|
+
// silently swallowed one.
|
|
91
91
|
const canRenderComposer = canComment || options.components.ComposerFallback != null
|
|
92
92
|
const showPendingComposer = pending != null && canRenderComposer
|
|
93
93
|
useEffect(() => {
|
|
@@ -223,6 +223,9 @@ function CanvasCommentsLayer(props: CommentingContext) {
|
|
|
223
223
|
openThreadId.set(editor, null)
|
|
224
224
|
e.preventDefault()
|
|
225
225
|
e.stopPropagation()
|
|
226
|
+
// Closing from inside the thread would leave focus on the page, out of reach of the next
|
|
227
|
+
// Escape (the editor listens on its container).
|
|
228
|
+
if (target && target.closest('.tlui-cmt-thread')) editor.getContainer().focus()
|
|
226
229
|
}
|
|
227
230
|
document.addEventListener('keydown', onKeyDown, true)
|
|
228
231
|
return () => document.removeEventListener('keydown', onKeyDown, true)
|
|
@@ -2,6 +2,7 @@ import { ReactNode, useCallback } from 'react'
|
|
|
2
2
|
import {
|
|
3
3
|
defineMessages,
|
|
4
4
|
EditorPortal,
|
|
5
|
+
TLComment,
|
|
5
6
|
TLCommentThread,
|
|
6
7
|
useEditor,
|
|
7
8
|
useTranslation,
|
|
@@ -16,8 +17,11 @@ import { getCommentsByThread, useCommentThreads } from './hooks'
|
|
|
16
17
|
import { useCommentingEnabled } from './license'
|
|
17
18
|
import { useCommentingOptions } from './options'
|
|
18
19
|
import { richTextToPlaintext } from './rich-text'
|
|
19
|
-
import { commentsSidebarOpen, openThreadId, sidebarFilters } from './state'
|
|
20
|
+
import { commentsHidden, commentsSidebarOpen, openThreadId, sidebarFilters } from './state'
|
|
20
21
|
import { focusThread } from './thread-state'
|
|
22
|
+
import { avatarRenderer } from './thread-view'
|
|
23
|
+
|
|
24
|
+
const EMPTY_COMMENTS: TLComment[] = []
|
|
21
25
|
|
|
22
26
|
const messages = defineMessages({
|
|
23
27
|
commentsEmpty: { id: 'comments.empty', defaultMessage: 'No comments on this page yet.' },
|
|
@@ -127,6 +131,7 @@ export function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {
|
|
|
127
131
|
count: threadComments.length,
|
|
128
132
|
selected: openId === thread.id,
|
|
129
133
|
href: getThreadHref?.(thread.id),
|
|
134
|
+
renderAvatar: avatarRenderer(options.components, thread.createdBy),
|
|
130
135
|
},
|
|
131
136
|
lastActivity: (last ?? thread).createdAt,
|
|
132
137
|
}
|
|
@@ -136,11 +141,15 @@ export function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {
|
|
|
136
141
|
|
|
137
142
|
const focus = (id: string) => {
|
|
138
143
|
const thread = threads.find((t) => t.id === id)
|
|
139
|
-
if (thread)
|
|
144
|
+
if (!thread) return
|
|
145
|
+
// The thread popover lives on the layer that hiding withholds, so it would open invisibly.
|
|
146
|
+
commentsHidden.set(editor, false)
|
|
147
|
+
focusThread(editor, thread)
|
|
140
148
|
}
|
|
141
149
|
|
|
142
|
-
// The `ThreadRow` component slot overrides the built-in row. It gets the thread record
|
|
143
|
-
// the summarized row, so host state on `
|
|
150
|
+
// The `ThreadRow` component slot overrides the built-in row. It gets the thread record and its
|
|
151
|
+
// comments alongside the summarized row, so host state on their `meta` is in reach without each
|
|
152
|
+
// row subscribing to the store again. Indexed
|
|
144
153
|
// once rather than scanned per row — this runs for every row on every render of the panel.
|
|
145
154
|
const ThreadRow = options.components.ThreadRow
|
|
146
155
|
const renderItem = ThreadRow
|
|
@@ -154,7 +163,13 @@ export function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {
|
|
|
154
163
|
// Can't happen — the items are built from these threads — but a row with no thread has
|
|
155
164
|
// nothing to render, and the slot's contract says the record is there.
|
|
156
165
|
if (!thread) return null
|
|
157
|
-
return
|
|
166
|
+
return (
|
|
167
|
+
<ThreadRow
|
|
168
|
+
{...rowProps}
|
|
169
|
+
thread={thread}
|
|
170
|
+
comments={byThread.get(thread.id) ?? EMPTY_COMMENTS}
|
|
171
|
+
/>
|
|
172
|
+
)
|
|
158
173
|
}
|
|
159
174
|
})()
|
|
160
175
|
: undefined
|
|
@@ -21,7 +21,7 @@ export function CommentsVisibilityToggle() {
|
|
|
21
21
|
type="icon"
|
|
22
22
|
tooltip={label}
|
|
23
23
|
title={label}
|
|
24
|
-
className="tlui-cmt-
|
|
24
|
+
className="tlui-cmt-icon-btn"
|
|
25
25
|
onClick={() => toggleCommentsHidden(editor)}
|
|
26
26
|
>
|
|
27
27
|
{hidden ? <EyeClosedIcon /> : <EyeOpenIcon />}
|
|
@@ -61,10 +61,11 @@ describe('CommentTool.configure', () => {
|
|
|
61
61
|
|
|
62
62
|
// A minimal editor stub: getCommentingOptions reads the comment tool's `options` off
|
|
63
63
|
// getStateDescendant, and commitCommentMutation forwards to run().
|
|
64
|
-
function stubEditor(options: CommentingOptions) {
|
|
64
|
+
function stubEditor(options: CommentingOptions, granted?: Set<string>) {
|
|
65
65
|
const runCalls: Array<{ history: unknown }> = []
|
|
66
66
|
const editor = {
|
|
67
67
|
getStateDescendant: () => ({ options }),
|
|
68
|
+
can: (permission: string) => !granted || granted.has(permission),
|
|
68
69
|
run: (fn: () => void, opts: { history: unknown }) => {
|
|
69
70
|
runCalls.push(opts)
|
|
70
71
|
fn()
|
|
@@ -250,6 +251,27 @@ describe('getCanModifyComment', () => {
|
|
|
250
251
|
})
|
|
251
252
|
})
|
|
252
253
|
|
|
254
|
+
describe('permissions', () => {
|
|
255
|
+
it('denies commenting without tl:comment:create, whatever canComment says', () => {
|
|
256
|
+
const options = { ...defaultCommentingOptions, canComment: () => true }
|
|
257
|
+
expect(getCanComment(stubEditor(options, new Set()).editor, 'alice')).toBe(false)
|
|
258
|
+
expect(getCanComment(stubEditor(options, new Set(['tl:comment:create'])).editor, 'alice')).toBe(
|
|
259
|
+
true
|
|
260
|
+
)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('asks the permission that matches each write, before the ownership rule', () => {
|
|
264
|
+
const comment = makeComment('alice')
|
|
265
|
+
const thread = makeThread('alice')
|
|
266
|
+
const { editor } = stubEditor(defaultCommentingOptions, new Set(['tl:comment:edit']))
|
|
267
|
+
expect(getCanModifyComment(editor, 'alice', { action: 'edit-comment', comment })).toBe(true)
|
|
268
|
+
expect(getCanModifyComment(editor, 'alice', { action: 'delete-comment', comment })).toBe(false)
|
|
269
|
+
expect(getCanModifyComment(editor, 'alice', { action: 'delete-thread', thread })).toBe(false)
|
|
270
|
+
// a permission does not give the affordance on someone else's comment
|
|
271
|
+
expect(getCanModifyComment(editor, 'bob', { action: 'edit-comment', comment })).toBe(false)
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
253
275
|
describe('commitCommentMutation', () => {
|
|
254
276
|
it('uses options.history for a mutation and returns the callback result', () => {
|
|
255
277
|
const { editor, runCalls } = stubEditor({
|
package/src/canvas/options.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AvatarProps } from '@tldraw/mentions'
|
|
1
2
|
import { useMemo, type ComponentType } from 'react'
|
|
2
3
|
import {
|
|
3
4
|
type Editor,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
useEditor,
|
|
10
11
|
useValue,
|
|
11
12
|
} from 'tldraw'
|
|
13
|
+
import { type BylineProps } from '../ui/byline'
|
|
12
14
|
import { type CommentListItemRenderProps } from '../ui/comments-list'
|
|
13
15
|
import { isAllowedReactionEmoji, type EmojiPickerProps } from '../ui/emoji-picker'
|
|
14
16
|
import { type ReactionTooltipProps } from '../ui/reaction'
|
|
@@ -60,6 +62,20 @@ export type CommentModificationContext = {
|
|
|
60
62
|
export interface CommentingComponents {
|
|
61
63
|
/** A comment's body. Replaces the default rich-text `<CommentBody>`. */
|
|
62
64
|
CommentBody?: ComponentType<{ comment: TLComment }>
|
|
65
|
+
/**
|
|
66
|
+
* A comment's byline: the author's avatar and name, the time, and the edited marker. Replaces the
|
|
67
|
+
* default `<Byline>`, which is exported — so a byline that only changes how the author is shown
|
|
68
|
+
* (a badge read from `comment.meta`, say) can spread these props into it with a different
|
|
69
|
+
* `author`. `author` is what `resolveAuthor` returned for the comment's `authorId`.
|
|
70
|
+
*/
|
|
71
|
+
CommentByline?: ComponentType<BylineProps & { comment: TLComment }>
|
|
72
|
+
/**
|
|
73
|
+
* An author's avatar, wherever the layer draws one: comment bylines, sidebar rows, the composers,
|
|
74
|
+
* and the default pin content. Replaces the default `<Avatar>`, which is exported — so an avatar
|
|
75
|
+
* that only adds something (a presence ring, a badge) can spread these props into it. `authorId`
|
|
76
|
+
* is the id `author` was resolved from, or `null` in a composer with no signed-in user.
|
|
77
|
+
*/
|
|
78
|
+
Avatar?: ComponentType<AvatarProps & { authorId: string | null }>
|
|
63
79
|
/** A pin's inner content. Replaces the author-initial default. */
|
|
64
80
|
PinContent?: ComponentType<{ thread: TLCommentThread; comments: TLComment[] }>
|
|
65
81
|
/** A sidebar row's preview. Replaces the plaintext default. */
|
|
@@ -67,9 +83,12 @@ export interface CommentingComponents {
|
|
|
67
83
|
/**
|
|
68
84
|
* A whole sidebar row. Replaces the default `<CommentListItem>`, which is exported — so a row
|
|
69
85
|
* that only adds an unread dot or a status chip can spread these props into it. Use
|
|
70
|
-
* `ThreadPreview` instead when only the preview text is changing.
|
|
86
|
+
* `ThreadPreview` instead when only the preview text is changing. `comments` are the thread's
|
|
87
|
+
* live comments, oldest first.
|
|
71
88
|
*/
|
|
72
|
-
ThreadRow?: ComponentType<
|
|
89
|
+
ThreadRow?: ComponentType<
|
|
90
|
+
CommentListItemRenderProps & { thread: TLCommentThread; comments: TLComment[] }
|
|
91
|
+
>
|
|
73
92
|
/**
|
|
74
93
|
* Extra controls in an open thread's header, added ahead of the built-in resolve and dismiss
|
|
75
94
|
* buttons rather than replacing them. "Copy link" is already built in whenever the host supplies
|
|
@@ -159,7 +178,8 @@ export interface CommentingOptions {
|
|
|
159
178
|
// Permissions
|
|
160
179
|
/**
|
|
161
180
|
* Whether the viewer may participate in commenting: composing, editing, deleting, resolving, and
|
|
162
|
-
* moving pins.
|
|
181
|
+
* moving pins. `editor.can('tl:comment:create')` is asked first, and a `false` there wins. When
|
|
182
|
+
* false, {@link CommentingComponents.ComposerFallback} renders in the
|
|
163
183
|
* composer's place and action affordances are hidden. Unset, participation is allowed exactly
|
|
164
184
|
* when `currentUserId` is set.
|
|
165
185
|
*
|
|
@@ -179,6 +199,11 @@ export interface CommentingOptions {
|
|
|
179
199
|
* anyone's comment) or to narrow it (no edits after an hour). Where it returns false the
|
|
180
200
|
* affordance isn't rendered.
|
|
181
201
|
*
|
|
202
|
+
* Checked after `editor.can` with the matching permission (`tl:comment:edit`,
|
|
203
|
+
* `tl:comment:delete`, or `tl:comment-thread:delete`), and a `false` there wins. So a permission
|
|
204
|
+
* grants no affordance on its own: an admin with `tl:comment:delete` still needs this to say yes
|
|
205
|
+
* for someone else's comment.
|
|
206
|
+
*
|
|
182
207
|
* Checked after {@link CommentingOptions.canComment}, which gates commenting as a whole: a
|
|
183
208
|
* viewer who may not participate gets no action affordances at all, whatever this returns.
|
|
184
209
|
*
|
|
@@ -281,6 +306,7 @@ function permits(option: string, check: () => boolean): boolean {
|
|
|
281
306
|
* @public
|
|
282
307
|
*/
|
|
283
308
|
export function getCanComment(editor: Editor, currentUserId: string | null | undefined): boolean {
|
|
309
|
+
if (!editor.can('tl:comment:create')) return false
|
|
284
310
|
const { canComment } = getCommentingOptions(editor)
|
|
285
311
|
if (!canComment) return currentUserId != null
|
|
286
312
|
return permits('canComment', () => canComment({ editor, currentUserId: currentUserId ?? null }))
|
|
@@ -336,6 +362,7 @@ export function getCanModifyComment(
|
|
|
336
362
|
currentUserId: string | null | undefined,
|
|
337
363
|
modification: CommentModification
|
|
338
364
|
): boolean {
|
|
365
|
+
if (!canModification(editor, modification)) return false
|
|
339
366
|
const { canModifyComment } = getCommentingOptions(editor)
|
|
340
367
|
const ctx: CommentModificationContext = {
|
|
341
368
|
editor,
|
|
@@ -346,6 +373,17 @@ export function getCanModifyComment(
|
|
|
346
373
|
return permits('canModifyComment', () => canModifyComment(ctx))
|
|
347
374
|
}
|
|
348
375
|
|
|
376
|
+
function canModification(editor: Editor, modification: CommentModification): boolean {
|
|
377
|
+
switch (modification.action) {
|
|
378
|
+
case 'edit-comment':
|
|
379
|
+
return editor.can('tl:comment:edit', { comment: modification.comment })
|
|
380
|
+
case 'delete-comment':
|
|
381
|
+
return editor.can('tl:comment:delete', { comment: modification.comment })
|
|
382
|
+
case 'delete-thread':
|
|
383
|
+
return editor.can('tl:comment-thread:delete', { thread: modification.thread })
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
349
387
|
/**
|
|
350
388
|
* Reactive React hook for {@link getCanModifyComment}: a `canModifyComment` callback that reads
|
|
351
389
|
* signals re-evaluates when they change.
|