@karimsa/mdxserve 0.5.1 → 0.6.0-rc.2

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.
Files changed (41) hide show
  1. package/README.md +3 -0
  2. package/client/DocView.tsx +26 -14
  3. package/client/ListingView.tsx +3 -3
  4. package/client/MdSection.tsx +14 -9
  5. package/client/RenderErrorBoundary.tsx +20 -5
  6. package/client/Settings.tsx +26 -21
  7. package/client/app.css +20 -0
  8. package/client/comments/CommentsPanel.tsx +194 -0
  9. package/client/comments/CommentsPopover.tsx +197 -0
  10. package/client/comments/CommentsSheet.tsx +63 -0
  11. package/client/comments/CommentsSidebar.tsx +24 -0
  12. package/client/comments/CtlButton.tsx +33 -0
  13. package/client/comments/DraftThread.tsx +86 -0
  14. package/client/comments/GutterCounters.tsx +121 -0
  15. package/client/comments/ReplyField.tsx +98 -0
  16. package/client/comments/SelectionButton.tsx +142 -0
  17. package/client/comments/Thread.tsx +308 -0
  18. package/client/comments/anchor.ts +204 -0
  19. package/client/comments/data.ts +98 -0
  20. package/client/comments/dom.ts +212 -0
  21. package/client/comments/drafts.ts +36 -0
  22. package/client/comments/highlights.ts +83 -0
  23. package/client/comments/model.ts +241 -0
  24. package/client/comments/motion.ts +44 -0
  25. package/client/comments/pins.ts +37 -0
  26. package/client/comments/self-writes.ts +22 -0
  27. package/client/comments/state.ts +67 -0
  28. package/client/comments/time.ts +21 -0
  29. package/client/entry.tsx +10 -0
  30. package/client/hooks.ts +19 -0
  31. package/client/platform.ts +8 -0
  32. package/client/router.ts +5 -0
  33. package/client/shell/AppShell.tsx +85 -15
  34. package/client/shell/StandaloneShell.tsx +3 -2
  35. package/client/shell/TopBar.tsx +25 -0
  36. package/client/ui/ConfirmDeleteDialog.tsx +1 -1
  37. package/client/ui/Toast.tsx +5 -1
  38. package/client/ui/icon-set.ts +10 -0
  39. package/dist/cli.js +872 -229
  40. package/package.json +1 -1
  41. package/skills/mdxserve/SKILL.md +86 -0
@@ -0,0 +1,44 @@
1
+ import type { Transition } from "framer-motion";
2
+ import { TRANSITIONS } from "../motion";
3
+
4
+ const INSTANT: Transition = { duration: 0 };
5
+
6
+ /**
7
+ * A row that makes room for itself: threads in the panel and messages in a
8
+ * thread. The element needs `overflow-hidden`, and its spacing has to be
9
+ * padding inside it, or the list jumps by the margin when the row appears.
10
+ * With reduced motion the height change is instant and only the fade remains.
11
+ */
12
+ export function rowMotion(reducedMotion: boolean | null) {
13
+ return {
14
+ initial: { opacity: 0, height: 0 },
15
+ animate: { opacity: 1, height: "auto" },
16
+ exit: {
17
+ opacity: 0,
18
+ height: 0,
19
+ transition: reducedMotion ? INSTANT : TRANSITIONS.base,
20
+ },
21
+ transition: reducedMotion
22
+ ? { height: INSTANT, opacity: TRANSITIONS.base }
23
+ : { height: TRANSITIONS.glide, opacity: TRANSITIONS.slow },
24
+ };
25
+ }
26
+
27
+ /**
28
+ * `TRANSITIONS.glide` with the damping raised to critical. A width must not
29
+ * overshoot: a spring closing to 0 dips negative, CSS drops the invalid value,
30
+ * and the column sits a few pixels wide until the spring settles.
31
+ */
32
+ const DOCK: Transition = { type: "spring", stiffness: 340, damping: 36, mass: 0.9 };
33
+
34
+ /** A docked column whose width opens and closes, taking the space from its neighbours. */
35
+ export function dockMotion(width: number | "auto", reducedMotion: boolean | null) {
36
+ return {
37
+ initial: { width: 0, opacity: 0 },
38
+ animate: { width, opacity: 1 },
39
+ exit: { width: 0, opacity: 0 },
40
+ transition: reducedMotion
41
+ ? { width: INSTANT, opacity: TRANSITIONS.fast }
42
+ : { width: DOCK, opacity: TRANSITIONS.base },
43
+ };
44
+ }
@@ -0,0 +1,37 @@
1
+ /** Pure placement of the gutter counters. */
2
+
3
+ export interface PinAnchor {
4
+ id: string;
5
+ /** Top of the anchor's first line, in the pins' coordinate space. */
6
+ top: number;
7
+ /** Height of that line. */
8
+ height: number;
9
+ }
10
+
11
+ export interface PlacedPin {
12
+ id: string;
13
+ top: number;
14
+ }
15
+
16
+ /**
17
+ * Centres each pin on its anchor line, then pushes pins down so none overlaps
18
+ * the one above it by less than `gap`. Input order does not matter; output is
19
+ * in top-to-bottom order.
20
+ */
21
+ export function layoutPins(anchors: readonly PinAnchor[], size: number, gap: number): PlacedPin[] {
22
+ const sorted = [...anchors].sort((left, right) => left.top - right.top);
23
+ const placed: PlacedPin[] = [];
24
+ let floor = Number.NEGATIVE_INFINITY;
25
+ for (const anchor of sorted) {
26
+ const top = Math.max(anchor.top + (anchor.height - size) / 2, floor);
27
+ placed.push({ id: anchor.id, top });
28
+ floor = top + size + gap;
29
+ }
30
+ return placed;
31
+ }
32
+
33
+ /** Left edge for a pin: just right of the doc column, kept inside the viewport. */
34
+ export function pinLeft(columnRight: number, pinWidth: number, viewportWidth: number): number {
35
+ const margin = 8;
36
+ return Math.max(0, Math.min(columnRight + margin, viewportWidth - pinWidth - margin));
37
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Paths this tab just wrote comments to. The "Reloaded" toast consults it so the
3
+ * author's own comment write does not announce a reload. Imports nothing, so
4
+ * Toast.tsx and the comment code can share it without a cycle.
5
+ */
6
+ export const SELF_WRITE_WINDOW_MS = 2000;
7
+
8
+ const writes = new Map<string, number>();
9
+
10
+ export function markSelfWrite(path: string, now: number = Date.now()): void {
11
+ writes.set(path, now + SELF_WRITE_WINDOW_MS);
12
+ }
13
+
14
+ export function isSelfWrite(path: string, now: number = Date.now()): boolean {
15
+ const until = writes.get(path);
16
+ if (until === undefined) return false;
17
+ if (now >= until) {
18
+ writes.delete(path);
19
+ return false;
20
+ }
21
+ return true;
22
+ }
@@ -0,0 +1,67 @@
1
+ import { atom } from "jotai";
2
+ import { atomWithStorage } from "jotai/utils";
3
+ import type { AnchorFields } from "./anchor";
4
+ import type { ReplyDrafts } from "./drafts";
5
+
6
+ /** Desktop sidebar open state; persisted. Takes the table-of-contents rail's place while open. */
7
+ export const commentsOpenAtom = atomWithStorage<boolean>(
8
+ "mdxserve.comments.open",
9
+ false,
10
+ undefined,
11
+ {
12
+ getOnInit: true,
13
+ },
14
+ );
15
+
16
+ /** Phone sheet open state; never persisted, or the sheet would cover the page on every load. */
17
+ export const commentsSheetOpenAtom = atom(false);
18
+
19
+ /** The focused thread, drawn with the active highlight and marked in the panel. */
20
+ export const activeThreadAtom = atom<string | null>(null);
21
+
22
+ /** The thread shown in the popover (desktop, sidebar closed). */
23
+ export const popoverThreadAtom = atom<string | null>(null);
24
+
25
+ /** Unsent reply text per thread; lives as long as the doc stays open. */
26
+ export const replyDraftsAtom = atom<ReplyDrafts>({});
27
+
28
+ export interface CommentDraft {
29
+ anchor: AnchorFields;
30
+ /** The selected text in the page, so the popover can sit under it. */
31
+ range: Range | null;
32
+ body: string;
33
+ /** Bumped on every press of the selection button so the composer refocuses. */
34
+ nonce: number;
35
+ }
36
+
37
+ export const draftAtom = atom<CommentDraft | null>(null);
38
+
39
+ /**
40
+ * The thread this tab just created, until something draws it. The popover
41
+ * animates that thread's first message in, so a sent comment visibly lands;
42
+ * a thread opened any other way appears as it is.
43
+ */
44
+ export const freshThreadAtom = atom<string | null>(null);
45
+
46
+ /**
47
+ * Replies and new comments being saved, by key (`pendingReplyKey`, `pendingDraftKey`).
48
+ * Shared, not component state: a thread or composer that remounts mid-save must
49
+ * still see its own send as pending, or the same text could be sent twice.
50
+ */
51
+ export const pendingSendsAtom = atom<ReadonlySet<string>>(new Set<string>());
52
+
53
+ export function pendingReplyKey(path: string, threadId: string): string {
54
+ return `reply:${path}:${threadId}`;
55
+ }
56
+
57
+ export function withPendingSend(
58
+ pending: ReadonlySet<string>,
59
+ key: string,
60
+ active: boolean,
61
+ ): ReadonlySet<string> {
62
+ if (pending.has(key) === active) return pending;
63
+ const next = new Set(pending);
64
+ if (active) next.add(key);
65
+ else next.delete(key);
66
+ return next;
67
+ }
@@ -0,0 +1,21 @@
1
+ const MINUTE = 60;
2
+ const HOUR = 60 * MINUTE;
3
+ const DAY = 24 * HOUR;
4
+ const WEEK = 7 * DAY;
5
+
6
+ /**
7
+ * A compact age for a message header: "now", "12m", "3h", "2d", then a short
8
+ * date ("Nov 24") once it is a week old. Empty for a missing or unparsable
9
+ * timestamp. The full date and time is on the element's title.
10
+ */
11
+ export function relativeTime(iso: string | undefined, now: number = Date.now()): string {
12
+ if (!iso) return "";
13
+ const then = Date.parse(iso);
14
+ if (Number.isNaN(then)) return "";
15
+ const elapsed = Math.round((now - then) / 1000);
16
+ if (elapsed < 45) return "now";
17
+ if (elapsed < HOUR) return `${Math.max(1, Math.floor(elapsed / MINUTE))}m`;
18
+ if (elapsed < DAY) return `${Math.floor(elapsed / HOUR)}h`;
19
+ if (elapsed < WEEK) return `${Math.floor(elapsed / DAY)}d`;
20
+ return new Date(then).toLocaleDateString(undefined, { month: "short", day: "numeric" });
21
+ }
package/client/entry.tsx CHANGED
@@ -49,5 +49,15 @@ function main() {
49
49
  main();
50
50
 
51
51
  if (import.meta.hot) {
52
+ // Every doc module exports `__mdxserveMetadata` (src/rendering/mdx/remark-metadata.ts)
53
+ // beside its component. Fast Refresh rejects a module with a non-component
54
+ // export whose value changed, and a doc has no static importer to fall back
55
+ // on, so without this every write to a doc — a comment included — reloads
56
+ // the whole page. The router's `mdxserve:doc-changed` handler re-imports the
57
+ // doc, so new metadata still arrives.
58
+ (
59
+ window as Window & { __getReactRefreshIgnoredExports?: () => string[] }
60
+ ).__getReactRefreshIgnoredExports = () => ["__mdxserveMetadata"];
61
+
52
62
  import.meta.hot.accept();
53
63
  }
package/client/hooks.ts CHANGED
@@ -1,4 +1,7 @@
1
+ import { useAtomValue } from "jotai";
1
2
  import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
3
+ import { COMPACT_MEDIA } from "./platform";
4
+ import { contentLayoutAtom } from "./state";
2
5
 
3
6
  /** Returns `value`, updated only after it has stayed unchanged for `delayMs`. */
4
7
  export function useDebounced<Value>(value: Value, delayMs: number): Value {
@@ -32,3 +35,19 @@ export function useMediaQuery(query: string, serverDefault = false): boolean {
32
35
  () => serverDefault,
33
36
  );
34
37
  }
38
+
39
+ /** Whether the viewport is phone-sized, in either orientation. */
40
+ export function useCompactScreen(): boolean {
41
+ return useMediaQuery(COMPACT_MEDIA);
42
+ }
43
+
44
+ /**
45
+ * Whether content fills the available width. Phones always do, whatever the
46
+ * saved preference says; the preference itself is left untouched so it
47
+ * applies again on a larger screen.
48
+ */
49
+ export function useFullWidth(): boolean {
50
+ const layout = useAtomValue(contentLayoutAtom);
51
+ const compact = useCompactScreen();
52
+ return compact || layout === "full-width";
53
+ }
@@ -14,3 +14,11 @@ export function isApplePlatform(): boolean {
14
14
  * screen by every component that adapts its layout.
15
15
  */
16
16
  export const DESKTOP_MEDIA = "(min-width: 768px)";
17
+
18
+ /**
19
+ * A phone in either orientation: narrower than the desktop breakpoint, or a
20
+ * touch screen too short to be anything but a landscape phone (tablets are
21
+ * never under ~740px tall). Layout preferences that only make sense with room
22
+ * to spare are overridden here.
23
+ */
24
+ export const COMPACT_MEDIA = "(max-width: 767px), (pointer: coarse) and (max-height: 500px)";
package/client/router.ts CHANGED
@@ -383,6 +383,11 @@ export function useRouter(initialRoute: Route) {
383
383
  if (!import.meta.hot) return;
384
384
  const handleDocChanged = (data: { files?: Array<{ path: string }> }) => {
385
385
  for (const file of data?.files ?? []) {
386
+ // An agent's reply lives in the frontmatter, so refetch the comments too.
387
+ void queryClient.invalidateQueries({
388
+ ...trpc.getDocComments.queryFilter({ path: file.path }),
389
+ refetchType: "all",
390
+ });
386
391
  if (!docModuleCache.has(file.path)) continue;
387
392
  void ensureDocModule(file.path, true).then(() => {
388
393
  setRoute((current) =>
@@ -1,12 +1,12 @@
1
1
  import { DiagramPreferences } from "../diagrams/Preferences";
2
- import { AnimatePresence, motion, useSpring } from "framer-motion";
2
+ import { AnimatePresence, motion, useReducedMotion, useSpring } from "framer-motion";
3
3
  import { useAtomValue } from "jotai";
4
4
  import { keepPreviousData, useQuery } from "@tanstack/react-query";
5
5
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
6
6
  import { trpc } from "../api";
7
7
  import { DocView } from "../DocView";
8
8
  import { HomeView } from "../HomeView";
9
- import { useDebounced } from "../hooks";
9
+ import { useDebounced, useFullWidth, useMediaQuery } from "../hooks";
10
10
  import { ListingView } from "../ListingView";
11
11
  import { fadeRise, TRANSITIONS } from "../motion";
12
12
  import { useTheme } from "../theme";
@@ -22,6 +22,13 @@ import {
22
22
  import type { ExportFormat } from "../../src/export/service";
23
23
  import { exportDocFromViewer } from "../export-doc";
24
24
  import { Breadcrumb, type BreadcrumbItem } from "../ui/Breadcrumb";
25
+ import { CommentsPopover } from "../comments/CommentsPopover";
26
+ import { CommentsSheet } from "../comments/CommentsSheet";
27
+ import { COMMENTS_SIDEBAR_WIDTH, CommentsSidebar } from "../comments/CommentsSidebar";
28
+ import { GutterCounters } from "../comments/GutterCounters";
29
+ import { useCommentsModel, useCommentsPanel } from "../comments/model";
30
+ import { dockMotion } from "../comments/motion";
31
+ import { SelectionButton } from "../comments/SelectionButton";
25
32
  import { PageNav, type PageNavLink } from "../ui/PageNav";
26
33
  import { SearchDialog, type SearchResult } from "../ui/SearchDialog";
27
34
  import { Footer } from "./Footer";
@@ -31,13 +38,7 @@ import { TocRail } from "./TocRail";
31
38
  import { TopBar } from "./TopBar";
32
39
  import { useContentWidth, useDocMaxWidth } from "./use-doc-width";
33
40
  import { DESKTOP_MEDIA } from "../platform";
34
- import {
35
- contentLayoutAtom,
36
- docWidthAtom,
37
- LISTING_MAX_WIDTH,
38
- LISTING_MIN_WIDTH,
39
- listingWidthAtom,
40
- } from "../state";
41
+ import { docWidthAtom, LISTING_MAX_WIDTH, LISTING_MIN_WIDTH, listingWidthAtom } from "../state";
41
42
 
42
43
  function sidebarStorageKey(): string {
43
44
  // Keep hosted navigation preferences separate from local reader defaults.
@@ -177,12 +178,15 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
177
178
 
178
179
  const [desktopOpen, setDesktopOpen] = useState(readStoredSidebarOpen);
179
180
  const [mobileOpen, setMobileOpen] = useState(false);
181
+ // Tracks rotation and resizes across the dock/drawer breakpoint, so the
182
+ // toggle and its pressed state always describe the layout on screen.
183
+ const isDesktop = useMediaQuery(DESKTOP_MEDIA, true);
180
184
 
181
185
  const [searchOpen, setSearchOpen] = useState(false);
182
186
  const [exporting, setExporting] = useState(false);
183
187
  const listingWidth = useAtomValue(listingWidthAtom);
184
188
  const docWidth = useAtomValue(docWidthAtom);
185
- const fullWidth = useAtomValue(contentLayoutAtom) === "full-width";
189
+ const fullWidth = useFullWidth();
186
190
  const contentRef = useRef<HTMLDivElement>(null);
187
191
  const contentWidth = useContentWidth(contentRef);
188
192
  const listingMaxWidth = useListingMaxWidth(contentWidth, listingWidth);
@@ -213,6 +217,15 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
213
217
  }
214
218
  }, []);
215
219
 
220
+ const comments = useCommentsModel(route.kind === "doc" ? route.path : null, tocVersion);
221
+ const commentsPanel = useCommentsPanel();
222
+ // The sidebar is docked beside <main>; the table-of-contents rail is hidden while it is open.
223
+ const commentsOpen = comments.available && commentsPanel.open;
224
+ const commentsSidebarOpen = comments.available && commentsPanel.sidebarOpen;
225
+ const setCommentsOpen = commentsPanel.setOpen;
226
+ const closeComments = useCallback(() => setCommentsOpen(false), [setCommentsOpen]);
227
+ const reducedMotion = useReducedMotion();
228
+
216
229
  useEffect(() => {
217
230
  try {
218
231
  localStorage.setItem(sidebarStorageKey(), desktopOpen ? "1" : "0");
@@ -230,6 +243,12 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
230
243
  setMobileOpen(false);
231
244
  }, [activePath]);
232
245
 
246
+ // Widening past the breakpoint docks the sidebar; a drawer left open on the
247
+ // narrow layout must not reappear the next time the screen narrows.
248
+ useEffect(() => {
249
+ if (isDesktop) setMobileOpen(false);
250
+ }, [isDesktop]);
251
+
233
252
  // One export at a time: the trigger is disabled while a build runs, and the
234
253
  // server queues builds anyway (see startServer).
235
254
  const handleExport = useCallback(
@@ -246,7 +265,7 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
246
265
  );
247
266
 
248
267
  const handleToggleSidebar = useCallback(() => {
249
- if (window.matchMedia(DESKTOP_MEDIA).matches) {
268
+ if (isDesktop) {
250
269
  // A click here would otherwise silently flip (and persist) the
251
270
  // preference for the next doc.
252
271
  if (sidebarHidden) return;
@@ -254,7 +273,7 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
254
273
  } else {
255
274
  setMobileOpen((previous) => !previous);
256
275
  }
257
- }, [sidebarHidden]);
276
+ }, [isDesktop, sidebarHidden]);
258
277
 
259
278
  // Global ⌘K / Ctrl+K to open search, from anywhere on the page.
260
279
  useEffect(() => {
@@ -312,7 +331,7 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
312
331
  const showSidebar = desktopOpen && !sidebarHidden;
313
332
 
314
333
  return (
315
- <div className="min-h-screen bg-surface-page">
334
+ <div className="relative min-h-screen bg-surface-page">
316
335
  <AnimatePresence>
317
336
  {diagramPreferences && (
318
337
  <DiagramPreferences
@@ -325,7 +344,12 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
325
344
  onDiagramPreferences={() => setDiagramPreferences(true)}
326
345
  homeHref="/"
327
346
  hostLabel={location.host}
328
- sidebar={{ open: showSidebar || mobileOpen, onToggle: handleToggleSidebar }}
347
+ sidebar={{
348
+ // Only the docked sidebar shows a pressed toggle; on a phone the
349
+ // drawer covers the bar, and a pressed state just looks stuck.
350
+ open: isDesktop && showSidebar,
351
+ onToggle: handleToggleSidebar,
352
+ }}
329
353
  search={{ onOpen: () => setSearchOpen(true) }}
330
354
  exportDoc={
331
355
  route.kind === "doc" && shellInfo.permissions !== "restricted" && shellInfo.sameMachine
@@ -334,6 +358,15 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
334
358
  }
335
359
  theme={theme}
336
360
  onToggleTheme={toggle}
361
+ comments={
362
+ route.kind === "doc" && comments.available
363
+ ? {
364
+ count: comments.openCount,
365
+ open: commentsOpen,
366
+ onToggle: () => commentsPanel.setOpen(!commentsPanel.open),
367
+ }
368
+ : undefined
369
+ }
337
370
  />
338
371
  <div className="flex items-start">
339
372
  <Sidebar
@@ -408,9 +441,46 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
408
441
  </motion.div>
409
442
  </AnimatePresence>
410
443
  </div>
411
- {route.kind === "doc" ? <TocRail path={route.path} version={tocVersion} /> : null}
444
+ {/* The comments sidebar takes the rail's place. Both are width-animated
445
+ wrappers, so the centred doc slides between the two layouts rather
446
+ than jumping. `overflow-x-clip`, not `hidden`: it must not become
447
+ the scroll container the sticky column inside sticks to. */}
448
+ <AnimatePresence initial={false}>
449
+ {route.kind === "doc" && !commentsSidebarOpen ? (
450
+ <motion.div
451
+ key="toc-rail"
452
+ data-print-hide
453
+ {...dockMotion("auto", reducedMotion)}
454
+ className="hidden shrink-0 self-stretch overflow-x-clip xl:block"
455
+ >
456
+ <TocRail path={route.path} version={tocVersion} />
457
+ </motion.div>
458
+ ) : null}
459
+ </AnimatePresence>
412
460
  </main>
461
+ <AnimatePresence initial={false}>
462
+ {route.kind === "doc" && commentsSidebarOpen ? (
463
+ <motion.div
464
+ key="comments-sidebar"
465
+ data-print-hide
466
+ {...dockMotion(COMMENTS_SIDEBAR_WIDTH, reducedMotion)}
467
+ className="shrink-0 self-stretch overflow-x-clip"
468
+ >
469
+ <CommentsSidebar model={comments} onClose={closeComments} />
470
+ </motion.div>
471
+ ) : null}
472
+ </AnimatePresence>
413
473
  </div>
474
+ {route.kind === "doc" && comments.available && !commentsPanel.isDesktop ? (
475
+ <CommentsSheet model={comments} open={commentsPanel.open} onClose={closeComments} />
476
+ ) : null}
477
+ {route.kind === "doc" && commentsPanel.isDesktop ? (
478
+ <>
479
+ {comments.available && !commentsSidebarOpen ? <GutterCounters model={comments} /> : null}
480
+ <CommentsPopover model={comments} sidebarOpen={commentsSidebarOpen} />
481
+ </>
482
+ ) : null}
483
+ {route.kind === "doc" && !comments.readOnly ? <SelectionButton model={comments} /> : null}
414
484
  <SearchDialog
415
485
  open={searchOpen}
416
486
  query={query}
@@ -6,7 +6,8 @@ import { DocView } from "../DocView";
6
6
  import { fadeRise } from "../motion";
7
7
  import { useTheme } from "../theme";
8
8
  import { docModuleCache } from "../doc-module-cache";
9
- import { contentLayoutAtom, docWidthAtom } from "../state";
9
+ import { docWidthAtom } from "../state";
10
+ import { useFullWidth } from "../hooks";
10
11
  import { Footer } from "./Footer";
11
12
  import { TocRail } from "./TocRail";
12
13
  import { TopBar } from "./TopBar";
@@ -24,7 +25,7 @@ export function StandaloneShell({ meta }: { meta: StandaloneMeta }) {
24
25
  const [settingsOpen, setSettingsOpen] = useState(false);
25
26
  const [tocVersion, setTocVersion] = useState(0);
26
27
  const docWidth = useAtomValue(docWidthAtom);
27
- const fullWidth = useAtomValue(contentLayoutAtom) === "full-width";
28
+ const fullWidth = useFullWidth();
28
29
  const contentRef = useRef<HTMLDivElement>(null);
29
30
  const contentWidth = useContentWidth(contentRef);
30
31
  const docMaxWidth = useDocMaxWidth(contentWidth, docWidth);
@@ -45,6 +45,7 @@ export function TopBar({
45
45
  theme,
46
46
  onToggleTheme,
47
47
  onDiagramPreferences,
48
+ comments,
48
49
  }: {
49
50
  /** Wordmark's link target; undefined renders it as a plain (non-link) span. */
50
51
  homeHref?: string;
@@ -59,6 +60,8 @@ export function TopBar({
59
60
  theme: Theme;
60
61
  onToggleTheme: () => void;
61
62
  onDiagramPreferences?: () => void;
63
+ /** Comments panel toggle (doc pages); omitted when undefined. */
64
+ comments?: { count: number; open: boolean; onToggle: () => void };
62
65
  }) {
63
66
  const mac = isApplePlatform();
64
67
 
@@ -77,6 +80,8 @@ export function TopBar({
77
80
  label="Toggle sidebar"
78
81
  size="sm"
79
82
  active={sidebar.open}
83
+ // No grey flash on tap in mobile Safari.
84
+ className="[-webkit-tap-highlight-color:transparent]"
80
85
  onClick={sidebar.onToggle}
81
86
  />
82
87
  ) : null}
@@ -115,6 +120,26 @@ export function TopBar({
115
120
  onChange={(format) => exportDoc.onExport(format as ExportFormat)}
116
121
  />
117
122
  ) : null}
123
+ {comments ? (
124
+ <span className="relative inline-flex shrink-0">
125
+ <IconButton
126
+ icon="message-square"
127
+ label={comments.count > 0 ? `Comments (${comments.count} open)` : "Comments"}
128
+ size="sm"
129
+ active={comments.open}
130
+ className="max-md:h-11 max-md:w-11"
131
+ onClick={comments.onToggle}
132
+ />
133
+ {comments.count > 0 ? (
134
+ <span
135
+ aria-hidden
136
+ className="pointer-events-none absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-pill bg-surface-accent px-1 text-[10px] font-semibold leading-none text-n-0 tabular-nums"
137
+ >
138
+ {comments.count > 99 ? "99+" : comments.count}
139
+ </span>
140
+ ) : null}
141
+ </span>
142
+ ) : null}
118
143
  {onDiagramPreferences && (
119
144
  <IconButton icon="settings" label="Settings" size="sm" onClick={onDiagramPreferences} />
120
145
  )}
@@ -26,7 +26,7 @@ export function ConfirmDeleteDialog({
26
26
  placement="top"
27
27
  role="alertdialog"
28
28
  aria-labelledby="confirm-delete-title"
29
- className="w-[560px] overflow-hidden"
29
+ className="w-[560px] max-w-[calc(100vw-2rem)] overflow-hidden"
30
30
  >
31
31
  <div className="flex items-center gap-2 border-b border-border-subtle px-4 py-3">
32
32
  <Icon name="trash-2" size="md" className="text-status-danger-fg" />
@@ -11,6 +11,7 @@ import {
11
11
  import { Icon } from "./Icon";
12
12
  import { nextCount } from "./toast-count";
13
13
  import { docModuleCache } from "../doc-module-cache";
14
+ import { isSelfWrite } from "../comments/self-writes";
14
15
 
15
16
  export type ToastTone = "info" | "ok" | "warn" | "danger";
16
17
 
@@ -148,7 +149,10 @@ export function ToastStack() {
148
149
  const handleDocChanged = (data: {
149
150
  files?: Array<{ path: string; root: string; rel: string }>;
150
151
  }) => {
151
- const files = (data?.files ?? []).filter((file) => docModuleCache.has(file.path));
152
+ // A comment this tab just wrote is not an outside change to announce.
153
+ const files = (data?.files ?? []).filter(
154
+ (file) => docModuleCache.has(file.path) && !isSelfWrite(file.path),
155
+ );
152
156
  const [first] = files;
153
157
  if (!first) return;
154
158
  if (files.length === 1) {
@@ -50,16 +50,21 @@ import Info from "lucide-react/dist/esm/icons/info.mjs";
50
50
  import Lightbulb from "lucide-react/dist/esm/icons/lightbulb.mjs";
51
51
  import ListChecks from "lucide-react/dist/esm/icons/list-checks.mjs";
52
52
  import Maximize from "lucide-react/dist/esm/icons/maximize.mjs";
53
+ import MessageSquare from "lucide-react/dist/esm/icons/message-square.mjs";
53
54
  import Minus from "lucide-react/dist/esm/icons/minus.mjs";
54
55
  import Moon from "lucide-react/dist/esm/icons/moon.mjs";
55
56
  import OctagonAlert from "lucide-react/dist/esm/icons/octagon-alert.mjs";
56
57
  import PanelLeft from "lucide-react/dist/esm/icons/panel-left.mjs";
58
+ import PanelRight from "lucide-react/dist/esm/icons/panel-right.mjs";
57
59
  import Pencil from "lucide-react/dist/esm/icons/pencil.mjs";
58
60
  import Plus from "lucide-react/dist/esm/icons/plus.mjs";
61
+ import RotateCcw from "lucide-react/dist/esm/icons/rotate-ccw.mjs";
59
62
  import Search from "lucide-react/dist/esm/icons/search.mjs";
63
+ import Sparkles from "lucide-react/dist/esm/icons/sparkles.mjs";
60
64
  import Sun from "lucide-react/dist/esm/icons/sun.mjs";
61
65
  import Trash2 from "lucide-react/dist/esm/icons/trash-2.mjs";
62
66
  import TriangleAlert from "lucide-react/dist/esm/icons/triangle-alert.mjs";
67
+ import User from "lucide-react/dist/esm/icons/user.mjs";
63
68
  import XIcon from "lucide-react/dist/esm/icons/x.mjs";
64
69
 
65
70
  export const staticIcons: Record<string, LucideIcon> = {
@@ -88,15 +93,20 @@ export const staticIcons: Record<string, LucideIcon> = {
88
93
  lightbulb: Lightbulb,
89
94
  "list-checks": ListChecks,
90
95
  maximize: Maximize,
96
+ "message-square": MessageSquare,
91
97
  minus: Minus,
92
98
  moon: Moon,
93
99
  "octagon-alert": OctagonAlert,
94
100
  "panel-left": PanelLeft,
101
+ "panel-right": PanelRight,
95
102
  pencil: Pencil,
96
103
  plus: Plus,
104
+ "rotate-ccw": RotateCcw,
97
105
  search: Search,
106
+ sparkles: Sparkles,
98
107
  sun: Sun,
99
108
  "trash-2": Trash2,
100
109
  "triangle-alert": TriangleAlert,
110
+ user: User,
101
111
  x: XIcon,
102
112
  };