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