@tldraw/commenting 5.7.0-next.0ef3ff64787a → 5.7.0-next.1768973fd1a0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/commenting.css +277 -275
  2. package/dist-cjs/canvas/canvas-events.js +25 -1
  3. package/dist-cjs/canvas/canvas-events.js.map +2 -2
  4. package/dist-cjs/canvas/comment-tool.js +29 -28
  5. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  6. package/dist-cjs/canvas/comments-filter-menu.js +55 -38
  7. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  8. package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
  9. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  10. package/dist-cjs/canvas/comments-overlay.js +1 -0
  11. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  12. package/dist-cjs/canvas/comments-sidebar.js +15 -3
  13. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  14. package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
  15. package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
  16. package/dist-cjs/canvas/options.js.map +2 -2
  17. package/dist-cjs/canvas/pending-composer.js +133 -8
  18. package/dist-cjs/canvas/pending-composer.js.map +2 -2
  19. package/dist-cjs/canvas/region-box.js +150 -35
  20. package/dist-cjs/canvas/region-box.js.map +3 -3
  21. package/dist-cjs/canvas/thread-pin.js +20 -4
  22. package/dist-cjs/canvas/thread-pin.js.map +2 -2
  23. package/dist-cjs/canvas/thread-view.js +130 -57
  24. package/dist-cjs/canvas/thread-view.js.map +2 -2
  25. package/dist-cjs/index.d.ts +39 -11
  26. package/dist-cjs/index.js +1 -1
  27. package/dist-cjs/ui/byline.js +2 -2
  28. package/dist-cjs/ui/byline.js.map +2 -2
  29. package/dist-cjs/ui/comment-card.js +3 -1
  30. package/dist-cjs/ui/comment-card.js.map +2 -2
  31. package/dist-cjs/ui/comment-extensions.js +4 -1
  32. package/dist-cjs/ui/comment-extensions.js.map +2 -2
  33. package/dist-cjs/ui/comments-list.js +6 -7
  34. package/dist-cjs/ui/comments-list.js.map +2 -2
  35. package/dist-cjs/ui/icons.js +4 -4
  36. package/dist-cjs/ui/icons.js.map +2 -2
  37. package/dist-cjs/ui/reaction-picker.js +2 -2
  38. package/dist-cjs/ui/reaction-picker.js.map +1 -1
  39. package/dist-cjs/ui/send-button.js.map +1 -1
  40. package/dist-esm/canvas/canvas-events.mjs +25 -1
  41. package/dist-esm/canvas/canvas-events.mjs.map +2 -2
  42. package/dist-esm/canvas/comment-tool.mjs +30 -29
  43. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  44. package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
  45. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  46. package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
  47. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  48. package/dist-esm/canvas/comments-overlay.mjs +1 -0
  49. package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
  50. package/dist-esm/canvas/comments-sidebar.mjs +16 -4
  51. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  52. package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
  53. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
  54. package/dist-esm/canvas/options.mjs.map +2 -2
  55. package/dist-esm/canvas/pending-composer.mjs +143 -9
  56. package/dist-esm/canvas/pending-composer.mjs.map +2 -2
  57. package/dist-esm/canvas/region-box.mjs +161 -38
  58. package/dist-esm/canvas/region-box.mjs.map +3 -3
  59. package/dist-esm/canvas/thread-pin.mjs +22 -6
  60. package/dist-esm/canvas/thread-pin.mjs.map +2 -2
  61. package/dist-esm/canvas/thread-view.mjs +140 -58
  62. package/dist-esm/canvas/thread-view.mjs.map +2 -2
  63. package/dist-esm/index.d.mts +39 -11
  64. package/dist-esm/index.mjs +1 -1
  65. package/dist-esm/ui/byline.mjs +2 -2
  66. package/dist-esm/ui/byline.mjs.map +2 -2
  67. package/dist-esm/ui/comment-card.mjs +3 -1
  68. package/dist-esm/ui/comment-card.mjs.map +2 -2
  69. package/dist-esm/ui/comment-extensions.mjs +11 -2
  70. package/dist-esm/ui/comment-extensions.mjs.map +2 -2
  71. package/dist-esm/ui/comments-list.mjs +6 -7
  72. package/dist-esm/ui/comments-list.mjs.map +2 -2
  73. package/dist-esm/ui/icons.mjs +4 -4
  74. package/dist-esm/ui/icons.mjs.map +2 -2
  75. package/dist-esm/ui/reaction-picker.mjs +2 -2
  76. package/dist-esm/ui/reaction-picker.mjs.map +1 -1
  77. package/dist-esm/ui/send-button.mjs.map +1 -1
  78. package/package.json +5 -5
  79. package/src/canvas/canvas-events.ts +39 -2
  80. package/src/canvas/canvas.css +73 -38
  81. package/src/canvas/comment-render.test.ts +8 -1
  82. package/src/canvas/comment-tool.test.ts +34 -44
  83. package/src/canvas/comment-tool.tsx +51 -55
  84. package/src/canvas/comments-filter-menu.tsx +19 -6
  85. package/src/canvas/comments-overflow-menu.tsx +12 -18
  86. package/src/canvas/comments-overlay.tsx +5 -2
  87. package/src/canvas/comments-sidebar.tsx +20 -5
  88. package/src/canvas/comments-visibility-toggle.tsx +1 -1
  89. package/src/canvas/options.ts +21 -2
  90. package/src/canvas/pending-composer.tsx +182 -17
  91. package/src/canvas/region-box.tsx +192 -42
  92. package/src/canvas/thread-pin.tsx +28 -6
  93. package/src/canvas/thread-view.test.ts +39 -0
  94. package/src/canvas/thread-view.tsx +185 -70
  95. package/src/ui/byline.tsx +5 -2
  96. package/src/ui/comment-card.tsx +7 -1
  97. package/src/ui/comment-extensions.ts +18 -5
  98. package/src/ui/comments-list.tsx +23 -17
  99. package/src/ui/comments.css +175 -201
  100. package/src/ui/icons.tsx +5 -5
  101. package/src/ui/reaction-picker.tsx +2 -2
  102. package/src/ui/send-button.tsx +2 -2
@@ -61,10 +61,6 @@
61
61
  outline: 2px solid var(--tl-color-selected);
62
62
  outline-offset: 2px;
63
63
  }
64
- /* Focus should read like hover, so the pin lifts the same way when tabbed to. */
65
- .tlui-cmt-canvas-pin__marker:focus-visible .tlui-cmt-marker {
66
- transform: scale(var(--tlui-cmt-marker-hover-scale));
67
- }
68
64
 
69
65
  .tlui-cmt-cluster-fade {
70
66
  opacity: 1;
@@ -99,6 +95,10 @@
99
95
  .tlui-cmt-canvas-pin--open {
100
96
  z-index: 1;
101
97
  }
98
+ /* A pin being dragged rides over everything it passes, the open thread's pin included. */
99
+ .tlui-cmt-canvas-pin--dragging {
100
+ z-index: 2;
101
+ }
102
102
 
103
103
  /* The count badge standing in for a stack of coincident pins — same face as a cluster badge,
104
104
  but clicking opens the stack's thread list rather than zooming (no zoom can separate them).
@@ -119,7 +119,6 @@
119
119
  .tlui-cmt-canvas-stack-badge:focus-visible .tlui-cmt-marker {
120
120
  outline: 2px solid var(--tl-color-selected);
121
121
  outline-offset: 2px;
122
- transform: scale(var(--tlui-cmt-marker-hover-scale));
123
122
  }
124
123
 
125
124
  /* The stack's popover content: one card per thread, the expanded thread inline among them. */
@@ -273,31 +272,39 @@
273
272
  cursor: pointer;
274
273
  }
275
274
 
276
- /* Every card surface that tints on hover — a collapsed thread in a stack list, a preview card, and
277
- the single-comment preview panel. One rule, because they're the same object to the eye.
278
-
279
- The opaque low-surface token, not a translucent muted one: these float directly over the canvas,
280
- where a translucent fill would let shapes show through.
281
-
282
- The second line is why this isn't a one-liner. `--tl-shadow-3` ends with a 1px *inset* ring in
283
- `--tl-color-panel-contrast` — pure white in light mode — and an inset shadow paints over the
284
- background. At rest that's invisible (the panel is 99% white under a 100% white ring), but tint
285
- the background to grey and the ring stays white, hugging the edge as a pale outline. Re-tinting
286
- `--tl-color-panel-contrast` here wouldn't reach it: `--tl-shadow-3` is declared on the container,
287
- so its var() was already substituted there and the white is baked into what we inherit. Instead
288
- lay a ring of the new surface over the old one — first shadow in the list paints on top. */
275
+ /* Every card surface that highlights on hover — a collapsed thread in a stack list, a preview
276
+ card, and the single-comment preview panel. One rule, because they're the same object to the eye.
277
+ The highlight is an inset, rounded wash like a menu item's, not a tint of the whole surface: the
278
+ card stays panel-white and a wash sits 4px inside its edge, its corners following the card's.
279
+ It paints behind the content (`isolation` keeps the -1 z-index above the card's own fill). */
280
+ .tlui-cmt-stack-list__card,
281
+ .tlui-cmt-preview-card--selectable,
282
+ .tlui-cmt-canvas-preview__panel--thread.tlui-cmt-canvas-preview__panel--selectable {
283
+ position: relative;
284
+ isolation: isolate;
285
+ }
286
+ .tlui-cmt-stack-list__card::after,
287
+ .tlui-cmt-preview-card--selectable::after,
288
+ .tlui-cmt-canvas-preview__panel--thread.tlui-cmt-canvas-preview__panel--selectable::after {
289
+ content: '';
290
+ position: absolute;
291
+ inset: 4px;
292
+ z-index: -1;
293
+ /* The cards' 12px radius, less the inset. */
294
+ border-radius: 8px;
295
+ pointer-events: none;
296
+ }
297
+ .tlui-cmt-canvas-preview__panel--thread.tlui-cmt-canvas-preview__panel--selectable::after {
298
+ border-radius: calc(var(--tl-radius-4) - 4px);
299
+ }
300
+ .tlui-cmt-stack-list__card:hover::after,
301
+ .tlui-cmt-preview-card--selectable:hover::after,
302
+ .tlui-cmt-canvas-preview__panel--thread.tlui-cmt-canvas-preview__panel--selectable:hover::after {
303
+ background: var(--tl-color-muted-2);
304
+ }
289
305
  .tlui-cmt-stack-list__card:hover,
290
306
  .tlui-cmt-preview-card--selectable:hover,
291
307
  .tlui-cmt-canvas-preview__panel--thread.tlui-cmt-canvas-preview__panel--selectable:hover {
292
- --tlui-cmt-preview-hover-surface: color-mix(
293
- in srgb,
294
- var(--tl-color-low) 50%,
295
- var(--tl-color-panel)
296
- );
297
- background: var(--tlui-cmt-preview-hover-surface);
298
- box-shadow:
299
- inset 0 0 0 1px var(--tlui-cmt-preview-hover-surface),
300
- var(--tl-shadow-3);
301
308
  cursor: pointer;
302
309
  }
303
310
 
@@ -341,23 +348,45 @@
341
348
  .tlui-cmt-canvas-region {
342
349
  position: absolute;
343
350
  pointer-events: none;
344
- border: 2px dashed var(--tl-color-selected);
345
- border-radius: 6px;
346
351
  background: color-mix(in srgb, var(--tl-color-selected) 10%, transparent);
347
352
  }
353
+ .tlui-cmt-canvas-region__outline {
354
+ position: absolute;
355
+ inset: 0;
356
+ overflow: visible;
357
+ fill: none;
358
+ stroke: var(--tl-color-selection-stroke);
359
+ stroke-width: 1.5px;
360
+ stroke-linecap: round;
361
+ }
362
+
363
+ .tlui-cmt-canvas-region-handles {
364
+ display: contents;
365
+ }
348
366
 
349
- /* Corner resize handles on a region box (three corners; the pin corner is the move handle). */
367
+ /* Corner resize handles on a region box (three corners; the pin corner is the move handle). The
368
+ element is the hit square, sized from the selection's corner hit area (see
369
+ `selectionCornerSizing`); the visible square is drawn like a selection corner: an 8px fill with a
370
+ 1.5px stroke centred on its edge. */
350
371
  .tlui-cmt-canvas-region-handle {
351
372
  position: absolute;
352
- width: 9px;
353
- height: 9px;
354
373
  transform: translate(-50%, -50%);
355
- background: var(--tl-color-panel);
356
- border: 1.5px solid var(--tl-color-selected);
357
- border-radius: 2px;
358
374
  pointer-events: auto;
359
375
  touch-action: none;
360
376
  }
377
+ .tlui-cmt-canvas-region-handle::before {
378
+ content: '';
379
+ position: absolute;
380
+ left: 50%;
381
+ top: 50%;
382
+ /* Not covered by the container's `*` border-box rule, which doesn't match pseudo-elements. */
383
+ box-sizing: border-box;
384
+ width: 9.5px;
385
+ height: 9.5px;
386
+ transform: translate(-50%, -50%);
387
+ background: var(--tl-color-background);
388
+ border: 1.5px solid var(--tl-color-selection-stroke);
389
+ }
361
390
 
362
391
  /* Anchor the pin by its bottom-left corner, so the marker's one sharp corner (the pin shape's
363
392
  3px bottom-left) points at the exact anchor point. */
@@ -489,14 +518,20 @@
489
518
  .tlui-cmt-canvas-composer .tlui-cmt-input__placeholder {
490
519
  left: 12px;
491
520
  }
492
- /* The draft avatar previews the pin it becomes — a white 28px pin holding the author's 22px avatar
493
- circle — sharing the composer's lift. Not interactive: it drops the pin's pointer cursor and
494
- hover affordances (scale + shadow bump), but keeps a 40×40 hit area (the ::after below). */
521
+ /* The draft avatar previews the pin it becomes and is the draft's drag handle. It keeps a 40×40 hit
522
+ area (the ::after below). */
495
523
  .tlui-cmt-canvas-composer .tlui-cmt-pin {
496
524
  position: relative;
497
525
  box-shadow: var(--tl-shadow-2);
498
526
  cursor: default;
499
527
  }
528
+ .tlui-cmt-canvas-composer__handle {
529
+ touch-action: none;
530
+ }
531
+ .tlui-cmt-canvas-composer--dragging .tlui-cmt-canvas-composer__handle,
532
+ .tlui-cmt-canvas-composer--dragging .tlui-cmt-pin {
533
+ cursor: var(--tl-cursor-move);
534
+ }
500
535
  .tlui-cmt-canvas-composer .tlui-cmt-pin::after {
501
536
  content: '';
502
537
  position: absolute;
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'
2
+ import { commentTipTapExtensions, EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'
3
3
  import { renderCommentHtml, renderCommentPlaintext } from './comment-render'
4
4
 
5
5
  const doc = (...content: any[]) => ({ type: 'doc', content }) as any
@@ -26,6 +26,13 @@ describe('renderCommentHtml', () => {
26
26
  expect(list).toContain('one')
27
27
  })
28
28
 
29
+ it('leaves task lists out of the limited set', () => {
30
+ // A posted comment is static HTML, so its checkboxes would toggle and never write back.
31
+ expect(commentTipTapExtensions.map((extension) => extension.name)).not.toEqual(
32
+ expect.arrayContaining([expect.stringMatching(/^task/)])
33
+ )
34
+ })
35
+
29
36
  it('renders a heading node as a paragraph, never a heading', () => {
30
37
  const html = renderCommentHtml(
31
38
  doc({ type: 'heading', attrs: { level: 1 }, content: [text('Title')] })
@@ -15,7 +15,7 @@ import {
15
15
  } from 'tldraw'
16
16
  import { afterEach, beforeEach, describe, expect, it } from 'vitest'
17
17
  import { CommentTool, commentToolOverrides, startCommentAt } from './comment-tool'
18
- import { commentsSidebarOpen, pendingComment, regionDraft } from './state'
18
+ import { pendingComment, regionDraft } from './state'
19
19
 
20
20
  /**
21
21
  * Pointer-driven tests for the comment tool's placement affordances. These need a real editor
@@ -110,8 +110,6 @@ describe('comment tool placement lifecycle', () => {
110
110
  editor.setCurrentTool('comment')
111
111
  driver.pointerDown(400, 300)
112
112
  driver.pointerUp(400, 300)
113
- // Placement opens the composer but the interaction isn't over — the tool holds on until
114
- // the comment is posted or dismissed, so the surrounding UI stays stable.
115
113
  expect(editor.isIn('comment.idle')).toBe(true)
116
114
  expect(pendingComment.get(editor)).toEqual({
117
115
  anchor: { type: 'point', x: 400, y: 300 },
@@ -119,63 +117,63 @@ describe('comment tool placement lifecycle', () => {
119
117
  })
120
118
  })
121
119
 
122
- it('cancels the placement and returns to select on a second click', () => {
120
+ it('keeps the composer open when the tool is left', () => {
123
121
  editor.setCurrentTool('comment')
124
122
  driver.pointerDown(400, 300)
125
123
  driver.pointerUp(400, 300)
126
- driver.pointerDown(200, 200)
127
- driver.pointerUp(200, 200)
128
- expect(editor.isIn('select.idle')).toBe(true)
129
- expect(pendingComment.get(editor)).toBeNull()
124
+ editor.setCurrentTool('hand')
125
+ expect(pendingComment.get(editor)).not.toBeNull()
130
126
  })
131
127
 
132
- it('drops the pending composer when the tool exits', () => {
128
+ it('hides the cursor on press, shows move once dragging, then the comment cursor on release', () => {
133
129
  editor.setCurrentTool('comment')
130
+ expect(editor.getInstanceState().cursor.type).toBe('comment')
134
131
  driver.pointerDown(400, 300)
135
- driver.pointerUp(400, 300)
136
- expect(pendingComment.get(editor)).not.toBeNull()
132
+ expect(editor.getInstanceState().cursor.type).toBe('none')
133
+ driver.pointerMove(450, 350)
134
+ expect(editor.isIn('comment.pointing')).toBe(true)
135
+ expect(editor.getInstanceState().cursor.type).toBe('move')
136
+ driver.pointerUp(450, 350)
137
+ expect(editor.getInstanceState().cursor.type).toBe('comment')
138
+ })
137
139
 
138
- // A direct tool switch (toolbar, shortcut) abandons the draft composer — it belongs to
139
- // the tool. The text itself survives in the comment draft store.
140
- editor.setCurrentTool('select')
140
+ it('escape mid-placement leaves the tool for select and drops the draft', () => {
141
+ editor.setCurrentTool('comment')
142
+ driver.pointerDown(400, 300)
143
+ editor.cancel()
144
+ expect(editor.isIn('select')).toBe(true)
141
145
  expect(pendingComment.get(editor)).toBeNull()
142
146
  })
143
147
 
144
- it('closes the comments sidebar for the whole interaction', () => {
145
- commentsSidebarOpen.set(editor, true)
148
+ it('escape before placing leaves the tool for select', () => {
146
149
  editor.setCurrentTool('comment')
147
- expect(commentsSidebarOpen.get(editor)).toBe(false)
148
-
149
- // ...and placing doesn't reopen it: the tool (and the closed sidebar) hold through the
150
- // composer. Reopening is the host's button, never a side effect of leaving the tool.
151
- driver.pointerDown(400, 300)
152
- driver.pointerUp(400, 300)
153
- expect(editor.isIn('comment.idle')).toBe(true)
154
- expect(commentsSidebarOpen.get(editor)).toBe(false)
150
+ editor.cancel()
151
+ expect(editor.isIn('select')).toBe(true)
155
152
  })
156
153
 
157
- it('escape leaves the tool for select and drops the draft', () => {
154
+ it('escape closes an open composer and stays in the tool, then a second escape leaves for select', () => {
155
+ editor.setCurrentTool('hand')
158
156
  editor.setCurrentTool('comment')
159
157
  driver.pointerDown(400, 300)
160
158
  driver.pointerUp(400, 300)
161
159
  editor.cancel()
162
- expect(editor.isIn('select')).toBe(true)
163
160
  expect(pendingComment.get(editor)).toBeNull()
161
+ expect(editor.isIn('comment.idle')).toBe(true)
162
+ // Select, not the tool that was active before the comment tool.
163
+ editor.cancel()
164
+ expect(editor.isIn('select')).toBe(true)
164
165
  })
165
166
  })
166
167
 
167
168
  describe('startCommentAt', () => {
168
- let driver: Driver
169
-
170
169
  beforeEach(() => {
171
- driver = makeEditor()
170
+ makeEditor()
172
171
  })
173
172
 
174
- it('enters the tool and opens the composer at a bare point on empty canvas', () => {
175
- commentsSidebarOpen.set(editor, true)
173
+ it('opens the composer at a bare point on empty canvas, with select active', () => {
174
+ editor.setCurrentTool('comment')
176
175
  startCommentAt(editor, { x: 400, y: 300 })
177
- expect(editor.isIn('comment.idle')).toBe(true)
178
- expect(commentsSidebarOpen.get(editor)).toBe(false)
176
+ expect(editor.isIn('select.idle')).toBe(true)
179
177
  expect(pendingComment.get(editor)).toEqual({
180
178
  anchor: { type: 'point', x: 400, y: 300 },
181
179
  point: { x: 400, y: 300 },
@@ -187,16 +185,6 @@ describe('startCommentAt', () => {
187
185
  startCommentAt(editor, { x: 150, y: 125 })
188
186
  expect(pendingComment.get(editor)?.anchor).toMatchObject({ type: 'shape', shapeId: id })
189
187
  })
190
-
191
- it('hints the anchored shape, not the one under the live pointer', () => {
192
- const anchored = makeShape()
193
- const underPointer = makeShape(400, 100)
194
- driver.pointerMove(450, 125)
195
- editor.setCurrentTool('comment')
196
- expect(editor.getHintingShapeIds()).toEqual([underPointer])
197
- startCommentAt(editor, { x: 150, y: 125 })
198
- expect(editor.getHintingShapeIds()).toEqual([anchored])
199
- })
200
188
  })
201
189
 
202
190
  describe('commentToolOverrides', () => {
@@ -219,7 +207,7 @@ describe('commentToolOverrides', () => {
219
207
  driver.pointerDown(400, 300).pointerUp(400, 300)
220
208
  driver.pointerMove(600, 500)
221
209
  getCommentTool().onSelect('context-menu')
222
- expect(editor.isIn('comment.idle')).toBe(true)
210
+ expect(editor.isIn('select.idle')).toBe(true)
223
211
  expect(pendingComment.get(editor)?.point).toEqual({ x: 400, y: 300 })
224
212
  })
225
213
 
@@ -262,6 +250,8 @@ describe('comment tool placement hints with regions enabled', () => {
262
250
  it('does not hint a shape under the pin corner of a placed region', () => {
263
251
  const driver = makeEditor(CommentTool.configure({ enableRegions: true }))
264
252
  makeShape(100, 100)
253
+ // The comment tool stays active with the region composer open, so its idle hover is what
254
+ // could re-hint the shape.
265
255
  editor.setCurrentTool('comment')
266
256
  // Release on top of the shape: a region anchors to its rectangle, so the outline that
267
257
  // normally previews a shape anchor would be a lie here.
@@ -9,7 +9,7 @@ import {
9
9
  defineMessages,
10
10
  } from 'tldraw'
11
11
  import { type CommentingOptions, defaultCommentingOptions, getCommentingOptions } from './options'
12
- import { commentsSidebarOpen, pendingComment, regionDraft } from './state'
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 while the composer is open — posting returns to select, and so does clicking the
58
- * canvas elsewhere, which cancels the placement.
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). The cursor resets
104
- // when the next tool takes over. The draft composer and region draft belong to the tool, so
105
- // they leave with it; the draft's text survives in the comment draft store.
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 leaves the tool, like the built-in tools (the editor dispatches `cancel` on 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
- function pendingCommentAt(editor: Editor, point: VecLike): PendingComment {
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: editor.inputs.getAltKey(),
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. Enters the comment tool
137
- * (which must be registered), since the draft composer closes when the tool exits. It doesn't check
138
- * `canComment`: a viewer who can't comment sees the `ComposerFallback` slot instead.
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('comment')
148
- const pending = pendingCommentAt(editor, point)
149
- pendingComment.set(editor, pending)
150
- // Entering the tool hints the shape under the live pointer, which is wherever the caller's UI
151
- // was (a menu item), not `point`.
152
- editor.setHintingShapes(pending.anchor.type === 'shape' ? [pending.anchor.shapeId] : [])
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 prior placing state may have hidden it).
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
- // With a region composer open, a shape outline under its pin corner would imply a shape
170
- // anchor the region will never use — and it would stick, since moves over the composer
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
- // Hide the cursor while placing: the draft composer is the pointer's stand-in now, so the pin
203
- // cursor sitting over it just reads as clutter.
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
- pendingComment.set(editor, pendingCommentAt(editor, point))
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 (Escape, focus loss, etc.). The
247
- // tool's onExit drops the draft.
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.setCurrentTool('select')
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
- pendingComment.set(editor, {
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.setCurrentTool('select')
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 comments' },
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-header-btn"
56
+ className="tlui-cmt-icon-btn"
55
57
  >
56
58
  <MoreMenuIcon />
57
59
  </TldrawUiButton>
58
60
  </TldrawUiDropdownMenuTrigger>
59
- {/* No tlui-cmt-menu here: the rows are tldraw menu items, which carry their own insets —
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>