@designtools/comments 0.0.0-stage → 0.2.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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/dist/adapter.d.ts +45 -0
- package/dist/adapter.js +177 -0
- package/dist/api.d.ts +20 -0
- package/dist/api.js +35 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +216 -0
- package/dist/comments.d.ts +24 -0
- package/dist/comments.js +586 -0
- package/dist/css.d.ts +2 -0
- package/dist/css.js +2 -0
- package/dist/identity.d.ts +6 -0
- package/dist/identity.js +66 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/prompt.d.ts +10 -0
- package/dist/prompt.js +35 -0
- package/dist/server/handler.d.ts +45 -0
- package/dist/server/handler.js +169 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +10 -0
- package/dist/server/memory.d.ts +6 -0
- package/dist/server/memory.js +81 -0
- package/dist/server/migrations.d.ts +17 -0
- package/dist/server/migrations.js +61 -0
- package/dist/server/postgres.d.ts +7 -0
- package/dist/server/postgres.js +100 -0
- package/dist/server/sql.d.ts +14 -0
- package/dist/server/sql.js +36 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.js +5 -0
- package/dist/validate.d.ts +40 -0
- package/dist/validate.js +144 -0
- package/package.json +80 -3
package/dist/comments.js
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Comments on a prototype, pinned to the part of the page they're about. `<Comments />` draws a
|
|
5
|
+
* launcher in the corner; Comment starts choosing (mouse, or arrow keys and Enter), and what's
|
|
6
|
+
* chosen gets a thread. Open threads show as pins beside their anchors; the panel lists this page's
|
|
7
|
+
* threads, open or resolved, and the ones whose anchor has gone.
|
|
8
|
+
*
|
|
9
|
+
* Everything is drawn in its own shadow root, apart from the page. It asks its route handler first
|
|
10
|
+
* and draws nothing when that answers 404, as it does in production.
|
|
11
|
+
*/
|
|
12
|
+
import { FOCUS, IconButton, LiveRegion, PickOutline, TipProvider, ToolRoot, usePicker, useRect } from "@designtools/widgets";
|
|
13
|
+
import { ArrowLeft, Check, Copy, MessageSquarePlus, MessagesSquare, RotateCcw, X } from "lucide-react";
|
|
14
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
15
|
+
import { anchorName, defaultAdapter, humanize } from "./adapter.js";
|
|
16
|
+
import { CommentsError, commentsApi } from "./api.js";
|
|
17
|
+
import { css, properties } from "./css.js";
|
|
18
|
+
import { useAuthor } from "./identity.js";
|
|
19
|
+
import { threadPrompt } from "./prompt.js";
|
|
20
|
+
import { LIMITS } from "./validate.js";
|
|
21
|
+
const STYLES = [{ id: "comments", css, properties }];
|
|
22
|
+
const LAYER = { position: "fixed", inset: 0, zIndex: 2147482000, pointerEvents: "none" };
|
|
23
|
+
const POLL_MS = 30_000;
|
|
24
|
+
/* a thread chosen in another page's list, carried across the navigation to it */
|
|
25
|
+
const HANDOFF = "designtools-comments:open";
|
|
26
|
+
function handOff(id) {
|
|
27
|
+
try {
|
|
28
|
+
sessionStorage.setItem(HANDOFF, id);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// no storage: the page still opens, just not the thread
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function takeHandoff() {
|
|
35
|
+
try {
|
|
36
|
+
const id = sessionStorage.getItem(HANDOFF);
|
|
37
|
+
if (id)
|
|
38
|
+
sessionStorage.removeItem(HANDOFF);
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const cx = (...c) => c.filter(Boolean).join(" ");
|
|
46
|
+
/* ---------- small pieces ---------- */
|
|
47
|
+
const rtf = typeof Intl !== "undefined" ? new Intl.RelativeTimeFormat(undefined, { numeric: "auto" }) : null;
|
|
48
|
+
export function ago(iso, now = Date.now()) {
|
|
49
|
+
const s = Math.round((new Date(iso).getTime() - now) / 1000);
|
|
50
|
+
const abs = Math.abs(s);
|
|
51
|
+
if (!rtf)
|
|
52
|
+
return new Date(iso).toLocaleString();
|
|
53
|
+
if (abs < 45)
|
|
54
|
+
return "just now";
|
|
55
|
+
if (abs < 3600)
|
|
56
|
+
return rtf.format(Math.round(s / 60), "minute");
|
|
57
|
+
if (abs < 86_400)
|
|
58
|
+
return rtf.format(Math.round(s / 3600), "hour");
|
|
59
|
+
if (abs < 7 * 86_400)
|
|
60
|
+
return rtf.format(Math.round(s / 86_400), "day");
|
|
61
|
+
return new Date(iso).toLocaleDateString(undefined, { day: "numeric", month: "short", year: new Date(iso).getFullYear() === new Date(now).getFullYear() ? undefined : "numeric" });
|
|
62
|
+
}
|
|
63
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
64
|
+
/** The page's path, followed through client-side navigation, which fires no event of its own. */
|
|
65
|
+
function usePath() {
|
|
66
|
+
const [path, setPath] = useState(() => (typeof location === "undefined" ? "/" : location.pathname));
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const check = () => setPath(location.pathname);
|
|
69
|
+
window.addEventListener("popstate", check);
|
|
70
|
+
const timer = setInterval(check, 500);
|
|
71
|
+
return () => {
|
|
72
|
+
window.removeEventListener("popstate", check);
|
|
73
|
+
clearInterval(timer);
|
|
74
|
+
};
|
|
75
|
+
}, []);
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
/** A count that moves whenever the page might have moved: scroll, resize, focus, the DOM changing. */
|
|
79
|
+
function useTick(on) {
|
|
80
|
+
const [tick, setTick] = useState(0);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!on)
|
|
83
|
+
return;
|
|
84
|
+
let frame = 0;
|
|
85
|
+
const bump = () => {
|
|
86
|
+
if (!frame)
|
|
87
|
+
frame = requestAnimationFrame(() => {
|
|
88
|
+
frame = 0;
|
|
89
|
+
setTick((t) => t + 1);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
window.addEventListener("scroll", bump, true);
|
|
93
|
+
window.addEventListener("resize", bump);
|
|
94
|
+
document.addEventListener("focusin", bump);
|
|
95
|
+
const observer = new MutationObserver(bump);
|
|
96
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
97
|
+
// images and fonts arriving move things without a mutation
|
|
98
|
+
const timer = setInterval(bump, 1500);
|
|
99
|
+
return () => {
|
|
100
|
+
cancelAnimationFrame(frame);
|
|
101
|
+
window.removeEventListener("scroll", bump, true);
|
|
102
|
+
window.removeEventListener("resize", bump);
|
|
103
|
+
document.removeEventListener("focusin", bump);
|
|
104
|
+
observer.disconnect();
|
|
105
|
+
clearInterval(timer);
|
|
106
|
+
};
|
|
107
|
+
}, [on]);
|
|
108
|
+
return tick;
|
|
109
|
+
}
|
|
110
|
+
const inTool = (el) => !!el?.closest("[data-designtools-host]");
|
|
111
|
+
/** How much of `a` a box covers, 0 to 1. */
|
|
112
|
+
function covered(a, box) {
|
|
113
|
+
const w = Math.max(0, Math.min(a.right, box.right) - Math.max(a.left, box.left));
|
|
114
|
+
const h = Math.max(0, Math.min(a.bottom, box.bottom) - Math.max(a.top, box.top));
|
|
115
|
+
const area = a.width * a.height;
|
|
116
|
+
return area > 0 ? (w * h) / area : 0;
|
|
117
|
+
}
|
|
118
|
+
const GUTTER = 16;
|
|
119
|
+
const PANEL_W = 360;
|
|
120
|
+
const LAUNCHER_H = 56;
|
|
121
|
+
/** Where the panel goes: beside the page on a wide window, a sheet at the bottom or top on a narrow one. */
|
|
122
|
+
function panelBox(place) {
|
|
123
|
+
const w = window.innerWidth;
|
|
124
|
+
const h = window.innerHeight;
|
|
125
|
+
if (w < 720) {
|
|
126
|
+
const sheet = Math.min(h * 0.6, 560);
|
|
127
|
+
// a sheet at the bottom, where a thumb is, running under the launcher (the panel keeps room for it);
|
|
128
|
+
// at the top when that would cover what matters
|
|
129
|
+
return place === "start" ? { left: 0, right: w, top: h - sheet - LAUNCHER_H, bottom: h } : { left: 0, right: w, top: 0, bottom: sheet };
|
|
130
|
+
}
|
|
131
|
+
return place === "start"
|
|
132
|
+
? { left: GUTTER, right: GUTTER + PANEL_W, top: GUTTER, bottom: h - LAUNCHER_H - GUTTER }
|
|
133
|
+
: { left: w - GUTTER - PANEL_W, right: w - GUTTER, top: GUTTER, bottom: h - LAUNCHER_H - GUTTER };
|
|
134
|
+
}
|
|
135
|
+
/* ---------- the tool ---------- */
|
|
136
|
+
export function Comments({ endpoint = "/api/comments", adapter: adapterProp, enabled = true, theme = "system", locale }) {
|
|
137
|
+
const [mounted, setMounted] = useState(false);
|
|
138
|
+
useEffect(() => setMounted(true), []);
|
|
139
|
+
if (!enabled || !mounted || window.self !== window.top)
|
|
140
|
+
return null;
|
|
141
|
+
return _jsx(CommentsTool, { endpoint: endpoint, adapter: adapterProp, theme: theme, locale: locale });
|
|
142
|
+
}
|
|
143
|
+
function CommentsTool({ endpoint, adapter: adapterProp, theme, locale }) {
|
|
144
|
+
const api = useMemo(() => commentsApi(endpoint), [endpoint]);
|
|
145
|
+
const adapter = useMemo(() => adapterProp ?? defaultAdapter(), [adapterProp]);
|
|
146
|
+
const path = usePath();
|
|
147
|
+
const [author, rememberName] = useAuthor();
|
|
148
|
+
// null until the handler has answered; false when it said 404 (production, or switched off)
|
|
149
|
+
const [available, setAvailable] = useState(null);
|
|
150
|
+
const [data, setData] = useState(null);
|
|
151
|
+
const [loadError, setLoadError] = useState(null);
|
|
152
|
+
const [panel, setPanel] = useState(false);
|
|
153
|
+
const [view, setView] = useState({ kind: "list" });
|
|
154
|
+
const [choosing, setChoosing] = useState(false);
|
|
155
|
+
const [filter, setFilter] = useState("open");
|
|
156
|
+
const [scope, setScope] = useState("page");
|
|
157
|
+
// every page's threads, while the panel shows them
|
|
158
|
+
const [everywhere, setEverywhere] = useState(null);
|
|
159
|
+
const [message, setMessage] = useState("");
|
|
160
|
+
const commentButton = useRef(null);
|
|
161
|
+
const panelButton = useRef(null);
|
|
162
|
+
const heading = useRef(null);
|
|
163
|
+
// where focus goes once the panel has drawn its next view
|
|
164
|
+
const focusNext = useRef(null);
|
|
165
|
+
const announce = useCallback((text) => {
|
|
166
|
+
setMessage("");
|
|
167
|
+
requestAnimationFrame(() => setMessage(text));
|
|
168
|
+
}, []);
|
|
169
|
+
const load = useCallback(async () => {
|
|
170
|
+
try {
|
|
171
|
+
const pageKey = adapter.page?.(document) ?? null;
|
|
172
|
+
const list = await api.list(path, pageKey);
|
|
173
|
+
// a page with a key, now at a new path: its threads follow it
|
|
174
|
+
if (pageKey && list.threads.some((t) => t.pageKey === pageKey && t.path !== path)) {
|
|
175
|
+
api.movePage(pageKey, path).catch(() => { });
|
|
176
|
+
list.threads = list.threads.map((t) => (t.pageKey === pageKey ? { ...t, path } : t));
|
|
177
|
+
}
|
|
178
|
+
setData(list);
|
|
179
|
+
setAvailable(true);
|
|
180
|
+
setLoadError(null);
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
if (e instanceof CommentsError && e.status === 404)
|
|
184
|
+
setAvailable(false);
|
|
185
|
+
else {
|
|
186
|
+
setAvailable((a) => a ?? true);
|
|
187
|
+
setLoadError(e.message);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, [api, path, adapter]);
|
|
191
|
+
// this page's threads: now, on a new path, every 30s while the tab is showing, and on coming back to it
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
setView({ kind: "list" });
|
|
194
|
+
load();
|
|
195
|
+
const timer = setInterval(() => document.visibilityState === "visible" && load(), POLL_MS);
|
|
196
|
+
const back = () => document.visibilityState === "visible" && load();
|
|
197
|
+
document.addEventListener("visibilitychange", back);
|
|
198
|
+
return () => {
|
|
199
|
+
clearInterval(timer);
|
|
200
|
+
document.removeEventListener("visibilitychange", back);
|
|
201
|
+
};
|
|
202
|
+
}, [load]);
|
|
203
|
+
const threads = data?.threads ?? [];
|
|
204
|
+
const tick = useTick(available === true);
|
|
205
|
+
// every page's threads: when the panel shows them, each time it comes back to the list, and every 30s
|
|
206
|
+
const listing = panel && scope === "all" && view.kind === "list";
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
if (!listing)
|
|
209
|
+
return;
|
|
210
|
+
const loadAll = () => api.listAll().then((l) => setEverywhere(l.threads), (e) => setLoadError(e.message));
|
|
211
|
+
loadAll();
|
|
212
|
+
const timer = setInterval(() => document.visibilityState === "visible" && loadAll(), POLL_MS);
|
|
213
|
+
return () => clearInterval(timer);
|
|
214
|
+
}, [listing, api]);
|
|
215
|
+
// a thread chosen on another page: once that page has loaded, open it
|
|
216
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs when this page's threads arrive
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
if (!data)
|
|
219
|
+
return;
|
|
220
|
+
const id = takeHandoff();
|
|
221
|
+
const thread = id ? data.threads.find((t) => t.id === id) : undefined;
|
|
222
|
+
if (!thread)
|
|
223
|
+
return;
|
|
224
|
+
setScope("page");
|
|
225
|
+
adapter.locate(thread.anchor, document)?.scrollIntoView({ block: "center" });
|
|
226
|
+
open({ kind: "thread", id: thread.id });
|
|
227
|
+
}, [data]);
|
|
228
|
+
// where each thread's anchor is on this page now; null when it has gone
|
|
229
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: tick stands for the page changing
|
|
230
|
+
const located = useMemo(() => {
|
|
231
|
+
const m = new Map();
|
|
232
|
+
for (const t of threads)
|
|
233
|
+
m.set(t.id, adapter.locate(t.anchor, document));
|
|
234
|
+
return m;
|
|
235
|
+
}, [threads, adapter, tick]);
|
|
236
|
+
/* choosing */
|
|
237
|
+
const candidates = useCallback(() => adapter.candidates(document).filter((el) => !inTool(el)), [adapter]);
|
|
238
|
+
const describe = useCallback((el) => {
|
|
239
|
+
const a = adapter.describe(el);
|
|
240
|
+
if (!a)
|
|
241
|
+
return null;
|
|
242
|
+
return a.field ? { label: el.getAttribute("data-comment-label") || humanize(a.field), kind: "field" } : { label: a.label, kind: a.kind };
|
|
243
|
+
}, [adapter]);
|
|
244
|
+
const resolve = useMemo(() => (adapter.resolve ? (t) => adapter.resolve?.(t) ?? null : undefined), [adapter]);
|
|
245
|
+
const choose = useCallback((el) => {
|
|
246
|
+
const anchor = adapter.describe(el);
|
|
247
|
+
if (!anchor) {
|
|
248
|
+
announce("That can't be commented on. Choose something else, or Escape to stop.");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
setChoosing(false);
|
|
252
|
+
setPanel(true);
|
|
253
|
+
setView({ kind: "compose", anchor });
|
|
254
|
+
focusNext.current = "field";
|
|
255
|
+
}, [adapter, announce]);
|
|
256
|
+
const stopChoosing = useCallback(() => {
|
|
257
|
+
setChoosing(false);
|
|
258
|
+
commentButton.current?.focus();
|
|
259
|
+
}, []);
|
|
260
|
+
const picker = usePicker({ active: choosing, candidates, describe, resolve, onChoose: choose, onCancel: stopChoosing });
|
|
261
|
+
/* the panel */
|
|
262
|
+
const open = (next) => {
|
|
263
|
+
setView(next);
|
|
264
|
+
setPanel(true);
|
|
265
|
+
focusNext.current = "heading";
|
|
266
|
+
};
|
|
267
|
+
const closePanel = () => {
|
|
268
|
+
setPanel(false);
|
|
269
|
+
setView({ kind: "list" });
|
|
270
|
+
panelButton.current?.focus();
|
|
271
|
+
};
|
|
272
|
+
// after the view changes, move focus into it: the first field when writing, else its heading
|
|
273
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs when a new view is drawn
|
|
274
|
+
useLayoutEffect(() => {
|
|
275
|
+
const to = focusNext.current;
|
|
276
|
+
if (!to || !panel || choosing)
|
|
277
|
+
return;
|
|
278
|
+
focusNext.current = null;
|
|
279
|
+
if (to === "field") {
|
|
280
|
+
const root = heading.current?.closest("[data-panel]");
|
|
281
|
+
const field = root?.querySelector("[data-first-field]");
|
|
282
|
+
(field ?? heading.current)?.focus();
|
|
283
|
+
}
|
|
284
|
+
else
|
|
285
|
+
heading.current?.focus();
|
|
286
|
+
}, [view, panel, choosing]);
|
|
287
|
+
const active = view.kind === "thread" ? threads.find((t) => t.id === view.id) : undefined;
|
|
288
|
+
const highlighted = view.kind === "thread" ? (located.get(view.id) ?? null) : view.kind === "compose" ? adapter.locate(view.anchor, document) : null;
|
|
289
|
+
const highlightRect = useRect(panel && !choosing ? highlighted : null);
|
|
290
|
+
// keep the panel off what matters: the page element with focus, else the anchor being discussed
|
|
291
|
+
const [place, setPlace] = useState("start");
|
|
292
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: tick stands for the page changing
|
|
293
|
+
useLayoutEffect(() => {
|
|
294
|
+
if (!panel)
|
|
295
|
+
return;
|
|
296
|
+
const focused = document.activeElement instanceof HTMLElement && document.activeElement !== document.body && !inTool(document.activeElement) ? document.activeElement : null;
|
|
297
|
+
const keep = focused ?? highlighted;
|
|
298
|
+
if (!keep)
|
|
299
|
+
return;
|
|
300
|
+
const r = keep.getBoundingClientRect();
|
|
301
|
+
const here = covered(r, panelBox(place));
|
|
302
|
+
const there = covered(r, panelBox(place === "start" ? "end" : "start"));
|
|
303
|
+
if (here > 0.25 && there < here)
|
|
304
|
+
setPlace(place === "start" ? "end" : "start");
|
|
305
|
+
}, [panel, tick, highlighted, place]);
|
|
306
|
+
if (available !== true)
|
|
307
|
+
return null;
|
|
308
|
+
const open_ = threads.filter((t) => t.status === "open");
|
|
309
|
+
const pinned = open_.filter((t) => located.get(t.id));
|
|
310
|
+
return (_jsx(ToolRoot, { theme: theme, styles: STYLES, style: LAYER, children: _jsxs(TipProvider, { children: [choosing && picker.current && _jsx(ChoosingOutline, { el: picker.current, label: picker.label }), !choosing && highlightRect && _jsx(PickOutline, { rect: highlightRect, label: anchorLabelFor(view, active) }), _jsx(LiveRegion, { message: choosing ? picker.announcement : message }), !choosing && (_jsx(Pins, { threads: pinned, located: located, activeId: panel && view.kind === "thread" ? view.id : null, cover: panel ? panelBox(place) : null, tick: tick, onOpen: (t) => open({ kind: "thread", id: t.id }) })), panel && !choosing && (_jsxs(Panel, { place: place, onEscape: view.kind === "list" ? closePanel : () => open({ kind: "list" }), children: [view.kind === "list" && (_jsx(ListView, { headingRef: heading, threads: threads, everywhere: everywhere, located: located, filter: filter, setFilter: setFilter, scope: scope, setScope: setScope, error: loadError, onOpen: (t) => {
|
|
311
|
+
if (!threads.some((x) => x.id === t.id)) {
|
|
312
|
+
// on another page: go there, and open it once it has loaded
|
|
313
|
+
handOff(t.id);
|
|
314
|
+
location.assign(t.path);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
located.get(t.id)?.scrollIntoView({ block: "nearest" });
|
|
318
|
+
open({ kind: "thread", id: t.id });
|
|
319
|
+
}, onNew: () => setChoosing(true), onClose: closePanel })), view.kind === "thread" && active && (_jsx(ThreadView, { headingRef: heading, thread: active, orphaned: !located.get(active.id), current: data?.deployment.branch ?? null, author: author, rememberName: rememberName, api: api, onBack: () => open({ kind: "list" }), onClose: closePanel, onChange: (t) => {
|
|
320
|
+
setData((d) => (d ? { ...d, threads: d.threads.map((x) => (x.id === t.id ? t : x)) } : d));
|
|
321
|
+
}, announce: announce })), view.kind === "thread" && !active && _jsx(Gone, { headingRef: heading, onBack: () => open({ kind: "list" }) }), view.kind === "compose" && (_jsx(ComposeView, { headingRef: heading, anchor: view.anchor, author: author, rememberName: rememberName, onCancel: () => open({ kind: "list" }), onClose: closePanel, onSend: async (body, who) => {
|
|
322
|
+
const thread = await api.createThread({
|
|
323
|
+
path,
|
|
324
|
+
pageKey: adapter.page?.(document) ?? null,
|
|
325
|
+
locale: (locale ?? (() => document.documentElement.lang || null))(),
|
|
326
|
+
anchor: view.anchor,
|
|
327
|
+
viewportWidth: window.innerWidth,
|
|
328
|
+
body,
|
|
329
|
+
author: who,
|
|
330
|
+
});
|
|
331
|
+
setData((d) => (d ? { ...d, threads: [thread, ...d.threads] } : d));
|
|
332
|
+
setFilter("open");
|
|
333
|
+
open({ kind: "thread", id: thread.id });
|
|
334
|
+
announce(`Comment added on ${anchorName(thread.anchor)}.`);
|
|
335
|
+
} })), _jsx(NameLine, { author: author, rememberName: rememberName })] })), _jsx(Launcher, { choosing: choosing, panel: panel, open: open_.length, commentRef: commentButton, panelRef: panelButton, onComment: () => (choosing ? stopChoosing() : setChoosing(true)), onPanel: () => (panel ? closePanel() : open({ kind: "list" })) })] }) }));
|
|
336
|
+
}
|
|
337
|
+
function anchorLabelFor(view, thread) {
|
|
338
|
+
if (view.kind === "compose")
|
|
339
|
+
return anchorName(view.anchor);
|
|
340
|
+
return thread ? anchorName(thread.anchor) : null;
|
|
341
|
+
}
|
|
342
|
+
function ChoosingOutline({ el, label }) {
|
|
343
|
+
const rect = useRect(el);
|
|
344
|
+
return rect ? _jsx(PickOutline, { rect: rect, label: label }) : null;
|
|
345
|
+
}
|
|
346
|
+
/* ---------- launcher ---------- */
|
|
347
|
+
const BAR_BUTTON = cx("inline-flex h-8 min-w-8 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-2.5 text-[12px] font-medium text-ink hover:bg-scrim aria-pressed:bg-scrim aria-expanded:bg-scrim", FOCUS);
|
|
348
|
+
function Launcher({ choosing, panel, open, commentRef, panelRef, onComment, onPanel, }) {
|
|
349
|
+
return (_jsx("div", { className: "pointer-events-auto fixed bottom-4 left-4 flex flex-col items-start gap-2", "data-launcher": "", children: _jsxs("div", { className: "flex gap-0.5 rounded-xl border border-edge bg-page p-1 text-ink shadow-lg shadow-black/15", children: [_jsxs("button", { ref: commentRef, type: "button", onClick: onComment, className: BAR_BUTTON, children: [choosing ? _jsx(X, { "aria-hidden": true, width: 14, height: 14 }) : _jsx(MessageSquarePlus, { "aria-hidden": true, width: 14, height: 14 }), choosing ? "Cancel" : "Comment"] }), _jsxs("button", { ref: panelRef, type: "button", "aria-expanded": panel, "aria-label": `Comments on this page, ${open} open`, onClick: onPanel, className: BAR_BUTTON, children: [_jsx(MessagesSquare, { "aria-hidden": true, width: 14, height: 14 }), _jsx("span", { className: "tabular-nums", children: open })] })] }) }));
|
|
350
|
+
}
|
|
351
|
+
/* ---------- pins ---------- */
|
|
352
|
+
const PIN = 24;
|
|
353
|
+
function Pins({ threads, located, activeId, cover, tick, onOpen, }) {
|
|
354
|
+
void tick; // drawn again whenever the page moves
|
|
355
|
+
const byEl = new Map();
|
|
356
|
+
for (const t of threads) {
|
|
357
|
+
const el = located.get(t.id);
|
|
358
|
+
if (!el)
|
|
359
|
+
continue;
|
|
360
|
+
const list = byEl.get(el) ?? [];
|
|
361
|
+
list.push(t);
|
|
362
|
+
byEl.set(el, list);
|
|
363
|
+
}
|
|
364
|
+
const w = window.innerWidth;
|
|
365
|
+
const h = window.innerHeight;
|
|
366
|
+
const pins = [];
|
|
367
|
+
for (const [el, list] of byEl) {
|
|
368
|
+
const r = el.getBoundingClientRect();
|
|
369
|
+
if (r.bottom < 0 || r.top > h || r.right < 0 || r.left > w)
|
|
370
|
+
continue;
|
|
371
|
+
// outside the anchor's top-right corner, its tail on the corner, so it never covers what's commented on;
|
|
372
|
+
// oldest nearest the corner, the rest outward
|
|
373
|
+
[...list].reverse().forEach((t, i) => {
|
|
374
|
+
const left = Math.min(Math.max(r.right + 2 + i * (PIN + 4), 4), w - PIN - 4);
|
|
375
|
+
const top = Math.min(Math.max(r.top - PIN - 2, 4), h - PIN - 4);
|
|
376
|
+
if (cover && left < cover.right && left + PIN > cover.left && top < cover.bottom && top + PIN > cover.top)
|
|
377
|
+
return;
|
|
378
|
+
const n = t.comments.length;
|
|
379
|
+
pins.push(_jsx("button", { type: "button", onClick: () => onOpen(t), "aria-label": `${plural(n, "comment")} on ${anchorName(t.anchor)}`, "aria-current": t.id === activeId ? "true" : undefined, className: cx("pointer-events-auto fixed flex cursor-pointer items-center justify-center rounded-full rounded-bl-none border-2 border-white bg-[#1d4ed8] text-[11px] font-semibold text-white tabular-nums shadow-md shadow-black/25 hover:bg-[#1e40af]", "outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#1d4ed8]", t.id === activeId && "outline-2 outline-offset-2 outline-[#1d4ed8]"), style: { left, top, width: PIN, height: PIN }, children: n }, t.id));
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return _jsx(_Fragment, { children: pins });
|
|
383
|
+
}
|
|
384
|
+
/* ---------- the panel ---------- */
|
|
385
|
+
function Panel({ place, onEscape, children }) {
|
|
386
|
+
const box = panelBox(place);
|
|
387
|
+
const sheet = window.innerWidth < 720;
|
|
388
|
+
const keydown = (e) => {
|
|
389
|
+
if (e.key !== "Escape")
|
|
390
|
+
return;
|
|
391
|
+
// a half-written comment isn't thrown away by a stray Escape
|
|
392
|
+
const t = e.target;
|
|
393
|
+
if ((t.tagName === "TEXTAREA" || t.tagName === "INPUT") && t.value.trim())
|
|
394
|
+
return;
|
|
395
|
+
e.stopPropagation();
|
|
396
|
+
onEscape();
|
|
397
|
+
};
|
|
398
|
+
return (_jsx("section", { "data-panel": "", "aria-label": "Comments", onKeyDown: keydown, className: cx("pointer-events-auto fixed flex flex-col overflow-hidden border border-edge bg-page text-ink shadow-2xl shadow-black/20", !sheet && "rounded-xl", sheet && place === "start" && "rounded-t-xl border-x-0 border-b-0", sheet && place === "end" && "rounded-b-xl border-x-0 border-t-0"), style: {
|
|
399
|
+
left: box.left,
|
|
400
|
+
top: box.top,
|
|
401
|
+
width: box.right - box.left,
|
|
402
|
+
height: box.bottom - box.top,
|
|
403
|
+
// the launcher sits on the foot of a bottom sheet
|
|
404
|
+
paddingBottom: sheet && place === "start" ? LAUNCHER_H : undefined,
|
|
405
|
+
}, children: children }));
|
|
406
|
+
}
|
|
407
|
+
function Header({ headingRef, title, back, onClose, children }) {
|
|
408
|
+
return (_jsxs("header", { className: "flex items-center gap-1 border-b border-edge py-2 pr-2 pl-2", children: [back && _jsx(IconButton, { icon: ArrowLeft, label: "Back to comments", size: "md", onClick: back }), _jsx("h2", { ref: headingRef, tabIndex: -1, className: cx("min-w-0 flex-1 truncate text-[13px] font-semibold outline-none", !back && "pl-2"), children: title }), children, _jsx(IconButton, { icon: X, label: "Close comments", size: "md", onClick: onClose })] }));
|
|
409
|
+
}
|
|
410
|
+
const SCROLL = "min-h-0 flex-1 overflow-y-auto";
|
|
411
|
+
const BUTTON = cx("inline-flex h-8 cursor-pointer items-center justify-center gap-1.5 rounded-md px-3 text-[12px] font-medium disabled:cursor-default disabled:opacity-50", FOCUS);
|
|
412
|
+
const PRIMARY = cx(BUTTON, "bg-[#1d4ed8] text-white hover:bg-[#1e40af] focus-visible:outline-offset-2 focus-visible:outline-[#1d4ed8]");
|
|
413
|
+
const SECONDARY = cx(BUTTON, "border border-edge bg-page text-ink hover:bg-scrim");
|
|
414
|
+
const INPUT = "w-full rounded-md border border-edge bg-page px-2.5 py-2 text-[13px] text-ink outline-none placeholder:text-ink2 focus:border-sel focus:outline-2 focus:-outline-offset-1 focus:outline-sel";
|
|
415
|
+
const TOGGLE = cx("inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium text-ink2 hover:bg-scrim aria-pressed:bg-muted aria-pressed:text-ink", FOCUS);
|
|
416
|
+
function ListView({ headingRef, threads, everywhere, located, filter, setFilter, scope, setScope, error, onOpen, onNew, onClose, }) {
|
|
417
|
+
const all = scope === "all";
|
|
418
|
+
const pool = all ? (everywhere ?? []) : threads;
|
|
419
|
+
const counts = { open: pool.filter((t) => t.status === "open").length, resolved: pool.filter((t) => t.status === "resolved").length };
|
|
420
|
+
return (_jsxs(_Fragment, { children: [_jsx(Header, { headingRef: headingRef, title: all ? "Comments on all pages" : "Comments on this page", onClose: onClose, children: _jsx(IconButton, { icon: MessageSquarePlus, label: "New comment", size: "md", onClick: onNew }) }), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b border-edge px-3 py-2", children: [_jsx("div", { className: "flex gap-1", role: "group", "aria-label": "Pages", children: ["page", "all"].map((s) => (_jsx("button", { type: "button", "aria-pressed": scope === s, onClick: () => setScope(s), className: TOGGLE, children: s === "page" ? "This page" : "All pages" }, s))) }), _jsx("div", { className: "flex gap-1", role: "group", "aria-label": "Show", children: ["open", "resolved"].map((f) => (_jsxs("button", { type: "button", "aria-pressed": filter === f, onClick: () => setFilter(f), className: TOGGLE, children: [f === "open" ? "Open" : "Resolved", _jsx("span", { className: "tabular-nums", children: all && !everywhere ? "–" : counts[f] })] }, f))) })] }), _jsxs("div", { className: SCROLL, children: [error && (_jsx("p", { role: "alert", className: "m-3 rounded-md bg-muted px-3 py-2 text-[12px] text-fail", children: error })), all ? (_jsx(AllPages, { threads: everywhere, here: threads, filter: filter, onOpen: onOpen })) : (_jsx(ThisPage, { threads: threads, located: located, filter: filter, onOpen: onOpen }))] })] }));
|
|
421
|
+
}
|
|
422
|
+
/** Every page's threads, grouped by page: this one first, then the rest by path. */
|
|
423
|
+
function AllPages({ threads, here, filter, onOpen }) {
|
|
424
|
+
if (!threads)
|
|
425
|
+
return _jsx("p", { className: "px-4 py-6 text-[12px] text-ink2", children: "Loading\u2026" });
|
|
426
|
+
const onThisPage = new Set(here.map((t) => t.id));
|
|
427
|
+
// where each page with a key is now: threads come newest first, so its latest path
|
|
428
|
+
const latest = new Map();
|
|
429
|
+
for (const t of threads)
|
|
430
|
+
if (t.pageKey && !latest.has(t.pageKey))
|
|
431
|
+
latest.set(t.pageKey, t.path);
|
|
432
|
+
// one group per page: this one, else by where it is now, whether its threads were found by key or path
|
|
433
|
+
const pages = new Map();
|
|
434
|
+
for (const t of threads) {
|
|
435
|
+
if (t.status !== filter)
|
|
436
|
+
continue;
|
|
437
|
+
const current = onThisPage.has(t.id);
|
|
438
|
+
const path = current ? location.pathname : t.pageKey ? (latest.get(t.pageKey) ?? t.path) : t.path;
|
|
439
|
+
const key = current ? "current" : path;
|
|
440
|
+
const page = pages.get(key) ?? { path, current, threads: [] };
|
|
441
|
+
page.threads.push(t);
|
|
442
|
+
pages.set(key, page);
|
|
443
|
+
}
|
|
444
|
+
if (!pages.size)
|
|
445
|
+
return _jsx("p", { className: "px-4 py-6 text-[12px] text-ink2", children: filter === "open" ? "No open comments on any page." : "No resolved comments on any page." });
|
|
446
|
+
const ordered = [...pages.values()].sort((a, b) => Number(b.current) - Number(a.current) || a.path.localeCompare(b.path));
|
|
447
|
+
return (_jsx(_Fragment, { children: ordered.map((p, i) => (_jsxs("section", { "aria-label": p.current ? `This page, ${p.path}` : p.path, className: cx(i > 0 && "border-t border-edge"), children: [_jsx("h3", { className: "flex items-baseline gap-2 px-4 pt-3 text-[12px] font-semibold text-ink", children: p.current ? (_jsxs(_Fragment, { children: ["This page ", _jsx("span", { className: "truncate font-normal text-ink2", children: p.path })] })) : (_jsx("a", { href: p.path, className: cx("truncate underline-offset-2 hover:underline", FOCUS), children: p.path })) }), _jsx(ThreadList, { threads: [...p.threads].reverse(), onOpen: onOpen })] }, `${p.path}${i}`))) }));
|
|
448
|
+
}
|
|
449
|
+
function ThisPage({ threads, located, filter, onOpen }) {
|
|
450
|
+
const shown = threads.filter((t) => t.status === filter);
|
|
451
|
+
// on the page in reading order; the ones whose anchor has gone, newest first, after them
|
|
452
|
+
const here = shown
|
|
453
|
+
.filter((t) => located.get(t.id))
|
|
454
|
+
.sort((a, b) => {
|
|
455
|
+
const ea = located.get(a.id);
|
|
456
|
+
const eb = located.get(b.id);
|
|
457
|
+
if (ea === eb)
|
|
458
|
+
return a.createdAt.localeCompare(b.createdAt);
|
|
459
|
+
return ea.compareDocumentPosition(eb) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
460
|
+
});
|
|
461
|
+
const gone = shown.filter((t) => !located.get(t.id));
|
|
462
|
+
return (_jsxs(_Fragment, { children: [!shown.length && (_jsx("p", { className: "px-4 py-6 text-[12px] text-ink2", children: filter === "open" ? "No open comments on this page. Choose Comment, then the part of the page it's about." : "No resolved comments on this page." })), here.length > 0 && _jsx(ThreadList, { threads: here, onOpen: onOpen }), gone.length > 0 && (_jsxs("section", { "aria-labelledby": "dt-comments-gone", className: "border-t border-edge", children: [_jsx("h3", { id: "dt-comments-gone", className: "px-4 pt-3 text-[12px] font-semibold text-ink", children: "No longer on this page" }), _jsx("p", { className: "px-4 pb-1 text-[12px] text-ink2", children: "What these were left on has moved or been removed." }), _jsx(ThreadList, { threads: gone, onOpen: onOpen, orphaned: true })] }))] }));
|
|
463
|
+
}
|
|
464
|
+
function ThreadList({ threads, onOpen, orphaned }) {
|
|
465
|
+
return (_jsx("ul", { className: "flex flex-col py-1", children: threads.map((t) => {
|
|
466
|
+
const first = t.comments[0];
|
|
467
|
+
const replies = t.comments.length - 1;
|
|
468
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", onClick: () => onOpen(t), className: cx("flex w-full cursor-pointer flex-col gap-1 px-4 py-2.5 text-left hover:bg-scrim", FOCUS), children: [_jsx("span", { className: "text-[12px] font-semibold text-ink", children: anchorName(t.anchor) }), first && _jsx("span", { className: "line-clamp-2 text-[13px] break-words text-ink", children: first.body }), _jsx("span", { className: "text-[11px] text-ink2", children: [first?.authorName, replies > 0 ? plural(replies, "reply", "replies") : null, ago(t.createdAt), orphaned && t.branch ? `on ${t.branch}` : null].filter(Boolean).join(" · ") })] }) }, t.id));
|
|
469
|
+
}) }));
|
|
470
|
+
}
|
|
471
|
+
function Gone({ headingRef, onBack }) {
|
|
472
|
+
return (_jsxs(_Fragment, { children: [_jsx(Header, { headingRef: headingRef, title: "Thread not found", back: onBack, onClose: onBack }), _jsx("p", { className: "px-4 py-6 text-[12px] text-ink2", children: "This thread isn't on this page." })] }));
|
|
473
|
+
}
|
|
474
|
+
function ThreadView({ headingRef, thread, orphaned, current, author, rememberName, api, onBack, onClose, onChange, announce, }) {
|
|
475
|
+
const [busy, setBusy] = useState(false);
|
|
476
|
+
const [error, setError] = useState(null);
|
|
477
|
+
const resolved = thread.status === "resolved";
|
|
478
|
+
const otherBranch = thread.branch && current && thread.branch !== current;
|
|
479
|
+
const [copied, setCopied] = useState(false);
|
|
480
|
+
useEffect(() => {
|
|
481
|
+
if (!copied)
|
|
482
|
+
return;
|
|
483
|
+
const t = setTimeout(() => setCopied(false), 2000);
|
|
484
|
+
return () => clearTimeout(t);
|
|
485
|
+
}, [copied]);
|
|
486
|
+
const copyPrompt = async () => {
|
|
487
|
+
setError(null);
|
|
488
|
+
try {
|
|
489
|
+
await navigator.clipboard.writeText(threadPrompt(thread, { origin: location.origin }));
|
|
490
|
+
setCopied(true);
|
|
491
|
+
announce("Prompt copied. Paste it into Claude.");
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
setError("Couldn't copy. The browser may not allow it on this page.");
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
const toggle = async () => {
|
|
498
|
+
// anyone can resolve; without a name yet, it's recorded as someone's, and nothing is remembered
|
|
499
|
+
const who = author ?? { name: "Someone", id: "anonymous" };
|
|
500
|
+
setBusy(true);
|
|
501
|
+
setError(null);
|
|
502
|
+
try {
|
|
503
|
+
const next = await api.setStatus(thread.id, resolved ? "open" : "resolved", who);
|
|
504
|
+
onChange(next);
|
|
505
|
+
announce(resolved ? "Thread reopened." : "Thread resolved.");
|
|
506
|
+
}
|
|
507
|
+
catch (e) {
|
|
508
|
+
setError(e.message);
|
|
509
|
+
}
|
|
510
|
+
finally {
|
|
511
|
+
setBusy(false);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
return (_jsxs(_Fragment, { children: [_jsx(Header, { headingRef: headingRef, title: anchorName(thread.anchor), back: onBack, onClose: onClose }), _jsxs("div", { className: SCROLL, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-2 gap-y-1 px-4 pt-3 text-[11px] text-ink2", children: [_jsx("span", { className: cx("rounded-full px-2 py-0.5 font-medium", resolved ? "bg-muted text-ink" : "bg-[#1d4ed8] text-white"), children: resolved ? "Resolved" : "Open" }), resolved && thread.resolvedBy && _jsxs("span", { children: ["by ", thread.resolvedBy] }), otherBranch && _jsxs("span", { children: ["Left on branch ", thread.branch] }), _jsxs("button", { type: "button", onClick: copyPrompt, className: cx(SECONDARY, "ml-auto"), title: "A prompt for Claude or another coding agent: the page, what this is on, the comments, and how to resolve it", children: [copied ? _jsx(Check, { "aria-hidden": true, width: 13, height: 13 }) : _jsx(Copy, { "aria-hidden": true, width: 13, height: 13 }), copied ? "Copied" : "Copy prompt"] })] }), orphaned && (_jsxs("p", { className: "mx-4 mt-3 rounded-md bg-muted px-3 py-2 text-[12px] text-ink", children: ["What this was left on isn't on this page any more.", " ", thread.deploymentUrl ? (_jsxs(_Fragment, { children: ["It was left on", " ", _jsx("a", { className: "text-ink underline underline-offset-2", href: `${thread.deploymentUrl}${thread.path}`, target: "_blank", rel: "noreferrer", children: thread.branch ? `the ${thread.branch} deployment` : "an earlier deployment" }), "."] })) : null] })), _jsx("ol", { className: "flex flex-col gap-3 px-4 py-3", children: thread.comments.map((c) => (_jsxs("li", { className: "flex flex-col gap-1", children: [_jsxs("p", { className: "flex items-baseline gap-2 text-[12px]", children: [_jsx("span", { className: "font-semibold text-ink", children: c.authorName }), _jsx("time", { dateTime: c.createdAt, title: new Date(c.createdAt).toLocaleString(), className: "text-[11px] text-ink2", children: ago(c.createdAt) })] }), _jsx("p", { className: "text-[13px] leading-[1.45] break-words whitespace-pre-wrap text-ink", children: c.body })] }, c.id))) })] }), _jsxs("div", { className: "flex flex-col gap-2 border-t border-edge p-3", children: [_jsx(Writer, { label: "Reply", send: "Reply", author: author, rememberName: rememberName, first: false, onSend: async (body, who) => {
|
|
515
|
+
const comment = await api.reply(thread.id, body, who);
|
|
516
|
+
onChange({ ...thread, comments: [...thread.comments, comment] });
|
|
517
|
+
announce("Reply added.");
|
|
518
|
+
}, children: _jsxs("button", { type: "button", onClick: toggle, disabled: busy, className: SECONDARY, children: [resolved ? _jsx(RotateCcw, { "aria-hidden": true, width: 13, height: 13 }) : _jsx(Check, { "aria-hidden": true, width: 13, height: 13 }), resolved ? "Reopen" : "Resolve"] }) }), error && (_jsx("p", { role: "alert", className: "text-[12px] text-fail", children: error }))] })] }));
|
|
519
|
+
}
|
|
520
|
+
function ComposeView({ headingRef, anchor, author, rememberName, onCancel, onClose, onSend, }) {
|
|
521
|
+
return (_jsxs(_Fragment, { children: [_jsx(Header, { headingRef: headingRef, title: `New comment on ${anchorName(anchor)}`, back: onCancel, onClose: onClose }), _jsx("div", { className: cx(SCROLL, "flex flex-col gap-2 p-3"), children: _jsx(Writer, { label: "Comment", send: "Send", author: author, rememberName: rememberName, first: true, onSend: onSend, rows: 5, children: _jsx("button", { type: "button", onClick: onCancel, className: SECONDARY, children: "Cancel" }) }) })] }));
|
|
522
|
+
}
|
|
523
|
+
/** A name field (until there's a name), a text box and a send button, with room for another action. */
|
|
524
|
+
function Writer({ label, send, author, rememberName, first, rows = 3, onSend, children, }) {
|
|
525
|
+
const id = useId();
|
|
526
|
+
const [name, setName] = useState("");
|
|
527
|
+
const [body, setBody] = useState("");
|
|
528
|
+
const [busy, setBusy] = useState(false);
|
|
529
|
+
const [error, setError] = useState(null);
|
|
530
|
+
const nameRef = useRef(null);
|
|
531
|
+
const bodyRef = useRef(null);
|
|
532
|
+
const submit = async (e) => {
|
|
533
|
+
e?.preventDefault();
|
|
534
|
+
if (busy)
|
|
535
|
+
return;
|
|
536
|
+
if (!author && !name.trim()) {
|
|
537
|
+
setError("Add your name, so people know who commented.");
|
|
538
|
+
nameRef.current?.focus();
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (!body.trim()) {
|
|
542
|
+
setError(`Write a ${label.toLowerCase()} first.`);
|
|
543
|
+
bodyRef.current?.focus();
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
setBusy(true);
|
|
547
|
+
setError(null);
|
|
548
|
+
try {
|
|
549
|
+
const who = author ?? rememberName(name);
|
|
550
|
+
await onSend(body.trim(), who);
|
|
551
|
+
setBody("");
|
|
552
|
+
}
|
|
553
|
+
catch (err) {
|
|
554
|
+
setError(err.message);
|
|
555
|
+
}
|
|
556
|
+
finally {
|
|
557
|
+
setBusy(false);
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const left = LIMITS.body - body.length;
|
|
561
|
+
return (_jsxs("form", { onSubmit: submit, className: "flex flex-col gap-2", noValidate: true, children: [!author && (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { htmlFor: `${id}-name`, className: "text-[12px] font-medium text-ink", children: "Your name" }), _jsx("input", { ref: nameRef, id: `${id}-name`, "data-first-field": first ? "" : undefined, className: INPUT, autoComplete: "name", maxLength: LIMITS.name, value: name, onChange: (e) => setName(e.target.value), "aria-describedby": `${id}-name-hint` }), _jsx("p", { id: `${id}-name-hint`, className: "text-[11px] text-ink2", children: "Shown with what you write. This browser remembers it." })] })), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { htmlFor: `${id}-body`, className: "text-[12px] font-medium text-ink", children: label }), _jsx("textarea", { ref: bodyRef, id: `${id}-body`, "data-first-field": first && author ? "" : undefined, className: cx(INPUT, "resize-y leading-[1.45]"), rows: rows, maxLength: LIMITS.body, value: body, onChange: (e) => setBody(e.target.value), onKeyDown: (e) => {
|
|
562
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
563
|
+
e.preventDefault();
|
|
564
|
+
submit();
|
|
565
|
+
}
|
|
566
|
+
}, "aria-describedby": `${id}-body-hint` }), _jsxs("p", { id: `${id}-body-hint`, className: "text-[11px] text-ink2", children: [left < 500 ? `${left} characters left. ` : "", "Ctrl or \u2318 Enter to send."] })] }), error && (_jsx("p", { role: "alert", className: "text-[12px] text-fail", children: error })), _jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("div", { className: "flex gap-2", children: children }), _jsx("button", { type: "submit", disabled: busy, className: PRIMARY, children: busy ? "Sending…" : send })] })] }));
|
|
567
|
+
}
|
|
568
|
+
/** Who you're commenting as, with a way to change it. */
|
|
569
|
+
function NameLine({ author, rememberName }) {
|
|
570
|
+
const [editing, setEditing] = useState(false);
|
|
571
|
+
const [name, setName] = useState(author?.name ?? "");
|
|
572
|
+
const id = useId();
|
|
573
|
+
if (!author)
|
|
574
|
+
return null;
|
|
575
|
+
if (editing)
|
|
576
|
+
return (_jsxs("form", { className: "flex items-end gap-2 border-t border-edge p-3", onSubmit: (e) => {
|
|
577
|
+
e.preventDefault();
|
|
578
|
+
if (name.trim())
|
|
579
|
+
rememberName(name);
|
|
580
|
+
setEditing(false);
|
|
581
|
+
}, children: [_jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsx("label", { htmlFor: id, className: "text-[12px] font-medium text-ink", children: "Your name" }), _jsx("input", { id: id, className: INPUT, autoComplete: "name", maxLength: LIMITS.name, value: name, onChange: (e) => setName(e.target.value) })] }), _jsx("button", { type: "submit", className: SECONDARY, children: "Save" })] }));
|
|
582
|
+
return (_jsxs("p", { className: "flex items-center gap-1 border-t border-edge px-4 py-2 text-[11px] text-ink2", children: ["Commenting as ", _jsx("span", { className: "font-medium text-ink", children: author.name }), _jsx("button", { type: "button", onClick: () => {
|
|
583
|
+
setName(author.name);
|
|
584
|
+
setEditing(true);
|
|
585
|
+
}, className: cx("ml-1 cursor-pointer rounded-sm px-1 text-ink underline underline-offset-2", FOCUS), children: "Change" })] }));
|
|
586
|
+
}
|
package/dist/css.d.ts
ADDED
package/dist/css.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const css = "/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600}}@layer utilities{.pointer-events-auto{pointer-events:auto}.visible{visibility:visible}.fixed{position:fixed}.bottom-4{bottom:16px}.left-4{left:16px}.m-3{margin:12px}.mx-4{margin-inline:16px}.mt-3{margin-top:12px}.ml-1{margin-left:4px}.ml-auto{margin-left:auto}.line-clamp-2{-webkit-line-clamp:2;-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden}.block{display:block}.flex{display:flex}.inline-flex{display:inline-flex}.table{display:table}.h-7{height:28px}.h-8{height:32px}.min-h-0{min-height:0}.w-full{width:100%}.min-w-0{min-width:0}.min-w-8{min-width:32px}.flex-1{flex:1}.cursor-pointer{cursor:pointer}.resize{resize:both}.resize-y{resize:vertical}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-baseline{align-items:baseline}.items-center{align-items:center}.items-end{align-items:flex-end}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-0\\.5{gap:2px}.gap-1{gap:4px}.gap-1\\.5{gap:6px}.gap-2{gap:8px}.gap-3{gap:12px}.gap-x-2{column-gap:8px}.gap-x-3{column-gap:12px}.gap-y-1{row-gap:4px}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:8px}.rounded-md{border-radius:6px}.rounded-sm{border-radius:4px}.rounded-xl{border-radius:12px}.rounded-t-xl{border-top-left-radius:12px;border-top-right-radius:12px}.rounded-b-xl{border-bottom-right-radius:12px;border-bottom-left-radius:12px}.rounded-bl-none{border-bottom-left-radius:0}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-x-0{border-inline-style:var(--tw-border-style);border-inline-width:0}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-t-0{border-top-style:var(--tw-border-style);border-top-width:0}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-b-0{border-bottom-style:var(--tw-border-style);border-bottom-width:0}.border-edge{border-color:var(--dt-edge)}.border-white{border-color:#fff}.bg-\\[\\#1d4ed8\\]{background-color:#1d4ed8}.bg-muted{background-color:var(--dt-muted)}.bg-page{background-color:var(--dt-page)}.p-1{padding:4px}.p-3{padding:12px}.px-1{padding-inline:4px}.px-2{padding-inline:8px}.px-2\\.5{padding-inline:10px}.px-3{padding-inline:12px}.px-4{padding-inline:16px}.py-0\\.5{padding-block:2px}.py-1{padding-block:4px}.py-2{padding-block:8px}.py-2\\.5{padding-block:10px}.py-3{padding-block:12px}.py-6{padding-block:24px}.pt-3{padding-top:12px}.pr-2{padding-right:8px}.pb-1{padding-bottom:4px}.pl-2{padding-left:8px}.text-left{text-align:left}.text-\\[11px\\]{font-size:11px}.text-\\[12px\\]{font-size:12px}.text-\\[13px\\]{font-size:13px}.leading-\\[1\\.45\\]{--tw-leading:1.45;line-height:1.45}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.break-words{overflow-wrap:break-word}.whitespace-pre-wrap{white-space:pre-wrap}.text-fail{color:var(--dt-fail)}.text-ink{color:var(--dt-ink)}.text-ink2{color:var(--dt-ink2)}.text-white{color:#fff}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,)}.underline{text-decoration-line:underline}.underline-offset-2{text-underline-offset:2px}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-2xl{--tw-shadow:0 25px 50px -12px var(--tw-shadow-color,#00000040);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a), 0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a), 0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-black\\/15{--tw-shadow-color:#00000026}@supports (color:color-mix(in lab, red, red)){.shadow-black\\/15{--tw-shadow-color:color-mix(in oklab, oklab(0% none none/.15) var(--tw-shadow-alpha), transparent)}}.shadow-black\\/20{--tw-shadow-color:#0003}@supports (color:color-mix(in lab, red, red)){.shadow-black\\/20{--tw-shadow-color:color-mix(in oklab, oklab(0% none none/.2) var(--tw-shadow-alpha), transparent)}}.shadow-black\\/25{--tw-shadow-color:#00000040}@supports (color:color-mix(in lab, red, red)){.shadow-black\\/25{--tw-shadow-color:color-mix(in oklab, oklab(0% none none/.25) var(--tw-shadow-alpha), transparent)}}.outline-2{outline-style:var(--tw-outline-style);outline-width:2px}.outline-offset-2{outline-offset:2px}.outline-\\[\\#1d4ed8\\]{outline-color:#1d4ed8}.filter{filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.outline-none{--tw-outline-style:none;outline-style:none}.placeholder\\:text-ink2::placeholder{color:var(--dt-ink2)}@media (hover:hover){.hover\\:bg-\\[\\#1e40af\\]:hover{background-color:#1e40af}.hover\\:bg-scrim:hover{background-color:var(--dt-scrim)}.hover\\:underline:hover{text-decoration-line:underline}}.focus\\:border-sel:focus{border-color:var(--dt-sel)}.focus\\:outline-2:focus{outline-style:var(--tw-outline-style);outline-width:2px}.focus\\:-outline-offset-1:focus{outline-offset:calc(1px * -1)}.focus\\:outline-sel:focus{outline-color:var(--dt-sel)}.focus-visible\\:outline-2:focus-visible{outline-style:var(--tw-outline-style);outline-width:2px}.focus-visible\\:outline-offset-2:focus-visible{outline-offset:2px}.focus-visible\\:outline-\\[\\#1d4ed8\\]:focus-visible{outline-color:#1d4ed8}.disabled\\:cursor-default:disabled{cursor:default}.disabled\\:opacity-50:disabled{opacity:.5}.aria-expanded\\:bg-scrim[aria-expanded=true]{background-color:var(--dt-scrim)}.aria-pressed\\:bg-muted[aria-pressed=true]{background-color:var(--dt-muted)}.aria-pressed\\:bg-scrim[aria-pressed=true]{background-color:var(--dt-scrim)}.aria-pressed\\:text-ink[aria-pressed=true]{color:var(--dt-ink)}}:host{all:initial}.dt-base{all:initial;--dt-page:#fff;--dt-raised:#f8f8f9;--dt-muted:#f0f0f2;--dt-edge:#e4e4e7;--dt-ink:#09090b;--dt-ink2:#71717a;--dt-ink3:#a1a1aa;--dt-sel:#3b82f6;--dt-scrim:#0000000f;--dt-ok:#16a34a;--dt-warn:#d97706;--dt-fail:#dc2626;--dt-icon:oklch(55% 0 0);color-scheme:light;font-family:var(--font-sans);letter-spacing:normal;text-align:left;cursor:auto;color:var(--dt-ink);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-size:11px;font-weight:400;line-height:1.4;display:contents}.dt-base[data-theme=dark]{--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}@media (prefers-color-scheme:dark){.dt-base:not([data-theme=light]){--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}}input[type=number]::-webkit-inner-spin-button{appearance:none;margin:0}input[type=number]::-webkit-outer-spin-button{appearance:none;margin:0}\n";
|
|
2
|
+
export const properties = "@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}\n@property --tw-leading{syntax:\"*\";inherits:false}\n@property --tw-font-weight{syntax:\"*\";inherits:false}\n@property --tw-ordinal{syntax:\"*\";inherits:false}\n@property --tw-slashed-zero{syntax:\"*\";inherits:false}\n@property --tw-numeric-figure{syntax:\"*\";inherits:false}\n@property --tw-numeric-spacing{syntax:\"*\";inherits:false}\n@property --tw-numeric-fraction{syntax:\"*\";inherits:false}\n@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-ring-color{syntax:\"*\";inherits:false}\n@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-ring-color{syntax:\"*\";inherits:false}\n@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-ring-inset{syntax:\"*\";inherits:false}\n@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}\n@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}\n@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-outline-style{syntax:\"*\";inherits:false;initial-value:solid}\n@property --tw-blur{syntax:\"*\";inherits:false}\n@property --tw-brightness{syntax:\"*\";inherits:false}\n@property --tw-contrast{syntax:\"*\";inherits:false}\n@property --tw-grayscale{syntax:\"*\";inherits:false}\n@property --tw-hue-rotate{syntax:\"*\";inherits:false}\n@property --tw-invert{syntax:\"*\";inherits:false}\n@property --tw-opacity{syntax:\"*\";inherits:false}\n@property --tw-saturate{syntax:\"*\";inherits:false}\n@property --tw-sepia{syntax:\"*\";inherits:false}\n@property --tw-drop-shadow{syntax:\"*\";inherits:false}\n@property --tw-drop-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-drop-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-drop-shadow-size{syntax:\"*\";inherits:false}";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Author } from "./types.js";
|
|
2
|
+
/** The remembered author, or null before a name has been given. */
|
|
3
|
+
export declare function readAuthor(): Author | null;
|
|
4
|
+
/** Remember a name, keeping the id this browser already has. Kept in memory when storage is blocked. */
|
|
5
|
+
export declare function rememberName(name: string): Author;
|
|
6
|
+
export declare function useAuthor(): [Author | null, (name: string) => Author];
|