@tldraw/commenting 0.0.0-bootstrap → 5.3.0-canary.31036673d3f8

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 (279) hide show
  1. package/README.md +0 -2
  2. package/commenting.css +1139 -329
  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/cluster-input.js +2 -2
  6. package/dist-cjs/canvas/cluster-input.js.map +2 -2
  7. package/dist-cjs/canvas/comment-body.js +1 -1
  8. package/dist-cjs/canvas/comment-body.js.map +2 -2
  9. package/dist-cjs/canvas/comment-drafts.js +54 -0
  10. package/dist-cjs/canvas/comment-drafts.js.map +7 -0
  11. package/dist-cjs/canvas/comment-mutations.js +123 -0
  12. package/dist-cjs/canvas/comment-mutations.js.map +7 -0
  13. package/dist-cjs/canvas/comment-reactions.js +163 -0
  14. package/dist-cjs/canvas/comment-reactions.js.map +7 -0
  15. package/dist-cjs/canvas/comment-render.js +5 -3
  16. package/dist-cjs/canvas/comment-render.js.map +2 -2
  17. package/dist-cjs/canvas/comment-store.js +19 -9
  18. package/dist-cjs/canvas/comment-store.js.map +2 -2
  19. package/dist-cjs/canvas/comment-tool.js +64 -14
  20. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  21. package/dist-cjs/canvas/comments-filter-menu.js +20 -38
  22. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  23. package/dist-cjs/canvas/comments-overflow-menu.js +22 -27
  24. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  25. package/dist-cjs/canvas/comments-overlay.js +429 -474
  26. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  27. package/dist-cjs/canvas/comments-sidebar.js +35 -32
  28. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  29. package/dist-cjs/canvas/comments-visibility-toggle.js +65 -0
  30. package/dist-cjs/canvas/comments-visibility-toggle.js.map +7 -0
  31. package/dist-cjs/canvas/context.js +17 -0
  32. package/dist-cjs/canvas/context.js.map +7 -0
  33. package/dist-cjs/canvas/hooks.js +22 -3
  34. package/dist-cjs/canvas/hooks.js.map +2 -2
  35. package/dist-cjs/canvas/options.js +19 -2
  36. package/dist-cjs/canvas/options.js.map +2 -2
  37. package/dist-cjs/canvas/pin-stacking.js +56 -0
  38. package/dist-cjs/canvas/pin-stacking.js.map +7 -0
  39. package/dist-cjs/canvas/sidebar-filters.js +2 -2
  40. package/dist-cjs/canvas/sidebar-filters.js.map +2 -2
  41. package/dist-cjs/canvas/state.js +28 -14
  42. package/dist-cjs/canvas/state.js.map +2 -2
  43. package/dist-cjs/canvas/thread-preview.js +185 -0
  44. package/dist-cjs/canvas/thread-preview.js.map +7 -0
  45. package/dist-cjs/canvas/thread-stack.js +199 -0
  46. package/dist-cjs/canvas/thread-stack.js.map +7 -0
  47. package/dist-cjs/canvas/thread-state.js +67 -21
  48. package/dist-cjs/canvas/thread-state.js.map +2 -2
  49. package/dist-cjs/canvas/thread-view.js +397 -0
  50. package/dist-cjs/canvas/thread-view.js.map +7 -0
  51. package/dist-cjs/clustering/computeClusterTable.js +4 -4
  52. package/dist-cjs/clustering/computeClusterTable.js.map +2 -2
  53. package/dist-cjs/clustering/runtime.js +119 -7
  54. package/dist-cjs/clustering/runtime.js.map +2 -2
  55. package/dist-cjs/clustering/types.js.map +1 -1
  56. package/dist-cjs/index.d.ts +763 -333
  57. package/dist-cjs/index.js +46 -28
  58. package/dist-cjs/index.js.map +2 -2
  59. package/dist-cjs/ui/byline.js +6 -4
  60. package/dist-cjs/ui/byline.js.map +2 -2
  61. package/dist-cjs/ui/comment-card.js +15 -8
  62. package/dist-cjs/ui/comment-card.js.map +2 -2
  63. package/dist-cjs/ui/comment-composer.js +137 -36
  64. package/dist-cjs/ui/comment-composer.js.map +2 -2
  65. package/dist-cjs/ui/comment-pin.js +24 -2
  66. package/dist-cjs/ui/comment-pin.js.map +2 -2
  67. package/dist-cjs/ui/comment-thread.js +9 -7
  68. package/dist-cjs/ui/comment-thread.js.map +2 -2
  69. package/dist-cjs/ui/comments-list.js +30 -18
  70. package/dist-cjs/ui/comments-list.js.map +2 -2
  71. package/dist-cjs/ui/count-badge.js +3 -2
  72. package/dist-cjs/ui/count-badge.js.map +2 -2
  73. package/dist-cjs/ui/emoji-picker.js +54 -0
  74. package/dist-cjs/ui/emoji-picker.js.map +7 -0
  75. package/dist-cjs/ui/empty-state.js +3 -3
  76. package/dist-cjs/ui/empty-state.js.map +2 -2
  77. package/dist-cjs/ui/format-time.js +4 -1
  78. package/dist-cjs/ui/format-time.js.map +2 -2
  79. package/dist-cjs/ui/reaction-picker.js +73 -0
  80. package/dist-cjs/ui/reaction-picker.js.map +7 -0
  81. package/dist-cjs/ui/reaction.js +59 -6
  82. package/dist-cjs/ui/reaction.js.map +2 -2
  83. package/dist-cjs/ui/reactions.js +20 -7
  84. package/dist-cjs/ui/reactions.js.map +2 -2
  85. package/dist-cjs/ui/{mention.js → reply-count.js} +9 -11
  86. package/dist-cjs/ui/reply-count.js.map +7 -0
  87. package/dist-cjs/ui/send-button.js +20 -1
  88. package/dist-cjs/ui/send-button.js.map +2 -2
  89. package/dist-cjs/ui/{comment-text.js → tooltip-button.js} +12 -9
  90. package/dist-cjs/ui/tooltip-button.js.map +7 -0
  91. package/dist-esm/canvas/anchor-lifecycle.mjs +128 -0
  92. package/dist-esm/canvas/anchor-lifecycle.mjs.map +7 -0
  93. package/dist-esm/canvas/cluster-input.mjs +2 -2
  94. package/dist-esm/canvas/cluster-input.mjs.map +2 -2
  95. package/dist-esm/canvas/comment-body.mjs +1 -1
  96. package/dist-esm/canvas/comment-body.mjs.map +2 -2
  97. package/dist-esm/canvas/comment-drafts.mjs +34 -0
  98. package/dist-esm/canvas/comment-drafts.mjs.map +7 -0
  99. package/dist-esm/canvas/comment-mutations.mjs +103 -0
  100. package/dist-esm/canvas/comment-mutations.mjs.map +7 -0
  101. package/dist-esm/canvas/comment-reactions.mjs +152 -0
  102. package/dist-esm/canvas/comment-reactions.mjs.map +7 -0
  103. package/dist-esm/canvas/comment-render.mjs +5 -3
  104. package/dist-esm/canvas/comment-render.mjs.map +2 -2
  105. package/dist-esm/canvas/comment-store.mjs +19 -9
  106. package/dist-esm/canvas/comment-store.mjs.map +2 -2
  107. package/dist-esm/canvas/comment-tool.mjs +67 -17
  108. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  109. package/dist-esm/canvas/comments-filter-menu.mjs +20 -38
  110. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  111. package/dist-esm/canvas/comments-overflow-menu.mjs +23 -27
  112. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  113. package/dist-esm/canvas/comments-overlay.mjs +450 -479
  114. package/dist-esm/canvas/comments-overlay.mjs.map +3 -3
  115. package/dist-esm/canvas/comments-sidebar.mjs +38 -35
  116. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  117. package/dist-esm/canvas/comments-visibility-toggle.mjs +45 -0
  118. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +7 -0
  119. package/dist-esm/canvas/context.mjs +1 -0
  120. package/dist-esm/canvas/context.mjs.map +7 -0
  121. package/dist-esm/canvas/hooks.mjs +28 -5
  122. package/dist-esm/canvas/hooks.mjs.map +2 -2
  123. package/dist-esm/canvas/options.mjs +21 -3
  124. package/dist-esm/canvas/options.mjs.map +2 -2
  125. package/dist-esm/canvas/pin-stacking.mjs +36 -0
  126. package/dist-esm/canvas/pin-stacking.mjs.map +7 -0
  127. package/dist-esm/canvas/sidebar-filters.mjs +2 -2
  128. package/dist-esm/canvas/sidebar-filters.mjs.map +2 -2
  129. package/dist-esm/canvas/state.mjs +29 -19
  130. package/dist-esm/canvas/state.mjs.map +2 -2
  131. package/dist-esm/canvas/thread-preview.mjs +170 -0
  132. package/dist-esm/canvas/thread-preview.mjs.map +7 -0
  133. package/dist-esm/canvas/thread-stack.mjs +190 -0
  134. package/dist-esm/canvas/thread-stack.mjs.map +7 -0
  135. package/dist-esm/canvas/thread-state.mjs +71 -22
  136. package/dist-esm/canvas/thread-state.mjs.map +2 -2
  137. package/dist-esm/canvas/thread-view.mjs +402 -0
  138. package/dist-esm/canvas/thread-view.mjs.map +7 -0
  139. package/dist-esm/clustering/computeClusterTable.mjs +4 -4
  140. package/dist-esm/clustering/computeClusterTable.mjs.map +2 -2
  141. package/dist-esm/clustering/runtime.mjs +119 -7
  142. package/dist-esm/clustering/runtime.mjs.map +2 -2
  143. package/dist-esm/index.d.mts +763 -333
  144. package/dist-esm/index.mjs +87 -41
  145. package/dist-esm/index.mjs.map +2 -2
  146. package/dist-esm/ui/byline.mjs +6 -4
  147. package/dist-esm/ui/byline.mjs.map +2 -2
  148. package/dist-esm/ui/comment-card.mjs +15 -8
  149. package/dist-esm/ui/comment-card.mjs.map +2 -2
  150. package/dist-esm/ui/comment-composer.mjs +148 -36
  151. package/dist-esm/ui/comment-composer.mjs.map +2 -2
  152. package/dist-esm/ui/comment-pin.mjs +24 -2
  153. package/dist-esm/ui/comment-pin.mjs.map +2 -2
  154. package/dist-esm/ui/comment-thread.mjs +9 -7
  155. package/dist-esm/ui/comment-thread.mjs.map +2 -2
  156. package/dist-esm/ui/comments-list.mjs +43 -29
  157. package/dist-esm/ui/comments-list.mjs.map +2 -2
  158. package/dist-esm/ui/count-badge.mjs +3 -2
  159. package/dist-esm/ui/count-badge.mjs.map +2 -2
  160. package/dist-esm/ui/emoji-picker.mjs +34 -0
  161. package/dist-esm/ui/emoji-picker.mjs.map +7 -0
  162. package/dist-esm/ui/empty-state.mjs +3 -3
  163. package/dist-esm/ui/empty-state.mjs.map +2 -2
  164. package/dist-esm/ui/format-time.mjs +4 -1
  165. package/dist-esm/ui/format-time.mjs.map +2 -2
  166. package/dist-esm/ui/reaction-picker.mjs +60 -0
  167. package/dist-esm/ui/reaction-picker.mjs.map +7 -0
  168. package/dist-esm/ui/reaction.mjs +60 -7
  169. package/dist-esm/ui/reaction.mjs.map +2 -2
  170. package/dist-esm/ui/reactions.mjs +21 -8
  171. package/dist-esm/ui/reactions.mjs.map +2 -2
  172. package/dist-esm/ui/reply-count.mjs +9 -0
  173. package/dist-esm/ui/reply-count.mjs.map +7 -0
  174. package/dist-esm/ui/send-button.mjs +20 -1
  175. package/dist-esm/ui/send-button.mjs.map +2 -2
  176. package/dist-esm/ui/tooltip-button.mjs +12 -0
  177. package/dist-esm/ui/tooltip-button.mjs.map +7 -0
  178. package/package.json +6 -6
  179. package/src/canvas/anchor-lifecycle.test.ts +290 -0
  180. package/src/canvas/anchor-lifecycle.ts +205 -0
  181. package/src/canvas/canvas.css +461 -46
  182. package/src/canvas/cluster-input.test.ts +31 -23
  183. package/src/canvas/cluster-input.ts +3 -4
  184. package/src/canvas/comment-body.tsx +1 -1
  185. package/src/canvas/comment-drafts.test.ts +55 -0
  186. package/src/canvas/comment-drafts.ts +46 -0
  187. package/src/canvas/comment-mutations.test.ts +410 -0
  188. package/src/canvas/comment-mutations.ts +288 -0
  189. package/src/canvas/comment-reactions.test.ts +132 -0
  190. package/src/canvas/comment-reactions.tsx +245 -0
  191. package/src/canvas/comment-render.test.ts +1 -1
  192. package/src/canvas/comment-render.ts +9 -5
  193. package/src/canvas/comment-store.ts +67 -27
  194. package/src/canvas/comment-tool.test.ts +162 -0
  195. package/src/canvas/comment-tool.tsx +105 -23
  196. package/src/canvas/comments-filter-menu.tsx +23 -32
  197. package/src/canvas/comments-overflow-menu.tsx +14 -21
  198. package/src/canvas/comments-overlay.tsx +695 -622
  199. package/src/canvas/comments-sidebar.test.ts +45 -0
  200. package/src/canvas/comments-sidebar.tsx +76 -58
  201. package/src/canvas/comments-visibility-toggle.tsx +49 -0
  202. package/src/canvas/context.ts +47 -0
  203. package/src/canvas/hooks.ts +52 -11
  204. package/src/canvas/options.test.ts +52 -2
  205. package/src/canvas/options.ts +133 -9
  206. package/src/canvas/pin-stacking.test.ts +114 -0
  207. package/src/canvas/pin-stacking.ts +57 -0
  208. package/src/canvas/sidebar-filters.ts +4 -3
  209. package/src/canvas/state.ts +92 -35
  210. package/src/canvas/thread-preview.test.ts +91 -0
  211. package/src/canvas/thread-preview.tsx +304 -0
  212. package/src/canvas/thread-stack.tsx +252 -0
  213. package/src/canvas/thread-state.test.ts +209 -0
  214. package/src/canvas/thread-state.ts +137 -36
  215. package/src/canvas/thread-view.tsx +516 -0
  216. package/src/clustering/computeClusterTable.test.ts +24 -23
  217. package/src/clustering/computeClusterTable.ts +5 -5
  218. package/src/clustering/runtime.test.ts +217 -7
  219. package/src/clustering/runtime.ts +171 -17
  220. package/src/clustering/types.ts +9 -9
  221. package/src/index.ts +76 -40
  222. package/src/ui/byline.tsx +7 -5
  223. package/src/ui/comment-card.tsx +20 -10
  224. package/src/ui/comment-composer.tsx +206 -40
  225. package/src/ui/comment-pin.tsx +26 -2
  226. package/src/ui/comment-thread.tsx +13 -6
  227. package/src/ui/comments-list.test.ts +31 -0
  228. package/src/ui/comments-list.tsx +45 -21
  229. package/src/ui/comments.css +566 -281
  230. package/src/ui/count-badge.tsx +9 -2
  231. package/src/ui/emoji-picker.test.ts +25 -0
  232. package/src/ui/emoji-picker.tsx +76 -0
  233. package/src/ui/empty-state.tsx +3 -3
  234. package/src/ui/format-time.ts +7 -2
  235. package/src/ui/reaction-picker.tsx +109 -0
  236. package/src/ui/reaction.tsx +121 -6
  237. package/src/ui/reactions.tsx +69 -10
  238. package/src/ui/reply-count.ts +16 -0
  239. package/src/ui/send-button.tsx +18 -3
  240. package/src/ui/tooltip-button.tsx +20 -0
  241. package/dist-cjs/canvas/region-options.js +0 -49
  242. package/dist-cjs/canvas/region-options.js.map +0 -7
  243. package/dist-cjs/ui/avatar.js +0 -43
  244. package/dist-cjs/ui/avatar.js.map +0 -7
  245. package/dist-cjs/ui/comment-mention.js +0 -42
  246. package/dist-cjs/ui/comment-mention.js.map +0 -7
  247. package/dist-cjs/ui/comment-text.js.map +0 -7
  248. package/dist-cjs/ui/mention-list.js +0 -70
  249. package/dist-cjs/ui/mention-list.js.map +0 -7
  250. package/dist-cjs/ui/mention-suggestion.js +0 -206
  251. package/dist-cjs/ui/mention-suggestion.js.map +0 -7
  252. package/dist-cjs/ui/mention.js.map +0 -7
  253. package/dist-cjs/ui/render-markdown.js +0 -63
  254. package/dist-cjs/ui/render-markdown.js.map +0 -7
  255. package/dist-esm/canvas/region-options.mjs +0 -29
  256. package/dist-esm/canvas/region-options.mjs.map +0 -7
  257. package/dist-esm/ui/avatar.mjs +0 -23
  258. package/dist-esm/ui/avatar.mjs.map +0 -7
  259. package/dist-esm/ui/comment-mention.mjs +0 -22
  260. package/dist-esm/ui/comment-mention.mjs.map +0 -7
  261. package/dist-esm/ui/comment-text.mjs +0 -9
  262. package/dist-esm/ui/comment-text.mjs.map +0 -7
  263. package/dist-esm/ui/mention-list.mjs +0 -50
  264. package/dist-esm/ui/mention-list.mjs.map +0 -7
  265. package/dist-esm/ui/mention-suggestion.mjs +0 -186
  266. package/dist-esm/ui/mention-suggestion.mjs.map +0 -7
  267. package/dist-esm/ui/mention.mjs +0 -11
  268. package/dist-esm/ui/mention.mjs.map +0 -7
  269. package/dist-esm/ui/render-markdown.mjs +0 -45
  270. package/dist-esm/ui/render-markdown.mjs.map +0 -7
  271. package/src/canvas/region-options.ts +0 -57
  272. package/src/ui/avatar.tsx +0 -31
  273. package/src/ui/comment-mention.ts +0 -47
  274. package/src/ui/comment-text.tsx +0 -12
  275. package/src/ui/mention-list.tsx +0 -106
  276. package/src/ui/mention-suggestion.test.ts +0 -18
  277. package/src/ui/mention-suggestion.tsx +0 -285
  278. package/src/ui/mention.tsx +0 -9
  279. package/src/ui/render-markdown.tsx +0 -72
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var anchor_lifecycle_exports = {};
20
+ __export(anchor_lifecycle_exports, {
21
+ registerCommentAnchorLifecycle: () => registerCommentAnchorLifecycle
22
+ });
23
+ module.exports = __toCommonJS(anchor_lifecycle_exports);
24
+ var import_utils = require("@tldraw/utils");
25
+ var import_comment_mutations = require("./comment-mutations");
26
+ var import_comment_store = require("./comment-store");
27
+ var import_thread_state = require("./thread-state");
28
+ const convertedByShapeCache = new import_utils.WeakCache();
29
+ function isAnchoredToShape(thread, shapeId) {
30
+ const anchor = thread.anchor;
31
+ return anchor.type === "shape" && anchor.shapeId === shapeId;
32
+ }
33
+ function registerCommentAnchorLifecycle(editor) {
34
+ const pendingByShape = /* @__PURE__ */ new Map();
35
+ const convertedByShape = convertedByShapeCache.get(editor, () => /* @__PURE__ */ new Map());
36
+ function rehomeThread(thread, pageId, updates) {
37
+ updates.push({ ...thread, pageId });
38
+ for (const comment of (0, import_comment_store.getComments)(editor)) {
39
+ if (comment.threadId === thread.id) updates.push({ ...comment, pageId });
40
+ }
41
+ }
42
+ const disposeBeforeDelete = editor.sideEffects.registerBeforeDeleteHandler(
43
+ "shape",
44
+ (shape, source) => {
45
+ if (source === "remote") return;
46
+ for (const thread of (0, import_comment_store.getCommentThreads)(editor)) {
47
+ if (!isAnchoredToShape(thread, shape.id)) continue;
48
+ let snapshot = pendingByShape.get(shape.id);
49
+ if (!snapshot) {
50
+ snapshot = /* @__PURE__ */ new Map();
51
+ pendingByShape.set(shape.id, snapshot);
52
+ }
53
+ let point = (0, import_thread_state.anchorPagePoint)(editor, thread.anchor);
54
+ const inset = (0, import_thread_state.impreciseShapePinInset)(editor, thread.anchor);
55
+ if (point && inset) {
56
+ const zoom = editor.getZoomLevel();
57
+ point = { x: point.x + inset.x / zoom, y: point.y + inset.y / zoom };
58
+ }
59
+ snapshot.set(thread.id, point);
60
+ }
61
+ }
62
+ );
63
+ const returnedShapeIds = /* @__PURE__ */ new Set();
64
+ const disposeOperationComplete = editor.sideEffects.registerOperationCompleteHandler((source) => {
65
+ if (source === "remote") return;
66
+ if (pendingByShape.size === 0 && returnedShapeIds.size === 0) return;
67
+ const settled = [...pendingByShape.entries()];
68
+ pendingByShape.clear();
69
+ const returned = [...returnedShapeIds];
70
+ returnedShapeIds.clear();
71
+ const updates = [];
72
+ for (const [shapeId, threadPoints] of settled) {
73
+ if (editor.getShape(shapeId)) continue;
74
+ for (const [threadId, point] of threadPoints) {
75
+ if (!point) continue;
76
+ const thread = (0, import_comment_store.getCommentRecord)(editor, threadId);
77
+ if (!thread || thread.typeName !== "comment-thread") continue;
78
+ if (!isAnchoredToShape(thread, shapeId)) continue;
79
+ let converted = convertedByShape.get(shapeId);
80
+ if (!converted) {
81
+ converted = [];
82
+ convertedByShape.set(shapeId, converted);
83
+ }
84
+ converted.push({ threadId, anchor: thread.anchor, point });
85
+ updates.push({ ...thread, anchor: { type: "point", x: point.x, y: point.y } });
86
+ }
87
+ }
88
+ for (const shapeId of returned) {
89
+ const shape = editor.getShape(shapeId);
90
+ if (!shape) continue;
91
+ const converted = convertedByShape.get(shapeId);
92
+ if (!converted) continue;
93
+ convertedByShape.delete(shapeId);
94
+ const pageId = editor.getAncestorPageId(shape);
95
+ for (const { threadId, anchor, point } of converted) {
96
+ const thread = (0, import_comment_store.getCommentRecord)(editor, threadId);
97
+ if (!thread || thread.typeName !== "comment-thread") continue;
98
+ const current = thread.anchor;
99
+ if (current.type !== "point" || current.x !== point.x || current.y !== point.y) {
100
+ continue;
101
+ }
102
+ if (!pageId || thread.pageId === pageId) {
103
+ updates.push({ ...thread, anchor });
104
+ } else {
105
+ rehomeThread({ ...thread, anchor }, pageId, updates);
106
+ }
107
+ }
108
+ }
109
+ if (updates.length > 0) {
110
+ (0, import_comment_mutations.commitCommentMutation)(editor, () => (0, import_comment_mutations.putRecordsInCommit)(editor, updates));
111
+ }
112
+ });
113
+ const disposeAfterCreate = editor.sideEffects.registerAfterCreateHandler(
114
+ "shape",
115
+ (shape, source) => {
116
+ if (source === "remote") return;
117
+ if (convertedByShape.has(shape.id)) returnedShapeIds.add(shape.id);
118
+ }
119
+ );
120
+ const disposeAfterChange = editor.sideEffects.registerAfterChangeHandler(
121
+ "shape",
122
+ (prev, next, source) => {
123
+ if (source === "remote") return;
124
+ if (prev.parentId === next.parentId) return;
125
+ const pageId = editor.getAncestorPageId(next);
126
+ if (!pageId) return;
127
+ const movedIds = editor.getShapeAndDescendantIds([next.id]);
128
+ const updates = [];
129
+ for (const thread of (0, import_comment_store.getCommentThreads)(editor)) {
130
+ const anchor = thread.anchor;
131
+ if (anchor.type !== "shape") continue;
132
+ if (!movedIds.has(anchor.shapeId)) continue;
133
+ if (thread.pageId === pageId) continue;
134
+ rehomeThread(thread, pageId, updates);
135
+ }
136
+ if (updates.length > 0) {
137
+ (0, import_comment_mutations.commitCommentMutation)(editor, () => (0, import_comment_mutations.putRecordsInCommit)(editor, updates));
138
+ }
139
+ }
140
+ );
141
+ return () => {
142
+ disposeBeforeDelete();
143
+ disposeOperationComplete();
144
+ disposeAfterCreate();
145
+ disposeAfterChange();
146
+ };
147
+ }
148
+ //# sourceMappingURL=anchor-lifecycle.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/canvas/anchor-lifecycle.ts"],
4
+ "sourcesContent": ["import { WeakCache } from '@tldraw/utils'\nimport { Editor, TLCommentAnchor, TLCommentThread, TLPageId, TLShapeId, VecLike } from 'tldraw'\nimport { commitCommentMutation, putRecordsInCommit } from './comment-mutations'\nimport { getCommentRecord, getComments, getCommentThreads, TLCommentRecord } from './comment-store'\nimport { anchorPagePoint, impreciseShapePinInset } from './thread-state'\n\ntype ShapeAnchor = Extract<TLCommentAnchor, { type: 'shape' }>\n\n/**\n * Threads converted to point anchors because their shape was deleted, kept so the anchor can be\n * restored if the shape comes back (page move re-create, undo of the delete). Owned by the\n * editor, not the registration closure: the registering effect can re-run (a prop identity\n * change, a remount), and an undo can arrive arbitrarily long after the delete \u2014 the memory has\n * to outlive any one registration.\n */\nconst convertedByShapeCache = new WeakCache<\n\tEditor,\n\tMap<TLShapeId, { threadId: string; anchor: ShapeAnchor; point: VecLike }[]>\n>()\n\nfunction isAnchoredToShape(\n\tthread: TLCommentThread,\n\tshapeId: TLShapeId\n): thread is TLCommentThread & { anchor: ShapeAnchor } {\n\tconst anchor = thread.anchor\n\treturn anchor.type === 'shape' && anchor.shapeId === shapeId\n}\n\n/**\n * Keep shape-anchored threads alive across their shape's lifecycle:\n *\n * - When the shape is deleted, the thread converts to a `point` anchor at the spot its pin last\n * occupied, so the conversation outlives the shape instead of becoming invisible (a missing\n * shape has no bounds, which hides the pin).\n * - When the shape moves to another page, the thread follows: its `pageId` and each comment's\n * denormalized `pageId` update to the shape's new page, and the anchor keeps riding the shape.\n * - When a deleted shape comes back (a page move re-creates it with its id preserved; undoing a\n * delete restores it), the thread re-attaches \u2014 unless its pin was manually moved in the\n * meantime, in which case the manual placement wins.\n *\n * A page move is `deleteShapes` + re-create with preserved ids inside one `editor.run`, but each\n * store write is its own operation \u2014 so at no single moment does \"this shape is being moved\"\n * exist as an observable event. The handlers therefore cooperate across operations:\n * `beforeDelete` snapshots where each affected pin sits (every record is still in the store at\n * that point, so page bounds resolve even for children of a deleted frame); the\n * operation-complete pass converts threads whose shape is really gone, remembering the original\n * anchor; `afterCreate` notes a reappeared shape id, and the operation-complete pass restores\n * the anchor once the store has settled (creation order within an operation is arbitrary, so a\n * fresh shape may not resolve an ancestor page mid-operation). Undo/redo of a move\n * replays as a `parentId` update (remove + add of one id squash to an update in the history\n * diff), so an `afterChange` handler re-homes threads on cross-page reparents \u2014 including\n * threads anchored to descendants, which move with their parent without change events of their\n * own.\n *\n * Remote changes are ignored: the client that performed the operation runs this same\n * maintenance and syncs the resulting thread updates. Writes honour the\n * {@link CommentingOptions.history} option, so the consumer decides whether they're undoable.\n *\n * Registered by `CanvasComments` on mount; parts-built consumers can call this directly.\n * Returns a cleanup function that unregisters all handlers.\n *\n * @public\n */\nexport function registerCommentAnchorLifecycle(editor: Editor): () => void {\n\t// Pin positions snapshotted during the current operation: shape id -> (thread id -> pin page\n\t// point).\n\tconst pendingByShape = new Map<TLShapeId, Map<string, VecLike | null>>()\n\tconst convertedByShape = convertedByShapeCache.get(editor, () => new Map())\n\n\tfunction rehomeThread(thread: TLCommentThread, pageId: TLPageId, updates: TLCommentRecord[]) {\n\t\tupdates.push({ ...thread, pageId })\n\t\tfor (const comment of getComments(editor)) {\n\t\t\tif (comment.threadId === thread.id) updates.push({ ...comment, pageId })\n\t\t}\n\t}\n\n\tconst disposeBeforeDelete = editor.sideEffects.registerBeforeDeleteHandler(\n\t\t'shape',\n\t\t(shape, source) => {\n\t\t\tif (source === 'remote') return\n\t\t\tfor (const thread of getCommentThreads(editor)) {\n\t\t\t\tif (!isAnchoredToShape(thread, shape.id)) continue\n\t\t\t\tlet snapshot = pendingByShape.get(shape.id)\n\t\t\t\tif (!snapshot) {\n\t\t\t\t\tsnapshot = new Map()\n\t\t\t\t\tpendingByShape.set(shape.id, snapshot)\n\t\t\t\t}\n\t\t\t\t// Snapshot where the pin is drawn, not just the anchor point: imprecise shape pins\n\t\t\t\t// render inset toward the shape's centre, and the converted point pin renders at\n\t\t\t\t// its point exactly \u2014 without the inset the pin would jump on deletion. The inset\n\t\t\t\t// is screen-fixed, so bake it in at the current zoom.\n\t\t\t\tlet point = anchorPagePoint(editor, thread.anchor)\n\t\t\t\tconst inset = impreciseShapePinInset(editor, thread.anchor)\n\t\t\t\tif (point && inset) {\n\t\t\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\t\t\tpoint = { x: point.x + inset.x / zoom, y: point.y + inset.y / zoom }\n\t\t\t\t}\n\t\t\t\tsnapshot.set(thread.id, point)\n\t\t\t}\n\t\t}\n\t)\n\n\t// Shape ids from `convertedByShape` re-created during the current operation. Restores are\n\t// settled at operation complete rather than in `afterCreate` itself: creation order within an\n\t// operation is arbitrary, so a shape can appear before its parent and not resolve an ancestor\n\t// page yet \u2014 and the conversion memory must outlive any such partial state.\n\tconst returnedShapeIds = new Set<TLShapeId>()\n\n\tconst disposeOperationComplete = editor.sideEffects.registerOperationCompleteHandler((source) => {\n\t\t// Only user-sourced handlers populate the maps and only local operations should settle\n\t\t// them; a remote operation completing leaves any (impossible-in-practice) leftovers for\n\t\t// the next local settle rather than judging them against remote state.\n\t\tif (source === 'remote') return\n\t\tif (pendingByShape.size === 0 && returnedShapeIds.size === 0) return\n\t\tconst settled = [...pendingByShape.entries()]\n\t\tpendingByShape.clear()\n\t\tconst returned = [...returnedShapeIds]\n\t\treturnedShapeIds.clear()\n\n\t\tconst updates: TLCommentRecord[] = []\n\t\tfor (const [shapeId, threadPoints] of settled) {\n\t\t\tif (editor.getShape(shapeId)) continue\n\t\t\tfor (const [threadId, point] of threadPoints) {\n\t\t\t\tif (!point) continue\n\t\t\t\tconst thread = getCommentRecord(editor, threadId)\n\t\t\t\tif (!thread || thread.typeName !== 'comment-thread') continue\n\t\t\t\tif (!isAnchoredToShape(thread, shapeId)) continue\n\t\t\t\tlet converted = convertedByShape.get(shapeId)\n\t\t\t\tif (!converted) {\n\t\t\t\t\tconverted = []\n\t\t\t\t\tconvertedByShape.set(shapeId, converted)\n\t\t\t\t}\n\t\t\t\tconverted.push({ threadId, anchor: thread.anchor, point })\n\t\t\t\tupdates.push({ ...thread, anchor: { type: 'point', x: point.x, y: point.y } })\n\t\t\t}\n\t\t}\n\n\t\tfor (const shapeId of returned) {\n\t\t\tconst shape = editor.getShape(shapeId)\n\t\t\tif (!shape) continue\n\t\t\tconst converted = convertedByShape.get(shapeId)\n\t\t\tif (!converted) continue\n\t\t\tconvertedByShape.delete(shapeId)\n\n\t\t\tconst pageId = editor.getAncestorPageId(shape)\n\t\t\tfor (const { threadId, anchor, point } of converted) {\n\t\t\t\tconst thread = getCommentRecord(editor, threadId)\n\t\t\t\tif (!thread || thread.typeName !== 'comment-thread') continue\n\t\t\t\t// Re-attach only threads still sitting exactly where the conversion left them \u2014 a\n\t\t\t\t// pin moved since then was placed deliberately, and that placement wins.\n\t\t\t\tconst current = thread.anchor\n\t\t\t\tif (current.type !== 'point' || current.x !== point.x || current.y !== point.y) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!pageId || thread.pageId === pageId) {\n\t\t\t\t\tupdates.push({ ...thread, anchor })\n\t\t\t\t} else {\n\t\t\t\t\trehomeThread({ ...thread, anchor }, pageId, updates)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (updates.length > 0) {\n\t\t\tcommitCommentMutation(editor, () => putRecordsInCommit(editor, updates))\n\t\t}\n\t})\n\n\tconst disposeAfterCreate = editor.sideEffects.registerAfterCreateHandler(\n\t\t'shape',\n\t\t(shape, source) => {\n\t\t\tif (source === 'remote') return\n\t\t\tif (convertedByShape.has(shape.id)) returnedShapeIds.add(shape.id)\n\t\t}\n\t)\n\n\tconst disposeAfterChange = editor.sideEffects.registerAfterChangeHandler(\n\t\t'shape',\n\t\t(prev, next, source) => {\n\t\t\tif (source === 'remote') return\n\t\t\tif (prev.parentId === next.parentId) return\n\t\t\tconst pageId = editor.getAncestorPageId(next)\n\t\t\tif (!pageId) return\n\t\t\t// Descendants move with their parent without change events of their own.\n\t\t\tconst movedIds = editor.getShapeAndDescendantIds([next.id])\n\t\t\tconst updates: TLCommentRecord[] = []\n\t\t\tfor (const thread of getCommentThreads(editor)) {\n\t\t\t\tconst anchor = thread.anchor\n\t\t\t\tif (anchor.type !== 'shape') continue\n\t\t\t\tif (!movedIds.has(anchor.shapeId)) continue\n\t\t\t\tif (thread.pageId === pageId) continue\n\t\t\t\trehomeThread(thread, pageId, updates)\n\t\t\t}\n\t\t\tif (updates.length > 0) {\n\t\t\t\tcommitCommentMutation(editor, () => putRecordsInCommit(editor, updates))\n\t\t\t}\n\t\t}\n\t)\n\n\treturn () => {\n\t\tdisposeBeforeDelete()\n\t\tdisposeOperationComplete()\n\t\tdisposeAfterCreate()\n\t\tdisposeAfterChange()\n\t}\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -22,13 +22,13 @@ __export(cluster_input_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(cluster_input_exports);
24
24
  var import_thread_state = require("./thread-state");
25
- function collectClusterLeaves(editor, threads, openThreadId, impreciseShapeAnchor) {
25
+ function collectClusterLeaves(editor, threads, openThreadId) {
26
26
  const pageId = editor.getCurrentPageId();
27
27
  const leaves = [];
28
28
  for (const thread of threads) {
29
29
  if (thread.id === openThreadId) continue;
30
30
  if (thread.pageId !== pageId) continue;
31
- const point = (0, import_thread_state.anchorPagePoint)(editor, thread.anchor, impreciseShapeAnchor);
31
+ const point = (0, import_thread_state.anchorPagePoint)(editor, thread.anchor);
32
32
  if (!point) continue;
33
33
  leaves.push({
34
34
  id: thread.id,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/cluster-input.ts"],
4
- "sourcesContent": ["import type { Editor, TLCommentThread } from 'tldraw'\nimport type { LeafInput } from '../clustering/types'\nimport { anchorPagePoint } from './thread-state'\n\n/** @public */\nexport function collectClusterLeaves(\n\teditor: Editor,\n\tthreads: readonly TLCommentThread[],\n\topenThreadId: string | null,\n\timpreciseShapeAnchor?: { x: number; y: number }\n): LeafInput[] {\n\tconst pageId = editor.getCurrentPageId()\n\tconst leaves: LeafInput[] = []\n\n\tfor (const thread of threads) {\n\t\tif (thread.id === openThreadId) continue\n\t\tif (thread.pageId !== pageId) continue\n\n\t\tconst point = anchorPagePoint(editor, thread.anchor, impreciseShapeAnchor)\n\t\tif (!point) continue\n\n\t\tleaves.push({\n\t\t\tid: thread.id,\n\t\t\tpoint: { x: point.x, y: point.y },\n\t\t})\n\t}\n\n\treturn leaves\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAgC;AAGzB,SAAS,qBACf,QACA,SACA,cACA,sBACc;AACd,QAAM,SAAS,OAAO,iBAAiB;AACvC,QAAM,SAAsB,CAAC;AAE7B,aAAW,UAAU,SAAS;AAC7B,QAAI,OAAO,OAAO,aAAc;AAChC,QAAI,OAAO,WAAW,OAAQ;AAE9B,UAAM,YAAQ,qCAAgB,QAAQ,OAAO,QAAQ,oBAAoB;AACzE,QAAI,CAAC,MAAO;AAEZ,WAAO,KAAK;AAAA,MACX,IAAI,OAAO;AAAA,MACX,OAAO,EAAE,GAAG,MAAM,GAAG,GAAG,MAAM,EAAE;AAAA,IACjC,CAAC;AAAA,EACF;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import type { Editor, TLCommentThread } from 'tldraw'\nimport type { LeafInput } from '../clustering/types'\nimport { anchorPagePoint } from './thread-state'\n\n/** The cluster leaves for the threads pinned on the current page. @internal */\nexport function collectClusterLeaves(\n\teditor: Editor,\n\tthreads: readonly TLCommentThread[],\n\topenThreadId: string | null\n): LeafInput[] {\n\tconst pageId = editor.getCurrentPageId()\n\tconst leaves: LeafInput[] = []\n\n\tfor (const thread of threads) {\n\t\tif (thread.id === openThreadId) continue\n\t\tif (thread.pageId !== pageId) continue\n\n\t\tconst point = anchorPagePoint(editor, thread.anchor)\n\t\tif (!point) continue\n\n\t\tleaves.push({\n\t\t\tid: thread.id,\n\t\t\tpoint: { x: point.x, y: point.y },\n\t\t})\n\t}\n\n\treturn leaves\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAgC;AAGzB,SAAS,qBACf,QACA,SACA,cACc;AACd,QAAM,SAAS,OAAO,iBAAiB;AACvC,QAAM,SAAsB,CAAC;AAE7B,aAAW,UAAU,SAAS;AAC7B,QAAI,OAAO,OAAO,aAAc;AAChC,QAAI,OAAO,WAAW,OAAQ;AAE9B,UAAM,YAAQ,qCAAgB,QAAQ,OAAO,MAAM;AACnD,QAAI,CAAC,MAAO;AAEZ,WAAO,KAAK;AAAA,MACX,IAAI,OAAO;AAAA,MACX,OAAO,EAAE,GAAG,MAAM,GAAG,GAAG,MAAM,EAAE;AAAA,IACjC,CAAC;AAAA,EACF;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -26,6 +26,6 @@ var import_react = require("react");
26
26
  var import_comment_render = require("./comment-render");
27
27
  function CommentBody({ richText, resolveName }) {
28
28
  const html = (0, import_react.useMemo)(() => (0, import_comment_render.renderCommentHtml)(richText, resolveName), [richText, resolveName]);
29
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "cmt-text", dangerouslySetInnerHTML: { __html: html } });
29
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tlui-cmt-text", dangerouslySetInnerHTML: { __html: html } });
30
30
  }
31
31
  //# sourceMappingURL=comment-body.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/comment-body.tsx"],
4
- "sourcesContent": ["import { useMemo } from 'react'\nimport { TLRichText } from 'tldraw'\nimport { renderCommentHtml } from './comment-render'\n\n/** @public */\nexport interface CommentBodyProps {\n\trichText: TLRichText\n\t/** Maps a member id to its current display name, so \\@mentions show the live name. */\n\tresolveName?(id: string): string | undefined\n}\n\n/**\n * Renders a comment's rich-text body read-only through the limited comment extension set (no\n * headings), so formatting (bold, links, lists, highlight) is preserved rather than flattened, and\n * headings can never render. Use this as the `body` of a `CommentCard` on a canvas.\n * @public @react\n */\nexport function CommentBody({ richText, resolveName }: CommentBodyProps) {\n\tconst html = useMemo(() => renderCommentHtml(richText, resolveName), [richText, resolveName])\n\treturn <div className=\"cmt-text\" dangerouslySetInnerHTML={{ __html: html }} />\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBQ;AAnBR,mBAAwB;AAExB,4BAAkC;AAe3B,SAAS,YAAY,EAAE,UAAU,YAAY,GAAqB;AACxE,QAAM,WAAO,sBAAQ,UAAM,yCAAkB,UAAU,WAAW,GAAG,CAAC,UAAU,WAAW,CAAC;AAC5F,SAAO,4CAAC,SAAI,WAAU,YAAW,yBAAyB,EAAE,QAAQ,KAAK,GAAG;AAC7E;",
4
+ "sourcesContent": ["import { useMemo } from 'react'\nimport { TLRichText } from 'tldraw'\nimport { renderCommentHtml } from './comment-render'\n\n/** @public */\nexport interface CommentBodyProps {\n\trichText: TLRichText\n\t/** Maps a member id to its current display name, so \\@mentions show the live name. */\n\tresolveName?(id: string): string | undefined\n}\n\n/**\n * Renders a comment's rich-text body read-only through the limited comment extension set (no\n * headings), so formatting (bold, links, lists, highlight) is preserved rather than flattened, and\n * headings can never render. Use this as the `body` of a `CommentCard` on a canvas.\n * @public @react\n */\nexport function CommentBody({ richText, resolveName }: CommentBodyProps) {\n\tconst html = useMemo(() => renderCommentHtml(richText, resolveName), [richText, resolveName])\n\treturn <div className=\"tlui-cmt-text\" dangerouslySetInnerHTML={{ __html: html }} />\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBQ;AAnBR,mBAAwB;AAExB,4BAAkC;AAe3B,SAAS,YAAY,EAAE,UAAU,YAAY,GAAqB;AACxE,QAAM,WAAO,sBAAQ,UAAM,yCAAkB,UAAU,WAAW,GAAG,CAAC,UAAU,WAAW,CAAC;AAC5F,SAAO,4CAAC,SAAI,WAAU,iBAAgB,yBAAyB,EAAE,QAAQ,KAAK,GAAG;AAClF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var comment_drafts_exports = {};
20
+ __export(comment_drafts_exports, {
21
+ NEW_COMMENT_DRAFT: () => NEW_COMMENT_DRAFT,
22
+ clearCommentDraft: () => clearCommentDraft,
23
+ getCommentDraft: () => getCommentDraft,
24
+ replyDraftSlot: () => replyDraftSlot,
25
+ saveCommentDraft: () => saveCommentDraft
26
+ });
27
+ module.exports = __toCommonJS(comment_drafts_exports);
28
+ var import_utils = require("@tldraw/utils");
29
+ var import_comment_extensions = require("../ui/comment-extensions");
30
+ const DRAFT_KEY_PREFIX = "tldraw-comment-draft";
31
+ const NEW_COMMENT_DRAFT = "new";
32
+ function replyDraftSlot(threadId) {
33
+ return `reply:${threadId}`;
34
+ }
35
+ function getCommentDraft(slot) {
36
+ const raw = (0, import_utils.getFromLocalStorage)(`${DRAFT_KEY_PREFIX}:${slot}`);
37
+ if (!raw) return void 0;
38
+ try {
39
+ return JSON.parse(raw);
40
+ } catch {
41
+ return void 0;
42
+ }
43
+ }
44
+ function saveCommentDraft(slot, value) {
45
+ if ((0, import_comment_extensions.isCommentEmpty)(value)) {
46
+ clearCommentDraft(slot);
47
+ return;
48
+ }
49
+ (0, import_utils.setInLocalStorage)(`${DRAFT_KEY_PREFIX}:${slot}`, JSON.stringify(value));
50
+ }
51
+ function clearCommentDraft(slot) {
52
+ (0, import_utils.deleteFromLocalStorage)(`${DRAFT_KEY_PREFIX}:${slot}`);
53
+ }
54
+ //# sourceMappingURL=comment-drafts.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/canvas/comment-drafts.ts"],
4
+ "sourcesContent": ["import { deleteFromLocalStorage, getFromLocalStorage, setInLocalStorage } from '@tldraw/utils'\nimport type { TLRichText } from 'tldraw'\nimport { isCommentEmpty } from '../ui/comment-extensions'\n\nconst DRAFT_KEY_PREFIX = 'tldraw-comment-draft'\n\n/** The single slot for an unsent new-comment (placement composer) draft. The anchor is re-picked\n * by clicking when the composer reopens, so only the text is worth keeping \u2014 and without a\n * universal document id in the SDK, one slot is the honest scope. */\nexport const NEW_COMMENT_DRAFT = 'new'\n\n/** The draft slot for an unsent reply on a thread. Thread record ids are globally unique and\n * stable across reloads, so replies never need a document key. @public */\nexport function replyDraftSlot(threadId: string): string {\n\treturn `reply:${threadId}`\n}\n\n/** Read a saved unsent draft, or undefined when there is none (or it fails to parse). @public */\nexport function getCommentDraft(slot: string): TLRichText | undefined {\n\tconst raw = getFromLocalStorage(`${DRAFT_KEY_PREFIX}:${slot}`)\n\tif (!raw) return undefined\n\ttry {\n\t\treturn JSON.parse(raw) as TLRichText\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Save an unsent draft so click-away and reload don't lose it \u2014 the flip side of not warning\n * before discard. Saving empty content clears the slot instead, so deleting your text and\n * closing doesn't resurrect an empty draft later.\n * @public\n */\nexport function saveCommentDraft(slot: string, value: TLRichText) {\n\tif (isCommentEmpty(value)) {\n\t\tclearCommentDraft(slot)\n\t\treturn\n\t}\n\tsetInLocalStorage(`${DRAFT_KEY_PREFIX}:${slot}`, JSON.stringify(value))\n}\n\n/** Remove a saved draft (after posting, or when its content was emptied). @public */\nexport function clearCommentDraft(slot: string) {\n\tdeleteFromLocalStorage(`${DRAFT_KEY_PREFIX}:${slot}`)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+E;AAE/E,gCAA+B;AAE/B,MAAM,mBAAmB;AAKlB,MAAM,oBAAoB;AAI1B,SAAS,eAAe,UAA0B;AACxD,SAAO,SAAS,QAAQ;AACzB;AAGO,SAAS,gBAAgB,MAAsC;AACrE,QAAM,UAAM,kCAAoB,GAAG,gBAAgB,IAAI,IAAI,EAAE;AAC7D,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI;AACH,WAAO,KAAK,MAAM,GAAG;AAAA,EACtB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAQO,SAAS,iBAAiB,MAAc,OAAmB;AACjE,UAAI,0CAAe,KAAK,GAAG;AAC1B,sBAAkB,IAAI;AACtB;AAAA,EACD;AACA,sCAAkB,GAAG,gBAAgB,IAAI,IAAI,IAAI,KAAK,UAAU,KAAK,CAAC;AACvE;AAGO,SAAS,kBAAkB,MAAc;AAC/C,2CAAuB,GAAG,gBAAgB,IAAI,IAAI,EAAE;AACrD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var comment_mutations_exports = {};
20
+ __export(comment_mutations_exports, {
21
+ commitCommentMutation: () => commitCommentMutation,
22
+ deleteComment: () => deleteComment,
23
+ deleteThread: () => deleteThread,
24
+ editComment: () => editComment,
25
+ putCommentRecords: () => putCommentRecords,
26
+ putRecordsInCommit: () => putRecordsInCommit,
27
+ removeCommentRecords: () => removeCommentRecords,
28
+ removeRecordsInCommit: () => removeRecordsInCommit,
29
+ reopenThread: () => reopenThread,
30
+ resolveThread: () => resolveThread
31
+ });
32
+ module.exports = __toCommonJS(comment_mutations_exports);
33
+ var import_comment_store = require("./comment-store");
34
+ var import_options = require("./options");
35
+ var import_state = require("./state");
36
+ function historyModeFor(options, kind) {
37
+ switch (kind) {
38
+ case "delete":
39
+ return "ignore";
40
+ case "drag":
41
+ return options.dragHistory ?? options.history;
42
+ case "mutation":
43
+ return options.history;
44
+ }
45
+ }
46
+ function commitCommentMutation(editor, fn, kind = "mutation") {
47
+ const history = historyModeFor((0, import_options.getCommentingOptions)(editor), kind);
48
+ let result;
49
+ editor.run(
50
+ () => {
51
+ result = fn();
52
+ },
53
+ { history }
54
+ );
55
+ return result;
56
+ }
57
+ function putRecordsInCommit(editor, records) {
58
+ editor.store.put(records);
59
+ }
60
+ function removeRecordsInCommit(editor, ids) {
61
+ editor.store.remove(ids);
62
+ }
63
+ function putCommentRecords(editor, records) {
64
+ commitCommentMutation(editor, () => putRecordsInCommit(editor, records));
65
+ }
66
+ function removeCommentRecords(editor, ids) {
67
+ commitCommentMutation(editor, () => removeRecordsInCommit(editor, ids));
68
+ }
69
+ function readLatest(editor, record) {
70
+ const current = (0, import_comment_store.getCommentRecord)(editor, record.id);
71
+ return current?.typeName === record.typeName ? current : void 0;
72
+ }
73
+ function editComment(editor, comment, body) {
74
+ commitCommentMutation(editor, () => {
75
+ const current = readLatest(editor, comment);
76
+ if (!current) return;
77
+ putRecordsInCommit(editor, [{ ...current, body, editedAt: Date.now() }]);
78
+ });
79
+ }
80
+ function resolveThread(editor, thread, userId) {
81
+ commitCommentMutation(editor, () => {
82
+ const current = readLatest(editor, thread);
83
+ if (!current) return;
84
+ putRecordsInCommit(editor, [{ ...current, resolved: { at: Date.now(), by: userId } }]);
85
+ });
86
+ }
87
+ function reopenThread(editor, thread) {
88
+ commitCommentMutation(editor, () => {
89
+ const current = readLatest(editor, thread);
90
+ if (!current) return;
91
+ putRecordsInCommit(editor, [{ ...current, resolved: null }]);
92
+ });
93
+ }
94
+ function deleteComment(editor, comment) {
95
+ commitCommentMutation(
96
+ editor,
97
+ () => {
98
+ const current = readLatest(editor, comment);
99
+ if (!current || current.isDeleted) return;
100
+ const isLastInThread = (0, import_comment_store.getLiveComments)(editor).filter((c) => c.threadId === current.threadId).length <= 1;
101
+ if (isLastInThread && import_state.openThreadId.get(editor) === current.threadId) {
102
+ import_state.openThreadId.set(editor, null);
103
+ }
104
+ putRecordsInCommit(editor, [{ ...current, isDeleted: true }]);
105
+ },
106
+ "delete"
107
+ );
108
+ }
109
+ function deleteThread(editor, thread) {
110
+ commitCommentMutation(
111
+ editor,
112
+ () => {
113
+ const current = readLatest(editor, thread);
114
+ if (!current) return;
115
+ if (import_state.openThreadId.get(editor) === current.id) {
116
+ import_state.openThreadId.set(editor, null);
117
+ }
118
+ putRecordsInCommit(editor, [{ ...current, isDeleted: true }]);
119
+ },
120
+ "delete"
121
+ );
122
+ }
123
+ //# sourceMappingURL=comment-mutations.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/canvas/comment-mutations.ts"],
4
+ "sourcesContent": ["import {\n\tEditor,\n\tTLComment,\n\tTLCommentId,\n\tTLCommentReactionId,\n\tTLCommentThread,\n\tTLCommentThreadId,\n\tTLHistoryBatchOptions,\n\tTLRecord,\n\tTLRichText,\n} from 'tldraw'\nimport { getCommentRecord, getLiveComments, type TLCommentRecord } from './comment-store'\nimport { getCommentingOptions, type CommentingOptions } from './options'\nimport { openThreadId } from './state'\n\n/**\n * Every write to a comment record, and the undo/redo policy governing them.\n *\n * This file layers bottom-up: {@link commitCommentMutation} resolves the history mode,\n * {@link putCommentRecords} and {@link removeCommentRecords} are the typed writes that run under\n * it, and the verbs below are those writes plus the one rule each carries \u2014 a timestamp to stamp, a\n * shape to put the `resolved` field in, or the soft-delete protocol. The built-in thread view calls\n * exactly these verbs, so a UI of your own behaves the same as the one in the box.\n *\n * Every verb takes the record it acts on, but treats it as the identity of what to change rather\n * than as the value to write back \u2014 see {@link readLatest}.\n *\n * Posting carries no such rule, so it isn't a verb here: build the records with\n * `createCommentThread`/`createComment` and write them with {@link putCommentRecords}.\n */\n\n/**\n * Which history policy a comment write follows:\n *\n * - `mutation` \u2014 {@link CommentingOptions.history}: posts, replies, edits, resolves.\n * - `drag` \u2014 {@link CommentingOptions.dragHistory}, falling back to `history`: pin and region\n * re-anchors, which are spatial edits a host may reasonably want undoable alongside a shape move.\n * - `delete` \u2014 always `'ignore'`, whatever the options say. A soft-delete flag is write-once\n * server-side, so an undo clearing it would be vetoed and rebased rather than restore anything.\n *\n * @internal\n */\nexport type CommentMutationKind = 'delete' | 'drag' | 'mutation'\n\n/** The undo/redo mode a write of the given kind runs under. See {@link CommentMutationKind}. */\nfunction historyModeFor(\n\toptions: CommentingOptions,\n\tkind: CommentMutationKind\n): TLHistoryBatchOptions['history'] {\n\tswitch (kind) {\n\t\tcase 'delete':\n\t\t\treturn 'ignore'\n\t\tcase 'drag':\n\t\t\treturn options.dragHistory ?? options.history\n\t\tcase 'mutation':\n\t\t\treturn options.history\n\t}\n}\n\n/**\n * Commit a comment mutation with the configured undo/redo behavior, so the\n * {@link CommentingOptions.history} option governs whether it lands on the undo stack. Defaults to\n * `'ignore'`. See {@link CommentMutationKind} for what each kind resolves to.\n * @internal\n */\nexport function commitCommentMutation<T>(\n\teditor: Editor,\n\tfn: () => T,\n\tkind: CommentMutationKind = 'mutation'\n): T {\n\tconst history = historyModeFor(getCommentingOptions(editor), kind)\n\tlet result: T\n\teditor.run(\n\t\t() => {\n\t\t\tresult = fn()\n\t\t},\n\t\t{ history }\n\t)\n\treturn result!\n}\n\n/**\n * Write records without opening a commit, for call sites that already sit inside one.\n *\n * `editor.run`'s history option isn't additive \u2014 a nested run overwrites the enclosing mode for its\n * own scope \u2014 so a {@link putCommentRecords} call inside a commit would discard the mode its caller\n * chose. A pin drag committed as `drag` under `dragHistory: 'record'` would land back on\n * `history: 'ignore'` and quietly stop being undoable. Inside a commit, write with this.\n *\n * @internal\n */\nexport function putRecordsInCommit(editor: Editor, records: TLCommentRecord[]): void {\n\teditor.store.put(records as unknown as TLRecord[])\n}\n\n/** {@link putRecordsInCommit}'s counterpart for removals. @internal */\nexport function removeRecordsInCommit(\n\teditor: Editor,\n\tids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]\n): void {\n\teditor.store.remove(ids as unknown as TLRecord['id'][])\n}\n\n/**\n * Write comment records to the store, under the configured\n * {@link CommentingOptions.history} behavior \u2014 so a record you write lands on the undo stack (or\n * doesn't) exactly like one the built-in UI writes. Defaults to `'ignore'`.\n *\n * Use it to seed or import threads, and to save an edit. To delete, prefer\n * {@link deleteComment} and {@link deleteThread} over {@link removeCommentRecords}: comments are\n * soft-deleted, and a synced server rejects the hard delete.\n *\n * @public\n */\nexport function putCommentRecords(editor: Editor, records: TLCommentRecord[]): void {\n\tcommitCommentMutation(editor, () => putRecordsInCommit(editor, records))\n}\n\n/**\n * Remove comment records from the store by id, under the configured\n * {@link CommentingOptions.history} behavior.\n *\n * This is a hard delete, which is rarely what you want for a comment or a thread: the built-in UI\n * soft-deletes them ({@link deleteComment}, {@link deleteThread}) so the server can prune the\n * records \u2014 including reactions, which belong to whoever left them rather than to the deleter. A\n * server that enforces per-record permissions will veto a hard delete outright. Reach for this on\n * a local, unsynced comment store, or to drop a reaction (which is a hard delete \u2014 see\n * {@link toggleCommentReaction}).\n *\n * @public\n */\nexport function removeCommentRecords(\n\teditor: Editor,\n\tids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]\n): void {\n\tcommitCommentMutation(editor, () => removeRecordsInCommit(editor, ids))\n}\n\n/**\n * The record as the store currently holds it, or `undefined` if it isn't there any more.\n *\n * A verb is handed a record, but that record is a snapshot of whenever its caller got hold of one,\n * and a comment record moves underneath it. A thread's `anchor` and `pageId` are rewritten without\n * anyone touching the thread: deleting a pinned shape converts the anchor to a point, reparenting\n * one rehomes the thread to another page, a pin drag re-anchors it. Writing the caller's snapshot\n * back would put those fields as they were and sync the revert out to everyone.\n *\n * `put` is also an upsert, so a record a remote delete has already removed would come back \u2014 with\n * `isDeleted: false` on an edit or a resolve. That's the multiplayer surprise the schema warns\n * about (see `TLComment`), reached by a route the history option doesn't cover.\n *\n * So a verb reads what it's changing rather than trusting what it was given, and a record that's\n * gone is a no-op: whatever the change was, there's nothing left for it to apply to.\n */\nfunction readLatest<T extends TLComment | TLCommentThread>(\n\teditor: Editor,\n\trecord: T\n): T | undefined {\n\tconst current = getCommentRecord(editor, record.id)\n\t// Record ids carry their type, so a matching `typeName` means a record of exactly T.\n\treturn current?.typeName === record.typeName ? (current as T) : undefined\n}\n\n/**\n * Replace a comment's body and stamp it as edited, which is what renders the \"(edited)\" marker on\n * its byline.\n *\n * Editing is the author's to do. The built-in UI only offers it on your own comments, and a server\n * that enforces per-record permissions rejects anyone else's edit.\n *\n * The `comment` you pass says which comment to edit; the body lands on the version the store\n * currently holds, so a copy you've held on to can't revert a change made since it, and can't\n * re-create a comment that's already been removed \u2014 editing one of those does nothing.\n *\n * @example\n * ```ts\n * editComment(editor, comment, toRichText('Actually, make it dashed'))\n * ```\n *\n * @public\n */\nexport function editComment(editor: Editor, comment: TLComment, body: TLRichText): void {\n\tcommitCommentMutation(editor, () => {\n\t\tconst current = readLatest(editor, comment)\n\t\tif (!current) return\n\t\tputRecordsInCommit(editor, [{ ...current, body, editedAt: Date.now() }])\n\t})\n}\n\n/**\n * Mark a thread resolved, stamping who resolved it and when. Resolved threads keep their pin (a\n * checked one) and are hidden from the sidebar until its \"show resolved\" filter is on.\n *\n * Only the resolution is written: the rest of the thread is read fresh, so resolving with a stale\n * copy in hand won't drag a pin back to where it used to be. A no-op on a thread that's gone.\n *\n * @public\n */\nexport function resolveThread(editor: Editor, thread: TLCommentThread, userId: string): void {\n\tcommitCommentMutation(editor, () => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tputRecordsInCommit(editor, [{ ...current, resolved: { at: Date.now(), by: userId } }])\n\t})\n}\n\n/**\n * Reopen a resolved thread, clearing the resolution. A no-op on a thread that isn't resolved, and\n * on one that's gone. Like {@link resolveThread}, it touches only the resolution.\n *\n * @public\n */\nexport function reopenThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(editor, () => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tputRecordsInCommit(editor, [{ ...current, resolved: null }])\n\t})\n}\n\n/**\n * Delete a comment.\n *\n * This is a soft delete: it sets the record's `isDeleted` flag rather than removing it, and the\n * server prunes the comment and its reactions once the flag is persisted. That way no client ever\n * removes records it doesn't own \u2014 a reaction belongs to whoever left it \u2014 and a server enforcing\n * per-record permissions has a write it can check rather than a deletion it can only refuse.\n * Deleting is the author's to do; the built-in UI only offers it on your own comments.\n *\n * The write is never undoable, whatever {@link CommentingOptions.history} says: the flag is\n * write-once server-side, so an undo clearing it would be vetoed and rebased rather than bring the\n * comment back.\n *\n * Deleting a thread's last comment leaves the thread with no surface \u2014 an empty thread renders\n * nothing \u2014 and closes it if it's open. The thread record is left for the server to prune, since\n * the deleter may not be its creator.\n *\n * A comment that's already deleted, or already pruned, is a no-op.\n *\n * @public\n */\nexport function deleteComment(editor: Editor, comment: TLComment): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t() => {\n\t\t\tconst current = readLatest(editor, comment)\n\t\t\t// Deleting twice \u2014 a double activation, a handler firing on a copy taken before the first\n\t\t\t// delete \u2014 is nothing to do rather than something to redo. The check below counts the\n\t\t\t// comment being deleted among the live ones, so it only reads as \"the last one\" while\n\t\t\t// this delete is the one taking it away.\n\t\t\tif (!current || current.isDeleted) return\n\t\t\tconst isLastInThread =\n\t\t\t\tgetLiveComments(editor).filter((c) => c.threadId === current.threadId).length <= 1\n\t\t\tif (isLastInThread && openThreadId.get(editor) === current.threadId) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tputRecordsInCommit(editor, [{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n\n/**\n * Delete a thread and, with it, the whole conversation.\n *\n * A soft delete on the same model as {@link deleteComment}: the flag goes on the thread record and\n * the server prunes the thread, its comments, and their reactions once it's persisted. Deleting a\n * thread is its creator's to do \u2014 a server enforcing per-record permissions vetoes anyone else \u2014\n * and the write is never undoable.\n *\n * Closes the thread if it's the open one. A thread that's already pruned is a no-op.\n *\n * @public\n */\nexport function deleteThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t() => {\n\t\t\tconst current = readLatest(editor, thread)\n\t\t\tif (!current) return\n\t\t\tif (openThreadId.get(editor) === current.id) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tputRecordsInCommit(editor, [{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var comment_reactions_exports = {};
20
+ __export(comment_reactions_exports, {
21
+ CommentReactionPicker: () => CommentReactionPicker,
22
+ CommentReactions: () => CommentReactions,
23
+ summarizeReactions: () => summarizeReactions,
24
+ toggleCommentReaction: () => toggleCommentReaction,
25
+ useCommentReactions: () => useCommentReactions
26
+ });
27
+ module.exports = __toCommonJS(comment_reactions_exports);
28
+ var import_jsx_runtime = require("react/jsx-runtime");
29
+ var import_react = require("react");
30
+ var import_tldraw = require("tldraw");
31
+ var import_reaction_picker = require("../ui/reaction-picker");
32
+ var import_reactions = require("../ui/reactions");
33
+ var import_comment_mutations = require("./comment-mutations");
34
+ var import_comment_render = require("./comment-render");
35
+ var import_comment_store = require("./comment-store");
36
+ var import_options = require("./options");
37
+ function useCommentReactions(editor, commentId) {
38
+ return (0, import_tldraw.useValue)(
39
+ "comment reactions",
40
+ () => (0, import_comment_store.getCommentReactions)(editor).filter((reaction) => reaction.commentId === commentId).sort((a, b) => a.createdAt - b.createdAt),
41
+ [editor, commentId]
42
+ );
43
+ }
44
+ function summarizeReactions(reactions, currentUserId, resolveName) {
45
+ const groups = /* @__PURE__ */ new Map();
46
+ for (const reaction of reactions) {
47
+ const mine = currentUserId != null && reaction.userId === currentUserId;
48
+ const reactor = { name: resolveName?.(reaction.userId) ?? import_comment_render.UNKNOWN_AUTHOR, you: mine };
49
+ const group = groups.get(reaction.emoji);
50
+ if (group) {
51
+ group.count++;
52
+ group.active ||= mine;
53
+ group.firstAt = Math.min(group.firstAt, reaction.createdAt);
54
+ group.reactors.push(reactor);
55
+ } else {
56
+ groups.set(reaction.emoji, {
57
+ count: 1,
58
+ active: mine,
59
+ firstAt: reaction.createdAt,
60
+ reactors: [reactor]
61
+ });
62
+ }
63
+ }
64
+ return [...groups].sort(([, a], [, b]) => a.firstAt - b.firstAt).map(([emoji, group]) => ({
65
+ emoji,
66
+ count: group.count,
67
+ active: group.active,
68
+ reactors: group.reactors
69
+ }));
70
+ }
71
+ function toggleCommentReaction(editor, comment, userId, emoji, now = Date.now()) {
72
+ const { allowMultipleReactions, isAllowedReaction } = (0, import_options.getCommentingOptions)(editor);
73
+ const targetId = (0, import_tldraw.createCommentReactionId)(comment.id, userId, emoji);
74
+ const mine = (0, import_comment_store.getCommentReactions)(editor).filter(
75
+ (reaction) => reaction.commentId === comment.id && reaction.userId === userId
76
+ );
77
+ const removing = mine.some((reaction) => reaction.id === targetId);
78
+ if (!removing && !isAllowedReaction(emoji)) return;
79
+ (0, import_comment_mutations.commitCommentMutation)(editor, () => {
80
+ if (removing) {
81
+ (0, import_comment_mutations.removeRecordsInCommit)(editor, [targetId]);
82
+ return;
83
+ }
84
+ if (!allowMultipleReactions && mine.length > 0) {
85
+ (0, import_comment_mutations.removeRecordsInCommit)(
86
+ editor,
87
+ mine.map((reaction) => reaction.id)
88
+ );
89
+ }
90
+ (0, import_comment_mutations.putRecordsInCommit)(editor, [
91
+ (0, import_tldraw.createCommentReaction)({
92
+ commentId: comment.id,
93
+ threadId: comment.threadId,
94
+ pageId: comment.pageId,
95
+ userId,
96
+ emoji,
97
+ now
98
+ })
99
+ ]);
100
+ });
101
+ }
102
+ function useReactionRenderer() {
103
+ const { components } = (0, import_options.useCommentingOptions)();
104
+ const ReactionContent = components.ReactionContent;
105
+ return (0, import_react.useMemo)(
106
+ () => ReactionContent ? (token) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactionContent, { token }) : void 0,
107
+ [ReactionContent]
108
+ );
109
+ }
110
+ function CommentReactions({ comment, currentUserId, resolveName }) {
111
+ const editor = (0, import_tldraw.useEditor)();
112
+ const renderReaction = useReactionRenderer();
113
+ const { components } = (0, import_options.useCommentingOptions)();
114
+ const reactions = useCommentReactions(editor, comment.id);
115
+ const summaries = (0, import_react.useMemo)(
116
+ () => summarizeReactions(reactions, currentUserId, resolveName),
117
+ [reactions, currentUserId, resolveName]
118
+ );
119
+ const anyMenuOpen = (0, import_tldraw.useValue)("any menu open", () => editor.menus.getOpenMenus().length > 0, [
120
+ editor
121
+ ]);
122
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
123
+ import_reactions.Reactions,
124
+ {
125
+ reactions: summaries,
126
+ canReact: currentUserId != null,
127
+ enableHoverList: !anyMenuOpen,
128
+ renderReaction,
129
+ ReactionTooltip: components.ReactionTooltip,
130
+ onToggle: (value) => {
131
+ if (currentUserId == null) return;
132
+ toggleCommentReaction(editor, comment, currentUserId, value);
133
+ }
134
+ }
135
+ );
136
+ }
137
+ function CommentReactionPicker({
138
+ comment,
139
+ currentUserId,
140
+ emoji
141
+ }) {
142
+ const editor = (0, import_tldraw.useEditor)();
143
+ const { components } = (0, import_options.useCommentingOptions)();
144
+ const renderReaction = useReactionRenderer();
145
+ const reactions = useCommentReactions(editor, comment.id);
146
+ const selected = (0, import_react.useMemo)(
147
+ () => reactions.filter((reaction) => currentUserId != null && reaction.userId === currentUserId).map((reaction) => reaction.emoji),
148
+ [reactions, currentUserId]
149
+ );
150
+ if (currentUserId == null) return null;
151
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
152
+ import_reaction_picker.ReactionPicker,
153
+ {
154
+ emoji,
155
+ selected,
156
+ renderReaction,
157
+ palette: components.ReactionPalette,
158
+ menuId: `comment-reactions-${comment.id}`,
159
+ onSelect: (value) => toggleCommentReaction(editor, comment, currentUserId, value)
160
+ }
161
+ );
162
+ }
163
+ //# sourceMappingURL=comment-reactions.js.map