@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
@@ -22,61 +22,23 @@ __export(comments_overlay_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(comments_overlay_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_mentions = require("@tldraw/mentions");
25
26
  var import_react = require("react");
26
- var import_react_dom = require("react-dom");
27
27
  var import_tldraw = require("tldraw");
28
- var import_computeClusterTable = require("../clustering/computeClusterTable");
29
- var import_runtime = require("../clustering/runtime");
30
- var import_comment_card = require("../ui/comment-card");
31
- var import_comment_composer = require("../ui/comment-composer");
32
- var import_comment_extensions = require("../ui/comment-extensions");
33
- var import_comment_pin = require("../ui/comment-pin");
34
- var import_comment_thread = require("../ui/comment-thread");
35
- var import_count_badge = require("../ui/count-badge");
36
- var import_mention_suggestion = require("../ui/mention-suggestion");
37
- var import_cluster_input = require("./cluster-input");
38
- var import_comment_body = require("./comment-body");
39
- var import_comment_render = require("./comment-render");
28
+ var import_anchor_lifecycle = require("./anchor-lifecycle");
29
+ var import_cluster_badge = require("./cluster-badge");
30
+ var import_cluster_fade = require("./cluster-fade");
31
+ var import_cluster_model = require("./cluster-model");
40
32
  var import_comment_store = require("./comment-store");
41
33
  var import_hooks = require("./hooks");
42
34
  var import_license = require("./license");
43
35
  var import_options = require("./options");
44
- var import_region_options = require("./region-options");
36
+ var import_pending_composer = require("./pending-composer");
37
+ var import_pin_stacking = require("./pin-stacking");
38
+ var import_region_box = require("./region-box");
45
39
  var import_state = require("./state");
46
- var import_thread_state = require("./thread-state");
47
- const stop = (e) => e.stopPropagation();
48
- const initialOf = (name) => ((0, import_tldraw.getFirstCharacter)(name.trim()) || "?").toUpperCase();
49
- const CLUSTER_FADE_MS = 150;
50
- const CLUSTER_EXPAND_ZOOM_MS = 450;
51
- const draftAvatar = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_comment_pin.CommentPin, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
52
- "svg",
53
- {
54
- viewBox: "0 0 24 24",
55
- width: "15",
56
- height: "15",
57
- fill: "none",
58
- stroke: "currentColor",
59
- strokeWidth: "2",
60
- strokeLinecap: "round",
61
- strokeLinejoin: "round",
62
- "aria-hidden": "true",
63
- children: [
64
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 20h9" }),
65
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" })
66
- ]
67
- }
68
- ) });
69
- function toCardProps(comment, props, components) {
70
- const Body = components.CommentBody;
71
- const body = Body ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Body, { comment }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_comment_body.CommentBody, { richText: comment.body, resolveName: props.resolveName });
72
- return {
73
- author: props.resolveName(comment.authorId) ?? import_comment_render.UNKNOWN_AUTHOR,
74
- body,
75
- date: new Date(comment.createdAt).toISOString(),
76
- you: comment.authorId === props.currentUserId,
77
- edited: comment.editedAt != null
78
- };
79
- }
40
+ var import_thread_pin = require("./thread-pin");
41
+ var import_thread_stack = require("./thread-stack");
80
42
  function CanvasComments(props) {
81
43
  const commentingEnabled = (0, import_license.useCommentingEnabled)();
82
44
  if (!commentingEnabled) return null;
@@ -85,184 +47,110 @@ function CanvasComments(props) {
85
47
  function CanvasCommentsLayer(props) {
86
48
  const editor = (0, import_tldraw.useEditor)();
87
49
  const options = (0, import_options.useCommentingOptions)();
88
- const container = (0, import_tldraw.useContainer)();
89
- const regionOptions = (0, import_react.useMemo)(
90
- () => ({ ...import_region_options.DEFAULT_REGION_COMMENT_OPTIONS, ...props.regionOptions }),
91
- [props.regionOptions]
92
- );
93
- (0, import_react.useEffect)(() => (0, import_region_options.setRegionCommentOptions)(editor, regionOptions), [editor, regionOptions]);
94
- const layerRef = (0, import_react.useRef)(null);
95
- (0, import_tldraw.usePassThroughWheelEvents)(layerRef);
96
- (0, import_tldraw.usePassThroughMouseOverEvents)(layerRef);
97
- const deepLinkHandled = (0, import_react.useRef)(false);
98
- const threads = (0, import_hooks.useCommentThreads)(editor);
50
+ const allThreads = (0, import_hooks.useCommentThreads)(editor);
99
51
  const pending = (0, import_state.usePendingComment)();
100
- const openId = (0, import_tldraw.useValue)("open thread id", () => import_state.openThreadId.get(editor), [editor]);
101
- const impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor;
102
- const [heldThreadIds, setHeldThreadIds] = (0, import_react.useState)(EMPTY_SET);
103
- const adoptOnRebuild = (0, import_react.useRef)(false);
104
- const clusterLeaves = (0, import_tldraw.useValue)(
105
- "comment cluster leaves",
106
- () => (0, import_cluster_input.collectClusterLeaves)(
107
- editor,
108
- threads.filter((thread) => !heldThreadIds.has(thread.id)),
109
- import_state.openThreadId.get(editor),
110
- impreciseShapeAnchor
111
- ),
112
- [editor, threads, impreciseShapeAnchor, heldThreadIds]
113
- );
114
- const clusterZoomBounds = (0, import_tldraw.useValue)(
115
- "comment cluster zoom bounds",
116
- () => getClusterZoomBounds(editor),
117
- [editor]
118
- );
119
- const latestModel = (0, import_react.useMemo)(() => {
120
- const table = (0, import_computeClusterTable.computeClusterTable)(clusterLeaves, clusterZoomBounds);
121
- const runtime = (0, import_runtime.createClusterRuntime)(table);
122
- runtime.seed(editor.getZoomLevel());
123
- return { runtime, table };
124
- }, [clusterLeaves, clusterZoomBounds, editor]);
125
- const [renderedModel, setRenderedModel] = (0, import_react.useState)(latestModel);
126
- let clusterModel = renderedModel;
127
- const pageId = (0, import_tldraw.useValue)("comment cluster page", () => editor.getCurrentPageId(), [editor]);
128
- const pageRef = (0, import_react.useRef)(pageId);
129
- if (pageRef.current !== pageId) {
130
- pageRef.current = pageId;
131
- adoptOnRebuild.current = false;
132
- latestModel.runtime.seed(editor.getZoomLevel());
133
- if (heldThreadIds.size > 0) setHeldThreadIds(EMPTY_SET);
134
- setRenderedModel(latestModel);
135
- clusterModel = latestModel;
136
- }
137
- const rejoinPending = heldThreadIds.size === 0 && adoptOnRebuild.current;
138
- if (renderedModel !== latestModel && rejoinPending) {
139
- adoptOnRebuild.current = false;
140
- latestModel.runtime.seedFrom(editor.getZoomLevel(), renderedModel.runtime.getVisible());
141
- setRenderedModel(latestModel);
142
- clusterModel = latestModel;
143
- } else if (heldThreadIds.size === 0 && renderedModel === latestModel) {
144
- adoptOnRebuild.current = false;
145
- }
146
- const newlyMovedIds = findMovedClusteredLeafIds(clusterModel, latestModel);
147
- if (newlyMovedIds.length > 0) {
148
- const next = new Set(heldThreadIds);
149
- for (const id of newlyMovedIds) next.add(id);
150
- setHeldThreadIds(next);
151
- }
152
- {
153
- const latestLeafIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id));
154
- for (const leaf of clusterModel.table.leaves) {
155
- if (!latestLeafIds.has(leaf.id)) {
156
- clusterModel.runtime.detachLeaf(leaf.id);
157
- }
158
- }
159
- }
160
- (0, import_react.useEffect)(() => {
161
- if (heldThreadIds.size === 0) return;
162
- let lastZoom = editor.getZoomLevel();
163
- return (0, import_tldraw.react)("rejoin moved comment pins on zoom out", () => {
164
- const zoom = editor.getZoomLevel();
165
- const prevZoom = lastZoom;
166
- lastZoom = zoom;
167
- if (zoom >= prevZoom) return;
168
- adoptOnRebuild.current = true;
169
- setHeldThreadIds(EMPTY_SET);
170
- });
171
- }, [heldThreadIds, editor]);
52
+ const canComment = (0, import_options.useCanComment)(props.currentUserId);
53
+ const canRenderComposer = canComment || options.components.ComposerFallback != null;
54
+ const showPendingComposer = pending != null && canRenderComposer;
172
55
  (0, import_react.useEffect)(() => {
173
- if (clusterModel === latestModel) return;
174
- let lastZoom = editor.getZoomLevel();
175
- return (0, import_tldraw.react)("adopt pending cluster model on zoom out", () => {
176
- const zoom = editor.getZoomLevel();
177
- const prevZoom = lastZoom;
178
- lastZoom = zoom;
179
- if (zoom >= prevZoom) return;
180
- latestModel.runtime.seedFrom(zoom, clusterModel.runtime.getVisible());
181
- setRenderedModel(latestModel);
182
- });
183
- }, [clusterModel, latestModel, editor]);
184
- const partitionVersion = clusterModel.runtime.version;
185
- const orphanThreads = (0, import_react.useMemo)(() => {
186
- if (clusterModel === latestModel) return [];
187
- const displayed = /* @__PURE__ */ new Set();
188
- for (const node of clusterModel.runtime.getVisible().values()) {
189
- for (const member of node.members) displayed.add(member);
190
- }
191
- const latestIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id));
192
- return threads.filter((thread) => latestIds.has(thread.id) && !displayed.has(thread.id));
193
- }, [clusterModel, latestModel, threads, partitionVersion]);
194
- const heldThreads = (0, import_react.useMemo)(
195
- () => threads.filter((thread) => heldThreadIds.has(thread.id) && thread.id !== openId),
196
- [threads, heldThreadIds, openId]
197
- );
198
- (0, import_tldraw.useValue)(
199
- "comment cluster version",
200
- () => {
201
- clusterModel.runtime.onCamera(editor.getZoomLevel());
202
- return clusterModel.runtime.version;
203
- },
204
- [clusterModel, editor]
56
+ if (pending && !showPendingComposer) import_state.pendingComment.set(editor, null);
57
+ }, [editor, pending, showPendingComposer]);
58
+ const openId = (0, import_tldraw.useValue)("open thread id", () => import_state.openThreadId.get(editor), [editor]);
59
+ const showResolved = (0, import_tldraw.useValue)("show resolved", () => import_state.sidebarFilters.get(editor).showResolved, [
60
+ editor
61
+ ]);
62
+ const threads = (0, import_react.useMemo)(
63
+ () => allThreads.filter((t) => showResolved || t.resolved == null || t.id === openId),
64
+ [allThreads, showResolved, openId]
205
65
  );
206
- const visibleNodes = (0, import_react.useMemo)(() => {
207
- return Array.from(clusterModel.runtime.getVisible().values());
208
- }, [clusterModel, partitionVersion]);
209
- const fadeNodes = useFadeVisibleNodes(visibleNodes, clusterModel);
66
+ (0, import_react.useEffect)(() => (0, import_anchor_lifecycle.registerCommentAnchorLifecycle)(editor), [editor]);
67
+ const {
68
+ model: clusterModel,
69
+ zoomBounds: clusterZoomBounds,
70
+ fadeNodes,
71
+ orphanThreads,
72
+ heldThreads
73
+ } = (0, import_cluster_model.useClusterModel)(editor, threads, openId);
210
74
  const threadsById = (0, import_react.useMemo)(
211
75
  () => new Map(threads.map((thread) => [thread.id, thread])),
212
76
  [threads]
213
77
  );
78
+ const pinStacksRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
79
+ const pinStacks = (0, import_tldraw.useValue)(
80
+ "comment pin stacks",
81
+ () => {
82
+ const stacks = (0, import_pin_stacking.computePinStacks)(editor, threads);
83
+ if ((0, import_pin_stacking.pinStacksEqual)(pinStacksRef.current, stacks)) return pinStacksRef.current;
84
+ pinStacksRef.current = stacks;
85
+ return stacks;
86
+ },
87
+ [editor, threads]
88
+ );
214
89
  const openThread = openId ? threadsById.get(openId) : null;
215
90
  const hidden = (0, import_tldraw.useValue)("comments hidden", () => import_state.commentsHidden.get(editor), [editor]);
216
91
  (0, import_react.useEffect)(() => {
217
92
  return () => {
218
93
  import_state.openThreadId.set(editor, null);
94
+ import_state.openStackId.set(editor, null);
219
95
  import_state.pendingComment.set(editor, null);
96
+ import_state.revealThreadRequest.set(editor, null);
220
97
  };
221
98
  }, [editor]);
99
+ const openStackKeyIsStale = (0, import_tldraw.useValue)(
100
+ "open stack key stale",
101
+ () => {
102
+ const key = import_state.openStackId.get(editor);
103
+ if (!key) return false;
104
+ return !(0, import_pin_stacking.isOpenStackKeyLive)(editor, key, pinStacks, threadsById);
105
+ },
106
+ [editor, pinStacks, threadsById]
107
+ );
222
108
  (0, import_react.useEffect)(() => {
223
- if (deepLinkHandled.current) return;
224
- const id = new URLSearchParams(window.location.search).get("comment");
225
- if (!id) {
226
- deepLinkHandled.current = true;
227
- return;
228
- }
229
- const record = (0, import_comment_store.getCommentRecord)(editor, id);
230
- if (!record) return;
231
- let thread;
232
- if (record.typeName === "comment") {
233
- thread = threadsById.get(record.threadId);
234
- } else {
235
- thread = record;
236
- }
237
- if (!thread) return;
238
- deepLinkHandled.current = true;
239
- revealDeepLinkedThread(
240
- editor,
241
- thread,
242
- clusterModel.table,
243
- clusterZoomBounds,
244
- options,
245
- impreciseShapeAnchor
246
- );
247
- import_state.openThreadId.set(editor, thread.id);
248
- }, [clusterModel.table, clusterZoomBounds, editor, threadsById, impreciseShapeAnchor, options]);
249
- const zoomToClusterSplit = (0, import_react.useCallback)(
250
- (node) => {
251
- const event = clusterModel.table.events.find((e) => e.result.id === node.id);
252
- if (!event || !Number.isFinite(event.zSplit)) return;
253
- const zoom = clamp(
254
- event.zSplit * options.clusterSplitZoomFactor,
255
- clusterZoomBounds.minZoom,
256
- clusterZoomBounds.maxZoom
109
+ if (openStackKeyIsStale) import_state.openStackId.set(editor, null);
110
+ }, [editor, openStackKeyIsStale]);
111
+ const requestedRevealThread = (0, import_tldraw.useValue)(
112
+ "requested reveal thread",
113
+ () => {
114
+ const id = import_state.revealThreadRequest.get(editor);
115
+ if (!id) return null;
116
+ const record = (0, import_comment_store.getCommentRecord)(editor, id);
117
+ if (!record) return null;
118
+ const thread = record.typeName === "comment" ? (0, import_comment_store.getCommentRecord)(editor, record.threadId) : record;
119
+ return thread?.typeName === "comment-thread" ? thread : null;
120
+ },
121
+ [editor]
122
+ );
123
+ (0, import_react.useEffect)(() => {
124
+ if (!requestedRevealThread) return;
125
+ import_state.revealThreadRequest.set(editor, null);
126
+ import_state.commentsHidden.set(editor, false);
127
+ (0, import_cluster_model.revealThreadPin)(editor, requestedRevealThread, clusterModel.table, clusterZoomBounds, options);
128
+ import_state.openThreadId.set(editor, requestedRevealThread.id);
129
+ }, [requestedRevealThread, clusterModel.table, clusterZoomBounds, editor, options]);
130
+ const revealClusteredThread = (0, import_react.useCallback)(
131
+ (thread) => {
132
+ (0, import_cluster_model.revealThreadPin)(
133
+ editor,
134
+ thread,
135
+ clusterModel.table,
136
+ clusterZoomBounds,
137
+ options,
138
+ import_cluster_model.CLUSTER_EXPAND_ZOOM_MS
257
139
  );
258
- centerOnPointAtZoom(editor, node.centroid, zoom, CLUSTER_EXPAND_ZOOM_MS);
140
+ import_state.openThreadId.set(editor, thread.id);
259
141
  },
260
- [clusterModel, clusterZoomBounds, editor, options]
142
+ [clusterModel.table, clusterZoomBounds, editor, options]
143
+ );
144
+ const expandCluster = (0, import_react.useCallback)(
145
+ (node) => {
146
+ (0, import_cluster_model.zoomToClusterSplit)(editor, clusterModel.table, clusterZoomBounds, node);
147
+ },
148
+ [clusterModel.table, clusterZoomBounds, editor]
261
149
  );
262
150
  (0, import_react.useEffect)(() => {
263
151
  const onKeyDown = (e) => {
264
152
  if (e.key !== "Escape" || import_state.openThreadId.get(editor) === null) return;
265
- if ((0, import_mention_suggestion.isMentionPickerOpen)()) return;
153
+ if ((0, import_mentions.isMentionPickerOpen)()) return;
266
154
  const target = e.target;
267
155
  if (target && target.closest(".tlui-cmt-editing")) return;
268
156
  import_state.openThreadId.set(editor, null);
@@ -284,813 +172,72 @@ function CanvasCommentsLayer(props) {
284
172
  return () => document.removeEventListener("keydown", onKeyDown, true);
285
173
  }, [editor]);
286
174
  if (hidden) return null;
287
- return (0, import_react_dom.createPortal)(
288
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: layerRef, className: "tlui-cmt-canvas-layer", children: [
289
- options.enableClustering ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
290
- fadeNodes.map(({ node, phase }) => {
291
- let content;
292
- if (node.count === 1) {
293
- const thread = threadsById.get(node.id);
294
- if (!thread) return null;
295
- content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
296
- ThreadPin,
297
- {
298
- editor,
299
- thread,
300
- ...props,
301
- regionOptions
302
- }
303
- );
304
- } else {
305
- content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClusterBadge, { editor, node, onExpand: zoomToClusterSplit });
306
- }
307
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: clusterFadeClassName(phase), children: content }, `cluster-fade:${node.id}`);
308
- }),
309
- orphanThreads.map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
310
- ThreadPin,
311
- {
312
- editor,
313
- thread,
314
- ...props,
315
- regionOptions
316
- },
317
- thread.id
318
- )),
319
- heldThreads.map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
320
- ThreadPin,
321
- {
322
- editor,
323
- thread,
324
- ...props,
325
- regionOptions
326
- },
327
- thread.id
328
- ))
329
- ] }) : (
330
- // Clustering off: every thread renders as its own live pin (each returns null when it's
331
- // not on the current page or its anchor is missing). The open thread is excluded here and
332
- // rendered once below, mirroring how the clustering path keeps it out of the cluster leaves —
333
- // otherwise it would mount a second, stacked pin.
334
- threads.filter((thread) => thread.id !== openId).map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
335
- ThreadPin,
336
- {
337
- editor,
338
- thread,
339
- ...props,
340
- regionOptions
341
- },
342
- thread.id
343
- ))
344
- ),
345
- openThread && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
346
- ThreadPin,
347
- {
348
- editor,
349
- thread: openThread,
350
- ...props,
351
- regionOptions
352
- },
353
- `open:${openThread.id}`
354
- ),
355
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RegionDraftBox, { editor }),
356
- pending?.anchor.type === "region" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RegionBox, { editor, box: pending.anchor }),
357
- pending && props.currentUserId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PendingComposer, { editor, pending, ...props })
358
- ] }),
359
- container
360
- );
361
- }
362
- const EMPTY_SET = /* @__PURE__ */ new Set();
363
- const MOVED_LEAF_EPSILON = 1e-6;
364
- function useFadeVisibleNodes(nodes, resetKey) {
365
- const resetKeyRef = (0, import_react.useRef)(resetKey);
366
- const didReset = resetKeyRef.current !== resetKey;
367
- if (didReset) {
368
- resetKeyRef.current = resetKey;
369
- }
370
- const [fadeNodes, setFadeNodes] = (0, import_react.useState)(() => toPresentFadeNodes(nodes));
371
- const renderedNodes = didReset ? toPresentFadeNodes(nodes) : fadeNodes;
372
- (0, import_react.useEffect)(() => {
373
- setFadeNodes(toPresentFadeNodes(nodes));
374
- }, [resetKey]);
375
- (0, import_react.useEffect)(() => {
376
- if (didReset) return;
377
- setFadeNodes((previous) => reconcileFadeNodes(previous, nodes));
378
- }, [didReset, nodes]);
379
- const hasEntering = renderedNodes.some((item) => item.phase === "entering");
380
- (0, import_react.useEffect)(() => {
381
- if (!hasEntering) return;
382
- const frame = requestClusterFadeFrame(() => {
383
- setFadeNodes(
384
- (previous) => previous.map((item) => item.phase === "entering" ? { ...item, phase: "present" } : item)
385
- );
386
- });
387
- return () => cancelClusterFadeFrame(frame);
388
- }, [hasEntering, renderedNodes]);
389
- const hasExiting = renderedNodes.some((item) => item.phase === "exiting");
390
- (0, import_react.useEffect)(() => {
391
- if (!hasExiting) return;
392
- const timeout = window.setTimeout(() => {
393
- setFadeNodes((previous) => previous.filter((item) => item.phase !== "exiting"));
394
- }, CLUSTER_FADE_MS);
395
- return () => window.clearTimeout(timeout);
396
- }, [hasExiting, renderedNodes]);
397
- return renderedNodes;
398
- }
399
- function toPresentFadeNodes(nodes) {
400
- return nodes.map((node) => ({ node, phase: "present" }));
401
- }
402
- function reconcileFadeNodes(previous, nextNodes) {
403
- const previousById = new Map(previous.map((item) => [item.node.id, item]));
404
- const nextIds = new Set(nextNodes.map((node) => node.id));
405
- const next = [];
406
- for (const node of nextNodes) {
407
- const previousItem = previousById.get(node.id);
408
- next.push({
409
- node,
410
- phase: previousItem && previousItem.phase !== "exiting" ? previousItem.phase : previousItem ? "present" : "entering"
411
- });
412
- }
413
- for (const item of previous) {
414
- if (nextIds.has(item.node.id)) continue;
415
- next.push(item.phase === "exiting" ? item : { ...item, phase: "exiting" });
416
- }
417
- return next;
418
- }
419
- function requestClusterFadeFrame(callback) {
420
- if (typeof requestAnimationFrame === "function") return requestAnimationFrame(callback);
421
- return window.setTimeout(() => callback(0), 16);
422
- }
423
- function cancelClusterFadeFrame(frame) {
424
- if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(frame);
425
- else window.clearTimeout(frame);
426
- }
427
- function clusterFadeClassName(phase) {
428
- return `tlui-cmt-cluster-fade tlui-cmt-cluster-fade--${phase}`;
429
- }
430
- function findMovedClusteredLeafIds(rendered, latest) {
431
- if (rendered.table === latest.table) return [];
432
- const visible = rendered.runtime.getVisible();
433
- const latestById = new Map(latest.table.leaves.map((leaf) => [leaf.id, leaf]));
434
- const moved = [];
435
- for (const leaf of rendered.table.leaves) {
436
- if (visible.has(leaf.id)) continue;
437
- const current = latestById.get(leaf.id);
438
- if (!current) continue;
439
- if (Math.abs(current.centroid.x - leaf.centroid.x) > MOVED_LEAF_EPSILON || Math.abs(current.centroid.y - leaf.centroid.y) > MOVED_LEAF_EPSILON) {
440
- moved.push(leaf.id);
441
- }
442
- }
443
- return moved;
444
- }
445
- function getClusterZoomBounds(editor) {
446
- const cameraOptions = editor.getCameraOptions();
447
- const baseZoom = cameraOptions.constraints ? editor.getBaseZoom() : 1;
448
- const zoomSteps = cameraOptions.zoomSteps;
449
- return {
450
- minZoom: zoomSteps[0] * baseZoom,
451
- maxZoom: zoomSteps[zoomSteps.length - 1] * baseZoom
175
+ const stackGroupOf = (node) => {
176
+ const group = pinStacks.get(node.members[0]);
177
+ if (!group) return null;
178
+ return node.members.every((id) => group.includes(id)) ? group : null;
452
179
  };
453
- }
454
- function revealDeepLinkedThread(editor, thread, table, zoomBounds, options, impreciseShapeAnchor) {
455
- if (thread.pageId !== editor.getCurrentPageId()) {
456
- editor.setCurrentPage(thread.pageId);
457
- }
458
- const point = (0, import_thread_state.anchorPagePoint)(editor, thread.anchor, impreciseShapeAnchor);
459
- if (!point) return;
180
+ const renderedThreadIds = /* @__PURE__ */ new Set();
460
181
  if (options.enableClustering) {
461
- const parentEvent = findDirectParentEvent(table, thread.id);
462
- if (parentEvent && Number.isFinite(parentEvent.zSplit) && parentEvent.zSplit <= zoomBounds.maxZoom) {
463
- const zoom = clamp(
464
- parentEvent.zSplit * options.clusterSplitZoomFactor,
465
- zoomBounds.minZoom,
466
- zoomBounds.maxZoom
467
- );
468
- centerOnPointAtZoom(editor, point, zoom);
469
- return;
182
+ for (const { node } of fadeNodes) {
183
+ if (node.count === 1) renderedThreadIds.add(node.id);
184
+ else if (stackGroupOf(node)) for (const id of node.members) renderedThreadIds.add(id);
470
185
  }
186
+ for (const thread of orphanThreads) renderedThreadIds.add(thread.id);
187
+ for (const thread of heldThreads) renderedThreadIds.add(thread.id);
188
+ } else {
189
+ for (const thread of threads) renderedThreadIds.add(thread.id);
471
190
  }
472
- editor.centerOnPoint(point, { animation: { duration: 200 } });
473
- }
474
- function findDirectParentEvent(table, threadId) {
475
- return table.events.find((event) => event.children.some((child) => child.id === threadId));
476
- }
477
- function centerOnPointAtZoom(editor, point, zoom, duration = 200) {
478
- const viewport = editor.getViewportScreenBounds();
479
- editor.setCamera(
480
- {
481
- x: viewport.w / (2 * zoom) - point.x,
482
- y: viewport.h / (2 * zoom) - point.y,
483
- z: zoom
484
- },
485
- { animation: { duration } }
486
- );
487
- }
488
- function clamp(value, min, max) {
489
- return Math.max(min, Math.min(max, value));
490
- }
491
- const ClusterBadge = (0, import_react.memo)(function ClusterBadge2({
492
- editor,
493
- node,
494
- onExpand
495
- }) {
496
- const point = (0, import_tldraw.useValue)(
497
- "cluster badge point",
498
- () => {
499
- const pagePoint = editor.pageToViewport(node.centroid);
500
- if (!isInInflatedViewport(editor, pagePoint)) return null;
501
- return pagePoint;
502
- },
503
- [editor, node]
504
- );
505
- if (!point) return null;
506
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
507
- "div",
508
- {
509
- className: "tlui-cmt-canvas-cluster",
510
- style: { left: point.x, top: point.y },
511
- onPointerDown: stop,
512
- onClick: (e) => {
513
- e.stopPropagation();
514
- onExpand(node);
515
- },
516
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_count_badge.CountBadge, { count: node.count })
517
- }
518
- );
519
- });
520
- function isInInflatedViewport(editor, point) {
521
- const viewport = editor.getViewportScreenBounds();
522
- const margin = (0, import_options.getCommentingOptions)(editor).clusterCullMargin;
523
- return point.x >= -margin && point.y >= -margin && point.x <= viewport.w + margin && point.y <= viewport.h + margin;
524
- }
525
- function ThreadPopover({
526
- container,
527
- style,
528
- children
529
- }) {
530
- const ref = (0, import_react.useRef)(null);
531
- (0, import_tldraw.usePassThroughWheelEvents)(ref);
532
- (0, import_tldraw.usePassThroughMouseOverEvents)(ref);
533
- return (0, import_react_dom.createPortal)(
534
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className: "tlui-cmt-canvas-popover", style, onPointerDown: stop, children }),
535
- container
536
- );
537
- }
538
- function RegionBox({
539
- editor,
540
- box,
541
- movable,
542
- onPreview,
543
- onCommit
544
- }) {
545
- const rect = (0, import_tldraw.useValue)(
546
- "region rect",
547
- () => {
548
- const topLeft = editor.pageToViewport({ x: box.x, y: box.y });
549
- const zoom = editor.getZoomLevel();
550
- return { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom };
551
- },
552
- [editor, box.x, box.y, box.w, box.h]
553
- );
554
- const grabRef = (0, import_react.useRef)(null);
555
- const translated = (e) => {
556
- const g = grabRef.current;
557
- const p = editor.screenToPage({ x: e.clientX, y: e.clientY });
558
- return { ...g.box, x: g.box.x + (p.x - g.page.x), y: g.box.y + (p.y - g.page.y) };
559
- };
560
- const startMove = (e) => {
561
- e.stopPropagation();
562
- grabRef.current = { page: editor.screenToPage({ x: e.clientX, y: e.clientY }), box };
563
- e.currentTarget.setPointerCapture(e.pointerId);
564
- };
565
- const onMove = (e) => {
566
- if (grabRef.current) onPreview?.(translated(e));
567
- };
568
- const endMove = (e) => {
569
- if (!grabRef.current) return;
570
- const bounds = translated(e);
571
- grabRef.current = null;
572
- if (e.currentTarget.hasPointerCapture(e.pointerId))
573
- e.currentTarget.releasePointerCapture(e.pointerId);
574
- onCommit?.(bounds);
575
- };
576
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
577
- "div",
578
- {
579
- className: movable ? "tlui-cmt-canvas-region tlui-cmt-canvas-region--movable" : "tlui-cmt-canvas-region",
580
- style: rect,
581
- onPointerDown: movable ? startMove : void 0,
582
- onPointerMove: movable ? onMove : void 0,
583
- onPointerUp: movable ? endMove : void 0
584
- }
585
- );
586
- }
587
- function RegionDraftBox({ editor }) {
588
- const box = (0, import_tldraw.useValue)("region draft", () => import_state.regionDraft.get(editor), [editor]);
589
- if (!box) return null;
590
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RegionBox, { editor, box });
591
- }
592
- const REGION_CORNERS = [
593
- { x: 0, y: 0, cursor: "nwse-resize" },
594
- { x: 1, y: 0, cursor: "nesw-resize" },
595
- { x: 0, y: 1, cursor: "nesw-resize" },
596
- { x: 1, y: 1, cursor: "nwse-resize" }
597
- ];
598
- const REGION_EDGES = [
599
- { x: 0.5, y: 0, cursor: "ns-resize" },
600
- { x: 1, y: 0.5, cursor: "ew-resize" },
601
- { x: 0.5, y: 1, cursor: "ns-resize" },
602
- { x: 0, y: 0.5, cursor: "ew-resize" }
603
- ];
604
- const REGION_HANDLE_MARGIN_PX = 12;
605
- function resizeRegion(box, handle, cursor) {
606
- const controlsX = handle.x !== 0.5;
607
- const controlsY = handle.y !== 0.5;
608
- const fixedX = box.x + (1 - handle.x) * box.w;
609
- const fixedY = box.y + (1 - handle.y) * box.h;
610
- return {
611
- x: controlsX ? Math.min(fixedX, cursor.x) : box.x,
612
- y: controlsY ? Math.min(fixedY, cursor.y) : box.y,
613
- w: controlsX ? Math.abs(cursor.x - fixedX) : box.w,
614
- h: controlsY ? Math.abs(cursor.y - fixedY) : box.h
615
- };
616
- }
617
- function RegionResizeHandles({
618
- editor,
619
- box,
620
- handles,
621
- onPreview,
622
- onCommit
623
- }) {
624
- const boxRef = (0, import_react.useRef)(null);
625
- const points = (0, import_tldraw.useValue)(
626
- "region handle points",
627
- () => handles.map((h) => {
628
- const p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h });
629
- return { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y };
630
- }),
631
- [editor, box.x, box.y, box.w, box.h, handles]
632
- );
633
- const startResize = (e) => {
634
- e.stopPropagation();
635
- boxRef.current = box;
636
- e.currentTarget.setPointerCapture(e.pointerId);
637
- };
638
- const resizedTo = (h, e) => resizeRegion(boxRef.current, h, editor.screenToPage({ x: e.clientX, y: e.clientY }));
639
- const onResize = (h) => (e) => {
640
- if (boxRef.current) onPreview(resizedTo(h, e));
641
- };
642
- const endResize = (h) => (e) => {
643
- if (!boxRef.current) return;
644
- const bounds = resizedTo(h, e);
645
- boxRef.current = null;
646
- if (e.currentTarget.hasPointerCapture(e.pointerId))
647
- e.currentTarget.releasePointerCapture(e.pointerId);
648
- onCommit(bounds);
649
- };
650
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: points.map((h) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
651
- "div",
652
- {
653
- className: "tlui-cmt-canvas-region-handle",
654
- style: { left: h.left, top: h.top, cursor: h.cursor },
655
- onPointerDown: startResize,
656
- onPointerMove: onResize(h),
657
- onPointerUp: endResize(h)
658
- },
659
- h.key
660
- )) });
661
- }
662
- const ThreadPin = (0, import_react.memo)(function ThreadPin2({
663
- editor,
664
- thread,
665
- regionOptions,
666
- ...props
667
- }) {
668
- const {
669
- currentUserId,
670
- resolveName,
671
- onPostComment,
672
- isCommentUnread,
673
- onCommentRead,
674
- getMentionSuggestions,
675
- renderMentionSuggestion
676
- } = props;
677
- const options = (0, import_options.useCommentingOptions)();
678
- const impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor;
679
- const container = (0, import_tldraw.useContainer)();
680
- const comments = (0, import_hooks.useThreadComments)(editor, thread.id);
681
- const msg = (0, import_tldraw.useTranslation)();
682
- const open = (0, import_tldraw.useValue)("thread open", () => import_state.openThreadId.get(editor) === thread.id, [
683
- editor,
684
- thread.id
685
- ]);
686
- const [reply, setReply] = (0, import_react.useState)(import_comment_extensions.EMPTY_COMMENT);
687
- const [editingId, setEditingId] = (0, import_react.useState)(null);
688
- const [editText, setEditText] = (0, import_react.useState)(import_comment_extensions.EMPTY_COMMENT);
689
- const [dragPagePoint, setDragPagePoint] = (0, import_react.useState)(null);
690
- const [resizeBounds, setResizeBounds] = (0, import_react.useState)(null);
691
- const [pinHovered, setPinHovered] = (0, import_react.useState)(false);
692
- const pointerInRegion = (0, import_tldraw.useValue)(
693
- "pointer in region",
694
- () => {
695
- if (thread.anchor.type !== "region" || thread.pageId !== editor.getCurrentPageId())
696
- return false;
697
- const m = REGION_HANDLE_MARGIN_PX / editor.getZoomLevel();
698
- const p = editor.inputs.getCurrentPagePoint();
699
- const a = thread.anchor;
700
- return p.x >= a.x - m && p.x <= a.x + a.w + m && p.y >= a.y - m && p.y <= a.y + a.h + m;
701
- },
702
- [editor, thread.anchor, thread.pageId]
703
- );
704
- const revealed = open || resizeBounds != null || regionOptions.reveal === "pointer" && pointerInRegion || regionOptions.reveal === "pin-hover" && pinHovered;
705
- const resizeHandles = (0, import_react.useMemo)(
706
- () => regionOptions.resize === "edges" ? REGION_EDGES : REGION_CORNERS.filter(
707
- (c) => c.x !== regionOptions.pinCorner.x || c.y !== regionOptions.pinCorner.y
708
- ),
709
- [regionOptions.resize, regionOptions.pinCorner]
710
- );
711
- const dragRef = (0, import_react.useRef)(null);
712
- const markerRef = (0, import_react.useRef)(null);
713
- (0, import_react.useEffect)(() => {
714
- if (!open) return;
715
- const onPointerDown = (e) => {
716
- const target = e.target;
717
- if (!target) return;
718
- if (target.closest(".tlui-cmt-canvas-popover")) return;
719
- const marker = markerRef.current;
720
- if (marker && marker.contains(target)) return;
721
- if (target.closest(".tlui-cmt-canvas-region-handle, .tlui-cmt-canvas-region--movable")) return;
722
- if (target.closest(".tlui-menu, [data-radix-popper-content-wrapper], .tlui-cmt-mention-popup"))
723
- return;
724
- import_state.openThreadId.set(editor, null);
725
- };
726
- document.addEventListener("pointerdown", onPointerDown, true);
727
- return () => document.removeEventListener("pointerdown", onPointerDown, true);
728
- }, [open, editor]);
729
- const point = (0, import_tldraw.useValue)(
730
- "pin point",
731
- () => {
732
- if (thread.pageId !== editor.getCurrentPageId()) return null;
733
- const pagePoint = (0, import_thread_state.anchorPagePoint)(editor, thread.anchor, impreciseShapeAnchor);
734
- return pagePoint ? editor.pageToViewport(pagePoint) : null;
735
- },
736
- [editor, thread.anchor, thread.pageId, impreciseShapeAnchor]
737
- );
738
- const visible = point !== null;
739
- (0, import_react.useEffect)(() => {
740
- if (!open || !visible || !isCommentUnread || !onCommentRead) return;
741
- for (const comment of comments) {
742
- if (isCommentUnread(comment.id)) {
743
- onCommentRead(comment.id);
744
- }
191
+ if (openThread) renderedThreadIds.add(openThread.id);
192
+ const renderThreadPin = (thread) => {
193
+ const group = pinStacks.get(thread.id);
194
+ if (group) {
195
+ const owner = group.find((id) => renderedThreadIds.has(id));
196
+ if (owner !== thread.id) return null;
197
+ const stackThreads = group.map((id) => threadsById.get(id)).filter((t) => t !== void 0);
198
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_thread_stack.ThreadStackPin, { editor, threads: stackThreads, ...props });
745
199
  }
746
- }, [open, visible, comments, isCommentUnread, onCommentRead]);
747
- if (!point) return null;
748
- const postReply = () => {
749
- if ((0, import_comment_extensions.isCommentEmpty)(reply) || !currentUserId) return;
750
- (0, import_state.commitCommentMutation)(editor, () => {
751
- const comment = (0, import_tldraw.createComment)({
752
- threadId: thread.id,
753
- pageId: thread.pageId,
754
- authorId: currentUserId,
755
- body: reply
756
- });
757
- (0, import_comment_store.putCommentRecords)(editor, [comment]);
758
- if (onPostComment) onPostComment(comment);
759
- });
760
- setReply(import_comment_extensions.EMPTY_COMMENT);
761
- };
762
- const toggleResolve = () => {
763
- if (!currentUserId) return;
764
- (0, import_state.commitCommentMutation)(editor, () => {
765
- (0, import_comment_store.putCommentRecords)(editor, [
766
- {
767
- ...thread,
768
- resolved: thread.resolved ? null : { at: Date.now(), by: currentUserId }
769
- }
770
- ]);
771
- });
772
- };
773
- const deleteThread = () => {
774
- import_state.openThreadId.set(editor, null);
775
- (0, import_state.commitCommentMutation)(
776
- editor,
777
- () => (0, import_comment_store.removeCommentRecords)(editor, [thread.id, ...comments.map((c) => c.id)])
778
- );
779
- };
780
- const startEdit = (comment) => {
781
- setEditingId(comment.id);
782
- setEditText(comment.body);
783
- };
784
- const saveEdit = () => {
785
- const comment = comments.find((c) => c.id === editingId);
786
- if (!comment || (0, import_comment_extensions.isCommentEmpty)(editText)) return;
787
- (0, import_state.commitCommentMutation)(editor, () => {
788
- (0, import_comment_store.putCommentRecords)(editor, [{ ...comment, body: editText, editedAt: Date.now() }]);
789
- });
790
- setEditingId(null);
791
- };
792
- const renderComment = (card, index) => {
793
- const comment = comments[index];
794
- if (editingId === comment.id) {
795
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
796
- "div",
797
- {
798
- className: "tlui-cmt-editing",
799
- onKeyDown: (e) => {
800
- if (e.key === "Escape") {
801
- setEditingId(null);
802
- e.stopPropagation();
803
- }
804
- },
805
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
806
- import_comment_composer.CommentComposer,
200
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_thread_pin.ThreadPin, { editor, thread, ...props });
201
+ };
202
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.EditorPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "tlui-cmt-canvas-layer", children: [
203
+ options.enableClustering ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
204
+ fadeNodes.map(({ node, phase }) => {
205
+ let content;
206
+ const stackGroup = node.count > 1 ? stackGroupOf(node) : null;
207
+ if (node.count === 1) {
208
+ const thread = threadsById.get(node.id);
209
+ if (!thread) return null;
210
+ content = renderThreadPin(thread);
211
+ } else if (stackGroup) {
212
+ const owner = stackGroup.find((id) => renderedThreadIds.has(id));
213
+ content = owner && node.members.includes(owner) ? renderThreadPin(threadsById.get(owner)) : null;
214
+ } else {
215
+ content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
216
+ import_cluster_badge.ClusterBadge,
807
217
  {
808
- author: card.author,
809
- placeholder: msg("comments.edit-placeholder"),
810
- value: editText,
811
- onChange: setEditText,
812
- onSubmit: saveEdit,
813
- sendLabel: msg("comments.save"),
814
- disabled: (0, import_comment_extensions.isCommentEmpty)(editText),
815
- getMentionSuggestions,
816
- renderMentionSuggestion,
817
- autoFocus: true
218
+ editor,
219
+ node,
220
+ onExpand: expandCluster,
221
+ onSelectThread: revealClusteredThread,
222
+ threadsById,
223
+ currentUserId: props.currentUserId,
224
+ resolveAuthor: props.resolveAuthor
818
225
  }
819
- )
226
+ );
820
227
  }
821
- );
822
- }
823
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
824
- import_comment_card.CommentCard,
825
- {
826
- ...card,
827
- actions: comment.authorId === currentUserId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
828
- "button",
829
- {
830
- className: "tlui-cmt-thread__action",
831
- title: msg("comments.edit"),
832
- onClick: () => startEdit(comment),
833
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiIcon, { icon: "dots-horizontal", label: msg("comments.edit"), small: true })
834
- }
835
- ) : void 0
836
- }
837
- );
838
- };
839
- const headerActions = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
840
- currentUserId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
841
- "button",
842
- {
843
- className: "tlui-cmt-thread__action",
844
- title: msg(thread.resolved ? "comments.reopen" : "comments.resolve"),
845
- onClick: toggleResolve,
846
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
847
- import_tldraw.TldrawUiIcon,
848
- {
849
- icon: "check",
850
- label: msg(thread.resolved ? "comments.reopen" : "comments.resolve"),
851
- small: true
852
- }
853
- )
854
- }
855
- ),
856
- currentUserId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
857
- "button",
858
- {
859
- className: "tlui-cmt-thread__action",
860
- title: msg("comments.delete"),
861
- onClick: deleteThread,
862
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiIcon, { icon: "trash", label: msg("comments.delete"), small: true })
863
- }
228
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_cluster_fade.clusterFadeClassName)(phase), children: content }, `cluster-fade:${node.id}`);
229
+ }),
230
+ orphanThreads.map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: renderThreadPin(thread) }, thread.id)),
231
+ heldThreads.map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: renderThreadPin(thread) }, thread.id))
232
+ ] }) : (
233
+ // Clustering off: every thread renders its own pin. The open thread is excluded and
234
+ // rendered once below, or it would mount a second, stacked pin.
235
+ threads.filter((thread) => thread.id !== openId).map((thread) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: renderThreadPin(thread) }, thread.id))
864
236
  ),
865
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
866
- "button",
867
- {
868
- className: "tlui-cmt-thread__action",
869
- title: msg("comments.dismiss"),
870
- onClick: () => import_state.openThreadId.set(editor, null),
871
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiIcon, { icon: "cross-2", label: msg("comments.dismiss"), small: true })
872
- }
873
- )
874
- ] });
875
- const PinContent = options.components.PinContent;
876
- const pinContent = PinContent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PinContent, { thread, comments }) : initialOf(resolveName(thread.createdBy) ?? import_comment_render.UNKNOWN_AUTHOR);
877
- const isRegion = thread.anchor.type === "region";
878
- const pinMovable = regionOptions.move !== "body";
879
- const bodyMovable = regionOptions.move !== "pin";
880
- const startDrag = (e) => {
881
- e.stopPropagation();
882
- dragRef.current = { startX: e.clientX, startY: e.clientY, moved: false };
883
- e.currentTarget.setPointerCapture(e.pointerId);
884
- };
885
- const onDrag = (e) => {
886
- const drag = dragRef.current;
887
- if (!drag) return;
888
- if (isRegion && !pinMovable) return;
889
- if (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return;
890
- drag.moved = true;
891
- setDragPagePoint(editor.screenToPage({ x: e.clientX, y: e.clientY }));
892
- };
893
- const endDrag = (e) => {
894
- const drag = dragRef.current;
895
- dragRef.current = null;
896
- if (e.currentTarget.hasPointerCapture(e.pointerId)) {
897
- e.currentTarget.releasePointerCapture(e.pointerId);
898
- }
899
- if (!drag) return;
900
- if (!drag.moved) {
901
- import_state.openThreadId.set(editor, import_state.openThreadId.get(editor) === thread.id ? null : thread.id);
902
- return;
903
- }
904
- const pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY });
905
- setDragPagePoint(null);
906
- let anchor;
907
- if (thread.anchor.type === "region") {
908
- anchor = {
909
- ...thread.anchor,
910
- x: pagePoint.x - regionOptions.pinCorner.x * thread.anchor.w,
911
- y: pagePoint.y - regionOptions.pinCorner.y * thread.anchor.h
912
- };
913
- } else {
914
- const hit = editor.getShapeAtPoint(pagePoint, { hitInside: true });
915
- anchor = hit ? (0, import_thread_state.shapeAnchorAt)(editor, hit.id, pagePoint, e.altKey) : { type: "point", x: pagePoint.x, y: pagePoint.y };
916
- }
917
- (0, import_state.commitCommentMutation)(editor, () => (0, import_comment_store.putCommentRecords)(editor, [{ ...thread, anchor }]), "drag");
918
- };
919
- const livePinPage = resizeBounds ? (0, import_thread_state.regionPinPoint)(resizeBounds, regionOptions.pinCorner) : dragPagePoint;
920
- const renderPoint = livePinPage ? editor.pageToViewport(livePinPage) : point;
921
- const regionAnchor = thread.anchor.type === "region" ? thread.anchor : void 0;
922
- const movedRegion = regionAnchor && dragPagePoint ? {
923
- ...regionAnchor,
924
- x: dragPagePoint.x - regionOptions.pinCorner.x * regionAnchor.w,
925
- y: dragPagePoint.y - regionOptions.pinCorner.y * regionAnchor.h
926
- } : regionAnchor;
927
- const regionBoxBounds = resizeBounds ?? movedRegion;
928
- const commitResize = (bounds) => {
929
- setResizeBounds(null);
930
- editor.run(
931
- () => (0, import_comment_store.putCommentRecords)(editor, [{ ...thread, anchor: { type: "region", ...bounds } }]),
932
- {
933
- history: "ignore"
934
- }
935
- );
936
- };
937
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
938
- regionBoxBounds && (dragPagePoint || revealed) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
939
- RegionBox,
940
- {
941
- editor,
942
- box: regionBoxBounds,
943
- movable: bodyMovable && !dragPagePoint,
944
- onPreview: setResizeBounds,
945
- onCommit: commitResize
946
- }
947
- ),
948
- regionBoxBounds && revealed && !dragPagePoint && regionOptions.resize !== "none" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
949
- RegionResizeHandles,
950
- {
951
- editor,
952
- box: regionBoxBounds,
953
- handles: resizeHandles,
954
- onPreview: setResizeBounds,
955
- onCommit: commitResize
956
- }
957
- ),
958
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
959
- "div",
960
- {
961
- className: open ? "tlui-cmt-canvas-pin tlui-cmt-canvas-pin--open" : "tlui-cmt-canvas-pin",
962
- style: { left: renderPoint.x, top: renderPoint.y },
963
- children: [
964
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
965
- "div",
966
- {
967
- ref: markerRef,
968
- className: "tlui-cmt-canvas-pin__marker",
969
- onPointerDown: startDrag,
970
- onPointerMove: onDrag,
971
- onPointerUp: endDrag,
972
- onPointerEnter: () => setPinHovered(true),
973
- onPointerLeave: () => setPinHovered(false),
974
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_comment_pin.CommentPin, { resolved: thread.resolved != null, open, children: pinContent })
975
- }
976
- ),
977
- open && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
978
- ThreadPopover,
979
- {
980
- container,
981
- style: { left: renderPoint.x + 36, top: renderPoint.y - 28 },
982
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
983
- import_comment_thread.CommentThread,
984
- {
985
- header: msg("comments.thread-title"),
986
- headerActions,
987
- renderComment,
988
- comments: comments.map((c) => toCardProps(c, props, options.components)),
989
- resolvedBanner: thread.resolved ? msg("comments.resolved-by").replace(
990
- "{name}",
991
- resolveName(thread.resolved.by) ?? import_comment_render.UNKNOWN_AUTHOR
992
- ) : void 0,
993
- composer: currentUserId && !thread.resolved ? {
994
- author: resolveName(currentUserId) ?? import_comment_render.UNKNOWN_AUTHOR,
995
- placeholder: msg("comments.reply-placeholder"),
996
- sendLabel: msg("comments.send"),
997
- value: reply,
998
- onChange: setReply,
999
- onSubmit: postReply,
1000
- disabled: (0, import_comment_extensions.isCommentEmpty)(reply),
1001
- getMentionSuggestions,
1002
- renderMentionSuggestion
1003
- } : void 0
1004
- }
1005
- )
1006
- }
1007
- )
1008
- ]
1009
- }
1010
- )
1011
- ] });
1012
- });
1013
- function PendingComposer({
1014
- editor,
1015
- pending,
1016
- currentUserId,
1017
- resolveName,
1018
- onPostComment,
1019
- getMentionSuggestions,
1020
- renderMentionSuggestion
1021
- }) {
1022
- const [text, setText] = (0, import_react.useState)(import_comment_extensions.EMPTY_COMMENT);
1023
- const ref = (0, import_react.useRef)(null);
1024
- const msg = (0, import_tldraw.useTranslation)();
1025
- const container = (0, import_tldraw.useContainer)();
1026
- (0, import_tldraw.usePassThroughWheelEvents)(ref);
1027
- (0, import_tldraw.usePassThroughMouseOverEvents)(ref);
1028
- const point = (0, import_tldraw.useValue)("composer point", () => editor.pageToViewport(pending.point), [
1029
- editor,
1030
- pending.point
1031
- ]);
1032
- (0, import_react.useEffect)(() => {
1033
- const onPointerDown = (e) => {
1034
- const el = ref.current;
1035
- const target = e.target;
1036
- if (!el || !target) return;
1037
- if (el.contains(target) || target.closest(".tlui-cmt-mention-popup")) return;
1038
- import_state.pendingComment.set(editor, null);
1039
- };
1040
- document.addEventListener("pointerdown", onPointerDown, true);
1041
- return () => document.removeEventListener("pointerdown", onPointerDown, true);
1042
- }, [editor]);
1043
- const submit = () => {
1044
- if ((0, import_comment_extensions.isCommentEmpty)(text) || !currentUserId) return;
1045
- (0, import_state.commitCommentMutation)(editor, () => {
1046
- const pageId = editor.getCurrentPageId();
1047
- const thread = (0, import_tldraw.createCommentThread)({
1048
- pageId,
1049
- anchor: pending.anchor,
1050
- createdBy: currentUserId
1051
- });
1052
- const comment = (0, import_tldraw.createComment)({
1053
- threadId: thread.id,
1054
- pageId,
1055
- authorId: currentUserId,
1056
- body: text
1057
- });
1058
- (0, import_comment_store.putCommentRecords)(editor, [thread, comment]);
1059
- if (onPostComment) onPostComment(comment);
1060
- });
1061
- setText(import_comment_extensions.EMPTY_COMMENT);
1062
- import_state.pendingComment.set(editor, null);
1063
- };
1064
- return (0, import_react_dom.createPortal)(
1065
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1066
- "div",
1067
- {
1068
- ref,
1069
- className: "tlui-cmt-canvas-composer",
1070
- style: { left: point.x, top: point.y },
1071
- onPointerDown: stop,
1072
- onKeyDown: (e) => {
1073
- if (e.key === "Escape" && !(0, import_mention_suggestion.isMentionPickerOpen)()) import_state.pendingComment.set(editor, null);
1074
- },
1075
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1076
- import_comment_composer.CommentComposer,
1077
- {
1078
- author: currentUserId ? resolveName(currentUserId) ?? import_comment_render.UNKNOWN_AUTHOR : "",
1079
- placeholder: msg("comments.add-placeholder"),
1080
- sendLabel: msg("comments.send"),
1081
- value: text,
1082
- onChange: setText,
1083
- onSubmit: submit,
1084
- disabled: (0, import_comment_extensions.isCommentEmpty)(text),
1085
- getMentionSuggestions,
1086
- renderMentionSuggestion,
1087
- autoFocus: true,
1088
- leading: draftAvatar
1089
- }
1090
- )
1091
- }
1092
- ),
1093
- container
1094
- );
237
+ openThread && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: renderThreadPin(openThread) }, `open:${openThread.id}`),
238
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_region_box.RegionDraftBox, { editor }),
239
+ pending?.anchor.type === "region" && showPendingComposer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_region_box.RegionBox, { editor, box: pending.anchor }),
240
+ pending && showPendingComposer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_pending_composer.PendingComposer, { editor, pending, ...props })
241
+ ] }) });
1095
242
  }
1096
243
  //# sourceMappingURL=comments-overlay.js.map