@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
@@ -0,0 +1,59 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useId } from "react";
3
+ import {
4
+ TldrawUiButton,
5
+ TldrawUiDropdownMenuContent,
6
+ TldrawUiDropdownMenuRoot,
7
+ TldrawUiDropdownMenuTrigger,
8
+ tlmenus,
9
+ useMaybeEditor,
10
+ useTranslation
11
+ } from "tldraw";
12
+ import { EmojiPicker } from "./emoji-picker.mjs";
13
+ import { SmileyIcon } from "./icons.mjs";
14
+ function ReactionPicker({
15
+ emoji,
16
+ selected,
17
+ onSelect,
18
+ renderReaction,
19
+ palette: Palette = EmojiPicker,
20
+ menuId,
21
+ className = "tlui-cmt-thread__action"
22
+ }) {
23
+ const msg = useTranslation();
24
+ const editor = useMaybeEditor();
25
+ const generatedId = useId();
26
+ const id = menuId ?? `comment-reactions-${generatedId}`;
27
+ const handleSelect = useCallback(
28
+ (value) => {
29
+ onSelect?.(value);
30
+ tlmenus.deleteOpenMenu(id, editor?.contextId);
31
+ },
32
+ [onSelect, id, editor]
33
+ );
34
+ return /* @__PURE__ */ jsxs(TldrawUiDropdownMenuRoot, { id, children: [
35
+ /* @__PURE__ */ jsx(TldrawUiDropdownMenuTrigger, { children: /* @__PURE__ */ jsx(
36
+ TldrawUiButton,
37
+ {
38
+ type: "icon",
39
+ tooltip: msg("comments.add-reaction"),
40
+ title: msg("comments.add-reaction"),
41
+ className,
42
+ children: /* @__PURE__ */ jsx(SmileyIcon, {})
43
+ }
44
+ ) }),
45
+ /* @__PURE__ */ jsx(TldrawUiDropdownMenuContent, { side: "bottom", align: "start", alignOffset: 0, sideOffset: 4, children: /* @__PURE__ */ jsx(
46
+ Palette,
47
+ {
48
+ emoji,
49
+ selected,
50
+ onSelect: handleSelect,
51
+ renderReaction
52
+ }
53
+ ) })
54
+ ] });
55
+ }
56
+ export {
57
+ ReactionPicker
58
+ };
59
+ //# sourceMappingURL=reaction-picker.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/reaction-picker.tsx"],
4
+ "sourcesContent": ["import { useCallback, useId, type ComponentType } from 'react'\nimport {\n\tTldrawUiButton,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\ttlmenus,\n\tuseMaybeEditor,\n\tuseTranslation,\n} from 'tldraw'\nimport { EmojiPicker, type EmojiPickerProps } from './emoji-picker'\nimport { SmileyIcon } from './icons'\nimport { RenderReaction } from './reaction'\n\n/** @public */\nexport interface ReactionPickerProps {\n\t/** The emoji to offer. Defaults to `DEFAULT_REACTION_EMOJI`. */\n\temoji?: string[]\n\t/** Emoji the current user has already reacted with; shown as pressed in the grid. */\n\tselected?: string[]\n\t/** Called when an emoji is chosen. */\n\tonSelect?(emoji: string): void\n\t/** How to draw each emoji token. Defaults to the token string (OS emoji font). */\n\trenderReaction?: RenderReaction\n\t/**\n\t * What the button opens \u2014 the thing that produces a token. Defaults to `EmojiPicker`, the grid of\n\t * emoji. Swap it for any component taking the same props to offer something else entirely (the\n\t * drawn reactions example replaces it with a canvas you draw in); the props are passed straight\n\t * through either way.\n\t */\n\tpalette?: ComponentType<EmojiPickerProps>\n\t/**\n\t * Identifies the menu in tldraw's global menu registry, which keys open/closed state by id.\n\t * A thread renders one picker per comment, so this must differ per comment \u2014 sharing an id\n\t * makes every picker in the thread open at once. Defaults to a per-instance generated id;\n\t * pass one only for a stabler, more debuggable value.\n\t */\n\tmenuId?: string\n\t/** Class for the trigger button. Defaults to the card-action style, matching the \u22EF button. */\n\tclassName?: string\n}\n\n/**\n * The add-reaction affordance: a smiley button that opens an emoji grid.\n *\n * Anchored to its own button rather than to the reactions row, so the menu keeps its position as\n * reactions are added and the row reflows.\n *\n * Picking an emoji dismisses the grid \u2014 adding and removing alike, since either way the picker has\n * done its job \u2014 and hands focus back to the trigger.\n * @public @react\n */\nexport function ReactionPicker({\n\temoji,\n\tselected,\n\tonSelect,\n\trenderReaction,\n\tpalette: Palette = EmojiPicker,\n\tmenuId,\n\tclassName = 'tlui-cmt-thread__action',\n}: ReactionPickerProps) {\n\tconst msg = useTranslation()\n\tconst editor = useMaybeEditor()\n\t// Unique per mounted picker unless the host supplies something stabler \u2014 see `menuId`.\n\tconst generatedId = useId()\n\tconst id = menuId ?? `comment-reactions-${generatedId}`\n\n\t// The dropdown's open state lives in tldraw's global menu registry, so dropping the entry is\n\t// what closes it. The palette's tokens are plain buttons \u2014 a swappable component, not radix\n\t// menu items \u2014 so nothing dismisses the menu on its own.\n\tconst handleSelect = useCallback(\n\t\t(value: string) => {\n\t\t\tonSelect?.(value)\n\t\t\ttlmenus.deleteOpenMenu(id, editor?.contextId)\n\t\t},\n\t\t[onSelect, id, editor]\n\t)\n\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id={id}>\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg('comments.add-reaction')}\n\t\t\t\t\ttitle={msg('comments.add-reaction')}\n\t\t\t\t\tclassName={className}\n\t\t\t\t>\n\t\t\t\t\t<SmileyIcon />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t{/* left-aligned under the trigger, so the grid opens rightward off the card's edge */}\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"start\" alignOffset={0} sideOffset={4}>\n\t\t\t\t<Palette\n\t\t\t\t\temoji={emoji}\n\t\t\t\t\tselected={selected}\n\t\t\t\t\tonSelect={handleSelect}\n\t\t\t\t\trenderReaction={renderReaction}\n\t\t\t\t/>\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n"],
5
+ "mappings": "AA+EE,SAQG,KARH;AA/EF,SAAS,aAAa,aAAiC;AACvD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAA0C;AACnD,SAAS,kBAAkB;AAyCpB,SAAS,eAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,UAAU;AAAA,EACnB;AAAA,EACA,YAAY;AACb,GAAwB;AACvB,QAAM,MAAM,eAAe;AAC3B,QAAM,SAAS,eAAe;AAE9B,QAAM,cAAc,MAAM;AAC1B,QAAM,KAAK,UAAU,qBAAqB,WAAW;AAKrD,QAAM,eAAe;AAAA,IACpB,CAAC,UAAkB;AAClB,iBAAW,KAAK;AAChB,cAAQ,eAAe,IAAI,QAAQ,SAAS;AAAA,IAC7C;AAAA,IACA,CAAC,UAAU,IAAI,MAAM;AAAA,EACtB;AAEA,SACC,qBAAC,4BAAyB,IACzB;AAAA,wBAAC,+BACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,SAAS,IAAI,uBAAuB;AAAA,QACpC,OAAO,IAAI,uBAAuB;AAAA,QAClC;AAAA,QAEA,8BAAC,cAAW;AAAA;AAAA,IACb,GACD;AAAA,IAEA,oBAAC,+BAA4B,MAAK,UAAS,OAAM,SAAQ,aAAa,GAAG,YAAY,GACpF;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,UAAU;AAAA,QACV;AAAA;AAAA,IACD,GACD;AAAA,KACD;AAEF;",
6
+ "names": []
7
+ }
@@ -1,18 +1,63 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- function Reaction({ emoji, count, active }) {
3
- return /* @__PURE__ */ jsxs(
4
- "button",
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { TldrawUiTooltip, useTranslation } from "tldraw";
3
+ function defaultRenderReaction(token) {
4
+ return token;
5
+ }
6
+ function Reaction({
7
+ emoji,
8
+ count,
9
+ active,
10
+ reactors,
11
+ enableHoverList = true,
12
+ renderReaction = defaultRenderReaction,
13
+ ReactionTooltip = DefaultReactionTooltip,
14
+ onClick
15
+ }) {
16
+ const Tag = onClick ? "button" : "span";
17
+ const pill = /* @__PURE__ */ jsxs(
18
+ Tag,
5
19
  {
6
20
  className: active ? "tlui-cmt-reaction tlui-cmt-reaction--active" : "tlui-cmt-reaction",
7
- type: "button",
21
+ ...(onClick ? { type: "button", "aria-pressed": active, onClick } : { role: "img" }),
22
+ "aria-label": `${emoji} ${count}`,
8
23
  children: [
9
- /* @__PURE__ */ jsx("span", { className: "tlui-cmt-reaction__emoji", children: emoji }),
24
+ /* @__PURE__ */ jsx("span", { className: "tlui-cmt-reaction__emoji", children: renderReaction(emoji) }),
10
25
  /* @__PURE__ */ jsx("span", { className: "tlui-cmt-reaction__count", children: count })
11
26
  ]
12
27
  }
13
28
  );
29
+ if (!enableHoverList || reactors.length === 0) return pill;
30
+ return /* @__PURE__ */ jsx(ReactionTooltip, { reactors, children: pill });
31
+ }
32
+ function DefaultReactionTooltip({ reactors, children }) {
33
+ return /* @__PURE__ */ jsx(TldrawUiTooltip, { side: "bottom", content: /* @__PURE__ */ jsx(DefaultReactionTooltipContent, { reactors }), children });
34
+ }
35
+ function DefaultReactionTooltipContent({ reactors }) {
36
+ const msg = useTranslation();
37
+ const names = reactors.map(
38
+ (reactor) => reactor.you ? msg("comments.mention-you") : reactor.name
39
+ );
40
+ const [a, b, c] = names;
41
+ switch (names.length) {
42
+ case 0:
43
+ return null;
44
+ case 1:
45
+ return /* @__PURE__ */ jsx(Fragment, { children: msg("comments.reacted-1").replace("{a}", a) });
46
+ case 2:
47
+ return /* @__PURE__ */ jsx(Fragment, { children: msg("comments.reacted-2").replace("{a}", a).replace("{b}", b) });
48
+ case 3:
49
+ return /* @__PURE__ */ jsx(Fragment, { children: msg("comments.reacted-3").replace("{a}", a).replace("{b}", b).replace("{c}", c) });
50
+ default: {
51
+ const others = names.length - 3;
52
+ const template = others === 1 ? "comments.reacted-more-one" : "comments.reacted-more";
53
+ return /* @__PURE__ */ jsx(Fragment, { children: msg(template).replace("{a}", a).replace("{b}", b).replace("{c}", c).replace("{count}", String(others)) });
54
+ }
55
+ }
14
56
  }
15
57
  export {
16
- Reaction
58
+ DefaultReactionTooltip,
59
+ DefaultReactionTooltipContent,
60
+ Reaction,
61
+ defaultRenderReaction
17
62
  };
18
63
  //# sourceMappingURL=reaction.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ui/reaction.tsx"],
4
- "sourcesContent": ["/** @public */\nexport interface ReactionProps {\n\temoji: string\n\tcount: number\n\tactive: boolean\n}\n\n/** A single emoji reaction pill with a count, highlighted when the user reacted. @public @react */\nexport function Reaction({ emoji, count, active }: ReactionProps) {\n\treturn (\n\t\t<button\n\t\t\tclassName={active ? 'tlui-cmt-reaction tlui-cmt-reaction--active' : 'tlui-cmt-reaction'}\n\t\t\ttype=\"button\"\n\t\t>\n\t\t\t<span className=\"tlui-cmt-reaction__emoji\">{emoji}</span>\n\t\t\t<span className=\"tlui-cmt-reaction__count\">{count}</span>\n\t\t</button>\n\t)\n}\n"],
5
- "mappings": "AAUE,SAIC,KAJD;AAFK,SAAS,SAAS,EAAE,OAAO,OAAO,OAAO,GAAkB;AACjE,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAW,SAAS,gDAAgD;AAAA,MACpE,MAAK;AAAA,MAEL;AAAA,4BAAC,UAAK,WAAU,4BAA4B,iBAAM;AAAA,QAClD,oBAAC,UAAK,WAAU,4BAA4B,iBAAM;AAAA;AAAA;AAAA,EACnD;AAEF;",
4
+ "sourcesContent": ["import { ComponentType, ReactNode } from 'react'\nimport { TldrawUiTooltip, useTranslation } from 'tldraw'\nimport { ReactionReactor } from './reactions'\n\n/** Render a reaction token to its visual \u2014 the emoji glyph by default. @public */\nexport type RenderReaction = (token: string) => ReactNode\n\n/** The default reaction renderer: emits the token string for the OS emoji font to draw. @public */\nexport function defaultRenderReaction(token: string): ReactNode {\n\treturn token\n}\n\n/** @public */\nexport interface ReactionProps {\n\temoji: string\n\tcount: number\n\tactive: boolean\n\t/** How to draw the emoji token. Defaults to the token string (OS emoji font). */\n\trenderReaction?: RenderReaction\n\t/** Who reacted with this emoji, in reaction order \u2014 shown when the pill is hovered. */\n\treactors: ReactionReactor[]\n\t/** Whether hovering shows the reactor list. Pass false to suppress it \u2014 e.g. while another\n\t * popup menu on the comment is open. Defaults to true. */\n\tenableHoverList?: boolean\n\t/** The hover affordance for the pill, naming who reacted. It receives the reactors and the pill\n\t * itself (as `children`) and returns the whole thing \u2014 so it owns the tooltip, its box, size,\n\t * shape, and position, not just the text inside. Defaults to `DefaultReactionTooltip`, which\n\t * hangs the built-in inline sentence below the pill. */\n\tReactionTooltip?: ComponentType<ReactionTooltipProps>\n\t/** Called when the pill is pressed \u2014 toggles the current user's reaction. */\n\tonClick?(): void\n}\n\n/**\n * A single emoji reaction pill with a count, highlighted when the user reacted. Hovering it shows a\n * tooltip naming who reacted (the current user included), when `enableHoverList` is set.\n * @public @react\n */\nexport function Reaction({\n\temoji,\n\tcount,\n\tactive,\n\treactors,\n\tenableHoverList = true,\n\trenderReaction = defaultRenderReaction,\n\tReactionTooltip = DefaultReactionTooltip,\n\tonClick,\n}: ReactionProps) {\n\t// An inert pill (no handler) is plain content, not a control \u2014 rendering it as a span keeps it\n\t// valid inside an anchor row (e.g. a notification list item) and out of the tab order.\n\tconst Tag = onClick ? 'button' : 'span'\n\tconst pill = (\n\t\t<Tag\n\t\t\tclassName={active ? 'tlui-cmt-reaction tlui-cmt-reaction--active' : 'tlui-cmt-reaction'}\n\t\t\t{...(onClick\n\t\t\t\t? { type: 'button' as const, 'aria-pressed': active, onClick }\n\t\t\t\t: { role: 'img' as const })}\n\t\t\t// The emoji alone announces as its unicode name (\"thumbs up\"); pairing it with the count\n\t\t\t// is what makes the pill's state legible to a screen reader. The inert span needs the\n\t\t\t// img role for the label to be announced at all.\n\t\t\taria-label={`${emoji} ${count}`}\n\t\t>\n\t\t\t<span className=\"tlui-cmt-reaction__emoji\">{renderReaction(emoji)}</span>\n\t\t\t<span className=\"tlui-cmt-reaction__count\">{count}</span>\n\t\t</Tag>\n\t)\n\n\t// A bare pill when hovering is suppressed, or when there's no one to name.\n\tif (!enableHoverList || reactors.length === 0) return pill\n\n\t// Hand the whole hover affordance to the tooltip component: it wraps the pill and owns how the\n\t// reactor list is presented.\n\treturn <ReactionTooltip reactors={reactors}>{pill}</ReactionTooltip>\n}\n\n/** @public */\nexport interface ReactionTooltipProps {\n\t/** Who reacted with this emoji, in reaction order. */\n\treactors: ReactionReactor[]\n\t/** The reaction pill to wrap. Anchor the hover affordance to this and render it. */\n\tchildren: ReactNode\n}\n\n/**\n * The default reactor tooltip: hangs the built-in inline sentence (`DefaultReactionTooltipContent`)\n * in a standard tooltip below the pill \u2014 the same tooltip the toolbar uses. Replace it via\n * `CommentingComponents.ReactionTooltip` to present the reactor list any other way (a different box,\n * avatars, a banner, anywhere on screen); it receives the pill as `children`.\n * @public @react\n */\nexport function DefaultReactionTooltip({ reactors, children }: ReactionTooltipProps) {\n\treturn (\n\t\t<TldrawUiTooltip side=\"bottom\" content={<DefaultReactionTooltipContent reactors={reactors} />}>\n\t\t\t{children}\n\t\t</TldrawUiTooltip>\n\t)\n}\n\n/**\n * The default reactor sentence naming who reacted \u2014 up to three names spelled out, then \"and N\n * others\" (e.g. \"You reacted\", \"You and Bo reacted\", \"You, Bo and Ada reacted\", \"You, Bo, Ada and 2\n * others reacted\"). The wording lives in the `comments.reacted-*` translation strings so each locale\n * controls the grammar. Exported so a custom `ReactionTooltip` can reuse it inside its own box.\n * @public @react\n */\nexport function DefaultReactionTooltipContent({ reactors }: { reactors: ReactionReactor[] }) {\n\tconst msg = useTranslation()\n\tconst names = reactors.map((reactor) =>\n\t\treactor.you ? msg('comments.mention-you') : reactor.name\n\t)\n\tconst [a, b, c] = names\n\tswitch (names.length) {\n\t\tcase 0:\n\t\t\treturn null\n\t\tcase 1:\n\t\t\treturn <>{msg('comments.reacted-1').replace('{a}', a)}</>\n\t\tcase 2:\n\t\t\treturn <>{msg('comments.reacted-2').replace('{a}', a).replace('{b}', b)}</>\n\t\tcase 3:\n\t\t\treturn <>{msg('comments.reacted-3').replace('{a}', a).replace('{b}', b).replace('{c}', c)}</>\n\t\tdefault: {\n\t\t\tconst others = names.length - 3\n\t\t\tconst template = others === 1 ? 'comments.reacted-more-one' : 'comments.reacted-more'\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t{msg(template)\n\t\t\t\t\t\t.replace('{a}', a)\n\t\t\t\t\t\t.replace('{b}', b)\n\t\t\t\t\t\t.replace('{c}', c)\n\t\t\t\t\t\t.replace('{count}', String(others))}\n\t\t\t\t</>\n\t\t\t)\n\t\t}\n\t}\n}\n"],
5
+ "mappings": "AAoDE,SA+DQ,UArDP,KAVD;AAnDF,SAAS,iBAAiB,sBAAsB;AAOzC,SAAS,sBAAsB,OAA0B;AAC/D,SAAO;AACR;AA4BO,SAAS,SAAS;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB;AACD,GAAkB;AAGjB,QAAM,MAAM,UAAU,WAAW;AACjC,QAAM,OACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAW,SAAS,gDAAgD;AAAA,MACnE,GAAI,UACF,EAAE,MAAM,UAAmB,gBAAgB,QAAQ,QAAQ,IAC3D,EAAE,MAAM,MAAe;AAAA,MAI1B,cAAY,GAAG,KAAK,IAAI,KAAK;AAAA,MAE7B;AAAA,4BAAC,UAAK,WAAU,4BAA4B,yBAAe,KAAK,GAAE;AAAA,QAClE,oBAAC,UAAK,WAAU,4BAA4B,iBAAM;AAAA;AAAA;AAAA,EACnD;AAID,MAAI,CAAC,mBAAmB,SAAS,WAAW,EAAG,QAAO;AAItD,SAAO,oBAAC,mBAAgB,UAAqB,gBAAK;AACnD;AAiBO,SAAS,uBAAuB,EAAE,UAAU,SAAS,GAAyB;AACpF,SACC,oBAAC,mBAAgB,MAAK,UAAS,SAAS,oBAAC,iCAA8B,UAAoB,GACzF,UACF;AAEF;AASO,SAAS,8BAA8B,EAAE,SAAS,GAAoC;AAC5F,QAAM,MAAM,eAAe;AAC3B,QAAM,QAAQ,SAAS;AAAA,IAAI,CAAC,YAC3B,QAAQ,MAAM,IAAI,sBAAsB,IAAI,QAAQ;AAAA,EACrD;AACA,QAAM,CAAC,GAAG,GAAG,CAAC,IAAI;AAClB,UAAQ,MAAM,QAAQ;AAAA,IACrB,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IACvD,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IACzE,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IAC3F,SAAS;AACR,YAAM,SAAS,MAAM,SAAS;AAC9B,YAAM,WAAW,WAAW,IAAI,8BAA8B;AAC9D,aACC,gCACE,cAAI,QAAQ,EACX,QAAQ,OAAO,CAAC,EAChB,QAAQ,OAAO,CAAC,EAChB,QAAQ,OAAO,CAAC,EAChB,QAAQ,WAAW,OAAO,MAAM,CAAC,GACpC;AAAA,IAEF;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,20 +1,25 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { Reaction } from "./reaction.mjs";
3
- function Reactions() {
4
- return /* @__PURE__ */ jsxs("div", { className: "tlui-cmt-reactions", children: [
5
- /* @__PURE__ */ jsx(Reaction, { emoji: "\u{1F44D}", count: 3, active: true }),
6
- /* @__PURE__ */ jsx(Reaction, { emoji: "\u{1F389}", count: 1, active: false }),
7
- /* @__PURE__ */ jsx(Reaction, { emoji: "\u{1F440}", count: 2, active: false }),
8
- /* @__PURE__ */ jsx(
9
- "button",
10
- {
11
- className: "tlui-cmt-reaction tlui-cmt-reaction--add",
12
- type: "button",
13
- "aria-label": "Add reaction",
14
- children: "\uFF0B"
15
- }
16
- )
17
- ] });
3
+ function Reactions({
4
+ reactions,
5
+ onToggle,
6
+ canReact = true,
7
+ enableHoverList = true,
8
+ renderReaction,
9
+ ReactionTooltip
10
+ }) {
11
+ if (reactions.length === 0) return null;
12
+ return /* @__PURE__ */ jsx("div", { className: "tlui-cmt-reactions", children: reactions.map((reaction) => /* @__PURE__ */ jsx(
13
+ Reaction,
14
+ {
15
+ ...reaction,
16
+ enableHoverList,
17
+ renderReaction,
18
+ ReactionTooltip,
19
+ onClick: canReact ? () => onToggle?.(reaction.emoji) : void 0
20
+ },
21
+ reaction.emoji
22
+ )) });
18
23
  }
19
24
  export {
20
25
  Reactions
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ui/reactions.tsx"],
4
- "sourcesContent": ["import { Reaction } from './reaction'\n\n/** The row of reactions under a comment, plus an add-reaction button. @public @react */\nexport function Reactions() {\n\treturn (\n\t\t<div className=\"tlui-cmt-reactions\">\n\t\t\t<Reaction emoji=\"\uD83D\uDC4D\" count={3} active={true} />\n\t\t\t<Reaction emoji=\"\uD83C\uDF89\" count={1} active={false} />\n\t\t\t<Reaction emoji=\"\uD83D\uDC40\" count={2} active={false} />\n\t\t\t<button\n\t\t\t\tclassName=\"tlui-cmt-reaction tlui-cmt-reaction--add\"\n\t\t\t\ttype=\"button\"\n\t\t\t\taria-label=\"Add reaction\"\n\t\t\t>\n\t\t\t\t\uFF0B\n\t\t\t</button>\n\t\t</div>\n\t)\n}\n"],
5
- "mappings": "AAKE,SACC,KADD;AALF,SAAS,gBAAgB;AAGlB,SAAS,YAAY;AAC3B,SACC,qBAAC,SAAI,WAAU,sBACd;AAAA,wBAAC,YAAS,OAAM,aAAK,OAAO,GAAG,QAAQ,MAAM;AAAA,IAC7C,oBAAC,YAAS,OAAM,aAAK,OAAO,GAAG,QAAQ,OAAO;AAAA,IAC9C,oBAAC,YAAS,OAAM,aAAK,OAAO,GAAG,QAAQ,OAAO;AAAA,IAC9C;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,MAAK;AAAA,QACL,cAAW;AAAA,QACX;AAAA;AAAA,IAED;AAAA,KACD;AAEF;",
4
+ "sourcesContent": ["import { ComponentType } from 'react'\nimport { Reaction, ReactionTooltipProps, RenderReaction } from './reaction'\n\n/** One person who reacted with a given emoji, for the hover list. @public */\nexport interface ReactionReactor {\n\t/** Display name of the person who reacted. */\n\tname: string\n\t/** True for the current user. */\n\tyou: boolean\n}\n\n/** One emoji's reactions on a comment, already tallied. @public */\nexport interface ReactionSummary {\n\temoji: string\n\t/** How many people reacted with this emoji. */\n\tcount: number\n\t/** True when the current user is one of them \u2014 renders the pill highlighted. */\n\tactive: boolean\n\t/** Who reacted with this emoji, in reaction order \u2014 shown in the hover list. */\n\treactors: ReactionReactor[]\n}\n\n/** @public */\nexport interface ReactionsProps {\n\t/** The comment's reactions, grouped by emoji. Empty renders nothing. */\n\treactions: ReactionSummary[]\n\t/** Toggles the current user's reaction for an emoji. */\n\tonToggle?(emoji: string): void\n\t/** Whether the current user may react. False makes the pills inert (e.g. a signed-out\n\t * viewer, or a read-only thread) while still showing counts. */\n\tcanReact?: boolean\n\t/** Whether hovering a pill shows its reactor list. Pass false to suppress it \u2014 e.g. while\n\t * another popup menu on the comment is open. Defaults to true. */\n\tenableHoverList?: boolean\n\t/** How to draw each emoji token. Defaults to the token string (OS emoji font). */\n\trenderReaction?: RenderReaction\n\t/** The tooltip naming who reacted, shown when a pill is hovered. Defaults to an inline sentence\n\t * (`DefaultReactionTooltip`). Swap it to render the reactor list however you like. */\n\tReactionTooltip?: ComponentType<ReactionTooltipProps>\n}\n\n/**\n * The row of tallied reactions under a comment. Presentational \u2014 the host supplies the summaries\n * and owns what toggling does. Hovering a pill lists who reacted (see `Reaction`).\n *\n * The add-reaction affordance is a separate component (`ReactionPicker`) so it can live outside\n * this row \u2014 on a comment card it sits with the card's hover actions, which keeps its position\n * fixed as reactions are added here.\n * @public @react\n */\nexport function Reactions({\n\treactions,\n\tonToggle,\n\tcanReact = true,\n\tenableHoverList = true,\n\trenderReaction,\n\tReactionTooltip,\n}: ReactionsProps) {\n\tif (reactions.length === 0) return null\n\treturn (\n\t\t<div className=\"tlui-cmt-reactions\">\n\t\t\t{reactions.map((reaction) => (\n\t\t\t\t<Reaction\n\t\t\t\t\tkey={reaction.emoji}\n\t\t\t\t\t{...reaction}\n\t\t\t\t\tenableHoverList={enableHoverList}\n\t\t\t\t\trenderReaction={renderReaction}\n\t\t\t\t\tReactionTooltip={ReactionTooltip}\n\t\t\t\t\tonClick={canReact ? () => onToggle?.(reaction.emoji) : undefined}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</div>\n\t)\n}\n"],
5
+ "mappings": "AA8DI;AA7DJ,SAAS,gBAAsD;AAiDxD,SAAS,UAAU;AAAA,EACzB;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB;AAAA,EACA;AACD,GAAmB;AAClB,MAAI,UAAU,WAAW,EAAG,QAAO;AACnC,SACC,oBAAC,SAAI,WAAU,sBACb,oBAAU,IAAI,CAAC,aACf;AAAA,IAAC;AAAA;AAAA,MAEC,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,WAAW,MAAM,WAAW,SAAS,KAAK,IAAI;AAAA;AAAA,IALlD,SAAS;AAAA,EAMf,CACA,GACF;AAEF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,9 @@
1
+ function replyCountLabel(msg, replyCount) {
2
+ if (replyCount <= 0) return null;
3
+ const key = replyCount === 1 ? "comments.replies-one" : "comments.replies";
4
+ return msg(key).replace("{count}", String(replyCount));
5
+ }
6
+ export {
7
+ replyCountLabel
8
+ };
9
+ //# sourceMappingURL=reply-count.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/reply-count.ts"],
4
+ "sourcesContent": ["import { useTranslation } from 'tldraw'\n\n/**\n * The localized \"N replies\" label (e.g. \"1 reply\", \"3 replies\") for a thread with `replyCount`\n * replies \u2014 the comments after the opening one. Returns null when there are none, so callers render\n * nothing rather than \"0 replies\". Shared by the sidebar row and the hover preview so both read the\n * same, with each site owning where it puts the text.\n */\nexport function replyCountLabel(\n\tmsg: ReturnType<typeof useTranslation>,\n\treplyCount: number\n): string | null {\n\tif (replyCount <= 0) return null\n\tconst key = replyCount === 1 ? 'comments.replies-one' : 'comments.replies'\n\treturn msg(key).replace('{count}', String(replyCount))\n}\n"],
5
+ "mappings": "AAQO,SAAS,gBACf,KACA,YACgB;AAChB,MAAI,cAAc,EAAG,QAAO;AAC5B,QAAM,MAAM,eAAe,IAAI,yBAAyB;AACxD,SAAO,IAAI,GAAG,EAAE,QAAQ,WAAW,OAAO,UAAU,CAAC;AACtD;",
6
+ "names": []
7
+ }
@@ -1,6 +1,18 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { SendIcon } from "./icons.mjs";
2
3
  function SendButton({ label, disabled, onClick }) {
3
- return /* @__PURE__ */ jsx("button", { className: "tlui-cmt-send", type: "button", disabled, onClick, children: label });
4
+ return /* @__PURE__ */ jsx(
5
+ "button",
6
+ {
7
+ className: "tlui-cmt-send",
8
+ type: "button",
9
+ disabled,
10
+ onClick,
11
+ "aria-label": label,
12
+ title: label,
13
+ children: /* @__PURE__ */ jsx(SendIcon, {})
14
+ }
15
+ );
4
16
  }
5
17
  export {
6
18
  SendButton
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ui/send-button.tsx"],
4
- "sourcesContent": ["/** @public */\nexport interface SendButtonProps {\n\tlabel: string\n\tdisabled?: boolean\n\tonClick?(): void\n}\n\n/** The button that posts a comment. @public @react */\nexport function SendButton({ label, disabled, onClick }: SendButtonProps) {\n\treturn (\n\t\t<button className=\"tlui-cmt-send\" type=\"button\" disabled={disabled} onClick={onClick}>\n\t\t\t{label}\n\t\t</button>\n\t)\n}\n"],
5
- "mappings": "AAUE;AAFK,SAAS,WAAW,EAAE,OAAO,UAAU,QAAQ,GAAoB;AACzE,SACC,oBAAC,YAAO,WAAU,iBAAgB,MAAK,UAAS,UAAoB,SAClE,iBACF;AAEF;",
4
+ "sourcesContent": ["import { SendIcon } from './icons'\n\n/** @public */\nexport interface SendButtonProps {\n\t/** The button's accessible name (e.g. \"Send\"). Shown as an up-arrow icon, so this is its label. */\n\tlabel: string\n\tdisabled?: boolean\n\tonClick?(): void\n}\n\n/** The button that posts a comment \u2014 an up arrow. @public @react */\nexport function SendButton({ label, disabled, onClick }: SendButtonProps) {\n\treturn (\n\t\t<button\n\t\t\tclassName=\"tlui-cmt-send\"\n\t\t\ttype=\"button\"\n\t\t\tdisabled={disabled}\n\t\t\tonClick={onClick}\n\t\t\taria-label={label}\n\t\t\ttitle={label}\n\t\t>\n\t\t\t<SendIcon />\n\t\t</button>\n\t)\n}\n"],
5
+ "mappings": "AAqBG;AArBH,SAAS,gBAAgB;AAWlB,SAAS,WAAW,EAAE,OAAO,UAAU,QAAQ,GAAoB;AACzE,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,MAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,cAAY;AAAA,MACZ,OAAO;AAAA,MAEP,8BAAC,YAAS;AAAA;AAAA,EACX;AAEF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,12 @@
1
+ function getVisibleViewport(win) {
2
+ const vv = win.visualViewport;
3
+ const top = vv ? vv.offsetTop : 0;
4
+ const left = vv ? vv.offsetLeft : 0;
5
+ const width = vv ? vv.width : win.innerWidth;
6
+ const height = vv ? vv.height : win.innerHeight;
7
+ return { top, left, width, height, bottom: top + height, right: left + width };
8
+ }
9
+ export {
10
+ getVisibleViewport
11
+ };
12
+ //# sourceMappingURL=visual-viewport.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/visual-viewport.ts"],
4
+ "sourcesContent": ["// The visual viewport is the region actually on screen. The software keyboard (and pinch-zoom)\n// shrink it while leaving the layout viewport \u2014 and CSS `dvh` \u2014 unchanged, most notably on iOS.\n// So placing a panel above the keyboard means measuring against `window.visualViewport`, not CSS.\n// These helpers are the single place the commenting layer reads it.\n\n/** The on-screen viewport region in window coordinates, falling back to the layout viewport where\n * `visualViewport` is unavailable. `top`/`left` carry the viewport's own offset \u2014 on iOS this is\n * non-zero while the keyboard is open, and dropping it misplaces anything measured against it. */\nexport interface VisibleViewport {\n\ttop: number\n\tleft: number\n\twidth: number\n\theight: number\n\tbottom: number\n\tright: number\n}\n\n/** Read the visible viewport once. Call it inside a `visualViewport` resize/scroll handler to keep\n * a measurement current as the keyboard opens and closes. */\nexport function getVisibleViewport(win: Window): VisibleViewport {\n\tconst vv = win.visualViewport\n\tconst top = vv ? vv.offsetTop : 0\n\tconst left = vv ? vv.offsetLeft : 0\n\tconst width = vv ? vv.width : win.innerWidth\n\tconst height = vv ? vv.height : win.innerHeight\n\treturn { top, left, width, height, bottom: top + height, right: left + width }\n}\n"],
5
+ "mappings": "AAmBO,SAAS,mBAAmB,KAA8B;AAChE,QAAM,KAAK,IAAI;AACf,QAAM,MAAM,KAAK,GAAG,YAAY;AAChC,QAAM,OAAO,KAAK,GAAG,aAAa;AAClC,QAAM,QAAQ,KAAK,GAAG,QAAQ,IAAI;AAClC,QAAM,SAAS,KAAK,GAAG,SAAS,IAAI;AACpC,SAAO,EAAE,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,QAAQ,OAAO,OAAO,MAAM;AAC9E;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/commenting",
3
3
  "description": "tldraw commenting UI components.",
4
- "version": "5.3.0-internal.c5c7f1d817d0",
4
+ "version": "5.3.0-next.030bf6014f04",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -28,7 +28,7 @@
28
28
  "test": "yarn run -T vitest --passWithNoTests",
29
29
  "test-coverage": "yarn run -T vitest run --coverage --passWithNoTests",
30
30
  "predev": "node ./scripts/copy-css-files.mjs",
31
- "dev": "chokidar 'src/ui/comments.css' 'src/canvas/canvas.css' -c 'node ./scripts/copy-css-files.mjs'",
31
+ "dev": "chokidar '../mentions/mentions.css' 'src/ui/comments.css' 'src/canvas/canvas.css' -c 'node ./scripts/copy-css-files.mjs'",
32
32
  "prebuild": "node ./scripts/copy-css-files.mjs",
33
33
  "build": "yarn run -T tsx ../../internal/scripts/build-package.ts",
34
34
  "build-api": "yarn run -T tsx ../../internal/scripts/build-api.ts",
@@ -38,6 +38,7 @@
38
38
  "lint": "yarn run -T tsx ../../internal/scripts/lint.ts"
39
39
  },
40
40
  "devDependencies": {
41
+ "@tldraw/driver": "5.3.0-next.030bf6014f04",
41
42
  "@types/react": "^19.2.7",
42
43
  "@types/react-dom": "^19.2.3",
43
44
  "react": "^19.2.1",
@@ -52,12 +53,11 @@
52
53
  },
53
54
  "dependencies": {
54
55
  "@tiptap/core": "^3.12.1",
55
- "@tiptap/extension-mention": "3.13.0",
56
56
  "@tiptap/pm": "^3.12.1",
57
57
  "@tiptap/react": "^3.12.1",
58
- "@tiptap/suggestion": "3.13.0",
59
- "@tldraw/utils": "5.3.0-internal.c5c7f1d817d0",
60
- "tldraw": "5.3.0-internal.c5c7f1d817d0"
58
+ "@tldraw/mentions": "5.3.0-next.030bf6014f04",
59
+ "@tldraw/utils": "5.3.0-next.030bf6014f04",
60
+ "tldraw": "5.3.0-next.030bf6014f04"
61
61
  },
62
62
  "module": "dist-esm/index.mjs",
63
63
  "source": "src/index.ts",
@@ -0,0 +1,290 @@
1
+ import {
2
+ commentSchemaRecords,
3
+ createCommentThread,
4
+ createShapeId,
5
+ createTLSchema,
6
+ createTLStore,
7
+ defaultBindingUtils,
8
+ defaultShapeUtils,
9
+ defaultTools,
10
+ Editor,
11
+ toRichText,
12
+ createComment as tlCreateComment,
13
+ TLPageId,
14
+ TLShapeId,
15
+ } from 'tldraw'
16
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
17
+ import { registerCommentAnchorLifecycle } from './anchor-lifecycle'
18
+ import { commitCommentMutation, putCommentRecords } from './comment-mutations'
19
+ import { getCommentRecord, getComments } from './comment-store'
20
+ import { CommentTool } from './comment-tool'
21
+
22
+ /**
23
+ * These tests need a real editor: the behavior under test is the interplay between store
24
+ * side effects (the beforeDelete snapshot, operation-complete settlement) and real editor
25
+ * operations like `deleteShapes` and `moveShapesToPage` — exactly what a stub can't model.
26
+ */
27
+
28
+ let editor: Editor
29
+ let dispose: () => void
30
+
31
+ beforeEach(() => {
32
+ editor = new Editor({
33
+ store: createTLStore({ schema: createTLSchema({ records: commentSchemaRecords }) }),
34
+ shapeUtils: defaultShapeUtils,
35
+ bindingUtils: defaultBindingUtils,
36
+ tools: defaultTools,
37
+ getContainer: () => document.body,
38
+ })
39
+ dispose = registerCommentAnchorLifecycle(editor)
40
+ })
41
+
42
+ afterEach(() => {
43
+ dispose()
44
+ editor.dispose()
45
+ })
46
+
47
+ function makeShape(x = 100, y = 100, w = 100, h = 50): TLShapeId {
48
+ const id = createShapeId()
49
+ editor.createShape({ id, type: 'geo', x, y, props: { w, h } })
50
+ return id
51
+ }
52
+
53
+ function makeThread(shapeId: TLShapeId, anchorX = 0.5, anchorY = 0.5, isPrecise = true) {
54
+ const thread = createCommentThread({
55
+ pageId: editor.getCurrentPageId(),
56
+ anchor: { type: 'shape', shapeId, x: anchorX, y: anchorY, isPrecise },
57
+ createdBy: 'me',
58
+ })
59
+ const comment = tlCreateComment({
60
+ threadId: thread.id,
61
+ pageId: thread.pageId,
62
+ authorId: 'me',
63
+ body: toRichText('hello'),
64
+ })
65
+ putCommentRecords(editor, [thread, comment])
66
+ return { thread, comment }
67
+ }
68
+
69
+ function makeSecondPage(): TLPageId {
70
+ editor.createPage({ name: 'page 2' })
71
+ return editor.getPages()[1].id
72
+ }
73
+
74
+ describe('shape deletion', () => {
75
+ it('converts a precise shape anchor to a point anchor where the pin sat', () => {
76
+ const shapeId = makeShape(100, 100, 100, 50)
77
+ const { thread } = makeThread(shapeId, 0.5, 0.5, true)
78
+
79
+ editor.deleteShape(shapeId)
80
+
81
+ const updated = getCommentRecord(editor, thread.id)!
82
+ expect(updated.typeName).toBe('comment-thread')
83
+ expect((updated as typeof thread).anchor).toEqual({ type: 'point', x: 150, y: 125 })
84
+ })
85
+
86
+ it('converts an imprecise shape anchor where the inset pin is drawn, not at the raw corner', () => {
87
+ const shapeId = makeShape(100, 100, 100, 50)
88
+ const { thread } = makeThread(shapeId, 0.2, 0.9, false)
89
+
90
+ editor.deleteShape(shapeId)
91
+
92
+ // Top-right corner (200, 100) plus the 20px screen inset toward the shape's centre.
93
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
94
+ expect(updated.anchor).toEqual({ type: 'point', x: 180, y: 120 })
95
+ })
96
+
97
+ it('resolves the imprecise spot from the commenting options when no override is passed', () => {
98
+ const configured = new Editor({
99
+ store: createTLStore({ schema: createTLSchema({ records: commentSchemaRecords }) }),
100
+ shapeUtils: defaultShapeUtils,
101
+ bindingUtils: defaultBindingUtils,
102
+ tools: [...defaultTools, CommentTool.configure({ impreciseShapeAnchor: { x: 0, y: 1 } })],
103
+ getContainer: () => document.body,
104
+ })
105
+ const disposeConfigured = registerCommentAnchorLifecycle(configured)
106
+ try {
107
+ const shapeId = createShapeId()
108
+ configured.createShape({ id: shapeId, type: 'geo', x: 100, y: 100, props: { w: 100, h: 50 } })
109
+ const thread = createCommentThread({
110
+ pageId: configured.getCurrentPageId(),
111
+ anchor: { type: 'shape', shapeId, x: 0.5, y: 0.5, isPrecise: false },
112
+ createdBy: 'me',
113
+ })
114
+ putCommentRecords(configured, [thread])
115
+
116
+ configured.deleteShape(shapeId)
117
+
118
+ // Bottom-left corner (100, 150) plus the inset toward the shape's centre.
119
+ const updated = getCommentRecord(configured, thread.id) as typeof thread
120
+ expect(updated.anchor).toEqual({ type: 'point', x: 120, y: 130 })
121
+ } finally {
122
+ disposeConfigured()
123
+ configured.dispose()
124
+ }
125
+ })
126
+
127
+ it('converts anchors on children when their frame is deleted with them', () => {
128
+ const frameId = createShapeId()
129
+ editor.createShape({ id: frameId, type: 'frame', x: 0, y: 0, props: { w: 400, h: 400 } })
130
+ const childId = createShapeId()
131
+ editor.createShape({
132
+ id: childId,
133
+ type: 'geo',
134
+ parentId: frameId,
135
+ x: 50,
136
+ y: 50,
137
+ props: { w: 100, h: 100 },
138
+ })
139
+ const { thread } = makeThread(childId, 0.5, 0.5, true)
140
+
141
+ editor.deleteShape(frameId)
142
+
143
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
144
+ expect(updated.anchor).toEqual({ type: 'point', x: 100, y: 100 })
145
+ })
146
+
147
+ it('re-attaches the thread when the delete is undone', () => {
148
+ const shapeId = makeShape(100, 100, 100, 50)
149
+ const { thread } = makeThread(shapeId, 0.5, 0.5, true)
150
+ editor.markHistoryStoppingPoint()
151
+
152
+ editor.deleteShape(shapeId)
153
+ expect((getCommentRecord(editor, thread.id) as typeof thread).anchor.type).toBe('point')
154
+
155
+ editor.undo()
156
+
157
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
158
+ expect(updated.anchor).toEqual(thread.anchor)
159
+ })
160
+
161
+ it('keeps the restore when a returning shape cannot resolve its page yet', () => {
162
+ const frameId = createShapeId()
163
+ editor.createShape({ id: frameId, type: 'frame', x: 0, y: 0, props: { w: 400, h: 400 } })
164
+ const childId = createShapeId()
165
+ editor.createShape({
166
+ id: childId,
167
+ type: 'geo',
168
+ parentId: frameId,
169
+ x: 50,
170
+ y: 50,
171
+ props: { w: 100, h: 100 },
172
+ })
173
+ const { thread } = makeThread(childId, 0.5, 0.5, true)
174
+ const childRecord = editor.getShape(childId)!
175
+ const frameRecord = editor.getShape(frameId)!
176
+
177
+ editor.deleteShape(frameId)
178
+ expect((getCommentRecord(editor, thread.id) as typeof thread).anchor.type).toBe('point')
179
+
180
+ // The child returns in an earlier operation than its parent, so its ancestor page can't
181
+ // resolve when it first reappears.
182
+ editor.store.put([childRecord])
183
+ editor.store.put([frameRecord])
184
+
185
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
186
+ expect(updated.anchor).toEqual(thread.anchor)
187
+ })
188
+
189
+ it('re-attaches on undo even when the lifecycle was re-registered in between', () => {
190
+ const shapeId = makeShape(100, 100, 100, 50)
191
+ const { thread } = makeThread(shapeId, 0.5, 0.5, true)
192
+ editor.markHistoryStoppingPoint()
193
+
194
+ editor.deleteShape(shapeId)
195
+ expect((getCommentRecord(editor, thread.id) as typeof thread).anchor.type).toBe('point')
196
+
197
+ // The registering effect re-runs whenever its inputs change identity; conversion memory
198
+ // must not live and die with any one registration.
199
+ dispose()
200
+ dispose = registerCommentAnchorLifecycle(editor)
201
+
202
+ editor.undo()
203
+
204
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
205
+ expect(updated.anchor).toEqual(thread.anchor)
206
+ })
207
+
208
+ it('does not re-attach on undo when the pin was moved after the conversion', () => {
209
+ const shapeId = makeShape(100, 100, 100, 50)
210
+ const { thread } = makeThread(shapeId, 0.5, 0.5, true)
211
+ editor.markHistoryStoppingPoint()
212
+
213
+ editor.deleteShape(shapeId)
214
+ const converted = getCommentRecord(editor, thread.id) as typeof thread
215
+ commitCommentMutation(editor, ({ put }) =>
216
+ put([{ ...converted, anchor: { type: 'point', x: 900, y: 900 } }])
217
+ )
218
+
219
+ editor.undo()
220
+
221
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
222
+ expect(updated.anchor).toEqual({ type: 'point', x: 900, y: 900 })
223
+ })
224
+
225
+ it('leaves threads on other shapes untouched', () => {
226
+ const shapeId = makeShape()
227
+ const otherId = makeShape(300, 300)
228
+ const { thread } = makeThread(otherId)
229
+
230
+ editor.deleteShape(shapeId)
231
+
232
+ const updated = getCommentRecord(editor, thread.id) as typeof thread
233
+ expect(updated.anchor.type).toBe('shape')
234
+ })
235
+ })
236
+
237
+ describe('moving a shape to another page', () => {
238
+ it('re-homes the thread and its comments to the new page, keeping the shape anchor', () => {
239
+ const shapeId = makeShape()
240
+ const { thread, comment } = makeThread(shapeId)
241
+ const page2 = makeSecondPage()
242
+
243
+ editor.moveShapesToPage([shapeId], page2)
244
+
245
+ const updatedThread = getCommentRecord(editor, thread.id) as typeof thread
246
+ expect(updatedThread.pageId).toBe(page2)
247
+ expect(updatedThread.anchor).toEqual(thread.anchor)
248
+ const updatedComment = getComments(editor).find((c) => c.id === comment.id)!
249
+ expect(updatedComment.pageId).toBe(page2)
250
+ })
251
+
252
+ it('re-homes threads anchored to children of a moved frame', () => {
253
+ const frameId = createShapeId()
254
+ editor.createShape({ id: frameId, type: 'frame', x: 0, y: 0, props: { w: 400, h: 400 } })
255
+ const childId = createShapeId()
256
+ editor.createShape({
257
+ id: childId,
258
+ type: 'geo',
259
+ parentId: frameId,
260
+ x: 50,
261
+ y: 50,
262
+ props: { w: 100, h: 100 },
263
+ })
264
+ const { thread } = makeThread(childId)
265
+ const page2 = makeSecondPage()
266
+
267
+ editor.moveShapesToPage([frameId], page2)
268
+
269
+ const updatedThread = getCommentRecord(editor, thread.id) as typeof thread
270
+ expect(updatedThread.pageId).toBe(page2)
271
+ expect(updatedThread.anchor.type).toBe('shape')
272
+ })
273
+
274
+ it('re-homes the thread back when the move is undone', () => {
275
+ const shapeId = makeShape()
276
+ const { thread } = makeThread(shapeId)
277
+ const page1 = editor.getCurrentPageId()
278
+ const page2 = makeSecondPage()
279
+ editor.markHistoryStoppingPoint()
280
+
281
+ editor.moveShapesToPage([shapeId], page2)
282
+ expect((getCommentRecord(editor, thread.id) as typeof thread).pageId).toBe(page2)
283
+
284
+ editor.undo()
285
+
286
+ const updatedThread = getCommentRecord(editor, thread.id) as typeof thread
287
+ expect(updatedThread.pageId).toBe(page1)
288
+ expect(updatedThread.anchor.type).toBe('shape')
289
+ })
290
+ })