@tldraw/commenting 5.5.0-canary.240ccfe6bb7b → 5.5.0-canary.2a22fdfebf61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commenting.css +32 -0
- package/dist-cjs/canvas/anchor-lifecycle.js +5 -4
- package/dist-cjs/canvas/anchor-lifecycle.js.map +2 -2
- package/dist-cjs/canvas/cluster-fade.js +1 -1
- package/dist-cjs/canvas/cluster-fade.js.map +2 -2
- package/dist-cjs/canvas/cluster-model.js +31 -22
- package/dist-cjs/canvas/cluster-model.js.map +2 -2
- package/dist-cjs/canvas/comment-render.js +19 -19
- package/dist-cjs/canvas/comment-render.js.map +2 -2
- package/dist-cjs/canvas/comment-store.js +5 -10
- package/dist-cjs/canvas/comment-store.js.map +2 -2
- package/dist-cjs/canvas/comments-overlay.js +16 -12
- package/dist-cjs/canvas/comments-overlay.js.map +2 -2
- package/dist-cjs/canvas/comments-sidebar.js +7 -1
- package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
- package/dist-cjs/canvas/hooks.js.map +1 -1
- package/dist-cjs/canvas/thread-pin.js +26 -14
- package/dist-cjs/canvas/thread-pin.js.map +2 -2
- package/dist-cjs/canvas/thread-stack.js +6 -2
- package/dist-cjs/canvas/thread-stack.js.map +2 -2
- package/dist-cjs/canvas/thread-state.js +0 -12
- package/dist-cjs/canvas/thread-state.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +78 -67
- package/dist-cjs/canvas/thread-view.js.map +2 -2
- package/dist-cjs/clustering/computeClusterTable.js +9 -2
- package/dist-cjs/clustering/computeClusterTable.js.map +2 -2
- package/dist-cjs/clustering/replay.js +23 -10
- package/dist-cjs/clustering/replay.js.map +2 -2
- package/dist-cjs/clustering/runtime.js +15 -9
- package/dist-cjs/clustering/runtime.js.map +2 -2
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/ui/comment-composer.js +4 -2
- package/dist-cjs/ui/comment-composer.js.map +2 -2
- package/dist-cjs/ui/format-time.js +8 -20
- package/dist-cjs/ui/format-time.js.map +2 -2
- package/dist-cjs/ui/reaction.js +15 -5
- package/dist-cjs/ui/reaction.js.map +2 -2
- package/dist-esm/canvas/anchor-lifecycle.mjs +6 -5
- package/dist-esm/canvas/anchor-lifecycle.mjs.map +2 -2
- package/dist-esm/canvas/cluster-fade.mjs +1 -1
- package/dist-esm/canvas/cluster-fade.mjs.map +2 -2
- package/dist-esm/canvas/cluster-model.mjs +32 -23
- package/dist-esm/canvas/cluster-model.mjs.map +2 -2
- package/dist-esm/canvas/comment-render.mjs +19 -19
- package/dist-esm/canvas/comment-render.mjs.map +2 -2
- package/dist-esm/canvas/comment-store.mjs +5 -10
- package/dist-esm/canvas/comment-store.mjs.map +2 -2
- package/dist-esm/canvas/comments-overlay.mjs +17 -13
- package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
- package/dist-esm/canvas/comments-sidebar.mjs +14 -3
- package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
- package/dist-esm/canvas/hooks.mjs.map +1 -1
- package/dist-esm/canvas/thread-pin.mjs +26 -16
- package/dist-esm/canvas/thread-pin.mjs.map +2 -2
- package/dist-esm/canvas/thread-stack.mjs +7 -3
- package/dist-esm/canvas/thread-stack.mjs.map +2 -2
- package/dist-esm/canvas/thread-state.mjs +0 -12
- package/dist-esm/canvas/thread-state.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +78 -67
- package/dist-esm/canvas/thread-view.mjs.map +2 -2
- package/dist-esm/clustering/computeClusterTable.mjs +9 -2
- package/dist-esm/clustering/computeClusterTable.mjs.map +2 -2
- package/dist-esm/clustering/replay.mjs +23 -10
- package/dist-esm/clustering/replay.mjs.map +2 -2
- package/dist-esm/clustering/runtime.mjs +15 -9
- package/dist-esm/clustering/runtime.mjs.map +2 -2
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/ui/comment-composer.mjs +4 -2
- package/dist-esm/ui/comment-composer.mjs.map +2 -2
- package/dist-esm/ui/format-time.mjs +8 -20
- package/dist-esm/ui/format-time.mjs.map +2 -2
- package/dist-esm/ui/reaction.mjs +15 -7
- package/dist-esm/ui/reaction.mjs.map +2 -2
- package/package.json +5 -5
- package/src/canvas/anchor-lifecycle.ts +6 -5
- package/src/canvas/cluster-fade.ts +6 -6
- package/src/canvas/cluster-model.ts +33 -27
- package/src/canvas/comment-render.ts +28 -30
- package/src/canvas/comment-store.ts +6 -16
- package/src/canvas/comments-overlay.tsx +19 -18
- package/src/canvas/comments-sidebar.tsx +18 -3
- package/src/canvas/hooks.ts +1 -1
- package/src/canvas/thread-pin.tsx +31 -21
- package/src/canvas/thread-stack.tsx +7 -3
- package/src/canvas/thread-state.ts +0 -26
- package/src/canvas/thread-view.tsx +95 -93
- package/src/clustering/computeClusterTable.ts +20 -3
- package/src/clustering/replay.ts +23 -10
- package/src/clustering/runtime.ts +15 -9
- package/src/ui/comment-composer.tsx +4 -2
- package/src/ui/comments.css +32 -0
- package/src/ui/format-time.ts +11 -24
- package/src/ui/reaction.tsx +23 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ui/reaction.tsx"],
|
|
4
|
-
"sourcesContent": ["import { ComponentType, ReactNode } from 'react'\nimport { TldrawUiTooltip, useTranslation } from 'tldraw'\nimport { ReactionReactor } from './reactions'\n\n/** Render a reaction token to its visual \u2014 the emoji glyph by default. @public */\nexport type RenderReaction = (token: string) => ReactNode\n\n/** The default reaction renderer: emits the token string for the OS emoji font to draw. @public */\nexport function defaultRenderReaction(token: string): ReactNode {\n\treturn token\n}\n\n/** @public */\nexport interface ReactionProps {\n\temoji: string\n\tcount: number\n\tactive: boolean\n\t/** How to draw the emoji token. Defaults to the token string (OS emoji font). */\n\trenderReaction?: RenderReaction\n\t/** Who reacted with this emoji, in reaction order \u2014 shown when the pill is hovered. */\n\treactors: ReactionReactor[]\n\t/** Whether hovering shows the reactor list. Pass false to suppress it \u2014 e.g. while another\n\t * popup menu on the comment is open. Defaults to true. */\n\tenableHoverList?: boolean\n\t/** The hover affordance for the pill, naming who reacted. It receives the reactors and the pill\n\t * itself (as `children`) and returns the whole thing \u2014 so it owns the tooltip, its box, size,\n\t * shape, and position, not just the text inside. Defaults to `DefaultReactionTooltip`, which\n\t * hangs the built-in inline sentence below the pill. */\n\tReactionTooltip?: ComponentType<ReactionTooltipProps>\n\t/** Called when the pill is pressed \u2014 toggles the current user's reaction. */\n\tonClick?(): void\n}\n\n/**\n * A single emoji reaction pill with a count, highlighted when the user reacted. Hovering it shows a\n * tooltip naming who reacted (the current user included), when `enableHoverList` is set.\n * @public @react\n */\nexport function Reaction({\n\temoji,\n\tcount,\n\tactive,\n\treactors,\n\tenableHoverList = true,\n\trenderReaction = defaultRenderReaction,\n\tReactionTooltip = DefaultReactionTooltip,\n\tonClick,\n}: ReactionProps) {\n\t// An inert pill (no handler) is plain content, not a control \u2014 rendering it as a span keeps it\n\t// valid inside an anchor row (e.g. a notification list item) and out of the tab order.\n\tconst Tag = onClick ? 'button' : 'span'\n\tconst pill = (\n\t\t<Tag\n\t\t\tclassName={active ? 'tlui-cmt-reaction tlui-cmt-reaction--active' : 'tlui-cmt-reaction'}\n\t\t\t{...(onClick\n\t\t\t\t? { type: 'button' as const, 'aria-pressed': active, onClick }\n\t\t\t\t: { role: 'img' as const })}\n\t\t\t// The emoji alone announces as its unicode name (\"thumbs up\"); pairing it with the count\n\t\t\t// is what makes the pill's state legible to a screen reader. The inert span needs the\n\t\t\t// img role for the label to be announced at all.\n\t\t\taria-label={`${emoji} ${count}`}\n\t\t>\n\t\t\t<span className=\"tlui-cmt-reaction__emoji\">{renderReaction(emoji)}</span>\n\t\t\t<span className=\"tlui-cmt-reaction__count\">{count}</span>\n\t\t</Tag>\n\t)\n\n\t// A bare pill when hovering is suppressed, or when there's no one to name.\n\tif (!enableHoverList || reactors.length === 0) return pill\n\n\t// Hand the whole hover affordance to the tooltip component: it wraps the pill and owns how the\n\t// reactor list is presented.\n\treturn <ReactionTooltip reactors={reactors}>{pill}</ReactionTooltip>\n}\n\n/** @public */\nexport interface ReactionTooltipProps {\n\t/** Who reacted with this emoji, in reaction order. */\n\treactors: ReactionReactor[]\n\t/** The reaction pill to wrap. Anchor the hover affordance to this and render it. */\n\tchildren: ReactNode\n}\n\n/**\n * The default reactor tooltip: hangs the built-in inline sentence (`DefaultReactionTooltipContent`)\n * in a standard tooltip below the pill \u2014 the same tooltip the toolbar uses. Replace it via\n * `CommentingComponents.ReactionTooltip` to present the reactor list any other way (a different box,\n * avatars, a banner, anywhere on screen); it receives the pill as `children`.\n * @public @react\n */\nexport function DefaultReactionTooltip({ reactors, children }: ReactionTooltipProps) {\n\treturn (\n\t\t<TldrawUiTooltip side=\"bottom\" content={<DefaultReactionTooltipContent reactors={reactors} />}>\n\t\t\t{children}\n\t\t</TldrawUiTooltip>\n\t)\n}\n\n/**\n * The default reactor sentence naming who reacted \u2014 up to three names spelled out, then \"and N\n * others\" (e.g. \"You reacted\", \"You and Bo reacted\", \"You, Bo and Ada reacted\", \"You, Bo, Ada and 2\n * others reacted\"). The wording lives in the `comments.reacted-*` translation strings so each locale\n * controls the grammar. Exported so a custom `ReactionTooltip` can reuse it inside its own box.\n * @public @react\n */\nexport function DefaultReactionTooltipContent({ reactors }: { reactors: ReactionReactor[] }) {\n\tconst msg = useTranslation()\n\tconst names = reactors.map((reactor) =>\n\t\treactor.you ? msg('comments.mention-you') : reactor.name\n\t)\n\
|
|
5
|
-
"mappings": "AAoDE,
|
|
4
|
+
"sourcesContent": ["import { ComponentType, ReactNode } from 'react'\nimport { TldrawUiTooltip, useTranslation } from 'tldraw'\nimport { ReactionReactor } from './reactions'\n\n/** Render a reaction token to its visual \u2014 the emoji glyph by default. @public */\nexport type RenderReaction = (token: string) => ReactNode\n\n/** The default reaction renderer: emits the token string for the OS emoji font to draw. @public */\nexport function defaultRenderReaction(token: string): ReactNode {\n\treturn token\n}\n\n/** @public */\nexport interface ReactionProps {\n\temoji: string\n\tcount: number\n\tactive: boolean\n\t/** How to draw the emoji token. Defaults to the token string (OS emoji font). */\n\trenderReaction?: RenderReaction\n\t/** Who reacted with this emoji, in reaction order \u2014 shown when the pill is hovered. */\n\treactors: ReactionReactor[]\n\t/** Whether hovering shows the reactor list. Pass false to suppress it \u2014 e.g. while another\n\t * popup menu on the comment is open. Defaults to true. */\n\tenableHoverList?: boolean\n\t/** The hover affordance for the pill, naming who reacted. It receives the reactors and the pill\n\t * itself (as `children`) and returns the whole thing \u2014 so it owns the tooltip, its box, size,\n\t * shape, and position, not just the text inside. Defaults to `DefaultReactionTooltip`, which\n\t * hangs the built-in inline sentence below the pill. */\n\tReactionTooltip?: ComponentType<ReactionTooltipProps>\n\t/** Called when the pill is pressed \u2014 toggles the current user's reaction. */\n\tonClick?(): void\n}\n\n/**\n * A single emoji reaction pill with a count, highlighted when the user reacted. Hovering it shows a\n * tooltip naming who reacted (the current user included), when `enableHoverList` is set.\n * @public @react\n */\nexport function Reaction({\n\temoji,\n\tcount,\n\tactive,\n\treactors,\n\tenableHoverList = true,\n\trenderReaction = defaultRenderReaction,\n\tReactionTooltip = DefaultReactionTooltip,\n\tonClick,\n}: ReactionProps) {\n\t// An inert pill (no handler) is plain content, not a control \u2014 rendering it as a span keeps it\n\t// valid inside an anchor row (e.g. a notification list item) and out of the tab order.\n\tconst Tag = onClick ? 'button' : 'span'\n\tconst pill = (\n\t\t<Tag\n\t\t\tclassName={active ? 'tlui-cmt-reaction tlui-cmt-reaction--active' : 'tlui-cmt-reaction'}\n\t\t\t{...(onClick\n\t\t\t\t? { type: 'button' as const, 'aria-pressed': active, onClick }\n\t\t\t\t: { role: 'img' as const })}\n\t\t\t// The emoji alone announces as its unicode name (\"thumbs up\"); pairing it with the count\n\t\t\t// is what makes the pill's state legible to a screen reader. The inert span needs the\n\t\t\t// img role for the label to be announced at all.\n\t\t\taria-label={`${emoji} ${count}`}\n\t\t>\n\t\t\t<span className=\"tlui-cmt-reaction__emoji\">{renderReaction(emoji)}</span>\n\t\t\t<span className=\"tlui-cmt-reaction__count\">{count}</span>\n\t\t</Tag>\n\t)\n\n\t// A bare pill when hovering is suppressed, or when there's no one to name.\n\tif (!enableHoverList || reactors.length === 0) return pill\n\n\t// Hand the whole hover affordance to the tooltip component: it wraps the pill and owns how the\n\t// reactor list is presented.\n\treturn <ReactionTooltip reactors={reactors}>{pill}</ReactionTooltip>\n}\n\n/** @public */\nexport interface ReactionTooltipProps {\n\t/** Who reacted with this emoji, in reaction order. */\n\treactors: ReactionReactor[]\n\t/** The reaction pill to wrap. Anchor the hover affordance to this and render it. */\n\tchildren: ReactNode\n}\n\n/**\n * The default reactor tooltip: hangs the built-in inline sentence (`DefaultReactionTooltipContent`)\n * in a standard tooltip below the pill \u2014 the same tooltip the toolbar uses. Replace it via\n * `CommentingComponents.ReactionTooltip` to present the reactor list any other way (a different box,\n * avatars, a banner, anywhere on screen); it receives the pill as `children`.\n * @public @react\n */\nexport function DefaultReactionTooltip({ reactors, children }: ReactionTooltipProps) {\n\treturn (\n\t\t<TldrawUiTooltip side=\"bottom\" content={<DefaultReactionTooltipContent reactors={reactors} />}>\n\t\t\t{children}\n\t\t</TldrawUiTooltip>\n\t)\n}\n\n/**\n * The default reactor sentence naming who reacted \u2014 up to three names spelled out, then \"and N\n * others\" (e.g. \"You reacted\", \"You and Bo reacted\", \"You, Bo and Ada reacted\", \"You, Bo, Ada and 2\n * others reacted\"). The wording lives in the `comments.reacted-*` translation strings so each locale\n * controls the grammar. Exported so a custom `ReactionTooltip` can reuse it inside its own box.\n * @public @react\n */\nexport function DefaultReactionTooltipContent({ reactors }: { reactors: ReactionReactor[] }) {\n\tconst msg = useTranslation()\n\tconst names = reactors.map((reactor) =>\n\t\treactor.you ? msg('comments.mention-you') : reactor.name\n\t)\n\tconst [a, b, c] = names\n\tswitch (names.length) {\n\t\tcase 0:\n\t\t\treturn null\n\t\tcase 1:\n\t\t\treturn <>{msg('comments.reacted-1').replace('{a}', a)}</>\n\t\tcase 2:\n\t\t\treturn <>{msg('comments.reacted-2').replace('{a}', a).replace('{b}', b)}</>\n\t\tcase 3:\n\t\t\treturn <>{msg('comments.reacted-3').replace('{a}', a).replace('{b}', b).replace('{c}', c)}</>\n\t\tdefault: {\n\t\t\tconst others = names.length - 3\n\t\t\tconst template = others === 1 ? 'comments.reacted-more-one' : 'comments.reacted-more'\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t{msg(template)\n\t\t\t\t\t\t.replace('{a}', a)\n\t\t\t\t\t\t.replace('{b}', b)\n\t\t\t\t\t\t.replace('{c}', c)\n\t\t\t\t\t\t.replace('{count}', String(others))}\n\t\t\t\t</>\n\t\t\t)\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAoDE,SA+DQ,UArDP,KAVD;AAnDF,SAAS,iBAAiB,sBAAsB;AAOzC,SAAS,sBAAsB,OAA0B;AAC/D,SAAO;AACR;AA4BO,SAAS,SAAS;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB;AACD,GAAkB;AAGjB,QAAM,MAAM,UAAU,WAAW;AACjC,QAAM,OACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAW,SAAS,gDAAgD;AAAA,MACnE,GAAI,UACF,EAAE,MAAM,UAAmB,gBAAgB,QAAQ,QAAQ,IAC3D,EAAE,MAAM,MAAe;AAAA,MAI1B,cAAY,GAAG,KAAK,IAAI,KAAK;AAAA,MAE7B;AAAA,4BAAC,UAAK,WAAU,4BAA4B,yBAAe,KAAK,GAAE;AAAA,QAClE,oBAAC,UAAK,WAAU,4BAA4B,iBAAM;AAAA;AAAA;AAAA,EACnD;AAID,MAAI,CAAC,mBAAmB,SAAS,WAAW,EAAG,QAAO;AAItD,SAAO,oBAAC,mBAAgB,UAAqB,gBAAK;AACnD;AAiBO,SAAS,uBAAuB,EAAE,UAAU,SAAS,GAAyB;AACpF,SACC,oBAAC,mBAAgB,MAAK,UAAS,SAAS,oBAAC,iCAA8B,UAAoB,GACzF,UACF;AAEF;AASO,SAAS,8BAA8B,EAAE,SAAS,GAAoC;AAC5F,QAAM,MAAM,eAAe;AAC3B,QAAM,QAAQ,SAAS;AAAA,IAAI,CAAC,YAC3B,QAAQ,MAAM,IAAI,sBAAsB,IAAI,QAAQ;AAAA,EACrD;AACA,QAAM,CAAC,GAAG,GAAG,CAAC,IAAI;AAClB,UAAQ,MAAM,QAAQ;AAAA,IACrB,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IACvD,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IACzE,KAAK;AACJ,aAAO,gCAAG,cAAI,oBAAoB,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,EAAE,QAAQ,OAAO,CAAC,GAAE;AAAA,IAC3F,SAAS;AACR,YAAM,SAAS,MAAM,SAAS;AAC9B,YAAM,WAAW,WAAW,IAAI,8BAA8B;AAC9D,aACC,gCACE,cAAI,QAAQ,EACX,QAAQ,OAAO,CAAC,EAChB,QAAQ,OAAO,CAAC,EAChB,QAAQ,OAAO,CAAC,EAChB,QAAQ,WAAW,OAAO,MAAM,CAAC,GACpC;AAAA,IAEF;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/commenting",
|
|
3
3
|
"description": "tldraw commenting UI components.",
|
|
4
|
-
"version": "5.5.0-canary.
|
|
4
|
+
"version": "5.5.0-canary.2a22fdfebf61",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lint": "yarn run -T tsx ../../internal/scripts/lint.ts"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tldraw/driver": "5.5.0-canary.
|
|
49
|
+
"@tldraw/driver": "5.5.0-canary.2a22fdfebf61",
|
|
50
50
|
"@types/react": "^19.2.7",
|
|
51
51
|
"@types/react-dom": "^19.2.3",
|
|
52
52
|
"react": "^19.2.1",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"@tiptap/core": "^3.12.1",
|
|
65
65
|
"@tiptap/pm": "^3.12.1",
|
|
66
66
|
"@tiptap/react": "^3.12.1",
|
|
67
|
-
"@tldraw/mentions": "5.5.0-canary.
|
|
68
|
-
"@tldraw/utils": "5.5.0-canary.
|
|
69
|
-
"tldraw": "5.5.0-canary.
|
|
67
|
+
"@tldraw/mentions": "5.5.0-canary.2a22fdfebf61",
|
|
68
|
+
"@tldraw/utils": "5.5.0-canary.2a22fdfebf61",
|
|
69
|
+
"tldraw": "5.5.0-canary.2a22fdfebf61"
|
|
70
70
|
},
|
|
71
71
|
"module": "dist-esm/index.mjs",
|
|
72
72
|
"source": "src/index.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WeakCache } from '@tldraw/utils'
|
|
2
2
|
import { Editor, TLCommentAnchor, TLCommentThread, TLPageId, TLShapeId, VecLike } from 'tldraw'
|
|
3
3
|
import { commitCommentMutation } from './comment-mutations'
|
|
4
|
-
import {
|
|
4
|
+
import { getCommentRecord, getComments, getCommentThreads, TLCommentRecord } from './comment-store'
|
|
5
5
|
import { anchorPagePoint, impreciseShapePinInset } from './thread-state'
|
|
6
6
|
|
|
7
7
|
type ShapeAnchor = Extract<TLCommentAnchor, { type: 'shape' }>
|
|
@@ -108,8 +108,9 @@ export function registerCommentAnchorLifecycle(editor: Editor): () => void {
|
|
|
108
108
|
if (editor.getShape(shapeId)) continue
|
|
109
109
|
for (const [threadId, point] of threadPoints) {
|
|
110
110
|
if (!point) continue
|
|
111
|
-
const thread =
|
|
112
|
-
if (!thread ||
|
|
111
|
+
const thread = getCommentRecord(editor, threadId)
|
|
112
|
+
if (!thread || thread.typeName !== 'comment-thread') continue
|
|
113
|
+
if (!isAnchoredToShape(thread, shapeId)) continue
|
|
113
114
|
let converted = convertedByShape.get(shapeId)
|
|
114
115
|
if (!converted) {
|
|
115
116
|
converted = []
|
|
@@ -129,8 +130,8 @@ export function registerCommentAnchorLifecycle(editor: Editor): () => void {
|
|
|
129
130
|
|
|
130
131
|
const pageId = editor.getAncestorPageId(shape)
|
|
131
132
|
for (const { threadId, anchor, point } of converted) {
|
|
132
|
-
const thread =
|
|
133
|
-
if (!thread) continue
|
|
133
|
+
const thread = getCommentRecord(editor, threadId)
|
|
134
|
+
if (!thread || thread.typeName !== 'comment-thread') continue
|
|
134
135
|
// Re-attach only threads still sitting exactly where the conversion left them — a
|
|
135
136
|
// pin moved since then was placed deliberately, and that placement wins.
|
|
136
137
|
const current = thread.anchor
|
|
@@ -78,14 +78,14 @@ function reconcileFadeNodes(
|
|
|
78
78
|
|
|
79
79
|
for (const node of nextNodes) {
|
|
80
80
|
const previousItem = previousById.get(node.id)
|
|
81
|
-
// A node that was fading out and came back snaps to present rather than re-entering.
|
|
82
81
|
next.push({
|
|
83
82
|
node,
|
|
84
|
-
phase:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
phase:
|
|
84
|
+
previousItem && previousItem.phase !== 'exiting'
|
|
85
|
+
? previousItem.phase
|
|
86
|
+
: previousItem
|
|
87
|
+
? 'present'
|
|
88
|
+
: 'entering',
|
|
89
89
|
})
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { Editor, react, TLCommentThread, useValue } from 'tldraw'
|
|
3
3
|
import { computeClusterTable } from '../clustering/computeClusterTable'
|
|
4
4
|
import { type ClusterRuntime, createClusterRuntime } from '../clustering/runtime'
|
|
5
5
|
import type { ClusterNode, ClusterTable, MergeEvent } from '../clustering/types'
|
|
@@ -169,14 +169,11 @@ export function useClusterModel(
|
|
|
169
169
|
for (const id of newlyMovedIds) next.add(id)
|
|
170
170
|
setHeldThreadIds(next)
|
|
171
171
|
}
|
|
172
|
-
const latestLeafIds = useMemo(
|
|
173
|
-
() => new Set(latestModel.table.leaves.map((leaf) => leaf.id)),
|
|
174
|
-
[latestModel]
|
|
175
|
-
)
|
|
176
172
|
// Local partition maintenance — the only non-zoom visual change. Any displayed leaf that has left the
|
|
177
173
|
// cluster input is detached from its badge in place; the corrected rebuild already sits in latestModel
|
|
178
174
|
// awaiting the next zoom-out. When the two models match, the leaf sets are identical, so skip the scan.
|
|
179
175
|
if (clusterModel !== latestModel) {
|
|
176
|
+
const latestLeafIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id))
|
|
180
177
|
const removedLeafIds: string[] = []
|
|
181
178
|
for (const leaf of clusterModel.table.leaves) {
|
|
182
179
|
if (!latestLeafIds.has(leaf.id)) {
|
|
@@ -191,7 +188,12 @@ export function useClusterModel(
|
|
|
191
188
|
// never folds pins into clusters — merging is a zoom-out-only move, matching the runtime.
|
|
192
189
|
useEffect(() => {
|
|
193
190
|
if (heldThreadIds.size === 0) return
|
|
194
|
-
|
|
191
|
+
let lastZoom = editor.getZoomLevel()
|
|
192
|
+
return react('rejoin moved comment pins on zoom out', () => {
|
|
193
|
+
const zoom = editor.getZoomLevel()
|
|
194
|
+
const prevZoom = lastZoom
|
|
195
|
+
lastZoom = zoom
|
|
196
|
+
if (zoom >= prevZoom) return
|
|
195
197
|
adoptOnRebuild.current = true
|
|
196
198
|
setHeldThreadIds(EMPTY_SET)
|
|
197
199
|
})
|
|
@@ -201,7 +203,12 @@ export function useClusterModel(
|
|
|
201
203
|
// splits correctly on its own (split thresholds are direction-safe by the hysteresis invariant).
|
|
202
204
|
useEffect(() => {
|
|
203
205
|
if (clusterModel === latestModel) return
|
|
204
|
-
|
|
206
|
+
let lastZoom = editor.getZoomLevel()
|
|
207
|
+
return react('adopt pending cluster model on zoom out', () => {
|
|
208
|
+
const zoom = editor.getZoomLevel()
|
|
209
|
+
const prevZoom = lastZoom
|
|
210
|
+
lastZoom = zoom
|
|
211
|
+
if (zoom >= prevZoom) return
|
|
205
212
|
latestModel.runtime.seedFrom(zoom, clusterModel.runtime.getVisible())
|
|
206
213
|
setRenderedModel(latestModel)
|
|
207
214
|
})
|
|
@@ -216,10 +223,11 @@ export function useClusterModel(
|
|
|
216
223
|
for (const node of clusterModel.runtime.getVisible().values()) {
|
|
217
224
|
for (const member of node.members) displayed.add(member)
|
|
218
225
|
}
|
|
219
|
-
|
|
226
|
+
const latestIds = new Set(latestModel.table.leaves.map((leaf) => leaf.id))
|
|
227
|
+
return threads.filter((thread) => latestIds.has(thread.id) && !displayed.has(thread.id))
|
|
220
228
|
// The runtime mutates its partition in place; partitionVersion is its change stamp.
|
|
221
229
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
-
}, [clusterModel, latestModel,
|
|
230
|
+
}, [clusterModel, latestModel, threads, partitionVersion])
|
|
223
231
|
const heldThreads = useMemo(
|
|
224
232
|
() => threads.filter((thread) => heldThreadIds.has(thread.id) && thread.id !== openId),
|
|
225
233
|
[threads, heldThreadIds, openId]
|
|
@@ -251,17 +259,6 @@ export function useClusterModel(
|
|
|
251
259
|
}
|
|
252
260
|
}
|
|
253
261
|
|
|
254
|
-
/** Run `onZoomOut` on each zoom change that decreased the zoom, starting from the current level. */
|
|
255
|
-
function reactOnZoomOut(editor: Editor, name: string, onZoomOut: (zoom: number) => void) {
|
|
256
|
-
let lastZoom = editor.getZoomLevel()
|
|
257
|
-
return react(name, () => {
|
|
258
|
-
const zoom = editor.getZoomLevel()
|
|
259
|
-
const prevZoom = lastZoom
|
|
260
|
-
lastZoom = zoom
|
|
261
|
-
if (zoom < prevZoom) onZoomOut(zoom)
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
|
|
265
262
|
/**
|
|
266
263
|
* Whether a position-only input change (ids equal, same order) moved a leaf folded inside a badge
|
|
267
264
|
* of the rendered partition — the one move the mid-drag freeze must let through.
|
|
@@ -361,7 +358,12 @@ export function revealThreadPin(
|
|
|
361
358
|
Number.isFinite(parentEvent.zSplit) &&
|
|
362
359
|
parentEvent.zSplit <= zoomBounds.maxZoom
|
|
363
360
|
) {
|
|
364
|
-
|
|
361
|
+
const zoom = clamp(
|
|
362
|
+
parentEvent.zSplit * CLUSTER_SPLIT_ZOOM_FACTOR,
|
|
363
|
+
zoomBounds.minZoom,
|
|
364
|
+
zoomBounds.maxZoom
|
|
365
|
+
)
|
|
366
|
+
centerOnPointAtZoom(editor, point, zoom, duration)
|
|
365
367
|
return
|
|
366
368
|
}
|
|
367
369
|
}
|
|
@@ -384,12 +386,12 @@ export function zoomToClusterSplit(
|
|
|
384
386
|
) {
|
|
385
387
|
const event = table.events.find((e) => e.result.id === node.id)
|
|
386
388
|
if (!event || !Number.isFinite(event.zSplit)) return
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
const zoom = clamp(
|
|
390
|
+
event.zSplit * CLUSTER_SPLIT_ZOOM_FACTOR,
|
|
391
|
+
zoomBounds.minZoom,
|
|
392
|
+
zoomBounds.maxZoom
|
|
393
|
+
)
|
|
394
|
+
centerOnPointAtZoom(editor, node.centroid, zoom, CLUSTER_EXPAND_ZOOM_MS)
|
|
393
395
|
}
|
|
394
396
|
|
|
395
397
|
function findDirectParentEvent(table: ClusterTable, threadId: string): MergeEvent | undefined {
|
|
@@ -414,3 +416,7 @@ function centerOnPointAtZoom(
|
|
|
414
416
|
{ animation: { duration } }
|
|
415
417
|
)
|
|
416
418
|
}
|
|
419
|
+
|
|
420
|
+
function clamp(value: number, min: number, max: number): number {
|
|
421
|
+
return Math.max(min, Math.min(max, value))
|
|
422
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateText, JSONContent } from '@tiptap/core'
|
|
2
2
|
import { type CommentAuthor, createMentionExtension } from '@tldraw/mentions'
|
|
3
3
|
import { renderHtmlFromRichTextWithExtensions, TLRichText } from 'tldraw'
|
|
4
4
|
import { commentTipTapExtensions, isCommentEmpty } from '../ui/comment-extensions'
|
|
@@ -41,47 +41,35 @@ function hasMention(node: JSONContent): boolean {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const htmlCache = new WeakMap<TLRichText, string>()
|
|
44
|
-
const textCache = new WeakMap<TLRichText, string>()
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
|
-
* Render a body through the comment extension set,
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Render a comment body to HTML through the limited comment extension set (no headings), so a body
|
|
47
|
+
* always renders with comment formatting regardless of the host editor's rich-text config. Renders
|
|
48
|
+
* through tldraw's shared helper, so it gets the same empty-paragraph fix that keeps blank lines
|
|
49
|
+
* from collapsing. `resolveName` maps a member id to its current name for any @mentions.
|
|
50
50
|
*/
|
|
51
|
-
function
|
|
52
|
-
cache: WeakMap<TLRichText, string>,
|
|
51
|
+
export function renderCommentHtml(
|
|
53
52
|
richText: TLRichText,
|
|
54
|
-
resolveName
|
|
55
|
-
render: (doc: JSONContent, extensions: Extensions) => string
|
|
53
|
+
resolveName?: (id: string) => string | undefined
|
|
56
54
|
): string {
|
|
57
55
|
const mentions = hasMention(richText as JSONContent)
|
|
58
56
|
if (!mentions) {
|
|
59
|
-
const cached =
|
|
57
|
+
const cached = htmlCache.get(richText)
|
|
60
58
|
if (cached !== undefined) return cached
|
|
61
59
|
}
|
|
62
60
|
const extensions = mentions
|
|
63
61
|
? [...commentTipTapExtensions, createMentionExtension({ resolveName })]
|
|
64
62
|
: commentTipTapExtensions
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Render a comment body to HTML through the limited comment extension set (no headings), so a body
|
|
72
|
-
* always renders with comment formatting regardless of the host editor's rich-text config. Renders
|
|
73
|
-
* through tldraw's shared helper, so it gets the same empty-paragraph fix that keeps blank lines
|
|
74
|
-
* from collapsing. `resolveName` maps a member id to its current name for any @mentions.
|
|
75
|
-
*/
|
|
76
|
-
export function renderCommentHtml(
|
|
77
|
-
richText: TLRichText,
|
|
78
|
-
resolveName?: (id: string) => string | undefined
|
|
79
|
-
): string {
|
|
80
|
-
return renderWithCommentExtensions(htmlCache, richText, resolveName, (doc, extensions) =>
|
|
81
|
-
renderHtmlFromRichTextWithExtensions(doc as TLRichText, extensions)
|
|
63
|
+
const html = renderHtmlFromRichTextWithExtensions(
|
|
64
|
+
demoteHeadings(richText as JSONContent) as TLRichText,
|
|
65
|
+
extensions
|
|
82
66
|
)
|
|
67
|
+
if (!mentions) htmlCache.set(richText, html)
|
|
68
|
+
return html
|
|
83
69
|
}
|
|
84
70
|
|
|
71
|
+
const textCache = new WeakMap<TLRichText, string>()
|
|
72
|
+
|
|
85
73
|
/**
|
|
86
74
|
* Flatten a comment body to plaintext through the limited comment extension set — paragraphs and
|
|
87
75
|
* list items separated by newlines. Used for previews (e.g. the sidebar) where formatting is dropped.
|
|
@@ -92,7 +80,17 @@ export function renderCommentPlaintext(
|
|
|
92
80
|
resolveName?: (id: string) => string | undefined
|
|
93
81
|
): string {
|
|
94
82
|
if (isCommentEmpty(richText)) return ''
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
const mentions = hasMention(richText as JSONContent)
|
|
84
|
+
if (!mentions) {
|
|
85
|
+
const cached = textCache.get(richText)
|
|
86
|
+
if (cached !== undefined) return cached
|
|
87
|
+
}
|
|
88
|
+
const extensions = mentions
|
|
89
|
+
? [...commentTipTapExtensions, createMentionExtension({ resolveName })]
|
|
90
|
+
: commentTipTapExtensions
|
|
91
|
+
const text = generateText(demoteHeadings(richText as JSONContent), extensions, {
|
|
92
|
+
blockSeparator: '\n',
|
|
93
|
+
})
|
|
94
|
+
if (!mentions) textCache.set(richText, text)
|
|
95
|
+
return text
|
|
98
96
|
}
|
|
@@ -33,12 +33,6 @@ export function getCommentRecord(editor: Editor, id: string): TLCommentRecord |
|
|
|
33
33
|
return undefined
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** Read one comment thread by id, or `undefined` if the id isn't a present thread. @internal */
|
|
37
|
-
export function getCommentThread(editor: Editor, id: string): TLCommentThread | undefined {
|
|
38
|
-
const record = getCommentRecord(editor, id)
|
|
39
|
-
return record?.typeName === 'comment-thread' ? record : undefined
|
|
40
|
-
}
|
|
41
|
-
|
|
42
36
|
/**
|
|
43
37
|
* Every comment thread in the store, **including soft-deleted and emptied ones** awaiting the
|
|
44
38
|
* server's prune, which nothing renders. For the set the UI shows, use {@link getLiveCommentThreads}.
|
|
@@ -47,7 +41,8 @@ export function getCommentThread(editor: Editor, id: string): TLCommentThread |
|
|
|
47
41
|
* @public
|
|
48
42
|
*/
|
|
49
43
|
export function getCommentThreads(editor: Editor): TLCommentThread[] {
|
|
50
|
-
|
|
44
|
+
const typeName = 'comment-thread' as TLRecord['typeName']
|
|
45
|
+
return editor.store.query.records(typeName).get() as unknown as TLCommentThread[]
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
/**
|
|
@@ -58,7 +53,8 @@ export function getCommentThreads(editor: Editor): TLCommentThread[] {
|
|
|
58
53
|
* @public
|
|
59
54
|
*/
|
|
60
55
|
export function getComments(editor: Editor): TLComment[] {
|
|
61
|
-
|
|
56
|
+
const typeName = 'comment' as TLRecord['typeName']
|
|
57
|
+
return editor.store.query.records(typeName).get() as unknown as TLComment[]
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
/**
|
|
@@ -89,12 +85,6 @@ export function getLiveCommentThreads(editor: Editor): TLCommentThread[] {
|
|
|
89
85
|
|
|
90
86
|
/** All comment reactions currently in the store (non-reactive; wrap in `useValue` to react). @public */
|
|
91
87
|
export function getCommentReactions(editor: Editor): TLCommentReaction[] {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
function queryCommentRecords<T extends TLCommentRecord>(
|
|
96
|
-
editor: Editor,
|
|
97
|
-
typeName: T['typeName']
|
|
98
|
-
): T[] {
|
|
99
|
-
return editor.store.query.records(typeName as TLRecord['typeName']).get() as unknown as T[]
|
|
88
|
+
const typeName = 'comment-reaction' as TLRecord['typeName']
|
|
89
|
+
return editor.store.query.records(typeName).get() as unknown as TLCommentReaction[]
|
|
100
90
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
useClusterModel,
|
|
12
12
|
zoomToClusterSplit,
|
|
13
13
|
} from './cluster-model'
|
|
14
|
-
import { getCommentRecord
|
|
14
|
+
import { getCommentRecord } from './comment-store'
|
|
15
15
|
import { type CommentingContext } from './context'
|
|
16
16
|
import { useCommentThreads } from './hooks'
|
|
17
17
|
import { useCommentingEnabled } from './license'
|
|
@@ -172,36 +172,37 @@ function CanvasCommentsLayer(props: CommentingContext) {
|
|
|
172
172
|
const record = getCommentRecord(editor, id)
|
|
173
173
|
if (!record) return null
|
|
174
174
|
const thread =
|
|
175
|
-
record.typeName === 'comment' ?
|
|
175
|
+
record.typeName === 'comment' ? getCommentRecord(editor, record.threadId) : record
|
|
176
176
|
return thread?.typeName === 'comment-thread' ? thread : null
|
|
177
177
|
},
|
|
178
178
|
[editor]
|
|
179
179
|
)
|
|
180
180
|
|
|
181
|
-
//
|
|
182
|
-
// folded into a badge
|
|
183
|
-
const revealAndOpenThread = useCallback(
|
|
184
|
-
(thread: TLCommentThread, duration?: number) => {
|
|
185
|
-
revealThreadPin(editor, thread, clusterModel.table, clusterZoomBounds, options, duration)
|
|
186
|
-
openThreadId.set(editor, thread.id)
|
|
187
|
-
},
|
|
188
|
-
[clusterModel.table, clusterZoomBounds, editor, options]
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
// Serve a pending reveal request. Also unhides pins: the popover opens on the layer that hiding
|
|
192
|
-
// withholds.
|
|
181
|
+
// Serve a pending reveal request, zooming to the first cluster split that reveals the pin if it's
|
|
182
|
+
// folded into a badge. Also unhides pins: the popover opens on the layer that hiding withholds.
|
|
193
183
|
useEffect(() => {
|
|
194
184
|
if (!requestedRevealThread) return
|
|
195
185
|
revealThreadRequest.set(editor, null)
|
|
196
186
|
commentsHidden.set(editor, false)
|
|
197
|
-
|
|
198
|
-
|
|
187
|
+
revealThreadPin(editor, requestedRevealThread, clusterModel.table, clusterZoomBounds, options)
|
|
188
|
+
openThreadId.set(editor, requestedRevealThread.id)
|
|
189
|
+
}, [requestedRevealThread, clusterModel.table, clusterZoomBounds, editor, options])
|
|
199
190
|
|
|
200
191
|
// Picking a thread out of a cluster's hover preview. `openThreadId` alone would work, but would
|
|
201
192
|
// cut straight there from the badge — zoom in first, the same move the badge's own click makes.
|
|
202
193
|
const revealClusteredThread = useCallback(
|
|
203
|
-
(thread: TLCommentThread) =>
|
|
204
|
-
|
|
194
|
+
(thread: TLCommentThread) => {
|
|
195
|
+
revealThreadPin(
|
|
196
|
+
editor,
|
|
197
|
+
thread,
|
|
198
|
+
clusterModel.table,
|
|
199
|
+
clusterZoomBounds,
|
|
200
|
+
options,
|
|
201
|
+
CLUSTER_EXPAND_ZOOM_MS
|
|
202
|
+
)
|
|
203
|
+
openThreadId.set(editor, thread.id)
|
|
204
|
+
},
|
|
205
|
+
[clusterModel.table, clusterZoomBounds, editor, options]
|
|
205
206
|
)
|
|
206
207
|
|
|
207
208
|
const expandCluster = useCallback(
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { ReactNode, useCallback } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
EditorPortal,
|
|
4
|
+
TLComment,
|
|
5
|
+
TLCommentThread,
|
|
6
|
+
useEditor,
|
|
7
|
+
useTranslation,
|
|
8
|
+
useValue,
|
|
9
|
+
} from 'tldraw'
|
|
3
10
|
import { CommentListItemProps, CommentListItemRenderProps, CommentsList } from '../ui/comments-list'
|
|
4
11
|
import { UNKNOWN_COMMENT_AUTHOR } from './comment-render'
|
|
5
12
|
import { CommentsFilterMenu } from './comments-filter-menu'
|
|
6
13
|
import { CommentsVisibilityToggle } from './comments-visibility-toggle'
|
|
7
14
|
import { type CommentingContext } from './context'
|
|
8
|
-
import {
|
|
15
|
+
import { useComments, useCommentThreads } from './hooks'
|
|
9
16
|
import { useCommentingEnabled } from './license'
|
|
10
17
|
import { useCommentingOptions } from './options'
|
|
11
18
|
import { richTextToPlaintext } from './rich-text'
|
|
@@ -46,7 +53,7 @@ export function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {
|
|
|
46
53
|
const commentingEnabled = useCommentingEnabled()
|
|
47
54
|
const msg = useTranslation()
|
|
48
55
|
const threads = useCommentThreads(editor)
|
|
49
|
-
const
|
|
56
|
+
const comments = useComments(editor)
|
|
50
57
|
const currentPageId = useValue('page id', () => editor.getCurrentPageId(), [editor])
|
|
51
58
|
const open = useValue('sidebar open', () => commentsSidebarOpen.get(editor), [editor])
|
|
52
59
|
const openId = useValue('open thread', () => openThreadId.get(editor), [editor])
|
|
@@ -59,6 +66,14 @@ export function CanvasCommentsSidebar(props: CanvasCommentsSidebarProps) {
|
|
|
59
66
|
|
|
60
67
|
if (!commentingEnabled || !open) return null
|
|
61
68
|
|
|
69
|
+
// Group comments by thread (they arrive oldest-first, so [0] is each thread's first comment).
|
|
70
|
+
const byThread = new Map<string, TLComment[]>()
|
|
71
|
+
for (const comment of comments) {
|
|
72
|
+
const list = byThread.get(comment.threadId) ?? []
|
|
73
|
+
list.push(comment)
|
|
74
|
+
byThread.set(comment.threadId, list)
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
// Page scoping is treated as scoping, not a filter: an empty page reads "no comments yet",
|
|
63
78
|
// while a list emptied by the toggles below reads "nothing matches your filters".
|
|
64
79
|
const pageThreads = threads.filter(
|
package/src/canvas/hooks.ts
CHANGED
|
@@ -30,7 +30,7 @@ export function useCommentThreads(editor: Editor): TLCommentThread[] {
|
|
|
30
30
|
*/
|
|
31
31
|
const commentsByThread = new WeakCache<Editor, Computed<Map<TLCommentThreadId, TLComment[]>>>()
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/** Exported for tests; use {@link useThreadComments} to consume. @internal */
|
|
34
34
|
export function getCommentsByThread(editor: Editor) {
|
|
35
35
|
return commentsByThread.get(editor, () =>
|
|
36
36
|
computed('comments by thread', (prev) => {
|
|
@@ -33,7 +33,6 @@ import { openThreadId } from './state'
|
|
|
33
33
|
import { ThreadPreview, useMarkerPreview } from './thread-preview'
|
|
34
34
|
import {
|
|
35
35
|
anchorPagePoint,
|
|
36
|
-
anchorViewportPoint,
|
|
37
36
|
commentTargetShapeAt,
|
|
38
37
|
impreciseShapePinInset,
|
|
39
38
|
isBoxInInflatedViewport,
|
|
@@ -41,7 +40,6 @@ import {
|
|
|
41
40
|
REGION_PIN_CORNER,
|
|
42
41
|
regionAnchorPinCorner,
|
|
43
42
|
regionPinPoint,
|
|
44
|
-
regionWithPinAt,
|
|
45
43
|
shapeAnchorAt,
|
|
46
44
|
} from './thread-state'
|
|
47
45
|
import { POPOVER_OFFSET, ThreadPopover, ThreadView } from './thread-view'
|
|
@@ -109,7 +107,7 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
109
107
|
// A region resizes from its corners — every corner but the pin's own, which the pin owns.
|
|
110
108
|
const resizeHandles = useMemo(
|
|
111
109
|
() => REGION_CORNERS.filter((c) => c.x !== pinCorner.x || c.y !== pinCorner.y),
|
|
112
|
-
[pinCorner
|
|
110
|
+
[pinCorner]
|
|
113
111
|
)
|
|
114
112
|
const dragRef = useRef<{
|
|
115
113
|
startX: number
|
|
@@ -167,8 +165,13 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
167
165
|
'pin point',
|
|
168
166
|
() => {
|
|
169
167
|
if (thread.pageId !== editor.getCurrentPageId()) return null
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
168
|
+
const pagePoint = anchorPagePoint(editor, thread.anchor)
|
|
169
|
+
if (!pagePoint) return null
|
|
170
|
+
const viewportPoint = editor.pageToViewport(pagePoint)
|
|
171
|
+
const inset = impreciseShapePinInset(editor, thread.anchor)
|
|
172
|
+
const point = inset
|
|
173
|
+
? { x: viewportPoint.x + inset.x, y: viewportPoint.y + inset.y }
|
|
174
|
+
: viewportPoint
|
|
172
175
|
// Off-screen pins (plus a pre-mount margin) unmount rather than re-render every camera frame. A
|
|
173
176
|
// region thread stays mounted while any part of its box is on screen, since the box renders here too.
|
|
174
177
|
if (!exemptFromCull) {
|
|
@@ -184,9 +187,6 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
184
187
|
)
|
|
185
188
|
if (!point) return null
|
|
186
189
|
|
|
187
|
-
const toggleOpen = () =>
|
|
188
|
-
openThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)
|
|
189
|
-
|
|
190
190
|
const PinContent = options.components.PinContent
|
|
191
191
|
const threadAuthor = resolveAuthor(thread.createdBy)
|
|
192
192
|
const pinContent = PinContent ? (
|
|
@@ -247,28 +247,28 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
247
247
|
editor.setHintingShapes(hit ? [hit.id] : [])
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
//
|
|
251
|
-
|
|
250
|
+
// A cancelled pointer (touch gesture takeover, browser interruption) aborts the drag outright:
|
|
251
|
+
// no re-anchor commit, no click-toggle — the pin snaps back and the hint clears.
|
|
252
|
+
const cancelDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {
|
|
252
253
|
const drag = dragRef.current
|
|
253
254
|
dragRef.current = null
|
|
254
255
|
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
|
255
256
|
e.currentTarget.releasePointerCapture(e.pointerId)
|
|
256
257
|
}
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
// A cancelled pointer (touch gesture takeover, browser interruption) aborts the drag outright:
|
|
260
|
-
// no re-anchor commit, no click-toggle — the pin snaps back and the hint clears.
|
|
261
|
-
const cancelDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {
|
|
262
|
-
if (!takeDrag(e)) return
|
|
258
|
+
if (!drag) return
|
|
263
259
|
setDragPagePoint(null)
|
|
264
260
|
editor.setHintingShapes([])
|
|
265
261
|
}
|
|
266
262
|
const endDrag = (e: ReactPointerEvent<HTMLButtonElement>) => {
|
|
267
|
-
const drag =
|
|
263
|
+
const drag = dragRef.current
|
|
264
|
+
dragRef.current = null
|
|
265
|
+
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
|
266
|
+
e.currentTarget.releasePointerCapture(e.pointerId)
|
|
267
|
+
}
|
|
268
268
|
if (!drag) return
|
|
269
269
|
editor.setHintingShapes([])
|
|
270
270
|
if (!drag.moved) {
|
|
271
|
-
|
|
271
|
+
openThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)
|
|
272
272
|
return
|
|
273
273
|
}
|
|
274
274
|
const cursorPage = editor.screenToPage({ x: e.clientX, y: e.clientY })
|
|
@@ -276,7 +276,12 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
276
276
|
setDragPagePoint(null)
|
|
277
277
|
let anchor: TLCommentThread['anchor']
|
|
278
278
|
if (thread.anchor.type === 'region') {
|
|
279
|
-
|
|
279
|
+
// Translate so the pin (the region's pin corner) lands at the drop; size unchanged.
|
|
280
|
+
anchor = {
|
|
281
|
+
...thread.anchor,
|
|
282
|
+
x: pagePoint.x - pinCorner.x * thread.anchor.w,
|
|
283
|
+
y: pagePoint.y - pinCorner.y * thread.anchor.h,
|
|
284
|
+
}
|
|
280
285
|
} else {
|
|
281
286
|
const hit = commentTargetShapeAt(editor, pagePoint)
|
|
282
287
|
anchor = hit
|
|
@@ -311,7 +316,11 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
311
316
|
const regionAnchor = thread.anchor.type === 'region' ? thread.anchor : undefined
|
|
312
317
|
const movedRegion =
|
|
313
318
|
regionAnchor && dragPagePoint
|
|
314
|
-
?
|
|
319
|
+
? {
|
|
320
|
+
...regionAnchor,
|
|
321
|
+
x: dragPagePoint.x - pinCorner.x * regionAnchor.w,
|
|
322
|
+
y: dragPagePoint.y - pinCorner.y * regionAnchor.h,
|
|
323
|
+
}
|
|
315
324
|
: regionAnchor
|
|
316
325
|
const regionBoxBounds = resizeBounds ?? movedRegion
|
|
317
326
|
const commitResize = (bounds: BoxModel) => {
|
|
@@ -365,7 +374,8 @@ export const ThreadPin = memo(function ThreadPin({
|
|
|
365
374
|
// from a drag), so only take keyboard-synthesised clicks here — those report
|
|
366
375
|
// `detail === 0` — or the thread would toggle twice per mouse click.
|
|
367
376
|
onClick={(e) => {
|
|
368
|
-
if (e.detail
|
|
377
|
+
if (e.detail !== 0) return
|
|
378
|
+
openThreadId.set(editor, openThreadId.get(editor) === thread.id ? null : thread.id)
|
|
369
379
|
}}
|
|
370
380
|
onPointerEnter={previewHandlers.onPointerEnter}
|
|
371
381
|
onPointerLeave={previewHandlers.onPointerLeave}
|