@openartifactsai/editor-kit 0.0.0-stage → 0.23.0-rc.0
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +143 -2
- package/package.json +67 -4
- package/src/Announcer.d.ts +2 -0
- package/src/Announcer.js +8 -0
- package/src/FindBar.d.ts +31 -0
- package/src/FindBar.js +37 -0
- package/src/FoldToolbar.d.ts +58 -0
- package/src/FoldToolbar.js +438 -0
- package/src/PanelEdge.d.ts +20 -0
- package/src/PanelEdge.js +74 -0
- package/src/VideoShrinkNotice.d.ts +10 -0
- package/src/VideoShrinkNotice.js +81 -0
- package/src/WheelZoomItem.d.ts +12 -0
- package/src/WheelZoomItem.js +18 -0
- package/src/agent.d.ts +68 -0
- package/src/agent.js +113 -0
- package/src/announce.d.ts +21 -0
- package/src/announce.js +31 -0
- package/src/chrome.d.ts +208 -0
- package/src/chrome.js +148 -0
- package/src/clipboard.d.ts +19 -0
- package/src/clipboard.js +48 -0
- package/src/collab/CommentList.d.ts +32 -0
- package/src/collab/CommentList.js +165 -0
- package/src/collab/CommentViews.d.ts +131 -0
- package/src/collab/CommentViews.js +619 -0
- package/src/collab/HistoryViews.d.ts +38 -0
- package/src/collab/HistoryViews.js +103 -0
- package/src/collab/PresenceViews.d.ts +53 -0
- package/src/collab/PresenceViews.js +48 -0
- package/src/collab/cds/cds.d.ts +151 -0
- package/src/collab/cds/cds.js +231 -0
- package/src/collab/cds/comment-card.d.ts +113 -0
- package/src/collab/cds/comment-card.js +230 -0
- package/src/collab/cds/comment-composer.d.ts +35 -0
- package/src/collab/cds/comment-composer.js +125 -0
- package/src/collab/cds/comments-css.d.ts +2 -0
- package/src/collab/cds/comments-css.js +3 -0
- package/src/collab/cds/comments.css +504 -0
- package/src/collab/cds/edge-piles.d.ts +69 -0
- package/src/collab/cds/edge-piles.js +178 -0
- package/src/collab/cds/layer.d.ts +41 -0
- package/src/collab/cds/layer.js +144 -0
- package/src/collab/cds/markdown.d.ts +20 -0
- package/src/collab/cds/markdown.js +534 -0
- package/src/collab/cds/shield.d.ts +28 -0
- package/src/collab/cds/shield.js +114 -0
- package/src/collab/cds/time.d.ts +2 -0
- package/src/collab/cds/time.js +41 -0
- package/src/collab/collab.d.ts +102 -0
- package/src/collab/collab.js +121 -0
- package/src/collab/comments.d.ts +272 -0
- package/src/collab/comments.js +596 -0
- package/src/collab/history-wiring.d.ts +32 -0
- package/src/collab/history-wiring.js +53 -0
- package/src/collab/history.d.ts +59 -0
- package/src/collab/history.js +96 -0
- package/src/collab/mentions/mention-list.d.ts +63 -0
- package/src/collab/mentions/mention-list.js +257 -0
- package/src/collab/mentions.d.ts +112 -0
- package/src/collab/mentions.js +164 -0
- package/src/collab/peer-colors.d.ts +123 -0
- package/src/collab/peer-colors.js +273 -0
- package/src/collab/pins.d.ts +70 -0
- package/src/collab/pins.js +44 -0
- package/src/collab/presence.d.ts +92 -0
- package/src/collab/presence.js +158 -0
- package/src/design-systems.d.ts +46 -0
- package/src/design-systems.js +61 -0
- package/src/downloads.d.ts +31 -0
- package/src/downloads.js +46 -0
- package/src/file-drop.d.ts +33 -0
- package/src/file-drop.js +36 -0
- package/src/find.d.ts +64 -0
- package/src/find.js +147 -0
- package/src/follow.d.ts +141 -0
- package/src/follow.js +389 -0
- package/src/index.d.ts +32 -0
- package/src/index.js +32 -0
- package/src/keys.d.ts +18 -0
- package/src/keys.js +42 -0
- package/src/menu-fit.d.ts +12 -0
- package/src/menu-fit.js +9 -0
- package/src/merge.d.ts +23 -0
- package/src/merge.js +116 -0
- package/src/page-link.d.ts +33 -0
- package/src/page-link.js +75 -0
- package/src/project-sync.d.ts +161 -0
- package/src/project-sync.js +319 -0
- package/src/react.d.ts +20 -0
- package/src/react.js +20 -0
- package/src/read-retries.d.ts +55 -0
- package/src/read-retries.js +125 -0
- package/src/right-drag-pan.d.ts +128 -0
- package/src/right-drag-pan.js +253 -0
- package/src/roles.d.ts +39 -0
- package/src/roles.js +27 -0
- package/src/session.d.ts +56 -0
- package/src/session.js +57 -0
- package/src/shell.d.ts +60 -0
- package/src/shell.js +111 -0
- package/src/stash.d.ts +26 -0
- package/src/stash.js +69 -0
- package/src/styles.css +17 -0
- package/src/toolbar-fold.d.ts +106 -0
- package/src/toolbar-fold.js +130 -0
- package/src/video-shrink/index.d.ts +8 -0
- package/src/video-shrink/index.js +7 -0
- package/src/video-shrink/plan.d.ts +92 -0
- package/src/video-shrink/plan.js +133 -0
- package/src/video-shrink/protocol.d.ts +29 -0
- package/src/video-shrink/protocol.js +2 -0
- package/src/video-shrink/queue.d.ts +69 -0
- package/src/video-shrink/queue.js +287 -0
- package/src/video-shrink/worker.d.ts +8 -0
- package/src/video-shrink/worker.js +223 -0
- package/src/wheel-zoom.d.ts +14 -0
- package/src/wheel-zoom.js +48 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { isComposingKey } from '@openartifactsai/ui';
|
|
4
|
+
import { Avatar, Button, cn, Icon, Menu, MenuItems, MenuPopup, Tooltip } from "./cds/cds.js";
|
|
5
|
+
import { Actions, Comment, CommentCard, DeleteConfirm, EditField, MoreMenu, Replies, ReplyField, ResolveAction, useLayerMenu } from "./cds/comment-card.js";
|
|
6
|
+
import { CommentComposer as CdsComposer } from "./cds/comment-composer.js";
|
|
7
|
+
import {} from "./mentions/mention-list.js";
|
|
8
|
+
import { EdgePiles, edgePiles, stackPins } from "./cds/edge-piles.js";
|
|
9
|
+
import { CommentsLayer, InLayer } from "./cds/layer.js";
|
|
10
|
+
import { commentMarkdown } from "./cds/markdown.js";
|
|
11
|
+
import { commentTime } from "./cds/time.js";
|
|
12
|
+
import { openMessageCount, queuedNote, WAIT_FOR_STATUS_CHANGE } from "./comments.js";
|
|
13
|
+
import { ALL_COMMENTS_RIGHT } from "./CommentList.js";
|
|
14
|
+
import { draftedText } from "../agent.js";
|
|
15
|
+
import { AGENT_KEY, leadsWithAgent, mentionName, sentMentionNames } from "./mentions.js";
|
|
16
|
+
import { screenBox, toScreenPoint, toWorldPoint } from "./pins.js";
|
|
17
|
+
/** Pixels the pointer must travel before a press becomes a drag. */
|
|
18
|
+
const DRAG_THRESHOLD = 5;
|
|
19
|
+
/** A dragged area narrower or shorter than this is dropped. */
|
|
20
|
+
const AREA_MIN = 12;
|
|
21
|
+
export const COMMENT_TARGET = '#ae7303';
|
|
22
|
+
const BUBBLE_SVG = "<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><path d='M 2 26 L 2 14 A 12 12 0 1 1 14 26 Z' fill='#000' stroke='#fff' stroke-width='2'/></svg>";
|
|
23
|
+
export const COMMENT_CURSOR = `url("data:image/svg+xml,${BUBBLE_SVG.replace(/[ '<>#]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())}") 2 26, crosshair`;
|
|
24
|
+
/** Stops surface gestures from starting inside comment UI. */
|
|
25
|
+
const stop = (event) => event.stopPropagation();
|
|
26
|
+
/** A short "5m ago" style time. */
|
|
27
|
+
export function timeAgo(iso, now = Date.now()) {
|
|
28
|
+
const seconds = Math.max(0, (now - Date.parse(iso)) / 1000);
|
|
29
|
+
if (!Number.isFinite(seconds))
|
|
30
|
+
return '';
|
|
31
|
+
if (seconds < 60)
|
|
32
|
+
return 'just now';
|
|
33
|
+
if (seconds < 3600)
|
|
34
|
+
return `${Math.floor(seconds / 60)}m ago`;
|
|
35
|
+
if (seconds < 86400)
|
|
36
|
+
return `${Math.floor(seconds / 3600)}h ago`;
|
|
37
|
+
return new Date(iso).toLocaleDateString();
|
|
38
|
+
}
|
|
39
|
+
/** In comment mode: clicks place threads, drags draw areas. */
|
|
40
|
+
export function CommentCapture({ comments, enabled, panning = false, camera, anchorAt, areaAnchor, highlight, onHover, revision }) {
|
|
41
|
+
const on = comments.store((s) => s.on);
|
|
42
|
+
const open = comments.store((s) => s.draft !== null || Boolean(s.active));
|
|
43
|
+
const element = useRef(null);
|
|
44
|
+
const press = useRef(null);
|
|
45
|
+
const [area, setArea] = useState(null);
|
|
46
|
+
// The box under the pointer, in this layer's pixels (one pick per frame).
|
|
47
|
+
const [hover, setHover] = useState(null);
|
|
48
|
+
const hoverFrame = useRef(0);
|
|
49
|
+
/** Where the pointer rests (layer pixels), to pick again on `revision`. */
|
|
50
|
+
const resting = useRef(null);
|
|
51
|
+
const pickAgain = useRef(null);
|
|
52
|
+
useEffect(() => () => cancelAnimationFrame(hoverFrame.current), []);
|
|
53
|
+
const live = on && enabled;
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (live)
|
|
56
|
+
pickAgain.current?.();
|
|
57
|
+
}, [revision]);
|
|
58
|
+
// Escape during a drag drops the area (before the editor's own Escape).
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!area)
|
|
61
|
+
return;
|
|
62
|
+
const onKey = (event) => {
|
|
63
|
+
if (event.key !== 'Escape')
|
|
64
|
+
return;
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
press.current = null;
|
|
68
|
+
setArea(null);
|
|
69
|
+
};
|
|
70
|
+
window.addEventListener('keydown', onKey, true);
|
|
71
|
+
return () => window.removeEventListener('keydown', onKey, true);
|
|
72
|
+
}, [area !== null]);
|
|
73
|
+
// Leaving comment mode forgets the pointer.
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (live)
|
|
76
|
+
return;
|
|
77
|
+
resting.current = null;
|
|
78
|
+
setHover(null);
|
|
79
|
+
}, [live]);
|
|
80
|
+
if (!on || !enabled || !comments.canComment())
|
|
81
|
+
return null;
|
|
82
|
+
const local = (event) => {
|
|
83
|
+
const bounds = element.current.getBoundingClientRect();
|
|
84
|
+
return { x: event.clientX - bounds.left, y: event.clientY - bounds.top };
|
|
85
|
+
};
|
|
86
|
+
const onDown = (event) => {
|
|
87
|
+
if (event.button !== 0 || panning)
|
|
88
|
+
return;
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
press.current = local(event);
|
|
92
|
+
try {
|
|
93
|
+
element.current.setPointerCapture(event.pointerId);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Synthetic events carry no capturable pointer.
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const clearHover = () => {
|
|
100
|
+
cancelAnimationFrame(hoverFrame.current);
|
|
101
|
+
resting.current = null;
|
|
102
|
+
setHover(null);
|
|
103
|
+
onHover?.(null);
|
|
104
|
+
};
|
|
105
|
+
const trackHover = (point) => {
|
|
106
|
+
resting.current = point;
|
|
107
|
+
if (!highlight && !onHover)
|
|
108
|
+
return;
|
|
109
|
+
cancelAnimationFrame(hoverFrame.current);
|
|
110
|
+
hoverFrame.current = requestAnimationFrame(() => {
|
|
111
|
+
const cam = camera();
|
|
112
|
+
const anchor = anchorAt(toWorldPoint(cam, point));
|
|
113
|
+
onHover?.(anchor);
|
|
114
|
+
if (!highlight)
|
|
115
|
+
return;
|
|
116
|
+
const box = highlight(anchor);
|
|
117
|
+
const next = box ? { x: box.x * cam.zoom + cam.x, y: box.y * cam.zoom + cam.y, w: box.w * cam.zoom, h: box.h * cam.zoom } : null;
|
|
118
|
+
setHover((last) => (last && next && last.x === next.x && last.y === next.y && last.w === next.w && last.h === next.h ? last : next));
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
pickAgain.current = () => {
|
|
122
|
+
if (resting.current && !press.current)
|
|
123
|
+
trackHover(resting.current);
|
|
124
|
+
};
|
|
125
|
+
const cancelDrag = () => {
|
|
126
|
+
press.current = null;
|
|
127
|
+
setArea(null);
|
|
128
|
+
};
|
|
129
|
+
const onMove = (event) => {
|
|
130
|
+
const start = press.current;
|
|
131
|
+
if (!start) {
|
|
132
|
+
if (panning || event.buttons)
|
|
133
|
+
clearHover();
|
|
134
|
+
else
|
|
135
|
+
trackHover(local(event));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// The button came up out of sight (another window took the release): the drag is over.
|
|
139
|
+
if ((event.buttons & 1) === 0) {
|
|
140
|
+
cancelDrag();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const point = local(event);
|
|
144
|
+
// Hidden while pressed; what lies under the pointer stays as it was (the release picks it).
|
|
145
|
+
if (hover)
|
|
146
|
+
setHover(null);
|
|
147
|
+
if (!area && Math.hypot(point.x - start.x, point.y - start.y) < DRAG_THRESHOLD)
|
|
148
|
+
return;
|
|
149
|
+
setArea({ x: Math.min(start.x, point.x), y: Math.min(start.y, point.y), w: Math.abs(point.x - start.x), h: Math.abs(point.y - start.y) });
|
|
150
|
+
};
|
|
151
|
+
const onUp = (event) => {
|
|
152
|
+
const start = press.current;
|
|
153
|
+
press.current = null;
|
|
154
|
+
if (!start)
|
|
155
|
+
return;
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
const cam = camera();
|
|
158
|
+
const point = local(event);
|
|
159
|
+
const state = comments.store.getState();
|
|
160
|
+
// Decided from the press and the release, not the drawn area: the last move may not have rendered yet.
|
|
161
|
+
const w = Math.abs(point.x - start.x);
|
|
162
|
+
const h = Math.abs(point.y - start.y);
|
|
163
|
+
if (area || Math.hypot(w, h) >= DRAG_THRESHOLD) {
|
|
164
|
+
setArea(null);
|
|
165
|
+
// Too small to be an area: dropped.
|
|
166
|
+
if (w < AREA_MIN || h < AREA_MIN)
|
|
167
|
+
return;
|
|
168
|
+
state.setDraft(areaAnchor(toWorldPoint(cam, start), toWorldPoint(cam, point)));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
state.setDraft(anchorAt(toWorldPoint(cam, point)));
|
|
172
|
+
};
|
|
173
|
+
return (_jsxs("div", { ref: element, "data-comment-capture": "", "aria-label": "Comment mode: click to comment, drag to comment on an area", className: "absolute inset-0 z-[2]", style: { cursor: panning ? 'grab' : COMMENT_CURSOR }, onPointerDown: onDown, onPointerMove: onMove, onPointerUp: onUp, onPointerCancel: cancelDrag, onPointerLeave: clearHover,
|
|
174
|
+
// The camera moves under a still pointer: the next move picks again.
|
|
175
|
+
onWheel: clearHover, onDoubleClick: stop, onContextMenu: (event) => event.preventDefault(), children: [hover && !area && !open && !panning ? (_jsx("div", { "data-comment-hover": "", className: "pointer-events-none absolute rounded", style: { left: hover.x, top: hover.y, width: hover.w, height: hover.h, border: `1.5px solid ${COMMENT_TARGET}` } })) : null, area && press.current ? _jsx(AreaOutline, { area: area, start: press.current }) : null] }));
|
|
176
|
+
}
|
|
177
|
+
function AreaOutline({ area, start }) {
|
|
178
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { "data-comment-area": "", className: "pointer-events-none absolute", style: { left: area.x, top: area.y, width: area.w, height: area.h, border: `1px dashed ${COMMENT_TARGET}` } }), _jsx("div", { className: "pointer-events-none absolute rounded-full", style: { left: start.x - 5, top: start.y - 5, width: 10, height: 10, background: COMMENT_TARGET } })] }));
|
|
179
|
+
}
|
|
180
|
+
/* -------------------------------------------------------------------------- */
|
|
181
|
+
/* Placing pins and cards */
|
|
182
|
+
/* -------------------------------------------------------------------------- */
|
|
183
|
+
const PIN = 36;
|
|
184
|
+
const PIN_GAP = 4;
|
|
185
|
+
const EDGE = 8;
|
|
186
|
+
/** A thread's card and the composer: 330px wide, 6px from the pin. */
|
|
187
|
+
const CARD_WIDTH = 330;
|
|
188
|
+
const CARD_GAP = 6;
|
|
189
|
+
/** The least room a card keeps beside its pin, however near the edge the pin is. */
|
|
190
|
+
const CARD_MIN_ROOM = 48;
|
|
191
|
+
export function pinBox(point, viewport) {
|
|
192
|
+
const below = viewport.height - (point.y + PIN_GAP);
|
|
193
|
+
const above = point.y - PIN_GAP;
|
|
194
|
+
const flip = below < 320 && above > below && (above >= 240 || (below < 240 && above >= 48));
|
|
195
|
+
const left = Math.min(Math.max(point.x, 0), Math.max(0, viewport.width - (PIN + EDGE)));
|
|
196
|
+
return { left, top: flip ? point.y - (PIN + PIN_GAP) : point.y + PIN_GAP, flip };
|
|
197
|
+
}
|
|
198
|
+
const cardCap = (height) => Math.max(320, Math.round(height * 0.6));
|
|
199
|
+
/** How tall the card beside `pin` may be: the cap, or the room on the pin's side, whichever is less. */
|
|
200
|
+
function cardMaxHeight(pin, viewport) {
|
|
201
|
+
const top = EDGE;
|
|
202
|
+
const bottom = viewport.height - EDGE;
|
|
203
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
204
|
+
const room = pin.flip
|
|
205
|
+
? clamp(pin.top + PIN + 2, Math.min(bottom, top + CARD_MIN_ROOM), bottom) - top
|
|
206
|
+
: bottom - clamp(pin.top - 2, top, Math.max(top, bottom - CARD_MIN_ROOM));
|
|
207
|
+
return Math.min(cardCap(viewport.height), Math.max(0, room));
|
|
208
|
+
}
|
|
209
|
+
export function CommentPopover({ pin, corner, viewport, width: wanted = CARD_WIDTH, onEscape, children }) {
|
|
210
|
+
const ref = useRef(null);
|
|
211
|
+
const [height, setHeight] = useState(0);
|
|
212
|
+
useLayoutEffect(() => {
|
|
213
|
+
const el = ref.current;
|
|
214
|
+
if (!el)
|
|
215
|
+
return;
|
|
216
|
+
setHeight(el.offsetHeight);
|
|
217
|
+
const observer = new ResizeObserver(() => setHeight(el.offsetHeight));
|
|
218
|
+
observer.observe(el);
|
|
219
|
+
return () => observer.disconnect();
|
|
220
|
+
}, []);
|
|
221
|
+
const width = Math.max(0, Math.min(wanted, viewport.width - 2 * EDGE));
|
|
222
|
+
let left;
|
|
223
|
+
let top;
|
|
224
|
+
let maxHeight;
|
|
225
|
+
if (corner || !pin) {
|
|
226
|
+
const at = corner ?? { x: EDGE, y: EDGE };
|
|
227
|
+
left = Math.max(EDGE, Math.min(at.x, viewport.width - EDGE - width));
|
|
228
|
+
top = Math.max(EDGE, Math.min(at.y, viewport.height - EDGE - height));
|
|
229
|
+
if (typeof children === 'function')
|
|
230
|
+
maxHeight = Math.min(cardCap(viewport.height), Math.max(CARD_MIN_ROOM, viewport.height - EDGE - Math.max(EDGE, at.y)));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
left = pin.left + PIN + CARD_GAP;
|
|
234
|
+
if (left + width > viewport.width - EDGE) {
|
|
235
|
+
const before = pin.left - CARD_GAP - width;
|
|
236
|
+
left = before >= EDGE ? before : Math.max(EDGE, viewport.width - EDGE - width);
|
|
237
|
+
}
|
|
238
|
+
top = pin.flip ? pin.top + PIN + 2 - height : pin.top - 2;
|
|
239
|
+
top = Math.max(EDGE, Math.min(top, viewport.height - EDGE - height));
|
|
240
|
+
if (typeof children === 'function')
|
|
241
|
+
maxHeight = cardMaxHeight(pin, viewport);
|
|
242
|
+
}
|
|
243
|
+
// Unmeasured, it is see-through rather than hidden: a hidden textarea can't take focus.
|
|
244
|
+
const style = {
|
|
245
|
+
position: 'absolute',
|
|
246
|
+
left,
|
|
247
|
+
top,
|
|
248
|
+
width,
|
|
249
|
+
pointerEvents: 'auto',
|
|
250
|
+
...(maxHeight === undefined ? {} : { maxHeight, '--comment-card-room': `${maxHeight}px`, display: 'flex', flexDirection: 'column' }),
|
|
251
|
+
...(height ? {} : { opacity: 0, pointerEvents: 'none' }),
|
|
252
|
+
};
|
|
253
|
+
return (_jsx("div", { ref: ref, style: style, "data-comment-card": "", onKeyDown: (event) => {
|
|
254
|
+
if (event.key !== 'Escape' || event.defaultPrevented || isComposingKey(event.nativeEvent))
|
|
255
|
+
return;
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
onEscape();
|
|
258
|
+
}, children: typeof children === 'function' ? children(maxHeight) : children }));
|
|
259
|
+
}
|
|
260
|
+
const PIN_CLASS = 'cds-reset absolute flex items-center justify-center rounded-full rounded-tl-none border-0 p-0 cursor-[var(--cds-cursor-interactive)] outline-none focus-visible:outline-hidden focus-visible:shadow-focus';
|
|
261
|
+
function PinButton({ pin, avatar, draft = false, parked = false, label, title, expanded, faded = false, screenTransform = false, ...handlers }) {
|
|
262
|
+
const { pinId, ...events } = handlers;
|
|
263
|
+
const style = {
|
|
264
|
+
...(screenTransform
|
|
265
|
+
? { left: 0, top: 0, transform: `translate3d(${pin.left}px, ${pin.top}px, 0)` }
|
|
266
|
+
: { left: pin.left, top: pin.top }),
|
|
267
|
+
width: PIN,
|
|
268
|
+
height: PIN,
|
|
269
|
+
pointerEvents: draft ? 'none' : 'auto',
|
|
270
|
+
touchAction: 'none',
|
|
271
|
+
...(pin.flip ? { borderRadius: '9999px 9999px 9999px 0' } : {}),
|
|
272
|
+
...(faded ? { opacity: 0.7 } : {}),
|
|
273
|
+
};
|
|
274
|
+
return (_jsx("button", { type: "button", "data-comment-pin": pinId, "data-comment-parked": parked ? '' : undefined, "aria-label": label, title: title, "aria-expanded": expanded, tabIndex: draft ? -1 : undefined, className: cn(PIN_CLASS, draft || parked ? 'bg-fill-accent' : 'bg-surface-2 shadow-panel-sm'), style: style, ...events, children: _jsx("span", { className: "flex rounded-full bg-surface-1", children: avatar }) }));
|
|
275
|
+
}
|
|
276
|
+
/** A message's author as the cards name them. */
|
|
277
|
+
function authorName(message, agent) {
|
|
278
|
+
if (message.author.kind === 'agent')
|
|
279
|
+
return message.author.name || agent.name;
|
|
280
|
+
return message.author.name || 'Someone';
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Who a box's `@` can name: the agent (when the viewer may send to it), who has the artifact and who is here (asked for
|
|
284
|
+
* at the first `@`), then whoever the threads name. `picked`: whom a message being edited already names.
|
|
285
|
+
*/
|
|
286
|
+
export function useMentionsSpec(comments, agent, sendable, picked) {
|
|
287
|
+
const self = comments.store((s) => s.self);
|
|
288
|
+
// The list draws from these: a change redraws it.
|
|
289
|
+
comments.store((s) => s.known);
|
|
290
|
+
comments.store((s) => s.threads);
|
|
291
|
+
return {
|
|
292
|
+
agentName: agent.name,
|
|
293
|
+
agentListed: sendable,
|
|
294
|
+
people: () => comments.mentionPeople(),
|
|
295
|
+
self: self ?? { name: comments.viewerName() },
|
|
296
|
+
onFirstUse: () => comments.followPeople(),
|
|
297
|
+
avatar: (option) => option.kind === 'agent' ? _jsx(Avatar, { name: option.label, variant: "agent", className: "size-[14px]" }) : _jsx(Avatar, { name: option.label, className: "size-[14px] text-[7px]" }),
|
|
298
|
+
...(picked ? { picked: picked.filter((key) => key !== AGENT_KEY).map((key) => ({ key, name: mentionName(key) })) } : {}),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* A message's text, with the `@names` it was sent to drawn as mentions; one a person sent to the agent without naming it
|
|
303
|
+
* leads with an `@agent` tag.
|
|
304
|
+
*/
|
|
305
|
+
function messageText(message, agent, flat = false) {
|
|
306
|
+
const text = commentMarkdown(message.text, { flat, mentions: sentMentionNames(message.to, agent.name) });
|
|
307
|
+
if (!leadsWithAgent(message, agent.name))
|
|
308
|
+
return text;
|
|
309
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { "data-sent-to-agent": "", className: "font-medium text-accent", children: `@${agent.name}` }), " ", text] }));
|
|
310
|
+
}
|
|
311
|
+
function threadAvatar(thread, agent) {
|
|
312
|
+
const first = thread.messages[0];
|
|
313
|
+
if (!first)
|
|
314
|
+
return _jsx(Avatar, { name: "?", size: "sm" });
|
|
315
|
+
return _jsx(Avatar, { name: authorName(first, agent), variant: first.author.kind === 'agent' ? 'agent' : 'default', size: "sm" });
|
|
316
|
+
}
|
|
317
|
+
export function CommentPins({ comments, camera, viewport, place, highlight, anchorAt, movable, onMove, agent, revision, screenTransform = false, piles = true, insets }) {
|
|
318
|
+
const canMove = movable !== false && Boolean(anchorAt || onMove);
|
|
319
|
+
const movableThread = (thread) => canMove && (typeof movable !== 'function' || movable(thread));
|
|
320
|
+
const available = comments.store((s) => s.available);
|
|
321
|
+
const threads = comments.store((s) => s.threads);
|
|
322
|
+
const active = comments.store((s) => s.active);
|
|
323
|
+
const draft = comments.store((s) => s.draft);
|
|
324
|
+
const parked = comments.store((s) => s.parked);
|
|
325
|
+
const on = comments.store((s) => s.on);
|
|
326
|
+
const showResolved = comments.store((s) => s.showResolved);
|
|
327
|
+
const listOpen = comments.store((s) => s.listOpen);
|
|
328
|
+
// A dragged pin's offset from its place.
|
|
329
|
+
const [drag, setDrag] = useState(null);
|
|
330
|
+
const placementCamera = screenTransform ? null : camera;
|
|
331
|
+
const anchored = useMemo(() => {
|
|
332
|
+
if (!available)
|
|
333
|
+
return [];
|
|
334
|
+
const out = [];
|
|
335
|
+
for (const thread of threads) {
|
|
336
|
+
if (thread.messages.length === 0)
|
|
337
|
+
continue;
|
|
338
|
+
if (thread.status !== 'open' && !showResolved && thread.id !== active)
|
|
339
|
+
continue;
|
|
340
|
+
// On the whole artifact: no pin (its card opens by the list, or where the type puts it).
|
|
341
|
+
if (comments.isWhole(thread))
|
|
342
|
+
continue;
|
|
343
|
+
const anchor = comments.anchorOf(thread);
|
|
344
|
+
const at = place(anchor);
|
|
345
|
+
if (at)
|
|
346
|
+
out.push({ key: thread.id, thread, anchor, state: at.state, world: at.world });
|
|
347
|
+
}
|
|
348
|
+
if (draft !== null && !comments.isWholeAnchor(draft)) {
|
|
349
|
+
const at = place(draft);
|
|
350
|
+
if (at)
|
|
351
|
+
out.push({ key: 'draft', thread: null, anchor: draft, state: at.state, world: at.world });
|
|
352
|
+
}
|
|
353
|
+
if (parked !== null) {
|
|
354
|
+
const at = place(parked.anchor);
|
|
355
|
+
if (at)
|
|
356
|
+
out.push({ key: 'parked', thread: null, anchor: parked.anchor, state: at.state, world: at.world });
|
|
357
|
+
}
|
|
358
|
+
return out;
|
|
359
|
+
}, [available, threads, active, draft, parked, showResolved, place, revision, comments, placementCamera]);
|
|
360
|
+
const focusKey = draft !== null ? 'draft' : active;
|
|
361
|
+
const focusedAnchor = anchored.find((p) => p.key === focusKey)?.anchor;
|
|
362
|
+
const cachedHighlight = useMemo(() => screenTransform && focusedAnchor !== undefined ? highlight?.(focusedAnchor) : null, [screenTransform, focusedAnchor, highlight, place, revision]);
|
|
363
|
+
if (!available)
|
|
364
|
+
return null;
|
|
365
|
+
if (!on && !active && draft === null && anchored.length === 0)
|
|
366
|
+
return null;
|
|
367
|
+
const placed = anchored.map((p) => ({ ...p, screen: toScreenPoint(camera, p.world) }));
|
|
368
|
+
const focus = placed.find((p) => p.key === focusKey);
|
|
369
|
+
const waiting = placed.find((p) => p.key === 'parked');
|
|
370
|
+
const lit = screenTransform ? cachedHighlight : focus && highlight ? highlight(focus.anchor) : null;
|
|
371
|
+
const pinned = placed.filter((p) => p.thread);
|
|
372
|
+
const pileSet = piles
|
|
373
|
+
? edgePiles({
|
|
374
|
+
points: pinned.map((p) => ({ id: p.key, x: p.screen.x, y: p.screen.y })),
|
|
375
|
+
openId: active,
|
|
376
|
+
box: { left: 0, top: 0, width: viewport.width, height: viewport.height },
|
|
377
|
+
top: 0,
|
|
378
|
+
floor: insets?.top ?? 0,
|
|
379
|
+
foot: insets?.bottom ? insets.bottom + 8 : 0,
|
|
380
|
+
reserveRight: listOpen ? ALL_COMMENTS_RIGHT : 0,
|
|
381
|
+
})
|
|
382
|
+
: null;
|
|
383
|
+
const shown = pinned.filter((p) => !pileSet?.piled.has(p.key)).map((p) => ({ ...p, box: pinBox(p.screen, viewport) }));
|
|
384
|
+
const stacked = stackPins(shown.map((p) => ({ id: p.key, x: p.box.left, y: p.box.top, w: PIN })), viewport.width, PIN);
|
|
385
|
+
const select = (id) => comments.store.getState().setActive(id);
|
|
386
|
+
const open = focus?.thread ? focus : undefined;
|
|
387
|
+
return (_jsxs(_Fragment, { children: [lit ? (
|
|
388
|
+
// An area is drawn as it was dragged (dashed); an element, a board or a note gets the hover ring.
|
|
389
|
+
_jsx("div", { "data-comment-target": "", className: cn('pointer-events-none absolute', !lit.area && 'rounded'), style: { ...screenBox(camera, lit), transform: lit.rotate ? `rotate(${lit.rotate}deg)` : undefined, border: lit.area ? `1px dashed ${COMMENT_TARGET}` : `1.5px solid ${COMMENT_TARGET}` } })) : null, _jsxs(CommentsLayer, { className: "pointer-events-none absolute inset-0 z-[3]", mark: "data-comment-layer", onEscape: () => {
|
|
390
|
+
const state = comments.store.getState();
|
|
391
|
+
if (state.draft !== null || state.active) {
|
|
392
|
+
state.setDraft(null);
|
|
393
|
+
state.setActive(null);
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}, children: [shown.map((p) => {
|
|
398
|
+
const thread = p.thread;
|
|
399
|
+
const dragging = drag?.id === thread.id ? drag : null;
|
|
400
|
+
const box = { ...p.box, left: p.box.left + (stacked.get(p.key) ?? 0) + (dragging?.x ?? 0), top: p.box.top + (dragging?.y ?? 0) };
|
|
401
|
+
return (_jsx(ThreadPin, { comments: comments, thread: thread, box: box, avatar: threadAvatar(thread, agent), expanded: active === thread.id, detached: p.state === 'detached', onDrag: (delta) => setDrag(delta ? { id: thread.id, ...delta } : null), movable: movableThread(thread), screenTransform: screenTransform, onDrop: (delta) => {
|
|
402
|
+
const screen = { x: p.screen.x + delta.x, y: p.screen.y + delta.y };
|
|
403
|
+
if (onMove)
|
|
404
|
+
onMove(thread.id, screen);
|
|
405
|
+
else if (anchorAt)
|
|
406
|
+
void comments.move(thread.id, anchorAt(toWorldPoint(camera, screen)));
|
|
407
|
+
} }, p.key));
|
|
408
|
+
}), pileSet ? (_jsx("div", { style: { display: 'contents', pointerEvents: 'auto' }, children: _jsx(EdgePiles, { piles: pileSet, onOpen: (id) => {
|
|
409
|
+
const thread = threads.find((t) => t.id === id);
|
|
410
|
+
if (thread)
|
|
411
|
+
comments.show(thread);
|
|
412
|
+
} }) })) : null, open ? (_jsx(CommentPopover, { pin: pinBox(open.screen, viewport), viewport: viewport, onEscape: () => select(null), children: (maxHeight) => _jsx(ThreadCard, { comments: comments, agent: agent, thread: open.thread, state: open.state, maxHeight: maxHeight }) }, open.key)) : null, waiting && parked ? (_jsx(PinButton, { pin: pinBox(waiting.screen, viewport), parked: true, screenTransform: screenTransform, label: "Your draft comment", avatar: _jsx(Avatar, { name: comments.viewerName(), size: "sm" }), onClick: () => comments.store.getState().setDraft(parked.anchor) })) : null, focus && !focus.thread && draft !== null ? (_jsxs(_Fragment, { children: [_jsx(PinButton, { pin: pinBox(focus.screen, viewport), draft: true, screenTransform: screenTransform, label: "New comment", avatar: _jsx(Avatar, { name: comments.viewerName(), size: "sm" }) }), _jsx(CommentPopover, { pin: pinBox(focus.screen, viewport), viewport: viewport, onEscape: () => comments.store.getState().setDraft(null), children: () => _jsx(CommentComposer, { comments: comments, agent: agent, anchor: draft }) })] })) : null] })] }));
|
|
413
|
+
}
|
|
414
|
+
/** One thread's pin: a click opens its card, a drag moves the thread. */
|
|
415
|
+
function ThreadPin({ comments, thread, box, avatar, expanded, detached, movable, screenTransform, onDrag, onDrop, }) {
|
|
416
|
+
const press = useRef(null);
|
|
417
|
+
/** The last press was a drag: the click that follows it does nothing. */
|
|
418
|
+
const dragged = useRef(false);
|
|
419
|
+
const resolved = thread.status === 'resolved';
|
|
420
|
+
const dropUnmoved = () => {
|
|
421
|
+
const p = press.current;
|
|
422
|
+
press.current = null;
|
|
423
|
+
if (!p?.moved)
|
|
424
|
+
return;
|
|
425
|
+
// A click that still arrives belongs to the drag, as after a drop.
|
|
426
|
+
dragged.current = true;
|
|
427
|
+
onDrag(null);
|
|
428
|
+
};
|
|
429
|
+
return (_jsx(PinButton, { pinId: thread.id, pin: box, screenTransform: screenTransform, avatar: avatar, expanded: expanded, faded: detached, label: `Comment: ${thread.label}${resolved ? ' (resolved)' : ''}`, title: detached ? 'What this comment was on is gone' : thread.label, onPointerDown: (event) => {
|
|
430
|
+
if (event.button !== 0)
|
|
431
|
+
return;
|
|
432
|
+
press.current = { x: event.clientX, y: event.clientY, moved: false };
|
|
433
|
+
dragged.current = false;
|
|
434
|
+
try {
|
|
435
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// no capturable pointer
|
|
439
|
+
}
|
|
440
|
+
}, onPointerMove: (event) => {
|
|
441
|
+
const p = press.current;
|
|
442
|
+
if (!p || !movable || !comments.canComment())
|
|
443
|
+
return;
|
|
444
|
+
const dx = event.clientX - p.x;
|
|
445
|
+
const dy = event.clientY - p.y;
|
|
446
|
+
if (!p.moved && Math.hypot(dx, dy) < DRAG_THRESHOLD)
|
|
447
|
+
return;
|
|
448
|
+
p.moved = true;
|
|
449
|
+
onDrag({ x: dx, y: dy });
|
|
450
|
+
}, onPointerUp: (event) => {
|
|
451
|
+
const p = press.current;
|
|
452
|
+
press.current = null;
|
|
453
|
+
if (!p?.moved)
|
|
454
|
+
return;
|
|
455
|
+
dragged.current = true;
|
|
456
|
+
onDrag(null);
|
|
457
|
+
onDrop({ x: event.clientX - p.x, y: event.clientY - p.y });
|
|
458
|
+
},
|
|
459
|
+
// A drag the browser takes away (a cancelled touch, capture lost to another element) puts the pin back unmoved.
|
|
460
|
+
onPointerCancel: () => dropUnmoved(), onLostPointerCapture: () => dropUnmoved(), onClick: (event) => {
|
|
461
|
+
const wasDrag = dragged.current;
|
|
462
|
+
dragged.current = false;
|
|
463
|
+
// Only the click that ends a drag is the drag's: Enter or Space on the pin (no pointer, `detail` 0) opens it.
|
|
464
|
+
if (wasDrag && event.detail !== 0)
|
|
465
|
+
return;
|
|
466
|
+
const state = comments.store.getState();
|
|
467
|
+
state.setActive(state.active === thread.id ? null : thread.id);
|
|
468
|
+
} }));
|
|
469
|
+
}
|
|
470
|
+
/* -------------------------------------------------------------------------- */
|
|
471
|
+
/* A thread's card */
|
|
472
|
+
/* -------------------------------------------------------------------------- */
|
|
473
|
+
function useFollowReplies(region, thread) {
|
|
474
|
+
const follow = useRef(null);
|
|
475
|
+
useLayoutEffect(() => {
|
|
476
|
+
const f = follow.current;
|
|
477
|
+
const el = region.current;
|
|
478
|
+
if (!f || !el)
|
|
479
|
+
return;
|
|
480
|
+
el.scrollTop = el.scrollHeight;
|
|
481
|
+
const newest = thread.messages.at(-1);
|
|
482
|
+
if (newest && newest.id !== f.after && newest.author.kind === 'agent') {
|
|
483
|
+
const item = [...el.querySelectorAll('[data-cds-part="comment"]')].at(-1);
|
|
484
|
+
const over = item ? el.getBoundingClientRect().top - item.getBoundingClientRect().top : 0;
|
|
485
|
+
if (over > 0) {
|
|
486
|
+
el.scrollTop -= over;
|
|
487
|
+
follow.current = null;
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
f.at = el.scrollTop;
|
|
492
|
+
});
|
|
493
|
+
const stop = () => {
|
|
494
|
+
follow.current = null;
|
|
495
|
+
};
|
|
496
|
+
return {
|
|
497
|
+
start: () => {
|
|
498
|
+
follow.current = { after: thread.messages.at(-1)?.id, at: 0 };
|
|
499
|
+
},
|
|
500
|
+
regionProps: {
|
|
501
|
+
onPointerDownCapture: stop,
|
|
502
|
+
onWheelCapture: (event) => {
|
|
503
|
+
if (event.deltaY < 0)
|
|
504
|
+
stop();
|
|
505
|
+
},
|
|
506
|
+
onScroll: (event) => {
|
|
507
|
+
const el = event.currentTarget;
|
|
508
|
+
const f = follow.current;
|
|
509
|
+
if (f && Math.abs(el.scrollTop - f.at) > 2 && el.scrollHeight - el.scrollTop - el.clientHeight > 2)
|
|
510
|
+
stop();
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
export function ThreadCard(props) {
|
|
516
|
+
return (_jsx(InLayer, { children: _jsx(ThreadCardBody, { ...props }) }));
|
|
517
|
+
}
|
|
518
|
+
function ThreadCardBody({ comments, agent, thread, state, maxHeight, onClose }) {
|
|
519
|
+
const [confirming, setConfirming] = useState(false);
|
|
520
|
+
// What is being edited and what is on its way live in the store: the panel's composer waits for them.
|
|
521
|
+
const editing = comments.store((s) => (s.editing?.thread === thread.id ? s.editing : null));
|
|
522
|
+
const deleting = comments.store((s) => s.writing.includes(`delete:${thread.id}`));
|
|
523
|
+
const replying = comments.store((s) => s.writing.includes(`reply:${thread.id}`));
|
|
524
|
+
const saving = comments.store((s) => editing !== null && s.writing.includes(`edit:${editing.message}`));
|
|
525
|
+
const setEditing = (next) => comments.store.getState().setEditing(next && { thread: thread.id, message: next.id, send: next.send, changed: next.changed ?? false });
|
|
526
|
+
// An edit ends with its card.
|
|
527
|
+
useEffect(() => () => {
|
|
528
|
+
const state = comments.store.getState();
|
|
529
|
+
if (state.editing?.thread === thread.id)
|
|
530
|
+
state.setEditing(null);
|
|
531
|
+
}, [comments, thread.id]);
|
|
532
|
+
const change = comments.store((s) => s.statusChange);
|
|
533
|
+
const nameId = useId();
|
|
534
|
+
const region = useRef(null);
|
|
535
|
+
const follow = useFollowReplies(region, thread);
|
|
536
|
+
const draft = comments.store((s) => s.replies[thread.id]) ?? { text: '', send: false };
|
|
537
|
+
const sendable = comments.canSendToAgent() && agent.available;
|
|
538
|
+
const commenting = comments.canComment();
|
|
539
|
+
const [top, ...replies] = thread.messages;
|
|
540
|
+
const mentions = useMentionsSpec(comments, agent, sendable);
|
|
541
|
+
const editMentions = useMentionsSpec(comments, agent, sendable, thread.messages.find((m) => m.id === editing?.message)?.to);
|
|
542
|
+
if (!top)
|
|
543
|
+
return null;
|
|
544
|
+
const close = onClose ?? (() => comments.store.getState().setActive(null));
|
|
545
|
+
const note = comments.stateNote(state ?? comments.stateOf(comments.anchorOf(thread)));
|
|
546
|
+
const sendLabel = `Send to ${agent.name}`;
|
|
547
|
+
const status = thread.status === 'open' ? thread.agent?.status : undefined;
|
|
548
|
+
const working = status === 'pending' ? 'queued' : status === 'delivered' ? 'working' : undefined;
|
|
549
|
+
const setDraft = (next) => comments.store.getState().setReply(thread.id, next);
|
|
550
|
+
const editItem = (message) => comments.canEdit(message.author) ? [{ label: 'Edit', icon: 'Edit', onSelect: () => setEditing({ id: message.id, send: false }) }] : [];
|
|
551
|
+
const topItems = [
|
|
552
|
+
...editItem(top),
|
|
553
|
+
...(comments.canRemove() ? [{ label: 'Delete thread', icon: 'Trash', variant: 'danger', onSelect: () => setConfirming(true) }] : []),
|
|
554
|
+
];
|
|
555
|
+
/** The edit box in place of a message's text, while it is the one being edited. */
|
|
556
|
+
const editor = (message) => editing?.message === message.id ? (_jsx(EditField, { savedValue: message.text, busy: saving, mentions: editMentions, sendBox: sendable ? { label: sendLabel, checked: editing.send, onCheckedChange: (send) => setEditing({ id: editing.message, send, changed: editing.changed }) } : undefined, onChanged: (changed) => {
|
|
557
|
+
const now = comments.store.getState().editing;
|
|
558
|
+
if (now?.message === message.id && now.changed !== changed)
|
|
559
|
+
comments.store.getState().setEditing({ ...now, changed });
|
|
560
|
+
}, onCancel: () => setEditing(null), onSave: (text, { send, to }) => {
|
|
561
|
+
// A message that went to the agent keeps saying so.
|
|
562
|
+
const named = message.to?.includes(AGENT_KEY) && !to.includes(AGENT_KEY) ? [AGENT_KEY, ...to] : to;
|
|
563
|
+
void comments.edit(thread.id, message.id, text, { send: sendable && send, to: named }).then((saved) => {
|
|
564
|
+
if (saved && comments.store.getState().editing?.message === message.id)
|
|
565
|
+
setEditing(null);
|
|
566
|
+
});
|
|
567
|
+
} }, message.id)) : undefined;
|
|
568
|
+
return (_jsxs(CommentCard, { expanded: true, active: true, onClose: close, labelledBy: nameId, maxHeight: maxHeight, scrollRef: region, scrollProps: follow.regionProps, className: "min-h-0 flex-1", reply: commenting && (_jsx(ReplyField, { children: _jsx(CdsComposer, { label: "Reply", placeholder: thread.status === 'resolved' ? 'Reply to reopen…' : sendable && draft.send ? 'What do you want to edit?' : undefined, value: draft.text, onChange: (text) => setDraft({ ...draft, text }), sendBox: sendable ? { label: sendLabel, checked: draft.send, onCheckedChange: (send) => setDraft({ ...draft, send }) } : undefined, mentions: mentions, busy: replying, onSubmit: (text, { send, to }) => {
|
|
569
|
+
follow.start();
|
|
570
|
+
void comments.reply(thread.id, text, { send: sendable && send, to });
|
|
571
|
+
}, onCancel: close }) })), children: [_jsx(Comment, { nameId: nameId, authorName: authorName(top, agent), agent: top.author.kind === 'agent', timestamp: commentTime(top.at), footnote: note ?? undefined, editor: editor(top), confirm: confirming ? (_jsx(DeleteConfirm, { busy: deleting, onCancel: () => setConfirming(false), onDelete: () => void comments.remove(thread.id) })) : undefined, actions: commenting || topItems.length > 0 ? (_jsxs(Actions, { children: [commenting ? (_jsx(ResolveAction, { resolved: thread.status === 'resolved', disabled: change !== null, onResolve: () => void comments.resolve(thread.id, true) })) : null, _jsx(MoreMenu, { items: topItems, disabled: change !== null && change.id !== thread.id, waitReason: change?.id === thread.id ? WAIT_FOR_STATUS_CHANGE : undefined })] })) : undefined, children: messageText(top, agent) }), replies.length > 0 || working ? (_jsxs(Replies, { children: [replies.map((message) => (_jsx(Comment, { authorName: authorName(message, agent), agent: message.author.kind === 'agent', timestamp: commentTime(message.at), editor: editor(message), actions: comments.canEdit(message.author) ? (_jsx(Actions, { children: _jsx(MoreMenu, { items: editItem(message) }) })) : undefined, children: messageText(message, agent) }, message.id))), working ? _jsx(Comment, { authorName: agent.name, agent: true, working: working, footnote: working === 'queued' ? queuedNote(agent) : thread.agent?.drafted ? draftedText(agent.name).label : 'Working…' }) : null] })) : null] }));
|
|
572
|
+
}
|
|
573
|
+
/* -------------------------------------------------------------------------- */
|
|
574
|
+
/* The new comment's composer */
|
|
575
|
+
/* -------------------------------------------------------------------------- */
|
|
576
|
+
/** The panel composer's prompt and name. */
|
|
577
|
+
const WHOLE_PLACEHOLDER = 'Add a comment';
|
|
578
|
+
export function CommentComposer(props) {
|
|
579
|
+
return (_jsx(InLayer, { children: _jsx(ComposerBody, { ...props }) }));
|
|
580
|
+
}
|
|
581
|
+
function ComposerBody({ comments, agent, anchor, onCancel }) {
|
|
582
|
+
const text = comments.store((s) => s.draftText);
|
|
583
|
+
const send = comments.store((s) => s.sendNew);
|
|
584
|
+
const busy = comments.store((s) => s.writing.includes('new'));
|
|
585
|
+
const field = useRef(null);
|
|
586
|
+
const sendable = comments.canSendToAgent() && agent.available;
|
|
587
|
+
const mentions = useMentionsSpec(comments, agent, sendable);
|
|
588
|
+
useEffect(() => {
|
|
589
|
+
field.current?.focus({ preventScroll: true });
|
|
590
|
+
}, [anchor]);
|
|
591
|
+
const cancel = () => (onCancel ? onCancel() : comments.store.getState().setDraft(null));
|
|
592
|
+
// On the whole artifact (the panel's composer): no line saying what it is on.
|
|
593
|
+
const whole = comments.isWholeAnchor(anchor);
|
|
594
|
+
return (_jsx(CdsComposer, { textareaRef: field, context: whole ? undefined : comments.labelOf(anchor), ...(whole ? { placeholder: WHOLE_PLACEHOLDER, label: WHOLE_PLACEHOLDER } : {}), value: text, onChange: (next) => comments.store.getState().setDraftText(next), sendBox: sendable ? { label: `Send to ${agent.name}`, checked: send, onCheckedChange: (on) => comments.store.getState().setSendNew(on) } : undefined, mentions: mentions, busy: busy, onSubmit: (body, how) => {
|
|
595
|
+
if (busy)
|
|
596
|
+
return;
|
|
597
|
+
void comments.create(anchor, body, { send: sendable && how.send, to: how.to });
|
|
598
|
+
}, onCancel: cancel }));
|
|
599
|
+
}
|
|
600
|
+
export function CommentsButton({ comments, shortcut = 'C', side = 'bottom' }) {
|
|
601
|
+
const available = comments.store((s) => s.available);
|
|
602
|
+
if (!available)
|
|
603
|
+
return null;
|
|
604
|
+
return (_jsx(CommentsLayer, { inline: true, mark: "data-comments-button", children: _jsx(ButtonBody, { comments: comments, shortcut: shortcut, side: side }) }));
|
|
605
|
+
}
|
|
606
|
+
function ButtonBody({ comments, shortcut, side }) {
|
|
607
|
+
const [menuOpen, setMenuOpen] = useLayerMenu();
|
|
608
|
+
const count = comments.store((s) => openMessageCount(s.threads));
|
|
609
|
+
const on = comments.store((s) => s.on);
|
|
610
|
+
const panelOpen = comments.store((s) => s.listOpen);
|
|
611
|
+
const waiting = !on && count > 0;
|
|
612
|
+
const tip = on ? 'Done commenting' : count > 0 ? `${count} open ${count === 1 ? 'comment' : 'comments'}` : 'Comments';
|
|
613
|
+
const setPanel = (open) => {
|
|
614
|
+
setMenuOpen(false);
|
|
615
|
+
comments.store.getState().setListOpen(open);
|
|
616
|
+
};
|
|
617
|
+
const item = panelOpen ? { label: 'Hide comments', onSelect: () => setPanel(false) } : { label: 'Show all comments', trailing: count, onSelect: () => setPanel(true) };
|
|
618
|
+
return (_jsxs("span", { className: "flex shrink-0 items-center", children: [comments.canComment() ? (_jsx(Tooltip, { content: tip, shortcut: shortcut, side: side, children: _jsx(Button, { variant: "ghost", iconOnly: true, tooltip: false, "aria-label": "Comments", "aria-pressed": on, icon: _jsxs("span", { className: "relative inline-flex", children: [_jsx(Icon, { name: on ? 'CommentFilled' : 'Comment', size: "sm" }), waiting ? (_jsx("span", { "aria-hidden": true, className: "absolute rounded-full bg-fill-accent", style: { top: -1, right: -2, width: 6, height: 6, boxShadow: '0 0 0 1.5px var(--cds-page-bg)' } })) : null] }), onClick: () => comments.store.getState().setOn(!on) }) })) : null, _jsxs(Menu.Root, { open: menuOpen, onOpenChange: setMenuOpen, modal: false, children: [_jsx(Tooltip, { content: "Comment options", disabled: menuOpen, side: side, children: _jsx(Menu.Trigger, { render: _jsx(Button, { variant: "ghost", "aria-label": "Comment options", style: { paddingInline: 2 }, children: _jsx(Icon, { name: "CaretDown", size: "xs" }) }) }) }), _jsx(MenuPopup, { align: "end", children: _jsx(MenuItems, { items: [item] }) })] })] }));
|
|
619
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version history on the page, for any editor: the panel (`HistoryPanel`
|
|
3
|
+
* from the UI package) on the right, and the frame of a read-only preview
|
|
4
|
+
* of a past version over the editor: its banner (restore it, back to the
|
|
5
|
+
* latest), a pan-and-zoom surface fitted to what the editor draws, Esc to
|
|
6
|
+
* leave.
|
|
7
|
+
*
|
|
8
|
+
* Editor-agnostic: the editor draws
|
|
9
|
+
* the version's content in world px (`renderWorld`) and anything that
|
|
10
|
+
* follows it on screen (`renderOverlay`).
|
|
11
|
+
*/
|
|
12
|
+
import { type ReactNode } from 'react';
|
|
13
|
+
import type { HistoryController } from './history.js';
|
|
14
|
+
import type { Box, Camera } from './pins.js';
|
|
15
|
+
/** The history panel, on the right. */
|
|
16
|
+
export declare function HistoryAside<P>({ history, viewerId }: {
|
|
17
|
+
history: HistoryController<P>;
|
|
18
|
+
viewerId: string;
|
|
19
|
+
}): ReactNode;
|
|
20
|
+
/** A camera that shows `rect` whole (at most 100%) in a `w` × `h` viewport. */
|
|
21
|
+
export declare function fitCamera(rect: Box | null, w: number, h: number, margin?: number): Camera;
|
|
22
|
+
export interface VersionPreviewProps<P> {
|
|
23
|
+
history: HistoryController<P>;
|
|
24
|
+
/** The viewer cannot edit (no restore, no "go back to edit" hint). */
|
|
25
|
+
readOnly: boolean;
|
|
26
|
+
/** World bounds of what the preview shows (fitted when it changes), `null` when empty. */
|
|
27
|
+
bounds(preview: P): Box | null;
|
|
28
|
+
/** The version's content in world px. */
|
|
29
|
+
renderWorld(preview: P): ReactNode;
|
|
30
|
+
/** Screen-space content that follows the camera (labels, per-part restore buttons). */
|
|
31
|
+
renderOverlay?(preview: P, camera: Camera, n: number, restorable: boolean): ReactNode;
|
|
32
|
+
/** A key that refits when it changes (the page shown…). */
|
|
33
|
+
fitKey?: unknown;
|
|
34
|
+
/** What the preview says when there is nothing to draw. */
|
|
35
|
+
emptyText?(n: number): string;
|
|
36
|
+
}
|
|
37
|
+
/** The read-only preview of a past version, over the editor. */
|
|
38
|
+
export declare function VersionPreview<P>({ history, readOnly, bounds, renderWorld, renderOverlay, fitKey, emptyText }: VersionPreviewProps<P>): ReactNode;
|