@karimsa/mdxserve 0.6.0-rc.2 → 0.6.0-rc.3

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.
@@ -74,7 +74,7 @@ function ThreadRow({ active, children }: { active: boolean; children: ReactNode
74
74
  );
75
75
  }
76
76
 
77
- /** Header and thread list shared by the docked sidebar and the phone sheet. */
77
+ /** Header and thread list shared by the desktop sidebar and the phone sheet. */
78
78
  export function CommentsPanel({
79
79
  model,
80
80
  variant,
@@ -1,24 +1,36 @@
1
+ import { motion } from "framer-motion";
1
2
  import { CommentsPanel } from "./CommentsPanel";
2
3
  import type { CommentsModel } from "./model";
3
-
4
- export const COMMENTS_SIDEBAR_WIDTH = 348;
4
+ import { SLIDE, SLIDE_BLEED, SLIDE_OUT } from "./motion";
5
5
 
6
6
  /**
7
- * Desktop column: 348px, full height under the top bar, flush to the window's
8
- * right edge. AppShell docks it beside `<main>` in a wrapper whose width opens
9
- * and closes, so the doc column narrows to make room. The column itself keeps
10
- * its full width throughout and is clipped by that wrapper: its contents slide
11
- * in from the right edge without reflowing.
7
+ * Desktop panel: 348px, full height under the top bar, fixed to the window's
8
+ * right edge. It slides in over the right-hand track AppShell reserves beside
9
+ * the doc (the one the table-of-contents rail sits in), so it never covers
10
+ * the doc. Render it inside an `AnimatePresence` for the exit.
11
+ *
12
+ * The slide is a spring that overshoots slightly, so the panel is wider than
13
+ * it looks: `SLIDE_BLEED` of padding hangs off the window's right edge and
14
+ * comes into view only while the spring is past its resting point.
12
15
  */
16
+ export const COMMENTS_SIDEBAR_WIDTH = 348;
13
17
  export function CommentsSidebar({ model, onClose }: { model: CommentsModel; onClose: () => void }) {
14
18
  return (
15
- <aside
19
+ <motion.aside
16
20
  data-print-hide
17
21
  aria-label="Comments"
18
- style={{ width: COMMENTS_SIDEBAR_WIDTH }}
19
- className="sticky top-topbar flex h-[calc(100vh-var(--topbar-height))] shrink-0 flex-col border-l border-border-default bg-surface-page"
22
+ initial={{ x: "100%" }}
23
+ animate={{ x: 0 }}
24
+ exit={{ x: "100%", transition: SLIDE_OUT }}
25
+ transition={SLIDE}
26
+ style={{
27
+ width: COMMENTS_SIDEBAR_WIDTH + SLIDE_BLEED,
28
+ right: -SLIDE_BLEED,
29
+ paddingRight: SLIDE_BLEED,
30
+ }}
31
+ className="fixed top-topbar bottom-0 z-[var(--z-sticky)] flex flex-col border-l border-border-default bg-surface-page shadow-lg"
20
32
  >
21
33
  <CommentsPanel model={model} variant="sidebar" onClose={onClose} />
22
- </aside>
34
+ </motion.aside>
23
35
  );
24
36
  }
@@ -72,8 +72,7 @@ export function GutterCounters({ model }: { model: CommentsModel }) {
72
72
 
73
73
  useLayoutEffect(measure, [measure]);
74
74
 
75
- // The doc reflows with the window, with late fonts and images, and with the
76
- // sidebar closing; anything that moves an anchor resizes the article. The
75
+ // The doc reflows with the window and with late fonts and images; anything that moves an anchor resizes the article. The
77
76
  // navigation sidebar and TOC rail shift the centred doc without resizing it,
78
77
  // but they do resize the content area around it.
79
78
  useEffect(() => {
@@ -25,20 +25,22 @@ export function rowMotion(reducedMotion: boolean | null) {
25
25
  }
26
26
 
27
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.
28
+ * The comments sidebar's slide: slower and looser than `TRANSITIONS.glide`, so
29
+ * the panel visibly travels and settles with a small overshoot (about 3% of
30
+ * its width). The sidebar bleeds past the window edge by `SLIDE_BLEED` so the
31
+ * overshoot never opens a gap there.
31
32
  */
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
- }
33
+ export const SLIDE: Transition = { type: "spring", stiffness: 170, damping: 19, mass: 1 };
34
+ export const SLIDE_BLEED = 32;
35
+ /**
36
+ * How far the spring carries the sidebar past its resting edge, rounded up
37
+ * (measured: 13px). The layout keeps this much clear beside the sidebar so
38
+ * the overshoot never crosses a doc that fills its column.
39
+ */
40
+ export const SLIDE_OVERSHOOT = 16;
41
+ /**
42
+ * Leaving is a plain accelerate-out: a spring's settling would happen off
43
+ * screen, and the layout waits for the exit to finish before it reclaims the
44
+ * sidebar's track.
45
+ */
46
+ export const SLIDE_OUT: Transition = { duration: 0.3, ease: [0.4, 0, 0.6, 1] };
@@ -3,7 +3,7 @@ import { atomWithStorage } from "jotai/utils";
3
3
  import type { AnchorFields } from "./anchor";
4
4
  import type { ReplyDrafts } from "./drafts";
5
5
 
6
- /** Desktop sidebar open state; persisted. Takes the table-of-contents rail's place while open. */
6
+ /** Desktop sidebar open state; persisted. Covers the table-of-contents rail while open. */
7
7
  export const commentsOpenAtom = atomWithStorage<boolean>(
8
8
  "mdxserve.comments.open",
9
9
  false,
@@ -1,8 +1,16 @@
1
1
  import { DiagramPreferences } from "../diagrams/Preferences";
2
- import { AnimatePresence, motion, useReducedMotion, useSpring } from "framer-motion";
2
+ import { AnimatePresence, motion, useSpring } from "framer-motion";
3
3
  import { useAtomValue } from "jotai";
4
4
  import { keepPreviousData, useQuery } from "@tanstack/react-query";
5
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import {
6
+ useCallback,
7
+ useEffect,
8
+ useLayoutEffect,
9
+ useMemo,
10
+ useRef,
11
+ useState,
12
+ type CSSProperties,
13
+ } from "react";
6
14
  import { trpc } from "../api";
7
15
  import { DocView } from "../DocView";
8
16
  import { HomeView } from "../HomeView";
@@ -27,7 +35,7 @@ import { CommentsSheet } from "../comments/CommentsSheet";
27
35
  import { COMMENTS_SIDEBAR_WIDTH, CommentsSidebar } from "../comments/CommentsSidebar";
28
36
  import { GutterCounters } from "../comments/GutterCounters";
29
37
  import { useCommentsModel, useCommentsPanel } from "../comments/model";
30
- import { dockMotion } from "../comments/motion";
38
+ import { SLIDE_OVERSHOOT } from "../comments/motion";
31
39
  import { SelectionButton } from "../comments/SelectionButton";
32
40
  import { PageNav, type PageNavLink } from "../ui/PageNav";
33
41
  import { SearchDialog, type SearchResult } from "../ui/SearchDialog";
@@ -219,12 +227,15 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
219
227
 
220
228
  const comments = useCommentsModel(route.kind === "doc" ? route.path : null, tocVersion);
221
229
  const commentsPanel = useCommentsPanel();
222
- // The sidebar is docked beside <main>; the table-of-contents rail is hidden while it is open.
230
+ // The sidebar slides in over the right-hand track, covering the table-of-contents rail.
223
231
  const commentsOpen = comments.available && commentsPanel.open;
224
232
  const commentsSidebarOpen = comments.available && commentsPanel.sidebarOpen;
225
233
  const setCommentsOpen = commentsPanel.setOpen;
226
234
  const closeComments = useCallback(() => setCommentsOpen(false), [setCommentsOpen]);
227
- const reducedMotion = useReducedMotion();
235
+ // The sidebar is still on screen while it slides out, so the track it covers
236
+ // stays reserved until that exit finishes.
237
+ const [commentsTrackHeld, setCommentsTrackHeld] = useState(commentsSidebarOpen);
238
+ if (commentsSidebarOpen && !commentsTrackHeld) setCommentsTrackHeld(true);
228
239
 
229
240
  useEffect(() => {
230
241
  try {
@@ -441,33 +452,36 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
441
452
  </motion.div>
442
453
  </AnimatePresence>
443
454
  </div>
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>
460
- </main>
461
- <AnimatePresence initial={false}>
462
- {route.kind === "doc" && commentsSidebarOpen ? (
463
- <motion.div
464
- key="comments-sidebar"
455
+ {/* The right-hand track, shared by the table-of-contents rail and the
456
+ comments sidebar. It is as wide as the sidebar (less <main>'s own
457
+ right padding, plus room for the slide's overshoot), so the sidebar slides in over the rail and can never
458
+ cover the doc. Where the rail already holds the track open (xl and
459
+ up, in a doc with headings) opening the sidebar moves nothing;
460
+ elsewhere the track opens in one step as the sidebar starts to
461
+ slide and closes in one step once it has left. Inert while covered, or focus could land on hidden links. */}
462
+ {route.kind === "doc" ? (
463
+ <div
465
464
  data-print-hide
466
- {...dockMotion(COMMENTS_SIDEBAR_WIDTH, reducedMotion)}
467
- className="shrink-0 self-stretch overflow-x-clip"
465
+ inert={commentsSidebarOpen}
466
+ style={
467
+ {
468
+ "--comments-track": `${COMMENTS_SIDEBAR_WIDTH - 32 + SLIDE_OVERSHOOT}px`,
469
+ } as CSSProperties
470
+ }
471
+ className={
472
+ "flex shrink-0 justify-end self-stretch " +
473
+ (commentsTrackHeld
474
+ ? "min-w-[var(--comments-track)]"
475
+ : "xl:has-[[data-toc-rail]]:min-w-[var(--comments-track)]")
476
+ }
468
477
  >
469
- <CommentsSidebar model={comments} onClose={closeComments} />
470
- </motion.div>
478
+ <TocRail path={route.path} version={tocVersion} />
479
+ </div>
480
+ ) : null}
481
+ </main>
482
+ <AnimatePresence initial={false} onExitComplete={() => setCommentsTrackHeld(false)}>
483
+ {route.kind === "doc" && commentsSidebarOpen ? (
484
+ <CommentsSidebar key="comments-sidebar" model={comments} onClose={closeComments} />
471
485
  ) : null}
472
486
  </AnimatePresence>
473
487
  </div>
@@ -27,6 +27,7 @@ export function TocRail({ path, version }: { path: string; version: number }) {
27
27
  return (
28
28
  <div
29
29
  ref={railRef}
30
+ data-toc-rail
30
31
  data-print-hide
31
32
  className="hidden xl:block shrink-0 self-start ml-10 sticky top-[calc(var(--topbar-height)+40px)]"
32
33
  style={{ width: clampWidth(width) }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karimsa/mdxserve",
3
- "version": "0.6.0-rc.2",
3
+ "version": "0.6.0-rc.3",
4
4
  "description": "Serve a directory of Markdown/MDX files, like `serve` but for docs",
5
5
  "license": "MIT",
6
6
  "repository": {