@tldraw/commenting 5.7.0-canary.a3a344359895 → 5.7.0-canary.a5daf389abd7
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.
- package/commenting.css +3 -3
- package/dist-cjs/canvas/pending-composer.js +3 -7
- package/dist-cjs/canvas/pending-composer.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +0 -2
- package/dist-cjs/canvas/thread-view.js.map +2 -2
- package/dist-cjs/index.js +1 -1
- package/dist-esm/canvas/pending-composer.mjs +3 -7
- package/dist-esm/canvas/pending-composer.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +0 -2
- package/dist-esm/canvas/thread-view.mjs.map +2 -2
- package/dist-esm/index.mjs +1 -1
- package/package.json +5 -5
- package/src/canvas/pending-composer.tsx +6 -10
- package/src/canvas/thread-view.tsx +2 -5
- package/src/ui/comments.css +3 -3
package/commenting.css
CHANGED
|
@@ -799,7 +799,7 @@ button.tlui-cmt-reaction:hover {
|
|
|
799
799
|
}
|
|
800
800
|
|
|
801
801
|
.tlui-cmt-thread .tlui-cmt-composer {
|
|
802
|
-
padding:
|
|
802
|
+
padding: 4px;
|
|
803
803
|
}
|
|
804
804
|
.tlui-cmt-thread .tlui-cmt-composer .tlui-cmt-avatar {
|
|
805
805
|
display: none;
|
|
@@ -878,10 +878,10 @@ button.tlui-cmt-reaction:hover {
|
|
|
878
878
|
justify-content: space-between;
|
|
879
879
|
gap: 8px;
|
|
880
880
|
/* Flush top and right, like the thread popover's header: the 40px buttons' 32px hover squares
|
|
881
|
-
then sit 4px in from the panel edge, and the title shares the popover's 12px inset.
|
|
882
|
-
divider is an inset shadow, not a border, so the header stays the buttons' 40px tall. */
|
|
881
|
+
then sit 4px in from the panel edge, and the title shares the popover's 12px inset. */
|
|
883
882
|
height: 40px;
|
|
884
883
|
padding: 0 0 0 12px;
|
|
884
|
+
border-bottom: 1px solid var(--tl-color-divider);
|
|
885
885
|
}
|
|
886
886
|
.tlui-cmt-list__header-title {
|
|
887
887
|
font-size: 12px;
|
|
@@ -77,19 +77,14 @@ function PendingComposer({
|
|
|
77
77
|
pending.point
|
|
78
78
|
]);
|
|
79
79
|
const placed = (0, import_mobile_placement.useMobilePlacement)(ref, point, isMobile);
|
|
80
|
-
const textRef = (0, import_react.useRef)(text);
|
|
81
|
-
textRef.current = text;
|
|
82
80
|
(0, import_react.useEffect)(() => {
|
|
83
81
|
const el = ref.current;
|
|
84
82
|
if (!el) return;
|
|
85
83
|
const onKeyDown = (e) => {
|
|
86
84
|
if (e.key !== "Escape" || (0, import_mentions.isMentionPickerOpen)()) return;
|
|
87
85
|
e.stopPropagation();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
(0, import_comment_drafts.clearCommentDraft)(import_comment_drafts.NEW_COMMENT_DRAFT);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
86
|
+
setText(import_comment_extensions.EMPTY_COMMENT);
|
|
87
|
+
(0, import_comment_drafts.clearCommentDraft)(import_comment_drafts.NEW_COMMENT_DRAFT);
|
|
93
88
|
import_state.pendingComment.set(editor, null);
|
|
94
89
|
editor.getContainer().focus();
|
|
95
90
|
};
|
|
@@ -129,6 +124,7 @@ function PendingComposer({
|
|
|
129
124
|
setText(import_comment_extensions.EMPTY_COMMENT);
|
|
130
125
|
(0, import_comment_drafts.clearCommentDraft)(import_comment_drafts.NEW_COMMENT_DRAFT);
|
|
131
126
|
import_state.pendingComment.set(editor, null);
|
|
127
|
+
editor.getContainer().focus();
|
|
132
128
|
onPostComment?.(comment);
|
|
133
129
|
};
|
|
134
130
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.EditorPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -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 {\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 { commitCommentMutation } 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 = 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// 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkFK;AAlFL,sBAA4C;AAC5C,mBAMO;AACP,oBAYO;AACP,8BAAgC;AAChC,gCAA8C;AAC9C,yBAA2B;AAC3B,2BAAkF;AAClF,4BAKO;AACP,+BAAsC;AACtC,4BAAuC;AACvC,0BAAiD;AAEjD,8BAA0D;AAC1D,qBAAoD;AACpD,mBAA+B;AAC/B,0BAKO;AACP,yBAA+B;AAE/B,MAAM,eAAW,8BAAe;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/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAoE;AACnE,QAAM,EAAE,WAAW,QAAI,qCAAqB;AAC5C,QAAM,mBAAmB,WAAW;AACpC,QAAM,iBAAa,8BAAc,aAAa;AAC9C,QAAM,KAAK,gBAAgB,cAAc,aAAa,IAAI;AAC1D,QAAM,eAAW,+CAAsB;AACvC,QAAM,OAAO,aAAa,QAAQ,OAAO;AAEzC,QAAM,cACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MAET,GAAI,WAAW,CAAC,IAAI,KAAK;AAAA,MAE1B,sDAAC,iCACC,iDAAe,YAAY,aAAa,IAAI,MAAM,4CAAsB,KACxE,4CAAC,0BAAO,QAAQ,MAAM,8CAAwB,GAEhD;AAAA;AAAA,EACD;AAID,QAAM,CAAC,MAAM,OAAO,QAAI;AAAA,IACvB,UAAM,uCAAgB,uCAAiB,KAAK;AAAA,EAC7C;AACA,QAAM,UAAM,qBAAuB,IAAI;AACvC,QAAM,UAAM,8BAAe;AAE3B,+CAA0B,GAAG;AAE7B,QAAM,YAAQ,wBAAS,kBAAkB,MAAM,OAAO,eAAe,QAAQ,KAAK,GAAG;AAAA,IACpF;AAAA,IACA,QAAQ;AAAA,EACT,CAAC;AAGD,QAAM,aAAS,4CAAmB,KAAK,OAAO,QAAQ;
|
|
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 { commitCommentMutation } 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// Handle Escape before it reaches the editor's container so closing the composer doesn't\n\t// also cancel the comment tool.\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\tsetText(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\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 = 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// Removing the focused composer would leave Escape outside the editor's keyboard listener.\n\t\teditor.getContainer().focus()\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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkFK;AAlFL,sBAA4C;AAC5C,mBAMO;AACP,oBAYO;AACP,8BAAgC;AAChC,gCAA8C;AAC9C,yBAA2B;AAC3B,2BAAkF;AAClF,4BAKO;AACP,+BAAsC;AACtC,4BAAuC;AACvC,0BAAiD;AAEjD,8BAA0D;AAC1D,qBAAoD;AACpD,mBAA+B;AAC/B,0BAKO;AACP,yBAA+B;AAE/B,MAAM,eAAW,8BAAe;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/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAC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@ -291,8 +291,6 @@ const ThreadView = (0, import_react.memo)(function ThreadView2({
|
|
|
291
291
|
if ((0, import_comment_extensions.isCommentEmpty)(replyRef.current)) return;
|
|
292
292
|
setReply(import_comment_extensions.EMPTY_COMMENT);
|
|
293
293
|
(0, import_comment_drafts.clearCommentDraft)((0, import_comment_drafts.replyDraftSlot)(thread.id));
|
|
294
|
-
e.preventDefault();
|
|
295
|
-
e.stopPropagation();
|
|
296
294
|
};
|
|
297
295
|
win.addEventListener("keydown", onKeyDown, true);
|
|
298
296
|
return () => win.removeEventListener("keydown", onKeyDown, true);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/thread-view.tsx"],
|
|
4
|
-
"sourcesContent": ["import { type CommentAuthor, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport {\n\tcreateComment,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLComment,\n\tTLCommentThread,\n\tTldrawUiButton,\n\tTldrawUiButtonLabel,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tTLRichText,\n\tuseContainer,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CommentBody } from './comment-body'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\treplyDraftSlot,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport {\n\tcommitCommentMutation,\n\tdeleteComment,\n\tdeleteThread,\n\teditComment,\n\treopenThread,\n\tresolveThread,\n} from './comment-mutations'\nimport { CommentReactionPicker, CommentReactions } from './comment-reactions'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { type CommentingContext } from './context'\nimport { useThreadComments } from './hooks'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport {\n\ttype CommentingComponents,\n\tgetCanModifyComment,\n\tuseCanComment,\n\tuseCanModifyComment,\n\tuseCommentingOptions,\n} from './options'\nimport { openThreadId } from './state'\n\nconst messages = defineMessages({\n\tactionDelete: { id: 'action.delete', defaultMessage: 'Delete' },\n\tcommentsCopyLink: { id: 'comments.copy-link', defaultMessage: 'Copy link' },\n\tcommentsDelete: { id: 'comments.delete', defaultMessage: 'Delete thread' },\n\tcommentsClose: { id: 'comments.close', defaultMessage: 'Close' },\n\tcommentsEdit: { id: 'comments.edit', defaultMessage: 'Edit' },\n\tcommentsEditPlaceholder: {\n\t\tid: 'comments.edit-placeholder',\n\t\tdefaultMessage: 'Edit comment\u2026',\n\t},\n\tcommentsLinkCopied: { id: 'comments.link-copied', defaultMessage: 'Link copied' },\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsReopen: { id: 'comments.reopen', defaultMessage: 'Reopen' },\n\tcommentsReplyPlaceholder: { id: 'comments.reply-placeholder', defaultMessage: 'Reply\u2026' },\n\tcommentsResolve: { id: 'comments.resolve', defaultMessage: 'Resolve' },\n\tcommentsResolvedBy: { id: 'comments.resolved-by', defaultMessage: 'Resolved by {name}' },\n\tcommentsSave: { id: 'comments.save', defaultMessage: 'Save' },\n\tcommentsSeeLess: { id: 'comments.see-less', defaultMessage: 'See less' },\n\tcommentsSeeMore: { id: 'comments.see-more', defaultMessage: 'See more' },\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsThreadTitle: { id: 'comments.thread-title', defaultMessage: 'Comment' },\n\tcommentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * A comment body clamped to 10 lines (see `.tlui-cmt-collapsible--collapsed`), with a See more /\n * See less toggle when it's longer. Overflow is measured rather than estimated from the text, so it\n * holds for any body (including a host's `CommentBody` slot) and re-checks as the panel resizes.\n */\nfunction CollapsibleBody({ children }: { children: ReactNode }) {\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst [expanded, setExpanded] = useState(false)\n\tconst [overflows, setOverflows] = useState(false)\n\tuseLayoutEffect(() => {\n\t\tconst el = ref.current\n\t\t// Expanded, nothing is clipped to measure; keep the collapsed reading so See less stays.\n\t\tif (!el || expanded) return\n\t\tconst measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)\n\t\tmeasure()\n\t\tconst observer = new ResizeObserver(measure)\n\t\tobserver.observe(el)\n\t\tfor (const child of Array.from(el.children)) observer.observe(child)\n\t\treturn () => observer.disconnect()\n\t}, [expanded, children])\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={['tlui-cmt-collapsible', !expanded && 'tlui-cmt-collapsible--collapsed']\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{overflows && (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"tlui-cmt-see-more\"\n\t\t\t\t\taria-expanded={expanded}\n\t\t\t\t\tonClick={() => setExpanded((v) => !v)}\n\t\t\t\t>\n\t\t\t\t\t{msg(expanded ? messages.commentsSeeLess : messages.commentsSeeMore)}\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\n/** The \"\u22EF\" dropdown used for both a comment's and the thread's actions. */\nfunction MoreOptionsMenu({\n\tid,\n\tmoreFor,\n\tchildren,\n}: {\n\tid: string\n\t/** The comment whose \u22EF button this is, so `startEdit` can find it again to return focus. */\n\tmoreFor?: string\n\tchildren: ReactNode\n}) {\n\tconst msg = useTranslation()\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id={id}>\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsMoreOptions)}\n\t\t\t\t\ttitle={msg(messages.commentsMoreOptions)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tdata-cmt-more-for={moreFor}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"dots-vertical\" label={msg(messages.commentsMoreOptions)} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={-6} sideOffset={0}>\n\t\t\t\t{children}\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n\nfunction MenuItem({\n\tlabel,\n\tnoClose,\n\tonClick,\n}: {\n\tlabel: string\n\tnoClose?: boolean\n\tonClick(): void\n}) {\n\treturn (\n\t\t<TldrawUiDropdownMenuItem noClose={noClose}>\n\t\t\t<TldrawUiButton type=\"menu\" onClick={onClick}>\n\t\t\t\t<TldrawUiButtonLabel>{label}</TldrawUiButtonLabel>\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiDropdownMenuItem>\n\t)\n}\n\n/**\n * A name-only view of an author resolver, for the mention/rich-text paths. Stable identity, so\n * `CommentBody`'s memoized render doesn't recompute on every render of its host.\n */\nexport function useResolveName(resolveAuthor: CommentingContext['resolveAuthor']) {\n\treturn useCallback((id: string) => resolveAuthor(id)?.name, [resolveAuthor])\n}\n\n/** How long the copy-link item reads \"Link copied\" before reverting. */\nconst LINK_COPIED_MS = 2000\n\n/**\n * What a thread's `getThreadHref` should put on the clipboard. Hosts may hand back a relative href,\n * which is meaningless once pasted elsewhere, so it's resolved against the current document first.\n * An href the URL parser can't make sense of is copied as-is rather than dropped.\n *\n * @internal\n */\nexport function absoluteThreadLink(href: string, base = window.location.href): string {\n\ttry {\n\t\treturn new URL(href, base).toString()\n\t} catch {\n\t\treturn href\n\t}\n}\n\n/**\n * Copy a thread's link, with a flag that stays set briefly afterwards so the control can confirm.\n * Only set once the write resolves, so a withheld clipboard doesn't claim a copy that didn't happen.\n */\nfunction useCopyLink(href: string | undefined) {\n\tconst [copied, setCopied] = useState(false)\n\tuseEffect(() => {\n\t\tif (!copied) return\n\t\tconst timeout = window.setTimeout(() => setCopied(false), LINK_COPIED_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [copied])\n\tconst copy = useCallback(() => {\n\t\tif (href === undefined) return\n\t\tnavigator.clipboard?.writeText(absoluteThreadLink(href)).then(\n\t\t\t() => setCopied(true),\n\t\t\t() => setCopied(false)\n\t\t)\n\t}, [href])\n\treturn [copied, copy] as const\n}\n\n/**\n * The `Avatar` component slot as a `renderAvatar` callback for the presentational components, bound\n * to the id the avatar stands for. Undefined without an override, so they draw their own default.\n */\nexport function avatarRenderer(\n\tcomponents: CommentingComponents,\n\tauthorId: string | null\n): ((author: CommentAuthor) => ReactNode) | undefined {\n\tconst Avatar = components.Avatar\n\tif (!Avatar) return undefined\n\treturn (author) => <Avatar author={author} authorId={authorId} />\n}\n\nexport function toCardProps(\n\tcomment: TLComment,\n\tprops: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'>,\n\tcomponents: CommentingComponents,\n\tresolveName: (id: string) => string | undefined\n): CommentCardProps {\n\tconst Body = components.CommentBody\n\t// The `CommentBody` component slot overrides the built-in rich-text default (which resolves\n\t// mention ids to names).\n\tconst body = Body ? (\n\t\t<Body comment={comment} />\n\t) : (\n\t\t<CommentBody richText={comment.body} resolveName={resolveName} />\n\t)\n\tconst author = props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR\n\tconst date = new Date(comment.createdAt).toISOString()\n\tconst edited = comment.editedAt != null\n\tconst renderAvatar = avatarRenderer(components, comment.authorId)\n\tconst Byline = components.CommentByline\n\treturn {\n\t\tauthor,\n\t\tbody,\n\t\tdate,\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited,\n\t\trenderAvatar,\n\t\tbyline: Byline ? (\n\t\t\t<Byline\n\t\t\t\tauthor={author}\n\t\t\t\tdate={date}\n\t\t\t\tedited={edited}\n\t\t\t\trenderAvatar={renderAvatar}\n\t\t\t\tcomment={comment}\n\t\t\t/>\n\t\t) : undefined,\n\t}\n}\n\n/** A pin is this square (mirrors `--tlui-cmt-pin-size`). The two marker kinds differ in size *and*\n * anchor point, so lining their previews up means correcting for both. Keep in sync with the CSS. */\nconst PIN_SIZE = 28\n\n/** A cluster/stack badge is this square (`--tlui-cmt-marker-size`) \u2014 pin-sized, so the marker\n * kinds read as one family. Keep in sync with the stylesheet. */\nconst MARKER_SIZE = PIN_SIZE\n\n/** Where a popover's top card sits vertically, measured from the marker visual's middle. */\nconst CARD_TOP_Y = -28\n\n/** The horizontal gap between a marker visual's right edge and its popover/preview panel. The\n * preview's hover bridge spans exactly this (see `--tlui-cmt-preview-bridge`). */\nconst PREVIEW_GAP = 6\n\n/**\n * Where a marker's popover sits relative to the marker's anchor point. The hover preview uses the\n * same origins, so moving a popover here moves its preview with it.\n *\n * Both marker kinds hang off their point the same way (`translate(0, -100%)`), differing only in\n * size \u2014 so each offset clears its own width plus the shared gap, and re-bases the shared card-top\n * measure from its bottom anchor to its middle.\n */\nexport const POPOVER_OFFSET = {\n\tthread: { x: PIN_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - PIN_SIZE / 2 },\n\tlist: { x: MARKER_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - MARKER_SIZE / 2 },\n} as const\n\n/** The open thread's popover container, portaled above the UI panels. A wheel over it passes\n * through to the canvas (unless it scrolls its own content), like tldraw's panels. */\nexport function ThreadPopover({\n\tbase,\n\tchildren,\n}: {\n\tbase: { x: number; y: number }\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\t// On mobile the popover slides off its fixed offset to stay above the software keyboard and\n\t// on-screen; desktop keeps the fixed offset (base returned unchanged).\n\tconst isMobile = useIsMobileCommenting()\n\tconst placed = useMobilePlacement(ref, base, isMobile)\n\treturn (\n\t\t<EditorPortal>\n\t\t\t{/* contextmenu also stops here: portals bubble React events to the canvas's context-menu\n\t\t\t trigger (the layer mounts inside it), which would open the canvas menu over this panel. */}\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName=\"tlui-cmt-canvas-popover\"\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{children}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n\n/**\n * One thread's interactive view: its comments, the reply composer, edit-in-place on your own\n * comments, and the resolve/delete actions. Read receipts are reported for every unread comment\n * while mounted, so only mount it where the thread is actually being shown.\n *\n * Memoized because the popover position rides the pin's per-frame render point, so the pin\n * re-renders on every camera frame while a thread is open.\n */\nexport const ThreadView = memo(function ThreadView({\n\teditor,\n\tthread,\n\t...props\n}: CommentingContext & { editor: Editor; thread: TLCommentThread }) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveAuthor,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentsRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t\tgetThreadHref,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\tconst resolveName = useResolveName(resolveAuthor)\n\t// Rebuilt only when the comments change, not on every render \u2014 each of which would otherwise\n\t// re-allocate a date string and body element per comment.\n\tconst cards = useMemo(\n\t\t() =>\n\t\t\tcomments.map((c) => {\n\t\t\t\tconst card = toCardProps(\n\t\t\t\t\tc,\n\t\t\t\t\t{ currentUserId, resolveAuthor },\n\t\t\t\t\toptions.components,\n\t\t\t\t\tresolveName\n\t\t\t\t)\n\t\t\t\treturn { ...card, body: <CollapsibleBody>{card.body}</CollapsibleBody> }\n\t\t\t}),\n\t\t[comments, currentUserId, resolveAuthor, options.components, resolveName]\n\t)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// Composing, editing, deleting, and resolving are all gated on the viewer's permission. Where it's\n\t// withheld the composer gives way to the ComposerFallback slot and the affordances are hidden.\n\tconst canComment = useCanComment(currentUserId)\n\t// Editing and deleting are further per-record: the author's to do by default, wider or narrower\n\t// under a `canModifyComment` callback. Computed for the thread's comments in one pass, since\n\t// `renderComment` is a callback rather than a component and can't call a hook per comment.\n\tconst commentPermissions = useValue(\n\t\t'comment permissions',\n\t\t() =>\n\t\t\tnew Map(\n\t\t\t\tcomments.map((comment) => [\n\t\t\t\t\tcomment.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tedit: getCanModifyComment(editor, currentUserId, { action: 'edit-comment', comment }),\n\t\t\t\t\t\tdelete: getCanModifyComment(editor, currentUserId, {\n\t\t\t\t\t\t\taction: 'delete-comment',\n\t\t\t\t\t\t\tcomment,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t),\n\t\t[editor, currentUserId, comments]\n\t)\n\t// Deleting a thread is its creator's by default (and server-enforced); `canModifyComment` is what\n\t// widens that. Still a commenting write, so `canComment` stays the outer gate.\n\tconst canModifyThread = useCanModifyComment(currentUserId, { action: 'delete-thread', thread })\n\tconst canDeleteThread = canComment && canModifyThread\n\tconst ComposerFallback = options.components.ComposerFallback\n\t// An unsent reply survives closing the thread (saved on every change, keyed by thread id) \u2014\n\t// the flip side of dismissing without a discard warning.\n\tconst [reply, setReply] = useState<TLRichText>(\n\t\t() => getCommentDraft(replyDraftSlot(thread.id)) ?? EMPTY_COMMENT\n\t)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst canReply = canComment && !thread.resolved\n\tconst container = useContainer()\n\n\t// Escape in a reply box with text clears the text and keeps the thread open; an empty one falls\n\t// through to the layer's Escape, which closes the thread. On the window, in the capture phase,\n\t// so it runs ahead of that document-level handler.\n\tconst replyRef = useRef(reply)\n\treplyRef.current = reply\n\tuseEffect(() => {\n\t\tconst win = container.ownerDocument.defaultView\n\t\tif (!win) return\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return\n\t\t\tif (target.closest('.tlui-cmt-editing')) return\n\t\t\tif (isCommentEmpty(replyRef.current)) return\n\t\t\tsetReply(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(replyDraftSlot(thread.id))\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\twin.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => win.removeEventListener('keydown', onKeyDown, true)\n\t}, [container, thread.id])\n\t// Resolved when the composer closes rather than held as an element: the card unmounts while the\n\t// composer stands in its place, so the node captured on the way in is gone by the way out.\n\tconst editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)\n\t// Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a\n\t// click on Save. See the focus hand-back below.\n\tconst editEndedByKeyboard = useRef(false)\n\n\t// Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor\n\t// container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.\n\tconst [focusReply, setFocusReply] = useState(false)\n\tconst tabTaken = useRef(false)\n\tconst swallowTabUp = useRef(false)\n\tuseEffect(() => {\n\t\tif (!canReply) {\n\t\t\t// Resolving unmounts the reply box under an open thread. Reopening it should feel like a\n\t\t\t// freshly opened thread: no autoFocus left armed from the last Tab, and Tab available again.\n\t\t\tsetFocusReply(false)\n\t\t\ttabTaken.current = false\n\t\t\treturn\n\t\t}\n\t\tconst doc = container.ownerDocument\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tif (e.defaultPrevented || tabTaken.current) return\n\t\t\t// Focus rests on the container (or nothing) after a pin click. Anywhere else is deliberate, and\n\t\t\t// Tab belongs to whatever holds it.\n\t\t\tif (e.target !== container && e.target !== doc.body) return\n\t\t\ttabTaken.current = true\n\t\t\tswallowTabUp.current = true\n\t\t\tsetFocusReply(true)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\t// The select tool navigates shapes on Tab's *keyup*, so a quick tap would both focus the reply and\n\t\t// step the selection. Swallow the release of the press we took, and only that one.\n\t\tconst onKeyUp = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || !swallowTabUp.current) return\n\t\t\tswallowTabUp.current = false\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdoc.addEventListener('keydown', onKeyDown, true)\n\t\tdoc.addEventListener('keyup', onKeyUp, true)\n\t\treturn () => {\n\t\t\tdoc.removeEventListener('keydown', onKeyDown, true)\n\t\t\tdoc.removeEventListener('keyup', onKeyUp, true)\n\t\t}\n\t}, [canReply, container])\n\n\t// Leaving the edit composer unmounts it while it holds focus, dropping focus to the editor\n\t// container \u2014 outside the thread, so a Tab from there walks the app's UI. Hand focus back to\n\t// whatever opened the composer instead.\n\tuseEffect(() => {\n\t\tif (editingId !== null) return\n\t\tconst resolve = editReturnFocus.current\n\t\teditReturnFocus.current = null\n\t\t// Runs after React has swapped the card back in, so the target is mounted again by now. Shown\n\t\t// as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after\n\t\t// a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a\n\t\t// keyboard user would otherwise be left on an invisible \u22EF button with no ring.\n\t\tresolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })\n\t\teditEndedByKeyboard.current = false\n\t}, [editingId])\n\n\t// Reported as one batch so the host can record the receipts in a single write. The write flips\n\t// isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!isCommentUnread || !onCommentsRead) return\n\t\tconst unreadIds = comments.filter((comment) => isCommentUnread(comment.id)).map((c) => c.id)\n\t\tif (unreadIds.length > 0) {\n\t\t\tonCommentsRead(unreadIds)\n\t\t}\n\t}, [comments, isCommentUnread, onCommentsRead])\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tconst comment = commitCommentMutation(editor, ({ put }) => {\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId: thread.pageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: reply,\n\t\t\t})\n\t\t\tput([comment])\n\t\t\treturn comment\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t\tclearCommentDraft(replyDraftSlot(thread.id))\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 reply.\n\t\tonPostComment?.(comment)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tif (thread.resolved) reopenThread(editor, thread)\n\t\telse resolveThread(editor, thread, currentUserId)\n\t}\n\n\t// No `currentUserId` check: unlike a resolve, a delete stamps nothing on the record, so who may\n\t// make it is `canModifyComment`'s call alone (which withholds it from an unidentified viewer by\n\t// default).\n\tconst removeThread = () => deleteThread(editor, thread)\n\n\tconst ThreadActions = options.components.ThreadActions\n\t// The host's URL for this thread. Its presence is what puts \"copy link\" in the header menu.\n\tconst threadHref = getThreadHref?.(thread.id)\n\tconst [linkCopied, copyThreadLink] = useCopyLink(threadHref)\n\n\tconst startEdit = (comment: TLComment, { fromMoreMenu = false } = {}) => {\n\t\t// Edit from the \u22EF menu comes back to that button, looked up again on the way out since the card\n\t\t// unmounts. Otherwise return to whatever held focus, ignoring the body and the editor container.\n\t\tconst active = container.ownerDocument.activeElement\n\t\teditReturnFocus.current = fromMoreMenu\n\t\t\t? () => container.querySelector<HTMLElement>(`[data-cmt-more-for=\"${comment.id}\"]`)\n\t\t\t: active instanceof HTMLElement && active !== container && active !== document.body\n\t\t\t\t? () => (active.isConnected ? active : null)\n\t\t\t\t: null\n\t\tsetEditingId(comment.id)\n\t\tsetEditText(comment.body)\n\t}\n\n\tconst saveEdit = () => {\n\t\tconst comment = comments.find((c) => c.id === editingId)\n\t\tif (!comment || isCommentEmpty(editText)) return\n\t\teditComment(editor, comment, editText)\n\t\tsetEditingId(null)\n\t}\n\n\t// Swap a comment for a pre-filled composer while it's being edited; otherwise show the card,\n\t// with the affordances the viewer is allowed on it.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\n\t\tconst permissions = commentPermissions.get(comment.id)\n\t\tif (editingId === comment.id) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"tlui-cmt-editing\"\n\t\t\t\t\tonPointerDown={() => {\n\t\t\t\t\t\teditEndedByKeyboard.current = false\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={(e) => {\n\t\t\t\t\t\teditEndedByKeyboard.current = true\n\t\t\t\t\t\tif (e.key === 'Escape') {\n\t\t\t\t\t\t\tsetEditingId(null)\n\t\t\t\t\t\t\te.stopPropagation()\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={card.author}\n\t\t\t\t\t\tleading={card.renderAvatar?.(card.author)}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsEditPlaceholder)}\n\t\t\t\t\t\tvalue={editText}\n\t\t\t\t\t\tonChange={setEditText}\n\t\t\t\t\t\tonSubmit={saveEdit}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSave)}\n\t\t\t\t\t\tdisabled={isCommentEmpty(editText)}\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/>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\treturn (\n\t\t\t<CommentCard\n\t\t\t\t{...card}\n\t\t\t\tfooter={\n\t\t\t\t\t<CommentReactions\n\t\t\t\t\t\tcomment={comment}\n\t\t\t\t\t\t// Reacting is a commenting write: without `canComment` the tally renders\n\t\t\t\t\t\t// read-only (no identity \u2192 pills aren't clickable).\n\t\t\t\t\t\tcurrentUserId={canComment ? currentUserId : null}\n\t\t\t\t\t\tresolveName={resolveName}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\tcanComment && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<CommentReactionPicker comment={comment} currentUserId={currentUserId} />\n\t\t\t\t\t\t\t{(permissions?.edit || permissions?.delete) && (\n\t\t\t\t\t\t\t\t<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>\n\t\t\t\t\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t\t\t{permissions?.edit && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.commentsEdit)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => startEdit(comment, { fromMoreMenu: true })}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t{permissions?.delete && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.actionDelete)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => deleteComment(editor, comment)}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t</MoreOptionsMenu>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\t// Resolve and delete are commenting writes: behind `canComment`, plus the `currentUserId` a\n\t// resolve stamps into `resolved.by`.\n\tconst resolveLabel = msg(thread.resolved ? messages.commentsReopen : messages.commentsResolve)\n\tconst headerActions = (\n\t\t<>\n\t\t\t{/* Host verbs \u2014 assign, link a ticket \u2014 sit ahead of the built-in actions. */}\n\t\t\t{ThreadActions && <ThreadActions thread={thread} comments={comments} />}\n\t\t\t{canComment && currentUserId && (\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={resolveLabel}\n\t\t\t\t\ttitle={resolveLabel}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"check\" label={resolveLabel} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t)}\n\t\t\t<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>\n\t\t\t\t{(threadHref !== undefined || canDeleteThread) && (\n\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t{/* A link is a read affordance: offered to anyone who can see the thread,\n\t\t\t\t\t\t including a viewer who can't comment. `noClose` keeps the menu up so the\n\t\t\t\t\t\t item can confirm the copy in place. */}\n\t\t\t\t\t\t{threadHref !== undefined && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tlabel={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}\n\t\t\t\t\t\t\t\tnoClose\n\t\t\t\t\t\t\t\tonClick={copyThreadLink}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{canDeleteThread && (\n\t\t\t\t\t\t\t<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tlabel={msg(messages.commentsClose)}\n\t\t\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t\t\t/>\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t</MoreOptionsMenu>\n\t\t</>\n\t)\n\n\treturn (\n\t\t<CommentThread\n\t\t\theader={msg(messages.commentsThreadTitle)}\n\t\t\theaderActions={headerActions}\n\t\t\trenderComment={renderComment}\n\t\t\tcomments={cards}\n\t\t\tresolvedBanner={\n\t\t\t\tthread.resolved\n\t\t\t\t\t? msg(messages.commentsResolvedBy, {\n\t\t\t\t\t\t\tname: resolveAuthor(thread.resolved.by)?.name ?? msg(messages.commentsUnknownAuthor),\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tcomposer={\n\t\t\t\tcanReply\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tauthor: me ?? UNKNOWN_COMMENT_AUTHOR,\n\t\t\t\t\t\t\tleading: avatarRenderer(\n\t\t\t\t\t\t\t\toptions.components,\n\t\t\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t\t\t)?.(me ?? UNKNOWN_COMMENT_AUTHOR),\n\t\t\t\t\t\t\tplaceholder: msg(messages.commentsReplyPlaceholder),\n\t\t\t\t\t\t\tsendLabel: msg(messages.commentsSend),\n\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\tonChange: (value: TLRichText) => {\n\t\t\t\t\t\t\t\tsetReply(value)\n\t\t\t\t\t\t\t\tsaveCommentDraft(replyDraftSlot(thread.id), value)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t// Up in the empty reply box edits the comment directly above it, chat-style \u2014\n\t\t\t\t\t\t\t// only when you're allowed to edit it (the same gate as the Edit link).\n\t\t\t\t\t\t\tonArrowUpWhenEmpty: () => {\n\t\t\t\t\t\t\t\tconst last = comments[comments.length - 1]\n\t\t\t\t\t\t\t\tif (last && commentPermissions.get(last.id)?.edit) startEdit(last)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply) || !currentUserId,\n\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t// Reuses the composer's own focus path, so the caret lands at the end of a\n\t\t\t\t\t\t\t// restored draft rather than in front of it.\n\t\t\t\t\t\t\tautoFocus: focusReply,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tfooter={\n\t\t\t\t!canComment && !thread.resolved && ComposerFallback ? (\n\t\t\t\t\t<ComposerFallback context=\"thread\" />\n\t\t\t\t) : undefined\n\t\t\t}\n\t\t/>\n\t)\n})\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiHE;AAjHF,sBAAwD;AACxD,mBASO;AACP,oBAoBO;AACP,0BAA8C;AAC9C,8BAAgC;AAChC,gCAA8C;AAC9C,4BAA8B;AAC9B,0BAA4B;AAC5B,4BAKO;AACP,+BAOO;AACP,+BAAwD;AACxD,4BAAuC;AAEvC,mBAAkC;AAClC,8BAA0D;AAC1D,qBAMO;AACP,mBAA6B;AAE7B,MAAM,eAAW,8BAAe;AAAA,EAC/B,cAAc,EAAE,IAAI,iBAAiB,gBAAgB,SAAS;AAAA,EAC9D,kBAAkB,EAAE,IAAI,sBAAsB,gBAAgB,YAAY;AAAA,EAC1E,gBA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Ae,OAAO,EAAE,GAAG,KAAK;AAAA,QAClD;AAAA,QACA,UAAU;AAAA;AAAA;AAAA,QAGV,oBAAoB,MAAM;AACzB,gBAAM,OAAO,SAAS,SAAS,SAAS,CAAC;AACzC,cAAI,QAAQ,mBAAmB,IAAI,KAAK,EAAE,GAAG,KAAM,WAAU,IAAI;AAAA,QAClE;AAAA;AAAA,QAEA,cAAU,0CAAe,KAAK,KAAK,CAAC;AAAA,QACpC;AAAA,QACA;AAAA;AAAA;AAAA,QAGA,WAAW;AAAA,MACZ,IACC;AAAA,MAEJ,QACC,CAAC,cAAc,CAAC,OAAO,YAAY,mBAClC,4CAAC,oBAAiB,SAAQ,UAAS,IAChC;AAAA;AAAA,EAEN;AAEF,CAAC;",
|
|
4
|
+
"sourcesContent": ["import { type CommentAuthor, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport {\n\tcreateComment,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLComment,\n\tTLCommentThread,\n\tTldrawUiButton,\n\tTldrawUiButtonLabel,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tTLRichText,\n\tuseContainer,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CommentBody } from './comment-body'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\treplyDraftSlot,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport {\n\tcommitCommentMutation,\n\tdeleteComment,\n\tdeleteThread,\n\teditComment,\n\treopenThread,\n\tresolveThread,\n} from './comment-mutations'\nimport { CommentReactionPicker, CommentReactions } from './comment-reactions'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { type CommentingContext } from './context'\nimport { useThreadComments } from './hooks'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport {\n\ttype CommentingComponents,\n\tgetCanModifyComment,\n\tuseCanComment,\n\tuseCanModifyComment,\n\tuseCommentingOptions,\n} from './options'\nimport { openThreadId } from './state'\n\nconst messages = defineMessages({\n\tactionDelete: { id: 'action.delete', defaultMessage: 'Delete' },\n\tcommentsCopyLink: { id: 'comments.copy-link', defaultMessage: 'Copy link' },\n\tcommentsDelete: { id: 'comments.delete', defaultMessage: 'Delete thread' },\n\tcommentsClose: { id: 'comments.close', defaultMessage: 'Close' },\n\tcommentsEdit: { id: 'comments.edit', defaultMessage: 'Edit' },\n\tcommentsEditPlaceholder: {\n\t\tid: 'comments.edit-placeholder',\n\t\tdefaultMessage: 'Edit comment\u2026',\n\t},\n\tcommentsLinkCopied: { id: 'comments.link-copied', defaultMessage: 'Link copied' },\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsReopen: { id: 'comments.reopen', defaultMessage: 'Reopen' },\n\tcommentsReplyPlaceholder: { id: 'comments.reply-placeholder', defaultMessage: 'Reply\u2026' },\n\tcommentsResolve: { id: 'comments.resolve', defaultMessage: 'Resolve' },\n\tcommentsResolvedBy: { id: 'comments.resolved-by', defaultMessage: 'Resolved by {name}' },\n\tcommentsSave: { id: 'comments.save', defaultMessage: 'Save' },\n\tcommentsSeeLess: { id: 'comments.see-less', defaultMessage: 'See less' },\n\tcommentsSeeMore: { id: 'comments.see-more', defaultMessage: 'See more' },\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsThreadTitle: { id: 'comments.thread-title', defaultMessage: 'Comment' },\n\tcommentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * A comment body clamped to 10 lines (see `.tlui-cmt-collapsible--collapsed`), with a See more /\n * See less toggle when it's longer. Overflow is measured rather than estimated from the text, so it\n * holds for any body (including a host's `CommentBody` slot) and re-checks as the panel resizes.\n */\nfunction CollapsibleBody({ children }: { children: ReactNode }) {\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst [expanded, setExpanded] = useState(false)\n\tconst [overflows, setOverflows] = useState(false)\n\tuseLayoutEffect(() => {\n\t\tconst el = ref.current\n\t\t// Expanded, nothing is clipped to measure; keep the collapsed reading so See less stays.\n\t\tif (!el || expanded) return\n\t\tconst measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)\n\t\tmeasure()\n\t\tconst observer = new ResizeObserver(measure)\n\t\tobserver.observe(el)\n\t\tfor (const child of Array.from(el.children)) observer.observe(child)\n\t\treturn () => observer.disconnect()\n\t}, [expanded, children])\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={['tlui-cmt-collapsible', !expanded && 'tlui-cmt-collapsible--collapsed']\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{overflows && (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"tlui-cmt-see-more\"\n\t\t\t\t\taria-expanded={expanded}\n\t\t\t\t\tonClick={() => setExpanded((v) => !v)}\n\t\t\t\t>\n\t\t\t\t\t{msg(expanded ? messages.commentsSeeLess : messages.commentsSeeMore)}\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\n/** The \"\u22EF\" dropdown used for both a comment's and the thread's actions. */\nfunction MoreOptionsMenu({\n\tid,\n\tmoreFor,\n\tchildren,\n}: {\n\tid: string\n\t/** The comment whose \u22EF button this is, so `startEdit` can find it again to return focus. */\n\tmoreFor?: string\n\tchildren: ReactNode\n}) {\n\tconst msg = useTranslation()\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id={id}>\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsMoreOptions)}\n\t\t\t\t\ttitle={msg(messages.commentsMoreOptions)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tdata-cmt-more-for={moreFor}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"dots-vertical\" label={msg(messages.commentsMoreOptions)} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={-6} sideOffset={0}>\n\t\t\t\t{children}\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n\nfunction MenuItem({\n\tlabel,\n\tnoClose,\n\tonClick,\n}: {\n\tlabel: string\n\tnoClose?: boolean\n\tonClick(): void\n}) {\n\treturn (\n\t\t<TldrawUiDropdownMenuItem noClose={noClose}>\n\t\t\t<TldrawUiButton type=\"menu\" onClick={onClick}>\n\t\t\t\t<TldrawUiButtonLabel>{label}</TldrawUiButtonLabel>\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiDropdownMenuItem>\n\t)\n}\n\n/**\n * A name-only view of an author resolver, for the mention/rich-text paths. Stable identity, so\n * `CommentBody`'s memoized render doesn't recompute on every render of its host.\n */\nexport function useResolveName(resolveAuthor: CommentingContext['resolveAuthor']) {\n\treturn useCallback((id: string) => resolveAuthor(id)?.name, [resolveAuthor])\n}\n\n/** How long the copy-link item reads \"Link copied\" before reverting. */\nconst LINK_COPIED_MS = 2000\n\n/**\n * What a thread's `getThreadHref` should put on the clipboard. Hosts may hand back a relative href,\n * which is meaningless once pasted elsewhere, so it's resolved against the current document first.\n * An href the URL parser can't make sense of is copied as-is rather than dropped.\n *\n * @internal\n */\nexport function absoluteThreadLink(href: string, base = window.location.href): string {\n\ttry {\n\t\treturn new URL(href, base).toString()\n\t} catch {\n\t\treturn href\n\t}\n}\n\n/**\n * Copy a thread's link, with a flag that stays set briefly afterwards so the control can confirm.\n * Only set once the write resolves, so a withheld clipboard doesn't claim a copy that didn't happen.\n */\nfunction useCopyLink(href: string | undefined) {\n\tconst [copied, setCopied] = useState(false)\n\tuseEffect(() => {\n\t\tif (!copied) return\n\t\tconst timeout = window.setTimeout(() => setCopied(false), LINK_COPIED_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [copied])\n\tconst copy = useCallback(() => {\n\t\tif (href === undefined) return\n\t\tnavigator.clipboard?.writeText(absoluteThreadLink(href)).then(\n\t\t\t() => setCopied(true),\n\t\t\t() => setCopied(false)\n\t\t)\n\t}, [href])\n\treturn [copied, copy] as const\n}\n\n/**\n * The `Avatar` component slot as a `renderAvatar` callback for the presentational components, bound\n * to the id the avatar stands for. Undefined without an override, so they draw their own default.\n */\nexport function avatarRenderer(\n\tcomponents: CommentingComponents,\n\tauthorId: string | null\n): ((author: CommentAuthor) => ReactNode) | undefined {\n\tconst Avatar = components.Avatar\n\tif (!Avatar) return undefined\n\treturn (author) => <Avatar author={author} authorId={authorId} />\n}\n\nexport function toCardProps(\n\tcomment: TLComment,\n\tprops: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'>,\n\tcomponents: CommentingComponents,\n\tresolveName: (id: string) => string | undefined\n): CommentCardProps {\n\tconst Body = components.CommentBody\n\t// The `CommentBody` component slot overrides the built-in rich-text default (which resolves\n\t// mention ids to names).\n\tconst body = Body ? (\n\t\t<Body comment={comment} />\n\t) : (\n\t\t<CommentBody richText={comment.body} resolveName={resolveName} />\n\t)\n\tconst author = props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR\n\tconst date = new Date(comment.createdAt).toISOString()\n\tconst edited = comment.editedAt != null\n\tconst renderAvatar = avatarRenderer(components, comment.authorId)\n\tconst Byline = components.CommentByline\n\treturn {\n\t\tauthor,\n\t\tbody,\n\t\tdate,\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited,\n\t\trenderAvatar,\n\t\tbyline: Byline ? (\n\t\t\t<Byline\n\t\t\t\tauthor={author}\n\t\t\t\tdate={date}\n\t\t\t\tedited={edited}\n\t\t\t\trenderAvatar={renderAvatar}\n\t\t\t\tcomment={comment}\n\t\t\t/>\n\t\t) : undefined,\n\t}\n}\n\n/** A pin is this square (mirrors `--tlui-cmt-pin-size`). The two marker kinds differ in size *and*\n * anchor point, so lining their previews up means correcting for both. Keep in sync with the CSS. */\nconst PIN_SIZE = 28\n\n/** A cluster/stack badge is this square (`--tlui-cmt-marker-size`) \u2014 pin-sized, so the marker\n * kinds read as one family. Keep in sync with the stylesheet. */\nconst MARKER_SIZE = PIN_SIZE\n\n/** Where a popover's top card sits vertically, measured from the marker visual's middle. */\nconst CARD_TOP_Y = -28\n\n/** The horizontal gap between a marker visual's right edge and its popover/preview panel. The\n * preview's hover bridge spans exactly this (see `--tlui-cmt-preview-bridge`). */\nconst PREVIEW_GAP = 6\n\n/**\n * Where a marker's popover sits relative to the marker's anchor point. The hover preview uses the\n * same origins, so moving a popover here moves its preview with it.\n *\n * Both marker kinds hang off their point the same way (`translate(0, -100%)`), differing only in\n * size \u2014 so each offset clears its own width plus the shared gap, and re-bases the shared card-top\n * measure from its bottom anchor to its middle.\n */\nexport const POPOVER_OFFSET = {\n\tthread: { x: PIN_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - PIN_SIZE / 2 },\n\tlist: { x: MARKER_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - MARKER_SIZE / 2 },\n} as const\n\n/** The open thread's popover container, portaled above the UI panels. A wheel over it passes\n * through to the canvas (unless it scrolls its own content), like tldraw's panels. */\nexport function ThreadPopover({\n\tbase,\n\tchildren,\n}: {\n\tbase: { x: number; y: number }\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\t// On mobile the popover slides off its fixed offset to stay above the software keyboard and\n\t// on-screen; desktop keeps the fixed offset (base returned unchanged).\n\tconst isMobile = useIsMobileCommenting()\n\tconst placed = useMobilePlacement(ref, base, isMobile)\n\treturn (\n\t\t<EditorPortal>\n\t\t\t{/* contextmenu also stops here: portals bubble React events to the canvas's context-menu\n\t\t\t trigger (the layer mounts inside it), which would open the canvas menu over this panel. */}\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName=\"tlui-cmt-canvas-popover\"\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{children}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n\n/**\n * One thread's interactive view: its comments, the reply composer, edit-in-place on your own\n * comments, and the resolve/delete actions. Read receipts are reported for every unread comment\n * while mounted, so only mount it where the thread is actually being shown.\n *\n * Memoized because the popover position rides the pin's per-frame render point, so the pin\n * re-renders on every camera frame while a thread is open.\n */\nexport const ThreadView = memo(function ThreadView({\n\teditor,\n\tthread,\n\t...props\n}: CommentingContext & { editor: Editor; thread: TLCommentThread }) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveAuthor,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentsRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t\tgetThreadHref,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\tconst resolveName = useResolveName(resolveAuthor)\n\t// Rebuilt only when the comments change, not on every render \u2014 each of which would otherwise\n\t// re-allocate a date string and body element per comment.\n\tconst cards = useMemo(\n\t\t() =>\n\t\t\tcomments.map((c) => {\n\t\t\t\tconst card = toCardProps(\n\t\t\t\t\tc,\n\t\t\t\t\t{ currentUserId, resolveAuthor },\n\t\t\t\t\toptions.components,\n\t\t\t\t\tresolveName\n\t\t\t\t)\n\t\t\t\treturn { ...card, body: <CollapsibleBody>{card.body}</CollapsibleBody> }\n\t\t\t}),\n\t\t[comments, currentUserId, resolveAuthor, options.components, resolveName]\n\t)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// Composing, editing, deleting, and resolving are all gated on the viewer's permission. Where it's\n\t// withheld the composer gives way to the ComposerFallback slot and the affordances are hidden.\n\tconst canComment = useCanComment(currentUserId)\n\t// Editing and deleting are further per-record: the author's to do by default, wider or narrower\n\t// under a `canModifyComment` callback. Computed for the thread's comments in one pass, since\n\t// `renderComment` is a callback rather than a component and can't call a hook per comment.\n\tconst commentPermissions = useValue(\n\t\t'comment permissions',\n\t\t() =>\n\t\t\tnew Map(\n\t\t\t\tcomments.map((comment) => [\n\t\t\t\t\tcomment.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tedit: getCanModifyComment(editor, currentUserId, { action: 'edit-comment', comment }),\n\t\t\t\t\t\tdelete: getCanModifyComment(editor, currentUserId, {\n\t\t\t\t\t\t\taction: 'delete-comment',\n\t\t\t\t\t\t\tcomment,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t),\n\t\t[editor, currentUserId, comments]\n\t)\n\t// Deleting a thread is its creator's by default (and server-enforced); `canModifyComment` is what\n\t// widens that. Still a commenting write, so `canComment` stays the outer gate.\n\tconst canModifyThread = useCanModifyComment(currentUserId, { action: 'delete-thread', thread })\n\tconst canDeleteThread = canComment && canModifyThread\n\tconst ComposerFallback = options.components.ComposerFallback\n\t// An unsent reply survives closing the thread (saved on every change, keyed by thread id) \u2014\n\t// the flip side of dismissing without a discard warning.\n\tconst [reply, setReply] = useState<TLRichText>(\n\t\t() => getCommentDraft(replyDraftSlot(thread.id)) ?? EMPTY_COMMENT\n\t)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst canReply = canComment && !thread.resolved\n\tconst container = useContainer()\n\n\t// Clear the reply before the document-level Escape handler closes the thread, so reopening\n\t// it doesn't restore the discarded draft. Let the event continue to that handler.\n\tconst replyRef = useRef(reply)\n\treplyRef.current = reply\n\tuseEffect(() => {\n\t\tconst win = container.ownerDocument.defaultView\n\t\tif (!win) return\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return\n\t\t\tif (target.closest('.tlui-cmt-editing')) return\n\t\t\tif (isCommentEmpty(replyRef.current)) return\n\t\t\tsetReply(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(replyDraftSlot(thread.id))\n\t\t}\n\t\twin.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => win.removeEventListener('keydown', onKeyDown, true)\n\t}, [container, thread.id])\n\t// Resolved when the composer closes rather than held as an element: the card unmounts while the\n\t// composer stands in its place, so the node captured on the way in is gone by the way out.\n\tconst editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)\n\t// Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a\n\t// click on Save. See the focus hand-back below.\n\tconst editEndedByKeyboard = useRef(false)\n\n\t// Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor\n\t// container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.\n\tconst [focusReply, setFocusReply] = useState(false)\n\tconst tabTaken = useRef(false)\n\tconst swallowTabUp = useRef(false)\n\tuseEffect(() => {\n\t\tif (!canReply) {\n\t\t\t// Resolving unmounts the reply box under an open thread. Reopening it should feel like a\n\t\t\t// freshly opened thread: no autoFocus left armed from the last Tab, and Tab available again.\n\t\t\tsetFocusReply(false)\n\t\t\ttabTaken.current = false\n\t\t\treturn\n\t\t}\n\t\tconst doc = container.ownerDocument\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tif (e.defaultPrevented || tabTaken.current) return\n\t\t\t// Focus rests on the container (or nothing) after a pin click. Anywhere else is deliberate, and\n\t\t\t// Tab belongs to whatever holds it.\n\t\t\tif (e.target !== container && e.target !== doc.body) return\n\t\t\ttabTaken.current = true\n\t\t\tswallowTabUp.current = true\n\t\t\tsetFocusReply(true)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\t// The select tool navigates shapes on Tab's *keyup*, so a quick tap would both focus the reply and\n\t\t// step the selection. Swallow the release of the press we took, and only that one.\n\t\tconst onKeyUp = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || !swallowTabUp.current) return\n\t\t\tswallowTabUp.current = false\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdoc.addEventListener('keydown', onKeyDown, true)\n\t\tdoc.addEventListener('keyup', onKeyUp, true)\n\t\treturn () => {\n\t\t\tdoc.removeEventListener('keydown', onKeyDown, true)\n\t\t\tdoc.removeEventListener('keyup', onKeyUp, true)\n\t\t}\n\t}, [canReply, container])\n\n\t// Leaving the edit composer unmounts it while it holds focus, dropping focus to the editor\n\t// container \u2014 outside the thread, so a Tab from there walks the app's UI. Hand focus back to\n\t// whatever opened the composer instead.\n\tuseEffect(() => {\n\t\tif (editingId !== null) return\n\t\tconst resolve = editReturnFocus.current\n\t\teditReturnFocus.current = null\n\t\t// Runs after React has swapped the card back in, so the target is mounted again by now. Shown\n\t\t// as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after\n\t\t// a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a\n\t\t// keyboard user would otherwise be left on an invisible \u22EF button with no ring.\n\t\tresolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })\n\t\teditEndedByKeyboard.current = false\n\t}, [editingId])\n\n\t// Reported as one batch so the host can record the receipts in a single write. The write flips\n\t// isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!isCommentUnread || !onCommentsRead) return\n\t\tconst unreadIds = comments.filter((comment) => isCommentUnread(comment.id)).map((c) => c.id)\n\t\tif (unreadIds.length > 0) {\n\t\t\tonCommentsRead(unreadIds)\n\t\t}\n\t}, [comments, isCommentUnread, onCommentsRead])\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tconst comment = commitCommentMutation(editor, ({ put }) => {\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId: thread.pageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: reply,\n\t\t\t})\n\t\t\tput([comment])\n\t\t\treturn comment\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t\tclearCommentDraft(replyDraftSlot(thread.id))\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 reply.\n\t\tonPostComment?.(comment)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tif (thread.resolved) reopenThread(editor, thread)\n\t\telse resolveThread(editor, thread, currentUserId)\n\t}\n\n\t// No `currentUserId` check: unlike a resolve, a delete stamps nothing on the record, so who may\n\t// make it is `canModifyComment`'s call alone (which withholds it from an unidentified viewer by\n\t// default).\n\tconst removeThread = () => deleteThread(editor, thread)\n\n\tconst ThreadActions = options.components.ThreadActions\n\t// The host's URL for this thread. Its presence is what puts \"copy link\" in the header menu.\n\tconst threadHref = getThreadHref?.(thread.id)\n\tconst [linkCopied, copyThreadLink] = useCopyLink(threadHref)\n\n\tconst startEdit = (comment: TLComment, { fromMoreMenu = false } = {}) => {\n\t\t// Edit from the \u22EF menu comes back to that button, looked up again on the way out since the card\n\t\t// unmounts. Otherwise return to whatever held focus, ignoring the body and the editor container.\n\t\tconst active = container.ownerDocument.activeElement\n\t\teditReturnFocus.current = fromMoreMenu\n\t\t\t? () => container.querySelector<HTMLElement>(`[data-cmt-more-for=\"${comment.id}\"]`)\n\t\t\t: active instanceof HTMLElement && active !== container && active !== document.body\n\t\t\t\t? () => (active.isConnected ? active : null)\n\t\t\t\t: null\n\t\tsetEditingId(comment.id)\n\t\tsetEditText(comment.body)\n\t}\n\n\tconst saveEdit = () => {\n\t\tconst comment = comments.find((c) => c.id === editingId)\n\t\tif (!comment || isCommentEmpty(editText)) return\n\t\teditComment(editor, comment, editText)\n\t\tsetEditingId(null)\n\t}\n\n\t// Swap a comment for a pre-filled composer while it's being edited; otherwise show the card,\n\t// with the affordances the viewer is allowed on it.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\n\t\tconst permissions = commentPermissions.get(comment.id)\n\t\tif (editingId === comment.id) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"tlui-cmt-editing\"\n\t\t\t\t\tonPointerDown={() => {\n\t\t\t\t\t\teditEndedByKeyboard.current = false\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={(e) => {\n\t\t\t\t\t\teditEndedByKeyboard.current = true\n\t\t\t\t\t\tif (e.key === 'Escape') {\n\t\t\t\t\t\t\tsetEditingId(null)\n\t\t\t\t\t\t\te.stopPropagation()\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={card.author}\n\t\t\t\t\t\tleading={card.renderAvatar?.(card.author)}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsEditPlaceholder)}\n\t\t\t\t\t\tvalue={editText}\n\t\t\t\t\t\tonChange={setEditText}\n\t\t\t\t\t\tonSubmit={saveEdit}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSave)}\n\t\t\t\t\t\tdisabled={isCommentEmpty(editText)}\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/>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\treturn (\n\t\t\t<CommentCard\n\t\t\t\t{...card}\n\t\t\t\tfooter={\n\t\t\t\t\t<CommentReactions\n\t\t\t\t\t\tcomment={comment}\n\t\t\t\t\t\t// Reacting is a commenting write: without `canComment` the tally renders\n\t\t\t\t\t\t// read-only (no identity \u2192 pills aren't clickable).\n\t\t\t\t\t\tcurrentUserId={canComment ? currentUserId : null}\n\t\t\t\t\t\tresolveName={resolveName}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\tcanComment && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<CommentReactionPicker comment={comment} currentUserId={currentUserId} />\n\t\t\t\t\t\t\t{(permissions?.edit || permissions?.delete) && (\n\t\t\t\t\t\t\t\t<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>\n\t\t\t\t\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t\t\t{permissions?.edit && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.commentsEdit)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => startEdit(comment, { fromMoreMenu: true })}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t{permissions?.delete && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.actionDelete)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => deleteComment(editor, comment)}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t</MoreOptionsMenu>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\t// Resolve and delete are commenting writes: behind `canComment`, plus the `currentUserId` a\n\t// resolve stamps into `resolved.by`.\n\tconst resolveLabel = msg(thread.resolved ? messages.commentsReopen : messages.commentsResolve)\n\tconst headerActions = (\n\t\t<>\n\t\t\t{/* Host verbs \u2014 assign, link a ticket \u2014 sit ahead of the built-in actions. */}\n\t\t\t{ThreadActions && <ThreadActions thread={thread} comments={comments} />}\n\t\t\t{canComment && currentUserId && (\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={resolveLabel}\n\t\t\t\t\ttitle={resolveLabel}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"check\" label={resolveLabel} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t)}\n\t\t\t<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>\n\t\t\t\t{(threadHref !== undefined || canDeleteThread) && (\n\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t{/* A link is a read affordance: offered to anyone who can see the thread,\n\t\t\t\t\t\t including a viewer who can't comment. `noClose` keeps the menu up so the\n\t\t\t\t\t\t item can confirm the copy in place. */}\n\t\t\t\t\t\t{threadHref !== undefined && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tlabel={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}\n\t\t\t\t\t\t\t\tnoClose\n\t\t\t\t\t\t\t\tonClick={copyThreadLink}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{canDeleteThread && (\n\t\t\t\t\t\t\t<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tlabel={msg(messages.commentsClose)}\n\t\t\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t\t\t/>\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t</MoreOptionsMenu>\n\t\t</>\n\t)\n\n\treturn (\n\t\t<CommentThread\n\t\t\theader={msg(messages.commentsThreadTitle)}\n\t\t\theaderActions={headerActions}\n\t\t\trenderComment={renderComment}\n\t\t\tcomments={cards}\n\t\t\tresolvedBanner={\n\t\t\t\tthread.resolved\n\t\t\t\t\t? msg(messages.commentsResolvedBy, {\n\t\t\t\t\t\t\tname: resolveAuthor(thread.resolved.by)?.name ?? msg(messages.commentsUnknownAuthor),\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tcomposer={\n\t\t\t\tcanReply\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tauthor: me ?? UNKNOWN_COMMENT_AUTHOR,\n\t\t\t\t\t\t\tleading: avatarRenderer(\n\t\t\t\t\t\t\t\toptions.components,\n\t\t\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t\t\t)?.(me ?? UNKNOWN_COMMENT_AUTHOR),\n\t\t\t\t\t\t\tplaceholder: msg(messages.commentsReplyPlaceholder),\n\t\t\t\t\t\t\tsendLabel: msg(messages.commentsSend),\n\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\tonChange: (value: TLRichText) => {\n\t\t\t\t\t\t\t\tsetReply(value)\n\t\t\t\t\t\t\t\tsaveCommentDraft(replyDraftSlot(thread.id), value)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t// Up in the empty reply box edits the comment directly above it, chat-style \u2014\n\t\t\t\t\t\t\t// only when you're allowed to edit it (the same gate as the Edit link).\n\t\t\t\t\t\t\tonArrowUpWhenEmpty: () => {\n\t\t\t\t\t\t\t\tconst last = comments[comments.length - 1]\n\t\t\t\t\t\t\t\tif (last && commentPermissions.get(last.id)?.edit) startEdit(last)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply) || !currentUserId,\n\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t// Reuses the composer's own focus path, so the caret lands at the end of a\n\t\t\t\t\t\t\t// restored draft rather than in front of it.\n\t\t\t\t\t\t\tautoFocus: focusReply,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tfooter={\n\t\t\t\t!canComment && !thread.resolved && ComposerFallback ? (\n\t\t\t\t\t<ComposerFallback context=\"thread\" />\n\t\t\t\t) : undefined\n\t\t\t}\n\t\t/>\n\t)\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiHE;AAjHF,sBAAwD;AACxD,mBASO;AACP,oBAoBO;AACP,0BAA8C;AAC9C,8BAAgC;AAChC,gCAA8C;AAC9C,4BAA8B;AAC9B,0BAA4B;AAC5B,4BAKO;AACP,+BAOO;AACP,+BAAwD;AACxD,4BAAuC;AAEvC,mBAAkC;AAClC,8BAA0D;AAC1D,qBAMO;AACP,mBAA6B;AAE7B,MAAM,eAAW,8BAAe;AAAA,EAC/B,cAAc,EAAE,IAAI,iBAAiB,gBAAgB,SAAS;AAAA,EAC9D,kBAAkB,EAAE,IAAI,sBAAsB,gBAAgB,YAAY;AAAA,EAC1E,gBAAgB,EAAE,IAAI,mBAAmB,gBAAgB,gBAAgB;AAAA,EACzE,eAAe,EAAE,IAAI,kB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,SAAS,SAAS,SAAS,CAAC;AACzC,cAAI,QAAQ,mBAAmB,IAAI,KAAK,EAAE,GAAG,KAAM,WAAU,IAAI;AAAA,QAClE;AAAA;AAAA,QAEA,cAAU,0CAAe,KAAK,KAAK,CAAC;AAAA,QACpC;AAAA,QACA;AAAA;AAAA;AAAA,QAGA,WAAW;AAAA,MACZ,IACC;AAAA,MAEJ,QACC,CAAC,cAAc,CAAC,OAAO,YAAY,mBAClC,4CAAC,oBAAiB,SAAQ,UAAS,IAChC;AAAA;AAAA,EAEN;AAEF,CAAC;",
|
|
6
6
|
"names": ["ThreadView", "comment"]
|
|
7
7
|
}
|
package/dist-cjs/index.js
CHANGED
|
@@ -145,7 +145,7 @@ var import_state = require("./canvas/state");
|
|
|
145
145
|
var import_thread_state = require("./canvas/thread-state");
|
|
146
146
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
147
147
|
"@tldraw/commenting",
|
|
148
|
-
"5.7.0-canary.
|
|
148
|
+
"5.7.0-canary.a5daf389abd7",
|
|
149
149
|
"cjs"
|
|
150
150
|
);
|
|
151
151
|
//# sourceMappingURL=index.js.map
|
|
@@ -76,19 +76,14 @@ function PendingComposer({
|
|
|
76
76
|
pending.point
|
|
77
77
|
]);
|
|
78
78
|
const placed = useMobilePlacement(ref, point, isMobile);
|
|
79
|
-
const textRef = useRef(text);
|
|
80
|
-
textRef.current = text;
|
|
81
79
|
useEffect(() => {
|
|
82
80
|
const el = ref.current;
|
|
83
81
|
if (!el) return;
|
|
84
82
|
const onKeyDown = (e) => {
|
|
85
83
|
if (e.key !== "Escape" || isMentionPickerOpen()) return;
|
|
86
84
|
e.stopPropagation();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
clearCommentDraft(NEW_COMMENT_DRAFT);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
85
|
+
setText(EMPTY_COMMENT);
|
|
86
|
+
clearCommentDraft(NEW_COMMENT_DRAFT);
|
|
92
87
|
pendingComment.set(editor, null);
|
|
93
88
|
editor.getContainer().focus();
|
|
94
89
|
};
|
|
@@ -128,6 +123,7 @@ function PendingComposer({
|
|
|
128
123
|
setText(EMPTY_COMMENT);
|
|
129
124
|
clearCommentDraft(NEW_COMMENT_DRAFT);
|
|
130
125
|
pendingComment.set(editor, null);
|
|
126
|
+
editor.getContainer().focus();
|
|
131
127
|
onPostComment?.(comment);
|
|
132
128
|
};
|
|
133
129
|
return /* @__PURE__ */ jsx(EditorPortal, { children: /* @__PURE__ */ jsx(
|
|
@@ -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 {\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 { commitCommentMutation } 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 = 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// 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,SAAS,eAAe,sBAAsB;AAC9C,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B,oBAAoB,wBAAwB;AAClF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AACvC,SAAyB,wBAAwB;AAEjD,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,eAAe,4BAA4B;AACpD,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,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/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAoE;AACnE,QAAM,EAAE,WAAW,IAAI,qBAAqB;AAC5C,QAAM,mBAAmB,WAAW;AACpC,QAAM,aAAa,cAAc,aAAa;AAC9C,QAAM,KAAK,gBAAgB,cAAc,aAAa,IAAI;AAC1D,QAAM,WAAW,sBAAsB;AACvC,QAAM,OAAO,aAAa,QAAQ,OAAO;AAEzC,QAAM,cACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MAET,GAAI,WAAW,CAAC,IAAI,KAAK;AAAA,MAE1B,8BAAC,cACC,yBAAe,YAAY,aAAa,IAAI,MAAM,sBAAsB,KACxE,oBAAC,UAAO,QAAQ,MAAM,wBAAwB,GAEhD;AAAA;AAAA,EACD;AAID,QAAM,CAAC,MAAM,OAAO,IAAI;AAAA,IACvB,MAAM,gBAAgB,iBAAiB,KAAK;AAAA,EAC7C;AACA,QAAM,MAAM,OAAuB,IAAI;AACvC,QAAM,MAAM,eAAe;AAE3B,4BAA0B,GAAG;AAE7B,QAAM,QAAQ,SAAS,kBAAkB,MAAM,OAAO,eAAe,QAAQ,KAAK,GAAG;AAAA,IACpF;AAAA,IACA,QAAQ;AAAA,EACT,CAAC;AAGD,QAAM,SAAS,mBAAmB,KAAK,OAAO,QAAQ;
|
|
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 { commitCommentMutation } 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// Handle Escape before it reaches the editor's container so closing the composer doesn't\n\t// also cancel the comment tool.\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\tsetText(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\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 = 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// Removing the focused composer would leave Escape outside the editor's keyboard listener.\n\t\teditor.getContainer().focus()\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,SAAS,eAAe,sBAAsB;AAC9C,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B,oBAAoB,wBAAwB;AAClF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AACvC,SAAyB,wBAAwB;AAEjD,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,eAAe,4BAA4B;AACpD,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,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/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAoE;AACnE,QAAM,EAAE,WAAW,IAAI,qBAAqB;AAC5C,QAAM,mBAAmB,WAAW;AACpC,QAAM,aAAa,cAAc,aAAa;AAC9C,QAAM,KAAK,gBAAgB,cAAc,aAAa,IAAI;AAC1D,QAAM,WAAW,sBAAsB;AACvC,QAAM,OAAO,aAAa,QAAQ,OAAO;AAEzC,QAA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AC,KAAM;AACX,UAAI,CAAC,KAAK,SAAS,KAAK,MAAM,EAAE,UAAU,KAAK,QAAQ,EAAE,UAAU,KAAK,MAAM,IAAI,EAAG;AACrF,WAAK,UAAU,EAAE;AACjB,WAAK,UAAU,EAAE;AACjB,UAAI,CAAC,KAAK,OAAO;AAChB,aAAK,QAAQ;AACb,aAAK,UAAU,iBAAiB,QAAQ;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
|
}
|
|
@@ -303,8 +303,6 @@ const ThreadView = memo(function ThreadView2({
|
|
|
303
303
|
if (isCommentEmpty(replyRef.current)) return;
|
|
304
304
|
setReply(EMPTY_COMMENT);
|
|
305
305
|
clearCommentDraft(replyDraftSlot(thread.id));
|
|
306
|
-
e.preventDefault();
|
|
307
|
-
e.stopPropagation();
|
|
308
306
|
};
|
|
309
307
|
win.addEventListener("keydown", onKeyDown, true);
|
|
310
308
|
return () => win.removeEventListener("keydown", onKeyDown, true);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/thread-view.tsx"],
|
|
4
|
-
"sourcesContent": ["import { type CommentAuthor, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport {\n\tcreateComment,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLComment,\n\tTLCommentThread,\n\tTldrawUiButton,\n\tTldrawUiButtonLabel,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tTLRichText,\n\tuseContainer,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CommentBody } from './comment-body'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\treplyDraftSlot,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport {\n\tcommitCommentMutation,\n\tdeleteComment,\n\tdeleteThread,\n\teditComment,\n\treopenThread,\n\tresolveThread,\n} from './comment-mutations'\nimport { CommentReactionPicker, CommentReactions } from './comment-reactions'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { type CommentingContext } from './context'\nimport { useThreadComments } from './hooks'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport {\n\ttype CommentingComponents,\n\tgetCanModifyComment,\n\tuseCanComment,\n\tuseCanModifyComment,\n\tuseCommentingOptions,\n} from './options'\nimport { openThreadId } from './state'\n\nconst messages = defineMessages({\n\tactionDelete: { id: 'action.delete', defaultMessage: 'Delete' },\n\tcommentsCopyLink: { id: 'comments.copy-link', defaultMessage: 'Copy link' },\n\tcommentsDelete: { id: 'comments.delete', defaultMessage: 'Delete thread' },\n\tcommentsClose: { id: 'comments.close', defaultMessage: 'Close' },\n\tcommentsEdit: { id: 'comments.edit', defaultMessage: 'Edit' },\n\tcommentsEditPlaceholder: {\n\t\tid: 'comments.edit-placeholder',\n\t\tdefaultMessage: 'Edit comment\u2026',\n\t},\n\tcommentsLinkCopied: { id: 'comments.link-copied', defaultMessage: 'Link copied' },\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsReopen: { id: 'comments.reopen', defaultMessage: 'Reopen' },\n\tcommentsReplyPlaceholder: { id: 'comments.reply-placeholder', defaultMessage: 'Reply\u2026' },\n\tcommentsResolve: { id: 'comments.resolve', defaultMessage: 'Resolve' },\n\tcommentsResolvedBy: { id: 'comments.resolved-by', defaultMessage: 'Resolved by {name}' },\n\tcommentsSave: { id: 'comments.save', defaultMessage: 'Save' },\n\tcommentsSeeLess: { id: 'comments.see-less', defaultMessage: 'See less' },\n\tcommentsSeeMore: { id: 'comments.see-more', defaultMessage: 'See more' },\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsThreadTitle: { id: 'comments.thread-title', defaultMessage: 'Comment' },\n\tcommentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * A comment body clamped to 10 lines (see `.tlui-cmt-collapsible--collapsed`), with a See more /\n * See less toggle when it's longer. Overflow is measured rather than estimated from the text, so it\n * holds for any body (including a host's `CommentBody` slot) and re-checks as the panel resizes.\n */\nfunction CollapsibleBody({ children }: { children: ReactNode }) {\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst [expanded, setExpanded] = useState(false)\n\tconst [overflows, setOverflows] = useState(false)\n\tuseLayoutEffect(() => {\n\t\tconst el = ref.current\n\t\t// Expanded, nothing is clipped to measure; keep the collapsed reading so See less stays.\n\t\tif (!el || expanded) return\n\t\tconst measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)\n\t\tmeasure()\n\t\tconst observer = new ResizeObserver(measure)\n\t\tobserver.observe(el)\n\t\tfor (const child of Array.from(el.children)) observer.observe(child)\n\t\treturn () => observer.disconnect()\n\t}, [expanded, children])\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={['tlui-cmt-collapsible', !expanded && 'tlui-cmt-collapsible--collapsed']\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{overflows && (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"tlui-cmt-see-more\"\n\t\t\t\t\taria-expanded={expanded}\n\t\t\t\t\tonClick={() => setExpanded((v) => !v)}\n\t\t\t\t>\n\t\t\t\t\t{msg(expanded ? messages.commentsSeeLess : messages.commentsSeeMore)}\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\n/** The \"\u22EF\" dropdown used for both a comment's and the thread's actions. */\nfunction MoreOptionsMenu({\n\tid,\n\tmoreFor,\n\tchildren,\n}: {\n\tid: string\n\t/** The comment whose \u22EF button this is, so `startEdit` can find it again to return focus. */\n\tmoreFor?: string\n\tchildren: ReactNode\n}) {\n\tconst msg = useTranslation()\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id={id}>\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsMoreOptions)}\n\t\t\t\t\ttitle={msg(messages.commentsMoreOptions)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tdata-cmt-more-for={moreFor}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"dots-vertical\" label={msg(messages.commentsMoreOptions)} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={-6} sideOffset={0}>\n\t\t\t\t{children}\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n\nfunction MenuItem({\n\tlabel,\n\tnoClose,\n\tonClick,\n}: {\n\tlabel: string\n\tnoClose?: boolean\n\tonClick(): void\n}) {\n\treturn (\n\t\t<TldrawUiDropdownMenuItem noClose={noClose}>\n\t\t\t<TldrawUiButton type=\"menu\" onClick={onClick}>\n\t\t\t\t<TldrawUiButtonLabel>{label}</TldrawUiButtonLabel>\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiDropdownMenuItem>\n\t)\n}\n\n/**\n * A name-only view of an author resolver, for the mention/rich-text paths. Stable identity, so\n * `CommentBody`'s memoized render doesn't recompute on every render of its host.\n */\nexport function useResolveName(resolveAuthor: CommentingContext['resolveAuthor']) {\n\treturn useCallback((id: string) => resolveAuthor(id)?.name, [resolveAuthor])\n}\n\n/** How long the copy-link item reads \"Link copied\" before reverting. */\nconst LINK_COPIED_MS = 2000\n\n/**\n * What a thread's `getThreadHref` should put on the clipboard. Hosts may hand back a relative href,\n * which is meaningless once pasted elsewhere, so it's resolved against the current document first.\n * An href the URL parser can't make sense of is copied as-is rather than dropped.\n *\n * @internal\n */\nexport function absoluteThreadLink(href: string, base = window.location.href): string {\n\ttry {\n\t\treturn new URL(href, base).toString()\n\t} catch {\n\t\treturn href\n\t}\n}\n\n/**\n * Copy a thread's link, with a flag that stays set briefly afterwards so the control can confirm.\n * Only set once the write resolves, so a withheld clipboard doesn't claim a copy that didn't happen.\n */\nfunction useCopyLink(href: string | undefined) {\n\tconst [copied, setCopied] = useState(false)\n\tuseEffect(() => {\n\t\tif (!copied) return\n\t\tconst timeout = window.setTimeout(() => setCopied(false), LINK_COPIED_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [copied])\n\tconst copy = useCallback(() => {\n\t\tif (href === undefined) return\n\t\tnavigator.clipboard?.writeText(absoluteThreadLink(href)).then(\n\t\t\t() => setCopied(true),\n\t\t\t() => setCopied(false)\n\t\t)\n\t}, [href])\n\treturn [copied, copy] as const\n}\n\n/**\n * The `Avatar` component slot as a `renderAvatar` callback for the presentational components, bound\n * to the id the avatar stands for. Undefined without an override, so they draw their own default.\n */\nexport function avatarRenderer(\n\tcomponents: CommentingComponents,\n\tauthorId: string | null\n): ((author: CommentAuthor) => ReactNode) | undefined {\n\tconst Avatar = components.Avatar\n\tif (!Avatar) return undefined\n\treturn (author) => <Avatar author={author} authorId={authorId} />\n}\n\nexport function toCardProps(\n\tcomment: TLComment,\n\tprops: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'>,\n\tcomponents: CommentingComponents,\n\tresolveName: (id: string) => string | undefined\n): CommentCardProps {\n\tconst Body = components.CommentBody\n\t// The `CommentBody` component slot overrides the built-in rich-text default (which resolves\n\t// mention ids to names).\n\tconst body = Body ? (\n\t\t<Body comment={comment} />\n\t) : (\n\t\t<CommentBody richText={comment.body} resolveName={resolveName} />\n\t)\n\tconst author = props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR\n\tconst date = new Date(comment.createdAt).toISOString()\n\tconst edited = comment.editedAt != null\n\tconst renderAvatar = avatarRenderer(components, comment.authorId)\n\tconst Byline = components.CommentByline\n\treturn {\n\t\tauthor,\n\t\tbody,\n\t\tdate,\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited,\n\t\trenderAvatar,\n\t\tbyline: Byline ? (\n\t\t\t<Byline\n\t\t\t\tauthor={author}\n\t\t\t\tdate={date}\n\t\t\t\tedited={edited}\n\t\t\t\trenderAvatar={renderAvatar}\n\t\t\t\tcomment={comment}\n\t\t\t/>\n\t\t) : undefined,\n\t}\n}\n\n/** A pin is this square (mirrors `--tlui-cmt-pin-size`). The two marker kinds differ in size *and*\n * anchor point, so lining their previews up means correcting for both. Keep in sync with the CSS. */\nconst PIN_SIZE = 28\n\n/** A cluster/stack badge is this square (`--tlui-cmt-marker-size`) \u2014 pin-sized, so the marker\n * kinds read as one family. Keep in sync with the stylesheet. */\nconst MARKER_SIZE = PIN_SIZE\n\n/** Where a popover's top card sits vertically, measured from the marker visual's middle. */\nconst CARD_TOP_Y = -28\n\n/** The horizontal gap between a marker visual's right edge and its popover/preview panel. The\n * preview's hover bridge spans exactly this (see `--tlui-cmt-preview-bridge`). */\nconst PREVIEW_GAP = 6\n\n/**\n * Where a marker's popover sits relative to the marker's anchor point. The hover preview uses the\n * same origins, so moving a popover here moves its preview with it.\n *\n * Both marker kinds hang off their point the same way (`translate(0, -100%)`), differing only in\n * size \u2014 so each offset clears its own width plus the shared gap, and re-bases the shared card-top\n * measure from its bottom anchor to its middle.\n */\nexport const POPOVER_OFFSET = {\n\tthread: { x: PIN_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - PIN_SIZE / 2 },\n\tlist: { x: MARKER_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - MARKER_SIZE / 2 },\n} as const\n\n/** The open thread's popover container, portaled above the UI panels. A wheel over it passes\n * through to the canvas (unless it scrolls its own content), like tldraw's panels. */\nexport function ThreadPopover({\n\tbase,\n\tchildren,\n}: {\n\tbase: { x: number; y: number }\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\t// On mobile the popover slides off its fixed offset to stay above the software keyboard and\n\t// on-screen; desktop keeps the fixed offset (base returned unchanged).\n\tconst isMobile = useIsMobileCommenting()\n\tconst placed = useMobilePlacement(ref, base, isMobile)\n\treturn (\n\t\t<EditorPortal>\n\t\t\t{/* contextmenu also stops here: portals bubble React events to the canvas's context-menu\n\t\t\t trigger (the layer mounts inside it), which would open the canvas menu over this panel. */}\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName=\"tlui-cmt-canvas-popover\"\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{children}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n\n/**\n * One thread's interactive view: its comments, the reply composer, edit-in-place on your own\n * comments, and the resolve/delete actions. Read receipts are reported for every unread comment\n * while mounted, so only mount it where the thread is actually being shown.\n *\n * Memoized because the popover position rides the pin's per-frame render point, so the pin\n * re-renders on every camera frame while a thread is open.\n */\nexport const ThreadView = memo(function ThreadView({\n\teditor,\n\tthread,\n\t...props\n}: CommentingContext & { editor: Editor; thread: TLCommentThread }) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveAuthor,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentsRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t\tgetThreadHref,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\tconst resolveName = useResolveName(resolveAuthor)\n\t// Rebuilt only when the comments change, not on every render \u2014 each of which would otherwise\n\t// re-allocate a date string and body element per comment.\n\tconst cards = useMemo(\n\t\t() =>\n\t\t\tcomments.map((c) => {\n\t\t\t\tconst card = toCardProps(\n\t\t\t\t\tc,\n\t\t\t\t\t{ currentUserId, resolveAuthor },\n\t\t\t\t\toptions.components,\n\t\t\t\t\tresolveName\n\t\t\t\t)\n\t\t\t\treturn { ...card, body: <CollapsibleBody>{card.body}</CollapsibleBody> }\n\t\t\t}),\n\t\t[comments, currentUserId, resolveAuthor, options.components, resolveName]\n\t)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// Composing, editing, deleting, and resolving are all gated on the viewer's permission. Where it's\n\t// withheld the composer gives way to the ComposerFallback slot and the affordances are hidden.\n\tconst canComment = useCanComment(currentUserId)\n\t// Editing and deleting are further per-record: the author's to do by default, wider or narrower\n\t// under a `canModifyComment` callback. Computed for the thread's comments in one pass, since\n\t// `renderComment` is a callback rather than a component and can't call a hook per comment.\n\tconst commentPermissions = useValue(\n\t\t'comment permissions',\n\t\t() =>\n\t\t\tnew Map(\n\t\t\t\tcomments.map((comment) => [\n\t\t\t\t\tcomment.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tedit: getCanModifyComment(editor, currentUserId, { action: 'edit-comment', comment }),\n\t\t\t\t\t\tdelete: getCanModifyComment(editor, currentUserId, {\n\t\t\t\t\t\t\taction: 'delete-comment',\n\t\t\t\t\t\t\tcomment,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t),\n\t\t[editor, currentUserId, comments]\n\t)\n\t// Deleting a thread is its creator's by default (and server-enforced); `canModifyComment` is what\n\t// widens that. Still a commenting write, so `canComment` stays the outer gate.\n\tconst canModifyThread = useCanModifyComment(currentUserId, { action: 'delete-thread', thread })\n\tconst canDeleteThread = canComment && canModifyThread\n\tconst ComposerFallback = options.components.ComposerFallback\n\t// An unsent reply survives closing the thread (saved on every change, keyed by thread id) \u2014\n\t// the flip side of dismissing without a discard warning.\n\tconst [reply, setReply] = useState<TLRichText>(\n\t\t() => getCommentDraft(replyDraftSlot(thread.id)) ?? EMPTY_COMMENT\n\t)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst canReply = canComment && !thread.resolved\n\tconst container = useContainer()\n\n\t// Escape in a reply box with text clears the text and keeps the thread open; an empty one falls\n\t// through to the layer's Escape, which closes the thread. On the window, in the capture phase,\n\t// so it runs ahead of that document-level handler.\n\tconst replyRef = useRef(reply)\n\treplyRef.current = reply\n\tuseEffect(() => {\n\t\tconst win = container.ownerDocument.defaultView\n\t\tif (!win) return\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return\n\t\t\tif (target.closest('.tlui-cmt-editing')) return\n\t\t\tif (isCommentEmpty(replyRef.current)) return\n\t\t\tsetReply(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(replyDraftSlot(thread.id))\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\twin.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => win.removeEventListener('keydown', onKeyDown, true)\n\t}, [container, thread.id])\n\t// Resolved when the composer closes rather than held as an element: the card unmounts while the\n\t// composer stands in its place, so the node captured on the way in is gone by the way out.\n\tconst editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)\n\t// Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a\n\t// click on Save. See the focus hand-back below.\n\tconst editEndedByKeyboard = useRef(false)\n\n\t// Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor\n\t// container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.\n\tconst [focusReply, setFocusReply] = useState(false)\n\tconst tabTaken = useRef(false)\n\tconst swallowTabUp = useRef(false)\n\tuseEffect(() => {\n\t\tif (!canReply) {\n\t\t\t// Resolving unmounts the reply box under an open thread. Reopening it should feel like a\n\t\t\t// freshly opened thread: no autoFocus left armed from the last Tab, and Tab available again.\n\t\t\tsetFocusReply(false)\n\t\t\ttabTaken.current = false\n\t\t\treturn\n\t\t}\n\t\tconst doc = container.ownerDocument\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tif (e.defaultPrevented || tabTaken.current) return\n\t\t\t// Focus rests on the container (or nothing) after a pin click. Anywhere else is deliberate, and\n\t\t\t// Tab belongs to whatever holds it.\n\t\t\tif (e.target !== container && e.target !== doc.body) return\n\t\t\ttabTaken.current = true\n\t\t\tswallowTabUp.current = true\n\t\t\tsetFocusReply(true)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\t// The select tool navigates shapes on Tab's *keyup*, so a quick tap would both focus the reply and\n\t\t// step the selection. Swallow the release of the press we took, and only that one.\n\t\tconst onKeyUp = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || !swallowTabUp.current) return\n\t\t\tswallowTabUp.current = false\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdoc.addEventListener('keydown', onKeyDown, true)\n\t\tdoc.addEventListener('keyup', onKeyUp, true)\n\t\treturn () => {\n\t\t\tdoc.removeEventListener('keydown', onKeyDown, true)\n\t\t\tdoc.removeEventListener('keyup', onKeyUp, true)\n\t\t}\n\t}, [canReply, container])\n\n\t// Leaving the edit composer unmounts it while it holds focus, dropping focus to the editor\n\t// container \u2014 outside the thread, so a Tab from there walks the app's UI. Hand focus back to\n\t// whatever opened the composer instead.\n\tuseEffect(() => {\n\t\tif (editingId !== null) return\n\t\tconst resolve = editReturnFocus.current\n\t\teditReturnFocus.current = null\n\t\t// Runs after React has swapped the card back in, so the target is mounted again by now. Shown\n\t\t// as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after\n\t\t// a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a\n\t\t// keyboard user would otherwise be left on an invisible \u22EF button with no ring.\n\t\tresolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })\n\t\teditEndedByKeyboard.current = false\n\t}, [editingId])\n\n\t// Reported as one batch so the host can record the receipts in a single write. The write flips\n\t// isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!isCommentUnread || !onCommentsRead) return\n\t\tconst unreadIds = comments.filter((comment) => isCommentUnread(comment.id)).map((c) => c.id)\n\t\tif (unreadIds.length > 0) {\n\t\t\tonCommentsRead(unreadIds)\n\t\t}\n\t}, [comments, isCommentUnread, onCommentsRead])\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tconst comment = commitCommentMutation(editor, ({ put }) => {\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId: thread.pageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: reply,\n\t\t\t})\n\t\t\tput([comment])\n\t\t\treturn comment\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t\tclearCommentDraft(replyDraftSlot(thread.id))\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 reply.\n\t\tonPostComment?.(comment)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tif (thread.resolved) reopenThread(editor, thread)\n\t\telse resolveThread(editor, thread, currentUserId)\n\t}\n\n\t// No `currentUserId` check: unlike a resolve, a delete stamps nothing on the record, so who may\n\t// make it is `canModifyComment`'s call alone (which withholds it from an unidentified viewer by\n\t// default).\n\tconst removeThread = () => deleteThread(editor, thread)\n\n\tconst ThreadActions = options.components.ThreadActions\n\t// The host's URL for this thread. Its presence is what puts \"copy link\" in the header menu.\n\tconst threadHref = getThreadHref?.(thread.id)\n\tconst [linkCopied, copyThreadLink] = useCopyLink(threadHref)\n\n\tconst startEdit = (comment: TLComment, { fromMoreMenu = false } = {}) => {\n\t\t// Edit from the \u22EF menu comes back to that button, looked up again on the way out since the card\n\t\t// unmounts. Otherwise return to whatever held focus, ignoring the body and the editor container.\n\t\tconst active = container.ownerDocument.activeElement\n\t\teditReturnFocus.current = fromMoreMenu\n\t\t\t? () => container.querySelector<HTMLElement>(`[data-cmt-more-for=\"${comment.id}\"]`)\n\t\t\t: active instanceof HTMLElement && active !== container && active !== document.body\n\t\t\t\t? () => (active.isConnected ? active : null)\n\t\t\t\t: null\n\t\tsetEditingId(comment.id)\n\t\tsetEditText(comment.body)\n\t}\n\n\tconst saveEdit = () => {\n\t\tconst comment = comments.find((c) => c.id === editingId)\n\t\tif (!comment || isCommentEmpty(editText)) return\n\t\teditComment(editor, comment, editText)\n\t\tsetEditingId(null)\n\t}\n\n\t// Swap a comment for a pre-filled composer while it's being edited; otherwise show the card,\n\t// with the affordances the viewer is allowed on it.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\n\t\tconst permissions = commentPermissions.get(comment.id)\n\t\tif (editingId === comment.id) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"tlui-cmt-editing\"\n\t\t\t\t\tonPointerDown={() => {\n\t\t\t\t\t\teditEndedByKeyboard.current = false\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={(e) => {\n\t\t\t\t\t\teditEndedByKeyboard.current = true\n\t\t\t\t\t\tif (e.key === 'Escape') {\n\t\t\t\t\t\t\tsetEditingId(null)\n\t\t\t\t\t\t\te.stopPropagation()\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={card.author}\n\t\t\t\t\t\tleading={card.renderAvatar?.(card.author)}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsEditPlaceholder)}\n\t\t\t\t\t\tvalue={editText}\n\t\t\t\t\t\tonChange={setEditText}\n\t\t\t\t\t\tonSubmit={saveEdit}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSave)}\n\t\t\t\t\t\tdisabled={isCommentEmpty(editText)}\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/>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\treturn (\n\t\t\t<CommentCard\n\t\t\t\t{...card}\n\t\t\t\tfooter={\n\t\t\t\t\t<CommentReactions\n\t\t\t\t\t\tcomment={comment}\n\t\t\t\t\t\t// Reacting is a commenting write: without `canComment` the tally renders\n\t\t\t\t\t\t// read-only (no identity \u2192 pills aren't clickable).\n\t\t\t\t\t\tcurrentUserId={canComment ? currentUserId : null}\n\t\t\t\t\t\tresolveName={resolveName}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\tcanComment && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<CommentReactionPicker comment={comment} currentUserId={currentUserId} />\n\t\t\t\t\t\t\t{(permissions?.edit || permissions?.delete) && (\n\t\t\t\t\t\t\t\t<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>\n\t\t\t\t\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t\t\t{permissions?.edit && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.commentsEdit)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => startEdit(comment, { fromMoreMenu: true })}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t{permissions?.delete && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.actionDelete)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => deleteComment(editor, comment)}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t</MoreOptionsMenu>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\t// Resolve and delete are commenting writes: behind `canComment`, plus the `currentUserId` a\n\t// resolve stamps into `resolved.by`.\n\tconst resolveLabel = msg(thread.resolved ? messages.commentsReopen : messages.commentsResolve)\n\tconst headerActions = (\n\t\t<>\n\t\t\t{/* Host verbs \u2014 assign, link a ticket \u2014 sit ahead of the built-in actions. */}\n\t\t\t{ThreadActions && <ThreadActions thread={thread} comments={comments} />}\n\t\t\t{canComment && currentUserId && (\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={resolveLabel}\n\t\t\t\t\ttitle={resolveLabel}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"check\" label={resolveLabel} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t)}\n\t\t\t<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>\n\t\t\t\t{(threadHref !== undefined || canDeleteThread) && (\n\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t{/* A link is a read affordance: offered to anyone who can see the thread,\n\t\t\t\t\t\t including a viewer who can't comment. `noClose` keeps the menu up so the\n\t\t\t\t\t\t item can confirm the copy in place. */}\n\t\t\t\t\t\t{threadHref !== undefined && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tlabel={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}\n\t\t\t\t\t\t\t\tnoClose\n\t\t\t\t\t\t\t\tonClick={copyThreadLink}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{canDeleteThread && (\n\t\t\t\t\t\t\t<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tlabel={msg(messages.commentsClose)}\n\t\t\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t\t\t/>\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t</MoreOptionsMenu>\n\t\t</>\n\t)\n\n\treturn (\n\t\t<CommentThread\n\t\t\theader={msg(messages.commentsThreadTitle)}\n\t\t\theaderActions={headerActions}\n\t\t\trenderComment={renderComment}\n\t\t\tcomments={cards}\n\t\t\tresolvedBanner={\n\t\t\t\tthread.resolved\n\t\t\t\t\t? msg(messages.commentsResolvedBy, {\n\t\t\t\t\t\t\tname: resolveAuthor(thread.resolved.by)?.name ?? msg(messages.commentsUnknownAuthor),\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tcomposer={\n\t\t\t\tcanReply\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tauthor: me ?? UNKNOWN_COMMENT_AUTHOR,\n\t\t\t\t\t\t\tleading: avatarRenderer(\n\t\t\t\t\t\t\t\toptions.components,\n\t\t\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t\t\t)?.(me ?? UNKNOWN_COMMENT_AUTHOR),\n\t\t\t\t\t\t\tplaceholder: msg(messages.commentsReplyPlaceholder),\n\t\t\t\t\t\t\tsendLabel: msg(messages.commentsSend),\n\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\tonChange: (value: TLRichText) => {\n\t\t\t\t\t\t\t\tsetReply(value)\n\t\t\t\t\t\t\t\tsaveCommentDraft(replyDraftSlot(thread.id), value)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t// Up in the empty reply box edits the comment directly above it, chat-style \u2014\n\t\t\t\t\t\t\t// only when you're allowed to edit it (the same gate as the Edit link).\n\t\t\t\t\t\t\tonArrowUpWhenEmpty: () => {\n\t\t\t\t\t\t\t\tconst last = comments[comments.length - 1]\n\t\t\t\t\t\t\t\tif (last && commentPermissions.get(last.id)?.edit) startEdit(last)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply) || !currentUserId,\n\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t// Reuses the composer's own focus path, so the caret lands at the end of a\n\t\t\t\t\t\t\t// restored draft rather than in front of it.\n\t\t\t\t\t\t\tautoFocus: focusReply,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tfooter={\n\t\t\t\t!canComment && !thread.resolved && ComposerFallback ? (\n\t\t\t\t\t<ComposerFallback context=\"thread\" />\n\t\t\t\t) : undefined\n\t\t\t}\n\t\t/>\n\t)\n})\n"],
|
|
5
|
-
"mappings": "AAiHE,mBACC,KADD;AAjHF,SAA6B,2BAA2B;AACxD;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EAEA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAqC;AAC9C,SAAS,uBAAuB;AAChC,SAAS,eAAe,sBAAsB;AAC9C,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,uBAAuB,wBAAwB;AACxD,SAAS,8BAA8B;AAEvC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB,0BAA0B;AAC1D;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;AAE7B,MAAM,WAAW,eAAe;AAAA,EAC/B,cAAc,E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CAAC,UAAsB;AAChC,mBAAS,KAAK;AACd,2BAAiB,eAAe,OAAO,EAAE,GAAG,KAAK;AAAA,QAClD;AAAA,QACA,UAAU;AAAA;AAAA;AAAA,QAGV,oBAAoB,MAAM;AACzB,gBAAM,OAAO,SAAS,SAAS,SAAS,CAAC;AACzC,cAAI,QAAQ,mBAAmB,IAAI,KAAK,EAAE,GAAG,KAAM,WAAU,IAAI;AAAA,QAClE;AAAA;AAAA,QAEA,UAAU,eAAe,KAAK,KAAK,CAAC;AAAA,QACpC;AAAA,QACA;AAAA;AAAA;AAAA,QAGA,WAAW;AAAA,MACZ,IACC;AAAA,MAEJ,QACC,CAAC,cAAc,CAAC,OAAO,YAAY,mBAClC,oBAAC,oBAAiB,SAAQ,UAAS,IAChC;AAAA;AAAA,EAEN;AAEF,CAAC;",
|
|
4
|
+
"sourcesContent": ["import { type CommentAuthor, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport {\n\tcreateComment,\n\tdefineMessages,\n\tEditor,\n\tEditorPortal,\n\tTLComment,\n\tTLCommentThread,\n\tTldrawUiButton,\n\tTldrawUiButtonLabel,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tTLRichText,\n\tuseContainer,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CommentBody } from './comment-body'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\treplyDraftSlot,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport {\n\tcommitCommentMutation,\n\tdeleteComment,\n\tdeleteThread,\n\teditComment,\n\treopenThread,\n\tresolveThread,\n} from './comment-mutations'\nimport { CommentReactionPicker, CommentReactions } from './comment-reactions'\nimport { UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { type CommentingContext } from './context'\nimport { useThreadComments } from './hooks'\nimport { useIsMobileCommenting, useMobilePlacement } from './mobile-placement'\nimport {\n\ttype CommentingComponents,\n\tgetCanModifyComment,\n\tuseCanComment,\n\tuseCanModifyComment,\n\tuseCommentingOptions,\n} from './options'\nimport { openThreadId } from './state'\n\nconst messages = defineMessages({\n\tactionDelete: { id: 'action.delete', defaultMessage: 'Delete' },\n\tcommentsCopyLink: { id: 'comments.copy-link', defaultMessage: 'Copy link' },\n\tcommentsDelete: { id: 'comments.delete', defaultMessage: 'Delete thread' },\n\tcommentsClose: { id: 'comments.close', defaultMessage: 'Close' },\n\tcommentsEdit: { id: 'comments.edit', defaultMessage: 'Edit' },\n\tcommentsEditPlaceholder: {\n\t\tid: 'comments.edit-placeholder',\n\t\tdefaultMessage: 'Edit comment\u2026',\n\t},\n\tcommentsLinkCopied: { id: 'comments.link-copied', defaultMessage: 'Link copied' },\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsReopen: { id: 'comments.reopen', defaultMessage: 'Reopen' },\n\tcommentsReplyPlaceholder: { id: 'comments.reply-placeholder', defaultMessage: 'Reply\u2026' },\n\tcommentsResolve: { id: 'comments.resolve', defaultMessage: 'Resolve' },\n\tcommentsResolvedBy: { id: 'comments.resolved-by', defaultMessage: 'Resolved by {name}' },\n\tcommentsSave: { id: 'comments.save', defaultMessage: 'Save' },\n\tcommentsSeeLess: { id: 'comments.see-less', defaultMessage: 'See less' },\n\tcommentsSeeMore: { id: 'comments.see-more', defaultMessage: 'See more' },\n\tcommentsSend: { id: 'comments.send', defaultMessage: 'Send' },\n\tcommentsThreadTitle: { id: 'comments.thread-title', defaultMessage: 'Comment' },\n\tcommentsUnknownAuthor: { id: 'comments.unknown-author', defaultMessage: 'Someone' },\n})\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/**\n * A comment body clamped to 10 lines (see `.tlui-cmt-collapsible--collapsed`), with a See more /\n * See less toggle when it's longer. Overflow is measured rather than estimated from the text, so it\n * holds for any body (including a host's `CommentBody` slot) and re-checks as the panel resizes.\n */\nfunction CollapsibleBody({ children }: { children: ReactNode }) {\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst [expanded, setExpanded] = useState(false)\n\tconst [overflows, setOverflows] = useState(false)\n\tuseLayoutEffect(() => {\n\t\tconst el = ref.current\n\t\t// Expanded, nothing is clipped to measure; keep the collapsed reading so See less stays.\n\t\tif (!el || expanded) return\n\t\tconst measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)\n\t\tmeasure()\n\t\tconst observer = new ResizeObserver(measure)\n\t\tobserver.observe(el)\n\t\tfor (const child of Array.from(el.children)) observer.observe(child)\n\t\treturn () => observer.disconnect()\n\t}, [expanded, children])\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={['tlui-cmt-collapsible', !expanded && 'tlui-cmt-collapsible--collapsed']\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{overflows && (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"tlui-cmt-see-more\"\n\t\t\t\t\taria-expanded={expanded}\n\t\t\t\t\tonClick={() => setExpanded((v) => !v)}\n\t\t\t\t>\n\t\t\t\t\t{msg(expanded ? messages.commentsSeeLess : messages.commentsSeeMore)}\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\n/** The \"\u22EF\" dropdown used for both a comment's and the thread's actions. */\nfunction MoreOptionsMenu({\n\tid,\n\tmoreFor,\n\tchildren,\n}: {\n\tid: string\n\t/** The comment whose \u22EF button this is, so `startEdit` can find it again to return focus. */\n\tmoreFor?: string\n\tchildren: ReactNode\n}) {\n\tconst msg = useTranslation()\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id={id}>\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsMoreOptions)}\n\t\t\t\t\ttitle={msg(messages.commentsMoreOptions)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tdata-cmt-more-for={moreFor}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"dots-vertical\" label={msg(messages.commentsMoreOptions)} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={-6} sideOffset={0}>\n\t\t\t\t{children}\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n\nfunction MenuItem({\n\tlabel,\n\tnoClose,\n\tonClick,\n}: {\n\tlabel: string\n\tnoClose?: boolean\n\tonClick(): void\n}) {\n\treturn (\n\t\t<TldrawUiDropdownMenuItem noClose={noClose}>\n\t\t\t<TldrawUiButton type=\"menu\" onClick={onClick}>\n\t\t\t\t<TldrawUiButtonLabel>{label}</TldrawUiButtonLabel>\n\t\t\t</TldrawUiButton>\n\t\t</TldrawUiDropdownMenuItem>\n\t)\n}\n\n/**\n * A name-only view of an author resolver, for the mention/rich-text paths. Stable identity, so\n * `CommentBody`'s memoized render doesn't recompute on every render of its host.\n */\nexport function useResolveName(resolveAuthor: CommentingContext['resolveAuthor']) {\n\treturn useCallback((id: string) => resolveAuthor(id)?.name, [resolveAuthor])\n}\n\n/** How long the copy-link item reads \"Link copied\" before reverting. */\nconst LINK_COPIED_MS = 2000\n\n/**\n * What a thread's `getThreadHref` should put on the clipboard. Hosts may hand back a relative href,\n * which is meaningless once pasted elsewhere, so it's resolved against the current document first.\n * An href the URL parser can't make sense of is copied as-is rather than dropped.\n *\n * @internal\n */\nexport function absoluteThreadLink(href: string, base = window.location.href): string {\n\ttry {\n\t\treturn new URL(href, base).toString()\n\t} catch {\n\t\treturn href\n\t}\n}\n\n/**\n * Copy a thread's link, with a flag that stays set briefly afterwards so the control can confirm.\n * Only set once the write resolves, so a withheld clipboard doesn't claim a copy that didn't happen.\n */\nfunction useCopyLink(href: string | undefined) {\n\tconst [copied, setCopied] = useState(false)\n\tuseEffect(() => {\n\t\tif (!copied) return\n\t\tconst timeout = window.setTimeout(() => setCopied(false), LINK_COPIED_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [copied])\n\tconst copy = useCallback(() => {\n\t\tif (href === undefined) return\n\t\tnavigator.clipboard?.writeText(absoluteThreadLink(href)).then(\n\t\t\t() => setCopied(true),\n\t\t\t() => setCopied(false)\n\t\t)\n\t}, [href])\n\treturn [copied, copy] as const\n}\n\n/**\n * The `Avatar` component slot as a `renderAvatar` callback for the presentational components, bound\n * to the id the avatar stands for. Undefined without an override, so they draw their own default.\n */\nexport function avatarRenderer(\n\tcomponents: CommentingComponents,\n\tauthorId: string | null\n): ((author: CommentAuthor) => ReactNode) | undefined {\n\tconst Avatar = components.Avatar\n\tif (!Avatar) return undefined\n\treturn (author) => <Avatar author={author} authorId={authorId} />\n}\n\nexport function toCardProps(\n\tcomment: TLComment,\n\tprops: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'>,\n\tcomponents: CommentingComponents,\n\tresolveName: (id: string) => string | undefined\n): CommentCardProps {\n\tconst Body = components.CommentBody\n\t// The `CommentBody` component slot overrides the built-in rich-text default (which resolves\n\t// mention ids to names).\n\tconst body = Body ? (\n\t\t<Body comment={comment} />\n\t) : (\n\t\t<CommentBody richText={comment.body} resolveName={resolveName} />\n\t)\n\tconst author = props.resolveAuthor(comment.authorId) ?? UNKNOWN_COMMENT_AUTHOR\n\tconst date = new Date(comment.createdAt).toISOString()\n\tconst edited = comment.editedAt != null\n\tconst renderAvatar = avatarRenderer(components, comment.authorId)\n\tconst Byline = components.CommentByline\n\treturn {\n\t\tauthor,\n\t\tbody,\n\t\tdate,\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited,\n\t\trenderAvatar,\n\t\tbyline: Byline ? (\n\t\t\t<Byline\n\t\t\t\tauthor={author}\n\t\t\t\tdate={date}\n\t\t\t\tedited={edited}\n\t\t\t\trenderAvatar={renderAvatar}\n\t\t\t\tcomment={comment}\n\t\t\t/>\n\t\t) : undefined,\n\t}\n}\n\n/** A pin is this square (mirrors `--tlui-cmt-pin-size`). The two marker kinds differ in size *and*\n * anchor point, so lining their previews up means correcting for both. Keep in sync with the CSS. */\nconst PIN_SIZE = 28\n\n/** A cluster/stack badge is this square (`--tlui-cmt-marker-size`) \u2014 pin-sized, so the marker\n * kinds read as one family. Keep in sync with the stylesheet. */\nconst MARKER_SIZE = PIN_SIZE\n\n/** Where a popover's top card sits vertically, measured from the marker visual's middle. */\nconst CARD_TOP_Y = -28\n\n/** The horizontal gap between a marker visual's right edge and its popover/preview panel. The\n * preview's hover bridge spans exactly this (see `--tlui-cmt-preview-bridge`). */\nconst PREVIEW_GAP = 6\n\n/**\n * Where a marker's popover sits relative to the marker's anchor point. The hover preview uses the\n * same origins, so moving a popover here moves its preview with it.\n *\n * Both marker kinds hang off their point the same way (`translate(0, -100%)`), differing only in\n * size \u2014 so each offset clears its own width plus the shared gap, and re-bases the shared card-top\n * measure from its bottom anchor to its middle.\n */\nexport const POPOVER_OFFSET = {\n\tthread: { x: PIN_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - PIN_SIZE / 2 },\n\tlist: { x: MARKER_SIZE + PREVIEW_GAP, y: CARD_TOP_Y - MARKER_SIZE / 2 },\n} as const\n\n/** The open thread's popover container, portaled above the UI panels. A wheel over it passes\n * through to the canvas (unless it scrolls its own content), like tldraw's panels. */\nexport function ThreadPopover({\n\tbase,\n\tchildren,\n}: {\n\tbase: { x: number; y: number }\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\t// On mobile the popover slides off its fixed offset to stay above the software keyboard and\n\t// on-screen; desktop keeps the fixed offset (base returned unchanged).\n\tconst isMobile = useIsMobileCommenting()\n\tconst placed = useMobilePlacement(ref, base, isMobile)\n\treturn (\n\t\t<EditorPortal>\n\t\t\t{/* contextmenu also stops here: portals bubble React events to the canvas's context-menu\n\t\t\t trigger (the layer mounts inside it), which would open the canvas menu over this panel. */}\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName=\"tlui-cmt-canvas-popover\"\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{children}\n\t\t\t</div>\n\t\t</EditorPortal>\n\t)\n}\n\n/**\n * One thread's interactive view: its comments, the reply composer, edit-in-place on your own\n * comments, and the resolve/delete actions. Read receipts are reported for every unread comment\n * while mounted, so only mount it where the thread is actually being shown.\n *\n * Memoized because the popover position rides the pin's per-frame render point, so the pin\n * re-renders on every camera frame while a thread is open.\n */\nexport const ThreadView = memo(function ThreadView({\n\teditor,\n\tthread,\n\t...props\n}: CommentingContext & { editor: Editor; thread: TLCommentThread }) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveAuthor,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentsRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t\tgetThreadHref,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\tconst resolveName = useResolveName(resolveAuthor)\n\t// Rebuilt only when the comments change, not on every render \u2014 each of which would otherwise\n\t// re-allocate a date string and body element per comment.\n\tconst cards = useMemo(\n\t\t() =>\n\t\t\tcomments.map((c) => {\n\t\t\t\tconst card = toCardProps(\n\t\t\t\t\tc,\n\t\t\t\t\t{ currentUserId, resolveAuthor },\n\t\t\t\t\toptions.components,\n\t\t\t\t\tresolveName\n\t\t\t\t)\n\t\t\t\treturn { ...card, body: <CollapsibleBody>{card.body}</CollapsibleBody> }\n\t\t\t}),\n\t\t[comments, currentUserId, resolveAuthor, options.components, resolveName]\n\t)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// Composing, editing, deleting, and resolving are all gated on the viewer's permission. Where it's\n\t// withheld the composer gives way to the ComposerFallback slot and the affordances are hidden.\n\tconst canComment = useCanComment(currentUserId)\n\t// Editing and deleting are further per-record: the author's to do by default, wider or narrower\n\t// under a `canModifyComment` callback. Computed for the thread's comments in one pass, since\n\t// `renderComment` is a callback rather than a component and can't call a hook per comment.\n\tconst commentPermissions = useValue(\n\t\t'comment permissions',\n\t\t() =>\n\t\t\tnew Map(\n\t\t\t\tcomments.map((comment) => [\n\t\t\t\t\tcomment.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tedit: getCanModifyComment(editor, currentUserId, { action: 'edit-comment', comment }),\n\t\t\t\t\t\tdelete: getCanModifyComment(editor, currentUserId, {\n\t\t\t\t\t\t\taction: 'delete-comment',\n\t\t\t\t\t\t\tcomment,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t),\n\t\t[editor, currentUserId, comments]\n\t)\n\t// Deleting a thread is its creator's by default (and server-enforced); `canModifyComment` is what\n\t// widens that. Still a commenting write, so `canComment` stays the outer gate.\n\tconst canModifyThread = useCanModifyComment(currentUserId, { action: 'delete-thread', thread })\n\tconst canDeleteThread = canComment && canModifyThread\n\tconst ComposerFallback = options.components.ComposerFallback\n\t// An unsent reply survives closing the thread (saved on every change, keyed by thread id) \u2014\n\t// the flip side of dismissing without a discard warning.\n\tconst [reply, setReply] = useState<TLRichText>(\n\t\t() => getCommentDraft(replyDraftSlot(thread.id)) ?? EMPTY_COMMENT\n\t)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst canReply = canComment && !thread.resolved\n\tconst container = useContainer()\n\n\t// Clear the reply before the document-level Escape handler closes the thread, so reopening\n\t// it doesn't restore the discarded draft. Let the event continue to that handler.\n\tconst replyRef = useRef(reply)\n\treplyRef.current = reply\n\tuseEffect(() => {\n\t\tconst win = container.ownerDocument.defaultView\n\t\tif (!win) return\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target?.closest('.tlui-cmt-thread .tlui-cmt-composer')) return\n\t\t\tif (target.closest('.tlui-cmt-editing')) return\n\t\t\tif (isCommentEmpty(replyRef.current)) return\n\t\t\tsetReply(EMPTY_COMMENT)\n\t\t\tclearCommentDraft(replyDraftSlot(thread.id))\n\t\t}\n\t\twin.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => win.removeEventListener('keydown', onKeyDown, true)\n\t}, [container, thread.id])\n\t// Resolved when the composer closes rather than held as an element: the card unmounts while the\n\t// composer stands in its place, so the node captured on the way in is gone by the way out.\n\tconst editReturnFocus = useRef<(() => HTMLElement | null) | null>(null)\n\t// Whether the edit was last driven from the keyboard (Escape, or Enter to save) rather than by a\n\t// click on Save. See the focus hand-back below.\n\tconst editEndedByKeyboard = useRef(false)\n\n\t// Tab from the canvas drops the caret in the reply box: a pin click leaves focus on the editor\n\t// container, so the first Tab would otherwise walk the app's UI. Capture phase, once per open thread.\n\tconst [focusReply, setFocusReply] = useState(false)\n\tconst tabTaken = useRef(false)\n\tconst swallowTabUp = useRef(false)\n\tuseEffect(() => {\n\t\tif (!canReply) {\n\t\t\t// Resolving unmounts the reply box under an open thread. Reopening it should feel like a\n\t\t\t// freshly opened thread: no autoFocus left armed from the last Tab, and Tab available again.\n\t\t\tsetFocusReply(false)\n\t\t\ttabTaken.current = false\n\t\t\treturn\n\t\t}\n\t\tconst doc = container.ownerDocument\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tif (e.defaultPrevented || tabTaken.current) return\n\t\t\t// Focus rests on the container (or nothing) after a pin click. Anywhere else is deliberate, and\n\t\t\t// Tab belongs to whatever holds it.\n\t\t\tif (e.target !== container && e.target !== doc.body) return\n\t\t\ttabTaken.current = true\n\t\t\tswallowTabUp.current = true\n\t\t\tsetFocusReply(true)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\t// The select tool navigates shapes on Tab's *keyup*, so a quick tap would both focus the reply and\n\t\t// step the selection. Swallow the release of the press we took, and only that one.\n\t\tconst onKeyUp = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Tab' || !swallowTabUp.current) return\n\t\t\tswallowTabUp.current = false\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdoc.addEventListener('keydown', onKeyDown, true)\n\t\tdoc.addEventListener('keyup', onKeyUp, true)\n\t\treturn () => {\n\t\t\tdoc.removeEventListener('keydown', onKeyDown, true)\n\t\t\tdoc.removeEventListener('keyup', onKeyUp, true)\n\t\t}\n\t}, [canReply, container])\n\n\t// Leaving the edit composer unmounts it while it holds focus, dropping focus to the editor\n\t// container \u2014 outside the thread, so a Tab from there walks the app's UI. Hand focus back to\n\t// whatever opened the composer instead.\n\tuseEffect(() => {\n\t\tif (editingId !== null) return\n\t\tconst resolve = editReturnFocus.current\n\t\teditReturnFocus.current = null\n\t\t// Runs after React has swapped the card back in, so the target is mounted again by now. Shown\n\t\t// as keyboard focus only after a keyboard edit: that is what reveals a card's actions, so after\n\t\t// a click on Save they'd stay up for a pointer that has moved away, but after Escape or Enter a\n\t\t// keyboard user would otherwise be left on an invisible \u22EF button with no ring.\n\t\tresolve?.()?.focus({ focusVisible: editEndedByKeyboard.current })\n\t\teditEndedByKeyboard.current = false\n\t}, [editingId])\n\n\t// Reported as one batch so the host can record the receipts in a single write. The write flips\n\t// isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!isCommentUnread || !onCommentsRead) return\n\t\tconst unreadIds = comments.filter((comment) => isCommentUnread(comment.id)).map((c) => c.id)\n\t\tif (unreadIds.length > 0) {\n\t\t\tonCommentsRead(unreadIds)\n\t\t}\n\t}, [comments, isCommentUnread, onCommentsRead])\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tconst comment = commitCommentMutation(editor, ({ put }) => {\n\t\t\tconst comment = createComment({\n\t\t\t\tthreadId: thread.id,\n\t\t\t\tpageId: thread.pageId,\n\t\t\t\tauthorId: currentUserId,\n\t\t\t\tbody: reply,\n\t\t\t})\n\t\t\tput([comment])\n\t\t\treturn comment\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t\tclearCommentDraft(replyDraftSlot(thread.id))\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 reply.\n\t\tonPostComment?.(comment)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tif (thread.resolved) reopenThread(editor, thread)\n\t\telse resolveThread(editor, thread, currentUserId)\n\t}\n\n\t// No `currentUserId` check: unlike a resolve, a delete stamps nothing on the record, so who may\n\t// make it is `canModifyComment`'s call alone (which withholds it from an unidentified viewer by\n\t// default).\n\tconst removeThread = () => deleteThread(editor, thread)\n\n\tconst ThreadActions = options.components.ThreadActions\n\t// The host's URL for this thread. Its presence is what puts \"copy link\" in the header menu.\n\tconst threadHref = getThreadHref?.(thread.id)\n\tconst [linkCopied, copyThreadLink] = useCopyLink(threadHref)\n\n\tconst startEdit = (comment: TLComment, { fromMoreMenu = false } = {}) => {\n\t\t// Edit from the \u22EF menu comes back to that button, looked up again on the way out since the card\n\t\t// unmounts. Otherwise return to whatever held focus, ignoring the body and the editor container.\n\t\tconst active = container.ownerDocument.activeElement\n\t\teditReturnFocus.current = fromMoreMenu\n\t\t\t? () => container.querySelector<HTMLElement>(`[data-cmt-more-for=\"${comment.id}\"]`)\n\t\t\t: active instanceof HTMLElement && active !== container && active !== document.body\n\t\t\t\t? () => (active.isConnected ? active : null)\n\t\t\t\t: null\n\t\tsetEditingId(comment.id)\n\t\tsetEditText(comment.body)\n\t}\n\n\tconst saveEdit = () => {\n\t\tconst comment = comments.find((c) => c.id === editingId)\n\t\tif (!comment || isCommentEmpty(editText)) return\n\t\teditComment(editor, comment, editText)\n\t\tsetEditingId(null)\n\t}\n\n\t// Swap a comment for a pre-filled composer while it's being edited; otherwise show the card,\n\t// with the affordances the viewer is allowed on it.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\n\t\tconst permissions = commentPermissions.get(comment.id)\n\t\tif (editingId === comment.id) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"tlui-cmt-editing\"\n\t\t\t\t\tonPointerDown={() => {\n\t\t\t\t\t\teditEndedByKeyboard.current = false\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={(e) => {\n\t\t\t\t\t\teditEndedByKeyboard.current = true\n\t\t\t\t\t\tif (e.key === 'Escape') {\n\t\t\t\t\t\t\tsetEditingId(null)\n\t\t\t\t\t\t\te.stopPropagation()\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<CommentComposer\n\t\t\t\t\t\tauthor={card.author}\n\t\t\t\t\t\tleading={card.renderAvatar?.(card.author)}\n\t\t\t\t\t\tplaceholder={msg(messages.commentsEditPlaceholder)}\n\t\t\t\t\t\tvalue={editText}\n\t\t\t\t\t\tonChange={setEditText}\n\t\t\t\t\t\tonSubmit={saveEdit}\n\t\t\t\t\t\tsendLabel={msg(messages.commentsSave)}\n\t\t\t\t\t\tdisabled={isCommentEmpty(editText)}\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/>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\treturn (\n\t\t\t<CommentCard\n\t\t\t\t{...card}\n\t\t\t\tfooter={\n\t\t\t\t\t<CommentReactions\n\t\t\t\t\t\tcomment={comment}\n\t\t\t\t\t\t// Reacting is a commenting write: without `canComment` the tally renders\n\t\t\t\t\t\t// read-only (no identity \u2192 pills aren't clickable).\n\t\t\t\t\t\tcurrentUserId={canComment ? currentUserId : null}\n\t\t\t\t\t\tresolveName={resolveName}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\tcanComment && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<CommentReactionPicker comment={comment} currentUserId={currentUserId} />\n\t\t\t\t\t\t\t{(permissions?.edit || permissions?.delete) && (\n\t\t\t\t\t\t\t\t<MoreOptionsMenu id={`comment-actions-${comment.id}`} moreFor={comment.id}>\n\t\t\t\t\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t\t\t{permissions?.edit && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.commentsEdit)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => startEdit(comment, { fromMoreMenu: true })}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t{permissions?.delete && (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tlabel={msg(messages.actionDelete)}\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => deleteComment(editor, comment)}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t\t\t</MoreOptionsMenu>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\t// Resolve and delete are commenting writes: behind `canComment`, plus the `currentUserId` a\n\t// resolve stamps into `resolved.by`.\n\tconst resolveLabel = msg(thread.resolved ? messages.commentsReopen : messages.commentsResolve)\n\tconst headerActions = (\n\t\t<>\n\t\t\t{/* Host verbs \u2014 assign, link a ticket \u2014 sit ahead of the built-in actions. */}\n\t\t\t{ThreadActions && <ThreadActions thread={thread} comments={comments} />}\n\t\t\t{canComment && currentUserId && (\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={resolveLabel}\n\t\t\t\t\ttitle={resolveLabel}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"check\" label={resolveLabel} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t)}\n\t\t\t<MoreOptionsMenu id={`comment-thread-actions-${thread.id}`}>\n\t\t\t\t{(threadHref !== undefined || canDeleteThread) && (\n\t\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t\t{/* A link is a read affordance: offered to anyone who can see the thread,\n\t\t\t\t\t\t including a viewer who can't comment. `noClose` keeps the menu up so the\n\t\t\t\t\t\t item can confirm the copy in place. */}\n\t\t\t\t\t\t{threadHref !== undefined && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tlabel={msg(linkCopied ? messages.commentsLinkCopied : messages.commentsCopyLink)}\n\t\t\t\t\t\t\t\tnoClose\n\t\t\t\t\t\t\t\tonClick={copyThreadLink}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{canDeleteThread && (\n\t\t\t\t\t\t\t<MenuItem label={msg(messages.commentsDelete)} onClick={removeThread} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tlabel={msg(messages.commentsClose)}\n\t\t\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t\t\t/>\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t</MoreOptionsMenu>\n\t\t</>\n\t)\n\n\treturn (\n\t\t<CommentThread\n\t\t\theader={msg(messages.commentsThreadTitle)}\n\t\t\theaderActions={headerActions}\n\t\t\trenderComment={renderComment}\n\t\t\tcomments={cards}\n\t\t\tresolvedBanner={\n\t\t\t\tthread.resolved\n\t\t\t\t\t? msg(messages.commentsResolvedBy, {\n\t\t\t\t\t\t\tname: resolveAuthor(thread.resolved.by)?.name ?? msg(messages.commentsUnknownAuthor),\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tcomposer={\n\t\t\t\tcanReply\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tauthor: me ?? UNKNOWN_COMMENT_AUTHOR,\n\t\t\t\t\t\t\tleading: avatarRenderer(\n\t\t\t\t\t\t\t\toptions.components,\n\t\t\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t\t\t)?.(me ?? UNKNOWN_COMMENT_AUTHOR),\n\t\t\t\t\t\t\tplaceholder: msg(messages.commentsReplyPlaceholder),\n\t\t\t\t\t\t\tsendLabel: msg(messages.commentsSend),\n\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\tonChange: (value: TLRichText) => {\n\t\t\t\t\t\t\t\tsetReply(value)\n\t\t\t\t\t\t\t\tsaveCommentDraft(replyDraftSlot(thread.id), value)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t// Up in the empty reply box edits the comment directly above it, chat-style \u2014\n\t\t\t\t\t\t\t// only when you're allowed to edit it (the same gate as the Edit link).\n\t\t\t\t\t\t\tonArrowUpWhenEmpty: () => {\n\t\t\t\t\t\t\t\tconst last = comments[comments.length - 1]\n\t\t\t\t\t\t\t\tif (last && commentPermissions.get(last.id)?.edit) startEdit(last)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply) || !currentUserId,\n\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t// Reuses the composer's own focus path, so the caret lands at the end of a\n\t\t\t\t\t\t\t// restored draft rather than in front of it.\n\t\t\t\t\t\t\tautoFocus: focusReply,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tfooter={\n\t\t\t\t!canComment && !thread.resolved && ComposerFallback ? (\n\t\t\t\t\t<ComposerFallback context=\"thread\" />\n\t\t\t\t) : undefined\n\t\t\t}\n\t\t/>\n\t)\n})\n"],
|
|
5
|
+
"mappings": "AAiHE,mBACC,KADD;AAjHF,SAA6B,2BAA2B;AACxD;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EAEA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAqC;AAC9C,SAAS,uBAAuB;AAChC,SAAS,eAAe,sBAAsB;AAC9C,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;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A,MACpF,CAAC,IACA;AAAA,MAEJ,UACC,WACG;AAAA,QACA,QAAQ,MAAM;AAAA,QACd,SAAS;AAAA,UACR,QAAQ;AAAA,UACR;AAAA,QACD,IAAI,MAAM,sBAAsB;AAAA,QAChC,aAAa,IAAI,SAAS,wBAAwB;AAAA,QAClD,WAAW,IAAI,SAAS,YAAY;AAAA,QACpC,OAAO;AAAA,QACP,UAAU,CAAC,UAAsB;AAChC,mBAAS,KAAK;AACd,2BAAiB,eAAe,OAAO,EAAE,GAAG,KAAK;AAAA,QAClD;AAAA,QACA,UAAU;AAAA;AAAA;AAAA,QAGV,oBAAoB,MAAM;AACzB,gBAAM,OAAO,SAAS,SAAS,SAAS,CAAC;AACzC,cAAI,QAAQ,mBAAmB,IAAI,KAAK,EAAE,GAAG,KAAM,WAAU,IAAI;AAAA,QAClE;AAAA;AAAA,QAEA,UAAU,eAAe,KAAK,KAAK,CAAC;AAAA,QACpC;AAAA,QACA;AAAA;AAAA;AAAA,QAGA,WAAW;AAAA,MACZ,IACC;AAAA,MAEJ,QACC,CAAC,cAAc,CAAC,OAAO,YAAY,mBAClC,oBAAC,oBAAiB,SAAQ,UAAS,IAChC;AAAA;AAAA,EAEN;AAEF,CAAC;",
|
|
6
6
|
"names": ["ThreadView", "comment"]
|
|
7
7
|
}
|
package/dist-esm/index.mjs
CHANGED
|
@@ -108,7 +108,7 @@ import {
|
|
|
108
108
|
import { anchorPagePoint, focusThread, shapeAnchorAt } from "./canvas/thread-state.mjs";
|
|
109
109
|
registerTldrawLibraryVersion(
|
|
110
110
|
"@tldraw/commenting",
|
|
111
|
-
"5.7.0-canary.
|
|
111
|
+
"5.7.0-canary.a5daf389abd7",
|
|
112
112
|
"esm"
|
|
113
113
|
);
|
|
114
114
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/commenting",
|
|
3
3
|
"description": "tldraw commenting UI components.",
|
|
4
|
-
"version": "5.7.0-canary.
|
|
4
|
+
"version": "5.7.0-canary.a5daf389abd7",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tldraw/driver": "5.7.0-canary.
|
|
35
|
+
"@tldraw/driver": "5.7.0-canary.a5daf389abd7",
|
|
36
36
|
"@types/react": "^19.2.7",
|
|
37
37
|
"@types/react-dom": "^19.2.3",
|
|
38
38
|
"react": "^19.2.1",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@tiptap/core": "^3.12.1",
|
|
51
51
|
"@tiptap/pm": "^3.12.1",
|
|
52
52
|
"@tiptap/react": "^3.12.1",
|
|
53
|
-
"@tldraw/mentions": "5.7.0-canary.
|
|
54
|
-
"@tldraw/utils": "5.7.0-canary.
|
|
55
|
-
"tldraw": "5.7.0-canary.
|
|
53
|
+
"@tldraw/mentions": "5.7.0-canary.a5daf389abd7",
|
|
54
|
+
"@tldraw/utils": "5.7.0-canary.a5daf389abd7",
|
|
55
|
+
"tldraw": "5.7.0-canary.a5daf389abd7"
|
|
56
56
|
},
|
|
57
57
|
"module": "dist-esm/index.mjs",
|
|
58
58
|
"source": "src/index.ts",
|
|
@@ -103,22 +103,16 @@ export function PendingComposer({
|
|
|
103
103
|
// keeps it pinned to the point.
|
|
104
104
|
const placed = useMobilePlacement(ref, point, isMobile)
|
|
105
105
|
|
|
106
|
-
// Escape
|
|
107
|
-
//
|
|
108
|
-
// would also cancel the comment tool) sits on its container, below React's root listener.
|
|
109
|
-
const textRef = useRef(text)
|
|
110
|
-
textRef.current = text
|
|
106
|
+
// Handle Escape before it reaches the editor's container so closing the composer doesn't
|
|
107
|
+
// also cancel the comment tool.
|
|
111
108
|
useEffect(() => {
|
|
112
109
|
const el = ref.current
|
|
113
110
|
if (!el) return
|
|
114
111
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
115
112
|
if (e.key !== 'Escape' || isMentionPickerOpen()) return
|
|
116
113
|
e.stopPropagation()
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
clearCommentDraft(NEW_COMMENT_DRAFT)
|
|
120
|
-
return
|
|
121
|
-
}
|
|
114
|
+
setText(EMPTY_COMMENT)
|
|
115
|
+
clearCommentDraft(NEW_COMMENT_DRAFT)
|
|
122
116
|
pendingComment.set(editor, null)
|
|
123
117
|
// Focus would drop to the page with the composer gone, out of reach of the next Escape.
|
|
124
118
|
editor.getContainer().focus()
|
|
@@ -165,6 +159,8 @@ export function PendingComposer({
|
|
|
165
159
|
setText(EMPTY_COMMENT)
|
|
166
160
|
clearCommentDraft(NEW_COMMENT_DRAFT)
|
|
167
161
|
pendingComment.set(editor, null)
|
|
162
|
+
// Removing the focused composer would leave Escape outside the editor's keyboard listener.
|
|
163
|
+
editor.getContainer().focus()
|
|
168
164
|
// The host's callback is its own operation, not part of the post's history scope. It runs
|
|
169
165
|
// last so a throwing host can't strand the composer holding a draft of a posted comment.
|
|
170
166
|
onPostComment?.(comment)
|
|
@@ -423,9 +423,8 @@ export const ThreadView = memo(function ThreadView({
|
|
|
423
423
|
const canReply = canComment && !thread.resolved
|
|
424
424
|
const container = useContainer()
|
|
425
425
|
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
// so it runs ahead of that document-level handler.
|
|
426
|
+
// Clear the reply before the document-level Escape handler closes the thread, so reopening
|
|
427
|
+
// it doesn't restore the discarded draft. Let the event continue to that handler.
|
|
429
428
|
const replyRef = useRef(reply)
|
|
430
429
|
replyRef.current = reply
|
|
431
430
|
useEffect(() => {
|
|
@@ -439,8 +438,6 @@ export const ThreadView = memo(function ThreadView({
|
|
|
439
438
|
if (isCommentEmpty(replyRef.current)) return
|
|
440
439
|
setReply(EMPTY_COMMENT)
|
|
441
440
|
clearCommentDraft(replyDraftSlot(thread.id))
|
|
442
|
-
e.preventDefault()
|
|
443
|
-
e.stopPropagation()
|
|
444
441
|
}
|
|
445
442
|
win.addEventListener('keydown', onKeyDown, true)
|
|
446
443
|
return () => win.removeEventListener('keydown', onKeyDown, true)
|
package/src/ui/comments.css
CHANGED
|
@@ -696,7 +696,7 @@ button.tlui-cmt-reaction:hover {
|
|
|
696
696
|
}
|
|
697
697
|
|
|
698
698
|
.tlui-cmt-thread .tlui-cmt-composer {
|
|
699
|
-
padding:
|
|
699
|
+
padding: 4px;
|
|
700
700
|
}
|
|
701
701
|
.tlui-cmt-thread .tlui-cmt-composer .tlui-cmt-avatar {
|
|
702
702
|
display: none;
|
|
@@ -775,10 +775,10 @@ button.tlui-cmt-reaction:hover {
|
|
|
775
775
|
justify-content: space-between;
|
|
776
776
|
gap: 8px;
|
|
777
777
|
/* Flush top and right, like the thread popover's header: the 40px buttons' 32px hover squares
|
|
778
|
-
then sit 4px in from the panel edge, and the title shares the popover's 12px inset.
|
|
779
|
-
divider is an inset shadow, not a border, so the header stays the buttons' 40px tall. */
|
|
778
|
+
then sit 4px in from the panel edge, and the title shares the popover's 12px inset. */
|
|
780
779
|
height: 40px;
|
|
781
780
|
padding: 0 0 0 12px;
|
|
781
|
+
border-bottom: 1px solid var(--tl-color-divider);
|
|
782
782
|
}
|
|
783
783
|
.tlui-cmt-list__header-title {
|
|
784
784
|
font-size: 12px;
|