@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
|
@@ -15,7 +15,7 @@ import { useCommentingOptions } from './options'
|
|
|
15
15
|
import { pinStackKey } from './pin-stacking'
|
|
16
16
|
import { openStackId, openThreadId } from './state'
|
|
17
17
|
import { ThreadPreview, useMarkerPreview } from './thread-preview'
|
|
18
|
-
import { anchorPagePoint,
|
|
18
|
+
import { anchorPagePoint, impreciseShapePinInset } from './thread-state'
|
|
19
19
|
import {
|
|
20
20
|
POPOVER_OFFSET,
|
|
21
21
|
ThreadPopover,
|
|
@@ -73,7 +73,11 @@ export const ThreadStackPin = memo(function ThreadStackPin({
|
|
|
73
73
|
// The badge hangs off its anchor point bottom-left like a pin, and applies the same imprecise-shape
|
|
74
74
|
// inset the pins it stands in for would (see ThreadPin) — otherwise the marker would snap from tucked
|
|
75
75
|
// inside the shape to the raw corner the moment a second comment turns a pin into a stack.
|
|
76
|
-
|
|
76
|
+
const pagePoint = anchorPagePoint(editor, first.anchor)
|
|
77
|
+
if (!pagePoint) return null
|
|
78
|
+
const viewportPoint = editor.pageToViewport(pagePoint)
|
|
79
|
+
const inset = impreciseShapePinInset(editor, first.anchor)
|
|
80
|
+
return inset ? { x: viewportPoint.x + inset.x, y: viewportPoint.y + inset.y } : viewportPoint
|
|
77
81
|
},
|
|
78
82
|
[editor, threads]
|
|
79
83
|
)
|
|
@@ -128,7 +132,7 @@ export const ThreadStackPin = memo(function ThreadStackPin({
|
|
|
128
132
|
// The expanded thread gains a header that pushes its first comment down from where the hover preview
|
|
129
133
|
// showed it. When that thread is the list's first, lift the whole list so its "You" holds position
|
|
130
134
|
// across hover -> open. Only the first entry — lifting can't also hold a lower thread's neighbours.
|
|
131
|
-
const liftForHeader = threads[0]
|
|
135
|
+
const liftForHeader = threads[0]?.id === openId ? 42 : 0
|
|
132
136
|
|
|
133
137
|
return (
|
|
134
138
|
<>
|
|
@@ -101,16 +101,6 @@ export function regionPinPoint(region: BoxModel, corner: VecLike = REGION_PIN_CO
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/** The inverse of {@link regionPinPoint}: a region translated so its pin corner lands on `pinPage`;
|
|
105
|
-
* size unchanged. */
|
|
106
|
-
export function regionWithPinAt(
|
|
107
|
-
region: Extract<TLCommentAnchor, { type: 'region' }>,
|
|
108
|
-
pinCorner: VecLike,
|
|
109
|
-
pinPage: VecLike
|
|
110
|
-
): Extract<TLCommentAnchor, { type: 'region' }> {
|
|
111
|
-
return { ...region, x: pinPage.x - pinCorner.x * region.w, y: pinPage.y - pinCorner.y * region.h }
|
|
112
|
-
}
|
|
113
|
-
|
|
114
104
|
/**
|
|
115
105
|
* Where a thread's pin sits on the page, for each anchor kind. Null hides the pin. Imprecise shape
|
|
116
106
|
* anchors use {@link CommentingOptions.impreciseShapeAnchor} rather than the stored `x`/`y`.
|
|
@@ -143,22 +133,6 @@ export function anchorPagePoint(
|
|
|
143
133
|
}
|
|
144
134
|
}
|
|
145
135
|
|
|
146
|
-
/**
|
|
147
|
-
* Where a thread's marker is drawn, in viewport space: {@link anchorPagePoint} projected through
|
|
148
|
-
* the camera, plus the imprecise-shape inset. Null when the anchor resolves to no point.
|
|
149
|
-
* @internal
|
|
150
|
-
*/
|
|
151
|
-
export function anchorViewportPoint(
|
|
152
|
-
editor: Editor,
|
|
153
|
-
anchor: TLCommentAnchor
|
|
154
|
-
): { x: number; y: number } | null {
|
|
155
|
-
const pagePoint = anchorPagePoint(editor, anchor)
|
|
156
|
-
if (!pagePoint) return null
|
|
157
|
-
const viewportPoint = editor.pageToViewport(pagePoint)
|
|
158
|
-
const inset = impreciseShapePinInset(editor, anchor)
|
|
159
|
-
return inset ? { x: viewportPoint.x + inset.x, y: viewportPoint.y + inset.y } : viewportPoint
|
|
160
|
-
}
|
|
161
|
-
|
|
162
136
|
/**
|
|
163
137
|
* The shape a comment placed at a page point should anchor to, or undefined for empty canvas.
|
|
164
138
|
*
|
|
@@ -53,68 +53,6 @@ import { openThreadId } from './state'
|
|
|
53
53
|
|
|
54
54
|
const stop = (e: { stopPropagation(): void }) => e.stopPropagation()
|
|
55
55
|
|
|
56
|
-
/** The "⋯" dropdown used for both a comment's and the thread's actions. */
|
|
57
|
-
function MoreOptionsMenu({
|
|
58
|
-
id,
|
|
59
|
-
moreFor,
|
|
60
|
-
children,
|
|
61
|
-
}: {
|
|
62
|
-
id: string
|
|
63
|
-
/** The comment whose ⋯ button this is, so `startEdit` can find it again to return focus. */
|
|
64
|
-
moreFor?: string
|
|
65
|
-
children: ReactNode
|
|
66
|
-
}) {
|
|
67
|
-
const msg = useTranslation()
|
|
68
|
-
return (
|
|
69
|
-
<TldrawUiDropdownMenuRoot id={id}>
|
|
70
|
-
<TldrawUiDropdownMenuTrigger>
|
|
71
|
-
<TldrawUiButton
|
|
72
|
-
type="icon"
|
|
73
|
-
tooltip={msg('comments.more-options')}
|
|
74
|
-
title={msg('comments.more-options')}
|
|
75
|
-
className="tlui-cmt-thread__action"
|
|
76
|
-
data-cmt-more-for={moreFor}
|
|
77
|
-
>
|
|
78
|
-
<TldrawUiIcon icon="dots-vertical" label={msg('comments.more-options')} small />
|
|
79
|
-
</TldrawUiButton>
|
|
80
|
-
</TldrawUiDropdownMenuTrigger>
|
|
81
|
-
<TldrawUiDropdownMenuContent
|
|
82
|
-
className="tlui-cmt-menu"
|
|
83
|
-
side="bottom"
|
|
84
|
-
align="start"
|
|
85
|
-
alignOffset={0}
|
|
86
|
-
sideOffset={4}
|
|
87
|
-
>
|
|
88
|
-
<TldrawUiDropdownMenuGroup>{children}</TldrawUiDropdownMenuGroup>
|
|
89
|
-
</TldrawUiDropdownMenuContent>
|
|
90
|
-
</TldrawUiDropdownMenuRoot>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function MenuItem({
|
|
95
|
-
label,
|
|
96
|
-
danger,
|
|
97
|
-
noClose,
|
|
98
|
-
onClick,
|
|
99
|
-
}: {
|
|
100
|
-
label: string
|
|
101
|
-
danger?: boolean
|
|
102
|
-
noClose?: boolean
|
|
103
|
-
onClick(): void
|
|
104
|
-
}) {
|
|
105
|
-
return (
|
|
106
|
-
<TldrawUiDropdownMenuItem noClose={noClose}>
|
|
107
|
-
<button
|
|
108
|
-
type="button"
|
|
109
|
-
className={danger ? 'tlui-cmt-menu-item tlui-cmt-menu-item--danger' : 'tlui-cmt-menu-item'}
|
|
110
|
-
onClick={onClick}
|
|
111
|
-
>
|
|
112
|
-
<span>{label}</span>
|
|
113
|
-
</button>
|
|
114
|
-
</TldrawUiDropdownMenuItem>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
56
|
/**
|
|
119
57
|
* A name-only view of an author resolver, for the mention/rich-text paths. Stable identity, so
|
|
120
58
|
* `CommentBody`'s memoized render doesn't recompute on every render of its host.
|
|
@@ -414,7 +352,9 @@ export const ThreadView = memo(function ThreadView({
|
|
|
414
352
|
// No `currentUserId` check: unlike a resolve, a delete stamps nothing on the record, so who may
|
|
415
353
|
// make it is `canModifyComment`'s call alone (which withholds it from an unidentified viewer by
|
|
416
354
|
// default).
|
|
417
|
-
const removeThread = () =>
|
|
355
|
+
const removeThread = () => {
|
|
356
|
+
deleteThread(editor, thread)
|
|
357
|
+
}
|
|
418
358
|
|
|
419
359
|
const ThreadActions = options.components.ThreadActions
|
|
420
360
|
// The host's URL for this thread. Its presence is what puts "copy link" in the header menu.
|
|
@@ -488,21 +428,55 @@ export const ThreadView = memo(function ThreadView({
|
|
|
488
428
|
canComment && (
|
|
489
429
|
<>
|
|
490
430
|
{(permissions?.edit || permissions?.delete) && (
|
|
491
|
-
<
|
|
492
|
-
|
|
493
|
-
<
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
431
|
+
<TldrawUiDropdownMenuRoot id={`comment-actions-${comment.id}`}>
|
|
432
|
+
<TldrawUiDropdownMenuTrigger>
|
|
433
|
+
<TldrawUiButton
|
|
434
|
+
type="icon"
|
|
435
|
+
tooltip={msg('comments.more-options')}
|
|
436
|
+
title={msg('comments.more-options')}
|
|
437
|
+
className="tlui-cmt-thread__action"
|
|
438
|
+
data-cmt-more-for={comment.id}
|
|
439
|
+
>
|
|
440
|
+
<TldrawUiIcon
|
|
441
|
+
icon="dots-vertical"
|
|
442
|
+
label={msg('comments.more-options')}
|
|
443
|
+
small
|
|
444
|
+
/>
|
|
445
|
+
</TldrawUiButton>
|
|
446
|
+
</TldrawUiDropdownMenuTrigger>
|
|
447
|
+
<TldrawUiDropdownMenuContent
|
|
448
|
+
className="tlui-cmt-menu"
|
|
449
|
+
side="bottom"
|
|
450
|
+
align="start"
|
|
451
|
+
alignOffset={0}
|
|
452
|
+
sideOffset={4}
|
|
453
|
+
>
|
|
454
|
+
<TldrawUiDropdownMenuGroup>
|
|
455
|
+
{permissions?.edit && (
|
|
456
|
+
<TldrawUiDropdownMenuItem>
|
|
457
|
+
<button
|
|
458
|
+
type="button"
|
|
459
|
+
className="tlui-cmt-menu-item"
|
|
460
|
+
onClick={() => startEdit(comment, { fromMoreMenu: true })}
|
|
461
|
+
>
|
|
462
|
+
<span>{msg('comments.edit')}</span>
|
|
463
|
+
</button>
|
|
464
|
+
</TldrawUiDropdownMenuItem>
|
|
465
|
+
)}
|
|
466
|
+
{permissions?.delete && (
|
|
467
|
+
<TldrawUiDropdownMenuItem>
|
|
468
|
+
<button
|
|
469
|
+
type="button"
|
|
470
|
+
className="tlui-cmt-menu-item tlui-cmt-menu-item--danger"
|
|
471
|
+
onClick={() => deleteComment(editor, comment)}
|
|
472
|
+
>
|
|
473
|
+
<span>{msg('action.delete')}</span>
|
|
474
|
+
</button>
|
|
475
|
+
</TldrawUiDropdownMenuItem>
|
|
476
|
+
)}
|
|
477
|
+
</TldrawUiDropdownMenuGroup>
|
|
478
|
+
</TldrawUiDropdownMenuContent>
|
|
479
|
+
</TldrawUiDropdownMenuRoot>
|
|
506
480
|
)}
|
|
507
481
|
{/* Last so react is always the rightmost pill. */}
|
|
508
482
|
<CommentReactionPicker comment={comment} currentUserId={currentUserId} />
|
|
@@ -521,21 +495,49 @@ export const ThreadView = memo(function ThreadView({
|
|
|
521
495
|
{/* Host verbs — assign, link a ticket — sit ahead of the built-in actions. */}
|
|
522
496
|
{ThreadActions && <ThreadActions thread={thread} comments={comments} />}
|
|
523
497
|
{(threadHref !== undefined || canDeleteThread) && (
|
|
524
|
-
<
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
498
|
+
<TldrawUiDropdownMenuRoot id={`comment-thread-actions-${thread.id}`}>
|
|
499
|
+
<TldrawUiDropdownMenuTrigger>
|
|
500
|
+
<TldrawUiButton
|
|
501
|
+
type="icon"
|
|
502
|
+
tooltip={msg('comments.more-options')}
|
|
503
|
+
title={msg('comments.more-options')}
|
|
504
|
+
className="tlui-cmt-thread__action"
|
|
505
|
+
>
|
|
506
|
+
<TldrawUiIcon icon="dots-vertical" label={msg('comments.more-options')} small />
|
|
507
|
+
</TldrawUiButton>
|
|
508
|
+
</TldrawUiDropdownMenuTrigger>
|
|
509
|
+
<TldrawUiDropdownMenuContent
|
|
510
|
+
className="tlui-cmt-menu"
|
|
511
|
+
side="bottom"
|
|
512
|
+
align="start"
|
|
513
|
+
alignOffset={0}
|
|
514
|
+
sideOffset={4}
|
|
515
|
+
>
|
|
516
|
+
<TldrawUiDropdownMenuGroup>
|
|
517
|
+
{/* A link is a read affordance: offered to anyone who can see the thread,
|
|
518
|
+
including a viewer who can't comment. `noClose` keeps the menu up so the
|
|
519
|
+
item can confirm the copy in place. */}
|
|
520
|
+
{threadHref !== undefined && (
|
|
521
|
+
<TldrawUiDropdownMenuItem noClose>
|
|
522
|
+
<button type="button" className="tlui-cmt-menu-item" onClick={copyThreadLink}>
|
|
523
|
+
<span>{msg(linkCopied ? 'comments.link-copied' : 'comments.copy-link')}</span>
|
|
524
|
+
</button>
|
|
525
|
+
</TldrawUiDropdownMenuItem>
|
|
526
|
+
)}
|
|
527
|
+
{canDeleteThread && (
|
|
528
|
+
<TldrawUiDropdownMenuItem>
|
|
529
|
+
<button
|
|
530
|
+
type="button"
|
|
531
|
+
className="tlui-cmt-menu-item tlui-cmt-menu-item--danger"
|
|
532
|
+
onClick={removeThread}
|
|
533
|
+
>
|
|
534
|
+
<span>{msg('comments.delete')}</span>
|
|
535
|
+
</button>
|
|
536
|
+
</TldrawUiDropdownMenuItem>
|
|
537
|
+
)}
|
|
538
|
+
</TldrawUiDropdownMenuGroup>
|
|
539
|
+
</TldrawUiDropdownMenuContent>
|
|
540
|
+
</TldrawUiDropdownMenuRoot>
|
|
539
541
|
)}
|
|
540
542
|
{canComment && currentUserId && (
|
|
541
543
|
<TldrawUiButton
|
|
@@ -9,6 +9,16 @@ import type {
|
|
|
9
9
|
LeafScreenOffsets,
|
|
10
10
|
} from './types'
|
|
11
11
|
|
|
12
|
+
interface ResolvedClusterOptions {
|
|
13
|
+
Tc: number
|
|
14
|
+
Tu: number
|
|
15
|
+
eps: number
|
|
16
|
+
Dmax: number
|
|
17
|
+
minZoom: number
|
|
18
|
+
maxZoom: number
|
|
19
|
+
maxSplitZoom: number
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
/** @internal */
|
|
13
23
|
export function computeClusterTable(
|
|
14
24
|
leaves: readonly LeafInput[],
|
|
@@ -25,13 +35,20 @@ export function computeClusterTable(
|
|
|
25
35
|
return { events: [], leaves: leafNodes }
|
|
26
36
|
}
|
|
27
37
|
|
|
28
|
-
const raw = cappedReplay(leaves, edges, opts, screenOffsets)
|
|
29
|
-
const
|
|
38
|
+
const raw = cappedReplay(leaves, edges, { Tc: opts.Tc, Dmax: opts.Dmax }, screenOffsets)
|
|
39
|
+
const contracted = contract(raw, opts.eps)
|
|
40
|
+
const events = finalize(contracted, {
|
|
41
|
+
Tc: opts.Tc,
|
|
42
|
+
Tu: opts.Tu,
|
|
43
|
+
minZoom: opts.minZoom,
|
|
44
|
+
maxZoom: opts.maxZoom,
|
|
45
|
+
maxSplitZoom: opts.maxSplitZoom,
|
|
46
|
+
})
|
|
30
47
|
|
|
31
48
|
return { events, leaves: leafNodes }
|
|
32
49
|
}
|
|
33
50
|
|
|
34
|
-
function resolveOptions(options: ClusterOptions):
|
|
51
|
+
function resolveOptions(options: ClusterOptions): ResolvedClusterOptions {
|
|
35
52
|
const Tc = options.Tc ?? 22
|
|
36
53
|
const Tu = options.Tu ?? 1.2 * Tc
|
|
37
54
|
const eps = options.eps ?? 0.7
|
package/src/clustering/replay.ts
CHANGED
|
@@ -166,6 +166,8 @@ class ClusterState {
|
|
|
166
166
|
private readonly centroidY: Float64Array
|
|
167
167
|
private readonly counts: Int32Array
|
|
168
168
|
private readonly nodes: ClusterNode[]
|
|
169
|
+
private readonly memberLists: string[][]
|
|
170
|
+
private readonly minMemberIds: string[]
|
|
169
171
|
// Per-cluster sums of member render offsets (screen px), maintained like the centroid sums.
|
|
170
172
|
// Null when no offsets were passed — offsetDelta() then answers null unconditionally, which
|
|
171
173
|
// routes every pricing call down the offset-unaware path.
|
|
@@ -183,6 +185,8 @@ class ClusterState {
|
|
|
183
185
|
this.centroidY = new Float64Array(n)
|
|
184
186
|
this.counts = new Int32Array(n)
|
|
185
187
|
this.nodes = new Array(n)
|
|
188
|
+
this.memberLists = new Array(n)
|
|
189
|
+
this.minMemberIds = new Array(n)
|
|
186
190
|
|
|
187
191
|
if (screenOffsets !== undefined && screenOffsets.size > 0) {
|
|
188
192
|
this.offsetX = new Float64Array(n)
|
|
@@ -209,6 +213,8 @@ class ClusterState {
|
|
|
209
213
|
this.centroidX[i] = leaf.point.x
|
|
210
214
|
this.centroidY[i] = leaf.point.y
|
|
211
215
|
this.counts[i] = 1
|
|
216
|
+
this.memberLists[i] = [leaf.id]
|
|
217
|
+
this.minMemberIds[i] = leaf.id
|
|
212
218
|
this.nodes[i] = {
|
|
213
219
|
id: leaf.id,
|
|
214
220
|
centroid: { x: leaf.point.x, y: leaf.point.y },
|
|
@@ -231,7 +237,6 @@ class ClusterState {
|
|
|
231
237
|
return root
|
|
232
238
|
}
|
|
233
239
|
|
|
234
|
-
/** Allocation-free: this is the hot path when no offsets are passed. */
|
|
235
240
|
centroidDistance(aRoot: number, bRoot: number): number {
|
|
236
241
|
return Math.hypot(
|
|
237
242
|
this.centroidX[aRoot] - this.centroidX[bRoot],
|
|
@@ -266,12 +271,12 @@ class ClusterState {
|
|
|
266
271
|
}
|
|
267
272
|
|
|
268
273
|
merge(aRoot: number, bRoot: number, z: number): RawMergeEvent {
|
|
269
|
-
const leftRoot = this.
|
|
274
|
+
const leftRoot = this.minMemberIds[aRoot] < this.minMemberIds[bRoot] ? aRoot : bRoot
|
|
270
275
|
const rightRoot = leftRoot === aRoot ? bRoot : aRoot
|
|
271
276
|
const left = this.nodes[leftRoot]
|
|
272
277
|
const right = this.nodes[rightRoot]
|
|
273
278
|
const count = this.counts[leftRoot] + this.counts[rightRoot]
|
|
274
|
-
const members = mergeSortedMembers(
|
|
279
|
+
const members = mergeSortedMembers(this.memberLists[leftRoot], this.memberLists[rightRoot])
|
|
275
280
|
|
|
276
281
|
const minX = Math.min(this.minX[leftRoot], this.minX[rightRoot])
|
|
277
282
|
const minY = Math.min(this.minY[leftRoot], this.minY[rightRoot])
|
|
@@ -303,6 +308,8 @@ class ClusterState {
|
|
|
303
308
|
this.centroidY[leftRoot] = centroidY
|
|
304
309
|
this.counts[leftRoot] = count
|
|
305
310
|
this.nodes[leftRoot] = result
|
|
311
|
+
this.memberLists[leftRoot] = members
|
|
312
|
+
this.minMemberIds[leftRoot] = members[0]
|
|
306
313
|
if (this.offsetX !== null && this.offsetY !== null) {
|
|
307
314
|
this.offsetX[leftRoot] += this.offsetX[rightRoot]
|
|
308
315
|
this.offsetY[leftRoot] += this.offsetY[rightRoot]
|
|
@@ -336,11 +343,10 @@ interface HeapEntry {
|
|
|
336
343
|
|
|
337
344
|
class EdgeMaxHeap {
|
|
338
345
|
private readonly items: HeapEntry[] = []
|
|
339
|
-
// Per-edge (lo, hi) id pair for the z tie-break, precomputed once so comparisons
|
|
340
|
-
// nothing.
|
|
341
|
-
//
|
|
342
|
-
//
|
|
343
|
-
// millions of short-lived tuples.
|
|
346
|
+
// Per-edge normalized (lo, hi) id pair for the z tie-break, precomputed once so comparisons
|
|
347
|
+
// allocate nothing. With coincident anchors every edge prices to the same z (+Infinity), so
|
|
348
|
+
// the tie-break runs on nearly every comparison of a rebuild — allocating the pair there
|
|
349
|
+
// churned millions of short-lived tuples.
|
|
344
350
|
private readonly loIds: string[]
|
|
345
351
|
private readonly hiIds: string[]
|
|
346
352
|
|
|
@@ -349,8 +355,15 @@ class EdgeMaxHeap {
|
|
|
349
355
|
this.loIds = new Array(n)
|
|
350
356
|
this.hiIds = new Array(n)
|
|
351
357
|
for (let i = 0; i < n; i++) {
|
|
352
|
-
|
|
353
|
-
|
|
358
|
+
const aId = leaves[edges[i].a].id
|
|
359
|
+
const bId = leaves[edges[i].b].id
|
|
360
|
+
if (aId < bId) {
|
|
361
|
+
this.loIds[i] = aId
|
|
362
|
+
this.hiIds[i] = bId
|
|
363
|
+
} else {
|
|
364
|
+
this.loIds[i] = bId
|
|
365
|
+
this.hiIds[i] = aId
|
|
366
|
+
}
|
|
354
367
|
}
|
|
355
368
|
}
|
|
356
369
|
|
|
@@ -70,7 +70,7 @@ class ClusterRuntimeImpl implements ClusterRuntime {
|
|
|
70
70
|
private resolvedCache: { version: number; map: Map<string, ClusterNode> } | null = null
|
|
71
71
|
|
|
72
72
|
constructor(private readonly table: ClusterTable) {
|
|
73
|
-
this.
|
|
73
|
+
this.resetVisible()
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
getSuppressedCount(): number {
|
|
@@ -84,7 +84,10 @@ class ClusterRuntimeImpl implements ClusterRuntime {
|
|
|
84
84
|
seed(zoom: number): void {
|
|
85
85
|
validateZoom(zoom)
|
|
86
86
|
this.k = seedCount(this.table.events, zoom)
|
|
87
|
-
this.
|
|
87
|
+
this.suppressed.clear()
|
|
88
|
+
this.detached.clear()
|
|
89
|
+
this.patched.clear()
|
|
90
|
+
this.resetVisible()
|
|
88
91
|
for (let i = 0; i < this.k; i++) {
|
|
89
92
|
applyEvent(this.visible, this.table.events[i])
|
|
90
93
|
}
|
|
@@ -111,7 +114,10 @@ class ClusterRuntimeImpl implements ClusterRuntime {
|
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
this.k = k
|
|
114
|
-
this.
|
|
117
|
+
this.suppressed.clear()
|
|
118
|
+
this.detached.clear()
|
|
119
|
+
this.patched.clear()
|
|
120
|
+
this.resetVisible()
|
|
115
121
|
for (let i = 0; i < k; i++) {
|
|
116
122
|
const event = events[i]
|
|
117
123
|
if (zoom > event.zMerge && !wasMergedTogether(event.result.members, ownerByMember)) {
|
|
@@ -216,8 +222,8 @@ class ClusterRuntimeImpl implements ClusterRuntime {
|
|
|
216
222
|
this.patched.set(id, null)
|
|
217
223
|
}
|
|
218
224
|
const patch = (node: ClusterNode) => {
|
|
225
|
+
if (node.members.length === 1 || !node.members.some((m) => this.detached.has(m))) return
|
|
219
226
|
const members = node.members.filter((m) => !this.detached.has(m))
|
|
220
|
-
if (members.length === node.members.length) return
|
|
221
227
|
if (members.length === 0) {
|
|
222
228
|
this.patched.set(node.id, null)
|
|
223
229
|
} else if (members.length === 1) {
|
|
@@ -244,11 +250,11 @@ class ClusterRuntimeImpl implements ClusterRuntime {
|
|
|
244
250
|
}
|
|
245
251
|
}
|
|
246
252
|
|
|
247
|
-
private
|
|
248
|
-
this.
|
|
249
|
-
this.
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
private resetVisible() {
|
|
254
|
+
this.visible = new Map()
|
|
255
|
+
for (const leaf of this.table.leaves) {
|
|
256
|
+
this.visible.set(leaf.id, leaf)
|
|
257
|
+
}
|
|
252
258
|
}
|
|
253
259
|
}
|
|
254
260
|
|
|
@@ -114,7 +114,8 @@ export function CommentComposer({
|
|
|
114
114
|
if (!expandedRef.current) setExpanded(true)
|
|
115
115
|
return
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const field = wrap.parentElement
|
|
118
|
+
const send = field ? field.querySelector<HTMLElement>('.tlui-cmt-send') : null
|
|
118
119
|
const input = wrap.querySelector('.tlui-cmt-input')
|
|
119
120
|
if (!send || !input) return
|
|
120
121
|
mirror.innerHTML = input.innerHTML
|
|
@@ -262,7 +263,8 @@ export function CommentComposer({
|
|
|
262
263
|
// space beside/below a short line) focuses the editor rather than only the text glyphs being
|
|
263
264
|
// clickable. The input (caret placement) and the send button keep their own click handling.
|
|
264
265
|
const focusEditorFromField = (e: ReactMouseEvent<HTMLDivElement>) => {
|
|
265
|
-
|
|
266
|
+
const target = e.target as HTMLElement
|
|
267
|
+
if (target.closest('.tlui-cmt-input') || target.closest('.tlui-cmt-send')) return
|
|
266
268
|
e.preventDefault()
|
|
267
269
|
editor?.commands.focus('end')
|
|
268
270
|
}
|
package/src/ui/comments.css
CHANGED
|
@@ -383,6 +383,35 @@
|
|
|
383
383
|
user-select: none;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/* thread */
|
|
387
|
+
.tlui-cmt-thread {
|
|
388
|
+
display: flex;
|
|
389
|
+
flex-direction: column;
|
|
390
|
+
width: 300px;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.tlui-cmt-thread__head {
|
|
394
|
+
display: flex;
|
|
395
|
+
align-items: center;
|
|
396
|
+
gap: 8px;
|
|
397
|
+
font-size: 12px;
|
|
398
|
+
font-weight: 600;
|
|
399
|
+
color: var(--tl-color-text-3);
|
|
400
|
+
text-transform: uppercase;
|
|
401
|
+
letter-spacing: 0.04em;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.tlui-cmt-badge {
|
|
405
|
+
font-size: 10px;
|
|
406
|
+
font-weight: 600;
|
|
407
|
+
text-transform: none;
|
|
408
|
+
letter-spacing: 0;
|
|
409
|
+
color: #fff;
|
|
410
|
+
background: var(--tl-color-muted-1);
|
|
411
|
+
padding: 1px 6px;
|
|
412
|
+
border-radius: 999px;
|
|
413
|
+
}
|
|
414
|
+
|
|
386
415
|
/* reactions */
|
|
387
416
|
.tlui-cmt-reactions {
|
|
388
417
|
display: flex;
|
|
@@ -619,6 +648,9 @@ button.tlui-cmt-reaction--active:hover {
|
|
|
619
648
|
.tlui-button.tlui-cmt-thread__action:hover {
|
|
620
649
|
color: var(--tl-color-text-1);
|
|
621
650
|
}
|
|
651
|
+
.tlui-button.tlui-cmt-thread__action--danger:hover {
|
|
652
|
+
color: var(--tl-color-danger);
|
|
653
|
+
}
|
|
622
654
|
.tlui-cmt-thread__resolved {
|
|
623
655
|
margin: 4px 12px;
|
|
624
656
|
padding: 6px 10px;
|
package/src/ui/format-time.ts
CHANGED
|
@@ -8,20 +8,6 @@ const DIVISIONS = [
|
|
|
8
8
|
{ amount: Number.POSITIVE_INFINITY, unit: 'year' },
|
|
9
9
|
] as const
|
|
10
10
|
|
|
11
|
-
// Both formatters are cached per locale — comment cards re-render on every reply keystroke, and
|
|
12
|
-
// constructing an Intl formatter is far more expensive than formatting with one.
|
|
13
|
-
const relativeTimeFormatters = new Map<string, Intl.RelativeTimeFormat>()
|
|
14
|
-
const fullDateTimeFormatters = new Map<string, Intl.DateTimeFormat>()
|
|
15
|
-
|
|
16
|
-
function getCached<T>(cache: Map<string, T>, locale: string, create: () => T): T {
|
|
17
|
-
let formatter = cache.get(locale)
|
|
18
|
-
if (!formatter) {
|
|
19
|
-
formatter = create()
|
|
20
|
-
cache.set(locale, formatter)
|
|
21
|
-
}
|
|
22
|
-
return formatter
|
|
23
|
-
}
|
|
24
|
-
|
|
25
11
|
/**
|
|
26
12
|
* Format an ISO datetime as compact relative time ("2h ago", "yesterday", "last wk.").
|
|
27
13
|
* Locale-aware via Intl.RelativeTimeFormat.
|
|
@@ -31,11 +17,7 @@ export function formatRelativeTime(iso: string, locale = 'en'): string {
|
|
|
31
17
|
const then = new Date(iso).getTime()
|
|
32
18
|
if (Number.isNaN(then)) return ''
|
|
33
19
|
|
|
34
|
-
const rtf =
|
|
35
|
-
relativeTimeFormatters,
|
|
36
|
-
locale,
|
|
37
|
-
() => new Intl.RelativeTimeFormat(locale, { numeric: 'auto', style: 'narrow' })
|
|
38
|
-
)
|
|
20
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto', style: 'narrow' })
|
|
39
21
|
let duration = (then - Date.now()) / 1000
|
|
40
22
|
// Under a minute is just "now" — with second granularity the label visibly ticks while
|
|
41
23
|
// typing a reply (every keystroke re-renders the card).
|
|
@@ -51,6 +33,10 @@ export function formatRelativeTime(iso: string, locale = 'en'): string {
|
|
|
51
33
|
return ''
|
|
52
34
|
}
|
|
53
35
|
|
|
36
|
+
// Cached per locale — comment cards re-render on every reply keystroke, and constructing a
|
|
37
|
+
// DateTimeFormat is far more expensive than formatting with one.
|
|
38
|
+
const fullDateTimeFormatters = new Map<string, Intl.DateTimeFormat>()
|
|
39
|
+
|
|
54
40
|
/**
|
|
55
41
|
* Format an ISO datetime as a full date and time ("Tuesday, July 22, 2025 at 4:44 PM").
|
|
56
42
|
* Locale-aware via Intl.DateTimeFormat.
|
|
@@ -59,9 +45,10 @@ export function formatRelativeTime(iso: string, locale = 'en'): string {
|
|
|
59
45
|
export function formatFullDateTime(iso: string, locale = 'en'): string {
|
|
60
46
|
const date = new Date(iso)
|
|
61
47
|
if (Number.isNaN(date.getTime())) return ''
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
locale,
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
let formatter = fullDateTimeFormatters.get(locale)
|
|
49
|
+
if (!formatter) {
|
|
50
|
+
formatter = new Intl.DateTimeFormat(locale, { dateStyle: 'full', timeStyle: 'short' })
|
|
51
|
+
fullDateTimeFormatters.set(locale, formatter)
|
|
52
|
+
}
|
|
53
|
+
return formatter.format(date)
|
|
67
54
|
}
|
package/src/ui/reaction.tsx
CHANGED
|
@@ -108,16 +108,28 @@ export function DefaultReactionTooltipContent({ reactors }: { reactors: Reaction
|
|
|
108
108
|
const names = reactors.map((reactor) =>
|
|
109
109
|
reactor.you ? msg('comments.mention-you') : reactor.name
|
|
110
110
|
)
|
|
111
|
-
if (names.length === 0) return null
|
|
112
111
|
const [a, b, c] = names
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
switch (names.length) {
|
|
113
|
+
case 0:
|
|
114
|
+
return null
|
|
115
|
+
case 1:
|
|
116
|
+
return <>{msg('comments.reacted-1').replace('{a}', a)}</>
|
|
117
|
+
case 2:
|
|
118
|
+
return <>{msg('comments.reacted-2').replace('{a}', a).replace('{b}', b)}</>
|
|
119
|
+
case 3:
|
|
120
|
+
return <>{msg('comments.reacted-3').replace('{a}', a).replace('{b}', b).replace('{c}', c)}</>
|
|
121
|
+
default: {
|
|
122
|
+
const others = names.length - 3
|
|
123
|
+
const template = others === 1 ? 'comments.reacted-more-one' : 'comments.reacted-more'
|
|
124
|
+
return (
|
|
125
|
+
<>
|
|
126
|
+
{msg(template)
|
|
127
|
+
.replace('{a}', a)
|
|
128
|
+
.replace('{b}', b)
|
|
129
|
+
.replace('{c}', c)
|
|
130
|
+
.replace('{count}', String(others))}
|
|
131
|
+
</>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
123
135
|
}
|