@tldraw/commenting 0.0.0-bootstrap → 5.3.0-internal.c5c7f1d817d0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/commenting.css +131 -131
  2. package/dist-cjs/canvas/comment-body.js +1 -1
  3. package/dist-cjs/canvas/comment-body.js.map +2 -2
  4. package/dist-cjs/canvas/comments-filter-menu.js +1 -1
  5. package/dist-cjs/canvas/comments-filter-menu.js.map +1 -1
  6. package/dist-cjs/canvas/comments-overflow-menu.js +3 -3
  7. package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
  8. package/dist-cjs/canvas/comments-overlay.js +65 -50
  9. package/dist-cjs/canvas/comments-overlay.js.map +2 -2
  10. package/dist-cjs/canvas/comments-sidebar.js +2 -2
  11. package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
  12. package/dist-cjs/clustering/runtime.js +119 -7
  13. package/dist-cjs/clustering/runtime.js.map +2 -2
  14. package/dist-cjs/index.d.ts +28 -8
  15. package/dist-cjs/index.js +1 -1
  16. package/dist-cjs/ui/avatar.js +10 -2
  17. package/dist-cjs/ui/avatar.js.map +2 -2
  18. package/dist-cjs/ui/byline.js +4 -4
  19. package/dist-cjs/ui/byline.js.map +2 -2
  20. package/dist-cjs/ui/comment-card.js +3 -3
  21. package/dist-cjs/ui/comment-card.js.map +2 -2
  22. package/dist-cjs/ui/comment-composer.js +30 -24
  23. package/dist-cjs/ui/comment-composer.js.map +2 -2
  24. package/dist-cjs/ui/comment-mention.js +1 -1
  25. package/dist-cjs/ui/comment-mention.js.map +2 -2
  26. package/dist-cjs/ui/comment-pin.js +5 -1
  27. package/dist-cjs/ui/comment-pin.js.map +2 -2
  28. package/dist-cjs/ui/comment-text.js +1 -1
  29. package/dist-cjs/ui/comment-text.js.map +2 -2
  30. package/dist-cjs/ui/comment-thread.js +6 -6
  31. package/dist-cjs/ui/comment-thread.js.map +2 -2
  32. package/dist-cjs/ui/comments-list.js +11 -11
  33. package/dist-cjs/ui/comments-list.js.map +2 -2
  34. package/dist-cjs/ui/count-badge.js +1 -1
  35. package/dist-cjs/ui/count-badge.js.map +2 -2
  36. package/dist-cjs/ui/empty-state.js +3 -3
  37. package/dist-cjs/ui/empty-state.js.map +2 -2
  38. package/dist-cjs/ui/mention-list.js +7 -7
  39. package/dist-cjs/ui/mention-list.js.map +2 -2
  40. package/dist-cjs/ui/mention-suggestion.js +3 -3
  41. package/dist-cjs/ui/mention-suggestion.js.map +2 -2
  42. package/dist-cjs/ui/mention.js +1 -1
  43. package/dist-cjs/ui/mention.js.map +2 -2
  44. package/dist-cjs/ui/reaction.js +11 -4
  45. package/dist-cjs/ui/reaction.js.map +2 -2
  46. package/dist-cjs/ui/reactions.js +10 -2
  47. package/dist-cjs/ui/reactions.js.map +2 -2
  48. package/dist-cjs/ui/send-button.js +1 -1
  49. package/dist-cjs/ui/send-button.js.map +2 -2
  50. package/dist-esm/canvas/comment-body.mjs +1 -1
  51. package/dist-esm/canvas/comment-body.mjs.map +2 -2
  52. package/dist-esm/canvas/comments-filter-menu.mjs +1 -1
  53. package/dist-esm/canvas/comments-filter-menu.mjs.map +1 -1
  54. package/dist-esm/canvas/comments-overflow-menu.mjs +3 -3
  55. package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
  56. package/dist-esm/canvas/comments-overlay.mjs +65 -50
  57. package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
  58. package/dist-esm/canvas/comments-sidebar.mjs +2 -2
  59. package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
  60. package/dist-esm/clustering/runtime.mjs +119 -7
  61. package/dist-esm/clustering/runtime.mjs.map +2 -2
  62. package/dist-esm/index.d.mts +28 -8
  63. package/dist-esm/index.mjs +1 -1
  64. package/dist-esm/ui/avatar.mjs +10 -2
  65. package/dist-esm/ui/avatar.mjs.map +2 -2
  66. package/dist-esm/ui/byline.mjs +4 -4
  67. package/dist-esm/ui/byline.mjs.map +2 -2
  68. package/dist-esm/ui/comment-card.mjs +3 -3
  69. package/dist-esm/ui/comment-card.mjs.map +2 -2
  70. package/dist-esm/ui/comment-composer.mjs +30 -24
  71. package/dist-esm/ui/comment-composer.mjs.map +2 -2
  72. package/dist-esm/ui/comment-mention.mjs +1 -1
  73. package/dist-esm/ui/comment-mention.mjs.map +2 -2
  74. package/dist-esm/ui/comment-pin.mjs +5 -1
  75. package/dist-esm/ui/comment-pin.mjs.map +2 -2
  76. package/dist-esm/ui/comment-text.mjs +1 -1
  77. package/dist-esm/ui/comment-text.mjs.map +2 -2
  78. package/dist-esm/ui/comment-thread.mjs +6 -6
  79. package/dist-esm/ui/comment-thread.mjs.map +2 -2
  80. package/dist-esm/ui/comments-list.mjs +11 -11
  81. package/dist-esm/ui/comments-list.mjs.map +2 -2
  82. package/dist-esm/ui/count-badge.mjs +1 -1
  83. package/dist-esm/ui/count-badge.mjs.map +2 -2
  84. package/dist-esm/ui/empty-state.mjs +3 -3
  85. package/dist-esm/ui/empty-state.mjs.map +2 -2
  86. package/dist-esm/ui/mention-list.mjs +7 -7
  87. package/dist-esm/ui/mention-list.mjs.map +2 -2
  88. package/dist-esm/ui/mention-suggestion.mjs +3 -3
  89. package/dist-esm/ui/mention-suggestion.mjs.map +2 -2
  90. package/dist-esm/ui/mention.mjs +1 -1
  91. package/dist-esm/ui/mention.mjs.map +2 -2
  92. package/dist-esm/ui/reaction.mjs +11 -4
  93. package/dist-esm/ui/reaction.mjs.map +2 -2
  94. package/dist-esm/ui/reactions.mjs +10 -2
  95. package/dist-esm/ui/reactions.mjs.map +2 -2
  96. package/dist-esm/ui/send-button.mjs +1 -1
  97. package/dist-esm/ui/send-button.mjs.map +2 -2
  98. package/package.json +3 -3
  99. package/src/canvas/canvas.css +25 -25
  100. package/src/canvas/comment-body.tsx +1 -1
  101. package/src/canvas/comment-render.test.ts +1 -1
  102. package/src/canvas/comments-filter-menu.tsx +1 -1
  103. package/src/canvas/comments-overflow-menu.tsx +3 -3
  104. package/src/canvas/comments-overlay.tsx +109 -76
  105. package/src/canvas/comments-sidebar.tsx +2 -2
  106. package/src/clustering/runtime.test.ts +183 -7
  107. package/src/clustering/runtime.ts +164 -15
  108. package/src/ui/avatar.tsx +9 -2
  109. package/src/ui/byline.tsx +4 -4
  110. package/src/ui/comment-card.tsx +3 -3
  111. package/src/ui/comment-composer.tsx +49 -30
  112. package/src/ui/comment-mention.ts +2 -2
  113. package/src/ui/comment-pin.tsx +5 -1
  114. package/src/ui/comment-text.tsx +1 -1
  115. package/src/ui/comment-thread.tsx +8 -6
  116. package/src/ui/comments-list.tsx +16 -12
  117. package/src/ui/comments.css +106 -106
  118. package/src/ui/count-badge.tsx +1 -1
  119. package/src/ui/empty-state.tsx +3 -3
  120. package/src/ui/mention-list.tsx +8 -8
  121. package/src/ui/mention-suggestion.tsx +3 -3
  122. package/src/ui/mention.tsx +1 -1
  123. package/src/ui/reaction.tsx +6 -3
  124. package/src/ui/reactions.tsx +6 -2
  125. package/src/ui/send-button.tsx +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/comments-overlay.tsx"],
4
- "sourcesContent": ["import {\n\tmemo,\n\ttype CSSProperties,\n\ttype PointerEvent as ReactPointerEvent,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport {\n\ttype BoxModel,\n\tcreateComment,\n\tcreateCommentThread,\n\tEditor,\n\tgetFirstCharacter,\n\treact,\n\tTLComment,\n\tTLCommentId,\n\tTLCommentThread,\n\tTLRichText,\n\tTldrawUiIcon,\n\tuseContainer,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n\tVecLike,\n} from 'tldraw'\nimport { computeClusterTable } from '../clustering/computeClusterTable'\nimport { type ClusterRuntime, createClusterRuntime } from '../clustering/runtime'\nimport type { ClusterNode, ClusterTable, MergeEvent } from '../clustering/types'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentPin } from '../ui/comment-pin'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CountBadge } from '../ui/count-badge'\nimport { MentionMember } from '../ui/mention-list'\nimport { isMentionPickerOpen } from '../ui/mention-suggestion'\nimport { collectClusterLeaves } from './cluster-input'\nimport { CommentBody } from './comment-body'\nimport { UNKNOWN_AUTHOR } from './comment-render'\nimport { getCommentRecord, putCommentRecords, removeCommentRecords } from './comment-store'\nimport { PendingComment } from './comment-tool'\nimport { useCommentThreads, useThreadComments } from './hooks'\nimport { useCommentingEnabled } from './license'\nimport {\n\ttype CommentingComponents,\n\ttype CommentingOptions,\n\tgetCommentingOptions,\n\tuseCommentingOptions,\n} from './options'\nimport {\n\tDEFAULT_REGION_COMMENT_OPTIONS,\n\tRegionCommentOptions,\n\tsetRegionCommentOptions,\n} from './region-options'\nimport {\n\tcommentsHidden,\n\tcommitCommentMutation,\n\topenThreadId,\n\tpendingComment,\n\tregionDraft,\n\ttoggleCommentsHidden,\n\tusePendingComment,\n} from './state'\nimport { anchorPagePoint, regionPinPoint, shapeAnchorAt } from './thread-state'\n\n/**\n * A ready-to-use comments layer for a tldraw canvas: pins each thread at its anchor, opens a\n * thread popover (with a reply composer) on click, and shows a composer where the comment tool\n * placed a new thread. Reads/writes comment records straight from `editor.store`.\n *\n * It's meant as the batteries-included default \u2014 every visible piece is a lever (the `CommentBody`\n * and `PinContent` slots on `CommentTool.configure({ components })`), and the pieces it composes\n * (`CommentPin`, `CommentThread`, `CommentComposer`, the hooks, the tool) are all exported, so a\n * consumer can rebuild this from parts instead.\n * @public\n */\nexport interface CanvasCommentsProps {\n\t/** The signed-in user's id, or null for a read-only viewer. Only a signed-in user composes. */\n\tcurrentUserId: string | null\n\t/** Map an author id to a display name, or `undefined` when the id can't be named. */\n\tresolveName(id: string): string | undefined\n\t/** Called after any comment (a new thread's first comment, or a reply) is posted. */\n\tonPostComment?(comment: TLComment): void\n\t/** Whether a comment is unread for the current user (return true for unread). */\n\tisCommentUnread?(commentId: TLCommentId): boolean\n\t/**\n\t * Called for each unread comment shown to the user in an open thread popover, so hosts can\n\t * record a read receipt. Needs `isCommentUnread` to know what's unread.\n\t */\n\tonCommentRead?(commentId: TLCommentId): void\n\t/** Resolve the members matching an `@`-query in the composers (sync or async). */\n\tgetMentionSuggestions?(query: string): MentionMember[] | Promise<MentionMember[]>\n\t/** Override a mention-picker row's content. */\n\trenderMentionSuggestion?(member: MentionMember): ReactNode\n\t/** Where imprecise shape pins sit \u2014 a normalized (0\u20131) spot within the shape. Default top-right. */\n\timpreciseShapeAnchor?: { x: number; y: number }\n\t/** Region comment behaviour. Region is off by default \u2014 omit this for click-only point/shape\n\t * comments. Anything unset falls back to {@link DEFAULT_REGION_COMMENT_OPTIONS}. */\n\tregionOptions?: Partial<RegionCommentOptions>\n}\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\nconst initialOf = (name: string): string => (getFirstCharacter(name.trim()) || '?').toUpperCase()\nconst CLUSTER_FADE_MS = 150\n/** Duration of the click-a-badge zoom-to-split animation. */\nconst CLUSTER_EXPAND_ZOOM_MS = 450\n\n/** The leading element for the placement composer \u2014 the comment pin's shape, but a pencil\n * instead of an initial, marking an unsent draft. */\nconst draftAvatar = (\n\t<CommentPin>\n\t\t<svg\n\t\t\tviewBox=\"0 0 24 24\"\n\t\t\twidth=\"15\"\n\t\t\theight=\"15\"\n\t\t\tfill=\"none\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth=\"2\"\n\t\t\tstrokeLinecap=\"round\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t<path d=\"M12 20h9\" />\n\t\t\t<path d=\"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z\" />\n\t\t</svg>\n\t</CommentPin>\n)\n\nfunction toCardProps(\n\tcomment: TLComment,\n\tprops: CanvasCommentsProps,\n\tcomponents: CommentingComponents\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={props.resolveName} />\n\t)\n\treturn {\n\t\tauthor: props.resolveName(comment.authorId) ?? UNKNOWN_AUTHOR,\n\t\tbody,\n\t\tdate: new Date(comment.createdAt).toISOString(),\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited: comment.editedAt != null,\n\t}\n}\n\n/** @public @react */\nexport function CanvasComments(props: CanvasCommentsProps) {\n\t// Gate the whole layer on the license before doing any work. The inner component holds all the\n\t// other hooks, so mounting/unmounting it as the license resolves keeps hook order stable here.\n\tconst commentingEnabled = useCommentingEnabled()\n\tif (!commentingEnabled) return null\n\treturn <CanvasCommentsLayer {...props} />\n}\n\nfunction CanvasCommentsLayer(props: CanvasCommentsProps) {\n\tconst editor = useEditor()\n\tconst options = useCommentingOptions()\n\tconst container = useContainer()\n\t// Merge the consumer's region options over the disabled defaults and publish them for this editor,\n\t// so the comment tool (which has no props) reads the same per-instance config.\n\tconst regionOptions = useMemo(\n\t\t() => ({ ...DEFAULT_REGION_COMMENT_OPTIONS, ...props.regionOptions }),\n\t\t[props.regionOptions]\n\t)\n\tuseEffect(() => setRegionCommentOptions(editor, regionOptions), [editor, regionOptions])\n\tconst layerRef = useRef<HTMLDivElement>(null)\n\t// Over the pins and cluster badges, wheel and hover pass through to the canvas beneath (these\n\t// events bubble up from the pointer-interactive markers to this layer root).\n\tusePassThroughWheelEvents(layerRef)\n\tusePassThroughMouseOverEvents(layerRef)\n\tconst deepLinkHandled = useRef(false)\n\tconst threads = useCommentThreads(editor)\n\tconst pending = usePendingComment()\n\tconst openId = useValue('open thread id', () => openThreadId.get(editor), [editor])\n\tconst impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor\n\t// Threads whose anchor has moved (by any means \u2014 drag, nudge, align, undo, a collaborator)\n\t// since the rendered clustering was built. They pop out of clustering and render as live pins,\n\t// and only rejoin at the next zoom event, when everything re-clusters anyway.\n\tconst [movedThreadIds, setMovedThreadIds] = useState<ReadonlySet<string>>(EMPTY_SET)\n\tconst adoptOnRebuild = useRef(false)\n\tconst clusterLeaves = useValue(\n\t\t'comment cluster leaves',\n\t\t() =>\n\t\t\tcollectClusterLeaves(\n\t\t\t\teditor,\n\t\t\t\tthreads.filter((thread) => !movedThreadIds.has(thread.id)),\n\t\t\t\topenThreadId.get(editor),\n\t\t\t\timpreciseShapeAnchor\n\t\t\t),\n\t\t[editor, threads, impreciseShapeAnchor, movedThreadIds]\n\t)\n\tconst clusterZoomBounds = useValue(\n\t\t'comment cluster zoom bounds',\n\t\t() => getClusterZoomBounds(editor),\n\t\t[editor]\n\t)\n\tconst latestModel = useMemo(() => {\n\t\tconst table = computeClusterTable(clusterLeaves, clusterZoomBounds)\n\t\tconst runtime = createClusterRuntime(table)\n\t\truntime.seed(editor.getZoomLevel())\n\t\treturn { runtime, table }\n\t}, [clusterLeaves, clusterZoomBounds, editor])\n\t// Re-clustering only applies while zooming: a rebuilt model (thread added, moved, or closed)\n\t// is held as `latestModel` and adopted on the next zoom change, so pins never re-flow into\n\t// clusters under a static camera. Until adoption, threads the rendered model doesn't know\n\t// about show as plain unclustered pins (`orphanThreads`). Exception: a rebuild that *removed*\n\t// leaves (thread deleted or opened, page changed) is adopted immediately, so stale pins and\n\t// badge counts never linger.\n\tconst [renderedModel, setRenderedModel] = useState(latestModel)\n\tlet clusterModel = renderedModel\n\tif (\n\t\trenderedModel !== latestModel &&\n\t\t(adoptOnRebuild.current || hasRemovedLeaves(renderedModel.table, latestModel.table))\n\t) {\n\t\tadoptOnRebuild.current = false\n\t\t// Carryover seed: events inside their hysteresis band inherit the outgoing partition's\n\t\t// merged/unmerged state instead of the geometric-mean tiebreak, so untouched pins never\n\t\t// snap together (or apart) just because the model was swapped. Idempotent, so safe to\n\t\t// run during render.\n\t\tlatestModel.runtime.seedFrom(editor.getZoomLevel(), renderedModel.runtime.getVisible())\n\t\tsetRenderedModel(latestModel)\n\t\tclusterModel = latestModel\n\t}\n\t// Pop-out detection: a leaf folded inside a badge can't follow its anchor (the badge position\n\t// is baked into the model), so when its live position drifts from the baked one it ghosts.\n\t// Marking it moved excludes it from the cluster input, which reads as a removal above and\n\t// re-clusters the rest of its pile immediately; the pin itself renders live below.\n\tconst newlyMovedIds = findMovedClusteredLeafIds(clusterModel, latestModel)\n\tif (newlyMovedIds.length > 0) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.debug(`[comments] pins popped out of clustering: ${newlyMovedIds.join(', ')}`)\n\t\tconst next = new Set(movedThreadIds)\n\t\tfor (const id of newlyMovedIds) next.add(id)\n\t\tsetMovedThreadIds(next)\n\t}\n\t// Moved pins rejoin clustering on the next zoom-out motion: clear the set (so the rebuild\n\t// includes them again) and adopt that rebuild immediately instead of deferring it. Zooming in\n\t// never folds pins into clusters \u2014 merging is a zoom-out-only move, matching the runtime.\n\tuseEffect(() => {\n\t\tif (movedThreadIds.size === 0) return\n\t\tlet lastZoom = editor.getZoomLevel()\n\t\treturn react('rejoin moved comment pins on zoom out', () => {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tconst prevZoom = lastZoom\n\t\t\tlastZoom = zoom\n\t\t\tif (zoom >= prevZoom) return\n\t\t\tadoptOnRebuild.current = true\n\t\t\tsetMovedThreadIds(EMPTY_SET)\n\t\t})\n\t}, [movedThreadIds, editor])\n\t// Adopt a pending rebuild only on zoom-out motion: folding deferred additions into clusters is\n\t// a merge, and merging only happens while zooming out. While zooming in, the stale table still\n\t// splits correctly on its own (split thresholds are direction-safe by the hysteresis invariant).\n\tuseEffect(() => {\n\t\tif (clusterModel === latestModel) return\n\t\tlet lastZoom = editor.getZoomLevel()\n\t\treturn react('adopt pending cluster model on zoom out', () => {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tconst prevZoom = lastZoom\n\t\t\tlastZoom = zoom\n\t\t\tif (zoom >= prevZoom) return\n\t\t\tlatestModel.runtime.seedFrom(zoom, clusterModel.runtime.getVisible())\n\t\t\tsetRenderedModel(latestModel)\n\t\t})\n\t}, [clusterModel, latestModel, editor])\n\tconst orphanThreads = useMemo(() => {\n\t\tif (clusterModel === latestModel) return []\n\t\tconst renderedIds = new Set(clusterModel.table.leaves.map((leaf) => leaf.id))\n\t\tconst latestIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id))\n\t\treturn threads.filter((thread) => latestIds.has(thread.id) && !renderedIds.has(thread.id))\n\t}, [clusterModel, latestModel, threads])\n\tconst movedThreads = useMemo(\n\t\t() => threads.filter((thread) => movedThreadIds.has(thread.id) && thread.id !== openId),\n\t\t[threads, movedThreadIds, openId]\n\t)\n\t// Subscribe to the runtime cursor, not the raw zoom: onCamera runs on every zoom tick (two\n\t// O(1) threshold checks against the event table) but returns the same integer until a merge\n\t// or split event actually fires \u2014 so this component only re-renders on cluster changes, not\n\t// on every camera frame.\n\tconst clusterCursor = useValue(\n\t\t'comment cluster cursor',\n\t\t() => {\n\t\t\tclusterModel.runtime.onCamera(editor.getZoomLevel())\n\t\t\treturn clusterModel.runtime.k\n\t\t},\n\t\t[clusterModel, editor]\n\t)\n\tconst visibleNodes = useMemo(() => {\n\t\tconst nodes = Array.from(clusterModel.runtime.getVisible().values())\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.debug(\n\t\t\t`[comments] cluster cursor k=${clusterCursor} \u2192 re-rendering ${nodes.length} visible nodes`\n\t\t)\n\t\treturn nodes\n\t}, [clusterModel, clusterCursor])\n\tconst fadeNodes = useFadeVisibleNodes(visibleNodes, clusterModel)\n\tconst threadsById = useMemo(\n\t\t() => new Map<string, TLCommentThread>(threads.map((thread) => [thread.id, thread])),\n\t\t[threads]\n\t)\n\tconst openThread = openId ? threadsById.get(openId) : null\n\tconst hidden = useValue('comments hidden', () => commentsHidden.get(editor), [editor])\n\n\t// Reset the transient UI state (open thread, half-placed comment) when this unmounts.\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\topenThreadId.set(editor, null)\n\t\t\tpendingComment.set(editor, null)\n\t\t}\n\t}, [editor])\n\n\t// Open the thread named by a deep link (?comment=<thread or comment id>). If the thread is\n\t// currently inside a cluster, zoom to the first split that reveals it before opening.\n\tuseEffect(() => {\n\t\tif (deepLinkHandled.current) return\n\t\tconst id = new URLSearchParams(window.location.search).get('comment')\n\t\tif (!id) {\n\t\t\tdeepLinkHandled.current = true\n\t\t\treturn\n\t\t}\n\n\t\tconst record = getCommentRecord(editor, id)\n\t\tif (!record) return\n\n\t\tlet thread: TLCommentThread | undefined\n\t\tif (record.typeName === 'comment') {\n\t\t\tthread = threadsById.get(record.threadId)\n\t\t} else {\n\t\t\tthread = record\n\t\t}\n\t\tif (!thread) return\n\n\t\tdeepLinkHandled.current = true\n\t\trevealDeepLinkedThread(\n\t\t\teditor,\n\t\t\tthread,\n\t\t\tclusterModel.table,\n\t\t\tclusterZoomBounds,\n\t\t\toptions,\n\t\t\timpreciseShapeAnchor\n\t\t)\n\t\topenThreadId.set(editor, thread.id)\n\t}, [clusterModel.table, clusterZoomBounds, editor, threadsById, impreciseShapeAnchor, options])\n\n\t// Clicking a badge zooms to just past the zoom at which that cluster first unclusters,\n\t// centered on its centroid. The event that created a visible cluster is the event that splits\n\t// it, and (by the table's sort + monotone thresholds) it has the smallest zSplit of everything\n\t// applied inside it \u2014 so its zSplit is exactly the first split within those comments. The\n\t// animated zoom-in then drives the runtime cursor like any manual zoom, so the badge splits\n\t// (and can be drilled into further) with no extra bookkeeping.\n\tconst zoomToClusterSplit = useCallback(\n\t\t(node: ClusterNode) => {\n\t\t\tconst event = clusterModel.table.events.find((e) => e.result.id === node.id)\n\t\t\tif (!event || !Number.isFinite(event.zSplit)) return\n\t\t\tconst zoom = clamp(\n\t\t\t\tevent.zSplit * options.clusterSplitZoomFactor,\n\t\t\t\tclusterZoomBounds.minZoom,\n\t\t\t\tclusterZoomBounds.maxZoom\n\t\t\t)\n\t\t\tcenterOnPointAtZoom(editor, node.centroid, zoom, CLUSTER_EXPAND_ZOOM_MS)\n\t\t},\n\t\t[clusterModel, clusterZoomBounds, editor, options]\n\t)\n\n\t// Escape collapses the open thread. Capture-phase + stopPropagation so it runs ahead of the\n\t// editor (which would otherwise cancel the current tool or clear the selection). If a comment is\n\t// being edited, let its own Escape handler exit edit mode first, keeping the thread open.\n\tuseEffect(() => {\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || openThreadId.get(editor) === null) return\n\t\t\t// The mention picker owns Escape while it's open \u2014 let it dismiss the roster alone.\n\t\t\tif (isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (target && target.closest('.cmt-editing')) return\n\t\t\topenThreadId.set(editor, null)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdocument.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => document.removeEventListener('keydown', onKeyDown, true)\n\t}, [editor])\n\n\t// Shift+C toggles comment-pin visibility on the canvas (matching Figma). Skipped while typing so\n\t// it never fires from inside a composer. Physical `KeyC` (layout-independent) with shift only.\n\tuseEffect(() => {\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.code !== 'KeyC' || !e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (target && target.closest('input, textarea, [contenteditable=\"true\"]')) return\n\t\t\ttoggleCommentsHidden(editor)\n\t\t\te.preventDefault()\n\t\t}\n\t\tdocument.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => document.removeEventListener('keydown', onKeyDown, true)\n\t}, [editor])\n\n\t// Hidden: the whole canvas layer (pins, open popover, pending composer) is withheld. The signal\n\t// is read above so this component stays mounted and its shortcut/Escape effects keep running.\n\tif (hidden) return null\n\n\t// Render into the container (above the panels' stacking context) so the pins and popovers\n\t// live in the UI layer rather than being clipped by the canvas layer.\n\treturn createPortal(\n\t\t<div ref={layerRef} className=\"cmt-canvas-layer\">\n\t\t\t{options.enableClustering ? (\n\t\t\t\t<>\n\t\t\t\t\t{fadeNodes.map(({ node, phase }) => {\n\t\t\t\t\t\tlet content: ReactNode\n\t\t\t\t\t\tif (node.count === 1) {\n\t\t\t\t\t\t\tconst thread = threadsById.get(node.id)\n\t\t\t\t\t\t\tif (!thread) return null\n\t\t\t\t\t\t\tcontent = (\n\t\t\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcontent = <ClusterBadge editor={editor} node={node} onExpand={zoomToClusterSplit} />\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={`cluster-fade:${node.id}`} className={clusterFadeClassName(phase)}>\n\t\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t\t{orphanThreads.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t\t{movedThreads.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\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\t\t// Clustering off: every thread renders as its own live pin (each returns null when it's\n\t\t\t\t// not on the current page or its anchor is missing). The open thread is excluded here and\n\t\t\t\t// rendered once below, mirroring how the clustering path keeps it out of the cluster leaves \u2014\n\t\t\t\t// otherwise it would mount a second, stacked pin.\n\t\t\t\tthreads\n\t\t\t\t\t.filter((thread) => thread.id !== openId)\n\t\t\t\t\t.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))\n\t\t\t)}\n\t\t\t{openThread && (\n\t\t\t\t<ThreadPin\n\t\t\t\t\tkey={`open:${openThread.id}`}\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tthread={openThread}\n\t\t\t\t\t{...props}\n\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<RegionDraftBox editor={editor} />\n\t\t\t{/* Keep the region visible while composing \u2014 the drag draft is gone by now, and no thread\n\t\t\t exists yet, so the pending anchor is what shows the area under the open composer. */}\n\t\t\t{pending?.anchor.type === 'region' && <RegionBox editor={editor} box={pending.anchor} />}\n\t\t\t{pending && props.currentUserId && (\n\t\t\t\t<PendingComposer editor={editor} pending={pending} {...props} />\n\t\t\t)}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n\nconst EMPTY_SET: ReadonlySet<string> = new Set()\nconst MOVED_LEAF_EPSILON = 1e-6\ntype ClusterFadePhase = 'entering' | 'present' | 'exiting'\n\ninterface ClusterFadeNode {\n\tnode: ClusterNode\n\tphase: ClusterFadePhase\n}\n\nfunction useFadeVisibleNodes(\n\tnodes: readonly ClusterNode[],\n\tresetKey: { runtime: ClusterRuntime; table: ClusterTable }\n): ClusterFadeNode[] {\n\tconst resetKeyRef = useRef(resetKey)\n\tconst didReset = resetKeyRef.current !== resetKey\n\tif (didReset) {\n\t\tresetKeyRef.current = resetKey\n\t}\n\n\tconst [fadeNodes, setFadeNodes] = useState<ClusterFadeNode[]>(() => toPresentFadeNodes(nodes))\n\tconst renderedNodes = didReset ? toPresentFadeNodes(nodes) : fadeNodes\n\n\tuseEffect(() => {\n\t\tsetFadeNodes(toPresentFadeNodes(nodes))\n\t\t// Resets only on a new model (resetKey); node-list changes within the same model are\n\t\t// handled by the reconcile effect below, which fades entries in/out instead of snapping.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [resetKey])\n\n\tuseEffect(() => {\n\t\tif (didReset) return\n\t\tsetFadeNodes((previous) => reconcileFadeNodes(previous, nodes))\n\t}, [didReset, nodes])\n\n\tconst hasEntering = renderedNodes.some((item) => item.phase === 'entering')\n\tuseEffect(() => {\n\t\tif (!hasEntering) return\n\t\tconst frame = requestClusterFadeFrame(() => {\n\t\t\tsetFadeNodes((previous) =>\n\t\t\t\tprevious.map((item) => (item.phase === 'entering' ? { ...item, phase: 'present' } : item))\n\t\t\t)\n\t\t})\n\t\treturn () => cancelClusterFadeFrame(frame)\n\t}, [hasEntering, renderedNodes])\n\n\tconst hasExiting = renderedNodes.some((item) => item.phase === 'exiting')\n\tuseEffect(() => {\n\t\tif (!hasExiting) return\n\t\tconst timeout = window.setTimeout(() => {\n\t\t\tsetFadeNodes((previous) => previous.filter((item) => item.phase !== 'exiting'))\n\t\t}, CLUSTER_FADE_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [hasExiting, renderedNodes])\n\n\treturn renderedNodes\n}\n\nfunction toPresentFadeNodes(nodes: readonly ClusterNode[]): ClusterFadeNode[] {\n\treturn nodes.map((node) => ({ node, phase: 'present' }))\n}\n\nfunction reconcileFadeNodes(\n\tprevious: readonly ClusterFadeNode[],\n\tnextNodes: readonly ClusterNode[]\n): ClusterFadeNode[] {\n\tconst previousById = new Map(previous.map((item) => [item.node.id, item]))\n\tconst nextIds = new Set(nextNodes.map((node) => node.id))\n\tconst next: ClusterFadeNode[] = []\n\n\tfor (const node of nextNodes) {\n\t\tconst previousItem = previousById.get(node.id)\n\t\tnext.push({\n\t\t\tnode,\n\t\t\tphase:\n\t\t\t\tpreviousItem && previousItem.phase !== 'exiting'\n\t\t\t\t\t? previousItem.phase\n\t\t\t\t\t: previousItem\n\t\t\t\t\t\t? 'present'\n\t\t\t\t\t\t: 'entering',\n\t\t})\n\t}\n\n\tfor (const item of previous) {\n\t\tif (nextIds.has(item.node.id)) continue\n\t\tnext.push(item.phase === 'exiting' ? item : { ...item, phase: 'exiting' })\n\t}\n\n\treturn next\n}\n\nfunction requestClusterFadeFrame(callback: FrameRequestCallback): number {\n\tif (typeof requestAnimationFrame === 'function') return requestAnimationFrame(callback)\n\treturn window.setTimeout(() => callback(0), 16)\n}\n\nfunction cancelClusterFadeFrame(frame: number) {\n\tif (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)\n\telse window.clearTimeout(frame)\n}\n\nfunction clusterFadeClassName(phase: ClusterFadePhase): string {\n\treturn `cmt-cluster-fade cmt-cluster-fade--${phase}`\n}\n\n/**\n * Leaves folded inside a badge whose live anchor no longer matches the position the rendered\n * model was built with. Visible (unclustered) leaf pins track their anchor live, so they can\n * stay deferred; a badge can't follow a member, so these must pop out of clustering.\n */\nfunction findMovedClusteredLeafIds(\n\trendered: { runtime: ClusterRuntime; table: ClusterTable },\n\tlatest: { table: ClusterTable }\n): string[] {\n\tif (rendered.table === latest.table) return []\n\tconst visible = rendered.runtime.getVisible()\n\tconst latestById = new Map(latest.table.leaves.map((leaf) => [leaf.id, leaf]))\n\tconst moved: string[] = []\n\tfor (const leaf of rendered.table.leaves) {\n\t\tif (visible.has(leaf.id)) continue\n\t\tconst current = latestById.get(leaf.id)\n\t\tif (!current) continue\n\t\tif (\n\t\t\tMath.abs(current.centroid.x - leaf.centroid.x) > MOVED_LEAF_EPSILON ||\n\t\t\tMath.abs(current.centroid.y - leaf.centroid.y) > MOVED_LEAF_EPSILON\n\t\t) {\n\t\t\tmoved.push(leaf.id)\n\t\t}\n\t}\n\treturn moved\n}\n\nfunction hasRemovedLeaves(rendered: ClusterTable, latest: ClusterTable): boolean {\n\tif (rendered.leaves.length === 0) return false\n\tconst latestIds = new Set(latest.leaves.map((leaf) => leaf.id))\n\treturn rendered.leaves.some((leaf) => !latestIds.has(leaf.id))\n}\n\nfunction getClusterZoomBounds(editor: Editor): { minZoom: number; maxZoom: number } {\n\tconst cameraOptions = editor.getCameraOptions()\n\tconst baseZoom = cameraOptions.constraints ? editor.getBaseZoom() : 1\n\tconst zoomSteps = cameraOptions.zoomSteps\n\treturn {\n\t\tminZoom: zoomSteps[0] * baseZoom,\n\t\tmaxZoom: zoomSteps[zoomSteps.length - 1] * baseZoom,\n\t}\n}\n\nfunction revealDeepLinkedThread(\n\teditor: Editor,\n\tthread: TLCommentThread,\n\ttable: ClusterTable,\n\tzoomBounds: { minZoom: number; maxZoom: number },\n\toptions: CommentingOptions,\n\timpreciseShapeAnchor: { x: number; y: number }\n) {\n\tif (thread.pageId !== editor.getCurrentPageId()) {\n\t\teditor.setCurrentPage(thread.pageId as any)\n\t}\n\n\t// Match where the rendered pin sits (resolved prop-or-option), so the camera centers on the pin.\n\tconst point = anchorPagePoint(editor, thread.anchor, impreciseShapeAnchor)\n\tif (!point) return\n\n\t// With clustering off the pin always renders individually, so skip the zoom-to-split (its cluster\n\t// badge never exists) and just center on the pin.\n\tif (options.enableClustering) {\n\t\tconst parentEvent = findDirectParentEvent(table, thread.id)\n\t\tif (\n\t\t\tparentEvent &&\n\t\t\tNumber.isFinite(parentEvent.zSplit) &&\n\t\t\tparentEvent.zSplit <= zoomBounds.maxZoom\n\t\t) {\n\t\t\tconst zoom = clamp(\n\t\t\t\tparentEvent.zSplit * options.clusterSplitZoomFactor,\n\t\t\t\tzoomBounds.minZoom,\n\t\t\t\tzoomBounds.maxZoom\n\t\t\t)\n\t\t\tcenterOnPointAtZoom(editor, point, zoom)\n\t\t\treturn\n\t\t}\n\t}\n\n\teditor.centerOnPoint(point, { animation: { duration: 200 } })\n}\n\nfunction findDirectParentEvent(table: ClusterTable, threadId: string): MergeEvent | undefined {\n\treturn table.events.find((event) => event.children.some((child) => child.id === threadId))\n}\n\nfunction centerOnPointAtZoom(\n\teditor: Editor,\n\tpoint: { x: number; y: number },\n\tzoom: number,\n\tduration = 200\n) {\n\tconst viewport = editor.getViewportScreenBounds()\n\teditor.setCamera(\n\t\t{\n\t\t\tx: viewport.w / (2 * zoom) - point.x,\n\t\t\ty: viewport.h / (2 * zoom) - point.y,\n\t\t\tz: zoom,\n\t\t},\n\t\t{ animation: { duration } }\n\t)\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.max(min, Math.min(max, value))\n}\n\n// Memoized: cluster nodes and thread records are identity-stable while unchanged, so pins and\n// badges skip re-rendering when the parent re-renders for reasons that don't concern them\n// (leaf recomputes during shape drags, partition changes elsewhere). Camera tracking still\n// works \u2014 each component subscribes to its own viewport position via signals, not via props.\nconst ClusterBadge = memo(function ClusterBadge({\n\teditor,\n\tnode,\n\tonExpand,\n}: {\n\teditor: Editor\n\tnode: ClusterNode\n\tonExpand(node: ClusterNode): void\n}) {\n\tconst point = useValue(\n\t\t'cluster badge point',\n\t\t() => {\n\t\t\tconst pagePoint = editor.pageToViewport(node.centroid)\n\t\t\tif (!isInInflatedViewport(editor, pagePoint)) return null\n\t\t\treturn pagePoint\n\t\t},\n\t\t[editor, node]\n\t)\n\n\tif (!point) return null\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"cmt-canvas-cluster\"\n\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\tonPointerDown={stop}\n\t\t\tonClick={(e) => {\n\t\t\t\te.stopPropagation()\n\t\t\t\tonExpand(node)\n\t\t\t}}\n\t\t>\n\t\t\t<CountBadge count={node.count} />\n\t\t</div>\n\t)\n})\n\nfunction isInInflatedViewport(editor: Editor, point: { x: number; y: number }): boolean {\n\tconst viewport = editor.getViewportScreenBounds()\n\tconst margin = getCommentingOptions(editor).clusterCullMargin\n\treturn (\n\t\tpoint.x >= -margin &&\n\t\tpoint.y >= -margin &&\n\t\tpoint.x <= viewport.w + margin &&\n\t\tpoint.y <= viewport.h + margin\n\t)\n}\n\n/** The open thread's popover, portaled above the UI panels. Over it, wheel and hover events pass\n * through to the canvas (unless the popover is scrolling its own content), like tldraw's panels. */\nfunction ThreadPopover({\n\tcontainer,\n\tstyle,\n\tchildren,\n}: {\n\tcontainer: HTMLElement\n\tstyle: CSSProperties\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\tusePassThroughMouseOverEvents(ref)\n\treturn createPortal(\n\t\t<div ref={ref} className=\"cmt-canvas-popover\" style={style} onPointerDown={stop}>\n\t\t\t{children}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n\n/** A dashed rectangle over a region anchor's bounds, in viewport space. Sits in the canvas layer as\n * a sibling of the pins. `pointer-events` stays off (canvas interaction passes through) unless\n * `movable`, in which case dragging the body translates the region \u2014 previews live, commits on drop. */\nfunction RegionBox({\n\teditor,\n\tbox,\n\tmovable,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\tmovable?: boolean\n\tonPreview?(bounds: BoxModel | null): void\n\tonCommit?(bounds: BoxModel): void\n}) {\n\tconst rect = useValue(\n\t\t'region rect',\n\t\t() => {\n\t\t\t// Position from the page\u2192viewport top-left; screen size scales with zoom, page size doesn't.\n\t\t\tconst topLeft = editor.pageToViewport({ x: box.x, y: box.y })\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\treturn { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h]\n\t)\n\t// The grab point and the box at grab time, captured so the drag translates by a stable delta even\n\t// as the box prop reflows under the live preview.\n\tconst grabRef = useRef<{ page: VecLike; box: BoxModel } | null>(null)\n\tconst translated = (e: ReactPointerEvent<HTMLDivElement>): BoxModel => {\n\t\tconst g = grabRef.current!\n\t\tconst p = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\treturn { ...g.box, x: g.box.x + (p.x - g.page.x), y: g.box.y + (p.y - g.page.y) }\n\t}\n\tconst startMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tgrabRef.current = { page: editor.screenToPage({ x: e.clientX, y: e.clientY }), box }\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (grabRef.current) onPreview?.(translated(e))\n\t}\n\tconst endMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (!grabRef.current) return\n\t\tconst bounds = translated(e)\n\t\tgrabRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit?.(bounds)\n\t}\n\treturn (\n\t\t<div\n\t\t\tclassName={movable ? 'cmt-canvas-region cmt-canvas-region--movable' : 'cmt-canvas-region'}\n\t\t\tstyle={rect}\n\t\t\tonPointerDown={movable ? startMove : undefined}\n\t\t\tonPointerMove={movable ? onMove : undefined}\n\t\t\tonPointerUp={movable ? endMove : undefined}\n\t\t/>\n\t)\n}\n\n/** The live region being dragged out by the comment tool, or nothing when not dragging. */\nfunction RegionDraftBox({ editor }: { editor: Editor }) {\n\tconst box = useValue('region draft', () => regionDraft.get(editor), [editor])\n\tif (!box) return null\n\treturn <RegionBox editor={editor} box={box} />\n}\n\n// A resize handle's normalized 0\u20131 spot on the box, and its cursor. An axis at 0.5 (a side midpoint)\n// is *not* controlled by that handle: corners resize both axes, edges resize only their own.\ninterface RegionHandle {\n\tx: number\n\ty: number\n\tcursor: string\n}\n\n// The four corners (both axes) and the four side midpoints (one axis each).\nconst REGION_CORNERS: readonly RegionHandle[] = [\n\t{ x: 0, y: 0, cursor: 'nwse-resize' },\n\t{ x: 1, y: 0, cursor: 'nesw-resize' },\n\t{ x: 0, y: 1, cursor: 'nesw-resize' },\n\t{ x: 1, y: 1, cursor: 'nwse-resize' },\n]\nconst REGION_EDGES: readonly RegionHandle[] = [\n\t{ x: 0.5, y: 0, cursor: 'ns-resize' },\n\t{ x: 1, y: 0.5, cursor: 'ew-resize' },\n\t{ x: 0.5, y: 1, cursor: 'ns-resize' },\n\t{ x: 0, y: 0.5, cursor: 'ew-resize' },\n]\n\n// Screen-space slack around a region's bounds within which its box and handles stay revealed, so\n// the handles (which sit on the edge) are comfortably reachable.\nconst REGION_HANDLE_MARGIN_PX = 12\n\n/** Resize `box` by dragging `handle` to `cursor` (page coords). Each controlled axis spans from the\n * handle's fixed opposite edge to the cursor (normalized, so dragging past it flips); an axis the\n * handle doesn't control (a midpoint, at 0.5) keeps its original position and size. */\nfunction resizeRegion(box: BoxModel, handle: RegionHandle, cursor: VecLike): BoxModel {\n\tconst controlsX = handle.x !== 0.5\n\tconst controlsY = handle.y !== 0.5\n\tconst fixedX = box.x + (1 - handle.x) * box.w\n\tconst fixedY = box.y + (1 - handle.y) * box.h\n\treturn {\n\t\tx: controlsX ? Math.min(fixedX, cursor.x) : box.x,\n\t\ty: controlsY ? Math.min(fixedY, cursor.y) : box.y,\n\t\tw: controlsX ? Math.abs(cursor.x - fixedX) : box.w,\n\t\th: controlsY ? Math.abs(cursor.y - fixedY) : box.h,\n\t}\n}\n\n/** Draggable handles that resize a region \u2014 corners (both axes) or edges (one axis), per the resize\n * option. Previews live, commits on release. */\nfunction RegionResizeHandles({\n\teditor,\n\tbox,\n\thandles,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\thandles: readonly RegionHandle[]\n\tonPreview(bounds: BoxModel | null): void\n\tonCommit(bounds: BoxModel): void\n}) {\n\t// The box at pointer-down, captured so the box prop reflowing under the live preview doesn't move\n\t// the fixed edges mid-drag.\n\tconst boxRef = useRef<BoxModel | null>(null)\n\tconst points = useValue(\n\t\t'region handle points',\n\t\t() =>\n\t\t\thandles.map((h) => {\n\t\t\t\tconst p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })\n\t\t\t\treturn { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }\n\t\t\t}),\n\t\t[editor, box.x, box.y, box.w, box.h, handles]\n\t)\n\tconst startResize = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tboxRef.current = box\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst resizedTo = (h: RegionHandle, e: ReactPointerEvent<HTMLDivElement>): BoxModel =>\n\t\tresizeRegion(boxRef.current!, h, editor.screenToPage({ x: e.clientX, y: e.clientY }))\n\tconst onResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (boxRef.current) onPreview(resizedTo(h, e))\n\t}\n\tconst endResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (!boxRef.current) return\n\t\tconst bounds = resizedTo(h, e)\n\t\tboxRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit(bounds)\n\t}\n\treturn (\n\t\t<>\n\t\t\t{points.map((h) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={h.key}\n\t\t\t\t\tclassName=\"cmt-canvas-region-handle\"\n\t\t\t\t\tstyle={{ left: h.left, top: h.top, cursor: h.cursor }}\n\t\t\t\t\tonPointerDown={startResize}\n\t\t\t\t\tonPointerMove={onResize(h)}\n\t\t\t\t\tonPointerUp={endResize(h)}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</>\n\t)\n}\n\nconst ThreadPin = memo(function ThreadPin({\n\teditor,\n\tthread,\n\tregionOptions,\n\t...props\n}: Omit<CanvasCommentsProps, 'regionOptions'> & {\n\teditor: Editor\n\tthread: TLCommentThread\n\tregionOptions: RegionCommentOptions\n}) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveName,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor\n\tconst container = useContainer()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\t// Only one thread's popover is open at a time \u2014 shared across pins via the atom.\n\tconst open = useValue('thread open', () => openThreadId.get(editor) === thread.id, [\n\t\teditor,\n\t\tthread.id,\n\t])\n\tconst [reply, setReply] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\t// While dragging the marker, its page point overrides the anchor's; committed on drop.\n\tconst [dragPagePoint, setDragPagePoint] = useState<{ x: number; y: number } | null>(null)\n\t// The live bounds while a corner handle is resizing the region, else null.\n\tconst [resizeBounds, setResizeBounds] = useState<BoxModel | null>(null)\n\t// Whether the pin marker is hovered \u2014 only consulted by the 'pin-hover' reveal mode.\n\tconst [pinHovered, setPinHovered] = useState(false)\n\t// The 'pointer' reveal mode: is the pointer within the region's bounds (plus a grab margin)?\n\t// Driven by pointer position, not DOM hover, so moving from anywhere in the region out to a corner\n\t// handle never loses the affordance \u2014 the box stays `pointer-events: none`.\n\tconst pointerInRegion = useValue(\n\t\t'pointer in region',\n\t\t() => {\n\t\t\tif (thread.anchor.type !== 'region' || thread.pageId !== editor.getCurrentPageId())\n\t\t\t\treturn false\n\t\t\tconst m = REGION_HANDLE_MARGIN_PX / editor.getZoomLevel()\n\t\t\tconst p = editor.inputs.getCurrentPagePoint()\n\t\t\tconst a = thread.anchor\n\t\t\treturn p.x >= a.x - m && p.x <= a.x + a.w + m && p.y >= a.y - m && p.y <= a.y + a.h + m\n\t\t},\n\t\t[editor, thread.anchor, thread.pageId]\n\t)\n\t// A region's box and handles are revealed while open or mid-resize, plus \u2014 per the reveal mode \u2014\n\t// while the pointer is within the region ('pointer') or the pin is hovered ('pin-hover').\n\tconst revealed =\n\t\topen ||\n\t\tresizeBounds != null ||\n\t\t(regionOptions.reveal === 'pointer' && pointerInRegion) ||\n\t\t(regionOptions.reveal === 'pin-hover' && pinHovered)\n\t// The resize handles: side midpoints ('edges'), or the corners other than the pin's ('corners').\n\tconst resizeHandles = useMemo(\n\t\t() =>\n\t\t\tregionOptions.resize === 'edges'\n\t\t\t\t? REGION_EDGES\n\t\t\t\t: REGION_CORNERS.filter(\n\t\t\t\t\t\t(c) => c.x !== regionOptions.pinCorner.x || c.y !== regionOptions.pinCorner.y\n\t\t\t\t\t),\n\t\t[regionOptions.resize, regionOptions.pinCorner]\n\t)\n\tconst dragRef = useRef<{ startX: number; startY: number; moved: boolean } | null>(null)\n\tconst markerRef = useRef<HTMLDivElement>(null)\n\n\t// Clicking outside the open popover (and off its own pin) closes the thread \u2014 mirrors the\n\t// pending composer's dismiss. Capture phase + a class check rather than stopPropagation, since the\n\t// popover portals elsewhere in the DOM. The pin marker is excluded so its own click-to-toggle\n\t// handles it instead of this closing then the toggle reopening.\n\tuseEffect(() => {\n\t\tif (!open) return\n\t\tconst onPointerDown = (e: PointerEvent) => {\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target) return\n\t\t\tif (target.closest('.cmt-canvas-popover')) return\n\t\t\tconst marker = markerRef.current\n\t\t\tif (marker && marker.contains(target)) return\n\t\t\t// A press on a region's resize handle or movable body edits this thread \u2014 don't dismiss it.\n\t\t\tif (target.closest('.cmt-canvas-region-handle, .cmt-canvas-region--movable')) return\n\t\t\t// A click inside a menu/popover layered above us (the sidebar's filter or overflow\n\t\t\t// dropdown, or the composer's mention picker \u2014 all portaled elsewhere) belongs to that\n\t\t\t// layer; defer to its own dismissal instead of closing the thread out from under it.\n\t\t\tif (target.closest('.tlui-menu, [data-radix-popper-content-wrapper], .cmt-mention-popup'))\n\t\t\t\treturn\n\t\t\topenThreadId.set(editor, null)\n\t\t}\n\t\tdocument.addEventListener('pointerdown', onPointerDown, true)\n\t\treturn () => document.removeEventListener('pointerdown', onPointerDown, true)\n\t}, [open, editor])\n\n\tconst point = useValue(\n\t\t'pin point',\n\t\t() => {\n\t\t\tif (thread.pageId !== editor.getCurrentPageId()) return null\n\t\t\tconst pagePoint = anchorPagePoint(editor, thread.anchor, impreciseShapeAnchor)\n\t\t\treturn pagePoint ? editor.pageToViewport(pagePoint) : null\n\t\t},\n\t\t[editor, thread.anchor, thread.pageId, impreciseShapeAnchor]\n\t)\n\tconst visible = point !== null\n\n\t// While the popover is open, every unread comment on display gets reported read \u2014 including\n\t// replies that arrive while it stays open, since the effect re-runs as `comments` changes.\n\t// The host's receipt write flips isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!open || !visible || !isCommentUnread || !onCommentRead) return\n\t\tfor (const comment of comments) {\n\t\t\tif (isCommentUnread(comment.id)) {\n\t\t\t\tonCommentRead(comment.id)\n\t\t\t}\n\t\t}\n\t}, [open, visible, comments, isCommentUnread, onCommentRead])\n\n\tif (!point) return null\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tcommitCommentMutation(editor, () => {\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\tputCommentRecords(editor, [comment])\n\t\t\tif (onPostComment) onPostComment(comment)\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tcommitCommentMutation(editor, () => {\n\t\t\tputCommentRecords(editor, [\n\t\t\t\t{\n\t\t\t\t\t...thread,\n\t\t\t\t\tresolved: thread.resolved ? null : { at: Date.now(), by: currentUserId },\n\t\t\t\t},\n\t\t\t])\n\t\t})\n\t}\n\n\tconst deleteThread = () => {\n\t\topenThreadId.set(editor, null)\n\t\tcommitCommentMutation(editor, () =>\n\t\t\tremoveCommentRecords(editor, [thread.id, ...comments.map((c) => c.id)])\n\t\t)\n\t}\n\n\tconst startEdit = (comment: TLComment) => {\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\tcommitCommentMutation(editor, () => {\n\t\t\tputCommentRecords(editor, [{ ...comment, body: editText, editedAt: Date.now() }])\n\t\t})\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 an edit affordance on your own comments.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\n\t\tif (editingId === comment.id) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"cmt-editing\"\n\t\t\t\t\tonKeyDown={(e) => {\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\tplaceholder={msg('comments.edit-placeholder')}\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('comments.save')}\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\tactions={\n\t\t\t\t\tcomment.authorId === currentUserId ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tclassName=\"cmt-thread__action\"\n\t\t\t\t\t\t\ttitle={msg('comments.edit')}\n\t\t\t\t\t\t\tonClick={() => startEdit(comment)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TldrawUiIcon icon=\"dots-horizontal\" label={msg('comments.edit')} small />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : undefined\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\tconst headerActions = (\n\t\t<>\n\t\t\t{currentUserId && (\n\t\t\t\t<button\n\t\t\t\t\tclassName=\"cmt-thread__action\"\n\t\t\t\t\ttitle={msg(thread.resolved ? 'comments.reopen' : 'comments.resolve')}\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon\n\t\t\t\t\t\ticon=\"check\"\n\t\t\t\t\t\tlabel={msg(thread.resolved ? 'comments.reopen' : 'comments.resolve')}\n\t\t\t\t\t\tsmall\n\t\t\t\t\t/>\n\t\t\t\t</button>\n\t\t\t)}\n\t\t\t{currentUserId && (\n\t\t\t\t<button\n\t\t\t\t\tclassName=\"cmt-thread__action\"\n\t\t\t\t\ttitle={msg('comments.delete')}\n\t\t\t\t\tonClick={deleteThread}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"trash\" label={msg('comments.delete')} small />\n\t\t\t\t</button>\n\t\t\t)}\n\t\t\t<button\n\t\t\t\tclassName=\"cmt-thread__action\"\n\t\t\t\ttitle={msg('comments.dismiss')}\n\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t>\n\t\t\t\t<TldrawUiIcon icon=\"cross-2\" label={msg('comments.dismiss')} small />\n\t\t\t</button>\n\t\t</>\n\t)\n\n\tconst PinContent = options.components.PinContent\n\t// The `PinContent` component slot overrides the built-in author-initial default.\n\tconst pinContent = PinContent ? (\n\t\t<PinContent thread={thread} comments={comments} />\n\t) : (\n\t\tinitialOf(resolveName(thread.createdBy) ?? UNKNOWN_AUTHOR)\n\t)\n\n\t// Drag the marker to move the thread: its position is overridden locally while dragging, then\n\t// re-anchored on drop. A point/shape thread re-anchors to whatever it's dropped on (a shape, else\n\t// a point); a region thread translates, keeping its size. A pointer that barely moves is a click \u2014\n\t// toggle the popover.\n\t// Which affordances move a region, per the option: 'pin' \u2192 pin only, 'body' \u2192 body only, 'both'.\n\tconst isRegion = thread.anchor.type === 'region'\n\tconst pinMovable = regionOptions.move !== 'body'\n\tconst bodyMovable = regionOptions.move !== 'pin'\n\tconst startDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tdragRef.current = { startX: e.clientX, startY: e.clientY, moved: false }\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\t// A region that moves by its body ignores pin drags (the pin only toggles the thread).\n\t\tif (isRegion && !pinMovable) return\n\t\tif (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return\n\t\tdrag.moved = true\n\t\tsetDragPagePoint(editor.screenToPage({ x: e.clientX, y: e.clientY }))\n\t}\n\tconst endDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tdragRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId)) {\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\t}\n\t\tif (!drag) return\n\t\tif (!drag.moved) {\n\t\t\topenThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)\n\t\t\treturn\n\t\t}\n\t\tconst pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\tsetDragPagePoint(null)\n\t\tlet anchor: TLCommentThread['anchor']\n\t\tif (thread.anchor.type === 'region') {\n\t\t\t// Translate so the pin (the region's pin corner) lands at the drop; size unchanged.\n\t\t\tanchor = {\n\t\t\t\t...thread.anchor,\n\t\t\t\tx: pagePoint.x - regionOptions.pinCorner.x * thread.anchor.w,\n\t\t\t\ty: pagePoint.y - regionOptions.pinCorner.y * thread.anchor.h,\n\t\t\t}\n\t\t} else {\n\t\t\tconst hit = editor.getShapeAtPoint(pagePoint, { hitInside: true })\n\t\t\tanchor = hit\n\t\t\t\t? shapeAnchorAt(editor, hit.id, pagePoint, e.altKey)\n\t\t\t\t: { type: 'point', x: pagePoint.x, y: pagePoint.y }\n\t\t}\n\t\tcommitCommentMutation(editor, () => putCommentRecords(editor, [{ ...thread, anchor }]), 'drag')\n\t}\n\n\t// The pin (and its popover) track the live edit: a resize moves it to the region's pin corner, a\n\t// move to the drag point; otherwise it sits at the stored anchor's viewport point.\n\tconst livePinPage = resizeBounds\n\t\t? regionPinPoint(resizeBounds, regionOptions.pinCorner)\n\t\t: dragPagePoint\n\tconst renderPoint = livePinPage ? editor.pageToViewport(livePinPage) : point\n\n\t// A region's live box bounds, by priority: a corner resize, else a pin-drag translation (the pin\n\t// corner tracks the cursor), else the stored anchor. Undefined for non-region threads.\n\tconst regionAnchor = thread.anchor.type === 'region' ? thread.anchor : undefined\n\tconst movedRegion =\n\t\tregionAnchor && dragPagePoint\n\t\t\t? {\n\t\t\t\t\t...regionAnchor,\n\t\t\t\t\tx: dragPagePoint.x - regionOptions.pinCorner.x * regionAnchor.w,\n\t\t\t\t\ty: dragPagePoint.y - regionOptions.pinCorner.y * regionAnchor.h,\n\t\t\t\t}\n\t\t\t: regionAnchor\n\tconst regionBoxBounds = resizeBounds ?? movedRegion\n\tconst commitResize = (bounds: BoxModel) => {\n\t\tsetResizeBounds(null)\n\t\teditor.run(\n\t\t\t() => putCommentRecords(editor, [{ ...thread, anchor: { type: 'region', ...bounds } }]),\n\t\t\t{\n\t\t\t\thistory: 'ignore',\n\t\t\t}\n\t\t)\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{regionBoxBounds && (dragPagePoint || revealed) && (\n\t\t\t\t<RegionBox\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tbox={regionBoxBounds}\n\t\t\t\t\tmovable={bodyMovable && !dragPagePoint}\n\t\t\t\t\tonPreview={setResizeBounds}\n\t\t\t\t\tonCommit={commitResize}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{regionBoxBounds && revealed && !dragPagePoint && regionOptions.resize !== 'none' && (\n\t\t\t\t<RegionResizeHandles\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tbox={regionBoxBounds}\n\t\t\t\t\thandles={resizeHandles}\n\t\t\t\t\tonPreview={setResizeBounds}\n\t\t\t\t\tonCommit={commitResize}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tclassName={open ? 'cmt-canvas-pin cmt-canvas-pin--open' : 'cmt-canvas-pin'}\n\t\t\t\tstyle={{ left: renderPoint.x, top: renderPoint.y }}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={markerRef}\n\t\t\t\t\tclassName=\"cmt-canvas-pin__marker\"\n\t\t\t\t\tonPointerDown={startDrag}\n\t\t\t\t\tonPointerMove={onDrag}\n\t\t\t\t\tonPointerUp={endDrag}\n\t\t\t\t\tonPointerEnter={() => setPinHovered(true)}\n\t\t\t\t\tonPointerLeave={() => setPinHovered(false)}\n\t\t\t\t>\n\t\t\t\t\t<CommentPin resolved={thread.resolved != null} open={open}>\n\t\t\t\t\t\t{pinContent}\n\t\t\t\t\t</CommentPin>\n\t\t\t\t</div>\n\t\t\t\t{/* The popover portals up to the menus layer (above the UI panels) so it isn't clipped;\n\t\t\t the pin itself stays in the canvas-in-front layer, beneath the UI. */}\n\t\t\t\t{open && (\n\t\t\t\t\t<ThreadPopover\n\t\t\t\t\t\tcontainer={container}\n\t\t\t\t\t\tstyle={{ left: renderPoint.x + 36, top: renderPoint.y - 28 }}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CommentThread\n\t\t\t\t\t\t\theader={msg('comments.thread-title')}\n\t\t\t\t\t\t\theaderActions={headerActions}\n\t\t\t\t\t\t\trenderComment={renderComment}\n\t\t\t\t\t\t\tcomments={comments.map((c) => toCardProps(c, props, options.components))}\n\t\t\t\t\t\t\tresolvedBanner={\n\t\t\t\t\t\t\t\tthread.resolved\n\t\t\t\t\t\t\t\t\t? msg('comments.resolved-by').replace(\n\t\t\t\t\t\t\t\t\t\t\t'{name}',\n\t\t\t\t\t\t\t\t\t\t\tresolveName(thread.resolved.by) ?? UNKNOWN_AUTHOR\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcomposer={\n\t\t\t\t\t\t\t\tcurrentUserId && !thread.resolved\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\tauthor: resolveName(currentUserId) ?? UNKNOWN_AUTHOR,\n\t\t\t\t\t\t\t\t\t\t\tplaceholder: msg('comments.reply-placeholder'),\n\t\t\t\t\t\t\t\t\t\t\tsendLabel: msg('comments.send'),\n\t\t\t\t\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\t\t\t\t\tonChange: setReply,\n\t\t\t\t\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply),\n\t\t\t\t\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ThreadPopover>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</>\n\t)\n})\n\nfunction PendingComposer({\n\teditor,\n\tpending,\n\tcurrentUserId,\n\tresolveName,\n\tonPostComment,\n\tgetMentionSuggestions,\n\trenderMentionSuggestion,\n}: CanvasCommentsProps & { editor: Editor; pending: PendingComment }) {\n\tconst [text, setText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst msg = useTranslation()\n\tconst container = useContainer()\n\t// Over this floating panel, scroll and hover reach the canvas (except where it scrolls itself).\n\tusePassThroughWheelEvents(ref)\n\tusePassThroughMouseOverEvents(ref)\n\n\tconst point = useValue('composer point', () => editor.pageToViewport(pending.point), [\n\t\teditor,\n\t\tpending.point,\n\t])\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('.cmt-mention-popup')) 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\tcommitCommentMutation(editor, () => {\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\tputCommentRecords(editor, [thread, comment])\n\t\t\tif (onPostComment) onPostComment(comment)\n\t\t})\n\t\tsetText(EMPTY_COMMENT)\n\t\tpendingComment.set(editor, null)\n\t}\n\n\treturn createPortal(\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName=\"cmt-canvas-composer\"\n\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\tonPointerDown={stop}\n\t\t\tonKeyDown={(e) => {\n\t\t\t\tif (e.key === 'Escape' && !isMentionPickerOpen()) pendingComment.set(editor, null)\n\t\t\t}}\n\t\t>\n\t\t\t<CommentComposer\n\t\t\t\tauthor={currentUserId ? (resolveName(currentUserId) ?? UNKNOWN_AUTHOR) : ''}\n\t\t\t\tplaceholder={msg('comments.add-placeholder')}\n\t\t\t\tsendLabel={msg('comments.send')}\n\t\t\t\tvalue={text}\n\t\t\t\tonChange={setText}\n\t\t\t\tonSubmit={submit}\n\t\t\t\tdisabled={isCommentEmpty(text)}\n\t\t\t\tgetMentionSuggestions={getMentionSuggestions}\n\t\t\t\trenderMentionSuggestion={renderMentionSuggestion}\n\t\t\t\tautoFocus\n\t\t\t\tleading={draftAvatar}\n\t\t\t/>\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuHE;AAvHF,mBAUO;AACP,uBAA6B;AAC7B,oBAmBO;AACP,iCAAoC;AACpC,qBAA0D;AAE1D,0BAA8C;AAC9C,8BAAgC;AAChC,gCAA8C;AAC9C,yBAA2B;AAC3B,4BAA8B;AAC9B,yBAA2B;AAE3B,gCAAoC;AACpC,2BAAqC;AACrC,0BAA4B;AAC5B,4BAA+B;AAC/B,2BAA0E;AAE1E,mBAAqD;AACrD,qBAAqC;AACrC,qBAKO;AACP,4BAIO;AACP,mBAQO;AACP,0BAA+D;AAsC/D,MAAM,OAAO,CAAC,MAAmC,EAAE,gBAAgB;AAEnE,MAAM,YAAY,CAAC,cAA0B,iC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AAA,QACA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,EAAE,MAAM,MAAM,GAAG,KAAK,MAAM,EAAE;AAAA,QACrC,eAAe;AAAA,QACf,WAAW,CAAC,MAAM;AACjB,cAAI,EAAE,QAAQ,YAAY,KAAC,+CAAoB,EAAG,6BAAe,IAAI,QAAQ,IAAI;AAAA,QAClF;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,QAAQ,gBAAiB,YAAY,aAAa,KAAK,uCAAkB;AAAA,YACzE,aAAa,IAAI,0BAA0B;AAAA,YAC3C,WAAW,IAAI,eAAe;AAAA,YAC9B,OAAO;AAAA,YACP,UAAU;AAAA,YACV,UAAU;AAAA,YACV,cAAU,0CAAe,IAAI;AAAA,YAC7B;AAAA,YACA;AAAA,YACA,WAAS;AAAA,YACT,SAAS;AAAA;AAAA,QACV;AAAA;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import {\n\tmemo,\n\ttype CSSProperties,\n\ttype PointerEvent as ReactPointerEvent,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport {\n\ttype BoxModel,\n\tcreateComment,\n\tcreateCommentThread,\n\tEditor,\n\tgetFirstCharacter,\n\treact,\n\tTLComment,\n\tTLCommentId,\n\tTLCommentThread,\n\tTLRichText,\n\tTldrawUiIcon,\n\tuseContainer,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tusePassThroughWheelEvents,\n\tuseTranslation,\n\tuseValue,\n\tVecLike,\n} from 'tldraw'\nimport { computeClusterTable } from '../clustering/computeClusterTable'\nimport { type ClusterRuntime, createClusterRuntime } from '../clustering/runtime'\nimport type { ClusterNode, ClusterTable, MergeEvent } from '../clustering/types'\nimport { CommentCard, CommentCardProps } from '../ui/comment-card'\nimport { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentPin } from '../ui/comment-pin'\nimport { CommentThread } from '../ui/comment-thread'\nimport { CountBadge } from '../ui/count-badge'\nimport { MentionMember } from '../ui/mention-list'\nimport { isMentionPickerOpen } from '../ui/mention-suggestion'\nimport { collectClusterLeaves } from './cluster-input'\nimport { CommentBody } from './comment-body'\nimport { UNKNOWN_AUTHOR } from './comment-render'\nimport { getCommentRecord, putCommentRecords, removeCommentRecords } from './comment-store'\nimport { PendingComment } from './comment-tool'\nimport { useCommentThreads, useThreadComments } from './hooks'\nimport { useCommentingEnabled } from './license'\nimport {\n\ttype CommentingComponents,\n\ttype CommentingOptions,\n\tgetCommentingOptions,\n\tuseCommentingOptions,\n} from './options'\nimport {\n\tDEFAULT_REGION_COMMENT_OPTIONS,\n\tRegionCommentOptions,\n\tsetRegionCommentOptions,\n} from './region-options'\nimport {\n\tcommentsHidden,\n\tcommitCommentMutation,\n\topenThreadId,\n\tpendingComment,\n\tregionDraft,\n\ttoggleCommentsHidden,\n\tusePendingComment,\n} from './state'\nimport { anchorPagePoint, regionPinPoint, shapeAnchorAt } from './thread-state'\n\n/**\n * A ready-to-use comments layer for a tldraw canvas: pins each thread at its anchor, opens a\n * thread popover (with a reply composer) on click, and shows a composer where the comment tool\n * placed a new thread. Reads/writes comment records straight from `editor.store`.\n *\n * It's meant as the batteries-included default \u2014 every visible piece is a lever (the `CommentBody`\n * and `PinContent` slots on `CommentTool.configure({ components })`), and the pieces it composes\n * (`CommentPin`, `CommentThread`, `CommentComposer`, the hooks, the tool) are all exported, so a\n * consumer can rebuild this from parts instead.\n * @public\n */\nexport interface CanvasCommentsProps {\n\t/** The signed-in user's id, or null for a read-only viewer. Only a signed-in user composes. */\n\tcurrentUserId: string | null\n\t/** Map an author id to a display name, or `undefined` when the id can't be named. */\n\tresolveName(id: string): string | undefined\n\t/** Called after any comment (a new thread's first comment, or a reply) is posted. */\n\tonPostComment?(comment: TLComment): void\n\t/** Whether a comment is unread for the current user (return true for unread). */\n\tisCommentUnread?(commentId: TLCommentId): boolean\n\t/**\n\t * Called for each unread comment shown to the user in an open thread popover, so hosts can\n\t * record a read receipt. Needs `isCommentUnread` to know what's unread.\n\t */\n\tonCommentRead?(commentId: TLCommentId): void\n\t/** Resolve the members matching an `@`-query in the composers (sync or async). */\n\tgetMentionSuggestions?(query: string): MentionMember[] | Promise<MentionMember[]>\n\t/** Override a mention-picker row's content. */\n\trenderMentionSuggestion?(member: MentionMember): ReactNode\n\t/** Where imprecise shape pins sit \u2014 a normalized (0\u20131) spot within the shape. Default top-right. */\n\timpreciseShapeAnchor?: { x: number; y: number }\n\t/** Region comment behaviour. Region is off by default \u2014 omit this for click-only point/shape\n\t * comments. Anything unset falls back to {@link DEFAULT_REGION_COMMENT_OPTIONS}. */\n\tregionOptions?: Partial<RegionCommentOptions>\n}\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\nconst initialOf = (name: string): string => (getFirstCharacter(name.trim()) || '?').toUpperCase()\nconst CLUSTER_FADE_MS = 150\n/** Duration of the click-a-badge zoom-to-split animation. */\nconst CLUSTER_EXPAND_ZOOM_MS = 450\n\n/** The leading element for the placement composer \u2014 the comment pin's shape, but a pencil\n * instead of an initial, marking an unsent draft. */\nconst draftAvatar = (\n\t<CommentPin>\n\t\t<svg\n\t\t\tviewBox=\"0 0 24 24\"\n\t\t\twidth=\"15\"\n\t\t\theight=\"15\"\n\t\t\tfill=\"none\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth=\"2\"\n\t\t\tstrokeLinecap=\"round\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t<path d=\"M12 20h9\" />\n\t\t\t<path d=\"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z\" />\n\t\t</svg>\n\t</CommentPin>\n)\n\nfunction toCardProps(\n\tcomment: TLComment,\n\tprops: CanvasCommentsProps,\n\tcomponents: CommentingComponents\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={props.resolveName} />\n\t)\n\treturn {\n\t\tauthor: props.resolveName(comment.authorId) ?? UNKNOWN_AUTHOR,\n\t\tbody,\n\t\tdate: new Date(comment.createdAt).toISOString(),\n\t\tyou: comment.authorId === props.currentUserId,\n\t\tedited: comment.editedAt != null,\n\t}\n}\n\n/** @public @react */\nexport function CanvasComments(props: CanvasCommentsProps) {\n\t// Gate the whole layer on the license before doing any work. The inner component holds all the\n\t// other hooks, so mounting/unmounting it as the license resolves keeps hook order stable here.\n\tconst commentingEnabled = useCommentingEnabled()\n\tif (!commentingEnabled) return null\n\treturn <CanvasCommentsLayer {...props} />\n}\n\nfunction CanvasCommentsLayer(props: CanvasCommentsProps) {\n\tconst editor = useEditor()\n\tconst options = useCommentingOptions()\n\tconst container = useContainer()\n\t// Merge the consumer's region options over the disabled defaults and publish them for this editor,\n\t// so the comment tool (which has no props) reads the same per-instance config.\n\tconst regionOptions = useMemo(\n\t\t() => ({ ...DEFAULT_REGION_COMMENT_OPTIONS, ...props.regionOptions }),\n\t\t[props.regionOptions]\n\t)\n\tuseEffect(() => setRegionCommentOptions(editor, regionOptions), [editor, regionOptions])\n\tconst layerRef = useRef<HTMLDivElement>(null)\n\t// Over the pins and cluster badges, wheel and hover pass through to the canvas beneath (these\n\t// events bubble up from the pointer-interactive markers to this layer root).\n\tusePassThroughWheelEvents(layerRef)\n\tusePassThroughMouseOverEvents(layerRef)\n\tconst deepLinkHandled = useRef(false)\n\tconst threads = useCommentThreads(editor)\n\tconst pending = usePendingComment()\n\tconst openId = useValue('open thread id', () => openThreadId.get(editor), [editor])\n\tconst impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor\n\t// Threads held out of clustering because their anchor moved while folded inside a badge\n\t// (drag, nudge, align, undo, a collaborator \u2014 detected by position, not gesture). They render\n\t// as live pins riding their anchor and rejoin clustering on the next zoom-out.\n\tconst [heldThreadIds, setHeldThreadIds] = useState<ReadonlySet<string>>(EMPTY_SET)\n\tconst adoptOnRebuild = useRef(false)\n\tconst clusterLeaves = useValue(\n\t\t'comment cluster leaves',\n\t\t() =>\n\t\t\tcollectClusterLeaves(\n\t\t\t\teditor,\n\t\t\t\tthreads.filter((thread) => !heldThreadIds.has(thread.id)),\n\t\t\t\topenThreadId.get(editor),\n\t\t\t\timpreciseShapeAnchor\n\t\t\t),\n\t\t[editor, threads, impreciseShapeAnchor, heldThreadIds]\n\t)\n\tconst clusterZoomBounds = useValue(\n\t\t'comment cluster zoom bounds',\n\t\t() => getClusterZoomBounds(editor),\n\t\t[editor]\n\t)\n\tconst latestModel = useMemo(() => {\n\t\tconst table = computeClusterTable(clusterLeaves, clusterZoomBounds)\n\t\tconst runtime = createClusterRuntime(table)\n\t\truntime.seed(editor.getZoomLevel())\n\t\treturn { runtime, table }\n\t}, [clusterLeaves, clusterZoomBounds, editor])\n\t// The core invariant: the only thing that re-flows clustering doc-wide is zoom. Every rebuild\n\t// (add / move / delete / open / pop-out) is computed immediately as `latestModel` \u2014 the MST\n\t// stays correct \u2014 but the on-screen partition is `renderedModel`, and it only ever changes via\n\t// (a) the cursor walking on zoom, (b) adoption of the pending rebuild on zoom-out, or\n\t// (c) LOCAL detach patches: a leaf that left the input (deleted, opened, popped out) is\n\t// detached from its own badge in place \u2014 count and centroid update for that badge alone,\n\t// and nothing else on the canvas moves.\n\tconst [renderedModel, setRenderedModel] = useState(latestModel)\n\tlet clusterModel = renderedModel\n\t// A page switch replaces the whole scene: hard-reset rather than detach the world.\n\tconst pageId = useValue('comment cluster page', () => editor.getCurrentPageId(), [editor])\n\tconst pageRef = useRef(pageId)\n\tif (pageRef.current !== pageId) {\n\t\tpageRef.current = pageId\n\t\tadoptOnRebuild.current = false\n\t\tlatestModel.runtime.seed(editor.getZoomLevel())\n\t\tif (heldThreadIds.size > 0) setHeldThreadIds(EMPTY_SET)\n\t\tsetRenderedModel(latestModel)\n\t\tclusterModel = latestModel\n\t}\n\t// adoptOnRebuild is set by the rejoin reaction below, outside React's render cycle, paired\n\t// with clearing heldThreadIds. Only trust it once that pairing is actually visible here\n\t// (heldThreadIds confirmed empty) \u2014 an unrelated re-render can land in the gap between the\n\t// ref being set and the state update it was paired with being applied.\n\tconst rejoinPending = heldThreadIds.size === 0 && adoptOnRebuild.current\n\tif (renderedModel !== latestModel && rejoinPending) {\n\t\tadoptOnRebuild.current = false\n\t\t// Carryover seed: band events inherit the outgoing partition's merged/unmerged state, so\n\t\t// nothing changes state because of the swap alone. Idempotent, so safe during render.\n\t\tlatestModel.runtime.seedFrom(editor.getZoomLevel(), renderedModel.runtime.getVisible())\n\t\tsetRenderedModel(latestModel)\n\t\tclusterModel = latestModel\n\t} else if (heldThreadIds.size === 0 && renderedModel === latestModel) {\n\t\t// Nothing pending and nothing to adopt: clear any leftover force-adopt intent so it can't\n\t\t// survive to force-adopt a later, unrelated rebuild.\n\t\tadoptOnRebuild.current = false\n\t}\n\t// Pop-out detection: a leaf folded inside a badge can't follow its anchor (the badge position\n\t// is baked into the model), so when its live position drifts from the baked one, hold it out.\n\t// It renders as a live pin riding the anchor; the detach loop below shrinks its badge locally.\n\tconst newlyMovedIds = findMovedClusteredLeafIds(clusterModel, latestModel)\n\tif (newlyMovedIds.length > 0) {\n\t\tconst next = new Set(heldThreadIds)\n\t\tfor (const id of newlyMovedIds) next.add(id)\n\t\tsetHeldThreadIds(next)\n\t}\n\t// Local partition maintenance \u2014 the only non-zoom visual change, and it is local by\n\t// construction: any displayed leaf that has left the cluster input (deleted, thread opened,\n\t// popped out above) is detached from its badge in place. The corrected rebuild is already\n\t// sitting in latestModel awaiting the next zoom-out.\n\t{\n\t\tconst latestLeafIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id))\n\t\tfor (const leaf of clusterModel.table.leaves) {\n\t\t\tif (!latestLeafIds.has(leaf.id)) {\n\t\t\t\tclusterModel.runtime.detachLeaf(leaf.id)\n\t\t\t}\n\t\t}\n\t}\n\t// Moved pins rejoin clustering on the next zoom-out motion: clear the set (so the rebuild\n\t// includes them again) and adopt that rebuild immediately instead of deferring it. Zooming in\n\t// never folds pins into clusters \u2014 merging is a zoom-out-only move, matching the runtime.\n\tuseEffect(() => {\n\t\tif (heldThreadIds.size === 0) return\n\t\tlet lastZoom = editor.getZoomLevel()\n\t\treturn react('rejoin moved comment pins on zoom out', () => {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tconst prevZoom = lastZoom\n\t\t\tlastZoom = zoom\n\t\t\tif (zoom >= prevZoom) return\n\t\t\tadoptOnRebuild.current = true\n\t\t\tsetHeldThreadIds(EMPTY_SET)\n\t\t})\n\t}, [heldThreadIds, editor])\n\t// Adopt a pending rebuild only on zoom-out motion: folding deferred additions into clusters is\n\t// a merge, and merging only happens while zooming out. While zooming in, the stale table still\n\t// splits correctly on its own (split thresholds are direction-safe by the hysteresis invariant).\n\tuseEffect(() => {\n\t\tif (clusterModel === latestModel) return\n\t\tlet lastZoom = editor.getZoomLevel()\n\t\treturn react('adopt pending cluster model on zoom out', () => {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tconst prevZoom = lastZoom\n\t\t\tlastZoom = zoom\n\t\t\tif (zoom >= prevZoom) return\n\t\t\tlatestModel.runtime.seedFrom(zoom, clusterModel.runtime.getVisible())\n\t\t\tsetRenderedModel(latestModel)\n\t\t})\n\t}, [clusterModel, latestModel, editor])\n\t// Threads in the current input that the displayed partition doesn't show anywhere (new\n\t// comments, reopened threads, undone deletions): render as plain pins until the next\n\t// zoom-out folds them in. Membership is judged against the *displayed* partition (with\n\t// detaches applied), not the rendered table, so a detached-then-restored leaf reappears.\n\tconst partitionVersion = clusterModel.runtime.version\n\tconst orphanThreads = useMemo(() => {\n\t\tif (clusterModel === latestModel) return []\n\t\tconst displayed = new Set<string>()\n\t\tfor (const node of clusterModel.runtime.getVisible().values()) {\n\t\t\tfor (const member of node.members) displayed.add(member)\n\t\t}\n\t\tconst latestIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id))\n\t\treturn threads.filter((thread) => latestIds.has(thread.id) && !displayed.has(thread.id))\n\t\t// The runtime mutates its partition in place; partitionVersion is its change stamp.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [clusterModel, latestModel, threads, partitionVersion])\n\tconst heldThreads = useMemo(\n\t\t() => threads.filter((thread) => heldThreadIds.has(thread.id) && thread.id !== openId),\n\t\t[threads, heldThreadIds, openId]\n\t)\n\t// Subscribe to the runtime's partition version, not the raw zoom: onCamera runs on every zoom\n\t// tick (O(1) threshold checks) but the version only moves when the partition actually changes\n\t// \u2014 so this component only re-renders on cluster changes, not on every camera frame. The memo\n\t// below keys on a fresh inline read of the version rather than the subscribed value, because\n\t// render-time detaches (above) bump it after the subscription's computed already evaluated.\n\tuseValue(\n\t\t'comment cluster version',\n\t\t() => {\n\t\t\tclusterModel.runtime.onCamera(editor.getZoomLevel())\n\t\t\treturn clusterModel.runtime.version\n\t\t},\n\t\t[clusterModel, editor]\n\t)\n\tconst visibleNodes = useMemo(() => {\n\t\treturn Array.from(clusterModel.runtime.getVisible().values())\n\t\t// The runtime mutates its partition in place; partitionVersion is its change stamp.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [clusterModel, partitionVersion])\n\tconst fadeNodes = useFadeVisibleNodes(visibleNodes, clusterModel)\n\tconst threadsById = useMemo(\n\t\t() => new Map<string, TLCommentThread>(threads.map((thread) => [thread.id, thread])),\n\t\t[threads]\n\t)\n\tconst openThread = openId ? threadsById.get(openId) : null\n\tconst hidden = useValue('comments hidden', () => commentsHidden.get(editor), [editor])\n\n\t// Reset the transient UI state (open thread, half-placed comment) when this unmounts.\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\topenThreadId.set(editor, null)\n\t\t\tpendingComment.set(editor, null)\n\t\t}\n\t}, [editor])\n\n\t// Open the thread named by a deep link (?comment=<thread or comment id>). If the thread is\n\t// currently inside a cluster, zoom to the first split that reveals it before opening.\n\tuseEffect(() => {\n\t\tif (deepLinkHandled.current) return\n\t\tconst id = new URLSearchParams(window.location.search).get('comment')\n\t\tif (!id) {\n\t\t\tdeepLinkHandled.current = true\n\t\t\treturn\n\t\t}\n\n\t\tconst record = getCommentRecord(editor, id)\n\t\tif (!record) return\n\n\t\tlet thread: TLCommentThread | undefined\n\t\tif (record.typeName === 'comment') {\n\t\t\tthread = threadsById.get(record.threadId)\n\t\t} else {\n\t\t\tthread = record\n\t\t}\n\t\tif (!thread) return\n\n\t\tdeepLinkHandled.current = true\n\t\trevealDeepLinkedThread(\n\t\t\teditor,\n\t\t\tthread,\n\t\t\tclusterModel.table,\n\t\t\tclusterZoomBounds,\n\t\t\toptions,\n\t\t\timpreciseShapeAnchor\n\t\t)\n\t\topenThreadId.set(editor, thread.id)\n\t}, [clusterModel.table, clusterZoomBounds, editor, threadsById, impreciseShapeAnchor, options])\n\n\t// Clicking a badge zooms to just past the zoom at which that cluster first unclusters,\n\t// centered on its centroid. The event that created a visible cluster is the event that splits\n\t// it, and (by the table's sort + monotone thresholds) it has the smallest zSplit of everything\n\t// applied inside it \u2014 so its zSplit is exactly the first split within those comments. The\n\t// animated zoom-in then drives the runtime cursor like any manual zoom, so the badge splits\n\t// (and can be drilled into further) with no extra bookkeeping.\n\tconst zoomToClusterSplit = useCallback(\n\t\t(node: ClusterNode) => {\n\t\t\tconst event = clusterModel.table.events.find((e) => e.result.id === node.id)\n\t\t\tif (!event || !Number.isFinite(event.zSplit)) return\n\t\t\tconst zoom = clamp(\n\t\t\t\tevent.zSplit * options.clusterSplitZoomFactor,\n\t\t\t\tclusterZoomBounds.minZoom,\n\t\t\t\tclusterZoomBounds.maxZoom\n\t\t\t)\n\t\t\tcenterOnPointAtZoom(editor, node.centroid, zoom, CLUSTER_EXPAND_ZOOM_MS)\n\t\t},\n\t\t[clusterModel, clusterZoomBounds, editor, options]\n\t)\n\n\t// Escape collapses the open thread. Capture-phase + stopPropagation so it runs ahead of the\n\t// editor (which would otherwise cancel the current tool or clear the selection). If a comment is\n\t// being edited, let its own Escape handler exit edit mode first, keeping the thread open.\n\tuseEffect(() => {\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.key !== 'Escape' || openThreadId.get(editor) === null) return\n\t\t\t// The mention picker owns Escape while it's open \u2014 let it dismiss the roster alone.\n\t\t\tif (isMentionPickerOpen()) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (target && target.closest('.tlui-cmt-editing')) return\n\t\t\topenThreadId.set(editor, null)\n\t\t\te.preventDefault()\n\t\t\te.stopPropagation()\n\t\t}\n\t\tdocument.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => document.removeEventListener('keydown', onKeyDown, true)\n\t}, [editor])\n\n\t// Shift+C toggles comment-pin visibility on the canvas (matching Figma). Skipped while typing so\n\t// it never fires from inside a composer. Physical `KeyC` (layout-independent) with shift only.\n\tuseEffect(() => {\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (e.code !== 'KeyC' || !e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (target && target.closest('input, textarea, [contenteditable=\"true\"]')) return\n\t\t\ttoggleCommentsHidden(editor)\n\t\t\te.preventDefault()\n\t\t}\n\t\tdocument.addEventListener('keydown', onKeyDown, true)\n\t\treturn () => document.removeEventListener('keydown', onKeyDown, true)\n\t}, [editor])\n\n\t// Hidden: the whole canvas layer (pins, open popover, pending composer) is withheld. The signal\n\t// is read above so this component stays mounted and its shortcut/Escape effects keep running.\n\tif (hidden) return null\n\n\t// Render into the container (above the panels' stacking context) so the pins and popovers\n\t// live in the UI layer rather than being clipped by the canvas layer.\n\treturn createPortal(\n\t\t<div ref={layerRef} className=\"tlui-cmt-canvas-layer\">\n\t\t\t{options.enableClustering ? (\n\t\t\t\t<>\n\t\t\t\t\t{fadeNodes.map(({ node, phase }) => {\n\t\t\t\t\t\tlet content: ReactNode\n\t\t\t\t\t\tif (node.count === 1) {\n\t\t\t\t\t\t\tconst thread = threadsById.get(node.id)\n\t\t\t\t\t\t\tif (!thread) return null\n\t\t\t\t\t\t\tcontent = (\n\t\t\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcontent = <ClusterBadge editor={editor} node={node} onExpand={zoomToClusterSplit} />\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={`cluster-fade:${node.id}`} className={clusterFadeClassName(phase)}>\n\t\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t\t{orphanThreads.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t\t{heldThreads.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\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\t\t// Clustering off: every thread renders as its own live pin (each returns null when it's\n\t\t\t\t// not on the current page or its anchor is missing). The open thread is excluded here and\n\t\t\t\t// rendered once below, mirroring how the clustering path keeps it out of the cluster leaves \u2014\n\t\t\t\t// otherwise it would mount a second, stacked pin.\n\t\t\t\tthreads\n\t\t\t\t\t.filter((thread) => thread.id !== openId)\n\t\t\t\t\t.map((thread) => (\n\t\t\t\t\t\t<ThreadPin\n\t\t\t\t\t\t\tkey={thread.id}\n\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\tthread={thread}\n\t\t\t\t\t\t\t{...props}\n\t\t\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))\n\t\t\t)}\n\t\t\t{openThread && (\n\t\t\t\t<ThreadPin\n\t\t\t\t\tkey={`open:${openThread.id}`}\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tthread={openThread}\n\t\t\t\t\t{...props}\n\t\t\t\t\tregionOptions={regionOptions}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<RegionDraftBox editor={editor} />\n\t\t\t{/* Keep the region visible while composing \u2014 the drag draft is gone by now, and no thread\n\t\t\t exists yet, so the pending anchor is what shows the area under the open composer. */}\n\t\t\t{pending?.anchor.type === 'region' && <RegionBox editor={editor} box={pending.anchor} />}\n\t\t\t{pending && props.currentUserId && (\n\t\t\t\t<PendingComposer editor={editor} pending={pending} {...props} />\n\t\t\t)}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n\nconst EMPTY_SET: ReadonlySet<string> = new Set()\nconst MOVED_LEAF_EPSILON = 1e-6\ntype ClusterFadePhase = 'entering' | 'present' | 'exiting'\n\ninterface ClusterFadeNode {\n\tnode: ClusterNode\n\tphase: ClusterFadePhase\n}\n\nfunction useFadeVisibleNodes(\n\tnodes: readonly ClusterNode[],\n\tresetKey: { runtime: ClusterRuntime; table: ClusterTable }\n): ClusterFadeNode[] {\n\tconst resetKeyRef = useRef(resetKey)\n\tconst didReset = resetKeyRef.current !== resetKey\n\tif (didReset) {\n\t\tresetKeyRef.current = resetKey\n\t}\n\n\tconst [fadeNodes, setFadeNodes] = useState<ClusterFadeNode[]>(() => toPresentFadeNodes(nodes))\n\tconst renderedNodes = didReset ? toPresentFadeNodes(nodes) : fadeNodes\n\n\tuseEffect(() => {\n\t\tsetFadeNodes(toPresentFadeNodes(nodes))\n\t\t// Resets only on a new model (resetKey); node-list changes within the same model are\n\t\t// handled by the reconcile effect below, which fades entries in/out instead of snapping.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [resetKey])\n\n\tuseEffect(() => {\n\t\tif (didReset) return\n\t\tsetFadeNodes((previous) => reconcileFadeNodes(previous, nodes))\n\t}, [didReset, nodes])\n\n\tconst hasEntering = renderedNodes.some((item) => item.phase === 'entering')\n\tuseEffect(() => {\n\t\tif (!hasEntering) return\n\t\tconst frame = requestClusterFadeFrame(() => {\n\t\t\tsetFadeNodes((previous) =>\n\t\t\t\tprevious.map((item) => (item.phase === 'entering' ? { ...item, phase: 'present' } : item))\n\t\t\t)\n\t\t})\n\t\treturn () => cancelClusterFadeFrame(frame)\n\t}, [hasEntering, renderedNodes])\n\n\tconst hasExiting = renderedNodes.some((item) => item.phase === 'exiting')\n\tuseEffect(() => {\n\t\tif (!hasExiting) return\n\t\tconst timeout = window.setTimeout(() => {\n\t\t\tsetFadeNodes((previous) => previous.filter((item) => item.phase !== 'exiting'))\n\t\t}, CLUSTER_FADE_MS)\n\t\treturn () => window.clearTimeout(timeout)\n\t}, [hasExiting, renderedNodes])\n\n\treturn renderedNodes\n}\n\nfunction toPresentFadeNodes(nodes: readonly ClusterNode[]): ClusterFadeNode[] {\n\treturn nodes.map((node) => ({ node, phase: 'present' }))\n}\n\nfunction reconcileFadeNodes(\n\tprevious: readonly ClusterFadeNode[],\n\tnextNodes: readonly ClusterNode[]\n): ClusterFadeNode[] {\n\tconst previousById = new Map(previous.map((item) => [item.node.id, item]))\n\tconst nextIds = new Set(nextNodes.map((node) => node.id))\n\tconst next: ClusterFadeNode[] = []\n\n\tfor (const node of nextNodes) {\n\t\tconst previousItem = previousById.get(node.id)\n\t\tnext.push({\n\t\t\tnode,\n\t\t\tphase:\n\t\t\t\tpreviousItem && previousItem.phase !== 'exiting'\n\t\t\t\t\t? previousItem.phase\n\t\t\t\t\t: previousItem\n\t\t\t\t\t\t? 'present'\n\t\t\t\t\t\t: 'entering',\n\t\t})\n\t}\n\n\tfor (const item of previous) {\n\t\tif (nextIds.has(item.node.id)) continue\n\t\tnext.push(item.phase === 'exiting' ? item : { ...item, phase: 'exiting' })\n\t}\n\n\treturn next\n}\n\nfunction requestClusterFadeFrame(callback: FrameRequestCallback): number {\n\tif (typeof requestAnimationFrame === 'function') return requestAnimationFrame(callback)\n\treturn window.setTimeout(() => callback(0), 16)\n}\n\nfunction cancelClusterFadeFrame(frame: number) {\n\tif (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)\n\telse window.clearTimeout(frame)\n}\n\nfunction clusterFadeClassName(phase: ClusterFadePhase): string {\n\treturn `tlui-cmt-cluster-fade tlui-cmt-cluster-fade--${phase}`\n}\n\n/**\n * Leaves folded inside a badge whose live anchor no longer matches the position the rendered\n * model was built with. Visible (unclustered) leaf pins track their anchor live, so they can\n * stay deferred; a badge can't follow a member, so these must pop out of clustering.\n */\nfunction findMovedClusteredLeafIds(\n\trendered: { runtime: ClusterRuntime; table: ClusterTable },\n\tlatest: { table: ClusterTable }\n): string[] {\n\tif (rendered.table === latest.table) return []\n\tconst visible = rendered.runtime.getVisible()\n\tconst latestById = new Map(latest.table.leaves.map((leaf) => [leaf.id, leaf]))\n\tconst moved: string[] = []\n\tfor (const leaf of rendered.table.leaves) {\n\t\tif (visible.has(leaf.id)) continue\n\t\tconst current = latestById.get(leaf.id)\n\t\tif (!current) continue\n\t\tif (\n\t\t\tMath.abs(current.centroid.x - leaf.centroid.x) > MOVED_LEAF_EPSILON ||\n\t\t\tMath.abs(current.centroid.y - leaf.centroid.y) > MOVED_LEAF_EPSILON\n\t\t) {\n\t\t\tmoved.push(leaf.id)\n\t\t}\n\t}\n\treturn moved\n}\n\nfunction getClusterZoomBounds(editor: Editor): { minZoom: number; maxZoom: number } {\n\tconst cameraOptions = editor.getCameraOptions()\n\tconst baseZoom = cameraOptions.constraints ? editor.getBaseZoom() : 1\n\tconst zoomSteps = cameraOptions.zoomSteps\n\treturn {\n\t\tminZoom: zoomSteps[0] * baseZoom,\n\t\tmaxZoom: zoomSteps[zoomSteps.length - 1] * baseZoom,\n\t}\n}\n\nfunction revealDeepLinkedThread(\n\teditor: Editor,\n\tthread: TLCommentThread,\n\ttable: ClusterTable,\n\tzoomBounds: { minZoom: number; maxZoom: number },\n\toptions: CommentingOptions,\n\timpreciseShapeAnchor: { x: number; y: number }\n) {\n\tif (thread.pageId !== editor.getCurrentPageId()) {\n\t\teditor.setCurrentPage(thread.pageId as any)\n\t}\n\n\t// Match where the rendered pin sits (resolved prop-or-option), so the camera centers on the pin.\n\tconst point = anchorPagePoint(editor, thread.anchor, impreciseShapeAnchor)\n\tif (!point) return\n\n\t// With clustering off the pin always renders individually, so skip the zoom-to-split (its cluster\n\t// badge never exists) and just center on the pin.\n\tif (options.enableClustering) {\n\t\tconst parentEvent = findDirectParentEvent(table, thread.id)\n\t\tif (\n\t\t\tparentEvent &&\n\t\t\tNumber.isFinite(parentEvent.zSplit) &&\n\t\t\tparentEvent.zSplit <= zoomBounds.maxZoom\n\t\t) {\n\t\t\tconst zoom = clamp(\n\t\t\t\tparentEvent.zSplit * options.clusterSplitZoomFactor,\n\t\t\t\tzoomBounds.minZoom,\n\t\t\t\tzoomBounds.maxZoom\n\t\t\t)\n\t\t\tcenterOnPointAtZoom(editor, point, zoom)\n\t\t\treturn\n\t\t}\n\t}\n\n\teditor.centerOnPoint(point, { animation: { duration: 200 } })\n}\n\nfunction findDirectParentEvent(table: ClusterTable, threadId: string): MergeEvent | undefined {\n\treturn table.events.find((event) => event.children.some((child) => child.id === threadId))\n}\n\nfunction centerOnPointAtZoom(\n\teditor: Editor,\n\tpoint: { x: number; y: number },\n\tzoom: number,\n\tduration = 200\n) {\n\tconst viewport = editor.getViewportScreenBounds()\n\teditor.setCamera(\n\t\t{\n\t\t\tx: viewport.w / (2 * zoom) - point.x,\n\t\t\ty: viewport.h / (2 * zoom) - point.y,\n\t\t\tz: zoom,\n\t\t},\n\t\t{ animation: { duration } }\n\t)\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.max(min, Math.min(max, value))\n}\n\n// Memoized: cluster nodes and thread records are identity-stable while unchanged, so pins and\n// badges skip re-rendering when the parent re-renders for reasons that don't concern them\n// (leaf recomputes during shape drags, partition changes elsewhere). Camera tracking still\n// works \u2014 each component subscribes to its own viewport position via signals, not via props.\nconst ClusterBadge = memo(function ClusterBadge({\n\teditor,\n\tnode,\n\tonExpand,\n}: {\n\teditor: Editor\n\tnode: ClusterNode\n\tonExpand(node: ClusterNode): void\n}) {\n\tconst point = useValue(\n\t\t'cluster badge point',\n\t\t() => {\n\t\t\tconst pagePoint = editor.pageToViewport(node.centroid)\n\t\t\tif (!isInInflatedViewport(editor, pagePoint)) return null\n\t\t\treturn pagePoint\n\t\t},\n\t\t[editor, node]\n\t)\n\n\tif (!point) return null\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"tlui-cmt-canvas-cluster\"\n\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\tonPointerDown={stop}\n\t\t\tonClick={(e) => {\n\t\t\t\te.stopPropagation()\n\t\t\t\tonExpand(node)\n\t\t\t}}\n\t\t>\n\t\t\t<CountBadge count={node.count} />\n\t\t</div>\n\t)\n})\n\nfunction isInInflatedViewport(editor: Editor, point: { x: number; y: number }): boolean {\n\tconst viewport = editor.getViewportScreenBounds()\n\tconst margin = getCommentingOptions(editor).clusterCullMargin\n\treturn (\n\t\tpoint.x >= -margin &&\n\t\tpoint.y >= -margin &&\n\t\tpoint.x <= viewport.w + margin &&\n\t\tpoint.y <= viewport.h + margin\n\t)\n}\n\n/** The open thread's popover, portaled above the UI panels. Over it, wheel and hover events pass\n * through to the canvas (unless the popover is scrolling its own content), like tldraw's panels. */\nfunction ThreadPopover({\n\tcontainer,\n\tstyle,\n\tchildren,\n}: {\n\tcontainer: HTMLElement\n\tstyle: CSSProperties\n\tchildren: ReactNode\n}) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\tusePassThroughMouseOverEvents(ref)\n\treturn createPortal(\n\t\t<div ref={ref} className=\"tlui-cmt-canvas-popover\" style={style} onPointerDown={stop}>\n\t\t\t{children}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n\n/** A dashed rectangle over a region anchor's bounds, in viewport space. Sits in the canvas layer as\n * a sibling of the pins. `pointer-events` stays off (canvas interaction passes through) unless\n * `movable`, in which case dragging the body translates the region \u2014 previews live, commits on drop. */\nfunction RegionBox({\n\teditor,\n\tbox,\n\tmovable,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\tmovable?: boolean\n\tonPreview?(bounds: BoxModel | null): void\n\tonCommit?(bounds: BoxModel): void\n}) {\n\tconst rect = useValue(\n\t\t'region rect',\n\t\t() => {\n\t\t\t// Position from the page\u2192viewport top-left; screen size scales with zoom, page size doesn't.\n\t\t\tconst topLeft = editor.pageToViewport({ x: box.x, y: box.y })\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\treturn { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h]\n\t)\n\t// The grab point and the box at grab time, captured so the drag translates by a stable delta even\n\t// as the box prop reflows under the live preview.\n\tconst grabRef = useRef<{ page: VecLike; box: BoxModel } | null>(null)\n\tconst translated = (e: ReactPointerEvent<HTMLDivElement>): BoxModel => {\n\t\tconst g = grabRef.current!\n\t\tconst p = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\treturn { ...g.box, x: g.box.x + (p.x - g.page.x), y: g.box.y + (p.y - g.page.y) }\n\t}\n\tconst startMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tgrabRef.current = { page: editor.screenToPage({ x: e.clientX, y: e.clientY }), box }\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (grabRef.current) onPreview?.(translated(e))\n\t}\n\tconst endMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (!grabRef.current) return\n\t\tconst bounds = translated(e)\n\t\tgrabRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit?.(bounds)\n\t}\n\treturn (\n\t\t<div\n\t\t\tclassName={\n\t\t\t\tmovable\n\t\t\t\t\t? 'tlui-cmt-canvas-region tlui-cmt-canvas-region--movable'\n\t\t\t\t\t: 'tlui-cmt-canvas-region'\n\t\t\t}\n\t\t\tstyle={rect}\n\t\t\tonPointerDown={movable ? startMove : undefined}\n\t\t\tonPointerMove={movable ? onMove : undefined}\n\t\t\tonPointerUp={movable ? endMove : undefined}\n\t\t/>\n\t)\n}\n\n/** The live region being dragged out by the comment tool, or nothing when not dragging. */\nfunction RegionDraftBox({ editor }: { editor: Editor }) {\n\tconst box = useValue('region draft', () => regionDraft.get(editor), [editor])\n\tif (!box) return null\n\treturn <RegionBox editor={editor} box={box} />\n}\n\n// A resize handle's normalized 0\u20131 spot on the box, and its cursor. An axis at 0.5 (a side midpoint)\n// is *not* controlled by that handle: corners resize both axes, edges resize only their own.\ninterface RegionHandle {\n\tx: number\n\ty: number\n\tcursor: string\n}\n\n// The four corners (both axes) and the four side midpoints (one axis each).\nconst REGION_CORNERS: readonly RegionHandle[] = [\n\t{ x: 0, y: 0, cursor: 'nwse-resize' },\n\t{ x: 1, y: 0, cursor: 'nesw-resize' },\n\t{ x: 0, y: 1, cursor: 'nesw-resize' },\n\t{ x: 1, y: 1, cursor: 'nwse-resize' },\n]\nconst REGION_EDGES: readonly RegionHandle[] = [\n\t{ x: 0.5, y: 0, cursor: 'ns-resize' },\n\t{ x: 1, y: 0.5, cursor: 'ew-resize' },\n\t{ x: 0.5, y: 1, cursor: 'ns-resize' },\n\t{ x: 0, y: 0.5, cursor: 'ew-resize' },\n]\n\n// Screen-space slack around a region's bounds within which its box and handles stay revealed, so\n// the handles (which sit on the edge) are comfortably reachable.\nconst REGION_HANDLE_MARGIN_PX = 12\n\n/** Resize `box` by dragging `handle` to `cursor` (page coords). Each controlled axis spans from the\n * handle's fixed opposite edge to the cursor (normalized, so dragging past it flips); an axis the\n * handle doesn't control (a midpoint, at 0.5) keeps its original position and size. */\nfunction resizeRegion(box: BoxModel, handle: RegionHandle, cursor: VecLike): BoxModel {\n\tconst controlsX = handle.x !== 0.5\n\tconst controlsY = handle.y !== 0.5\n\tconst fixedX = box.x + (1 - handle.x) * box.w\n\tconst fixedY = box.y + (1 - handle.y) * box.h\n\treturn {\n\t\tx: controlsX ? Math.min(fixedX, cursor.x) : box.x,\n\t\ty: controlsY ? Math.min(fixedY, cursor.y) : box.y,\n\t\tw: controlsX ? Math.abs(cursor.x - fixedX) : box.w,\n\t\th: controlsY ? Math.abs(cursor.y - fixedY) : box.h,\n\t}\n}\n\n/** Draggable handles that resize a region \u2014 corners (both axes) or edges (one axis), per the resize\n * option. Previews live, commits on release. */\nfunction RegionResizeHandles({\n\teditor,\n\tbox,\n\thandles,\n\tonPreview,\n\tonCommit,\n}: {\n\teditor: Editor\n\tbox: BoxModel\n\thandles: readonly RegionHandle[]\n\tonPreview(bounds: BoxModel | null): void\n\tonCommit(bounds: BoxModel): void\n}) {\n\t// The box at pointer-down, captured so the box prop reflowing under the live preview doesn't move\n\t// the fixed edges mid-drag.\n\tconst boxRef = useRef<BoxModel | null>(null)\n\tconst points = useValue(\n\t\t'region handle points',\n\t\t() =>\n\t\t\thandles.map((h) => {\n\t\t\t\tconst p = editor.pageToViewport({ x: box.x + h.x * box.w, y: box.y + h.y * box.h })\n\t\t\t\treturn { ...h, key: `${h.x}-${h.y}`, left: p.x, top: p.y }\n\t\t\t}),\n\t\t[editor, box.x, box.y, box.w, box.h, handles]\n\t)\n\tconst startResize = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tboxRef.current = box\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst resizedTo = (h: RegionHandle, e: ReactPointerEvent<HTMLDivElement>): BoxModel =>\n\t\tresizeRegion(boxRef.current!, h, editor.screenToPage({ x: e.clientX, y: e.clientY }))\n\tconst onResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (boxRef.current) onPreview(resizedTo(h, e))\n\t}\n\tconst endResize = (h: RegionHandle) => (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tif (!boxRef.current) return\n\t\tconst bounds = resizedTo(h, e)\n\t\tboxRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId))\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\tonCommit(bounds)\n\t}\n\treturn (\n\t\t<>\n\t\t\t{points.map((h) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={h.key}\n\t\t\t\t\tclassName=\"tlui-cmt-canvas-region-handle\"\n\t\t\t\t\tstyle={{ left: h.left, top: h.top, cursor: h.cursor }}\n\t\t\t\t\tonPointerDown={startResize}\n\t\t\t\t\tonPointerMove={onResize(h)}\n\t\t\t\t\tonPointerUp={endResize(h)}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</>\n\t)\n}\n\nconst ThreadPin = memo(function ThreadPin({\n\teditor,\n\tthread,\n\tregionOptions,\n\t...props\n}: Omit<CanvasCommentsProps, 'regionOptions'> & {\n\teditor: Editor\n\tthread: TLCommentThread\n\tregionOptions: RegionCommentOptions\n}) {\n\tconst {\n\t\tcurrentUserId,\n\t\tresolveName,\n\t\tonPostComment,\n\t\tisCommentUnread,\n\t\tonCommentRead,\n\t\tgetMentionSuggestions,\n\t\trenderMentionSuggestion,\n\t} = props\n\tconst options = useCommentingOptions()\n\tconst impreciseShapeAnchor = props.impreciseShapeAnchor ?? options.impreciseShapeAnchor\n\tconst container = useContainer()\n\tconst comments = useThreadComments(editor, thread.id)\n\tconst msg = useTranslation()\n\t// Only one thread's popover is open at a time \u2014 shared across pins via the atom.\n\tconst open = useValue('thread open', () => openThreadId.get(editor) === thread.id, [\n\t\teditor,\n\t\tthread.id,\n\t])\n\tconst [reply, setReply] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst [editingId, setEditingId] = useState<string | null>(null)\n\tconst [editText, setEditText] = useState<TLRichText>(EMPTY_COMMENT)\n\t// While dragging the marker, its page point overrides the anchor's; committed on drop.\n\tconst [dragPagePoint, setDragPagePoint] = useState<{ x: number; y: number } | null>(null)\n\t// The live bounds while a corner handle is resizing the region, else null.\n\tconst [resizeBounds, setResizeBounds] = useState<BoxModel | null>(null)\n\t// Whether the pin marker is hovered \u2014 only consulted by the 'pin-hover' reveal mode.\n\tconst [pinHovered, setPinHovered] = useState(false)\n\t// The 'pointer' reveal mode: is the pointer within the region's bounds (plus a grab margin)?\n\t// Driven by pointer position, not DOM hover, so moving from anywhere in the region out to a corner\n\t// handle never loses the affordance \u2014 the box stays `pointer-events: none`.\n\tconst pointerInRegion = useValue(\n\t\t'pointer in region',\n\t\t() => {\n\t\t\tif (thread.anchor.type !== 'region' || thread.pageId !== editor.getCurrentPageId())\n\t\t\t\treturn false\n\t\t\tconst m = REGION_HANDLE_MARGIN_PX / editor.getZoomLevel()\n\t\t\tconst p = editor.inputs.getCurrentPagePoint()\n\t\t\tconst a = thread.anchor\n\t\t\treturn p.x >= a.x - m && p.x <= a.x + a.w + m && p.y >= a.y - m && p.y <= a.y + a.h + m\n\t\t},\n\t\t[editor, thread.anchor, thread.pageId]\n\t)\n\t// A region's box and handles are revealed while open or mid-resize, plus \u2014 per the reveal mode \u2014\n\t// while the pointer is within the region ('pointer') or the pin is hovered ('pin-hover').\n\tconst revealed =\n\t\topen ||\n\t\tresizeBounds != null ||\n\t\t(regionOptions.reveal === 'pointer' && pointerInRegion) ||\n\t\t(regionOptions.reveal === 'pin-hover' && pinHovered)\n\t// The resize handles: side midpoints ('edges'), or the corners other than the pin's ('corners').\n\tconst resizeHandles = useMemo(\n\t\t() =>\n\t\t\tregionOptions.resize === 'edges'\n\t\t\t\t? REGION_EDGES\n\t\t\t\t: REGION_CORNERS.filter(\n\t\t\t\t\t\t(c) => c.x !== regionOptions.pinCorner.x || c.y !== regionOptions.pinCorner.y\n\t\t\t\t\t),\n\t\t[regionOptions.resize, regionOptions.pinCorner]\n\t)\n\tconst dragRef = useRef<{ startX: number; startY: number; moved: boolean } | null>(null)\n\tconst markerRef = useRef<HTMLDivElement>(null)\n\n\t// Clicking outside the open popover (and off its own pin) closes the thread \u2014 mirrors the\n\t// pending composer's dismiss. Capture phase + a class check rather than stopPropagation, since the\n\t// popover portals elsewhere in the DOM. The pin marker is excluded so its own click-to-toggle\n\t// handles it instead of this closing then the toggle reopening.\n\tuseEffect(() => {\n\t\tif (!open) return\n\t\tconst onPointerDown = (e: PointerEvent) => {\n\t\t\tconst target = e.target as HTMLElement | null\n\t\t\tif (!target) return\n\t\t\tif (target.closest('.tlui-cmt-canvas-popover')) return\n\t\t\tconst marker = markerRef.current\n\t\t\tif (marker && marker.contains(target)) return\n\t\t\t// A press on a region's resize handle or movable body edits this thread \u2014 don't dismiss it.\n\t\t\tif (target.closest('.tlui-cmt-canvas-region-handle, .tlui-cmt-canvas-region--movable')) return\n\t\t\t// A click inside a menu/popover layered above us (the sidebar's filter or overflow\n\t\t\t// dropdown, or the composer's mention picker \u2014 all portaled elsewhere) belongs to that\n\t\t\t// layer; defer to its own dismissal instead of closing the thread out from under it.\n\t\t\tif (\n\t\t\t\ttarget.closest('.tlui-menu, [data-radix-popper-content-wrapper], .tlui-cmt-mention-popup')\n\t\t\t)\n\t\t\t\treturn\n\t\t\topenThreadId.set(editor, null)\n\t\t}\n\t\tdocument.addEventListener('pointerdown', onPointerDown, true)\n\t\treturn () => document.removeEventListener('pointerdown', onPointerDown, true)\n\t}, [open, editor])\n\n\tconst point = useValue(\n\t\t'pin point',\n\t\t() => {\n\t\t\tif (thread.pageId !== editor.getCurrentPageId()) return null\n\t\t\tconst pagePoint = anchorPagePoint(editor, thread.anchor, impreciseShapeAnchor)\n\t\t\treturn pagePoint ? editor.pageToViewport(pagePoint) : null\n\t\t},\n\t\t[editor, thread.anchor, thread.pageId, impreciseShapeAnchor]\n\t)\n\tconst visible = point !== null\n\n\t// While the popover is open, every unread comment on display gets reported read \u2014 including\n\t// replies that arrive while it stays open, since the effect re-runs as `comments` changes.\n\t// The host's receipt write flips isCommentUnread to false, so re-runs find nothing to report.\n\tuseEffect(() => {\n\t\tif (!open || !visible || !isCommentUnread || !onCommentRead) return\n\t\tfor (const comment of comments) {\n\t\t\tif (isCommentUnread(comment.id)) {\n\t\t\t\tonCommentRead(comment.id)\n\t\t\t}\n\t\t}\n\t}, [open, visible, comments, isCommentUnread, onCommentRead])\n\n\tif (!point) return null\n\n\tconst postReply = () => {\n\t\tif (isCommentEmpty(reply) || !currentUserId) return\n\t\tcommitCommentMutation(editor, () => {\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\tputCommentRecords(editor, [comment])\n\t\t\tif (onPostComment) onPostComment(comment)\n\t\t})\n\t\tsetReply(EMPTY_COMMENT)\n\t}\n\n\tconst toggleResolve = () => {\n\t\tif (!currentUserId) return\n\t\tcommitCommentMutation(editor, () => {\n\t\t\tputCommentRecords(editor, [\n\t\t\t\t{\n\t\t\t\t\t...thread,\n\t\t\t\t\tresolved: thread.resolved ? null : { at: Date.now(), by: currentUserId },\n\t\t\t\t},\n\t\t\t])\n\t\t})\n\t}\n\n\tconst deleteThread = () => {\n\t\topenThreadId.set(editor, null)\n\t\tcommitCommentMutation(editor, () =>\n\t\t\tremoveCommentRecords(editor, [thread.id, ...comments.map((c) => c.id)])\n\t\t)\n\t}\n\n\tconst startEdit = (comment: TLComment) => {\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\tcommitCommentMutation(editor, () => {\n\t\t\tputCommentRecords(editor, [{ ...comment, body: editText, editedAt: Date.now() }])\n\t\t})\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 an edit affordance on your own comments.\n\tconst renderComment = (card: CommentCardProps, index: number): ReactNode => {\n\t\tconst comment = comments[index]\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\tonKeyDown={(e) => {\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\tplaceholder={msg('comments.edit-placeholder')}\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('comments.save')}\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\tactions={\n\t\t\t\t\tcomment.authorId === currentUserId ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tclassName=\"tlui-cmt-thread__action\"\n\t\t\t\t\t\t\ttitle={msg('comments.edit')}\n\t\t\t\t\t\t\tonClick={() => startEdit(comment)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TldrawUiIcon icon=\"dots-horizontal\" label={msg('comments.edit')} small />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : undefined\n\t\t\t\t}\n\t\t\t/>\n\t\t)\n\t}\n\n\tconst headerActions = (\n\t\t<>\n\t\t\t{currentUserId && (\n\t\t\t\t<button\n\t\t\t\t\tclassName=\"tlui-cmt-thread__action\"\n\t\t\t\t\ttitle={msg(thread.resolved ? 'comments.reopen' : 'comments.resolve')}\n\t\t\t\t\tonClick={toggleResolve}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon\n\t\t\t\t\t\ticon=\"check\"\n\t\t\t\t\t\tlabel={msg(thread.resolved ? 'comments.reopen' : 'comments.resolve')}\n\t\t\t\t\t\tsmall\n\t\t\t\t\t/>\n\t\t\t\t</button>\n\t\t\t)}\n\t\t\t{currentUserId && (\n\t\t\t\t<button\n\t\t\t\t\tclassName=\"tlui-cmt-thread__action\"\n\t\t\t\t\ttitle={msg('comments.delete')}\n\t\t\t\t\tonClick={deleteThread}\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"trash\" label={msg('comments.delete')} small />\n\t\t\t\t</button>\n\t\t\t)}\n\t\t\t<button\n\t\t\t\tclassName=\"tlui-cmt-thread__action\"\n\t\t\t\ttitle={msg('comments.dismiss')}\n\t\t\t\tonClick={() => openThreadId.set(editor, null)}\n\t\t\t>\n\t\t\t\t<TldrawUiIcon icon=\"cross-2\" label={msg('comments.dismiss')} small />\n\t\t\t</button>\n\t\t</>\n\t)\n\n\tconst PinContent = options.components.PinContent\n\t// The `PinContent` component slot overrides the built-in author-initial default.\n\tconst pinContent = PinContent ? (\n\t\t<PinContent thread={thread} comments={comments} />\n\t) : (\n\t\tinitialOf(resolveName(thread.createdBy) ?? UNKNOWN_AUTHOR)\n\t)\n\n\t// Drag the marker to move the thread: its position is overridden locally while dragging, then\n\t// re-anchored on drop. A point/shape thread re-anchors to whatever it's dropped on (a shape, else\n\t// a point); a region thread translates, keeping its size. A pointer that barely moves is a click \u2014\n\t// toggle the popover.\n\t// Which affordances move a region, per the option: 'pin' \u2192 pin only, 'body' \u2192 body only, 'both'.\n\tconst isRegion = thread.anchor.type === 'region'\n\tconst pinMovable = regionOptions.move !== 'body'\n\tconst bodyMovable = regionOptions.move !== 'pin'\n\tconst startDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\te.stopPropagation()\n\t\tdragRef.current = { startX: e.clientX, startY: e.clientY, moved: false }\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\t// A region that moves by its body ignores pin drags (the pin only toggles the thread).\n\t\tif (isRegion && !pinMovable) return\n\t\tif (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < 4) return\n\t\tdrag.moved = true\n\t\tsetDragPagePoint(editor.screenToPage({ x: e.clientX, y: e.clientY }))\n\t}\n\tconst endDrag = (e: ReactPointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current\n\t\tdragRef.current = null\n\t\tif (e.currentTarget.hasPointerCapture(e.pointerId)) {\n\t\t\te.currentTarget.releasePointerCapture(e.pointerId)\n\t\t}\n\t\tif (!drag) return\n\t\tif (!drag.moved) {\n\t\t\topenThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)\n\t\t\treturn\n\t\t}\n\t\tconst pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\tsetDragPagePoint(null)\n\t\tlet anchor: TLCommentThread['anchor']\n\t\tif (thread.anchor.type === 'region') {\n\t\t\t// Translate so the pin (the region's pin corner) lands at the drop; size unchanged.\n\t\t\tanchor = {\n\t\t\t\t...thread.anchor,\n\t\t\t\tx: pagePoint.x - regionOptions.pinCorner.x * thread.anchor.w,\n\t\t\t\ty: pagePoint.y - regionOptions.pinCorner.y * thread.anchor.h,\n\t\t\t}\n\t\t} else {\n\t\t\tconst hit = editor.getShapeAtPoint(pagePoint, { hitInside: true })\n\t\t\tanchor = hit\n\t\t\t\t? shapeAnchorAt(editor, hit.id, pagePoint, e.altKey)\n\t\t\t\t: { type: 'point', x: pagePoint.x, y: pagePoint.y }\n\t\t}\n\t\tcommitCommentMutation(editor, () => putCommentRecords(editor, [{ ...thread, anchor }]), 'drag')\n\t}\n\n\t// The pin (and its popover) track the live edit: a resize moves it to the region's pin corner, a\n\t// move to the drag point; otherwise it sits at the stored anchor's viewport point.\n\tconst livePinPage = resizeBounds\n\t\t? regionPinPoint(resizeBounds, regionOptions.pinCorner)\n\t\t: dragPagePoint\n\tconst renderPoint = livePinPage ? editor.pageToViewport(livePinPage) : point\n\n\t// A region's live box bounds, by priority: a corner resize, else a pin-drag translation (the pin\n\t// corner tracks the cursor), else the stored anchor. Undefined for non-region threads.\n\tconst regionAnchor = thread.anchor.type === 'region' ? thread.anchor : undefined\n\tconst movedRegion =\n\t\tregionAnchor && dragPagePoint\n\t\t\t? {\n\t\t\t\t\t...regionAnchor,\n\t\t\t\t\tx: dragPagePoint.x - regionOptions.pinCorner.x * regionAnchor.w,\n\t\t\t\t\ty: dragPagePoint.y - regionOptions.pinCorner.y * regionAnchor.h,\n\t\t\t\t}\n\t\t\t: regionAnchor\n\tconst regionBoxBounds = resizeBounds ?? movedRegion\n\tconst commitResize = (bounds: BoxModel) => {\n\t\tsetResizeBounds(null)\n\t\teditor.run(\n\t\t\t() => putCommentRecords(editor, [{ ...thread, anchor: { type: 'region', ...bounds } }]),\n\t\t\t{\n\t\t\t\thistory: 'ignore',\n\t\t\t}\n\t\t)\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{regionBoxBounds && (dragPagePoint || revealed) && (\n\t\t\t\t<RegionBox\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tbox={regionBoxBounds}\n\t\t\t\t\tmovable={bodyMovable && !dragPagePoint}\n\t\t\t\t\tonPreview={setResizeBounds}\n\t\t\t\t\tonCommit={commitResize}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{regionBoxBounds && revealed && !dragPagePoint && regionOptions.resize !== 'none' && (\n\t\t\t\t<RegionResizeHandles\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tbox={regionBoxBounds}\n\t\t\t\t\thandles={resizeHandles}\n\t\t\t\t\tonPreview={setResizeBounds}\n\t\t\t\t\tonCommit={commitResize}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tclassName={open ? 'tlui-cmt-canvas-pin tlui-cmt-canvas-pin--open' : 'tlui-cmt-canvas-pin'}\n\t\t\t\tstyle={{ left: renderPoint.x, top: renderPoint.y }}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={markerRef}\n\t\t\t\t\tclassName=\"tlui-cmt-canvas-pin__marker\"\n\t\t\t\t\tonPointerDown={startDrag}\n\t\t\t\t\tonPointerMove={onDrag}\n\t\t\t\t\tonPointerUp={endDrag}\n\t\t\t\t\tonPointerEnter={() => setPinHovered(true)}\n\t\t\t\t\tonPointerLeave={() => setPinHovered(false)}\n\t\t\t\t>\n\t\t\t\t\t<CommentPin resolved={thread.resolved != null} open={open}>\n\t\t\t\t\t\t{pinContent}\n\t\t\t\t\t</CommentPin>\n\t\t\t\t</div>\n\t\t\t\t{/* The popover portals up to the menus layer (above the UI panels) so it isn't clipped;\n\t\t\t the pin itself stays in the canvas-in-front layer, beneath the UI. */}\n\t\t\t\t{open && (\n\t\t\t\t\t<ThreadPopover\n\t\t\t\t\t\tcontainer={container}\n\t\t\t\t\t\tstyle={{ left: renderPoint.x + 36, top: renderPoint.y - 28 }}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CommentThread\n\t\t\t\t\t\t\theader={msg('comments.thread-title')}\n\t\t\t\t\t\t\theaderActions={headerActions}\n\t\t\t\t\t\t\trenderComment={renderComment}\n\t\t\t\t\t\t\tcomments={comments.map((c) => toCardProps(c, props, options.components))}\n\t\t\t\t\t\t\tresolvedBanner={\n\t\t\t\t\t\t\t\tthread.resolved\n\t\t\t\t\t\t\t\t\t? msg('comments.resolved-by').replace(\n\t\t\t\t\t\t\t\t\t\t\t'{name}',\n\t\t\t\t\t\t\t\t\t\t\tresolveName(thread.resolved.by) ?? UNKNOWN_AUTHOR\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcomposer={\n\t\t\t\t\t\t\t\tcurrentUserId && !thread.resolved\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\tauthor: resolveName(currentUserId) ?? UNKNOWN_AUTHOR,\n\t\t\t\t\t\t\t\t\t\t\tplaceholder: msg('comments.reply-placeholder'),\n\t\t\t\t\t\t\t\t\t\t\tsendLabel: msg('comments.send'),\n\t\t\t\t\t\t\t\t\t\t\tvalue: reply,\n\t\t\t\t\t\t\t\t\t\t\tonChange: setReply,\n\t\t\t\t\t\t\t\t\t\t\tonSubmit: postReply,\n\t\t\t\t\t\t\t\t\t\t\tdisabled: isCommentEmpty(reply),\n\t\t\t\t\t\t\t\t\t\t\tgetMentionSuggestions,\n\t\t\t\t\t\t\t\t\t\t\trenderMentionSuggestion,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ThreadPopover>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</>\n\t)\n})\n\nfunction PendingComposer({\n\teditor,\n\tpending,\n\tcurrentUserId,\n\tresolveName,\n\tonPostComment,\n\tgetMentionSuggestions,\n\trenderMentionSuggestion,\n}: CanvasCommentsProps & { editor: Editor; pending: PendingComment }) {\n\tconst [text, setText] = useState<TLRichText>(EMPTY_COMMENT)\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst msg = useTranslation()\n\tconst container = useContainer()\n\t// Over this floating panel, scroll and hover reach the canvas (except where it scrolls itself).\n\tusePassThroughWheelEvents(ref)\n\tusePassThroughMouseOverEvents(ref)\n\n\tconst point = useValue('composer point', () => editor.pageToViewport(pending.point), [\n\t\teditor,\n\t\tpending.point,\n\t])\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\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\tcommitCommentMutation(editor, () => {\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\tputCommentRecords(editor, [thread, comment])\n\t\t\tif (onPostComment) onPostComment(comment)\n\t\t})\n\t\tsetText(EMPTY_COMMENT)\n\t\tpendingComment.set(editor, null)\n\t}\n\n\treturn createPortal(\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName=\"tlui-cmt-canvas-composer\"\n\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\tonPointerDown={stop}\n\t\t\tonKeyDown={(e) => {\n\t\t\t\tif (e.key === 'Escape' && !isMentionPickerOpen()) pendingComment.set(editor, null)\n\t\t\t}}\n\t\t>\n\t\t\t<CommentComposer\n\t\t\t\tauthor={currentUserId ? (resolveName(currentUserId) ?? UNKNOWN_AUTHOR) : ''}\n\t\t\t\tplaceholder={msg('comments.add-placeholder')}\n\t\t\t\tsendLabel={msg('comments.send')}\n\t\t\t\tvalue={text}\n\t\t\t\tonChange={setText}\n\t\t\t\tonSubmit={submit}\n\t\t\t\tdisabled={isCommentEmpty(text)}\n\t\t\t\tgetMentionSuggestions={getMentionSuggestions}\n\t\t\t\trenderMentionSuggestion={renderMentionSuggestion}\n\t\t\t\tautoFocus\n\t\t\t\tleading={draftAvatar}\n\t\t\t/>\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuHE;AAvHF,mBAUO;AACP,uBAA6B;AAC7B,oBAmBO;AACP,iCAAoC;AACpC,qBAA0D;AAE1D,0BAA8C;AAC9C,8BAAgC;AAChC,gCAA8C;AAC9C,yBAA2B;AAC3B,4BAA8B;AAC9B,yBAA2B;AAE3B,gCAAoC;AACpC,2BAAqC;AACrC,0BAA4B;AAC5B,4BAA+B;AAC/B,2BAA0E;AAE1E,mBAAqD;AACrD,qBAAqC;AACrC,qBAKO;AACP,4BAIO;AACP,mBAQO;AACP,0BAA+D;AAsC/D,MAAM,OAAO,CAAC,MAAmC,EAAE,gBAAgB;AAEnE,MAAM,YAAY,CAAC,cAA0B,iCAAkB,KAAK,KAAK,CAAC,KAAK,KAAK,YAAY;AAChG,MAAM,kBAAkB;AAExB,MAAM,yBAAyB;AAI/B,MAAM,cACL,4CAAC,iCACA;AAAA,EAAC;AAAA;AAAA,IACA,SAAQ;AAAA,IACR,OAAM;AAAA,IACN,QAAO;AAAA,IACP,MAAK;AAAA,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e,eAAc,OAAO;AAAA,IACzC,CAAC;AACD,YAAQ,uCAAa;AACrB,gCAAe,IAAI,QAAQ,IAAI;AAAA,EAChC;AAEA,aAAO;AAAA,IACN;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,EAAE,MAAM,MAAM,GAAG,KAAK,MAAM,EAAE;AAAA,QACrC,eAAe;AAAA,QACf,WAAW,CAAC,MAAM;AACjB,cAAI,EAAE,QAAQ,YAAY,KAAC,+CAAoB,EAAG,6BAAe,IAAI,QAAQ,IAAI;AAAA,QAClF;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,QAAQ,gBAAiB,YAAY,aAAa,KAAK,uCAAkB;AAAA,YACzE,aAAa,IAAI,0BAA0B;AAAA,YAC3C,WAAW,IAAI,eAAe;AAAA,YAC9B,OAAO;AAAA,YACP,UAAU;AAAA,YACV,UAAU;AAAA,YACV,cAAU,0CAAe,IAAI;AAAA,YAC7B;AAAA,YACA;AAAA,YACA,WAAS;AAAA,YACT,SAAS;AAAA;AAAA,QACV;AAAA;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;",
6
6
  "names": ["ClusterBadge", "ThreadPin"]
7
7
  }
@@ -107,7 +107,7 @@ function CanvasCommentsSidebar(props) {
107
107
  {
108
108
  items,
109
109
  header: header ?? msg("comments.title"),
110
- headerAction: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "cmt-list__header-actions", children: [
110
+ headerAction: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "tlui-cmt-list__header-actions", children: [
111
111
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
112
  import_comments_filter_menu.CommentsFilterMenu,
113
113
  {
@@ -127,7 +127,7 @@ function SidebarPanel({ container, children }) {
127
127
  const ref = (0, import_react.useRef)(null);
128
128
  (0, import_tldraw.usePassThroughMouseOverEvents)(ref);
129
129
  return (0, import_react_dom.createPortal)(
130
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className: "cmt-canvas-sidebar", children }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className: "tlui-cmt-canvas-sidebar", children }),
131
131
  container
132
132
  );
133
133
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/canvas/comments-sidebar.tsx"],
4
- "sourcesContent": ["import { ReactNode, useRef } from 'react'\nimport { createPortal } from 'react-dom'\nimport {\n\tTLComment,\n\tTLCommentId,\n\tuseContainer,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentListItemProps, CommentsList } from '../ui/comments-list'\nimport { UNKNOWN_AUTHOR } from './comment-render'\nimport { CommentsFilterMenu } from './comments-filter-menu'\nimport { CommentsOverflowMenu } from './comments-overflow-menu'\nimport { useComments, useCommentThreads } from './hooks'\nimport { useCommentingEnabled } from './license'\nimport { useCommentingOptions } from './options'\nimport { richTextToPlaintext } from './rich-text'\nimport { openThreadId, sidebarFilters } from './state'\nimport { focusThread } from './thread-state'\n\n/** @public */\nexport interface CanvasCommentsSidebarProps {\n\t/** Map an author id to a display name, or `undefined` when the id can't be named. */\n\tresolveName(id: string): string | undefined\n\t/** The signed-in user's id. Enables the \"only your threads\" filter when present. */\n\tcurrentUserId?: string\n\t/**\n\t * Whether a comment is unread for the current user (return true for unread). Enables the\n\t * \"only unread\" filter when present.\n\t */\n\tisCommentUnread?(commentId: TLCommentId): boolean\n\t/** Tool ids that show the sidebar. Defaults to the comment tool. */\n\ttools?: string[]\n\t/** Header above the list. */\n\theader?: ReactNode\n\t/** Shown when the page has no threads. */\n\tempty?: ReactNode\n\t/** Where imprecise shape pins sit, so navigation centres on the same spot. Default top-right. */\n\timpreciseShapeAnchor?: { x: number; y: number }\n}\n\n/**\n * A comments list panel for the current page, shown while the comment tool is active. Clicking a\n * thread brings its pin into view and opens it. Batteries-included over the store (a sibling to\n * `CanvasComments`); `CommentsList` is exported for a differently-placed or always-on list.\n * @public @react\n */\nexport function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {\n\tconst {\n\t\tresolveName,\n\t\tcurrentUserId,\n\t\tisCommentUnread,\n\t\ttools,\n\t\theader,\n\t\tempty,\n\t\timpreciseShapeAnchor,\n\t} = props\n\tconst editor = useEditor()\n\tconst options = useCommentingOptions()\n\tconst sidebarTools = tools ?? ['comment']\n\tconst container = useContainer()\n\tconst commentingEnabled = useCommentingEnabled()\n\tconst msg = useTranslation()\n\tconst threads = useCommentThreads(editor)\n\tconst comments = useComments(editor)\n\tconst currentPageId = useValue('page id', () => editor.getCurrentPageId(), [editor])\n\tconst activeTool = useValue('tool id', () => editor.getCurrentToolId(), [editor])\n\tconst openId = useValue('open thread', () => openThreadId.get(editor), [editor])\n\tconst filters = useValue('sidebar filters', () => sidebarFilters.get(editor), [editor])\n\tconst pageNames = useValue(\n\t\t'page names',\n\t\t() => new Map(editor.getPages().map((page) => [page.id, page.name])),\n\t\t[editor]\n\t)\n\n\tif (!commentingEnabled || !sidebarTools.includes(activeTool)) return null\n\n\t// Group comments by thread (they arrive oldest-first, so [0] is each thread's first comment).\n\tconst byThread = new Map<string, TLComment[]>()\n\tfor (const comment of comments) {\n\t\tconst list = byThread.get(comment.threadId) ?? []\n\t\tlist.push(comment)\n\t\tbyThread.set(comment.threadId, list)\n\t}\n\n\t// Page scoping is treated as scoping, not a filter: an empty page reads \"no comments yet\",\n\t// while a list emptied by the toggles below reads \"nothing matches your filters\".\n\tconst pageThreads = threads.filter(\n\t\t(thread) => !filters.onlyCurrentPage || thread.pageId === currentPageId\n\t)\n\n\tconst items: CommentListItemProps[] = pageThreads\n\t\t.filter((thread) => filters.showResolved || thread.resolved == null)\n\t\t// \"Only mine\" is ignored without a known user \u2014 otherwise a persisted onlyMine=true would\n\t\t// empty the list for a signed-out viewer, with the (hidden) toggle giving no way to clear it.\n\t\t.filter(\n\t\t\t(thread) =>\n\t\t\t\t!filters.onlyMine || currentUserId === undefined || thread.createdBy === currentUserId\n\t\t)\n\t\t// \"Only unread\" is likewise ignored without a read-status source.\n\t\t.filter(\n\t\t\t(thread) =>\n\t\t\t\t!filters.onlyUnread ||\n\t\t\t\tisCommentUnread === undefined ||\n\t\t\t\t(byThread.get(thread.id) ?? []).some((c) => isCommentUnread(c.id))\n\t\t)\n\t\t.map((thread) => {\n\t\t\tconst threadComments = byThread.get(thread.id) ?? []\n\t\t\tconst first = threadComments[0]\n\t\t\tlet preview: ReactNode = ''\n\t\t\t// The `ThreadPreview` component slot overrides the built-in plaintext default.\n\t\t\tconst ThreadPreview = options.components.ThreadPreview\n\t\t\tif (first) {\n\t\t\t\tpreview = ThreadPreview ? (\n\t\t\t\t\t<ThreadPreview comment={first} />\n\t\t\t\t) : (\n\t\t\t\t\trichTextToPlaintext(first.body, resolveName)\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: thread.id,\n\t\t\t\tauthor: resolveName(thread.createdBy) ?? UNKNOWN_AUTHOR,\n\t\t\t\tpreview,\n\t\t\t\tdate: new Date((first ?? thread).createdAt).toISOString(),\n\t\t\t\tresolved: thread.resolved != null,\n\t\t\t\tpage: pageNames.get(thread.pageId),\n\t\t\t\tcount: threadComments.length,\n\t\t\t\tselected: openId === thread.id,\n\t\t\t}\n\t\t})\n\t\t// unresolved first, then most-recent first\n\t\t.sort((a, b) => {\n\t\t\tif (!!a.resolved !== !!b.resolved) return a.resolved ? 1 : -1\n\t\t\treturn b.date.localeCompare(a.date)\n\t\t})\n\n\tconst focus = (id: string) => {\n\t\tconst thread = threads.find((t) => t.id === id)\n\t\t// Resolve prop-or-option like the overlay pins do, so sidebar navigation centers on the same\n\t\t// spot the pin renders at when the anchor is configured via `CommentTool.configure`.\n\t\tif (thread) focusThread(editor, thread, impreciseShapeAnchor ?? options.impreciseShapeAnchor)\n\t}\n\n\treturn (\n\t\t<SidebarPanel container={container}>\n\t\t\t<CommentsList\n\t\t\t\titems={items}\n\t\t\t\theader={header ?? msg('comments.title')}\n\t\t\t\theaderAction={\n\t\t\t\t\t<div className=\"cmt-list__header-actions\">\n\t\t\t\t\t\t<CommentsFilterMenu\n\t\t\t\t\t\t\tcanFilterByAuthor={currentUserId !== undefined}\n\t\t\t\t\t\t\tcanFilterByUnread={isCommentUnread !== undefined}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<CommentsOverflowMenu />\n\t\t\t\t\t</div>\n\t\t\t\t}\n\t\t\t\tempty={\n\t\t\t\t\titems.length === 0 && pageThreads.length > 0\n\t\t\t\t\t\t? msg('comments.empty-filtered')\n\t\t\t\t\t\t: (empty ?? msg('comments.empty'))\n\t\t\t\t}\n\t\t\t\tresolvedLabel={msg('comments.resolved')}\n\t\t\t\tonSelect={focus}\n\t\t\t/>\n\t\t</SidebarPanel>\n\t)\n}\n\n/** The sidebar surface, portaled into the container. It scrolls its own list, so \u2014 unlike tldraw's\n * wheel-transparent panels \u2014 a wheel over it doesn't pan the canvas. Hover still passes through so\n * shapes beneath it stay interactive. */\nfunction SidebarPanel({ container, children }: { container: HTMLElement; children: ReactNode }) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughMouseOverEvents(ref)\n\treturn createPortal(\n\t\t<div ref={ref} className=\"cmt-canvas-sidebar\">\n\t\t\t{children}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoHK;AApHL,mBAAkC;AAClC,uBAA6B;AAC7B,oBAQO;AACP,2BAAmD;AACnD,4BAA+B;AAC/B,kCAAmC;AACnC,oCAAqC;AACrC,mBAA+C;AAC/C,qBAAqC;AACrC,qBAAqC;AACrC,uBAAoC;AACpC,mBAA6C;AAC7C,0BAA4B;AA6BrB,SAAS,sBAAsB,OAAmC;AACxE,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AA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AC,SAAI,WAAU,4BACd;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,mBAAmB,kBAAkB;AAAA,YACrC,mBAAmB,oBAAoB;AAAA;AAAA,QACxC;AAAA,QACA,4CAAC,sDAAqB;AAAA,SACvB;AAAA,MAED,OACC,MAAM,WAAW,KAAK,YAAY,SAAS,IACxC,IAAI,yBAAyB,IAC5B,SAAS,IAAI,gBAAgB;AAAA,MAElC,eAAe,IAAI,mBAAmB;AAAA,MACtC,UAAU;AAAA;AAAA,EACX,GACD;AAEF;AAKA,SAAS,aAAa,EAAE,WAAW,SAAS,GAAoD;AAC/F,QAAM,UAAM,qBAAuB,IAAI;AACvC,mDAA8B,GAAG;AACjC,aAAO;AAAA,IACN,4CAAC,SAAI,KAAU,WAAU,sBACvB,UACF;AAAA,IACA;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import { ReactNode, useRef } from 'react'\nimport { createPortal } from 'react-dom'\nimport {\n\tTLComment,\n\tTLCommentId,\n\tuseContainer,\n\tuseEditor,\n\tusePassThroughMouseOverEvents,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { CommentListItemProps, CommentsList } from '../ui/comments-list'\nimport { UNKNOWN_AUTHOR } from './comment-render'\nimport { CommentsFilterMenu } from './comments-filter-menu'\nimport { CommentsOverflowMenu } from './comments-overflow-menu'\nimport { useComments, useCommentThreads } from './hooks'\nimport { useCommentingEnabled } from './license'\nimport { useCommentingOptions } from './options'\nimport { richTextToPlaintext } from './rich-text'\nimport { openThreadId, sidebarFilters } from './state'\nimport { focusThread } from './thread-state'\n\n/** @public */\nexport interface CanvasCommentsSidebarProps {\n\t/** Map an author id to a display name, or `undefined` when the id can't be named. */\n\tresolveName(id: string): string | undefined\n\t/** The signed-in user's id. Enables the \"only your threads\" filter when present. */\n\tcurrentUserId?: string\n\t/**\n\t * Whether a comment is unread for the current user (return true for unread). Enables the\n\t * \"only unread\" filter when present.\n\t */\n\tisCommentUnread?(commentId: TLCommentId): boolean\n\t/** Tool ids that show the sidebar. Defaults to the comment tool. */\n\ttools?: string[]\n\t/** Header above the list. */\n\theader?: ReactNode\n\t/** Shown when the page has no threads. */\n\tempty?: ReactNode\n\t/** Where imprecise shape pins sit, so navigation centres on the same spot. Default top-right. */\n\timpreciseShapeAnchor?: { x: number; y: number }\n}\n\n/**\n * A comments list panel for the current page, shown while the comment tool is active. Clicking a\n * thread brings its pin into view and opens it. Batteries-included over the store (a sibling to\n * `CanvasComments`); `CommentsList` is exported for a differently-placed or always-on list.\n * @public @react\n */\nexport function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {\n\tconst {\n\t\tresolveName,\n\t\tcurrentUserId,\n\t\tisCommentUnread,\n\t\ttools,\n\t\theader,\n\t\tempty,\n\t\timpreciseShapeAnchor,\n\t} = props\n\tconst editor = useEditor()\n\tconst options = useCommentingOptions()\n\tconst sidebarTools = tools ?? ['comment']\n\tconst container = useContainer()\n\tconst commentingEnabled = useCommentingEnabled()\n\tconst msg = useTranslation()\n\tconst threads = useCommentThreads(editor)\n\tconst comments = useComments(editor)\n\tconst currentPageId = useValue('page id', () => editor.getCurrentPageId(), [editor])\n\tconst activeTool = useValue('tool id', () => editor.getCurrentToolId(), [editor])\n\tconst openId = useValue('open thread', () => openThreadId.get(editor), [editor])\n\tconst filters = useValue('sidebar filters', () => sidebarFilters.get(editor), [editor])\n\tconst pageNames = useValue(\n\t\t'page names',\n\t\t() => new Map(editor.getPages().map((page) => [page.id, page.name])),\n\t\t[editor]\n\t)\n\n\tif (!commentingEnabled || !sidebarTools.includes(activeTool)) return null\n\n\t// Group comments by thread (they arrive oldest-first, so [0] is each thread's first comment).\n\tconst byThread = new Map<string, TLComment[]>()\n\tfor (const comment of comments) {\n\t\tconst list = byThread.get(comment.threadId) ?? []\n\t\tlist.push(comment)\n\t\tbyThread.set(comment.threadId, list)\n\t}\n\n\t// Page scoping is treated as scoping, not a filter: an empty page reads \"no comments yet\",\n\t// while a list emptied by the toggles below reads \"nothing matches your filters\".\n\tconst pageThreads = threads.filter(\n\t\t(thread) => !filters.onlyCurrentPage || thread.pageId === currentPageId\n\t)\n\n\tconst items: CommentListItemProps[] = pageThreads\n\t\t.filter((thread) => filters.showResolved || thread.resolved == null)\n\t\t// \"Only mine\" is ignored without a known user \u2014 otherwise a persisted onlyMine=true would\n\t\t// empty the list for a signed-out viewer, with the (hidden) toggle giving no way to clear it.\n\t\t.filter(\n\t\t\t(thread) =>\n\t\t\t\t!filters.onlyMine || currentUserId === undefined || thread.createdBy === currentUserId\n\t\t)\n\t\t// \"Only unread\" is likewise ignored without a read-status source.\n\t\t.filter(\n\t\t\t(thread) =>\n\t\t\t\t!filters.onlyUnread ||\n\t\t\t\tisCommentUnread === undefined ||\n\t\t\t\t(byThread.get(thread.id) ?? []).some((c) => isCommentUnread(c.id))\n\t\t)\n\t\t.map((thread) => {\n\t\t\tconst threadComments = byThread.get(thread.id) ?? []\n\t\t\tconst first = threadComments[0]\n\t\t\tlet preview: ReactNode = ''\n\t\t\t// The `ThreadPreview` component slot overrides the built-in plaintext default.\n\t\t\tconst ThreadPreview = options.components.ThreadPreview\n\t\t\tif (first) {\n\t\t\t\tpreview = ThreadPreview ? (\n\t\t\t\t\t<ThreadPreview comment={first} />\n\t\t\t\t) : (\n\t\t\t\t\trichTextToPlaintext(first.body, resolveName)\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: thread.id,\n\t\t\t\tauthor: resolveName(thread.createdBy) ?? UNKNOWN_AUTHOR,\n\t\t\t\tpreview,\n\t\t\t\tdate: new Date((first ?? thread).createdAt).toISOString(),\n\t\t\t\tresolved: thread.resolved != null,\n\t\t\t\tpage: pageNames.get(thread.pageId),\n\t\t\t\tcount: threadComments.length,\n\t\t\t\tselected: openId === thread.id,\n\t\t\t}\n\t\t})\n\t\t// unresolved first, then most-recent first\n\t\t.sort((a, b) => {\n\t\t\tif (!!a.resolved !== !!b.resolved) return a.resolved ? 1 : -1\n\t\t\treturn b.date.localeCompare(a.date)\n\t\t})\n\n\tconst focus = (id: string) => {\n\t\tconst thread = threads.find((t) => t.id === id)\n\t\t// Resolve prop-or-option like the overlay pins do, so sidebar navigation centers on the same\n\t\t// spot the pin renders at when the anchor is configured via `CommentTool.configure`.\n\t\tif (thread) focusThread(editor, thread, impreciseShapeAnchor ?? options.impreciseShapeAnchor)\n\t}\n\n\treturn (\n\t\t<SidebarPanel container={container}>\n\t\t\t<CommentsList\n\t\t\t\titems={items}\n\t\t\t\theader={header ?? msg('comments.title')}\n\t\t\t\theaderAction={\n\t\t\t\t\t<div className=\"tlui-cmt-list__header-actions\">\n\t\t\t\t\t\t<CommentsFilterMenu\n\t\t\t\t\t\t\tcanFilterByAuthor={currentUserId !== undefined}\n\t\t\t\t\t\t\tcanFilterByUnread={isCommentUnread !== undefined}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<CommentsOverflowMenu />\n\t\t\t\t\t</div>\n\t\t\t\t}\n\t\t\t\tempty={\n\t\t\t\t\titems.length === 0 && pageThreads.length > 0\n\t\t\t\t\t\t? msg('comments.empty-filtered')\n\t\t\t\t\t\t: (empty ?? msg('comments.empty'))\n\t\t\t\t}\n\t\t\t\tresolvedLabel={msg('comments.resolved')}\n\t\t\t\tonSelect={focus}\n\t\t\t/>\n\t\t</SidebarPanel>\n\t)\n}\n\n/** The sidebar surface, portaled into the container. It scrolls its own list, so \u2014 unlike tldraw's\n * wheel-transparent panels \u2014 a wheel over it doesn't pan the canvas. Hover still passes through so\n * shapes beneath it stay interactive. */\nfunction SidebarPanel({ container, children }: { container: HTMLElement; children: ReactNode }) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughMouseOverEvents(ref)\n\treturn createPortal(\n\t\t<div ref={ref} className=\"tlui-cmt-canvas-sidebar\">\n\t\t\t{children}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoHK;AApHL,mBA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