@tldraw/commenting 0.0.0-bootstrap → 5.3.0-canary.31036673d3f8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/commenting.css +1139 -329
- package/dist-cjs/canvas/anchor-lifecycle.js +148 -0
- package/dist-cjs/canvas/anchor-lifecycle.js.map +7 -0
- package/dist-cjs/canvas/cluster-input.js +2 -2
- package/dist-cjs/canvas/cluster-input.js.map +2 -2
- package/dist-cjs/canvas/comment-body.js +1 -1
- package/dist-cjs/canvas/comment-body.js.map +2 -2
- package/dist-cjs/canvas/comment-drafts.js +54 -0
- package/dist-cjs/canvas/comment-drafts.js.map +7 -0
- package/dist-cjs/canvas/comment-mutations.js +123 -0
- package/dist-cjs/canvas/comment-mutations.js.map +7 -0
- package/dist-cjs/canvas/comment-reactions.js +163 -0
- package/dist-cjs/canvas/comment-reactions.js.map +7 -0
- package/dist-cjs/canvas/comment-render.js +5 -3
- package/dist-cjs/canvas/comment-render.js.map +2 -2
- package/dist-cjs/canvas/comment-store.js +19 -9
- package/dist-cjs/canvas/comment-store.js.map +2 -2
- package/dist-cjs/canvas/comment-tool.js +64 -14
- package/dist-cjs/canvas/comment-tool.js.map +2 -2
- package/dist-cjs/canvas/comments-filter-menu.js +20 -38
- package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overflow-menu.js +22 -27
- package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overlay.js +429 -474
- package/dist-cjs/canvas/comments-overlay.js.map +2 -2
- package/dist-cjs/canvas/comments-sidebar.js +35 -32
- package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
- package/dist-cjs/canvas/comments-visibility-toggle.js +65 -0
- package/dist-cjs/canvas/comments-visibility-toggle.js.map +7 -0
- package/dist-cjs/canvas/context.js +17 -0
- package/dist-cjs/canvas/context.js.map +7 -0
- package/dist-cjs/canvas/hooks.js +22 -3
- package/dist-cjs/canvas/hooks.js.map +2 -2
- package/dist-cjs/canvas/options.js +19 -2
- package/dist-cjs/canvas/options.js.map +2 -2
- package/dist-cjs/canvas/pin-stacking.js +56 -0
- package/dist-cjs/canvas/pin-stacking.js.map +7 -0
- package/dist-cjs/canvas/sidebar-filters.js +2 -2
- package/dist-cjs/canvas/sidebar-filters.js.map +2 -2
- package/dist-cjs/canvas/state.js +28 -14
- package/dist-cjs/canvas/state.js.map +2 -2
- package/dist-cjs/canvas/thread-preview.js +185 -0
- package/dist-cjs/canvas/thread-preview.js.map +7 -0
- package/dist-cjs/canvas/thread-stack.js +199 -0
- package/dist-cjs/canvas/thread-stack.js.map +7 -0
- package/dist-cjs/canvas/thread-state.js +67 -21
- package/dist-cjs/canvas/thread-state.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +397 -0
- package/dist-cjs/canvas/thread-view.js.map +7 -0
- package/dist-cjs/clustering/computeClusterTable.js +4 -4
- package/dist-cjs/clustering/computeClusterTable.js.map +2 -2
- package/dist-cjs/clustering/runtime.js +119 -7
- package/dist-cjs/clustering/runtime.js.map +2 -2
- package/dist-cjs/clustering/types.js.map +1 -1
- package/dist-cjs/index.d.ts +763 -333
- package/dist-cjs/index.js +46 -28
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/ui/byline.js +6 -4
- package/dist-cjs/ui/byline.js.map +2 -2
- package/dist-cjs/ui/comment-card.js +15 -8
- package/dist-cjs/ui/comment-card.js.map +2 -2
- package/dist-cjs/ui/comment-composer.js +137 -36
- package/dist-cjs/ui/comment-composer.js.map +2 -2
- package/dist-cjs/ui/comment-pin.js +24 -2
- package/dist-cjs/ui/comment-pin.js.map +2 -2
- package/dist-cjs/ui/comment-thread.js +9 -7
- package/dist-cjs/ui/comment-thread.js.map +2 -2
- package/dist-cjs/ui/comments-list.js +30 -18
- package/dist-cjs/ui/comments-list.js.map +2 -2
- package/dist-cjs/ui/count-badge.js +3 -2
- package/dist-cjs/ui/count-badge.js.map +2 -2
- package/dist-cjs/ui/emoji-picker.js +54 -0
- package/dist-cjs/ui/emoji-picker.js.map +7 -0
- package/dist-cjs/ui/empty-state.js +3 -3
- package/dist-cjs/ui/empty-state.js.map +2 -2
- package/dist-cjs/ui/format-time.js +4 -1
- package/dist-cjs/ui/format-time.js.map +2 -2
- package/dist-cjs/ui/reaction-picker.js +73 -0
- package/dist-cjs/ui/reaction-picker.js.map +7 -0
- package/dist-cjs/ui/reaction.js +59 -6
- package/dist-cjs/ui/reaction.js.map +2 -2
- package/dist-cjs/ui/reactions.js +20 -7
- package/dist-cjs/ui/reactions.js.map +2 -2
- package/dist-cjs/ui/{mention.js → reply-count.js} +9 -11
- package/dist-cjs/ui/reply-count.js.map +7 -0
- package/dist-cjs/ui/send-button.js +20 -1
- package/dist-cjs/ui/send-button.js.map +2 -2
- package/dist-cjs/ui/{comment-text.js → tooltip-button.js} +12 -9
- package/dist-cjs/ui/tooltip-button.js.map +7 -0
- package/dist-esm/canvas/anchor-lifecycle.mjs +128 -0
- package/dist-esm/canvas/anchor-lifecycle.mjs.map +7 -0
- package/dist-esm/canvas/cluster-input.mjs +2 -2
- package/dist-esm/canvas/cluster-input.mjs.map +2 -2
- package/dist-esm/canvas/comment-body.mjs +1 -1
- package/dist-esm/canvas/comment-body.mjs.map +2 -2
- package/dist-esm/canvas/comment-drafts.mjs +34 -0
- package/dist-esm/canvas/comment-drafts.mjs.map +7 -0
- package/dist-esm/canvas/comment-mutations.mjs +103 -0
- package/dist-esm/canvas/comment-mutations.mjs.map +7 -0
- package/dist-esm/canvas/comment-reactions.mjs +152 -0
- package/dist-esm/canvas/comment-reactions.mjs.map +7 -0
- package/dist-esm/canvas/comment-render.mjs +5 -3
- package/dist-esm/canvas/comment-render.mjs.map +2 -2
- package/dist-esm/canvas/comment-store.mjs +19 -9
- package/dist-esm/canvas/comment-store.mjs.map +2 -2
- package/dist-esm/canvas/comment-tool.mjs +67 -17
- package/dist-esm/canvas/comment-tool.mjs.map +2 -2
- package/dist-esm/canvas/comments-filter-menu.mjs +20 -38
- package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overflow-menu.mjs +23 -27
- package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overlay.mjs +450 -479
- package/dist-esm/canvas/comments-overlay.mjs.map +3 -3
- package/dist-esm/canvas/comments-sidebar.mjs +38 -35
- package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
- package/dist-esm/canvas/comments-visibility-toggle.mjs +45 -0
- package/dist-esm/canvas/comments-visibility-toggle.mjs.map +7 -0
- package/dist-esm/canvas/context.mjs +1 -0
- package/dist-esm/canvas/context.mjs.map +7 -0
- package/dist-esm/canvas/hooks.mjs +28 -5
- package/dist-esm/canvas/hooks.mjs.map +2 -2
- package/dist-esm/canvas/options.mjs +21 -3
- package/dist-esm/canvas/options.mjs.map +2 -2
- package/dist-esm/canvas/pin-stacking.mjs +36 -0
- package/dist-esm/canvas/pin-stacking.mjs.map +7 -0
- package/dist-esm/canvas/sidebar-filters.mjs +2 -2
- package/dist-esm/canvas/sidebar-filters.mjs.map +2 -2
- package/dist-esm/canvas/state.mjs +29 -19
- package/dist-esm/canvas/state.mjs.map +2 -2
- package/dist-esm/canvas/thread-preview.mjs +170 -0
- package/dist-esm/canvas/thread-preview.mjs.map +7 -0
- package/dist-esm/canvas/thread-stack.mjs +190 -0
- package/dist-esm/canvas/thread-stack.mjs.map +7 -0
- package/dist-esm/canvas/thread-state.mjs +71 -22
- package/dist-esm/canvas/thread-state.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +402 -0
- package/dist-esm/canvas/thread-view.mjs.map +7 -0
- package/dist-esm/clustering/computeClusterTable.mjs +4 -4
- package/dist-esm/clustering/computeClusterTable.mjs.map +2 -2
- package/dist-esm/clustering/runtime.mjs +119 -7
- package/dist-esm/clustering/runtime.mjs.map +2 -2
- package/dist-esm/index.d.mts +763 -333
- package/dist-esm/index.mjs +87 -41
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/ui/byline.mjs +6 -4
- package/dist-esm/ui/byline.mjs.map +2 -2
- package/dist-esm/ui/comment-card.mjs +15 -8
- package/dist-esm/ui/comment-card.mjs.map +2 -2
- package/dist-esm/ui/comment-composer.mjs +148 -36
- package/dist-esm/ui/comment-composer.mjs.map +2 -2
- package/dist-esm/ui/comment-pin.mjs +24 -2
- package/dist-esm/ui/comment-pin.mjs.map +2 -2
- package/dist-esm/ui/comment-thread.mjs +9 -7
- package/dist-esm/ui/comment-thread.mjs.map +2 -2
- package/dist-esm/ui/comments-list.mjs +43 -29
- package/dist-esm/ui/comments-list.mjs.map +2 -2
- package/dist-esm/ui/count-badge.mjs +3 -2
- package/dist-esm/ui/count-badge.mjs.map +2 -2
- package/dist-esm/ui/emoji-picker.mjs +34 -0
- package/dist-esm/ui/emoji-picker.mjs.map +7 -0
- package/dist-esm/ui/empty-state.mjs +3 -3
- package/dist-esm/ui/empty-state.mjs.map +2 -2
- package/dist-esm/ui/format-time.mjs +4 -1
- package/dist-esm/ui/format-time.mjs.map +2 -2
- package/dist-esm/ui/reaction-picker.mjs +60 -0
- package/dist-esm/ui/reaction-picker.mjs.map +7 -0
- package/dist-esm/ui/reaction.mjs +60 -7
- package/dist-esm/ui/reaction.mjs.map +2 -2
- package/dist-esm/ui/reactions.mjs +21 -8
- package/dist-esm/ui/reactions.mjs.map +2 -2
- package/dist-esm/ui/reply-count.mjs +9 -0
- package/dist-esm/ui/reply-count.mjs.map +7 -0
- package/dist-esm/ui/send-button.mjs +20 -1
- package/dist-esm/ui/send-button.mjs.map +2 -2
- package/dist-esm/ui/tooltip-button.mjs +12 -0
- package/dist-esm/ui/tooltip-button.mjs.map +7 -0
- package/package.json +6 -6
- package/src/canvas/anchor-lifecycle.test.ts +290 -0
- package/src/canvas/anchor-lifecycle.ts +205 -0
- package/src/canvas/canvas.css +461 -46
- package/src/canvas/cluster-input.test.ts +31 -23
- package/src/canvas/cluster-input.ts +3 -4
- package/src/canvas/comment-body.tsx +1 -1
- package/src/canvas/comment-drafts.test.ts +55 -0
- package/src/canvas/comment-drafts.ts +46 -0
- package/src/canvas/comment-mutations.test.ts +410 -0
- package/src/canvas/comment-mutations.ts +288 -0
- package/src/canvas/comment-reactions.test.ts +132 -0
- package/src/canvas/comment-reactions.tsx +245 -0
- package/src/canvas/comment-render.test.ts +1 -1
- package/src/canvas/comment-render.ts +9 -5
- package/src/canvas/comment-store.ts +67 -27
- package/src/canvas/comment-tool.test.ts +162 -0
- package/src/canvas/comment-tool.tsx +105 -23
- package/src/canvas/comments-filter-menu.tsx +23 -32
- package/src/canvas/comments-overflow-menu.tsx +14 -21
- package/src/canvas/comments-overlay.tsx +695 -622
- package/src/canvas/comments-sidebar.test.ts +45 -0
- package/src/canvas/comments-sidebar.tsx +76 -58
- package/src/canvas/comments-visibility-toggle.tsx +49 -0
- package/src/canvas/context.ts +47 -0
- package/src/canvas/hooks.ts +52 -11
- package/src/canvas/options.test.ts +52 -2
- package/src/canvas/options.ts +133 -9
- package/src/canvas/pin-stacking.test.ts +114 -0
- package/src/canvas/pin-stacking.ts +57 -0
- package/src/canvas/sidebar-filters.ts +4 -3
- package/src/canvas/state.ts +92 -35
- package/src/canvas/thread-preview.test.ts +91 -0
- package/src/canvas/thread-preview.tsx +304 -0
- package/src/canvas/thread-stack.tsx +252 -0
- package/src/canvas/thread-state.test.ts +209 -0
- package/src/canvas/thread-state.ts +137 -36
- package/src/canvas/thread-view.tsx +516 -0
- package/src/clustering/computeClusterTable.test.ts +24 -23
- package/src/clustering/computeClusterTable.ts +5 -5
- package/src/clustering/runtime.test.ts +217 -7
- package/src/clustering/runtime.ts +171 -17
- package/src/clustering/types.ts +9 -9
- package/src/index.ts +76 -40
- package/src/ui/byline.tsx +7 -5
- package/src/ui/comment-card.tsx +20 -10
- package/src/ui/comment-composer.tsx +206 -40
- package/src/ui/comment-pin.tsx +26 -2
- package/src/ui/comment-thread.tsx +13 -6
- package/src/ui/comments-list.test.ts +31 -0
- package/src/ui/comments-list.tsx +45 -21
- package/src/ui/comments.css +566 -281
- package/src/ui/count-badge.tsx +9 -2
- package/src/ui/emoji-picker.test.ts +25 -0
- package/src/ui/emoji-picker.tsx +76 -0
- package/src/ui/empty-state.tsx +3 -3
- package/src/ui/format-time.ts +7 -2
- package/src/ui/reaction-picker.tsx +109 -0
- package/src/ui/reaction.tsx +121 -6
- package/src/ui/reactions.tsx +69 -10
- package/src/ui/reply-count.ts +16 -0
- package/src/ui/send-button.tsx +18 -3
- package/src/ui/tooltip-button.tsx +20 -0
- package/dist-cjs/canvas/region-options.js +0 -49
- package/dist-cjs/canvas/region-options.js.map +0 -7
- package/dist-cjs/ui/avatar.js +0 -43
- package/dist-cjs/ui/avatar.js.map +0 -7
- package/dist-cjs/ui/comment-mention.js +0 -42
- package/dist-cjs/ui/comment-mention.js.map +0 -7
- package/dist-cjs/ui/comment-text.js.map +0 -7
- package/dist-cjs/ui/mention-list.js +0 -70
- package/dist-cjs/ui/mention-list.js.map +0 -7
- package/dist-cjs/ui/mention-suggestion.js +0 -206
- package/dist-cjs/ui/mention-suggestion.js.map +0 -7
- package/dist-cjs/ui/mention.js.map +0 -7
- package/dist-cjs/ui/render-markdown.js +0 -63
- package/dist-cjs/ui/render-markdown.js.map +0 -7
- package/dist-esm/canvas/region-options.mjs +0 -29
- package/dist-esm/canvas/region-options.mjs.map +0 -7
- package/dist-esm/ui/avatar.mjs +0 -23
- package/dist-esm/ui/avatar.mjs.map +0 -7
- package/dist-esm/ui/comment-mention.mjs +0 -22
- package/dist-esm/ui/comment-mention.mjs.map +0 -7
- package/dist-esm/ui/comment-text.mjs +0 -9
- package/dist-esm/ui/comment-text.mjs.map +0 -7
- package/dist-esm/ui/mention-list.mjs +0 -50
- package/dist-esm/ui/mention-list.mjs.map +0 -7
- package/dist-esm/ui/mention-suggestion.mjs +0 -186
- package/dist-esm/ui/mention-suggestion.mjs.map +0 -7
- package/dist-esm/ui/mention.mjs +0 -11
- package/dist-esm/ui/mention.mjs.map +0 -7
- package/dist-esm/ui/render-markdown.mjs +0 -45
- package/dist-esm/ui/render-markdown.mjs.map +0 -7
- package/src/canvas/region-options.ts +0 -57
- package/src/ui/avatar.tsx +0 -31
- package/src/ui/comment-mention.ts +0 -47
- package/src/ui/comment-text.tsx +0 -12
- package/src/ui/mention-list.tsx +0 -106
- package/src/ui/mention-suggestion.test.ts +0 -18
- package/src/ui/mention-suggestion.tsx +0 -285
- package/src/ui/mention.tsx +0 -9
- package/src/ui/render-markdown.tsx +0 -72
|
@@ -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": "AAuHE,SA2SE,UAhSD,KAXD;AAvHF;AAAA,EACC;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;AAC7B;AAAA,EAEC;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,2BAA2B;AACpC,SAA8B,4BAA4B;AAE1D,SAAS,mBAAqC;AAC9C,SAAS,uBAAuB;AAChC,SAAS,eAAe,sBAAsB;AAC9C,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,mBAAmB,4BAA4B;AAE1E,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,4BAA4B;AACrC;AAAA,EAGC;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EAEA;AAAA,OACM;A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AAQ,aAAa;AACrB,mBAAe,IAAI,QAAQ,IAAI;AAAA,EAChC;AAEA,SAAO;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,CAAC,oBAAoB,EAAG,gBAAe,IAAI,QAAQ,IAAI;AAAA,QAClF;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,QAAQ,gBAAiB,YAAY,aAAa,KAAK,iBAAkB;AAAA,YACzE,aAAa,IAAI,0BAA0B;AAAA,YAC3C,WAAW,IAAI,eAAe;AAAA,YAC9B,OAAO;AAAA,YACP,UAAU;AAAA,YACV,UAAU;AAAA,YACV,UAAU,eAAe,IAAI;AAAA,YAC7B;AAAA,YACA;AAAA,YACA,WAAS;AAAA,YACT,SAAS;AAAA;AAAA,QACV;AAAA;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
-
"names": ["ClusterBadge", "ThreadPin"]
|
|
4
|
+
"sourcesContent": ["import { Avatar, isMentionPickerOpen } from '@tldraw/mentions'\nimport {\n\tFragment,\n\tmemo,\n\ttype PointerEvent as ReactPointerEvent,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\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\treact,\n\tTLCommentThread,\n\tTLRichText,\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 { CommentComposer } from '../ui/comment-composer'\nimport { EMPTY_COMMENT, isCommentEmpty } from '../ui/comment-extensions'\nimport { CommentPin } from '../ui/comment-pin'\nimport { CountBadge } from '../ui/count-badge'\nimport { registerCommentAnchorLifecycle } from './anchor-lifecycle'\nimport { collectClusterLeaves } from './cluster-input'\nimport {\n\tclearCommentDraft,\n\tgetCommentDraft,\n\tNEW_COMMENT_DRAFT,\n\tsaveCommentDraft,\n} from './comment-drafts'\nimport { commitCommentMutation, putRecordsInCommit } from './comment-mutations'\nimport { UNKNOWN_AUTHOR, UNKNOWN_COMMENT_AUTHOR } from './comment-render'\nimport { getCommentRecord } from './comment-store'\nimport { PendingComment } from './comment-tool'\nimport { type CommentingContext } from './context'\nimport { useCommentThreads, useThreadComments } from './hooks'\nimport { useCommentingEnabled } from './license'\nimport {\n\ttype CommentingOptions,\n\tgetCommentingOptions,\n\tuseCanComment,\n\tuseCommentingOptions,\n} from './options'\nimport { computePinStacks, pinStackKey } from './pin-stacking'\nimport {\n\tcommentsHidden,\n\topenStackId,\n\topenThreadId,\n\tpendingComment,\n\tregionDraft,\n\trevealThreadRequest,\n\tsidebarFilters,\n\ttoggleCommentsHidden,\n\tusePendingComment,\n} from './state'\nimport { ThreadPreview, sortThreadsForPreview, useMarkerPreview } from './thread-preview'\nimport { ThreadStackPin } from './thread-stack'\nimport {\n\tanchorPagePoint,\n\tcommentCenterScreenOffset,\n\tcommentTargetShapeAt,\n\timpreciseShapePinInset,\n\tREGION_PIN_CORNER,\n\tregionAnchorPinCorner,\n\tregionPinPoint,\n\tshapeAnchorAt,\n} from './thread-state'\nimport { POPOVER_OFFSET, ThreadPopover, ThreadView } from './thread-view'\n\n/**\n * The host wiring for {@link CanvasComments} \u2014 see {@link CommentingContext}, which the sidebar\n * takes the same fields from.\n *\n * @public\n */\nexport type CanvasCommentsProps = CommentingContext\n\nconst stop = (e: { stopPropagation(): void }) => e.stopPropagation()\n\n/** A pointer-down that belongs to the camera, not the comment UI: any non-primary button\n * (middle/right-button pans), or a primary press with the spacebar pan key held. */\nconst isCanvasPanGesture = (editor: Editor, e: ReactPointerEvent) =>\n\te.button !== 0 || editor.inputs.keys.has('Space')\n\n/** Hand a pointer event to the canvas beneath the comments layer, marked the same way the\n * pass-through wheel/hover hooks mark their re-dispatched events. */\nfunction forwardPointerEventToCanvas(container: HTMLElement, e: ReactPointerEvent) {\n\tconst cvs = container.querySelector('.tl-canvas')\n\tif (!cvs) return\n\tconst newEvent = new PointerEvent(e.type, e.nativeEvent as any)\n\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\tcvs.dispatchEvent(newEvent)\n}\n\nconst CLUSTER_FADE_MS = 150\n/** Duration of the click-a-badge zoom-to-split animation. */\nconst CLUSTER_EXPAND_ZOOM_MS = 450\n/** How far past a cluster's split zoom to land when expanding it \u2014 a 5% overshoot, so the badge\n * lands clear of the threshold it just crossed rather than flickering on it. */\nconst CLUSTER_SPLIT_ZOOM_FACTOR = 1.05\n/** Screen-pixel margin by which the viewport is inflated when culling cluster badges, so a badge\n * just off-screen is already mounted when a pan brings it in. */\nconst CLUSTER_CULL_MARGIN_PX = 120\n\n/** The opened popover has a header row the hover preview lacks, so it opens this much higher \u2014 the\n * first comment then lands where the preview's sat. Measured: the expanded first comment sits ~42px\n * below the panel top (the 40px header, no gap) vs the preview's 4px (its panel padding).\n * Re-measure if the header height or the preview panel padding changes. */\nconst THREAD_HEADER_BLOCK = 36\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 *\n * The host wiring \u2014 who the viewer is, how ids become names, read status, mentions \u2014 is the\n * {@link CommentingContext}, which `CanvasCommentsSidebar` takes too, so a host mounting both can\n * build it once and spread it into each.\n *\n * @public @react\n */\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\n/**\n * A mount point appended to the end of the editor container, for a portal that has to come last\n * among the container's children.\n *\n * `createPortal(\u2026, container)` doesn't get to say where its node lands: React places a portal\n * during the same commit that mounts it, and a portal nested this deep in the tree is placed\n * before the container's own, shallower children \u2014 so the layer ends up ahead of the UI and its\n * \"move focus to canvas\" skip link. That link only works if nothing precedes it, and the pins are\n * real buttons, so a single comment would take the first tab stop and leave no keyboard route to\n * the canvas. A layout effect runs after the whole commit instead, by which point the container's\n * children are all in place and appending is guaranteed to land at the end.\n *\n * Null until the effect has run, so the first render has nothing to portal into.\n */\nfunction useTrailingPortalHost(container: HTMLElement) {\n\tconst [host, setHost] = useState<HTMLDivElement | null>(null)\n\tuseLayoutEffect(() => {\n\t\tconst elm = container.ownerDocument.createElement('div')\n\t\t// The host is a position in the DOM, not a box \u2014 what it holds is positioned against the\n\t\t// container, the same as it was when it hung off the container directly.\n\t\telm.style.display = 'contents'\n\t\tcontainer.appendChild(elm)\n\t\tsetHost(elm)\n\t\treturn () => {\n\t\t\telm.remove()\n\t\t\tsetHost(null)\n\t\t}\n\t}, [container])\n\treturn host\n}\n\nfunction CanvasCommentsLayer(props: CommentingContext) {\n\tconst editor = useEditor()\n\tconst options = useCommentingOptions()\n\tconst container = useContainer()\n\tconst portalHost = useTrailingPortalHost(container)\n\tconst layerRef = useRef<HTMLDivElement>(null)\n\t// Over the pins and cluster badges, hover passes through to the canvas beneath (these events\n\t// bubble up from the pointer-interactive markers to this layer root). Wheel pass-through is\n\t// NOT on this root: it lives on each interactive element instead. The root spans the whole\n\t// canvas, so any pin past its bottom/right edge inflates the root's scrollHeight \u2014 which the\n\t// wheel hook's is-this-scrollable guard reads as scrollable, silently disabling pass-through.\n\tusePassThroughMouseOverEvents(layerRef)\n\tconst allThreads = useCommentThreads(editor)\n\tconst pending = usePendingComment()\n\tconst canComment = useCanComment(props.currentUserId)\n\t// With composing blocked and no fallback slot there's nothing to render for a pending comment \u2014\n\t// and the dismiss handlers (Escape, click-away) live inside PendingComposer, which would never\n\t// mount. Clear the atom instead of stranding it (a stale pending would pop a composer at the\n\t// old click point if `canComment` later flips true).\n\tconst canRenderComposer = canComment || options.components.ComposerFallback != null\n\tconst showPendingComposer = pending != null && canRenderComposer\n\tuseEffect(() => {\n\t\tif (pending && !showPendingComposer) pendingComment.set(editor, null)\n\t}, [editor, pending, showPendingComposer])\n\tconst openId = useValue('open thread id', () => openThreadId.get(editor), [editor])\n\t// Hide resolved threads' pins by default, matching the sidebar's `showResolved` filter. The open\n\t// thread stays in \u2014 resolving from its own popover shouldn't make the pin vanish under it.\n\tconst showResolved = useValue('show resolved', () => sidebarFilters.get(editor).showResolved, [\n\t\teditor,\n\t])\n\tconst threads = useMemo(\n\t\t() => allThreads.filter((t) => showResolved || t.resolved == null || t.id === openId),\n\t\t[allThreads, showResolved, openId]\n\t)\n\tuseEffect(() => registerCommentAnchorLifecycle(editor), [editor])\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),\n\t\t[editor, threads, 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\t// Zooming separates near pins, but pins with the *same* anchor point (several imprecise\n\t// comments on one shape) coincide at every zoom \u2014 those render as one count-badge stack that\n\t// opens the threads as a list. Keyed on page-space anchors, so camera moves never recompute this.\n\tconst pinStacks = useValue('comment pin stacks', () => computePinStacks(editor, threads), [\n\t\teditor,\n\t\tthreads,\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, open stack, half-placed comment, unserved reveal)\n\t// when this unmounts.\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\topenThreadId.set(editor, null)\n\t\t\topenStackId.set(editor, null)\n\t\t\tpendingComment.set(editor, null)\n\t\t\trevealThreadRequest.set(editor, null)\n\t\t}\n\t}, [editor])\n\n\t// Clear a stale open-stack key. `openStackId` is a stack's coincident point key, and only the\n\t// stack's own (mounted) handlers clear it \u2014 so collapsing the stack to a single pin unmounts the\n\t// `ThreadStackPin` and strands the key. A dangling `openStackId` is not harmless: `useMarkerPreview`\n\t// treats any non-null value as \"a stack is open\" and suppresses every hover preview until it's\n\t// cleared. Keep it while any live stack still sits at that key (so losing a member \u2014 even the\n\t// oldest \u2014 keeps the list open under the survivors), and clear it once none does.\n\tuseEffect(() => {\n\t\tconst key = openStackId.get(editor)\n\t\tif (!key) return\n\t\tfor (const id of pinStacks.keys()) {\n\t\t\tconst thread = threadsById.get(id)\n\t\t\tif (!thread) continue\n\t\t\tconst point = anchorPagePoint(editor, thread.anchor)\n\t\t\tif (point && pinStackKey(point) === key) return\n\t\t}\n\t\topenStackId.set(editor, null)\n\t}, [editor, pinStacks, threadsById])\n\n\t// The requested thread, once it (and, for a comment id, its parent thread) has synced into the\n\t// store; null while records are still arriving or when no request is pending.\n\tconst requestedRevealThread = useValue(\n\t\t'requested reveal thread',\n\t\t() => {\n\t\t\tconst id = revealThreadRequest.get(editor)\n\t\t\tif (!id) return null\n\t\t\tconst record = getCommentRecord(editor, id)\n\t\t\tif (!record) return null\n\t\t\tconst thread =\n\t\t\t\trecord.typeName === 'comment' ? getCommentRecord(editor, record.threadId) : record\n\t\t\treturn thread?.typeName === 'comment-thread' ? thread : null\n\t\t},\n\t\t[editor]\n\t)\n\n\t// Serve a pending reveal request: open the thread, zooming to the first cluster split that\n\t// reveals its pin when it's currently folded into a badge. A reveal is an explicit ask to see\n\t// the thread, so it also unhides pins \u2014 the popover opens on the on-canvas layer, which stays\n\t// invisible while hidden.\n\tuseEffect(() => {\n\t\tif (!requestedRevealThread) return\n\t\trevealThreadRequest.set(editor, null)\n\t\tcommentsHidden.set(editor, false)\n\t\trevealThreadPin(editor, requestedRevealThread, clusterModel.table, clusterZoomBounds, options)\n\t\topenThreadId.set(editor, requestedRevealThread.id)\n\t}, [requestedRevealThread, clusterModel.table, clusterZoomBounds, editor, options])\n\n\t// Picking a thread out of a cluster's hover preview. Setting `openThreadId` alone would work \u2014\n\t// the thread leaves the cluster input and renders its own pin \u2014 but it would cut straight there\n\t// from wherever the badge was. Zoom in on it first, the same move (and duration) the badge's\n\t// own click makes, so the thread arrives instead of appearing.\n\tconst revealClusteredThread = useCallback(\n\t\t(thread: TLCommentThread) => {\n\t\t\trevealThreadPin(\n\t\t\t\teditor,\n\t\t\t\tthread,\n\t\t\t\tclusterModel.table,\n\t\t\t\tclusterZoomBounds,\n\t\t\t\toptions,\n\t\t\t\tCLUSTER_EXPAND_ZOOM_MS\n\t\t\t)\n\t\t\topenThreadId.set(editor, thread.id)\n\t\t},\n\t\t[clusterModel.table, clusterZoomBounds, editor, options]\n\t)\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 * CLUSTER_SPLIT_ZOOM_FACTOR,\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]\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. Skipped while typing so it never fires\n\t// 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// Which threads are on screen this render, across every path below. A stack renders exactly\n\t// once, owned by its first member that is actually on screen \u2014 members can arrive by different\n\t// paths (a leaf via clustering while its open sibling renders via the open slot), so ownership\n\t// can't be decided per-path.\n\t// A cluster node that is exactly one coincident stack \u2014 every member shares a single pin-stack\n\t// group, with no distinct-position comment mixed in. Such a node is a stack standing on its own\n\t// (its neighbours have already split off as the view zoomed in), so it renders as the immediate\n\t// cascading count-badge list rather than a zoom-to-split cluster badge. Returns the stack's full\n\t// group \u2014 which can include an open or orphan member the node's own leaves omit \u2014 or null.\n\tconst stackGroupOf = (node: ClusterNode): readonly string[] | null => {\n\t\tconst group = pinStacks.get(node.members[0])\n\t\tif (!group) return null\n\t\treturn node.members.every((id) => group.includes(id)) ? group : null\n\t}\n\n\tconst renderedThreadIds = new Set<string>()\n\tif (options.enableClustering) {\n\t\tfor (const { node } of fadeNodes) {\n\t\t\tif (node.count === 1) renderedThreadIds.add(node.id)\n\t\t\t// A pure-stack node owns its members here (they aren't count-1 leaves), so register them so\n\t\t\t// the owner logic can pick one \u2014 mirroring how count-1 leaves are added above.\n\t\t\telse if (stackGroupOf(node)) for (const id of node.members) renderedThreadIds.add(id)\n\t\t}\n\t\tfor (const thread of orphanThreads) renderedThreadIds.add(thread.id)\n\t\tfor (const thread of heldThreads) renderedThreadIds.add(thread.id)\n\t} else {\n\t\tfor (const thread of threads) renderedThreadIds.add(thread.id)\n\t}\n\tif (openThread) renderedThreadIds.add(openThread.id)\n\n\t// A coincident-stack member renders as the group's single count-badge stack (if it owns it)\n\t// or not at all; everything else is an ordinary pin.\n\tconst renderThreadPin = (thread: TLCommentThread): ReactNode => {\n\t\tconst group = pinStacks.get(thread.id)\n\t\tif (group) {\n\t\t\tconst owner = group.find((id) => renderedThreadIds.has(id))\n\t\t\tif (owner !== thread.id) return null\n\t\t\tconst stackThreads = group\n\t\t\t\t.map((id) => threadsById.get(id))\n\t\t\t\t.filter((t): t is TLCommentThread => t !== undefined)\n\t\t\treturn <ThreadStackPin editor={editor} threads={stackThreads} {...props} />\n\t\t}\n\t\treturn <ThreadPin editor={editor} thread={thread} {...props} />\n\t}\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 \u2014 but at the end of it,\n\t// behind the editor's own children in the tab order. See `useTrailingPortalHost`.\n\tif (!portalHost) return null\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\tconst stackGroup = node.count > 1 ? stackGroupOf(node) : null\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 = renderThreadPin(thread)\n\t\t\t\t\t\t} else if (stackGroup) {\n\t\t\t\t\t\t\t// A coincident stack standing alone: draw the cascading count-badge list now\n\t\t\t\t\t\t\t// instead of a zoom-to-split cluster badge. Route it through the stack's owner so\n\t\t\t\t\t\t\t// the open/orphan/held slots stay deduped \u2014 when the owner is one of them, that\n\t\t\t\t\t\t\t// slot draws the stack and this node draws nothing.\n\t\t\t\t\t\t\tconst owner = stackGroup.find((id) => renderedThreadIds.has(id))\n\t\t\t\t\t\t\tcontent =\n\t\t\t\t\t\t\t\towner && node.members.includes(owner)\n\t\t\t\t\t\t\t\t\t? renderThreadPin(threadsById.get(owner)!)\n\t\t\t\t\t\t\t\t\t: null\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcontent = (\n\t\t\t\t\t\t\t\t<ClusterBadge\n\t\t\t\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\t\t\t\tnode={node}\n\t\t\t\t\t\t\t\t\tonExpand={zoomToClusterSplit}\n\t\t\t\t\t\t\t\t\tonSelectThread={revealClusteredThread}\n\t\t\t\t\t\t\t\t\tthreadsById={threadsById}\n\t\t\t\t\t\t\t\t\tcurrentUserId={props.currentUserId}\n\t\t\t\t\t\t\t\t\tresolveAuthor={props.resolveAuthor}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\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<Fragment key={thread.id}>{renderThreadPin(thread)}</Fragment>\n\t\t\t\t\t))}\n\t\t\t\t\t{heldThreads.map((thread) => (\n\t\t\t\t\t\t<Fragment key={thread.id}>{renderThreadPin(thread)}</Fragment>\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) => <Fragment key={thread.id}>{renderThreadPin(thread)}</Fragment>)\n\t\t\t)}\n\t\t\t{openThread && (\n\t\t\t\t<Fragment key={`open:${openThread.id}`}>{renderThreadPin(openThread)}</Fragment>\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' && showPendingComposer && (\n\t\t\t\t<RegionBox editor={editor} box={pending.anchor} />\n\t\t\t)}\n\t\t\t{pending && showPendingComposer && (\n\t\t\t\t<PendingComposer editor={editor} pending={pending} {...props} />\n\t\t\t)}\n\t\t</div>,\n\t\tportalHost\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 revealThreadPin(\n\teditor: Editor,\n\tthread: TLCommentThread,\n\ttable: ClusterTable,\n\tzoomBounds: { minZoom: number; maxZoom: number },\n\toptions: CommentingOptions,\n\tduration = 200\n) {\n\tif (thread.pageId !== editor.getCurrentPageId()) {\n\t\teditor.setCurrentPage(thread.pageId as any)\n\t}\n\n\tconst point = anchorPagePoint(editor, thread.anchor)\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 * CLUSTER_SPLIT_ZOOM_FACTOR,\n\t\t\t\tzoomBounds.minZoom,\n\t\t\t\tzoomBounds.maxZoom\n\t\t\t)\n\t\t\tcenterOnPointAtZoom(editor, point, zoom, duration)\n\t\t\treturn\n\t\t}\n\t}\n\n\tconst offset = commentCenterScreenOffset(editor) / editor.getZoomLevel()\n\teditor.centerOnPoint({ x: point.x + offset, y: point.y }, { animation: { duration } })\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\t// The open sidebar shifts the target left so the pin lands mid-uncovered-area, not under it.\n\tconst offset = commentCenterScreenOffset(editor)\n\teditor.setCamera(\n\t\t{\n\t\t\tx: (viewport.w / 2 - offset) / 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\tonSelectThread,\n\tthreadsById,\n\t...props\n}: Pick<CommentingContext, 'currentUserId' | 'resolveAuthor'> & {\n\teditor: Editor\n\tnode: ClusterNode\n\tonExpand(node: ClusterNode): void\n\tonSelectThread(thread: TLCommentThread): void\n\tthreadsById: ReadonlyMap<string, TLCommentThread>\n}) {\n\tconst container = useContainer()\n\tconst msg = useTranslation()\n\tconst badgeRef = useRef<HTMLButtonElement>(null)\n\tconst { previewShown, previewHandlers } = useMarkerPreview(editor, `cluster:${node.id}`)\n\t// Wheel pass-through sits on the badge (never scrollable), not the layer root \u2014 see the\n\t// note on the layer.\n\tusePassThroughWheelEvents(badgeRef)\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\t// `node.members` is sorted by id (the clustering table's ordering); the preview wants them in\n\t// the order a reader would expect. Only computed while the preview is up.\n\tconst previewThreads = useMemo(() => {\n\t\tif (!previewShown) return []\n\t\tconst threads: TLCommentThread[] = []\n\t\tfor (const id of node.members) {\n\t\t\tconst thread = threadsById.get(id)\n\t\t\tif (thread) threads.push(thread)\n\t\t}\n\t\treturn sortThreadsForPreview(threads)\n\t}, [previewShown, node.members, threadsById])\n\n\tif (!point) return null\n\n\treturn (\n\t\t<>\n\t\t\t<button\n\t\t\t\tref={badgeRef}\n\t\t\t\ttype=\"button\"\n\t\t\t\tclassName=\"tlui-cmt-button tlui-cmt-canvas-cluster\"\n\t\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\t\taria-label={msg('comments.cluster-label').replace('{count}', String(node.count))}\n\t\t\t\tonPointerDown={(e) => {\n\t\t\t\t\tif (isCanvasPanGesture(editor, e)) {\n\t\t\t\t\t\tforwardPointerEventToCanvas(container, e)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\te.stopPropagation()\n\t\t\t\t}}\n\t\t\t\tonClick={(e) => {\n\t\t\t\t\te.stopPropagation()\n\t\t\t\t\tonExpand(node)\n\t\t\t\t}}\n\t\t\t\t{...previewHandlers}\n\t\t\t\tonFocus={previewHandlers.onPointerEnter}\n\t\t\t\tonBlur={previewHandlers.onPointerLeave}\n\t\t\t>\n\t\t\t\t<CountBadge count={node.count} />\n\t\t\t</button>\n\t\t\t{previewShown && previewThreads.length > 0 && (\n\t\t\t\t<ThreadPreview\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tthreads={previewThreads}\n\t\t\t\t\tcontainer={container}\n\t\t\t\t\tvariant=\"list\"\n\t\t\t\t\tpoint={point}\n\t\t\t\t\tonSelectThread={onSelectThread}\n\t\t\t\t\t{...previewHandlers}\n\t\t\t\t\t{...props}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</>\n\t)\n})\n\nfunction isInInflatedViewport(editor: Editor, point: { x: number; y: number }): boolean {\n\tconst viewport = editor.getViewportScreenBounds()\n\tconst margin = CLUSTER_CULL_MARGIN_PX\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/** 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. */\n/** A region's dashed box. Purely visual \u2014 a region moves by its pin and resizes from its corner\n * handles, so the box itself takes no pointer events. */\nfunction RegionBox({ editor, box }: { editor: Editor; box: BoxModel }) {\n\tconst rect = useValue(\n\t\t'region rect',\n\t\t() => {\n\t\t\t// Position from the page\u2192viewport top-left; screen size scales with zoom, page size doesn't.\n\t\t\tconst topLeft = editor.pageToViewport({ x: box.x, y: box.y })\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\treturn { left: topLeft.x, top: topLeft.y, width: box.w * zoom, height: box.h * zoom }\n\t\t},\n\t\t[editor, box.x, box.y, box.w, box.h]\n\t)\n\treturn <div className=\"tlui-cmt-canvas-region\" style={rect} />\n}\n\n/** The live region being dragged out by the comment tool, or nothing when not dragging. */\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 is *not*\n// controlled by that handle \u2014 the resize math reads the spot rather than special-casing corners.\ninterface RegionHandle {\n\tx: number\n\ty: number\n\tcursor: string\n}\n\n// The four corners, each resizing both axes.\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]\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\t...props\n}: CommentingContext & {\n\teditor: Editor\n\tthread: TLCommentThread\n}) {\n\tconst { resolveAuthor } = props\n\tconst options = useCommentingOptions()\n\tconst canComment = useCanComment(props.currentUserId)\n\tconst container = useContainer()\n\tconst msg = useTranslation()\n\tconst comments = useThreadComments(editor, thread.id)\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\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// Hovering the marker previews the thread's opening comment, on the delay every marker uses.\n\tconst { previewShown, previewHandlers } = useMarkerPreview(editor, `pin:${thread.id}`)\n\tconst previewThreads = useMemo(() => [thread], [thread])\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, mid-resize, or while the pointer is\n\t// within the region.\n\tconst revealed = open || resizeBounds != null || pointerInRegion\n\t// A region thread's pin corner is its own (the corner its creating drag released on), with\n\t// the default as the fallback for older records.\n\tconst pinCorner =\n\t\tthread.anchor.type === 'region' ? regionAnchorPinCorner(thread.anchor) : REGION_PIN_CORNER\n\t// A region resizes from its corners \u2014 every corner but the pin's own, which the pin owns.\n\tconst resizeHandles = useMemo(\n\t\t() => REGION_CORNERS.filter((c) => c.x !== pinCorner.x || c.y !== pinCorner.y),\n\t\t[pinCorner]\n\t)\n\tconst dragRef = useRef<{\n\t\tstartX: number\n\t\tstartY: number\n\t\tmoved: boolean\n\t\t// The anchor's page-space offset from the grab point, so a drag translates the pin by the\n\t\t// cursor's delta (like RegionBox's move) instead of snapping the anchor to the cursor.\n\t\toffsetX: number\n\t\toffsetY: number\n\t} | null>(null)\n\tconst markerRef = useRef<HTMLButtonElement>(null)\n\t// Wheel pass-through sits on the marker (which is never scrollable), not the layer root \u2014\n\t// see the note on the layer.\n\tusePassThroughWheelEvents(markerRef)\n\n\t// The drop-target hint is editor-global state with no automatic reset. If the pin unmounts\n\t// mid-drag (e.g. Shift+C hides comments), no pointer event will ever reach the drag handlers \u2014\n\t// clear the hint here or it stays on the shape indefinitely.\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (dragRef.current) editor.setHintingShapes([])\n\t\t}\n\t}, [editor])\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)\n\t\t\tif (!pagePoint) return null\n\t\t\tconst viewportPoint = editor.pageToViewport(pagePoint)\n\t\t\tconst inset = impreciseShapePinInset(editor, thread.anchor)\n\t\t\treturn inset ? { x: viewportPoint.x + inset.x, y: viewportPoint.y + inset.y } : viewportPoint\n\t\t},\n\t\t[editor, thread.anchor, thread.pageId]\n\t)\n\tif (!point) return null\n\n\tconst PinContent = options.components.PinContent\n\t// The `PinContent` component slot overrides the built-in author-avatar default.\n\tconst threadAuthor = resolveAuthor(thread.createdBy)\n\tconst pinContent = PinContent ? (\n\t\t<PinContent thread={thread} comments={comments} />\n\t) : (\n\t\t<Avatar author={threadAuthor ?? UNKNOWN_COMMENT_AUTHOR} />\n\t)\n\tconst pinLabel = msg(\n\t\tthread.resolved ? 'comments.pin-label-resolved' : 'comments.pin-label'\n\t).replace('{name}', threadAuthor?.name ?? UNKNOWN_AUTHOR)\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\tconst isRegion = thread.anchor.type === 'region'\n\t// The marker is a button (so it's keyboard-reachable), so the drag handlers are typed to it.\n\tconst startDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {\n\t\t// A middle/right-button or space-held press over a pin is a camera pan, not a pin drag \u2014\n\t\t// hand it to the canvas untouched.\n\t\tif (isCanvasPanGesture(editor, e)) {\n\t\t\tforwardPointerEventToCanvas(container, e)\n\t\t\treturn\n\t\t}\n\t\te.stopPropagation()\n\t\tconst grabPage = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\tconst anchorPage = anchorPagePoint(editor, thread.anchor)\n\t\t// The drag delta is taken from where the pin is drawn, which for an imprecise shape pin\n\t\t// is inset from its anchor point \u2014 without this the pin jumps by the inset on drag start.\n\t\tconst inset = impreciseShapePinInset(editor, thread.anchor)\n\t\tif (anchorPage && inset) {\n\t\t\tconst zoom = editor.getZoomLevel()\n\t\t\tanchorPage.x += inset.x / zoom\n\t\t\tanchorPage.y += inset.y / zoom\n\t\t}\n\t\tdragRef.current = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tmoved: false,\n\t\t\toffsetX: anchorPage ? anchorPage.x - grabPage.x : 0,\n\t\t\toffsetY: anchorPage ? anchorPage.y - grabPage.y : 0,\n\t\t}\n\t\te.currentTarget.setPointerCapture(e.pointerId)\n\t}\n\tconst onDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {\n\t\tconst drag = dragRef.current\n\t\tif (!drag) return\n\t\t// Moving a pin re-anchors the thread record \u2014 a commenting write. Without the permission the\n\t\t// press stays a click (`moved` never sets, so release toggles the popover and never commits).\n\t\tif (!canComment) 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\tconst cursorPage = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\tconst pagePoint = { x: cursorPage.x + drag.offsetX, y: cursorPage.y + drag.offsetY }\n\t\tsetDragPagePoint(pagePoint)\n\t\t// Hint the shape the pin would re-anchor to on drop \u2014 the same hit-test endDrag resolves\n\t\t// with. Regions translate rather than re-anchor, so they never hint.\n\t\tif (!isRegion) {\n\t\t\tconst hit = commentTargetShapeAt(editor, pagePoint)\n\t\t\teditor.setHintingShapes(hit ? [hit.id] : [])\n\t\t}\n\t}\n\t// A cancelled pointer (touch gesture takeover, browser interruption) aborts the drag outright:\n\t// no re-anchor commit, no click-toggle \u2014 the pin snaps back and the hint clears.\n\tconst cancelDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {\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\tsetDragPagePoint(null)\n\t\teditor.setHintingShapes([])\n\t}\n\tconst endDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {\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\teditor.setHintingShapes([])\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 cursorPage = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\t\tconst pagePoint = { x: cursorPage.x + drag.offsetX, y: cursorPage.y + drag.offsetY }\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 - pinCorner.x * thread.anchor.w,\n\t\t\t\ty: pagePoint.y - pinCorner.y * thread.anchor.h,\n\t\t\t}\n\t\t} else {\n\t\t\tconst hit = commentTargetShapeAt(editor, pagePoint)\n\t\t\tanchor = hit\n\t\t\t\t? shapeAnchorAt(\n\t\t\t\t\t\teditor,\n\t\t\t\t\t\thit.id,\n\t\t\t\t\t\tpagePoint,\n\t\t\t\t\t\tgetCommentingOptions(editor).shouldBePrecise(editor, {\n\t\t\t\t\t\t\tshapeId: hit.id,\n\t\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t\t\taltKey: e.altKey,\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t: { type: 'point', x: pagePoint.x, y: pagePoint.y }\n\t\t}\n\t\tcommitCommentMutation(editor, () => putRecordsInCommit(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 ? regionPinPoint(resizeBounds, pinCorner) : dragPagePoint\n\tconst renderPointBase = livePinPage ? editor.pageToViewport(livePinPage) : point\n\t// A region's pin centres on its corner \u2014 overlapping the box \u2014 rather than hanging off it.\n\t// The marker anchors bottom-left, so step half its 34px size left and down (screen px).\n\tconst renderPoint = isRegion\n\t\t? { x: renderPointBase.x - 17, y: renderPointBase.y + 17 }\n\t\t: renderPointBase\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 - pinCorner.x * regionAnchor.w,\n\t\t\t\t\ty: dragPagePoint.y - 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\tif (!canComment) return\n\t\t// Same commit path as a pin drag, so the configured `dragHistory` governs both \u2014 going\n\t\t// straight to `editor.run` here would make region resizes silently ignore the option.\n\t\tcommitCommentMutation(\n\t\t\teditor,\n\t\t\t// Spread the existing anchor first so the region's pin corner survives a resize.\n\t\t\t() => putRecordsInCommit(editor, [{ ...thread, anchor: { ...regionAnchor!, ...bounds } }]),\n\t\t\t'drag'\n\t\t)\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{regionBoxBounds && (dragPagePoint || revealed) && (\n\t\t\t\t<RegionBox editor={editor} box={regionBoxBounds} />\n\t\t\t)}\n\t\t\t{regionBoxBounds && revealed && !dragPagePoint && canComment && (\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={[\n\t\t\t\t\t'tlui-cmt-canvas-pin',\n\t\t\t\t\topen && 'tlui-cmt-canvas-pin--open',\n\t\t\t\t\tdragPagePoint && 'tlui-cmt-canvas-pin--dragging',\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ')}\n\t\t\t\tstyle={{ left: renderPoint.x, top: renderPoint.y }}\n\t\t\t>\n\t\t\t\t<button\n\t\t\t\t\tref={markerRef}\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"tlui-cmt-button tlui-cmt-canvas-pin__marker\"\n\t\t\t\t\taria-label={pinLabel}\n\t\t\t\t\taria-expanded={open}\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\tonPointerCancel={cancelDrag}\n\t\t\t\t\t// Pointer activation is already handled by endDrag (which distinguishes a click\n\t\t\t\t\t// from a drag), so only take keyboard-synthesised clicks here \u2014 those report\n\t\t\t\t\t// `detail === 0` \u2014 or the thread would toggle twice per mouse click.\n\t\t\t\t\tonClick={(e) => {\n\t\t\t\t\t\tif (e.detail !== 0) return\n\t\t\t\t\t\topenThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)\n\t\t\t\t\t}}\n\t\t\t\t\tonPointerEnter={previewHandlers.onPointerEnter}\n\t\t\t\t\tonPointerLeave={previewHandlers.onPointerLeave}\n\t\t\t\t\t// Focus stands in for hover, so tabbing to a marker gets the same preview.\n\t\t\t\t\tonFocus={previewHandlers.onPointerEnter}\n\t\t\t\t\tonBlur={previewHandlers.onPointerLeave}\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</button>\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={{\n\t\t\t\t\t\t\tleft: renderPoint.x + POPOVER_OFFSET.thread.x,\n\t\t\t\t\t\t\ttop: renderPoint.y + POPOVER_OFFSET.thread.y - THREAD_HEADER_BLOCK,\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ThreadView editor={editor} thread={thread} {...props} />\n\t\t\t\t\t</ThreadPopover>\n\t\t\t\t)}\n\t\t\t\t{/* Not while dragging: the pin is being moved, not read, and a panel trailing the\n\t\t\t\t cursor would obscure the drop target. */}\n\t\t\t\t{previewShown && !dragPagePoint && (\n\t\t\t\t\t<ThreadPreview\n\t\t\t\t\t\teditor={editor}\n\t\t\t\t\t\tthreads={previewThreads}\n\t\t\t\t\t\tcontainer={container}\n\t\t\t\t\t\tvariant=\"thread\"\n\t\t\t\t\t\tpoint={renderPoint}\n\t\t\t\t\t\tonSelectThread={() => openThreadId.set(editor, thread.id)}\n\t\t\t\t\t\t{...previewHandlers}\n\t\t\t\t\t\tcurrentUserId={props.currentUserId}\n\t\t\t\t\t\tresolveAuthor={resolveAuthor}\n\t\t\t\t\t/>\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\tresolveAuthor,\n\tonPostComment,\n\tgetMentionSuggestions,\n\trenderMentionSuggestion,\n}: CommentingContext & { editor: Editor; pending: PendingComment }) {\n\tconst ComposerFallback = useCommentingOptions().components.ComposerFallback\n\tconst canComment = useCanComment(currentUserId)\n\tconst me = currentUserId ? resolveAuthor(currentUserId) : undefined\n\t// The leading pin previews the pin this draft becomes: a white pin holding the author's avatar.\n\tconst draftAvatar = (\n\t\t<CommentPin>\n\t\t\t<Avatar author={me ?? UNKNOWN_COMMENT_AUTHOR} />\n\t\t</CommentPin>\n\t)\n\t// Click-away keeps the draft (saved on every change) and the next placement composer\n\t// restores it \u2014 the flip side of dismissing without a discard warning.\n\tconst [text, setText] = useState<TLRichText>(\n\t\t() => getCommentDraft(NEW_COMMENT_DRAFT) ?? EMPTY_COMMENT\n\t)\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst msg = useTranslation()\n\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\tputRecordsInCommit(editor, [thread, comment])\n\t\t\tif (onPostComment) onPostComment(comment)\n\t\t})\n\t\tsetText(EMPTY_COMMENT)\n\t\tclearCommentDraft(NEW_COMMENT_DRAFT)\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={[\n\t\t\t\t'tlui-cmt-canvas-composer',\n\t\t\t\tpending.anchor.type === 'region' && 'tlui-cmt-canvas-composer--region',\n\t\t\t\t!canComment && 'tlui-cmt-canvas-composer--fallback',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={{ left: point.x, top: point.y }}\n\t\t\tonPointerDown={stop}\n\t\t\tonContextMenu={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{canComment ? (\n\t\t\t\t<CommentComposer\n\t\t\t\t\tauthor={me ?? UNKNOWN_COMMENT_AUTHOR}\n\t\t\t\t\tplaceholder={msg('comments.add-placeholder')}\n\t\t\t\t\tsendLabel={msg('comments.send')}\n\t\t\t\t\tvalue={text}\n\t\t\t\t\tonChange={(value) => {\n\t\t\t\t\t\tsetText(value)\n\t\t\t\t\t\tsaveCommentDraft(NEW_COMMENT_DRAFT, value)\n\t\t\t\t\t}}\n\t\t\t\t\tonSubmit={submit}\n\t\t\t\t\t// No user, no author for the record \u2014 dead send button.\n\t\t\t\t\tdisabled={isCommentEmpty(text) || !currentUserId}\n\t\t\t\t\tgetMentionSuggestions={getMentionSuggestions}\n\t\t\t\t\trenderMentionSuggestion={renderMentionSuggestion}\n\t\t\t\t\tautoFocus\n\t\t\t\t\tleading={draftAvatar}\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\tComposerFallback && <ComposerFallback context=\"pending\" />\n\t\t\t)}\n\t\t</div>,\n\t\tcontainer\n\t)\n}\n"],
|
|
5
|
+
"mappings": "AAkJQ,SAoaJ,UApaI,KAoaJ,YApaI;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AA,YACA,UAAU;AAAA,YAEV,UAAU,eAAe,IAAI,KAAK,CAAC;AAAA,YACnC;AAAA,YACA;AAAA,YACA,WAAS;AAAA,YACT,SAAS;AAAA;AAAA,QACV,IAEA,oBAAoB,oBAAC,oBAAiB,SAAQ,WAAU;AAAA;AAAA,IAE1D;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["Fragment", "ClusterBadge", "ThreadPin"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useRef } from "react";
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import {
|
|
5
5
|
useContainer,
|
|
@@ -9,35 +9,27 @@ import {
|
|
|
9
9
|
useValue
|
|
10
10
|
} from "tldraw";
|
|
11
11
|
import { CommentsList } from "../ui/comments-list.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { UNKNOWN_COMMENT_AUTHOR } from "./comment-render.mjs";
|
|
13
13
|
import { CommentsFilterMenu } from "./comments-filter-menu.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { CommentsVisibilityToggle } from "./comments-visibility-toggle.mjs";
|
|
15
15
|
import { useComments, useCommentThreads } from "./hooks.mjs";
|
|
16
16
|
import { useCommentingEnabled } from "./license.mjs";
|
|
17
17
|
import { useCommentingOptions } from "./options.mjs";
|
|
18
18
|
import { richTextToPlaintext } from "./rich-text.mjs";
|
|
19
|
-
import { openThreadId, sidebarFilters } from "./state.mjs";
|
|
19
|
+
import { commentsSidebarOpen, openThreadId, sidebarFilters } from "./state.mjs";
|
|
20
20
|
import { focusThread } from "./thread-state.mjs";
|
|
21
21
|
function CanvasCommentsSidebar(props) {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
currentUserId,
|
|
25
|
-
isCommentUnread,
|
|
26
|
-
tools,
|
|
27
|
-
header,
|
|
28
|
-
empty,
|
|
29
|
-
impreciseShapeAnchor
|
|
30
|
-
} = props;
|
|
22
|
+
const { resolveAuthor, currentUserId, isCommentUnread, header, empty, getThreadHref } = props;
|
|
23
|
+
const resolveName = useCallback((id) => resolveAuthor(id)?.name, [resolveAuthor]);
|
|
31
24
|
const editor = useEditor();
|
|
32
25
|
const options = useCommentingOptions();
|
|
33
|
-
const sidebarTools = tools ?? ["comment"];
|
|
34
26
|
const container = useContainer();
|
|
35
27
|
const commentingEnabled = useCommentingEnabled();
|
|
36
28
|
const msg = useTranslation();
|
|
37
29
|
const threads = useCommentThreads(editor);
|
|
38
30
|
const comments = useComments(editor);
|
|
39
31
|
const currentPageId = useValue("page id", () => editor.getCurrentPageId(), [editor]);
|
|
40
|
-
const
|
|
32
|
+
const open = useValue("sidebar open", () => commentsSidebarOpen.get(editor), [editor]);
|
|
41
33
|
const openId = useValue("open thread", () => openThreadId.get(editor), [editor]);
|
|
42
34
|
const filters = useValue("sidebar filters", () => sidebarFilters.get(editor), [editor]);
|
|
43
35
|
const pageNames = useValue(
|
|
@@ -45,7 +37,7 @@ function CanvasCommentsSidebar(props) {
|
|
|
45
37
|
() => new Map(editor.getPages().map((page) => [page.id, page.name])),
|
|
46
38
|
[editor]
|
|
47
39
|
);
|
|
48
|
-
if (!commentingEnabled || !
|
|
40
|
+
if (!commentingEnabled || !open) return null;
|
|
49
41
|
const byThread = /* @__PURE__ */ new Map();
|
|
50
42
|
for (const comment of comments) {
|
|
51
43
|
const list = byThread.get(comment.threadId) ?? [];
|
|
@@ -55,50 +47,55 @@ function CanvasCommentsSidebar(props) {
|
|
|
55
47
|
const pageThreads = threads.filter(
|
|
56
48
|
(thread) => !filters.onlyCurrentPage || thread.pageId === currentPageId
|
|
57
49
|
);
|
|
58
|
-
const
|
|
59
|
-
(thread) => !filters.onlyMine || currentUserId ===
|
|
50
|
+
const rows = pageThreads.filter((thread) => filters.showResolved || thread.resolved == null).filter(
|
|
51
|
+
(thread) => !filters.onlyMine || currentUserId === null || thread.createdBy === currentUserId
|
|
60
52
|
).filter(
|
|
61
53
|
(thread) => !filters.onlyUnread || isCommentUnread === void 0 || (byThread.get(thread.id) ?? []).some((c) => isCommentUnread(c.id))
|
|
62
54
|
).map((thread) => {
|
|
63
55
|
const threadComments = byThread.get(thread.id) ?? [];
|
|
64
56
|
const first = threadComments[0];
|
|
57
|
+
const last = threadComments[threadComments.length - 1];
|
|
65
58
|
let preview = "";
|
|
66
59
|
const ThreadPreview = options.components.ThreadPreview;
|
|
67
60
|
if (first) {
|
|
68
61
|
preview = ThreadPreview ? /* @__PURE__ */ jsx(ThreadPreview, { comment: first }) : richTextToPlaintext(first.body, resolveName);
|
|
69
62
|
}
|
|
70
63
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
item: {
|
|
65
|
+
id: thread.id,
|
|
66
|
+
author: resolveAuthor(thread.createdBy) ?? UNKNOWN_COMMENT_AUTHOR,
|
|
67
|
+
preview,
|
|
68
|
+
date: new Date((first ?? thread).createdAt).toISOString(),
|
|
69
|
+
resolved: thread.resolved != null,
|
|
70
|
+
// The page label only earns its place when it adds information: multiple pages
|
|
71
|
+
// exist, and the thread is somewhere other than where you already are.
|
|
72
|
+
page: pageNames.size > 1 && thread.pageId !== currentPageId ? pageNames.get(thread.pageId) : void 0,
|
|
73
|
+
count: threadComments.length,
|
|
74
|
+
selected: openId === thread.id,
|
|
75
|
+
href: getThreadHref?.(thread.id)
|
|
76
|
+
},
|
|
77
|
+
lastActivity: (last ?? thread).createdAt
|
|
79
78
|
};
|
|
80
|
-
}).sort((a, b) => {
|
|
81
|
-
if (!!a.resolved !== !!b.resolved) return a.resolved ? 1 : -1;
|
|
82
|
-
return b.date.localeCompare(a.date);
|
|
83
79
|
});
|
|
80
|
+
const items = sortSidebarRows(rows).map((row) => row.item);
|
|
84
81
|
const focus = (id) => {
|
|
85
82
|
const thread = threads.find((t) => t.id === id);
|
|
86
|
-
if (thread) focusThread(editor, thread
|
|
83
|
+
if (thread) focusThread(editor, thread);
|
|
87
84
|
};
|
|
88
85
|
return /* @__PURE__ */ jsx(SidebarPanel, { container, children: /* @__PURE__ */ jsx(
|
|
89
86
|
CommentsList,
|
|
90
87
|
{
|
|
91
88
|
items,
|
|
92
89
|
header: header ?? msg("comments.title"),
|
|
93
|
-
headerAction: /* @__PURE__ */ jsxs("div", { className: "cmt-list__header-actions", children: [
|
|
90
|
+
headerAction: /* @__PURE__ */ jsxs("div", { className: "tlui-cmt-list__header-actions", children: [
|
|
94
91
|
/* @__PURE__ */ jsx(
|
|
95
92
|
CommentsFilterMenu,
|
|
96
93
|
{
|
|
97
|
-
canFilterByAuthor: currentUserId !==
|
|
94
|
+
canFilterByAuthor: currentUserId !== null,
|
|
98
95
|
canFilterByUnread: isCommentUnread !== void 0
|
|
99
96
|
}
|
|
100
97
|
),
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
98
|
+
/* @__PURE__ */ jsx(CommentsVisibilityToggle, {})
|
|
102
99
|
] }),
|
|
103
100
|
empty: items.length === 0 && pageThreads.length > 0 ? msg("comments.empty-filtered") : empty ?? msg("comments.empty"),
|
|
104
101
|
resolvedLabel: msg("comments.resolved"),
|
|
@@ -106,15 +103,21 @@ function CanvasCommentsSidebar(props) {
|
|
|
106
103
|
}
|
|
107
104
|
) });
|
|
108
105
|
}
|
|
106
|
+
function sortSidebarRows(rows) {
|
|
107
|
+
return [...rows].sort(
|
|
108
|
+
(a, b) => Number(!!a.item.resolved) - Number(!!b.item.resolved) || b.lastActivity - a.lastActivity || (a.item.id < b.item.id ? -1 : 1)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
109
111
|
function SidebarPanel({ container, children }) {
|
|
110
112
|
const ref = useRef(null);
|
|
111
113
|
usePassThroughMouseOverEvents(ref);
|
|
112
114
|
return createPortal(
|
|
113
|
-
/* @__PURE__ */ jsx("div", { ref, className: "cmt-canvas-sidebar", children }),
|
|
115
|
+
/* @__PURE__ */ jsx("div", { ref, className: "tlui-cmt-canvas-sidebar", onContextMenu: (e) => e.stopPropagation(), children }),
|
|
114
116
|
container
|
|
115
117
|
);
|
|
116
118
|
}
|
|
117
119
|
export {
|
|
118
|
-
CanvasCommentsSidebar
|
|
120
|
+
CanvasCommentsSidebar,
|
|
121
|
+
sortSidebarRows
|
|
119
122
|
};
|
|
120
123
|
//# sourceMappingURL=comments-sidebar.mjs.map
|