@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.
- package/client/comments/CommentsPanel.tsx +1 -1
- package/client/comments/CommentsSidebar.tsx +23 -11
- package/client/comments/GutterCounters.tsx +1 -2
- package/client/comments/motion.ts +18 -16
- package/client/comments/state.ts +1 -1
- package/client/shell/AppShell.tsx +44 -30
- package/client/shell/TocRail.tsx +1 -0
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
8
|
-
* right edge.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
|
|
19
|
-
|
|
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
|
|
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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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] };
|
package/client/comments/state.ts
CHANGED
|
@@ -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.
|
|
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,
|
|
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 {
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
the
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
-
{
|
|
467
|
-
|
|
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
|
-
<
|
|
470
|
-
</
|
|
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>
|
package/client/shell/TocRail.tsx
CHANGED
|
@@ -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) }}
|