@karimsa/mdxserve 0.6.0-rc.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.
- package/client/DocView.tsx +23 -6
- package/client/MdSection.tsx +14 -9
- package/client/RenderErrorBoundary.tsx +20 -5
- package/client/comments/CommentsPanel.tsx +43 -12
- package/client/comments/CommentsSidebar.tsx +8 -2
- package/client/comments/DraftThread.tsx +3 -0
- package/client/comments/GutterCounters.tsx +27 -19
- package/client/comments/ReplyField.tsx +1 -1
- package/client/comments/Thread.tsx +102 -72
- package/client/comments/motion.ts +44 -0
- package/client/comments/state.ts +7 -0
- package/client/entry.tsx +10 -0
- package/client/shell/AppShell.tsx +32 -8
- package/package.json +1 -1
package/client/DocView.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
1
|
+
import { memo, useLayoutEffect, useMemo, useRef, type ComponentType, type ReactNode } from "react";
|
|
2
2
|
import { useAtomValue, useSetAtom } from "jotai";
|
|
3
3
|
import { DocContext } from "./DocContext";
|
|
4
4
|
import { ErrorBox } from "./ErrorBox";
|
|
@@ -10,7 +10,7 @@ import { DOC_MAX_WIDTH, DOC_MIN_WIDTH, docWidthAtom, openSectionAtom } from "./s
|
|
|
10
10
|
|
|
11
11
|
// Each Component a re-import produces (including an HMR re-import after a
|
|
12
12
|
// fix) is a distinct function identity, so this assigns it a stable, unique
|
|
13
|
-
//
|
|
13
|
+
// number the RenderErrorBoundary below resets itself on.
|
|
14
14
|
const moduleKeys = new WeakMap<object, number>();
|
|
15
15
|
let nextModuleKey = 0;
|
|
16
16
|
function keyForComponent(Component: object): number {
|
|
@@ -22,7 +22,24 @@ function keyForComponent(Component: object): number {
|
|
|
22
22
|
return key;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Calls the doc's compiled content function instead of mounting it. A re-import
|
|
27
|
+
* after an edit yields a new function; mounted as a component, React would see
|
|
28
|
+
* a new type and rebuild the whole article. Called from this one long-lived
|
|
29
|
+
* component, only the elements it returns are diffed, so unchanged blocks keep
|
|
30
|
+
* their DOM and state. The content function's own hooks (`useMDXComponents`)
|
|
31
|
+
* are the same on every import, so they are safe to run as this component's.
|
|
32
|
+
*/
|
|
33
|
+
function DocContent({ render }: { render: ComponentType }) {
|
|
34
|
+
return (render as (props: Record<string, never>) => ReactNode)({});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Memoized: the shell re-renders on every frame of a width change (the
|
|
39
|
+
* comments sidebar opening, a window resize), and without this each of those
|
|
40
|
+
* would re-run the whole doc's content function.
|
|
41
|
+
*/
|
|
42
|
+
export const DocView = memo(function DocView({
|
|
26
43
|
path,
|
|
27
44
|
module,
|
|
28
45
|
onRendered,
|
|
@@ -99,11 +116,11 @@ export function DocView({
|
|
|
99
116
|
)}
|
|
100
117
|
<article className="mdx-prose min-w-0 max-w-full">
|
|
101
118
|
<DocContext value={docContext}>
|
|
102
|
-
<RenderErrorBoundary
|
|
103
|
-
<Content />
|
|
119
|
+
<RenderErrorBoundary resetKey={keyForComponent(Content)}>
|
|
120
|
+
<DocContent render={Content} />
|
|
104
121
|
</RenderErrorBoundary>
|
|
105
122
|
</DocContext>
|
|
106
123
|
</article>
|
|
107
124
|
</div>
|
|
108
125
|
);
|
|
109
|
-
}
|
|
126
|
+
});
|
package/client/MdSection.tsx
CHANGED
|
@@ -58,14 +58,11 @@ export interface MdSectionProps {
|
|
|
58
58
|
* it's invisible — same children, same DOM — until hovered, when a pencil
|
|
59
59
|
* appears to swap it into an inline Tiptap editor seeded from the raw file.
|
|
60
60
|
*
|
|
61
|
-
* This outer component only resolves `path`
|
|
62
|
-
* on
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* state across that update and leave it holding an editor pointed at
|
|
67
|
-
* now-stale line numbers; keying on the range forces a clean remount back to
|
|
68
|
-
* read mode instead.
|
|
61
|
+
* This outer component only resolves `path`. `Section` is deliberately not
|
|
62
|
+
* keyed on its line range: anything that adds lines above it — a comment
|
|
63
|
+
* growing the frontmatter, an edit to an earlier section — shifts the range,
|
|
64
|
+
* and a key would remount every section below, diagrams included. `Section`
|
|
65
|
+
* drops back to read mode itself when its range moves.
|
|
69
66
|
*/
|
|
70
67
|
export function MdSection({ index, startLine, endLine, rawJsx, children }: MdSectionProps) {
|
|
71
68
|
const ctxPath = useContext(DocContext)?.path;
|
|
@@ -78,7 +75,6 @@ export function MdSection({ index, startLine, endLine, rawJsx, children }: MdSec
|
|
|
78
75
|
|
|
79
76
|
return (
|
|
80
77
|
<Section
|
|
81
|
-
key={`${path}:${startLine}:${endLine}`}
|
|
82
78
|
path={path}
|
|
83
79
|
index={index}
|
|
84
80
|
startLine={Number(startLine)}
|
|
@@ -112,6 +108,15 @@ function Section({
|
|
|
112
108
|
const [openSection, setOpenSection] = useAtom(openSectionAtom);
|
|
113
109
|
const key = `${path}:${startLine}:${endLine}`;
|
|
114
110
|
|
|
111
|
+
// The range moved under this section (a save or an outside write shifted
|
|
112
|
+
// it), so an open editor now points at stale line numbers: back to read
|
|
113
|
+
// mode. Reset during render so the editor never commits with the new range.
|
|
114
|
+
const [renderedKey, setRenderedKey] = useState(key);
|
|
115
|
+
if (renderedKey !== key) {
|
|
116
|
+
setRenderedKey(key);
|
|
117
|
+
setMode("read");
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
// Only one section edits (or loads) at a time. The atom is claimed the
|
|
116
121
|
// moment a section starts opening, so if a different section claims it
|
|
117
122
|
// while this one is mid-fetch or mid-edit, this one drops back to read
|
|
@@ -4,6 +4,8 @@ import { ErrorBox } from "./ErrorBox";
|
|
|
4
4
|
type RenderErrorBoundaryState = {
|
|
5
5
|
error: Error | null;
|
|
6
6
|
componentStack: string | null;
|
|
7
|
+
/** The `resetKey` this state belongs to. */
|
|
8
|
+
resetKey: number;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -12,15 +14,28 @@ type RenderErrorBoundaryState = {
|
|
|
12
14
|
* shows ErrorBox instead of leaving the page blank. React error boundaries
|
|
13
15
|
* only work as class components — there is no hook equivalent.
|
|
14
16
|
*
|
|
15
|
-
* The parent
|
|
16
|
-
* re-import after a fix
|
|
17
|
-
*
|
|
17
|
+
* The parent passes the cached module's identity as `resetKey`, so an HMR
|
|
18
|
+
* re-import after a fix clears the stale error rather than getting stuck on
|
|
19
|
+
* the first throw. It is a prop and not a React `key`: a key would remount the
|
|
20
|
+
* whole article on every re-import, error or not.
|
|
18
21
|
*/
|
|
19
22
|
export class RenderErrorBoundary extends Component<
|
|
20
|
-
{ children: ReactNode },
|
|
23
|
+
{ resetKey: number; children: ReactNode },
|
|
21
24
|
RenderErrorBoundaryState
|
|
22
25
|
> {
|
|
23
|
-
state: RenderErrorBoundaryState = {
|
|
26
|
+
state: RenderErrorBoundaryState = {
|
|
27
|
+
error: null,
|
|
28
|
+
componentStack: null,
|
|
29
|
+
resetKey: this.props.resetKey,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
static getDerivedStateFromProps(
|
|
33
|
+
props: { resetKey: number },
|
|
34
|
+
state: RenderErrorBoundaryState,
|
|
35
|
+
): RenderErrorBoundaryState | null {
|
|
36
|
+
if (props.resetKey === state.resetKey) return null;
|
|
37
|
+
return { error: null, componentStack: null, resetKey: props.resetKey };
|
|
38
|
+
}
|
|
24
39
|
|
|
25
40
|
static getDerivedStateFromError(error: Error): Partial<RenderErrorBoundaryState> {
|
|
26
41
|
return { error };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
|
|
1
2
|
import { useAtomValue } from "jotai";
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
3
4
|
import type { CommentThread } from "../../src/comments/schema";
|
|
4
5
|
import { CtlButton } from "./CtlButton";
|
|
5
6
|
import { DraftThread } from "./DraftThread";
|
|
6
7
|
import type { CommentsModel } from "./model";
|
|
8
|
+
import { rowMotion } from "./motion";
|
|
7
9
|
import { activeThreadAtom, draftAtom } from "./state";
|
|
8
10
|
import { Thread } from "./Thread";
|
|
9
11
|
|
|
@@ -48,6 +50,30 @@ function Tabs({
|
|
|
48
50
|
);
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* One thread's place in the list. It expands in when the thread joins the tab
|
|
55
|
+
* (a new comment, a reopen) and collapses when it leaves (a resolve), so the
|
|
56
|
+
* rows around it move aside instead of jumping.
|
|
57
|
+
*/
|
|
58
|
+
function ThreadRow({ active, children }: { active: boolean; children: ReactNode }) {
|
|
59
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
60
|
+
const reducedMotion = useReducedMotion();
|
|
61
|
+
return (
|
|
62
|
+
<motion.div
|
|
63
|
+
ref={ref}
|
|
64
|
+
{...rowMotion(reducedMotion)}
|
|
65
|
+
// Thread scrolls itself into view when it becomes active, but a new one
|
|
66
|
+
// is still collapsed then; bring it fully into view once it has opened.
|
|
67
|
+
onAnimationComplete={() => {
|
|
68
|
+
if (active) ref.current?.scrollIntoView({ block: "nearest" });
|
|
69
|
+
}}
|
|
70
|
+
className="overflow-hidden"
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</motion.div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
51
77
|
/** Header and thread list shared by the docked sidebar and the phone sheet. */
|
|
52
78
|
export function CommentsPanel({
|
|
53
79
|
model,
|
|
@@ -95,14 +121,15 @@ export function CommentsPanel({
|
|
|
95
121
|
|
|
96
122
|
function renderThread(thread: CommentThread) {
|
|
97
123
|
return (
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
<ThreadRow key={`${model.path}:${thread.id}`} active={thread.id === activeId}>
|
|
125
|
+
<Thread
|
|
126
|
+
thread={thread}
|
|
127
|
+
view={views.get(thread.id)}
|
|
128
|
+
active={thread.id === activeId}
|
|
129
|
+
variant={variant}
|
|
130
|
+
model={model}
|
|
131
|
+
/>
|
|
132
|
+
</ThreadRow>
|
|
106
133
|
);
|
|
107
134
|
}
|
|
108
135
|
|
|
@@ -134,14 +161,18 @@ export function CommentsPanel({
|
|
|
134
161
|
<DraftThread model={model} sidebarOpen={false} reserveTools={false} padded />
|
|
135
162
|
</div>
|
|
136
163
|
) : null}
|
|
137
|
-
|
|
138
|
-
|
|
164
|
+
{/* Keyed by tab and doc: switching either swaps the whole list at once,
|
|
165
|
+
and only a thread joining or leaving the list on screen animates. */}
|
|
166
|
+
<div key={`${model.path}:${tab}`} className="divide-y divide-border-default">
|
|
167
|
+
<AnimatePresence initial={false}>{shown.map(renderThread)}</AnimatePresence>
|
|
139
168
|
{tab === "open" && detached.length > 0 ? (
|
|
140
169
|
<div>
|
|
141
170
|
<h3 className="m-0 px-4 pt-3.5 text-[length:var(--size-2xs)] font-semibold tracking-wide text-text-subtle uppercase">
|
|
142
171
|
Detached
|
|
143
172
|
</h3>
|
|
144
|
-
<div className="divide-y divide-border-default">
|
|
173
|
+
<div className="divide-y divide-border-default">
|
|
174
|
+
<AnimatePresence initial={false}>{detached.map(renderThread)}</AnimatePresence>
|
|
175
|
+
</div>
|
|
145
176
|
</div>
|
|
146
177
|
) : null}
|
|
147
178
|
</div>
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { CommentsPanel } from "./CommentsPanel";
|
|
2
2
|
import type { CommentsModel } from "./model";
|
|
3
3
|
|
|
4
|
+
export const COMMENTS_SIDEBAR_WIDTH = 348;
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Desktop column: 348px, full height under the top bar, flush to the window's
|
|
6
|
-
* right edge.
|
|
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
12
|
*/
|
|
8
13
|
export function CommentsSidebar({ model, onClose }: { model: CommentsModel; onClose: () => void }) {
|
|
9
14
|
return (
|
|
10
15
|
<aside
|
|
11
16
|
data-print-hide
|
|
12
17
|
aria-label="Comments"
|
|
13
|
-
|
|
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"
|
|
14
20
|
>
|
|
15
21
|
<CommentsPanel model={model} variant="sidebar" onClose={onClose} />
|
|
16
22
|
</aside>
|
|
@@ -4,6 +4,7 @@ import { ReplyField } from "./ReplyField";
|
|
|
4
4
|
import {
|
|
5
5
|
activeThreadAtom,
|
|
6
6
|
draftAtom,
|
|
7
|
+
freshThreadAtom,
|
|
7
8
|
pendingSendsAtom,
|
|
8
9
|
popoverThreadAtom,
|
|
9
10
|
withPendingSend,
|
|
@@ -26,6 +27,7 @@ export function DraftThread({
|
|
|
26
27
|
const [draft, setDraft] = useAtom(draftAtom);
|
|
27
28
|
const setActive = useSetAtom(activeThreadAtom);
|
|
28
29
|
const setPopover = useSetAtom(popoverThreadAtom);
|
|
30
|
+
const setFresh = useSetAtom(freshThreadAtom);
|
|
29
31
|
// Shared, so a composer that remounts mid-save (the sheet closed and reopened)
|
|
30
32
|
// still shows its send as pending and cannot post the comment twice.
|
|
31
33
|
const [pendingSends, setPendingSends] = useAtom(pendingSendsAtom);
|
|
@@ -47,6 +49,7 @@ export function DraftThread({
|
|
|
47
49
|
if (created === null) return;
|
|
48
50
|
// The user moved on to another comment (or another doc) while this one saved.
|
|
49
51
|
if (store.get(draftAtom)?.nonce !== submitted) return;
|
|
52
|
+
setFresh(created);
|
|
50
53
|
setDraft(null);
|
|
51
54
|
setActive(created);
|
|
52
55
|
// The popover follows the new thread unless the sidebar shows it.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
1
2
|
import { useAtomValue } from "jotai";
|
|
2
3
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { TRANSITIONS } from "../motion";
|
|
3
5
|
import { Icon } from "../ui/Icon";
|
|
4
6
|
import { findArticle } from "./dom";
|
|
5
7
|
import type { CommentsModel, ThreadView } from "./model";
|
|
@@ -89,25 +91,31 @@ export function GutterCounters({ model }: { model: CommentsModel }) {
|
|
|
89
91
|
|
|
90
92
|
return (
|
|
91
93
|
<div ref={containerRef} data-print-hide className="pointer-events-none absolute top-0 left-0">
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
<AnimatePresence>
|
|
95
|
+
{pins.map((pin) => (
|
|
96
|
+
<motion.button
|
|
97
|
+
key={pin.id}
|
|
98
|
+
initial={{ opacity: 0, scale: 0.85 }}
|
|
99
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
100
|
+
exit={{ opacity: 0, transition: TRANSITIONS.fast }}
|
|
101
|
+
transition={TRANSITIONS.snap}
|
|
102
|
+
type="button"
|
|
103
|
+
data-comments-keep
|
|
104
|
+
aria-label={`Open comment thread, ${pin.count} ${pin.count === 1 ? "message" : "messages"}`}
|
|
105
|
+
onClick={() => model.showPopover(pin.id)}
|
|
106
|
+
style={{ top: pin.top, left: pin.left, height: PIN_HEIGHT }}
|
|
107
|
+
className={
|
|
108
|
+
"pointer-events-auto absolute z-[1] inline-flex cursor-pointer items-center gap-1 rounded-full border px-[7px] font-sans text-[11.5px] leading-none font-semibold tabular-nums " +
|
|
109
|
+
(pin.id === activeId
|
|
110
|
+
? "border-border-strong bg-surface-hover text-text-heading"
|
|
111
|
+
: "border-border-default bg-surface-card text-text-muted hover:text-text-heading")
|
|
112
|
+
}
|
|
113
|
+
>
|
|
114
|
+
<Icon name="message-square" size={12} />
|
|
115
|
+
{pin.count}
|
|
116
|
+
</motion.button>
|
|
117
|
+
))}
|
|
118
|
+
</AnimatePresence>
|
|
111
119
|
</div>
|
|
112
120
|
);
|
|
113
121
|
}
|
|
@@ -85,7 +85,7 @@ export function ReplyField({
|
|
|
85
85
|
disabled={!ready}
|
|
86
86
|
onClick={onSubmit}
|
|
87
87
|
className={
|
|
88
|
-
"grid h-6 w-6 shrink-0 cursor-pointer place-items-center rounded-full border-0 p-0 transition-
|
|
88
|
+
"grid h-6 w-6 shrink-0 cursor-pointer place-items-center rounded-full border-0 p-0 transition-[color,background-color,scale] duration-150 ease-out enabled:active:scale-90 disabled:cursor-not-allowed motion-reduce:enabled:active:scale-100 " +
|
|
89
89
|
(ready
|
|
90
90
|
? "bg-surface-accent text-text-inverse"
|
|
91
91
|
: "bg-surface-hover text-text-subtle group-focus-within/field:bg-surface-accent group-focus-within/field:text-text-inverse")
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
|
|
2
|
+
import { useAtom, useStore } from "jotai";
|
|
2
3
|
import { useEffect, useRef, useState, type ReactNode } from "react";
|
|
3
4
|
import type { CommentMessage, CommentThread } from "../../src/comments/schema";
|
|
4
5
|
import { Icon } from "../ui/Icon";
|
|
5
6
|
import { CtlButton } from "./CtlButton";
|
|
6
7
|
import { replyDraftOf, withReplyDraft } from "./drafts";
|
|
7
8
|
import type { CommentsModel, ThreadView } from "./model";
|
|
9
|
+
import { rowMotion } from "./motion";
|
|
8
10
|
import { ReplyField } from "./ReplyField";
|
|
9
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
freshThreadAtom,
|
|
13
|
+
pendingReplyKey,
|
|
14
|
+
pendingSendsAtom,
|
|
15
|
+
replyDraftsAtom,
|
|
16
|
+
withPendingSend,
|
|
17
|
+
} from "./state";
|
|
10
18
|
import { relativeTime } from "./time";
|
|
11
19
|
|
|
12
20
|
/** Where a thread is drawn: a sidebar row, the sheet's row, or the popover's body. */
|
|
@@ -42,6 +50,7 @@ export function QuoteText({ text, active }: { text: string; active: boolean }) {
|
|
|
42
50
|
|
|
43
51
|
function Message({
|
|
44
52
|
message,
|
|
53
|
+
first,
|
|
45
54
|
last,
|
|
46
55
|
reserveTools,
|
|
47
56
|
canEdit,
|
|
@@ -49,6 +58,7 @@ function Message({
|
|
|
49
58
|
onEdit,
|
|
50
59
|
}: {
|
|
51
60
|
message: CommentMessage;
|
|
61
|
+
first: boolean;
|
|
52
62
|
last: boolean;
|
|
53
63
|
/** Leaves room for the popover's tool buttons beside the first header. */
|
|
54
64
|
reserveTools: boolean;
|
|
@@ -60,6 +70,7 @@ function Message({
|
|
|
60
70
|
const [draft, setDraft] = useState(message.body);
|
|
61
71
|
const [pending, setPending] = useState(false);
|
|
62
72
|
const agent = message.author === "agent";
|
|
73
|
+
const reducedMotion = useReducedMotion();
|
|
63
74
|
|
|
64
75
|
async function save() {
|
|
65
76
|
setPending(true);
|
|
@@ -68,71 +79,79 @@ function Message({
|
|
|
68
79
|
if (saved) setEditing(false);
|
|
69
80
|
}
|
|
70
81
|
|
|
82
|
+
// The gap above a message is drawn inside it (the timeline's connector, then
|
|
83
|
+
// 2px of air) instead of as a margin, so a new message's whole footprint
|
|
84
|
+
// grows from nothing and the reply field below is pushed down smoothly.
|
|
71
85
|
return (
|
|
72
|
-
<div className="group
|
|
73
|
-
{
|
|
74
|
-
<span
|
|
75
|
-
aria-hidden
|
|
76
|
-
className="absolute top-7 -bottom-3 left-[11.5px] w-px bg-border-default"
|
|
77
|
-
/>
|
|
86
|
+
<motion.div {...rowMotion(reducedMotion)} className="group overflow-hidden">
|
|
87
|
+
{first ? null : (
|
|
88
|
+
<span aria-hidden className="mb-0.5 ml-[11.5px] block h-3 w-px bg-border-default" />
|
|
78
89
|
)}
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
title={message.createdAt ? new Date(message.createdAt).toLocaleString() : undefined}
|
|
90
|
+
<div className="relative grid grid-cols-[24px_1fr] gap-x-2.5">
|
|
91
|
+
{last ? null : (
|
|
92
|
+
<span
|
|
93
|
+
aria-hidden
|
|
94
|
+
className="absolute top-7 bottom-0 left-[11.5px] w-px bg-border-default"
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
<Avatar author={message.author} />
|
|
98
|
+
<div className="min-w-0">
|
|
99
|
+
<div
|
|
100
|
+
className={
|
|
101
|
+
"flex items-baseline gap-[7px] pt-[3px] text-[12.5px] leading-[1.3] " +
|
|
102
|
+
(reserveTools ? "pr-[84px]" : "")
|
|
103
|
+
}
|
|
94
104
|
>
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
aria-label="Edit comment"
|
|
103
|
-
onClick={() => {
|
|
104
|
-
setDraft(message.body);
|
|
105
|
-
setEditing(true);
|
|
106
|
-
}}
|
|
107
|
-
className="ml-auto inline-flex cursor-pointer items-center gap-1 rounded-sm border-0 bg-transparent p-0 text-[11.5px] font-semibold text-text-subtle opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 hover:text-text-heading focus-visible:opacity-100 disabled:cursor-not-allowed disabled:opacity-0 group-hover:disabled:opacity-45 [@media(hover:none)]:opacity-100"
|
|
105
|
+
<span className={"font-bold " + (agent ? "text-text-accent" : "text-text-heading")}>
|
|
106
|
+
{agent ? "Agent" : "You"}
|
|
107
|
+
</span>
|
|
108
|
+
<time
|
|
109
|
+
className="text-[11.5px] text-text-subtle tabular-nums"
|
|
110
|
+
dateTime={message.createdAt}
|
|
111
|
+
title={message.createdAt ? new Date(message.createdAt).toLocaleString() : undefined}
|
|
108
112
|
>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
</
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/>
|
|
113
|
+
{relativeTime(message.createdAt)}
|
|
114
|
+
{message.editedAt ? " · edited" : ""}
|
|
115
|
+
</time>
|
|
116
|
+
{canEdit && !editing ? (
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
disabled={editDisabled}
|
|
120
|
+
aria-label="Edit comment"
|
|
121
|
+
onClick={() => {
|
|
122
|
+
setDraft(message.body);
|
|
123
|
+
setEditing(true);
|
|
124
|
+
}}
|
|
125
|
+
className="ml-auto inline-flex cursor-pointer items-center gap-1 rounded-sm border-0 bg-transparent p-0 text-[11.5px] font-semibold text-text-subtle opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 hover:text-text-heading focus-visible:opacity-100 disabled:cursor-not-allowed disabled:opacity-0 group-hover:disabled:opacity-45 [@media(hover:none)]:opacity-100"
|
|
126
|
+
>
|
|
127
|
+
<Icon name="pencil" size={11} />
|
|
128
|
+
Edit
|
|
129
|
+
</button>
|
|
130
|
+
) : null}
|
|
128
131
|
</div>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
{editing ? (
|
|
133
|
+
<div className="mt-1.5" data-comment-edit>
|
|
134
|
+
<ReplyField
|
|
135
|
+
label="Edit comment"
|
|
136
|
+
sendLabel="Save comment"
|
|
137
|
+
placeholder=""
|
|
138
|
+
value={draft}
|
|
139
|
+
onChange={setDraft}
|
|
140
|
+
onSubmit={() => void save()}
|
|
141
|
+
onCancel={() => setEditing(false)}
|
|
142
|
+
disabled={editDisabled}
|
|
143
|
+
pending={pending}
|
|
144
|
+
focusNonce={0}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
) : (
|
|
148
|
+
<p className="m-0 mt-[3px] text-[13.5px] leading-[1.55] break-words whitespace-pre-wrap text-text-body">
|
|
149
|
+
{message.body}
|
|
150
|
+
</p>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
134
153
|
</div>
|
|
135
|
-
</div>
|
|
154
|
+
</motion.div>
|
|
136
155
|
);
|
|
137
156
|
}
|
|
138
157
|
|
|
@@ -165,6 +184,14 @@ export function Thread({
|
|
|
165
184
|
const popover = variant === "popover";
|
|
166
185
|
const reply = replyDraftOf(drafts, thread.id);
|
|
167
186
|
|
|
187
|
+
// A thread this tab just created shows its message arriving in the popover.
|
|
188
|
+
// In the panel the whole row expands in instead (CommentsPanel).
|
|
189
|
+
const store = useStore();
|
|
190
|
+
const [animateFirst] = useState(() => popover && store.get(freshThreadAtom) === thread.id);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (store.get(freshThreadAtom) === thread.id) store.set(freshThreadAtom, null);
|
|
193
|
+
}, [store, thread.id]);
|
|
194
|
+
|
|
168
195
|
useEffect(() => {
|
|
169
196
|
if (active && !popover) ref.current?.scrollIntoView({ block: "nearest" });
|
|
170
197
|
}, [active, popover]);
|
|
@@ -246,17 +273,20 @@ export function Thread({
|
|
|
246
273
|
)}
|
|
247
274
|
{note ? <p className="m-0 text-xs text-status-warn-fg">{note}</p> : null}
|
|
248
275
|
<div>
|
|
249
|
-
{
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
276
|
+
<AnimatePresence initial={animateFirst}>
|
|
277
|
+
{thread.messages.map((message, index) => (
|
|
278
|
+
<Message
|
|
279
|
+
key={message.id}
|
|
280
|
+
message={message}
|
|
281
|
+
first={index === 0}
|
|
282
|
+
last={index === thread.messages.length - 1}
|
|
283
|
+
reserveTools={popover && index === 0}
|
|
284
|
+
canEdit={!readOnly && message.author === "human"}
|
|
285
|
+
editDisabled={writesDisabled}
|
|
286
|
+
onEdit={async (body) => (await actions.edit(thread.id, message.id, body)) !== null}
|
|
287
|
+
/>
|
|
288
|
+
))}
|
|
289
|
+
</AnimatePresence>
|
|
260
290
|
</div>
|
|
261
291
|
{showReply ? (
|
|
262
292
|
<div className="grid grid-cols-[24px_1fr] items-end gap-x-2.5">
|
|
@@ -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
|
+
}
|
package/client/comments/state.ts
CHANGED
|
@@ -36,6 +36,13 @@ export interface CommentDraft {
|
|
|
36
36
|
|
|
37
37
|
export const draftAtom = atom<CommentDraft | null>(null);
|
|
38
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
|
+
|
|
39
46
|
/**
|
|
40
47
|
* Replies and new comments being saved, by key (`pendingReplyKey`, `pendingDraftKey`).
|
|
41
48
|
* Shared, not component state: a thread or composer that remounts mid-save must
|
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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
@@ -24,9 +24,10 @@ import { exportDocFromViewer } from "../export-doc";
|
|
|
24
24
|
import { Breadcrumb, type BreadcrumbItem } from "../ui/Breadcrumb";
|
|
25
25
|
import { CommentsPopover } from "../comments/CommentsPopover";
|
|
26
26
|
import { CommentsSheet } from "../comments/CommentsSheet";
|
|
27
|
-
import { CommentsSidebar } from "../comments/CommentsSidebar";
|
|
27
|
+
import { COMMENTS_SIDEBAR_WIDTH, CommentsSidebar } from "../comments/CommentsSidebar";
|
|
28
28
|
import { GutterCounters } from "../comments/GutterCounters";
|
|
29
29
|
import { useCommentsModel, useCommentsPanel } from "../comments/model";
|
|
30
|
+
import { dockMotion } from "../comments/motion";
|
|
30
31
|
import { SelectionButton } from "../comments/SelectionButton";
|
|
31
32
|
import { PageNav, type PageNavLink } from "../ui/PageNav";
|
|
32
33
|
import { SearchDialog, type SearchResult } from "../ui/SearchDialog";
|
|
@@ -223,6 +224,7 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
|
|
|
223
224
|
const commentsSidebarOpen = comments.available && commentsPanel.sidebarOpen;
|
|
224
225
|
const setCommentsOpen = commentsPanel.setOpen;
|
|
225
226
|
const closeComments = useCallback(() => setCommentsOpen(false), [setCommentsOpen]);
|
|
227
|
+
const reducedMotion = useReducedMotion();
|
|
226
228
|
|
|
227
229
|
useEffect(() => {
|
|
228
230
|
try {
|
|
@@ -439,13 +441,35 @@ export function AppShell({ route, navigate }: { route: Route; navigate: (path: s
|
|
|
439
441
|
</motion.div>
|
|
440
442
|
</AnimatePresence>
|
|
441
443
|
</div>
|
|
442
|
-
{
|
|
443
|
-
|
|
444
|
-
|
|
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>
|
|
445
460
|
</main>
|
|
446
|
-
{
|
|
447
|
-
|
|
448
|
-
|
|
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>
|
|
449
473
|
</div>
|
|
450
474
|
{route.kind === "doc" && comments.available && !commentsPanel.isDesktop ? (
|
|
451
475
|
<CommentsSheet model={comments} open={commentsPanel.open} onClose={closeComments} />
|