@tldraw/commenting 5.3.0-internal.c5c7f1d817d0 → 5.3.0-next.030bf6014f04

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 (328) hide show
  1. package/README.md +0 -2
  2. package/commenting.css +1059 -257
  3. package/dist-cjs/canvas/anchor-lifecycle.js +148 -0
  4. package/dist-cjs/canvas/anchor-lifecycle.js.map +7 -0
  5. package/dist-cjs/canvas/canvas-events.js +35 -0
  6. package/dist-cjs/canvas/canvas-events.js.map +7 -0
  7. package/dist-cjs/canvas/cluster-badge.js +121 -0
  8. package/dist-cjs/canvas/cluster-badge.js.map +7 -0
  9. package/dist-cjs/canvas/cluster-fade.js +85 -0
  10. package/dist-cjs/canvas/cluster-fade.js.map +7 -0
  11. package/dist-cjs/canvas/cluster-input.js +53 -3
  12. package/dist-cjs/canvas/cluster-input.js.map +2 -2
  13. package/dist-cjs/canvas/cluster-model.js +252 -0
  14. package/dist-cjs/canvas/cluster-model.js.map +7 -0
  15. package/dist-cjs/canvas/comment-drafts.js +54 -0
  16. package/dist-cjs/canvas/comment-drafts.js.map +7 -0
  17. package/dist-cjs/canvas/comment-mutations.js +152 -0
  18. package/dist-cjs/canvas/comment-mutations.js.map +7 -0
  19. package/dist-cjs/canvas/comment-reactions.js +160 -0
  20. package/dist-cjs/canvas/comment-reactions.js.map +7 -0
  21. package/dist-cjs/canvas/comment-render.js +9 -6
  22. package/dist-cjs/canvas/comment-render.js.map +2 -2
  23. package/dist-cjs/canvas/comment-store.js +19 -9
  24. package/dist-cjs/canvas/comment-store.js.map +2 -2
  25. package/dist-cjs/canvas/comment-tool.js +63 -14
  26. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  27. package/dist-cjs/canvas/comments-filter-menu.js +17 -37
  28. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  29. package/dist-cjs/canvas/comments-overflow-menu.js +25 -22
  30. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  31. package/dist-cjs/canvas/comments-overlay.js +150 -1003
  32. package/dist-cjs/canvas/comments-overlay.js.map +3 -3
  33. package/dist-cjs/canvas/comments-sidebar.js +48 -40
  34. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  35. package/dist-cjs/canvas/comments-visibility-toggle.js +45 -0
  36. package/dist-cjs/canvas/comments-visibility-toggle.js.map +7 -0
  37. package/dist-cjs/canvas/context.js +17 -0
  38. package/dist-cjs/canvas/context.js.map +7 -0
  39. package/dist-cjs/canvas/hooks.js +28 -3
  40. package/dist-cjs/canvas/hooks.js.map +2 -2
  41. package/dist-cjs/canvas/license.js.map +1 -1
  42. package/dist-cjs/canvas/mobile-placement.js +91 -0
  43. package/dist-cjs/canvas/mobile-placement.js.map +7 -0
  44. package/dist-cjs/canvas/options.js +57 -2
  45. package/dist-cjs/canvas/options.js.map +2 -2
  46. package/dist-cjs/canvas/pending-composer.js +134 -0
  47. package/dist-cjs/canvas/pending-composer.js.map +7 -0
  48. package/dist-cjs/canvas/pin-stacking.js +81 -0
  49. package/dist-cjs/canvas/pin-stacking.js.map +7 -0
  50. package/dist-cjs/canvas/region-box.js +113 -0
  51. package/dist-cjs/canvas/region-box.js.map +7 -0
  52. package/dist-cjs/canvas/sidebar-filters.js +2 -2
  53. package/dist-cjs/canvas/sidebar-filters.js.map +2 -2
  54. package/dist-cjs/canvas/state.js +28 -14
  55. package/dist-cjs/canvas/state.js.map +2 -2
  56. package/dist-cjs/canvas/thread-pin.js +304 -0
  57. package/dist-cjs/canvas/thread-pin.js.map +7 -0
  58. package/dist-cjs/canvas/thread-preview.js +177 -0
  59. package/dist-cjs/canvas/thread-preview.js.map +7 -0
  60. package/dist-cjs/canvas/thread-stack.js +199 -0
  61. package/dist-cjs/canvas/thread-stack.js.map +7 -0
  62. package/dist-cjs/canvas/thread-state.js +82 -21
  63. package/dist-cjs/canvas/thread-state.js.map +2 -2
  64. package/dist-cjs/canvas/thread-view.js +450 -0
  65. package/dist-cjs/canvas/thread-view.js.map +7 -0
  66. package/dist-cjs/clustering/computeClusterTable.js +6 -6
  67. package/dist-cjs/clustering/computeClusterTable.js.map +2 -2
  68. package/dist-cjs/clustering/replay.js +89 -22
  69. package/dist-cjs/clustering/replay.js.map +3 -3
  70. package/dist-cjs/clustering/runtime.js +27 -20
  71. package/dist-cjs/clustering/runtime.js.map +2 -2
  72. package/dist-cjs/clustering/types.js.map +1 -1
  73. package/dist-cjs/index.d.ts +904 -373
  74. package/dist-cjs/index.js +52 -28
  75. package/dist-cjs/index.js.map +2 -2
  76. package/dist-cjs/ui/byline.js +8 -4
  77. package/dist-cjs/ui/byline.js.map +2 -2
  78. package/dist-cjs/ui/comment-card.js +12 -5
  79. package/dist-cjs/ui/comment-card.js.map +2 -2
  80. package/dist-cjs/ui/comment-composer.js +99 -20
  81. package/dist-cjs/ui/comment-composer.js.map +2 -2
  82. package/dist-cjs/ui/comment-pin.js +7 -2
  83. package/dist-cjs/ui/comment-pin.js.map +2 -2
  84. package/dist-cjs/ui/comment-thread.js +4 -2
  85. package/dist-cjs/ui/comment-thread.js.map +2 -2
  86. package/dist-cjs/ui/comments-list.js +32 -33
  87. package/dist-cjs/ui/comments-list.js.map +2 -2
  88. package/dist-cjs/ui/count-badge.js +3 -2
  89. package/dist-cjs/ui/count-badge.js.map +2 -2
  90. package/dist-cjs/ui/emoji-picker.js +54 -0
  91. package/dist-cjs/ui/emoji-picker.js.map +7 -0
  92. package/dist-cjs/ui/format-time.js +16 -1
  93. package/dist-cjs/ui/format-time.js.map +2 -2
  94. package/dist-cjs/ui/icons.js +115 -0
  95. package/dist-cjs/ui/icons.js.map +7 -0
  96. package/dist-cjs/ui/reaction-picker.js +71 -0
  97. package/dist-cjs/ui/reaction-picker.js.map +7 -0
  98. package/dist-cjs/ui/reaction.js +51 -6
  99. package/dist-cjs/ui/reaction.js.map +2 -2
  100. package/dist-cjs/ui/reactions.js +20 -15
  101. package/dist-cjs/ui/reactions.js.map +2 -2
  102. package/dist-cjs/ui/{mention.js → reply-count.js} +9 -11
  103. package/dist-cjs/ui/reply-count.js.map +7 -0
  104. package/dist-cjs/ui/send-button.js +13 -1
  105. package/dist-cjs/ui/send-button.js.map +2 -2
  106. package/dist-cjs/ui/{comment-text.js → visual-viewport.js} +12 -9
  107. package/dist-cjs/ui/visual-viewport.js.map +7 -0
  108. package/dist-esm/canvas/anchor-lifecycle.mjs +128 -0
  109. package/dist-esm/canvas/anchor-lifecycle.mjs.map +7 -0
  110. package/dist-esm/canvas/canvas-events.mjs +15 -0
  111. package/dist-esm/canvas/canvas-events.mjs.map +7 -0
  112. package/dist-esm/canvas/cluster-badge.mjs +106 -0
  113. package/dist-esm/canvas/cluster-badge.mjs.map +7 -0
  114. package/dist-esm/canvas/cluster-fade.mjs +65 -0
  115. package/dist-esm/canvas/cluster-fade.mjs.map +7 -0
  116. package/dist-esm/canvas/cluster-input.mjs +54 -4
  117. package/dist-esm/canvas/cluster-input.mjs.map +2 -2
  118. package/dist-esm/canvas/cluster-model.mjs +236 -0
  119. package/dist-esm/canvas/cluster-model.mjs.map +7 -0
  120. package/dist-esm/canvas/comment-drafts.mjs +34 -0
  121. package/dist-esm/canvas/comment-drafts.mjs.map +7 -0
  122. package/dist-esm/canvas/comment-mutations.mjs +132 -0
  123. package/dist-esm/canvas/comment-mutations.mjs.map +7 -0
  124. package/dist-esm/canvas/comment-reactions.mjs +145 -0
  125. package/dist-esm/canvas/comment-reactions.mjs.map +7 -0
  126. package/dist-esm/canvas/comment-render.mjs +10 -7
  127. package/dist-esm/canvas/comment-render.mjs.map +2 -2
  128. package/dist-esm/canvas/comment-store.mjs +19 -9
  129. package/dist-esm/canvas/comment-store.mjs.map +2 -2
  130. package/dist-esm/canvas/comment-tool.mjs +66 -17
  131. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  132. package/dist-esm/canvas/comments-filter-menu.mjs +17 -36
  133. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  134. package/dist-esm/canvas/comments-overflow-menu.mjs +27 -22
  135. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  136. package/dist-esm/canvas/comments-overlay.mjs +156 -1024
  137. package/dist-esm/canvas/comments-overlay.mjs.map +3 -3
  138. package/dist-esm/canvas/comments-sidebar.mjs +52 -45
  139. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  140. package/dist-esm/canvas/comments-visibility-toggle.mjs +25 -0
  141. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +7 -0
  142. package/dist-esm/canvas/context.mjs +1 -0
  143. package/dist-esm/canvas/context.mjs.map +7 -0
  144. package/dist-esm/canvas/hooks.mjs +35 -5
  145. package/dist-esm/canvas/hooks.mjs.map +2 -2
  146. package/dist-esm/canvas/license.mjs.map +1 -1
  147. package/dist-esm/canvas/mobile-placement.mjs +71 -0
  148. package/dist-esm/canvas/mobile-placement.mjs.map +7 -0
  149. package/dist-esm/canvas/options.mjs +59 -3
  150. package/dist-esm/canvas/options.mjs.map +2 -2
  151. package/dist-esm/canvas/pending-composer.mjs +126 -0
  152. package/dist-esm/canvas/pending-composer.mjs.map +7 -0
  153. package/dist-esm/canvas/pin-stacking.mjs +61 -0
  154. package/dist-esm/canvas/pin-stacking.mjs.map +7 -0
  155. package/dist-esm/canvas/region-box.mjs +93 -0
  156. package/dist-esm/canvas/region-box.mjs.map +7 -0
  157. package/dist-esm/canvas/sidebar-filters.mjs +2 -2
  158. package/dist-esm/canvas/sidebar-filters.mjs.map +2 -2
  159. package/dist-esm/canvas/state.mjs +29 -19
  160. package/dist-esm/canvas/state.mjs.map +2 -2
  161. package/dist-esm/canvas/thread-pin.mjs +310 -0
  162. package/dist-esm/canvas/thread-pin.mjs.map +7 -0
  163. package/dist-esm/canvas/thread-preview.mjs +163 -0
  164. package/dist-esm/canvas/thread-preview.mjs.map +7 -0
  165. package/dist-esm/canvas/thread-stack.mjs +189 -0
  166. package/dist-esm/canvas/thread-stack.mjs.map +7 -0
  167. package/dist-esm/canvas/thread-state.mjs +86 -22
  168. package/dist-esm/canvas/thread-state.mjs.map +2 -2
  169. package/dist-esm/canvas/thread-view.mjs +461 -0
  170. package/dist-esm/canvas/thread-view.mjs.map +7 -0
  171. package/dist-esm/clustering/computeClusterTable.mjs +6 -6
  172. package/dist-esm/clustering/computeClusterTable.mjs.map +2 -2
  173. package/dist-esm/clustering/replay.mjs +89 -22
  174. package/dist-esm/clustering/replay.mjs.map +3 -3
  175. package/dist-esm/clustering/runtime.mjs +27 -20
  176. package/dist-esm/clustering/runtime.mjs.map +2 -2
  177. package/dist-esm/index.d.mts +904 -373
  178. package/dist-esm/index.mjs +102 -43
  179. package/dist-esm/index.mjs.map +2 -2
  180. package/dist-esm/ui/byline.mjs +9 -5
  181. package/dist-esm/ui/byline.mjs.map +2 -2
  182. package/dist-esm/ui/comment-card.mjs +12 -5
  183. package/dist-esm/ui/comment-card.mjs.map +2 -2
  184. package/dist-esm/ui/comment-composer.mjs +109 -19
  185. package/dist-esm/ui/comment-composer.mjs.map +2 -2
  186. package/dist-esm/ui/comment-pin.mjs +7 -2
  187. package/dist-esm/ui/comment-pin.mjs.map +2 -2
  188. package/dist-esm/ui/comment-thread.mjs +4 -2
  189. package/dist-esm/ui/comment-thread.mjs.map +2 -2
  190. package/dist-esm/ui/comments-list.mjs +48 -47
  191. package/dist-esm/ui/comments-list.mjs.map +2 -2
  192. package/dist-esm/ui/count-badge.mjs +3 -2
  193. package/dist-esm/ui/count-badge.mjs.map +2 -2
  194. package/dist-esm/ui/emoji-picker.mjs +34 -0
  195. package/dist-esm/ui/emoji-picker.mjs.map +7 -0
  196. package/dist-esm/ui/format-time.mjs +16 -1
  197. package/dist-esm/ui/format-time.mjs.map +2 -2
  198. package/dist-esm/ui/icons.mjs +95 -0
  199. package/dist-esm/ui/icons.mjs.map +7 -0
  200. package/dist-esm/ui/reaction-picker.mjs +59 -0
  201. package/dist-esm/ui/reaction-picker.mjs.map +7 -0
  202. package/dist-esm/ui/reaction.mjs +52 -7
  203. package/dist-esm/ui/reaction.mjs.map +2 -2
  204. package/dist-esm/ui/reactions.mjs +21 -16
  205. package/dist-esm/ui/reactions.mjs.map +2 -2
  206. package/dist-esm/ui/reply-count.mjs +9 -0
  207. package/dist-esm/ui/reply-count.mjs.map +7 -0
  208. package/dist-esm/ui/send-button.mjs +13 -1
  209. package/dist-esm/ui/send-button.mjs.map +2 -2
  210. package/dist-esm/ui/visual-viewport.mjs +12 -0
  211. package/dist-esm/ui/visual-viewport.mjs.map +7 -0
  212. package/package.json +6 -6
  213. package/src/canvas/anchor-lifecycle.test.ts +290 -0
  214. package/src/canvas/anchor-lifecycle.ts +191 -0
  215. package/src/canvas/canvas-events.ts +18 -0
  216. package/src/canvas/canvas.css +444 -35
  217. package/src/canvas/cluster-badge.tsx +133 -0
  218. package/src/canvas/cluster-fade.ts +102 -0
  219. package/src/canvas/cluster-input.test.ts +178 -36
  220. package/src/canvas/cluster-input.ts +95 -9
  221. package/src/canvas/cluster-model.ts +378 -0
  222. package/src/canvas/comment-drafts.test.ts +55 -0
  223. package/src/canvas/comment-drafts.ts +46 -0
  224. package/src/canvas/comment-mutations.test.ts +452 -0
  225. package/src/canvas/comment-mutations.ts +299 -0
  226. package/src/canvas/comment-reactions.test.ts +154 -0
  227. package/src/canvas/comment-reactions.tsx +246 -0
  228. package/src/canvas/comment-render.ts +17 -13
  229. package/src/canvas/comment-store.ts +68 -33
  230. package/src/canvas/comment-tool.test.ts +162 -0
  231. package/src/canvas/comment-tool.tsx +103 -25
  232. package/src/canvas/comments-filter-menu.tsx +20 -36
  233. package/src/canvas/comments-overflow-menu.tsx +15 -17
  234. package/src/canvas/comments-overlay.tsx +251 -1401
  235. package/src/canvas/comments-sidebar.test.ts +45 -0
  236. package/src/canvas/comments-sidebar.tsx +111 -72
  237. package/src/canvas/comments-visibility-toggle.tsx +25 -0
  238. package/src/canvas/context.ts +48 -0
  239. package/src/canvas/hooks.test.ts +94 -0
  240. package/src/canvas/hooks.ts +66 -11
  241. package/src/canvas/license.ts +1 -1
  242. package/src/canvas/mobile-placement.ts +115 -0
  243. package/src/canvas/options.test.ts +176 -4
  244. package/src/canvas/options.ts +276 -18
  245. package/src/canvas/pending-composer.tsx +157 -0
  246. package/src/canvas/pin-stacking.test.ts +224 -0
  247. package/src/canvas/pin-stacking.ts +103 -0
  248. package/src/canvas/region-box.tsx +124 -0
  249. package/src/canvas/sidebar-filters.ts +4 -3
  250. package/src/canvas/state.ts +88 -39
  251. package/src/canvas/thread-pin.tsx +418 -0
  252. package/src/canvas/thread-preview.test.ts +91 -0
  253. package/src/canvas/thread-preview.tsx +294 -0
  254. package/src/canvas/thread-stack.tsx +242 -0
  255. package/src/canvas/thread-state.test.ts +260 -0
  256. package/src/canvas/thread-state.ts +171 -37
  257. package/src/canvas/thread-view.test.ts +72 -0
  258. package/src/canvas/thread-view.tsx +614 -0
  259. package/src/clustering/computeClusterTable.test.ts +24 -23
  260. package/src/clustering/computeClusterTable.ts +17 -8
  261. package/src/clustering/replay.test.ts +0 -7
  262. package/src/clustering/replay.ts +131 -32
  263. package/src/clustering/runtime.test.ts +84 -6
  264. package/src/clustering/runtime.ts +52 -44
  265. package/src/clustering/schedule.test.ts +0 -6
  266. package/src/clustering/screen-offsets.test.ts +171 -0
  267. package/src/clustering/types.ts +19 -9
  268. package/src/index.ts +91 -42
  269. package/src/ui/byline.tsx +20 -8
  270. package/src/ui/comment-card.tsx +17 -7
  271. package/src/ui/comment-composer.tsx +146 -43
  272. package/src/ui/comment-pin.tsx +9 -2
  273. package/src/ui/comment-thread.tsx +6 -1
  274. package/src/ui/comments-list.test.ts +31 -0
  275. package/src/ui/comments-list.tsx +69 -38
  276. package/src/ui/comments.css +505 -222
  277. package/src/ui/count-badge.tsx +9 -2
  278. package/src/ui/emoji-picker.test.ts +25 -0
  279. package/src/ui/emoji-picker.tsx +76 -0
  280. package/src/ui/format-time.test.ts +69 -0
  281. package/src/ui/format-time.ts +27 -2
  282. package/src/ui/icons.tsx +116 -0
  283. package/src/ui/reaction-picker.tsx +102 -0
  284. package/src/ui/reaction.tsx +123 -7
  285. package/src/ui/reactions.tsx +68 -13
  286. package/src/ui/reply-count.ts +16 -0
  287. package/src/ui/send-button.tsx +13 -3
  288. package/src/ui/visual-viewport.test.ts +36 -0
  289. package/src/ui/visual-viewport.ts +27 -0
  290. package/dist-cjs/canvas/region-options.js +0 -49
  291. package/dist-cjs/canvas/region-options.js.map +0 -7
  292. package/dist-cjs/ui/avatar.js +0 -51
  293. package/dist-cjs/ui/avatar.js.map +0 -7
  294. package/dist-cjs/ui/comment-mention.js +0 -42
  295. package/dist-cjs/ui/comment-mention.js.map +0 -7
  296. package/dist-cjs/ui/comment-text.js.map +0 -7
  297. package/dist-cjs/ui/mention-list.js +0 -70
  298. package/dist-cjs/ui/mention-list.js.map +0 -7
  299. package/dist-cjs/ui/mention-suggestion.js +0 -206
  300. package/dist-cjs/ui/mention-suggestion.js.map +0 -7
  301. package/dist-cjs/ui/mention.js.map +0 -7
  302. package/dist-cjs/ui/render-markdown.js +0 -63
  303. package/dist-cjs/ui/render-markdown.js.map +0 -7
  304. package/dist-esm/canvas/region-options.mjs +0 -29
  305. package/dist-esm/canvas/region-options.mjs.map +0 -7
  306. package/dist-esm/ui/avatar.mjs +0 -31
  307. package/dist-esm/ui/avatar.mjs.map +0 -7
  308. package/dist-esm/ui/comment-mention.mjs +0 -22
  309. package/dist-esm/ui/comment-mention.mjs.map +0 -7
  310. package/dist-esm/ui/comment-text.mjs +0 -9
  311. package/dist-esm/ui/comment-text.mjs.map +0 -7
  312. package/dist-esm/ui/mention-list.mjs +0 -50
  313. package/dist-esm/ui/mention-list.mjs.map +0 -7
  314. package/dist-esm/ui/mention-suggestion.mjs +0 -186
  315. package/dist-esm/ui/mention-suggestion.mjs.map +0 -7
  316. package/dist-esm/ui/mention.mjs +0 -11
  317. package/dist-esm/ui/mention.mjs.map +0 -7
  318. package/dist-esm/ui/render-markdown.mjs +0 -45
  319. package/dist-esm/ui/render-markdown.mjs.map +0 -7
  320. package/src/canvas/region-options.ts +0 -57
  321. package/src/ui/avatar.tsx +0 -38
  322. package/src/ui/comment-mention.ts +0 -47
  323. package/src/ui/comment-text.tsx +0 -12
  324. package/src/ui/mention-list.tsx +0 -106
  325. package/src/ui/mention-suggestion.test.ts +0 -18
  326. package/src/ui/mention-suggestion.tsx +0 -285
  327. package/src/ui/mention.tsx +0 -9
  328. package/src/ui/render-markdown.tsx +0 -72
@@ -1,12 +1,12 @@
1
+ import { type CommentAuthor } from '@tldraw/mentions'
1
2
  import { ReactNode } from 'react'
2
- import { Avatar } from './avatar'
3
3
  import { Byline } from './byline'
4
4
 
5
5
  /** @public */
6
6
  export interface CommentCardProps {
7
- author: string
8
- /** The rendered comment body. The card doesn't dictate a format — pass a `<CommentText>`
9
- * for markdown, a rich-text render, or any node. */
7
+ author: CommentAuthor
8
+ /** The rendered comment body. The card doesn't dictate a format — pass a `<CommentBody>`
9
+ * for a comment's rich text, or any node of your own. */
10
10
  body: ReactNode
11
11
  /** ISO datetime; formatted to relative time by the component. */
12
12
  date: string
@@ -15,16 +15,26 @@ export interface CommentCardProps {
15
15
  edited?: boolean
16
16
  /** Hover-revealed controls at the card's top-right (e.g. an edit affordance). */
17
17
  actions?: ReactNode
18
+ /** Content under the body, aligned with it rather than the avatar (e.g. a `<Reactions>` row). */
19
+ footer?: ReactNode
18
20
  }
19
21
 
20
22
  /** A single comment: Avatar, Byline, and a body slot the consumer renders. @public @react */
21
- export function CommentCard({ author, body, date, you, edited, actions }: CommentCardProps) {
23
+ export function CommentCard({
24
+ author,
25
+ body,
26
+ date,
27
+ you,
28
+ edited,
29
+ actions,
30
+ footer,
31
+ }: CommentCardProps) {
22
32
  return (
23
33
  <div className={you ? 'tlui-cmt-card tlui-cmt-card--you' : 'tlui-cmt-card'}>
24
- <Avatar name={author} />
34
+ <Byline author={author} date={date} edited={edited} />
25
35
  <div className="tlui-cmt-body">
26
- <Byline author={author} date={date} edited={edited} />
27
36
  {body}
37
+ {footer}
28
38
  </div>
29
39
  {actions !== undefined && <div className="tlui-cmt-card__actions">{actions}</div>}
30
40
  </div>
@@ -1,17 +1,29 @@
1
1
  import { JSONContent } from '@tiptap/core'
2
2
  import { EditorContent, useEditor } from '@tiptap/react'
3
- import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'
3
+ import {
4
+ Avatar,
5
+ type CommentAuthor,
6
+ createMentionExtension,
7
+ createMentionSuggestion,
8
+ isMentionPickerOpen,
9
+ MentionMember,
10
+ } from '@tldraw/mentions'
11
+ import {
12
+ type MouseEvent as ReactMouseEvent,
13
+ ReactNode,
14
+ useEffect,
15
+ useLayoutEffect,
16
+ useMemo,
17
+ useRef,
18
+ useState,
19
+ } from 'react'
4
20
  import { isEqual, TLRichText, useMaybeEditor } from 'tldraw'
5
- import { Avatar } from './avatar'
6
21
  import { commentTipTapExtensions, EMPTY_COMMENT, isCommentEmpty } from './comment-extensions'
7
- import { commentMention } from './comment-mention'
8
- import { MentionMember } from './mention-list'
9
- import { createMentionSuggestion, isMentionPickerOpen } from './mention-suggestion'
10
22
  import { SendButton } from './send-button'
11
23
 
12
24
  /** @public */
13
25
  export interface CommentComposerProps {
14
- author: string
26
+ author: CommentAuthor
15
27
  placeholder: string
16
28
  /** Controlled rich-text value. Omit for the presentational (display-only) composer. */
17
29
  value?: TLRichText
@@ -19,6 +31,9 @@ export interface CommentComposerProps {
19
31
  /** Called on Send click or Enter. When set, the composer is interactive. */
20
32
  onSubmit?(): void
21
33
  sendLabel?: string
34
+ /** Called when Up is pressed in an empty composer — e.g. to start editing the comment above,
35
+ * the way chat apps edit your last message. With content in the field, Up moves the cursor. */
36
+ onArrowUpWhenEmpty?(): void
22
37
  disabled?: boolean
23
38
  autoFocus?: boolean
24
39
  /** The leading element before the field. Defaults to the author's avatar. */
@@ -43,6 +58,7 @@ export function CommentComposer({
43
58
  onChange,
44
59
  onSubmit,
45
60
  sendLabel = 'Send',
61
+ onArrowUpWhenEmpty,
46
62
  disabled,
47
63
  autoFocus,
48
64
  leading,
@@ -50,16 +66,16 @@ export function CommentComposer({
50
66
  renderMentionSuggestion,
51
67
  }: CommentComposerProps) {
52
68
  const interactive = !!onChange || !!onSubmit
53
- // The canvas editor the composer lives in, if any — lets the mention popup track the camera. Null
54
- // when the composer is used outside a tldraw editor (e.g. an isolated demo).
69
+ // Lets the mention popup track the camera. Null outside a tldraw editor.
55
70
  const tlEditor = useMaybeEditor()
56
71
 
57
- // Callbacks are read through refs so the editor instance doesn't need to be recreated when they
58
- // change identity between renders.
72
+ // Read through refs so the editor isn't recreated when callback identity changes.
59
73
  const onChangeRef = useRef(onChange)
60
74
  onChangeRef.current = onChange
61
75
  const onSubmitRef = useRef(onSubmit)
62
76
  onSubmitRef.current = onSubmit
77
+ const onArrowUpWhenEmptyRef = useRef(onArrowUpWhenEmpty)
78
+ onArrowUpWhenEmptyRef.current = onArrowUpWhenEmpty
63
79
  const disabledRef = useRef(disabled)
64
80
  disabledRef.current = disabled
65
81
  const getMentionSuggestionsRef = useRef(getMentionSuggestions)
@@ -68,42 +84,80 @@ export function CommentComposer({
68
84
  renderMentionSuggestionRef.current = renderMentionSuggestion
69
85
 
70
86
  const [isEmpty, setIsEmpty] = useState(() => !value || isCommentEmpty(value))
87
+ // Whether the field has grown to two rows: input across the full width, send button below.
88
+ // Flips when the (single-line) content width reaches the space left beside the send button.
89
+ const [expanded, setExpanded] = useState(false)
90
+ const expandedRef = useRef(expanded)
91
+ expandedRef.current = expanded
92
+ const inputWrapRef = useRef<HTMLDivElement>(null)
93
+ const mirrorRef = useRef<HTMLDivElement>(null)
71
94
 
72
- // The editor instance, reachable from `handleKeyDown` (which is created before `useEditor`
73
- // returns). Updated on every render so the ref never points at a stale editor.
95
+ // Measure whether the content still fits on one line beside the send button, against a hidden
96
+ // nowrap clone so marks and mention chips measure at their true width. The gap between the
97
+ // expand and collapse thresholds is a dead zone, so the layout can't flap at the boundary.
98
+ const remeasure = () => {
99
+ const wrap = inputWrapRef.current
100
+ const mirror = mirrorRef.current
101
+ const editor = editorRef.current
102
+ if (!wrap || !mirror || !editor) return
103
+ // Empty always fits — and measuring before TipTap has laid out reads zero widths, flashing
104
+ // the expanded layout for a frame on mount.
105
+ if (editor.isEmpty) {
106
+ if (expandedRef.current) setExpanded(false)
107
+ return
108
+ }
109
+ if (wrap.clientWidth === 0) return
110
+ const doc = editor.state.doc
111
+ const multiBlock =
112
+ doc.childCount > 1 || (doc.firstChild !== null && doc.firstChild.type.name !== 'paragraph')
113
+ if (multiBlock) {
114
+ if (!expandedRef.current) setExpanded(true)
115
+ return
116
+ }
117
+ const field = wrap.parentElement
118
+ const send = field ? field.querySelector<HTMLElement>('.tlui-cmt-send') : null
119
+ const input = wrap.querySelector('.tlui-cmt-input')
120
+ if (!send || !input) return
121
+ mirror.innerHTML = input.innerHTML
122
+ const textWidth = mirror.offsetWidth
123
+ // Measured against the wrap's *content* box: text wraps at clientWidth minus padding, so
124
+ // without subtracting it the input grows a line before expansion fires and then snaps.
125
+ const wrapStyle = getComputedStyle(wrap)
126
+ const wrapPadX = parseFloat(wrapStyle.paddingLeft) + parseFloat(wrapStyle.paddingRight)
127
+ const collapsedAvailable =
128
+ wrap.clientWidth - wrapPadX - (expandedRef.current ? send.offsetWidth + 6 : 0)
129
+ if (!expandedRef.current && textWidth > collapsedAvailable - 8) {
130
+ setExpanded(true)
131
+ } else if (expandedRef.current && textWidth < collapsedAvailable - 24) {
132
+ setExpanded(false)
133
+ }
134
+ }
135
+ const remeasureRef = useRef(remeasure)
136
+ remeasureRef.current = remeasure
137
+
138
+ // Reachable from `handleKeyDown`, which is created before `useEditor` returns.
74
139
  const editorRef = useRef<ReturnType<typeof useEditor>>(null)
75
140
 
76
- // Set while we replay Enter through the keymaps for a Shift+Enter newline: `commands.enter()`
77
- // re-dispatches Enter through `handleKeyDown`, and without this guard our own handler would catch
78
- // that synthetic Enter and submit instead.
141
+ // `commands.enter()` re-dispatches through `handleKeyDown`; without this guard our own handler
142
+ // would catch the synthetic Enter and submit.
79
143
  const replayingEnter = useRef(false)
80
144
 
81
- // Enter and Cmd/Ctrl+Enter submit the comment; Shift+Enter inserts a new line for the occasional
82
- // multi-line comment. This is handled through `editorProps.handleKeyDown` (below) rather than a
83
- // keyboard-shortcut extension: ProseMirror runs `handleKeyDown` before every keymap plugin, so it
84
- // can tell Shift+Enter apart from Enter — an `Enter` keymap binding also fires on Shift/Cmd+Enter
85
- // and would otherwise swallow the newline.
86
-
87
- // The suggestion plugin is built once (the editor is recreated only on `interactive`) and runs
88
- // outside React, so it must read the mention callbacks through refs — like onChange/onSubmit —
89
- // or it queries the roster present at mount forever, never seeing a member who loads or joins
90
- // later. Whether mentions (and a custom picker row) are wired at all is fixed at mount; only the
91
- // callbacks themselves are live.
145
+ // The suggestion plugin is built once and runs outside React, so it reads the mention callbacks
146
+ // through refs — otherwise it queries the roster present at mount forever, never seeing a member
147
+ // who joins later. Whether mentions are wired at all is fixed at mount; the callbacks are live.
92
148
  const mentionsEnabled = !!getMentionSuggestions
93
149
  const hasCustomRow = !!renderMentionSuggestion
94
150
  const extensions = useMemo(() => {
95
151
  const list = [...commentTipTapExtensions]
96
- // Always register the mention node so an existing body that contains a mention keeps it on
97
- // edit (an unregistered node would be stripped by ProseMirror when the content loads). The `@`
98
- // picker itself only turns on when the host provides a resolver; otherwise the node is present
99
- // but its trigger is disabled.
152
+ // The mention node is always registered, or ProseMirror strips existing mentions when an
153
+ // edited body loads. Only the `@` trigger is gated on the host providing a resolver.
100
154
  if (mentionsEnabled) {
101
155
  const resolveSuggestions = (query: string) => getMentionSuggestionsRef.current?.(query) ?? []
102
156
  const renderRow = hasCustomRow
103
157
  ? (member: MentionMember) => renderMentionSuggestionRef.current?.(member)
104
158
  : undefined
105
159
  list.push(
106
- commentMention({
160
+ createMentionExtension({
107
161
  suggestion: createMentionSuggestion(resolveSuggestions, {
108
162
  renderMember: renderRow,
109
163
  editor: tlEditor,
@@ -111,7 +165,7 @@ export function CommentComposer({
111
165
  })
112
166
  )
113
167
  } else {
114
- list.push(commentMention({ suggestion: { char: '@', allow: () => false } }))
168
+ list.push(createMentionExtension({ suggestion: { char: '@', allow: () => false } }))
115
169
  }
116
170
  return list
117
171
  }, [mentionsEnabled, hasCustomRow, tlEditor])
@@ -121,25 +175,43 @@ export function CommentComposer({
121
175
  extensions,
122
176
  content: (value ?? EMPTY_COMMENT) as JSONContent,
123
177
  editable: interactive,
124
- // tldraw's default extensions add their own TextDirection extension (so it can be
125
- // overridden), so disable TipTap's core one to avoid a duplicate-extension warning —
126
- // mirrors RichTextArea's setup.
178
+ // tldraw ships its own TextDirection extension, so TipTap's core one would warn about a
179
+ // duplicate. Mirrors RichTextArea's setup.
127
180
  enableCoreExtensions: { textDirection: false },
128
181
  textDirection: 'auto',
129
182
  editorProps: {
130
- attributes: { class: 'tlui-cmt-input' },
183
+ attributes: {
184
+ class: 'tlui-cmt-input',
185
+ 'aria-label': placeholder,
186
+ role: 'textbox',
187
+ 'aria-multiline': 'true',
188
+ },
131
189
  // Runs before every keymap plugin, so it can distinguish Shift+Enter from Enter — an
132
190
  // `Enter` keymap binding also fires on Shift+Enter and would otherwise swallow it.
133
191
  handleKeyDown: (_view, event) => {
134
192
  // Let the keymaps handle the synthetic Enter we replay for a Shift+Enter newline.
135
193
  if (replayingEnter.current) return false
194
+ // Up in an empty composer hands off to the host. With content it stays cursor
195
+ // movement, and with the picker open it navigates the roster.
196
+ if (event.key === 'ArrowUp' && !event.isComposing) {
197
+ if (
198
+ onArrowUpWhenEmptyRef.current &&
199
+ editorRef.current?.isEmpty &&
200
+ !isMentionPickerOpen()
201
+ ) {
202
+ onArrowUpWhenEmptyRef.current()
203
+ return true
204
+ }
205
+ return false
206
+ }
136
207
  if (event.key !== 'Enter' || event.isComposing) return false
137
208
  // While the @-mention picker is open, Enter selects the highlighted member — defer.
138
209
  if (isMentionPickerOpen()) return false
139
- // Shift+Enter inserts a new line. Replay a plain Enter through the keymaps (guarded so
140
- // we don't re-enter and submit) to reuse the editor's list-aware Enter handling — a new
141
- // list item in a list, a new paragraph otherwise. tldraw doesn't do soft breaks.
210
+ // Shift+Enter inserts a new line by replaying a plain Enter through the keymaps, reusing
211
+ // the editor's list-aware handling. tldraw doesn't do soft breaks.
142
212
  if (event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey) {
213
+ // An empty field would open the comment with a stray leading blank line.
214
+ if (editorRef.current?.isEmpty) return true
143
215
  replayingEnter.current = true
144
216
  try {
145
217
  editorRef.current?.commands.enter()
@@ -155,10 +227,12 @@ export function CommentComposer({
155
227
  },
156
228
  onUpdate: ({ editor }) => {
157
229
  setIsEmpty(editor.isEmpty)
230
+ // Same-value state sets don't re-render, and the DOM is already updated here.
231
+ remeasureRef.current()
158
232
  onChangeRef.current?.(editor.getJSON() as TLRichText)
159
233
  },
160
234
  },
161
- [interactive]
235
+ [interactive, placeholder]
162
236
  )
163
237
  editorRef.current = editor
164
238
 
@@ -171,6 +245,12 @@ export function CommentComposer({
171
245
  setIsEmpty(editor.isEmpty)
172
246
  }, [editor, value])
173
247
 
248
+ // Measure once the editor's content is in the DOM, so a composer that mounts pre-filled (the
249
+ // edit-in-place composer) starts in the right layout.
250
+ useLayoutEffect(() => {
251
+ remeasureRef.current()
252
+ }, [editor, value])
253
+
174
254
  // Focus on the next frame rather than via TipTap's autofocus: the composer often mounts from a
175
255
  // canvas pointer event whose default focus handling would otherwise steal it back.
176
256
  useEffect(() => {
@@ -179,17 +259,40 @@ export function CommentComposer({
179
259
  return () => cancelAnimationFrame(raf)
180
260
  }, [autoFocus, editor])
181
261
 
262
+ // The whole field behaves like the text input: clicking its empty area (the padding, or the
263
+ // space beside/below a short line) focuses the editor rather than only the text glyphs being
264
+ // clickable. The input (caret placement) and the send button keep their own click handling.
265
+ const focusEditorFromField = (e: ReactMouseEvent<HTMLDivElement>) => {
266
+ const target = e.target as HTMLElement
267
+ if (target.closest('.tlui-cmt-input') || target.closest('.tlui-cmt-send')) return
268
+ e.preventDefault()
269
+ editor?.commands.focus('end')
270
+ }
271
+
182
272
  return (
183
273
  <div className="tlui-cmt-composer">
184
- {leading ?? <Avatar name={author} />}
185
- <div className="tlui-cmt-composer__field">
186
- <div className="tlui-cmt-composer__input-wrap">
274
+ {leading ?? <Avatar author={author} />}
275
+ <div
276
+ className={[
277
+ 'tlui-cmt-composer__field',
278
+ interactive && expanded && 'tlui-cmt-composer__field--expanded',
279
+ ]
280
+ .filter(Boolean)
281
+ .join(' ')}
282
+ onMouseDown={interactive ? focusEditorFromField : undefined}
283
+ >
284
+ <div className="tlui-cmt-composer__input-wrap" ref={inputWrapRef}>
187
285
  <EditorContent editor={editor} />
188
286
  {isEmpty && (
189
287
  <div className="tlui-cmt-input__placeholder" aria-hidden="true">
190
288
  {placeholder}
191
289
  </div>
192
290
  )}
291
+ <div
292
+ className="tlui-cmt-composer__mirror tlui-cmt-input"
293
+ ref={mirrorRef}
294
+ aria-hidden="true"
295
+ />
193
296
  </div>
194
297
  {interactive && <SendButton label={sendLabel} onClick={onSubmit} disabled={disabled} />}
195
298
  </div>
@@ -1,4 +1,5 @@
1
1
  import { ReactNode } from 'react'
2
+ import { PinCheckIcon } from './icons'
2
3
 
3
4
  /** @public */
4
5
  export interface CommentPinProps {
@@ -10,16 +11,22 @@ export interface CommentPinProps {
10
11
  open?: boolean
11
12
  }
12
13
 
14
+ /* Decorative — the pin's accessible name lives on whatever wraps it. */
15
+ const resolvedCheck = <PinCheckIcon />
16
+
13
17
  /** A canvas comment marker: shows its `children` (or a check when resolved). Purely
14
18
  * presentational — it reflects open/resolved state via CSS; wrap it to make it clickable.
15
19
  * @public @react */
16
20
  export function CommentPin({ children, resolved, open }: CommentPinProps) {
17
21
  const className = [
22
+ // `tlui-cmt-marker` carries the resting shadow and the hover lift — the same treatment a
23
+ // count badge wears, so the two markers behave alike.
24
+ 'tlui-cmt-marker',
18
25
  'tlui-cmt-pin',
19
26
  resolved && 'tlui-cmt-pin--resolved',
20
- open && 'tlui-cmt-pin--open',
27
+ open && 'tlui-cmt-marker--open',
21
28
  ]
22
29
  .filter(Boolean)
23
30
  .join(' ')
24
- return <div className={className}>{resolved ? '✓' : children}</div>
31
+ return <div className={className}>{resolved ? resolvedCheck : children}</div>
25
32
  }
@@ -14,6 +14,9 @@ export interface CommentThreadProps {
14
14
  resolvedBanner?: ReactNode
15
15
  /** Reply composer props. Omit for a read-only thread (no composer). */
16
16
  composer?: CommentComposerProps
17
+ /** Shown at the bottom of the thread (e.g. a sign-in prompt when there's no composer). When
18
+ * both are set, the footer renders after the composer. */
19
+ footer?: ReactNode
17
20
  /** Override how each comment renders. Defaults to `<CommentCard>`. */
18
21
  renderComment?(comment: CommentCardProps, index: number): ReactNode
19
22
  }
@@ -30,13 +33,14 @@ export function CommentThread({
30
33
  headerActions,
31
34
  resolvedBanner,
32
35
  composer,
36
+ footer,
33
37
  renderComment,
34
38
  }: CommentThreadProps) {
35
39
  return (
36
40
  <div className="tlui-cmt-thread">
37
41
  {(header !== undefined || headerActions !== undefined) && (
38
42
  <div className="tlui-cmt-thread__header">
39
- <span className="tlui-cmt-thread__title">{header}</span>
43
+ {header !== undefined && <span className="tlui-cmt-thread__title">{header}</span>}
40
44
  {headerActions !== undefined && (
41
45
  <div className="tlui-cmt-thread__actions">{headerActions}</div>
42
46
  )}
@@ -53,6 +57,7 @@ export function CommentThread({
53
57
  ))}
54
58
  </div>
55
59
  {composer !== undefined && <CommentComposer {...composer} />}
60
+ {footer !== undefined && <div className="tlui-cmt-thread__footer">{footer}</div>}
56
61
  </div>
57
62
  )
58
63
  }
@@ -0,0 +1,31 @@
1
+ import { MouseEvent } from 'react'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { isOpenInNewTabClick } from './comments-list'
4
+
5
+ function click(overrides: Partial<MouseEvent> = {}): MouseEvent {
6
+ return {
7
+ metaKey: false,
8
+ ctrlKey: false,
9
+ shiftKey: false,
10
+ altKey: false,
11
+ button: 0,
12
+ ...overrides,
13
+ } as MouseEvent
14
+ }
15
+
16
+ describe('isOpenInNewTabClick', () => {
17
+ it('treats a plain left click as an in-place select', () => {
18
+ expect(isOpenInNewTabClick(click())).toBe(false)
19
+ })
20
+
21
+ it.each(['metaKey', 'ctrlKey', 'shiftKey', 'altKey'] as const)(
22
+ 'leaves a %s click to the browser',
23
+ (modifier) => {
24
+ expect(isOpenInNewTabClick(click({ [modifier]: true }))).toBe(true)
25
+ }
26
+ )
27
+
28
+ it('leaves non-primary-button clicks to the browser', () => {
29
+ expect(isOpenInNewTabClick(click({ button: 1 }))).toBe(true)
30
+ })
31
+ })
@@ -1,11 +1,15 @@
1
- import { ReactNode } from 'react'
2
- import { Avatar } from './avatar'
1
+ import { Avatar, type CommentAuthor } from '@tldraw/mentions'
2
+ import { Fragment, MouseEvent, ReactNode } from 'react'
3
+ import { useTranslation } from 'tldraw'
3
4
  import { Byline } from './byline'
5
+ import { CheckIcon } from './icons'
6
+ import { Reactions, type ReactionSummary } from './reactions'
7
+ import { replyCountLabel } from './reply-count'
4
8
 
5
9
  /** @public */
6
10
  export interface CommentListItemProps {
7
11
  id: string
8
- author: string
12
+ author: CommentAuthor
9
13
  /** A short preview of the thread — e.g. the first comment's body. */
10
14
  preview: ReactNode
11
15
  /** ISO datetime of the thread's first comment. */
@@ -17,6 +21,28 @@ export interface CommentListItemProps {
17
21
  count?: number
18
22
  /** Whether this thread is the open one. */
19
23
  selected?: boolean
24
+ /** Tallied reactions for the row (a thread's, or a single comment's when the row is one
25
+ * comment), shown as inert pills under the preview. Omit to hide. */
26
+ reactions?: ReactionSummary[]
27
+ /**
28
+ * Link target for the item. When set, the row renders as an anchor so browser affordances
29
+ * (ctrl/cmd-click, middle-click) open it in a new tab; a plain click still calls `onSelect`.
30
+ */
31
+ href?: string
32
+ }
33
+
34
+ /**
35
+ * What a row is rendered with: the item, plus the list-level wiring it needs to be interactive.
36
+ * A custom row gets the same props the default `<CommentListItem>` does, so it can wrap the
37
+ * default rather than reimplement it.
38
+ *
39
+ * @public
40
+ */
41
+ export interface CommentListItemRenderProps extends CommentListItemProps {
42
+ /** Label for a resolved thread's marker on its row. */
43
+ resolvedLabel?: string
44
+ /** Called with the thread id when the row is chosen. */
45
+ onSelect?(id: string): void
20
46
  }
21
47
 
22
48
  /** @public */
@@ -32,8 +58,12 @@ export interface CommentsListProps {
32
58
  empty?: ReactNode
33
59
  /** Label for a resolved thread's marker on its row. Defaults to "Resolved". */
34
60
  resolvedLabel?: string
35
- /** Override how each item renders. Defaults to `<CommentListItem>`. */
36
- renderItem?(item: CommentListItemProps): ReactNode
61
+ /**
62
+ * Override how each item renders. Defaults to `<CommentListItem>`, which is exported — so a
63
+ * row that only adds something can spread these props into it rather than start over. The list
64
+ * supplies the key, so a custom row doesn't need one.
65
+ */
66
+ renderItem?(props: CommentListItemRenderProps): ReactNode
37
67
  }
38
68
 
39
69
  /**
@@ -63,25 +93,25 @@ export function CommentsList({
63
93
  <div className="tlui-cmt-list__empty">{empty}</div>
64
94
  ) : (
65
95
  <div className="tlui-cmt-list__items">
66
- {items.map((item) =>
67
- renderItem ? (
68
- renderItem(item)
96
+ {items.map((item) => {
97
+ const props: CommentListItemRenderProps = { ...item, resolvedLabel, onSelect }
98
+ // A custom row is wrapped rather than keyed directly: it's the consumer's element,
99
+ // and requiring them to remember a key is the kind of thing that only shows up as a
100
+ // console warning in someone else's app.
101
+ return renderItem ? (
102
+ <Fragment key={item.id}>{renderItem(props)}</Fragment>
69
103
  ) : (
70
- <CommentListItem
71
- key={item.id}
72
- {...item}
73
- resolvedLabel={resolvedLabel}
74
- onSelect={onSelect}
75
- />
104
+ <CommentListItem key={item.id} {...props} />
76
105
  )
77
- )}
106
+ })}
78
107
  </div>
79
108
  )}
80
109
  </div>
81
110
  )
82
111
  }
83
112
 
84
- function CommentListItem({
113
+ /** One thread's row in a {@link CommentsList}. @public @react */
114
+ export function CommentListItem({
85
115
  id,
86
116
  author,
87
117
  preview,
@@ -90,26 +120,35 @@ function CommentListItem({
90
120
  page,
91
121
  count,
92
122
  selected,
123
+ reactions,
124
+ href,
93
125
  resolvedLabel = 'Resolved',
94
126
  onSelect,
95
- }: CommentListItemProps & { resolvedLabel?: string; onSelect?(id: string): void }) {
96
- const handleClick = () => {
127
+ }: CommentListItemRenderProps) {
128
+ const msg = useTranslation()
129
+ const handleClick = (e: MouseEvent) => {
130
+ if (href && isOpenInNewTabClick(e)) return
131
+ e.preventDefault()
97
132
  if (onSelect) onSelect(id)
98
133
  }
134
+ const Tag = href ? 'a' : 'button'
135
+ // `count` is the thread's total comments; a reply is every comment after the opening one.
136
+ const replies = count !== undefined ? replyCountLabel(msg, count - 1) : null
99
137
  return (
100
- <button
101
- type="button"
138
+ <Tag
139
+ {...(href ? { href } : { type: 'button' })}
102
140
  className={
103
141
  selected ? 'tlui-cmt-list__item tlui-cmt-list__item--selected' : 'tlui-cmt-list__item'
104
142
  }
105
143
  data-resolved={resolved || undefined}
106
144
  onClick={handleClick}
107
145
  >
108
- <Avatar name={author} />
146
+ <Avatar author={author} />
109
147
  <div className="tlui-cmt-list__item-body">
110
148
  <Byline author={author} date={date} />
111
149
  <div className="tlui-cmt-list__item-preview">{preview}</div>
112
- {(resolved || page !== undefined) && (
150
+ {reactions && <Reactions reactions={reactions} canReact={false} enableHoverList={false} />}
151
+ {(resolved || page !== undefined || replies) && (
113
152
  <div className="tlui-cmt-list__item-meta">
114
153
  {resolved && (
115
154
  <span className="tlui-cmt-list__item-resolved">
@@ -118,26 +157,18 @@ function CommentListItem({
118
157
  </span>
119
158
  )}
120
159
  {page !== undefined && <span className="tlui-cmt-list__item-page">{page}</span>}
160
+ {replies && <span className="tlui-cmt-list__item-replies">{replies}</span>}
121
161
  </div>
122
162
  )}
123
163
  </div>
124
- {count !== undefined && count > 1 && (
125
- <span className="tlui-cmt-list__item-count">{count}</span>
126
- )}
127
- </button>
164
+ </Tag>
128
165
  )
129
166
  }
130
167
 
131
- function CheckIcon() {
132
- return (
133
- <svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
134
- <path
135
- d="M2.5 6.2 4.7 8.4 9.5 3.6"
136
- stroke="currentColor"
137
- strokeWidth="1.5"
138
- strokeLinecap="round"
139
- strokeLinejoin="round"
140
- />
141
- </svg>
142
- )
168
+ /**
169
+ * Whether a click should be left to the browser's link handling (new tab, new window, or download).
170
+ * @public
171
+ */
172
+ export function isOpenInNewTabClick(e: MouseEvent) {
173
+ return e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0
143
174
  }