@tldraw/commenting 5.7.0-canary.fd4a9d669e63 → 5.7.0-internal.5fe8922939ec

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 (111) hide show
  1. package/commenting.css +280 -275
  2. package/dist-cjs/canvas/canvas-events.js +25 -1
  3. package/dist-cjs/canvas/canvas-events.js.map +2 -2
  4. package/dist-cjs/canvas/comment-mutations.js +5 -0
  5. package/dist-cjs/canvas/comment-mutations.js.map +2 -2
  6. package/dist-cjs/canvas/comment-tool.js +29 -28
  7. package/dist-cjs/canvas/comment-tool.js.map +2 -2
  8. package/dist-cjs/canvas/comments-filter-menu.js +55 -38
  9. package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
  10. package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
  11. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  12. package/dist-cjs/canvas/comments-overlay.js +1 -0
  13. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  14. package/dist-cjs/canvas/comments-sidebar.js +15 -3
  15. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  16. package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
  17. package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
  18. package/dist-cjs/canvas/options.js +12 -0
  19. package/dist-cjs/canvas/options.js.map +2 -2
  20. package/dist-cjs/canvas/pending-composer.js +139 -9
  21. package/dist-cjs/canvas/pending-composer.js.map +2 -2
  22. package/dist-cjs/canvas/region-box.js +150 -35
  23. package/dist-cjs/canvas/region-box.js.map +3 -3
  24. package/dist-cjs/canvas/thread-pin.js +20 -4
  25. package/dist-cjs/canvas/thread-pin.js.map +2 -2
  26. package/dist-cjs/canvas/thread-view.js +134 -58
  27. package/dist-cjs/canvas/thread-view.js.map +2 -2
  28. package/dist-cjs/index.d.ts +46 -12
  29. package/dist-cjs/index.js +1 -1
  30. package/dist-cjs/ui/byline.js +2 -2
  31. package/dist-cjs/ui/byline.js.map +2 -2
  32. package/dist-cjs/ui/comment-card.js +3 -1
  33. package/dist-cjs/ui/comment-card.js.map +2 -2
  34. package/dist-cjs/ui/comment-extensions.js +4 -1
  35. package/dist-cjs/ui/comment-extensions.js.map +2 -2
  36. package/dist-cjs/ui/comments-list.js +6 -7
  37. package/dist-cjs/ui/comments-list.js.map +2 -2
  38. package/dist-cjs/ui/icons.js +4 -4
  39. package/dist-cjs/ui/icons.js.map +2 -2
  40. package/dist-cjs/ui/reaction-picker.js +2 -2
  41. package/dist-cjs/ui/reaction-picker.js.map +1 -1
  42. package/dist-cjs/ui/send-button.js.map +1 -1
  43. package/dist-esm/canvas/canvas-events.mjs +25 -1
  44. package/dist-esm/canvas/canvas-events.mjs.map +2 -2
  45. package/dist-esm/canvas/comment-mutations.mjs +5 -0
  46. package/dist-esm/canvas/comment-mutations.mjs.map +2 -2
  47. package/dist-esm/canvas/comment-tool.mjs +30 -29
  48. package/dist-esm/canvas/comment-tool.mjs.map +2 -2
  49. package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
  50. package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
  51. package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
  52. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  53. package/dist-esm/canvas/comments-overlay.mjs +1 -0
  54. package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
  55. package/dist-esm/canvas/comments-sidebar.mjs +16 -4
  56. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  57. package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
  58. package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
  59. package/dist-esm/canvas/options.mjs +12 -0
  60. package/dist-esm/canvas/options.mjs.map +2 -2
  61. package/dist-esm/canvas/pending-composer.mjs +150 -11
  62. package/dist-esm/canvas/pending-composer.mjs.map +2 -2
  63. package/dist-esm/canvas/region-box.mjs +161 -38
  64. package/dist-esm/canvas/region-box.mjs.map +3 -3
  65. package/dist-esm/canvas/thread-pin.mjs +22 -6
  66. package/dist-esm/canvas/thread-pin.mjs.map +2 -2
  67. package/dist-esm/canvas/thread-view.mjs +145 -60
  68. package/dist-esm/canvas/thread-view.mjs.map +2 -2
  69. package/dist-esm/index.d.mts +46 -12
  70. package/dist-esm/index.mjs +1 -1
  71. package/dist-esm/ui/byline.mjs +2 -2
  72. package/dist-esm/ui/byline.mjs.map +2 -2
  73. package/dist-esm/ui/comment-card.mjs +3 -1
  74. package/dist-esm/ui/comment-card.mjs.map +2 -2
  75. package/dist-esm/ui/comment-extensions.mjs +11 -2
  76. package/dist-esm/ui/comment-extensions.mjs.map +2 -2
  77. package/dist-esm/ui/comments-list.mjs +6 -7
  78. package/dist-esm/ui/comments-list.mjs.map +2 -2
  79. package/dist-esm/ui/icons.mjs +4 -4
  80. package/dist-esm/ui/icons.mjs.map +2 -2
  81. package/dist-esm/ui/reaction-picker.mjs +2 -2
  82. package/dist-esm/ui/reaction-picker.mjs.map +1 -1
  83. package/dist-esm/ui/send-button.mjs.map +1 -1
  84. package/package.json +5 -5
  85. package/src/canvas/canvas-events.ts +39 -2
  86. package/src/canvas/canvas.css +76 -38
  87. package/src/canvas/comment-mutations.test.ts +51 -0
  88. package/src/canvas/comment-mutations.ts +14 -0
  89. package/src/canvas/comment-render.test.ts +8 -1
  90. package/src/canvas/comment-tool.test.ts +34 -44
  91. package/src/canvas/comment-tool.tsx +51 -55
  92. package/src/canvas/comments-filter-menu.tsx +19 -6
  93. package/src/canvas/comments-overflow-menu.tsx +12 -18
  94. package/src/canvas/comments-overlay.tsx +5 -2
  95. package/src/canvas/comments-sidebar.tsx +20 -5
  96. package/src/canvas/comments-visibility-toggle.tsx +1 -1
  97. package/src/canvas/options.test.ts +23 -1
  98. package/src/canvas/options.ts +41 -3
  99. package/src/canvas/pending-composer.tsx +190 -19
  100. package/src/canvas/region-box.tsx +192 -42
  101. package/src/canvas/thread-pin.tsx +28 -6
  102. package/src/canvas/thread-view.test.ts +39 -0
  103. package/src/canvas/thread-view.tsx +192 -72
  104. package/src/ui/byline.tsx +5 -2
  105. package/src/ui/comment-card.tsx +7 -1
  106. package/src/ui/comment-extensions.ts +18 -5
  107. package/src/ui/comments-list.tsx +23 -17
  108. package/src/ui/comments.css +175 -201
  109. package/src/ui/icons.tsx +5 -5
  110. package/src/ui/reaction-picker.tsx +2 -2
  111. package/src/ui/send-button.tsx +2 -2
@@ -1,6 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { Avatar, isMentionPickerOpen } from "@tldraw/mentions";
3
- import { useEffect, useRef, useState } from "react";
3
+ import {
4
+ useEffect,
5
+ useRef,
6
+ useState
7
+ } from "react";
4
8
  import {
5
9
  createComment,
6
10
  createCommentThread,
@@ -13,17 +17,26 @@ import {
13
17
  import { CommentComposer } from "../ui/comment-composer.mjs";
14
18
  import { EMPTY_COMMENT, isCommentEmpty } from "../ui/comment-extensions.mjs";
15
19
  import { CommentPin } from "../ui/comment-pin.mjs";
20
+ import { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from "./canvas-events.mjs";
16
21
  import {
17
22
  clearCommentDraft,
18
23
  getCommentDraft,
19
24
  NEW_COMMENT_DRAFT,
20
25
  saveCommentDraft
21
26
  } from "./comment-drafts.mjs";
22
- import { commitCommentMutation } from "./comment-mutations.mjs";
27
+ import { commitCommentPost } from "./comment-mutations.mjs";
23
28
  import { UNKNOWN_COMMENT_AUTHOR } from "./comment-render.mjs";
29
+ import { pendingCommentAt } from "./comment-tool.mjs";
24
30
  import { useIsMobileCommenting, useMobilePlacement } from "./mobile-placement.mjs";
25
31
  import { useCanComment, useCommentingOptions } from "./options.mjs";
26
32
  import { pendingComment } from "./state.mjs";
33
+ import {
34
+ commentTargetShapeAt,
35
+ regionAnchorPinCorner,
36
+ regionPinPoint,
37
+ regionWithPinAt
38
+ } from "./thread-state.mjs";
39
+ import { avatarRenderer } from "./thread-view.mjs";
27
40
  const messages = defineMessages({
28
41
  commentsSend: { id: "comments.send", defaultMessage: "Send" },
29
42
  commentsAddPlaceholder: { id: "comments.add-placeholder", defaultMessage: "Add a comment\u2026" }
@@ -38,10 +51,20 @@ function PendingComposer({
38
51
  getMentionSuggestions,
39
52
  renderMentionSuggestion
40
53
  }) {
41
- const ComposerFallback = useCommentingOptions().components.ComposerFallback;
54
+ const { components } = useCommentingOptions();
55
+ const ComposerFallback = components.ComposerFallback;
42
56
  const canComment = useCanComment(currentUserId);
43
57
  const me = currentUserId ? resolveAuthor(currentUserId) : void 0;
44
- const draftAvatar = /* @__PURE__ */ jsx(CommentPin, { children: /* @__PURE__ */ jsx(Avatar, { author: me ?? UNKNOWN_COMMENT_AUTHOR }) });
58
+ const isMobile = useIsMobileCommenting();
59
+ const drag = useDraftDrag(editor, pending);
60
+ const draftAvatar = /* @__PURE__ */ jsx(
61
+ "div",
62
+ {
63
+ className: "tlui-cmt-canvas-composer__handle",
64
+ ...(isMobile ? {} : drag.handlers),
65
+ children: /* @__PURE__ */ jsx(CommentPin, { children: avatarRenderer(components, currentUserId)?.(me ?? UNKNOWN_COMMENT_AUTHOR) ?? /* @__PURE__ */ jsx(Avatar, { author: me ?? UNKNOWN_COMMENT_AUTHOR }) })
66
+ }
67
+ );
45
68
  const [text, setText] = useState(
46
69
  () => getCommentDraft(NEW_COMMENT_DRAFT) ?? EMPTY_COMMENT
47
70
  );
@@ -52,15 +75,33 @@ function PendingComposer({
52
75
  editor,
53
76
  pending.point
54
77
  ]);
55
- const isMobile = useIsMobileCommenting();
56
78
  const placed = useMobilePlacement(ref, point, isMobile);
79
+ const textRef = useRef(text);
80
+ textRef.current = text;
81
+ useEffect(() => {
82
+ const el = ref.current;
83
+ if (!el) return;
84
+ const onKeyDown = (e) => {
85
+ if (e.key !== "Escape" || isMentionPickerOpen()) return;
86
+ e.stopPropagation();
87
+ if (!isCommentEmpty(textRef.current)) {
88
+ setText(EMPTY_COMMENT);
89
+ clearCommentDraft(NEW_COMMENT_DRAFT);
90
+ return;
91
+ }
92
+ pendingComment.set(editor, null);
93
+ editor.getContainer().focus();
94
+ };
95
+ el.addEventListener("keydown", onKeyDown);
96
+ return () => el.removeEventListener("keydown", onKeyDown);
97
+ }, [editor]);
57
98
  useEffect(() => {
58
99
  const onPointerDown = (e) => {
59
100
  const el = ref.current;
60
101
  const target = e.target;
61
102
  if (!el || !target) return;
62
103
  if (el.contains(target) || target.closest(".tlui-cmt-mention-popup")) return;
63
- if (editor.getContainer().querySelector(".tl-canvas")?.contains(target)) return;
104
+ if (isCanvasPanGesture(editor, e) || e.isSpecialRedispatchedEvent) return;
64
105
  pendingComment.set(editor, null);
65
106
  };
66
107
  document.addEventListener("pointerdown", onPointerDown, true);
@@ -68,7 +109,7 @@ function PendingComposer({
68
109
  }, [editor]);
69
110
  const submit = () => {
70
111
  if (isCommentEmpty(text) || !currentUserId) return;
71
- const comment = commitCommentMutation(editor, ({ put }) => {
112
+ const comment = commitCommentPost(editor, ({ put }) => {
72
113
  const pageId = editor.getCurrentPageId();
73
114
  const thread = createCommentThread({
74
115
  pageId,
@@ -84,10 +125,10 @@ function PendingComposer({
84
125
  put([thread, comment2]);
85
126
  return comment2;
86
127
  });
128
+ if (!comment) return;
87
129
  setText(EMPTY_COMMENT);
88
130
  clearCommentDraft(NEW_COMMENT_DRAFT);
89
131
  pendingComment.set(editor, null);
90
- if (editor.isIn("comment.idle")) editor.setCurrentTool("select");
91
132
  onPostComment?.(comment);
92
133
  };
93
134
  return /* @__PURE__ */ jsx(EditorPortal, { children: /* @__PURE__ */ jsx(
@@ -97,14 +138,12 @@ function PendingComposer({
97
138
  className: [
98
139
  "tlui-cmt-canvas-composer",
99
140
  pending.anchor.type === "region" && "tlui-cmt-canvas-composer--region",
141
+ drag.dragging && "tlui-cmt-canvas-composer--dragging",
100
142
  !canComment && "tlui-cmt-canvas-composer--fallback"
101
143
  ].filter(Boolean).join(" "),
102
144
  style: { left: placed.left, top: placed.top },
103
145
  onPointerDown: stop,
104
146
  onContextMenu: stop,
105
- onKeyDown: (e) => {
106
- if (e.key === "Escape" && !isMentionPickerOpen()) pendingComment.set(editor, null);
107
- },
108
147
  children: canComment ? /* @__PURE__ */ jsx(
109
148
  CommentComposer,
110
149
  {
@@ -127,6 +166,106 @@ function PendingComposer({
127
166
  }
128
167
  ) });
129
168
  }
169
+ function useDraftDrag(editor, pending) {
170
+ const [dragging, setDragging] = useState(false);
171
+ const dragRef = useRef(null);
172
+ useEffect(
173
+ () => () => {
174
+ if (!dragRef.current) return;
175
+ dragRef.current.endDrag?.();
176
+ editor.setHintingShapes([]);
177
+ },
178
+ [editor]
179
+ );
180
+ const pagePointFor = (clientX, clientY) => {
181
+ const drag = dragRef.current;
182
+ const cursor = editor.screenToPage({ x: clientX, y: clientY });
183
+ return { x: cursor.x + drag.offsetX, y: cursor.y + drag.offsetY };
184
+ };
185
+ const moveRegion = (anchor, point) => {
186
+ const corner = regionAnchorPinCorner(anchor);
187
+ const moved = regionWithPinAt(anchor, corner, point);
188
+ pendingComment.set(editor, { anchor: moved, point: regionPinPoint(moved, corner) });
189
+ };
190
+ const previewAt = (point) => {
191
+ const current = pendingComment.get(editor);
192
+ if (!current) return;
193
+ if (current.anchor.type === "region") return moveRegion(current.anchor, point);
194
+ pendingComment.set(editor, { ...current, point: { x: point.x, y: point.y } });
195
+ const hit = commentTargetShapeAt(editor, point);
196
+ editor.setHintingShapes(hit ? [hit.id] : []);
197
+ };
198
+ const settleAt = (point, altKey) => {
199
+ const current = pendingComment.get(editor);
200
+ if (!current) return;
201
+ if (current.anchor.type === "region") return moveRegion(current.anchor, point);
202
+ pendingComment.set(editor, pendingCommentAt(editor, point, altKey));
203
+ };
204
+ const takeDrag = (e) => {
205
+ const drag = dragRef.current;
206
+ dragRef.current = null;
207
+ drag?.endDrag?.();
208
+ editor.setHintingShapes([]);
209
+ setDragging(false);
210
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) {
211
+ e.currentTarget.releasePointerCapture(e.pointerId);
212
+ }
213
+ return drag;
214
+ };
215
+ const handlers = {
216
+ onPointerDown: (e) => {
217
+ if (isCanvasPanGesture(editor, e)) {
218
+ forwardPointerEventToCanvas(editor.getContainer(), e);
219
+ return;
220
+ }
221
+ const grab = editor.screenToPage({ x: e.clientX, y: e.clientY });
222
+ dragRef.current = {
223
+ startX: e.clientX,
224
+ startY: e.clientY,
225
+ clientX: e.clientX,
226
+ clientY: e.clientY,
227
+ moved: false,
228
+ offsetX: pending.point.x - grab.x,
229
+ offsetY: pending.point.y - grab.y
230
+ };
231
+ e.currentTarget.setPointerCapture(e.pointerId);
232
+ },
233
+ // Keep focus in the comment field: grabbing the pin shouldn't blur what's being typed.
234
+ onMouseDown: (e) => e.preventDefault(),
235
+ onPointerMove: (e) => {
236
+ const drag = dragRef.current;
237
+ if (!drag) return;
238
+ if (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return;
239
+ drag.clientX = e.clientX;
240
+ drag.clientY = e.clientY;
241
+ if (!drag.moved) {
242
+ drag.moved = true;
243
+ drag.endDrag = startCommentDrag(editor, {
244
+ cursor: "move",
245
+ onCameraMove: () => {
246
+ const d = dragRef.current;
247
+ if (d) previewAt(pagePointFor(d.clientX, d.clientY));
248
+ }
249
+ });
250
+ setDragging(true);
251
+ }
252
+ previewAt(pagePointFor(e.clientX, e.clientY));
253
+ },
254
+ onPointerUp: (e) => {
255
+ const moved = dragRef.current?.moved;
256
+ const point = moved ? pagePointFor(e.clientX, e.clientY) : null;
257
+ takeDrag(e);
258
+ if (point) settleAt(point, e.altKey);
259
+ },
260
+ // A cancelled pointer leaves the draft where the drag last put it, with its anchor resolved.
261
+ onPointerCancel: (e) => {
262
+ const drag = takeDrag(e);
263
+ const current = pendingComment.get(editor);
264
+ if (drag?.moved && current) settleAt(current.point, editor.inputs.getAltKey());
265
+ }
266
+ };
267
+ return { dragging, handlers };
268
+ }
130
269
  export {
131
270
  PendingComposer
132
271
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/pending-composer.tsx"],
4
- "sourcesContent": ["import { Avatar, isMentionPickerOpen } from '@tldraw/mentions'\nimport { useEffect, useRef, useState } from 'react'\nimport {\n\tcreateComment,\n\tcreateCommentThread,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLRichText,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentPin } from '../ui/comment-pin'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\tNEW_COMMENT_DRAFT,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport { commitCommentMutation } from './comment-mutations'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { PendingComment } from './comment-tool'\nimport { type CommentingContext } from './context'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport { useCanComment, useCommentingOptions } from './options'\nimport { pendingComment } from './state'\n\nconst messages = defineMessages({\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsAddPlaceholder: { id: 'comments.add-placeholder', defaultMessage: 'Add a comment\u2026' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * The composer for a thread that doesn't exist yet: the comment tool has placed a point (or\n * region) and is waiting on a first comment. Submitting creates the thread and its comment\n * together; clicking away keeps the draft for the next placement.\n */\nexport function PendingComposer({\n\teditor,\n\tpending,\n\tcurrentUserId,\n\tresolveAuthor,\n\tonPostComment,\n\tgetMentionSuggestions,\n\trenderMentionSuggestion,\n}: CommentingContext & { editor: Editor; pending: PendingComment }) {\n\tconst ComposerFallback = useCommentingOptions().components.ComposerFallback\n\tconst canComment = useCanComment(currentUserId)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// The leading pin previews the pin this draft becomes: a white pin holding the author's avatar.\n\tconst draftAvatar = (\n\t\t<CommentPin>\n\t\t\t<Avatar author={me ?? UNKNOWN_COMMENT_AUTHOR} />\n\t\t</CommentPin>\n\t)\n\t// Click-away keeps the draft (saved on every change) and the next placement composer\n\t// restores it \u2014 the flip side of dismissing without a discard warning.\n\tconst [text, setText] = useState<TLRichText>(\n\t\t() => getCommentDraft(NEW_COMMENT_DRAFT) ?? EMPTY_COMMENT\n\t)\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst msg = useTranslation()\n\t// Over this floating panel, a scroll reaches the canvas (except where it scrolls itself).\n\tusePassThroughWheelEvents(ref)\n\n\tconst point = useValue('composer point', () => editor.pageToViewport(pending.point), [\n\t\teditor,\n\t\tpending.point,\n\t])\n\t// On mobile the composer floats free of the pin so it can clear the software keyboard; desktop\n\t// keeps it pinned to the point.\n\tconst isMobile = useIsMobileCommenting()\n\tconst placed = useMobilePlacement(ref, point, isMobile)\n\n\t// Dismiss on a click anywhere outside the composer (capture-phase, ahead of stopPropagation).\n\tuseEffect(() => {\n\t\tconst onPointerDown = (e: PointerEvent) => {\n\t\t\tconst el = ref.current\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!el || !target) return\n\t\t\t// A click in the composer, or in the mention picker it spawns (portaled elsewhere), is\n\t\t\t// not \"outside\" \u2014 keep the draft open so the pick can insert.\n\t\t\tif (el.contains(target) || target.closest('.tlui-cmt-mention-popup')) return\n\t\t\t// A press on the canvas is the comment tool's to handle: it ends the placement and returns\n\t\t\t// to select. Clearing here first would let that press re-place the composer instead.\n\t\t\tif (editor.getContainer().querySelector('.tl-canvas')?.contains(target)) return\n\t\t\tpendingComment.set(editor, null)\n\t\t}\n\t\tdocument.addEventListener('pointerdown', onPointerDown, true)\n\t\treturn () => document.removeEventListener('pointerdown', onPointerDown, true)\n\t}, [editor])\n\n\tconst submit = () => {\n\t\tif (isCommentEmpty(text) || !currentUserId) return\n\t\tconst comment = commitCommentMutation(editor, ({ put }) => {\n\t\t\tconst pageId = editor.getCurrentPageId()\n\t\t\tconst thread = createCommentThread({\n\t\t\t\tpageId,\n\t\t\t\tanchor: pending.anchor,\n\t\t\t\tcreatedBy: currentUserId,\n\t\t\t})\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: text,\n\t\t\t})\n\t\t\tput([thread, comment])\n\t\t\treturn comment\n\t\t})\n\t\tsetText(EMPTY_COMMENT)\n\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\n\t\tpendingComment.set(editor, null)\n\t\t// Posting ends the placement interaction \u2014 hand the comment tool back to select. Only from\n\t\t// the settled idle state: Enter can land while a fresh press is mid-gesture (the composer\n\t\t// trails the pointer), and switching tools under a held pointer would strand the gesture.\n\t\tif (editor.isIn('comment.idle')) editor.setCurrentTool('select')\n\t\t// The host's callback is its own operation, not part of the post's history scope. It runs\n\t\t// last so a throwing host can't strand the composer holding a draft of a posted comment.\n\t\tonPostComment?.(comment)\n\t}\n\n\treturn (\n\t\t<EditorPortal>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={[\n\t\t\t\t\t'tlui-cmt-canvas-composer',\n\t\t\t\t\tpending.anchor.type === 'region' && 'tlui-cmt-canvas-composer--region',\n\t\t\t\t\t!canComment && 'tlui-cmt-canvas-composer--fallback',\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t\tstyle={{ left: placed.left, top: placed.top }}\n\t\t\t\tonPointerDown={stop}\n\t\t\t\tonContextMenu={stop}\n\t\t\t\tonKeyDown={(e) => {\n\t\t\t\t\tif (e.key === 'Escape' && !isMentionPickerOpen()) pendingComment.set(editor, null)\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{canComment ? (\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={me ?? UNKNOWN_COMMENT_AUTHOR}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsAddPlaceholder)}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSend)}\n\t\t\t\t\t\tvalue={text}\n\t\t\t\t\t\tonChange={(value) => {\n\t\t\t\t\t\t\tsetText(value)\n\t\t\t\t\t\t\tsaveCommentDraft(NEW_COMMENT_DRAFT, value)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonSubmit={submit}\n\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\tdisabled={isCommentEmpty(text) || !currentUserId}\n\t\t\t\t\t\tgetMentionSuggestions={getMentionSuggestions}\n\t\t\t\t\t\trenderMentionSuggestion={renderMentionSuggestion}\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tleading={draftAvatar}\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\tComposerFallback && <ComposerFallback context=\"pending\" />\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n"],
5
- "mappings": "AAyDG;AAzDH,SAAS,QAAQ,2BAA2B;AAC5C,SAAS,WAAW,QAAQ,gBAAgB;AAC5C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,uBAAuB;AAChC,SAAS,eAAe,sBAAsB;AAC9C,SAAS,kBAAkB;AAC3B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAGvC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,eAAe,4BAA4B;AACpD,SAAS,sBAAsB;AAE/B,MAAM,WAAW,eAAe;AAAA,EAC/B,cAAc,EAAE,IAAI,iBAAiB,gBAAgB,OAAO;AAAA,EAC5D,wBAAwB,EAAE,IAAI,4BAA4B,gBAAgB,sBAAiB;AAC5F,CAAC;AAED,MAAM,OAAO,CAAC,MAAmC,EAAE,gBAAgB;AAO5D,SAAS,gBAAgB;AAAA,EAC/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BAAiB,SAAQ,WAAU;AAAA;AAAA,EAE1D,GACD;AAEF;",
4
+ "sourcesContent": ["import { Avatar, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\ttype MouseEvent as ReactMouseEvent,\n\ttype PointerEvent as ReactPointerEvent,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport {\n\tcreateComment,\n\tcreateCommentThread,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLCommentAnchor,\n\tTLRichText,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n\tVecLike,\n} from 'tldraw'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentPin } from '../ui/comment-pin'\nimport { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from './canvas-events'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\tNEW_COMMENT_DRAFT,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport { commitCommentPost } from './comment-mutations'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { PendingComment, pendingCommentAt } from './comment-tool'\nimport { type CommentingContext } from './context'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport { useCanComment, useCommentingOptions } from './options'\nimport { pendingComment } from './state'\nimport {\n\tcommentTargetShapeAt,\n\tregionAnchorPinCorner,\n\tregionPinPoint,\n\tregionWithPinAt,\n} from './thread-state'\nimport { avatarRenderer } from './thread-view'\n\nconst messages = defineMessages({\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsAddPlaceholder: { id: 'comments.add-placeholder', defaultMessage: 'Add a comment\u2026' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * The composer for a thread that doesn't exist yet: the comment tool has placed a point (or\n * region) and is waiting on a first comment. Submitting creates the thread and its comment\n * together; clicking away keeps the draft for the next placement.\n */\nexport function PendingComposer({\n\teditor,\n\tpending,\n\tcurrentUserId,\n\tresolveAuthor,\n\tonPostComment,\n\tgetMentionSuggestions,\n\trenderMentionSuggestion,\n}: CommentingContext & { editor: Editor; pending: PendingComment }) {\n\tconst { components } = useCommentingOptions()\n\tconst ComposerFallback = components.ComposerFallback\n\tconst canComment = useCanComment(currentUserId)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\tconst isMobile = useIsMobileCommenting()\n\tconst drag = useDraftDrag(editor, pending)\n\t// The leading pin previews the pin this draft becomes: a white pin holding the author's avatar.\n\tconst draftAvatar = (\n\t\t<div\n\t\t\tclassName=\"tlui-cmt-canvas-composer__handle\"\n\t\t\t// On mobile the composer floats free of its point, so there's no pin to drag.\n\t\t\t{...(isMobile ? {} : drag.handlers)}\n\t\t>\n\t\t\t<CommentPin>\n\t\t\t\t{avatarRenderer(components, currentUserId)?.(me ?? UNKNOWN_COMMENT_AUTHOR) ?? (\n\t\t\t\t\t<Avatar author={me ?? UNKNOWN_COMMENT_AUTHOR} />\n\t\t\t\t)}\n\t\t\t</CommentPin>\n\t\t</div>\n\t)\n\t// Click-away keeps the draft (saved on every change) and the next placement composer\n\t// restores it \u2014 the flip side of dismissing without a discard warning.\n\tconst [text, setText] = useState<TLRichText>(\n\t\t() => getCommentDraft(NEW_COMMENT_DRAFT) ?? EMPTY_COMMENT\n\t)\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst msg = useTranslation()\n\t// Over this floating panel, a scroll reaches the canvas (except where it scrolls itself).\n\tusePassThroughWheelEvents(ref)\n\n\tconst point = useValue('composer point', () => editor.pageToViewport(pending.point), [\n\t\teditor,\n\t\tpending.point,\n\t])\n\t// On mobile the composer floats free of the pin so it can clear the software keyboard; desktop\n\t// keeps it pinned to the point.\n\tconst placed = useMobilePlacement(ref, point, isMobile)\n\n\t// Escape steps back one level at a time: a draft with text is cleared first, and only an empty\n\t// one closes. A native listener on the composer, because the editor's own Escape handler (which\n\t// would also cancel the comment tool) sits on its container, below React's root listener.\n\tconst textRef = useRef(text)\n\ttextRef.current = text\n\tuseEffect(() => {\n\t\tconst el = ref.current\n\t\tif (!el) return\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || isMentionPickerOpen()) return\n\t\t\te.stopPropagation()\n\t\t\tif (!isCommentEmpty(textRef.current)) {\n\t\t\t\tsetText(EMPTY_COMMENT)\n\t\t\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tpendingComment.set(editor, null)\n\t\t\t// Focus would drop to the page with the composer gone, out of reach of the next Escape.\n\t\t\teditor.getContainer().focus()\n\t\t}\n\t\tel.addEventListener('keydown', onKeyDown)\n\t\treturn () => el.removeEventListener('keydown', onKeyDown)\n\t}, [editor])\n\n\t// Dismiss on a click anywhere outside the composer (capture-phase, ahead of stopPropagation).\n\tuseEffect(() => {\n\t\tconst onPointerDown = (e: PointerEvent) => {\n\t\t\tconst el = ref.current\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!el || !target) return\n\t\t\t// A click in the composer, or in the mention picker it spawns (portaled elsewhere), is\n\t\t\t// not \"outside\" \u2014 keep the draft open so the pick can insert.\n\t\t\tif (el.contains(target) || target.closest('.tlui-cmt-mention-popup')) return\n\t\t\t// Panning the camera to look around while writing isn't leaving the draft.\n\t\t\tif (isCanvasPanGesture(editor, e) || (e as any).isSpecialRedispatchedEvent) return\n\t\t\tpendingComment.set(editor, null)\n\t\t}\n\t\tdocument.addEventListener('pointerdown', onPointerDown, true)\n\t\treturn () => document.removeEventListener('pointerdown', onPointerDown, true)\n\t}, [editor])\n\n\tconst submit = () => {\n\t\tif (isCommentEmpty(text) || !currentUserId) return\n\t\tconst comment = commitCommentPost(editor, ({ put }) => {\n\t\t\tconst pageId = editor.getCurrentPageId()\n\t\t\tconst thread = createCommentThread({\n\t\t\t\tpageId,\n\t\t\t\tanchor: pending.anchor,\n\t\t\t\tcreatedBy: currentUserId,\n\t\t\t})\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: text,\n\t\t\t})\n\t\t\tput([thread, comment])\n\t\t\treturn comment\n\t\t})\n\t\t// refused: keep the draft; the editor has emitted 'refused'\n\t\tif (!comment) return\n\t\tsetText(EMPTY_COMMENT)\n\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\n\t\tpendingComment.set(editor, null)\n\t\t// The host's callback is its own operation, not part of the post's history scope. It runs\n\t\t// last so a throwing host can't strand the composer holding a draft of a posted comment.\n\t\tonPostComment?.(comment)\n\t}\n\n\treturn (\n\t\t<EditorPortal>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={[\n\t\t\t\t\t'tlui-cmt-canvas-composer',\n\t\t\t\t\tpending.anchor.type === 'region' && 'tlui-cmt-canvas-composer--region',\n\t\t\t\t\tdrag.dragging && 'tlui-cmt-canvas-composer--dragging',\n\t\t\t\t\t!canComment && 'tlui-cmt-canvas-composer--fallback',\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t\tstyle={{ left: placed.left, top: placed.top }}\n\t\t\t\tonPointerDown={stop}\n\t\t\t\tonContextMenu={stop}\n\t\t\t>\n\t\t\t\t{canComment ? (\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={me ?? UNKNOWN_COMMENT_AUTHOR}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsAddPlaceholder)}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSend)}\n\t\t\t\t\t\tvalue={text}\n\t\t\t\t\t\tonChange={(value) => {\n\t\t\t\t\t\t\tsetText(value)\n\t\t\t\t\t\t\tsaveCommentDraft(NEW_COMMENT_DRAFT, value)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonSubmit={submit}\n\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\tdisabled={isCommentEmpty(text) || !currentUserId}\n\t\t\t\t\t\tgetMentionSuggestions={getMentionSuggestions}\n\t\t\t\t\t\trenderMentionSuggestion={renderMentionSuggestion}\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tleading={draftAvatar}\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\tComposerFallback && <ComposerFallback context=\"pending\" />\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n\n/** Drag the draft by its avatar pin, the way a placed pin drags: the composer follows the pointer\n * and, on release, re-anchors to the shape under it (a region translates, keeping its size). */\nfunction useDraftDrag(editor: Editor, pending: PendingComment) {\n\tconst [dragging, setDragging] = useState(false)\n\tconst dragRef = useRef<{\n\t\tstartX: number\n\t\tstartY: number\n\t\tmoved: boolean\n\t\t// The pin's page offset from the grab point, so the pin keeps its place under the pointer.\n\t\toffsetX: number\n\t\toffsetY: number\n\t\tclientX: number\n\t\tclientY: number\n\t\tendDrag?(): void\n\t} | null>(null)\n\t// Unmounting mid-drag (the draft is dismissed) gets no pointer up to end the drag, and the\n\t// drop-target hint is editor-global state that would otherwise stay on the shape.\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (!dragRef.current) return\n\t\t\tdragRef.current.endDrag?.()\n\t\t\teditor.setHintingShapes([])\n\t\t},\n\t\t[editor]\n\t)\n\n\tconst pagePointFor = (clientX: number, clientY: number) => {\n\t\tconst drag = dragRef.current!\n\t\tconst cursor = editor.screenToPage({ x: clientX, y: clientY })\n\t\treturn { x: cursor.x + drag.offsetX, y: cursor.y + drag.offsetY }\n\t}\n\n\t// A region moves as a whole, its box riding with the pin corner; a point draft moves only its\n\t// composer until the drop, when its anchor resolves against what's under it.\n\tconst moveRegion = (anchor: Extract<TLCommentAnchor, { type: 'region' }>, point: VecLike) => {\n\t\tconst corner = regionAnchorPinCorner(anchor)\n\t\tconst moved = regionWithPinAt(anchor, corner, point)\n\t\tpendingComment.set(editor, { anchor: moved, point: regionPinPoint(moved, corner) })\n\t}\n\n\t// Mid-drag, a point draft hints the shape a drop here would anchor to.\n\tconst previewAt = (point: VecLike) => {\n\t\tconst current = pendingComment.get(editor)\n\t\tif (!current) return\n\t\tif (current.anchor.type === 'region') return moveRegion(current.anchor, point)\n\t\tpendingComment.set(editor, { ...current, point: { x: point.x, y: point.y } })\n\t\tconst hit = commentTargetShapeAt(editor, point)\n\t\teditor.setHintingShapes(hit ? [hit.id] : [])\n\t}\n\n\tconst settleAt = (point: VecLike, altKey: boolean) => {\n\t\tconst current = pendingComment.get(editor)\n\t\tif (!current) return\n\t\tif (current.anchor.type === 'region') return moveRegion(current.anchor, point)\n\t\tpendingComment.set(editor, pendingCommentAt(editor, point, altKey))\n\t}\n\n\tconst takeDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tdragRef.current = null\n\t\tdrag?.endDrag?.()\n\t\teditor.setHintingShapes([])\n\t\tsetDragging(false)\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId)) {\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\t}\n\t\treturn drag\n\t}\n\n\tconst handlers = {\n\t\tonPointerDown: (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\t\t// A middle/right-button or space-held press is a camera pan, not a drag.\n\t\t\tif (isCanvasPanGesture(editor, e)) {\n\t\t\t\tforwardPointerEventToCanvas(editor.getContainer(), e)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst grab = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\t\tdragRef.current = {\n\t\t\t\tstartX: e.clientX,\n\t\t\t\tstartY: e.clientY,\n\t\t\t\tclientX: e.clientX,\n\t\t\t\tclientY: e.clientY,\n\t\t\t\tmoved: false,\n\t\t\t\toffsetX: pending.point.x - grab.x,\n\t\t\t\toffsetY: pending.point.y - grab.y,\n\t\t\t}\n\t\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t\t},\n\t\t// Keep focus in the comment field: grabbing the pin shouldn't blur what's being typed.\n\t\tonMouseDown: (e: ReactMouseEvent) => e.preventDefault(),\n\t\tonPointerMove: (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\t\tconst drag = dragRef.current\n\t\t\tif (!drag) return\n\t\t\tif (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return\n\t\t\tdrag.clientX = e.clientX\n\t\t\tdrag.clientY = e.clientY\n\t\t\tif (!drag.moved) {\n\t\t\t\tdrag.moved = true\n\t\t\t\tdrag.endDrag = startCommentDrag(editor, {\n\t\t\t\t\tcursor: 'move',\n\t\t\t\t\tonCameraMove: () => {\n\t\t\t\t\t\tconst d = dragRef.current\n\t\t\t\t\t\tif (d) previewAt(pagePointFor(d.clientX, d.clientY))\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tsetDragging(true)\n\t\t\t}\n\t\t\tpreviewAt(pagePointFor(e.clientX, e.clientY))\n\t\t},\n\t\tonPointerUp: (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\t\tconst moved = dragRef.current?.moved\n\t\t\tconst point = moved ? pagePointFor(e.clientX, e.clientY) : null\n\t\t\ttakeDrag(e)\n\t\t\tif (point) settleAt(point, e.altKey)\n\t\t},\n\t\t// A cancelled pointer leaves the draft where the drag last put it, with its anchor resolved.\n\t\tonPointerCancel: (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\t\tconst drag = takeDrag(e)\n\t\t\tconst current = pendingComment.get(editor)\n\t\t\tif (drag?.moved && current) settleAt(current.point, editor.inputs.getAltKey())\n\t\t},\n\t}\n\n\treturn { dragging, handlers }\n}\n"],
5
+ "mappings": "AAkFK;AAlFL,SAAS,QAAQ,2BAA2B;AAC5C;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,uBAAuB;AAChC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AAAA,UACvC,QAAQ;AAAA,UACR,cAAc,MAAM;AACnB,kBAAM,IAAI,QAAQ;AAClB,gBAAI,EAAG,WAAU,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC;AAAA,UACpD;AAAA,QACD,CAAC;AACD,oBAAY,IAAI;AAAA,MACjB;AACA,gBAAU,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC;AAAA,IAC7C;AAAA,IACA,aAAa,CAAC,MAAyC;AACtD,YAAM,QAAQ,QAAQ,SAAS;AAC/B,YAAM,QAAQ,QAAQ,aAAa,EAAE,SAAS,EAAE,OAAO,IAAI;AAC3D,eAAS,CAAC;AACV,UAAI,MAAO,UAAS,OAAO,EAAE,MAAM;AAAA,IACpC;AAAA;AAAA,IAEA,iBAAiB,CAAC,MAAyC;AAC1D,YAAM,OAAO,SAAS,CAAC;AACvB,YAAM,UAAU,eAAe,IAAI,MAAM;AACzC,UAAI,MAAM,SAAS,QAAS,UAAS,QAAQ,OAAO,OAAO,OAAO,UAAU,CAAC;AAAA,IAC9E;AAAA,EACD;AAEA,SAAO,EAAE,UAAU,SAAS;AAC7B;",
6
6
  "names": ["comment"]
7
7
  }
@@ -1,6 +1,12 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
2
- import { useRef } from "react";
3
- import { useValue } from "tldraw";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import {
4
+ getCursor,
5
+ getPerfectDashProps,
6
+ usePassThroughWheelEvents,
7
+ useValue
8
+ } from "tldraw";
9
+ import { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from "./canvas-events.mjs";
4
10
  import { regionDraft } from "./state.mjs";
5
11
  function RegionBox({ editor, box }) {
6
12
  const rect = useValue(
@@ -12,7 +18,32 @@ function RegionBox({ editor, box }) {
12
18
  },
13
19
  [editor, box.x, box.y, box.w, box.h]
14
20
  );
15
- return /* @__PURE__ */ jsx("div", { className: "tlui-cmt-canvas-region", style: rect });
21
+ const { width: w, height: h } = rect;
22
+ const sides = [
23
+ [0, 0, w, 0],
24
+ [w, 0, w, h],
25
+ [w, h, 0, h],
26
+ [0, h, 0, 0]
27
+ ];
28
+ return /* @__PURE__ */ jsx("div", { className: "tlui-cmt-canvas-region", style: rect, children: /* @__PURE__ */ jsx("svg", { className: "tlui-cmt-canvas-region__outline", width: w, height: h, "aria-hidden": "true", children: sides.map(([x1, y1, x2, y2], i) => {
29
+ const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(
30
+ Math.hypot(x2 - x1, y2 - y1),
31
+ 1,
32
+ { style: "dashed", lengthRatio: 4 }
33
+ );
34
+ return /* @__PURE__ */ jsx(
35
+ "line",
36
+ {
37
+ x1,
38
+ y1,
39
+ x2,
40
+ y2,
41
+ strokeDasharray,
42
+ strokeDashoffset
43
+ },
44
+ i
45
+ );
46
+ }) }) });
16
47
  }
17
48
  function RegionDraftBox({ editor }) {
18
49
  const box = useValue("region draft", () => regionDraft.get(editor), [editor]);
@@ -27,17 +58,37 @@ const REGION_CORNERS = [
27
58
  ];
28
59
  const REGION_HANDLE_MARGIN_PX = 12;
29
60
  function resizeRegion(box, handle, cursor) {
30
- const controlsX = handle.x !== 0.5;
31
- const controlsY = handle.y !== 0.5;
32
61
  const fixedX = box.x + (1 - handle.x) * box.w;
33
62
  const fixedY = box.y + (1 - handle.y) * box.h;
34
63
  return {
35
- x: controlsX ? Math.min(fixedX, cursor.x) : box.x,
36
- y: controlsY ? Math.min(fixedY, cursor.y) : box.y,
37
- w: controlsX ? Math.abs(cursor.x - fixedX) : box.w,
38
- h: controlsY ? Math.abs(cursor.y - fixedY) : box.h
64
+ x: Math.min(fixedX, cursor.x),
65
+ y: Math.min(fixedY, cursor.y),
66
+ w: Math.abs(cursor.x - fixedX),
67
+ h: Math.abs(cursor.y - fixedY)
39
68
  };
40
69
  }
70
+ function selectionCornerSizing(w, h, isCoarsePointer) {
71
+ const handleSize = 8;
72
+ const mobileHandleMultiplier = isCoarsePointer ? 1.75 : 1;
73
+ const hitTargetSize = 6 * mobileHandleMultiplier;
74
+ const isSmallX = w < handleSize * 4;
75
+ const isSmallY = h < handleSize * 4;
76
+ const hitTargetSizeX = (isSmallX ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75);
77
+ const hitTargetSizeY = (isSmallY ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75);
78
+ const isTinyX = w < handleSize * 2;
79
+ const isTinyY = h < handleSize * 2;
80
+ return {
81
+ // The corner hit square's full side: the util's `cornerHitHalfSize`, doubled.
82
+ hitSize: Math.max(hitTargetSizeX, hitTargetSizeY) * 1.5 * 2,
83
+ hideAlternateCorners: isTinyX || isTinyY,
84
+ showOnlyOneCorner: isTinyX && isTinyY
85
+ };
86
+ }
87
+ function isHiddenCorner(h, sizing) {
88
+ if (h.x === 0 && h.y === 0) return false;
89
+ if (h.x === 1 && h.y === 1) return sizing.showOnlyOneCorner;
90
+ return sizing.hideAlternateCorners;
91
+ }
41
92
  function RegionResizeHandles({
42
93
  editor,
43
94
  box,
@@ -45,49 +96,121 @@ function RegionResizeHandles({
45
96
  onPreview,
46
97
  onCommit
47
98
  }) {
48
- const boxRef = useRef(null);
49
- const points = useValue(
50
- "region handle points",
51
- () => handles.map((h) => {
52
- const p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h });
53
- return { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y };
54
- }),
99
+ const dragRef = useRef(null);
100
+ const wheelRef = useRef(null);
101
+ usePassThroughWheelEvents(wheelRef);
102
+ useEffect(() => () => dragRef.current?.endDrag(), []);
103
+ const layout = useValue(
104
+ "region handle layout",
105
+ () => {
106
+ const zoom = editor.getZoomLevel();
107
+ const sizing = selectionCornerSizing(
108
+ box.w * zoom,
109
+ box.h * zoom,
110
+ editor.getInstanceState().isCoarsePointer
111
+ );
112
+ const dragged = dragRef.current?.handle;
113
+ const points2 = handles.filter((h) => h.x === dragged?.x && h.y === dragged?.y || !isHiddenCorner(h, sizing)).map((h) => {
114
+ const p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h });
115
+ return { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y };
116
+ });
117
+ const { cursor: cursorColor } = editor.getCurrentTheme().colors[editor.getColorMode()];
118
+ const cursors2 = {
119
+ "nwse-resize": getCursor("nwse-resize", 0, cursorColor),
120
+ "nesw-resize": getCursor("nesw-resize", 0, cursorColor)
121
+ };
122
+ return { points: points2, hitSize: sizing.hitSize, cursors: cursors2 };
123
+ },
55
124
  [editor, box.x, box.y, box.w, box.h, handles]
56
125
  );
57
- const startResize = (e) => {
126
+ const { points, hitSize, cursors } = layout;
127
+ const resized = () => {
128
+ const drag = dragRef.current;
129
+ return resizeRegion(
130
+ drag.box,
131
+ drag.handle,
132
+ editor.screenToPage({ x: drag.clientX, y: drag.clientY })
133
+ );
134
+ };
135
+ const startResize = (h) => (e) => {
136
+ if (isCanvasPanGesture(editor, e)) {
137
+ forwardPointerEventToCanvas(editor.getContainer(), e);
138
+ return;
139
+ }
58
140
  e.stopPropagation();
59
- boxRef.current = box;
141
+ dragRef.current?.endDrag();
142
+ dragRef.current = {
143
+ box,
144
+ handle: h,
145
+ clientX: e.clientX,
146
+ clientY: e.clientY,
147
+ endDrag: startCommentDrag(editor, {
148
+ cursor: h.cursor,
149
+ onCameraMove: () => {
150
+ if (dragRef.current) onPreview(resized());
151
+ }
152
+ })
153
+ };
60
154
  e.currentTarget.setPointerCapture(e.pointerId);
61
155
  };
62
- const resizedTo = (h, e) => resizeRegion(boxRef.current, h, editor.screenToPage({ x: e.clientX, y: e.clientY }));
63
- const onResize = (h) => (e) => {
64
- if (boxRef.current) onPreview(resizedTo(h, e));
156
+ const onResize = (e) => {
157
+ const drag = dragRef.current;
158
+ if (!drag) return;
159
+ drag.clientX = e.clientX;
160
+ drag.clientY = e.clientY;
161
+ onPreview(resized());
65
162
  };
66
- const endResize = (h) => (e) => {
67
- if (!boxRef.current) return;
68
- const bounds = resizedTo(h, e);
69
- boxRef.current = null;
163
+ const endResize = (e) => {
164
+ const drag = dragRef.current;
165
+ if (!drag) return;
166
+ drag.clientX = e.clientX;
167
+ drag.clientY = e.clientY;
168
+ const bounds = resized();
169
+ dragRef.current = null;
170
+ drag.endDrag();
70
171
  if (e.currentTarget.hasPointerCapture(e.pointerId))
71
172
  e.currentTarget.releasePointerCapture(e.pointerId);
72
173
  onCommit(bounds);
73
174
  };
74
- return /* @__PURE__ */ jsx(Fragment, { children: points.map((h) => /* @__PURE__ */ jsx(
75
- "div",
76
- {
77
- className: "tlui-cmt-canvas-region-handle",
78
- style: { left: h.left, top: h.top, cursor: h.cursor },
79
- onPointerDown: startResize,
80
- onPointerMove: onResize(h),
81
- onPointerUp: endResize(h)
82
- },
83
- h.key
84
- )) });
175
+ const cancelResize = () => {
176
+ const drag = dragRef.current;
177
+ if (!drag) return;
178
+ dragRef.current = null;
179
+ drag.endDrag();
180
+ onPreview(null);
181
+ };
182
+ return (
183
+ // A wheel over a handle (even mid-resize) scrolls the canvas, like everywhere else on it.
184
+ /* @__PURE__ */ (jsx(
185
+ "div",
186
+ { ref: wheelRef, className: "tlui-cmt-canvas-region-handles", children: points.map((h) => /* @__PURE__ */ jsx(
187
+ "div",
188
+ {
189
+ className: "tlui-cmt-canvas-region-handle",
190
+ style: {
191
+ left: h.left,
192
+ top: h.top,
193
+ width: hitSize,
194
+ height: hitSize,
195
+ cursor: cursors[h.cursor]
196
+ },
197
+ onPointerDown: startResize(h),
198
+ onPointerMove: onResize,
199
+ onPointerUp: endResize,
200
+ onPointerCancel: cancelResize,
201
+ onLostPointerCapture: cancelResize
202
+ },
203
+ h.key
204
+ )) }
205
+ ))
206
+ );
85
207
  }
86
208
  export {
87
209
  REGION_CORNERS,
88
210
  REGION_HANDLE_MARGIN_PX,
89
211
  RegionBox,
90
212
  RegionDraftBox,
91
- RegionResizeHandles
213
+ RegionResizeHandles,
214
+ selectionCornerSizing
92
215
  };
93
216
  //# sourceMappingURL=region-box.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/region-box.tsx"],
4
- "sourcesContent": ["import { type PointerEvent as ReactPointerEvent, useRef } from 'react'\nimport { type BoxModel, Editor, useValue, VecLike } from 'tldraw'\nimport { regionDraft } from './state'\n\n/** A region's dashed box. Purely visual \u2014 a region moves by its pin and resizes from its corner\n * handles, so the box itself takes no pointer events. Positioned in viewport space, as a sibling\n * of the pins in the canvas layer. */\nexport function RegionBox({ editor, box }: { editor: Editor; box: BoxModel }) {\n\tconst rect = useValue(\n\t\t'region rect',\n\t\t() => {\n\t\t\t// Position from the page\u2192viewport top-left; screen size scales with zoom, page size doesn't.\n\t\t\tconst topLeft = editor.pageToViewport({ x: box.x, y: box.y })\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\treturn { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h]\n\t)\n\treturn <div className=\"tlui-cmt-canvas-region\" style={rect} />\n}\n\n/** The live region being dragged out by the comment tool, or nothing when not dragging. */\nexport function RegionDraftBox({ editor }: { editor: Editor }) {\n\tconst box = useValue('region draft', () => regionDraft.get(editor), [editor])\n\tif (!box) return null\n\treturn <RegionBox editor={editor} box={box} />\n}\n\n// A resize handle's normalized 0\u20131 spot on the box, and its cursor. An axis at 0.5 is *not*\n// controlled by that handle \u2014 the resize math reads the spot rather than special-casing corners.\nexport interface RegionHandle {\n\tx: number\n\ty: number\n\tcursor: string\n}\n\n// The four corners, each resizing both axes.\nexport const REGION_CORNERS: readonly RegionHandle[] = [\n\t{ x: 0, y: 0, cursor: 'nwse-resize' },\n\t{ x: 1, y: 0, cursor: 'nesw-resize' },\n\t{ x: 0, y: 1, cursor: 'nesw-resize' },\n\t{ x: 1, y: 1, cursor: 'nwse-resize' },\n]\n\n// Screen-space slack around a region's bounds within which its box and handles stay revealed, so\n// the handles (which sit on the edge) are comfortably reachable.\nexport const REGION_HANDLE_MARGIN_PX = 12\n\n/** Resize `box` by dragging `handle` to `cursor` (page coords). Each controlled axis spans from the\n * handle's fixed opposite edge to the cursor (normalized, so dragging past it flips); an axis the\n * handle doesn't control (a midpoint, at 0.5) keeps its original position and size. */\nfunction resizeRegion(box: BoxModel, handle: RegionHandle, cursor: VecLike): BoxModel {\n\tconst controlsX = handle.x !== 0.5\n\tconst controlsY = handle.y !== 0.5\n\tconst fixedX = box.x + (1 - handle.x) * box.w\n\tconst fixedY = box.y + (1 - handle.y) * box.h\n\treturn {\n\t\tx: controlsX ? Math.min(fixedX, cursor.x) : box.x,\n\t\ty: controlsY ? Math.min(fixedY, cursor.y) : box.y,\n\t\tw: controlsX ? Math.abs(cursor.x - fixedX) : box.w,\n\t\th: controlsY ? Math.abs(cursor.y - fixedY) : box.h,\n\t}\n}\n\n/** Draggable handles that resize a region \u2014 corners (both axes) or edges (one axis), per the resize\n * option. Previews live, commits on release. */\nexport function RegionResizeHandles({\n\teditor,\n\tbox,\n\thandles,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\thandles: readonly RegionHandle[]\n\tonPreview(bounds: BoxModel | null): void\n\tonCommit(bounds: BoxModel): void\n}) {\n\t// The box at pointer-down, captured so the box prop reflowing under the live preview doesn't move\n\t// the fixed edges mid-drag.\n\tconst boxRef = useRef<BoxModel | null>(null)\n\tconst points = useValue(\n\t\t'region handle points',\n\t\t() =>\n\t\t\thandles.map((h) => {\n\t\t\t\tconst p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })\n\t\t\t\treturn { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }\n\t\t\t}),\n\t\t[editor, box.x, box.y, box.w, box.h, handles]\n\t)\n\tconst startResize = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tboxRef.current = box\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst resizedTo = (h: RegionHandle, e: ReactPointerEvent<HTMLDivElement>): BoxModel =>\n\t\tresizeRegion(boxRef.current!, h, editor.screenToPage({ x: e.clientX, y: e.clientY }))\n\tconst onResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (boxRef.current) onPreview(resizedTo(h, e))\n\t}\n\tconst endResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (!boxRef.current) return\n\t\tconst bounds = resizedTo(h, e)\n\t\tboxRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit(bounds)\n\t}\n\treturn (\n\t\t<>\n\t\t\t{points.map((h) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={h.key}\n\t\t\t\t\tclassName=\"tlui-cmt-canvas-region-handle\"\n\t\t\t\t\tstyle={{ left: h.left, top: h.top, cursor: h.cursor }}\n\t\t\t\t\tonPointerDown={startResize}\n\t\t\t\t\tonPointerMove={onResize(h)}\n\t\t\t\t\tonPointerUp={endResize(h)}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</>\n\t)\n}\n"],
5
- "mappings": "AAkBQ,SA4FN,UA5FM;AAlBR,SAAiD,cAAc;AAC/D,SAAgC,gBAAyB;AACzD,SAAS,mBAAmB;AAKrB,SAAS,UAAU,EAAE,QAAQ,IAAI,GAAsC;AAC7E,QAAM,OAAO;AAAA,IACZ;AAAA,IACA,MAAM;AAEL,YAAM,UAAU,OAAO,eAAe,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,EAAE,CAAC;AAC5D,YAAM,OAAO,OAAO,aAAa;AACjC,aAAO,EAAE,MAAM,QAAQ,GAAG,KAAK,QAAQ,GAAG,OAAO,IAAI,IAAI,MAAM,QAAQ,IAAI,IAAI,KAAK;AAAA,IACrF;AAAA,IACA,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAA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F;AAEF;",
6
- "names": []
4
+ "sourcesContent": ["import { type PointerEvent as ReactPointerEvent, useEffect, useRef } from 'react'\nimport {\n\ttype BoxModel,\n\tEditor,\n\tgetCursor,\n\tgetPerfectDashProps,\n\tusePassThroughWheelEvents,\n\tuseValue,\n\tVecLike,\n} from 'tldraw'\nimport { forwardPointerEventToCanvas, isCanvasPanGesture, startCommentDrag } from './canvas-events'\nimport { regionDraft } from './state'\n\n/** A region's dashed box. Purely visual \u2014 a region moves by its pin and resizes from its corner\n * handles, so the box itself takes no pointer events. Positioned in viewport space, as a sibling\n * of the pins in the canvas layer. */\nexport function RegionBox({ editor, box }: { editor: Editor; box: BoxModel }) {\n\tconst rect = useValue(\n\t\t'region rect',\n\t\t() => {\n\t\t\t// Position from the page\u2192viewport top-left; screen size scales with zoom, page size doesn't.\n\t\t\tconst topLeft = editor.pageToViewport({ x: box.x, y: box.y })\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\treturn { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h]\n\t)\n\tconst { width: w, height: h } = rect\n\t// The group outline's dashes: drawn per side with perfect dashes (so every side starts and ends\n\t// on a dash), at the 1px dash scale and 1.5px stroke the editor's selection outline uses.\n\tconst sides = [\n\t\t[0, 0, w, 0],\n\t\t[w, 0, w, h],\n\t\t[w, h, 0, h],\n\t\t[0, h, 0, 0],\n\t]\n\treturn (\n\t\t<div className=\"tlui-cmt-canvas-region\" style={rect}>\n\t\t\t<svg className=\"tlui-cmt-canvas-region__outline\" width={w} height={h} aria-hidden=\"true\">\n\t\t\t\t{sides.map(([x1, y1, x2, y2], i) => {\n\t\t\t\t\tconst { strokeDasharray, strokeDashoffset } = getPerfectDashProps(\n\t\t\t\t\t\tMath.hypot(x2 - x1, y2 - y1),\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t{ style: 'dashed', lengthRatio: 4 }\n\t\t\t\t\t)\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={i}\n\t\t\t\t\t\t\tx1={x1}\n\t\t\t\t\t\t\ty1={y1}\n\t\t\t\t\t\t\tx2={x2}\n\t\t\t\t\t\t\ty2={y2}\n\t\t\t\t\t\t\tstrokeDasharray={strokeDasharray}\n\t\t\t\t\t\t\tstrokeDashoffset={strokeDashoffset}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t})}\n\t\t\t</svg>\n\t\t</div>\n\t)\n}\n\n/** The live region being dragged out by the comment tool, or nothing when not dragging. */\nexport function RegionDraftBox({ editor }: { editor: Editor }) {\n\tconst box = useValue('region draft', () => regionDraft.get(editor), [editor])\n\tif (!box) return null\n\treturn <RegionBox editor={editor} box={box} />\n}\n\n// A corner resize handle: its normalized 0\u20131 spot on the box, and its cursor.\nexport interface RegionHandle {\n\tx: number\n\ty: number\n\tcursor: 'nwse-resize' | 'nesw-resize'\n}\n\nexport const REGION_CORNERS: readonly RegionHandle[] = [\n\t{ x: 0, y: 0, cursor: 'nwse-resize' },\n\t{ x: 1, y: 0, cursor: 'nesw-resize' },\n\t{ x: 0, y: 1, cursor: 'nesw-resize' },\n\t{ x: 1, y: 1, cursor: 'nwse-resize' },\n]\n\n// Screen-space slack around a region's bounds within which its box and handles stay revealed, so\n// the handles (which sit on the edge) are comfortably reachable.\nexport const REGION_HANDLE_MARGIN_PX = 12\n\n/** Resize `box` by dragging corner `handle` to `cursor` (page coords): the box spans from the\n * opposite corner to the cursor, normalized so dragging past that corner flips it. */\nfunction resizeRegion(box: BoxModel, handle: RegionHandle, cursor: VecLike): BoxModel {\n\tconst fixedX = box.x + (1 - handle.x) * box.w\n\tconst fixedY = box.y + (1 - handle.y) * box.h\n\treturn {\n\t\tx: Math.min(fixedX, cursor.x),\n\t\ty: Math.min(fixedY, cursor.y),\n\t\tw: Math.abs(cursor.x - fixedX),\n\t\th: Math.abs(cursor.y - fixedY),\n\t}\n}\n\n/**\n * The selection's corner-handle sizing (`SelectionForegroundOverlayUtil`), in screen px for a box\n * `w`\u00D7`h` px on screen, so a region's corners look and hit exactly like a shape's resize corners.\n * Keep in step with that util: the constants are its, not tuned here.\n */\nexport function selectionCornerSizing(w: number, h: number, isCoarsePointer: boolean) {\n\tconst handleSize = 8\n\tconst mobileHandleMultiplier = isCoarsePointer ? 1.75 : 1\n\tconst hitTargetSize = 6 * mobileHandleMultiplier\n\tconst isSmallX = w < handleSize * 4\n\tconst isSmallY = h < handleSize * 4\n\tconst hitTargetSizeX =\n\t\t(isSmallX ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75)\n\tconst hitTargetSizeY =\n\t\t(isSmallY ? hitTargetSize / 2 : hitTargetSize) * (mobileHandleMultiplier * 0.75)\n\tconst isTinyX = w < handleSize * 2\n\tconst isTinyY = h < handleSize * 2\n\treturn {\n\t\t// The corner hit square's full side: the util's `cornerHitHalfSize`, doubled.\n\t\thitSize: Math.max(hitTargetSizeX, hitTargetSizeY) * 1.5 * 2,\n\t\thideAlternateCorners: isTinyX || isTinyY,\n\t\tshowOnlyOneCorner: isTinyX && isTinyY,\n\t}\n}\n\n// The selection hides the top-right and bottom-left corners on a tiny box, and the bottom-right too\n// when it's tiny both ways (top-left always shows).\nfunction isHiddenCorner(\n\th: RegionHandle,\n\tsizing: ReturnType<typeof selectionCornerSizing>\n): boolean {\n\tif (h.x === 0 && h.y === 0) return false\n\tif (h.x === 1 && h.y === 1) return sizing.showOnlyOneCorner\n\treturn sizing.hideAlternateCorners\n}\n\n/** Draggable corner handles that resize a region. Previews live, commits on release. */\nexport function RegionResizeHandles({\n\teditor,\n\tbox,\n\thandles,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\thandles: readonly RegionHandle[]\n\tonPreview(bounds: BoxModel | null): void\n\tonCommit(bounds: BoxModel): void\n}) {\n\t// The box at pointer-down, captured so the box prop reflowing under the live preview doesn't move\n\t// the fixed edges mid-drag.\n\tconst dragRef = useRef<{\n\t\tbox: BoxModel\n\t\thandle: RegionHandle\n\t\tclientX: number\n\t\tclientY: number\n\t\tendDrag(): void\n\t} | null>(null)\n\tconst wheelRef = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(wheelRef)\n\t// Unmounting mid-resize gets no pointer up to end the drag.\n\tuseEffect(() => () => dragRef.current?.endDrag(), [])\n\tconst layout = useValue(\n\t\t'region handle layout',\n\t\t() => {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tconst sizing = selectionCornerSizing(\n\t\t\t\tbox.w * zoom,\n\t\t\t\tbox.h * zoom,\n\t\t\t\teditor.getInstanceState().isCoarsePointer\n\t\t\t)\n\t\t\tconst dragged = dragRef.current?.handle\n\t\t\tconst points = handles\n\t\t\t\t// The corner being dragged stays, even as the box shrinks to a size that hides it:\n\t\t\t\t// unmounting it would drop its pointer capture and strand the resize.\n\t\t\t\t.filter((h) => (h.x === dragged?.x && h.y === dragged?.y) || !isHiddenCorner(h, sizing))\n\t\t\t\t.map((h) => {\n\t\t\t\t\tconst p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })\n\t\t\t\t\treturn { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }\n\t\t\t\t})\n\t\t\t// tldraw's own resize cursors (the editor's, in the theme's cursor colour), not the\n\t\t\t// browser's native ones.\n\t\t\tconst { cursor: cursorColor } = editor.getCurrentTheme().colors[editor.getColorMode()]\n\t\t\tconst cursors = {\n\t\t\t\t'nwse-resize': getCursor('nwse-resize', 0, cursorColor),\n\t\t\t\t'nesw-resize': getCursor('nesw-resize', 0, cursorColor),\n\t\t\t}\n\t\t\treturn { points, hitSize: sizing.hitSize, cursors }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h, handles]\n\t)\n\tconst { points, hitSize, cursors } = layout\n\tconst resized = () => {\n\t\tconst drag = dragRef.current!\n\t\treturn resizeRegion(\n\t\t\tdrag.box,\n\t\t\tdrag.handle,\n\t\t\teditor.screenToPage({ x: drag.clientX, y: drag.clientY })\n\t\t)\n\t}\n\tconst startResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\t// A middle/right-button or space-held press is a camera pan, not a resize.\n\t\tif (isCanvasPanGesture(editor, e)) {\n\t\t\tforwardPointerEventToCanvas(editor.getContainer(), e)\n\t\t\treturn\n\t\t}\n\t\te.stopPropagation()\n\t\tdragRef.current?.endDrag()\n\t\tdragRef.current = {\n\t\t\tbox,\n\t\t\thandle: h,\n\t\t\tclientX: e.clientX,\n\t\t\tclientY: e.clientY,\n\t\t\tendDrag: startCommentDrag(editor, {\n\t\t\t\tcursor: h.cursor,\n\t\t\t\tonCameraMove: () => {\n\t\t\t\t\tif (dragRef.current) onPreview(resized())\n\t\t\t\t},\n\t\t\t}),\n\t\t}\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onResize = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\tdrag.clientX = e.clientX\n\t\tdrag.clientY = e.clientY\n\t\tonPreview(resized())\n\t}\n\tconst endResize = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\tdrag.clientX = e.clientX\n\t\tdrag.clientY = e.clientY\n\t\tconst bounds = resized()\n\t\tdragRef.current = null\n\t\tdrag.endDrag()\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit(bounds)\n\t}\n\t// A cancelled pointer abandons the resize: the region snaps back to its stored bounds.\n\tconst cancelResize = () => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\tdragRef.current = null\n\t\tdrag.endDrag()\n\t\tonPreview(null)\n\t}\n\treturn (\n\t\t// A wheel over a handle (even mid-resize) scrolls the canvas, like everywhere else on it.\n\t\t<div ref={wheelRef} className=\"tlui-cmt-canvas-region-handles\">\n\t\t\t{points.map((h) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={h.key}\n\t\t\t\t\tclassName=\"tlui-cmt-canvas-region-handle\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tleft: h.left,\n\t\t\t\t\t\ttop: h.top,\n\t\t\t\t\t\twidth: hitSize,\n\t\t\t\t\t\theight: hitSize,\n\t\t\t\t\t\tcursor: cursors[h.cursor],\n\t\t\t\t\t}}\n\t\t\t\t\tonPointerDown={startResize(h)}\n\t\t\t\t\tonPointerMove={onResize}\n\t\t\t\t\tonPointerUp={endResize}\n\t\t\t\t\tonPointerCancel={cancelResize}\n\t\t\t\t\tonLostPointerCapture={cancelResize}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</div>\n\t)\n}\n"],
5
+ "mappings": "AA8CM;AA9CN,SAAiD,WAAW,cAAc;AAC1E;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,6BAA6B,oBAAoB,wBAAwB;AAClF,SAAS,mBAAmB;AAKrB,SAAS,UAAU,EAAE,QAAQ,IAAI,GAAsC;AAC7E,QAAM,OAAO;AAAA,IACZ;AAAA,IACA,MAAM;AAEL,YAAM,UAAU,OAAO,eAAe,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,EAAE,CAAC;AAC5D,YAAM,OAAO,OAAO,aAAa;AACjC,aAAO,EAAE,MAAM,QAAQ,GAAG,KAAK,QAAQ,GAAG,OAAO,IAAI,IAAI,MAAM,QAAQ,IAAI,IAAI,KAAK;AAAA,IACrF;AAAA,IACA,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAAA,EACpC;AACA,QAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,IAAI;AAGhC,QAAM,QAAQ;AAAA,IACb,CAAC,GAAG,GAAG,GAAG,CAAC;AAAA,IACX,CAAC,GAAG,GAAG,GAAG,CAAC;AAAA,IACX,CAAC,GAAG,GAAG,GA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