@karimsa/mdxserve 0.5.0 → 0.6.0-rc.1
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/README.md +3 -0
- package/client/DocView.tsx +3 -8
- package/client/ListingView.tsx +3 -3
- package/client/Settings.tsx +26 -21
- package/client/app.css +20 -0
- package/client/comments/CommentsPanel.tsx +163 -0
- package/client/comments/CommentsPopover.tsx +197 -0
- package/client/comments/CommentsSheet.tsx +63 -0
- package/client/comments/CommentsSidebar.tsx +18 -0
- package/client/comments/CtlButton.tsx +33 -0
- package/client/comments/DraftThread.tsx +83 -0
- package/client/comments/GutterCounters.tsx +113 -0
- package/client/comments/ReplyField.tsx +98 -0
- package/client/comments/SelectionButton.tsx +142 -0
- package/client/comments/Thread.tsx +278 -0
- package/client/comments/anchor.ts +204 -0
- package/client/comments/data.ts +98 -0
- package/client/comments/dom.ts +212 -0
- package/client/comments/drafts.ts +36 -0
- package/client/comments/highlights.ts +83 -0
- package/client/comments/model.ts +241 -0
- package/client/comments/pins.ts +37 -0
- package/client/comments/self-writes.ts +22 -0
- package/client/comments/state.ts +60 -0
- package/client/comments/time.ts +21 -0
- package/client/hooks.ts +19 -0
- package/client/platform.ts +8 -0
- package/client/router.ts +5 -0
- package/client/shell/AppShell.tsx +60 -14
- package/client/shell/StandaloneShell.tsx +3 -2
- package/client/shell/TopBar.tsx +25 -0
- package/client/ui/ConfirmDeleteDialog.tsx +1 -1
- package/client/ui/Toast.tsx +5 -1
- package/client/ui/icon-set.ts +10 -0
- package/dist/cli.js +891 -230
- package/package.json +1 -1
- package/skills/mdxserve/SKILL.md +86 -0
package/README.md
CHANGED
|
@@ -248,6 +248,9 @@ and when it was last edited.
|
|
|
248
248
|
- The top bar toggles light and dark (it remembers your choice), prints, and exports.
|
|
249
249
|
- Double-click a section, or use its pencil, to edit it in place; `⌘S` saves,
|
|
250
250
|
`Esc` cancels. The edit is written back to the file on disk.
|
|
251
|
+
- Select text and press the comment button to start a thread on it. Agents reply by editing the
|
|
252
|
+
file, since threads live in the doc's frontmatter. See
|
|
253
|
+
[comments](docs/advanced.md#comments).
|
|
251
254
|
- Saving a file from your editor re-renders the open page, and a toast names what changed.
|
|
252
255
|
- In a folder listing, select files to move them to the OS Trash (never deleted outright).
|
|
253
256
|
- Diagrams and charts open full-screen; a flowchart's direction can be flipped without
|
package/client/DocView.tsx
CHANGED
|
@@ -2,16 +2,11 @@ import { useLayoutEffect, useMemo, useRef } from "react";
|
|
|
2
2
|
import { useAtomValue, useSetAtom } from "jotai";
|
|
3
3
|
import { DocContext } from "./DocContext";
|
|
4
4
|
import { ErrorBox } from "./ErrorBox";
|
|
5
|
+
import { useFullWidth } from "./hooks";
|
|
5
6
|
import { RenderErrorBoundary } from "./RenderErrorBoundary";
|
|
6
7
|
import type { DocModuleState } from "./doc-module-cache";
|
|
7
8
|
import { ResizeHandle } from "./ui/ResizeHandle";
|
|
8
|
-
import {
|
|
9
|
-
contentLayoutAtom,
|
|
10
|
-
DOC_MAX_WIDTH,
|
|
11
|
-
DOC_MIN_WIDTH,
|
|
12
|
-
docWidthAtom,
|
|
13
|
-
openSectionAtom,
|
|
14
|
-
} from "./state";
|
|
9
|
+
import { DOC_MAX_WIDTH, DOC_MIN_WIDTH, docWidthAtom, openSectionAtom } from "./state";
|
|
15
10
|
|
|
16
11
|
// Each Component a re-import produces (including an HMR re-import after a
|
|
17
12
|
// fix) is a distinct function identity, so this assigns it a stable, unique
|
|
@@ -51,7 +46,7 @@ export function DocView({
|
|
|
51
46
|
onRendered?: () => void;
|
|
52
47
|
}) {
|
|
53
48
|
const cached = module;
|
|
54
|
-
const fullWidth =
|
|
49
|
+
const fullWidth = useFullWidth();
|
|
55
50
|
const setWidth = useSetAtom(docWidthAtom);
|
|
56
51
|
// While a section is being edited the page width is pinned: a drag would
|
|
57
52
|
// reflow the editor under the caret, and the handles' hover strips sit
|
package/client/ListingView.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AnimatePresence, motion } from "framer-motion";
|
|
2
|
-
import { useAtom,
|
|
2
|
+
import { useAtom, useSetAtom } from "jotai";
|
|
3
3
|
import { useMutation } from "@tanstack/react-query";
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
|
5
5
|
import { queryClient, trpc } from "./api";
|
|
6
6
|
import { formatModified, formatSize } from "./format";
|
|
7
|
+
import { useFullWidth } from "./hooks";
|
|
7
8
|
import { stagger, TRANSITIONS, VARIANTS } from "./motion";
|
|
8
9
|
import { Icon } from "./ui/Icon";
|
|
9
10
|
import { ResizeHandle } from "./ui/ResizeHandle";
|
|
@@ -13,7 +14,6 @@ import { shellInfo, type ListingEntry } from "./router";
|
|
|
13
14
|
import Button from "./builtins/Button";
|
|
14
15
|
import Dropdown from "./builtins/Dropdown";
|
|
15
16
|
import {
|
|
16
|
-
contentLayoutAtom,
|
|
17
17
|
LISTING_MAX_WIDTH,
|
|
18
18
|
LISTING_MIN_WIDTH,
|
|
19
19
|
listingSortAtom,
|
|
@@ -391,7 +391,7 @@ export function ListingView({
|
|
|
391
391
|
[sorted, sidebar],
|
|
392
392
|
);
|
|
393
393
|
const setWidth = useSetAtom(listingWidthAtom);
|
|
394
|
-
const fullWidth =
|
|
394
|
+
const fullWidth = useFullWidth();
|
|
395
395
|
const container = useRef<HTMLDivElement>(null);
|
|
396
396
|
|
|
397
397
|
const [selectedNames, setSelectedNames] = useState<Set<string>>(new Set());
|
package/client/Settings.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import Network from "lucide-react/dist/esm/icons/network.mjs";
|
|
|
5
5
|
import PanelsTopLeft from "lucide-react/dist/esm/icons/panels-top-left.mjs";
|
|
6
6
|
import SettingsIcon from "lucide-react/dist/esm/icons/settings.mjs";
|
|
7
7
|
import CloseIcon from "lucide-react/dist/esm/icons/x.mjs";
|
|
8
|
+
import { useCompactScreen } from "./hooks";
|
|
8
9
|
import { contentLayoutAtom, tocVisibleAtom, type ContentLayout } from "./state";
|
|
9
10
|
import { Modal } from "./ui/Modal";
|
|
10
11
|
|
|
@@ -22,6 +23,8 @@ export function Settings({
|
|
|
22
23
|
const [category, setCategory] = useState<"diagrams" | "layout">(diagrams ? "diagrams" : "layout");
|
|
23
24
|
const [layout, setLayout] = useAtom(contentLayoutAtom);
|
|
24
25
|
const [tocVisible, setTocVisible] = useAtom(tocVisibleAtom);
|
|
26
|
+
// Phones always fill the width (see useFullWidth), so the choice is moot there.
|
|
27
|
+
const compact = useCompactScreen();
|
|
25
28
|
return (
|
|
26
29
|
<Modal
|
|
27
30
|
open
|
|
@@ -72,27 +75,29 @@ export function Settings({
|
|
|
72
75
|
<section>
|
|
73
76
|
<h3>Layout</h3>
|
|
74
77
|
<p>Choose how content fills the available space.</p>
|
|
75
|
-
|
|
76
|
-
<
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<select
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
{compact ? null : (
|
|
79
|
+
<label className="diagram-setting-row" htmlFor="content-layout">
|
|
80
|
+
<span>
|
|
81
|
+
<strong>Content layout</strong>
|
|
82
|
+
<small>
|
|
83
|
+
{layout === "flexible"
|
|
84
|
+
? "Drag the bars to resize content."
|
|
85
|
+
: "Content automatically fills the available width."}
|
|
86
|
+
</small>
|
|
87
|
+
</span>
|
|
88
|
+
<span className="diagram-agent-select">
|
|
89
|
+
<select
|
|
90
|
+
id="content-layout"
|
|
91
|
+
value={layout}
|
|
92
|
+
onChange={(event) => setLayout(event.target.value as ContentLayout)}
|
|
93
|
+
>
|
|
94
|
+
<option value="flexible">Flexible</option>
|
|
95
|
+
<option value="full-width">Full width</option>
|
|
96
|
+
</select>
|
|
97
|
+
<ChevronDown size={14} aria-hidden="true" />
|
|
98
|
+
</span>
|
|
99
|
+
</label>
|
|
100
|
+
)}
|
|
96
101
|
<label className="diagram-setting-row" htmlFor="toc-visibility">
|
|
97
102
|
<span>
|
|
98
103
|
<strong>Table of contents</strong>
|
package/client/app.css
CHANGED
|
@@ -165,6 +165,15 @@ html {
|
|
|
165
165
|
scroll-padding-top: calc(var(--topbar-height) + var(--space-2));
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/* Keep the page from panning sideways or rubber-banding on touch devices.
|
|
169
|
+
`clip` rather than `hidden`, so the sticky topbar and sidebar keep working;
|
|
170
|
+
wide content (code, tables, diagrams) scrolls inside its own box instead. */
|
|
171
|
+
html,
|
|
172
|
+
body {
|
|
173
|
+
overflow-x: clip;
|
|
174
|
+
overscroll-behavior: none;
|
|
175
|
+
}
|
|
176
|
+
|
|
168
177
|
@media (prefers-reduced-motion: no-preference) {
|
|
169
178
|
html {
|
|
170
179
|
scroll-behavior: smooth;
|
|
@@ -366,6 +375,17 @@ code[data-line-numbers-max-digits="4"] [data-line]::before {
|
|
|
366
375
|
}
|
|
367
376
|
}
|
|
368
377
|
|
|
378
|
+
/* Comment highlights (client/comments/highlights.ts) use the CSS Custom Highlight API,
|
|
379
|
+
so React's DOM is untouched. Browsers without it show the panel and no marks. */
|
|
380
|
+
::highlight(mdxserve-comment) {
|
|
381
|
+
background-color: var(--status-warn-bg);
|
|
382
|
+
color: inherit;
|
|
383
|
+
}
|
|
384
|
+
::highlight(mdxserve-comment-active) {
|
|
385
|
+
background-color: color-mix(in oklab, var(--status-warn-fg) 32%, var(--status-warn-bg));
|
|
386
|
+
color: inherit;
|
|
387
|
+
}
|
|
388
|
+
|
|
369
389
|
/* Print: the reader gets the prose, nothing else. */
|
|
370
390
|
@media print {
|
|
371
391
|
[data-print-hide] {
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { useAtomValue } from "jotai";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import type { CommentThread } from "../../src/comments/schema";
|
|
4
|
+
import { CtlButton } from "./CtlButton";
|
|
5
|
+
import { DraftThread } from "./DraftThread";
|
|
6
|
+
import type { CommentsModel } from "./model";
|
|
7
|
+
import { activeThreadAtom, draftAtom } from "./state";
|
|
8
|
+
import { Thread } from "./Thread";
|
|
9
|
+
|
|
10
|
+
type Tab = "open" | "resolved";
|
|
11
|
+
|
|
12
|
+
function Tabs({
|
|
13
|
+
tab,
|
|
14
|
+
onChange,
|
|
15
|
+
openCount,
|
|
16
|
+
resolvedCount,
|
|
17
|
+
}: {
|
|
18
|
+
tab: Tab;
|
|
19
|
+
onChange: (next: Tab) => void;
|
|
20
|
+
openCount: number;
|
|
21
|
+
resolvedCount: number;
|
|
22
|
+
}) {
|
|
23
|
+
const entries: Array<{ value: Tab; label: string; count: number }> = [
|
|
24
|
+
{ value: "open", label: "Open", count: openCount },
|
|
25
|
+
{ value: "resolved", label: "Resolved", count: resolvedCount },
|
|
26
|
+
];
|
|
27
|
+
return (
|
|
28
|
+
<div role="tablist" aria-label="Comment status" className="flex gap-3.5 self-stretch">
|
|
29
|
+
{entries.map((entry) => (
|
|
30
|
+
<button
|
|
31
|
+
key={entry.value}
|
|
32
|
+
type="button"
|
|
33
|
+
role="tab"
|
|
34
|
+
aria-selected={tab === entry.value}
|
|
35
|
+
onClick={() => onChange(entry.value)}
|
|
36
|
+
className={
|
|
37
|
+
"-mb-px inline-flex cursor-pointer items-center gap-[5px] border-0 border-b-2 bg-transparent p-0 text-[12.5px] leading-none font-semibold tabular-nums " +
|
|
38
|
+
(tab === entry.value
|
|
39
|
+
? "border-text-heading text-text-heading"
|
|
40
|
+
: "border-transparent text-text-subtle hover:text-text-heading")
|
|
41
|
+
}
|
|
42
|
+
>
|
|
43
|
+
{entry.label}
|
|
44
|
+
<span className="font-medium text-text-subtle">{entry.count}</span>
|
|
45
|
+
</button>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Header and thread list shared by the docked sidebar and the phone sheet. */
|
|
52
|
+
export function CommentsPanel({
|
|
53
|
+
model,
|
|
54
|
+
variant,
|
|
55
|
+
onClose,
|
|
56
|
+
}: {
|
|
57
|
+
model: CommentsModel;
|
|
58
|
+
variant: "sidebar" | "sheet";
|
|
59
|
+
onClose: () => void;
|
|
60
|
+
}) {
|
|
61
|
+
const [tab, setTab] = useState<Tab>("open");
|
|
62
|
+
const activeId = useAtomValue(activeThreadAtom);
|
|
63
|
+
// The composer is the sheet's: on desktop a new comment opens in the popover.
|
|
64
|
+
const draft = useAtomValue(draftAtom);
|
|
65
|
+
const { threads, views, readOnly } = model;
|
|
66
|
+
const sheet = variant === "sheet";
|
|
67
|
+
|
|
68
|
+
// Selecting a thread (a highlight click, say) shows the tab that holds it.
|
|
69
|
+
const threadsRef = useRef(threads);
|
|
70
|
+
threadsRef.current = threads;
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const active = threadsRef.current.find((thread) => thread.id === activeId);
|
|
73
|
+
if (active) setTab(active.resolved ? "resolved" : "open");
|
|
74
|
+
}, [activeId]);
|
|
75
|
+
|
|
76
|
+
const { open, detached, resolved } = useMemo(() => {
|
|
77
|
+
const unresolved = threads.filter((thread) => !thread.resolved);
|
|
78
|
+
const placed: Array<{ thread: CommentThread; position: number; order: number }> = [];
|
|
79
|
+
const lost: CommentThread[] = [];
|
|
80
|
+
unresolved.forEach((thread, order) => {
|
|
81
|
+
const view = views.get(thread.id);
|
|
82
|
+
if (view?.resolution.state === "detached") lost.push(thread);
|
|
83
|
+
else placed.push({ thread, position: view?.position ?? Number.MAX_SAFE_INTEGER, order });
|
|
84
|
+
});
|
|
85
|
+
placed.sort((left, right) => left.position - right.position || left.order - right.order);
|
|
86
|
+
return {
|
|
87
|
+
open: placed.map((entry) => entry.thread),
|
|
88
|
+
detached: lost,
|
|
89
|
+
resolved: threads.filter((thread) => thread.resolved),
|
|
90
|
+
};
|
|
91
|
+
}, [threads, views]);
|
|
92
|
+
|
|
93
|
+
const shown = tab === "open" ? open : resolved;
|
|
94
|
+
const empty = open.length === 0 && detached.length === 0;
|
|
95
|
+
|
|
96
|
+
function renderThread(thread: CommentThread) {
|
|
97
|
+
return (
|
|
98
|
+
<Thread
|
|
99
|
+
key={`${model.path}:${thread.id}`}
|
|
100
|
+
thread={thread}
|
|
101
|
+
view={views.get(thread.id)}
|
|
102
|
+
active={thread.id === activeId}
|
|
103
|
+
variant={variant}
|
|
104
|
+
model={model}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
<div
|
|
112
|
+
className={
|
|
113
|
+
"flex h-[42px] shrink-0 items-center gap-3 border-b pr-2 pl-4 " +
|
|
114
|
+
(sheet ? "border-border-subtle" : "border-border-default")
|
|
115
|
+
}
|
|
116
|
+
>
|
|
117
|
+
<Tabs
|
|
118
|
+
tab={tab}
|
|
119
|
+
onChange={setTab}
|
|
120
|
+
openCount={open.length + detached.length}
|
|
121
|
+
resolvedCount={resolved.length}
|
|
122
|
+
/>
|
|
123
|
+
<span className="flex-1" />
|
|
124
|
+
<CtlButton
|
|
125
|
+
icon="x"
|
|
126
|
+
label="Close comments"
|
|
127
|
+
className="max-md:h-9 max-md:w-9"
|
|
128
|
+
onClick={onClose}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
<div className="min-h-0 flex-1 overflow-y-auto [scrollbar-color:var(--border-strong)_transparent] [scrollbar-width:thin]">
|
|
132
|
+
{sheet && draft ? (
|
|
133
|
+
<div className="border-b border-border-default">
|
|
134
|
+
<DraftThread model={model} sidebarOpen={false} reserveTools={false} padded />
|
|
135
|
+
</div>
|
|
136
|
+
) : null}
|
|
137
|
+
<div className="divide-y divide-border-default">
|
|
138
|
+
{shown.map(renderThread)}
|
|
139
|
+
{tab === "open" && detached.length > 0 ? (
|
|
140
|
+
<div>
|
|
141
|
+
<h3 className="m-0 px-4 pt-3.5 text-[length:var(--size-2xs)] font-semibold tracking-wide text-text-subtle uppercase">
|
|
142
|
+
Detached
|
|
143
|
+
</h3>
|
|
144
|
+
<div className="divide-y divide-border-default">{detached.map(renderThread)}</div>
|
|
145
|
+
</div>
|
|
146
|
+
) : null}
|
|
147
|
+
</div>
|
|
148
|
+
{tab === "open" && empty && !draft ? (
|
|
149
|
+
<p className="m-0 px-4 py-4 text-[length:var(--size-sm)] text-text-subtle">
|
|
150
|
+
{readOnly
|
|
151
|
+
? "No open comments."
|
|
152
|
+
: "No open comments. Select text in the doc to add one."}
|
|
153
|
+
</p>
|
|
154
|
+
) : null}
|
|
155
|
+
{tab === "resolved" && resolved.length === 0 ? (
|
|
156
|
+
<p className="m-0 px-4 py-4 text-[length:var(--size-sm)] text-text-subtle">
|
|
157
|
+
No resolved comments.
|
|
158
|
+
</p>
|
|
159
|
+
) : null}
|
|
160
|
+
</div>
|
|
161
|
+
</>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { autoUpdate, computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
2
|
+
import { useAtom } from "jotai";
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, type ReactNode } from "react";
|
|
4
|
+
import { CtlButton } from "./CtlButton";
|
|
5
|
+
import { DraftThread } from "./DraftThread";
|
|
6
|
+
import { threadAtPoint } from "./highlights";
|
|
7
|
+
import type { CommentsModel } from "./model";
|
|
8
|
+
import { draftAtom } from "./state";
|
|
9
|
+
import { Thread } from "./Thread";
|
|
10
|
+
|
|
11
|
+
const GAP = 8;
|
|
12
|
+
const EDGE = 16;
|
|
13
|
+
|
|
14
|
+
/** Where the popover hangs: the thread's range when it has one, else its block. */
|
|
15
|
+
function useReference(range: Range | null, element: Element | null) {
|
|
16
|
+
return useMemo(() => {
|
|
17
|
+
if (!range && !element) return null;
|
|
18
|
+
return {
|
|
19
|
+
getBoundingClientRect: () =>
|
|
20
|
+
range?.getBoundingClientRect() ?? element?.getBoundingClientRect() ?? new DOMRect(),
|
|
21
|
+
getClientRects: () => (range ? range.getClientRects() : element?.getClientRects()) ?? [],
|
|
22
|
+
contextElement: element ?? undefined,
|
|
23
|
+
};
|
|
24
|
+
}, [range, element]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A 360px card under the highlight with the thread's timeline. Placed with
|
|
29
|
+
* floating-ui against the range, and follows scroll and resize. Escape or a
|
|
30
|
+
* click outside closes it.
|
|
31
|
+
*/
|
|
32
|
+
function PopoverFrame({
|
|
33
|
+
reference,
|
|
34
|
+
onClose,
|
|
35
|
+
keepOpen,
|
|
36
|
+
focusFrame,
|
|
37
|
+
label,
|
|
38
|
+
tools,
|
|
39
|
+
children,
|
|
40
|
+
}: {
|
|
41
|
+
reference: ReturnType<typeof useReference>;
|
|
42
|
+
onClose: () => void;
|
|
43
|
+
/** An outside click leaves it open (a draft with text in it). */
|
|
44
|
+
keepOpen: boolean;
|
|
45
|
+
focusFrame: boolean;
|
|
46
|
+
label: string;
|
|
47
|
+
tools: ReactNode;
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
}) {
|
|
50
|
+
const frameRef = useRef<HTMLDivElement>(null);
|
|
51
|
+
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
const floating = frameRef.current;
|
|
54
|
+
if (!reference || !floating) return;
|
|
55
|
+
return autoUpdate(reference, floating, () => {
|
|
56
|
+
void computePosition(reference, floating, {
|
|
57
|
+
strategy: "fixed",
|
|
58
|
+
placement: "bottom-start",
|
|
59
|
+
middleware: [offset(GAP), flip({ padding: EDGE }), shift({ padding: EDGE })],
|
|
60
|
+
}).then(({ x, y }) => {
|
|
61
|
+
floating.style.left = `${x}px`;
|
|
62
|
+
floating.style.top = `${y}px`;
|
|
63
|
+
floating.style.visibility = "visible";
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}, [reference]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (focusFrame) frameRef.current?.focus({ preventScroll: true });
|
|
70
|
+
}, [focusFrame]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
function onKeyDown(event: KeyboardEvent) {
|
|
74
|
+
if (event.key === "Escape" && !event.defaultPrevented) onClose();
|
|
75
|
+
}
|
|
76
|
+
function onPointerDown(event: PointerEvent) {
|
|
77
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
78
|
+
if (!target || frameRef.current?.contains(target)) return;
|
|
79
|
+
if (keepOpen || target.closest("[data-comments-keep]")) return;
|
|
80
|
+
// A comment being edited holds unsaved text: Escape or Close ends it, a stray click does not.
|
|
81
|
+
if (frameRef.current?.querySelector("[data-comment-edit]")) return;
|
|
82
|
+
// A click on another highlight is handled there: it swaps the thread.
|
|
83
|
+
if (threadAtPoint(event.clientX, event.clientY)) return;
|
|
84
|
+
onClose();
|
|
85
|
+
}
|
|
86
|
+
window.addEventListener("keydown", onKeyDown);
|
|
87
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
88
|
+
return () => {
|
|
89
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
90
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
91
|
+
};
|
|
92
|
+
}, [onClose, keepOpen]);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div
|
|
96
|
+
ref={frameRef}
|
|
97
|
+
role="dialog"
|
|
98
|
+
aria-label={label}
|
|
99
|
+
tabIndex={-1}
|
|
100
|
+
data-print-hide
|
|
101
|
+
style={{ position: "fixed", left: 0, top: 0, visibility: "hidden" }}
|
|
102
|
+
className="z-[var(--z-dropdown)] w-[360px] max-w-[calc(100vw-32px)] rounded-xl border border-border-default bg-surface-card shadow-lg outline-0"
|
|
103
|
+
>
|
|
104
|
+
<span className="absolute top-2 right-2 z-[1] flex">{tools}</span>
|
|
105
|
+
<div className="max-h-[min(70vh,560px)] overflow-y-auto p-3.5 [scrollbar-color:var(--border-strong)_transparent] [scrollbar-width:thin]">
|
|
106
|
+
{children}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The popover for desktop with the sidebar closed: an existing thread (opened
|
|
114
|
+
* from a highlight or a gutter counter) or a new comment's composer. A new
|
|
115
|
+
* comment opens it whether or not the sidebar is open.
|
|
116
|
+
*/
|
|
117
|
+
export function CommentsPopover({
|
|
118
|
+
model,
|
|
119
|
+
sidebarOpen,
|
|
120
|
+
}: {
|
|
121
|
+
model: CommentsModel;
|
|
122
|
+
sidebarOpen: boolean;
|
|
123
|
+
}) {
|
|
124
|
+
const [draft, setDraft] = useAtom(draftAtom);
|
|
125
|
+
const thread = draft ? undefined : model.threads.find((entry) => entry.id === model.popoverId);
|
|
126
|
+
const view = thread ? model.views.get(thread.id) : undefined;
|
|
127
|
+
const reference = useReference(
|
|
128
|
+
draft ? draft.range : (view?.range ?? null),
|
|
129
|
+
draft ? null : (view?.scrollTarget ?? null),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const close = model.closePopover;
|
|
133
|
+
const discardDraft = () => setDraft(null);
|
|
134
|
+
const writing = draft !== null && draft.body.trim() !== "";
|
|
135
|
+
// Read when a request finishes, so a newer popover is not dismissed by an older resolve.
|
|
136
|
+
const shownId = useRef(model.popoverId);
|
|
137
|
+
shownId.current = model.popoverId;
|
|
138
|
+
|
|
139
|
+
if (draft) {
|
|
140
|
+
return (
|
|
141
|
+
<PopoverFrame
|
|
142
|
+
reference={reference}
|
|
143
|
+
onClose={discardDraft}
|
|
144
|
+
keepOpen={writing}
|
|
145
|
+
focusFrame={false}
|
|
146
|
+
label="New comment"
|
|
147
|
+
tools={<CtlButton icon="x" label="Discard comment" onClick={discardDraft} />}
|
|
148
|
+
>
|
|
149
|
+
<DraftThread model={model} sidebarOpen={sidebarOpen} reserveTools padded={false} />
|
|
150
|
+
</PopoverFrame>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (!thread || thread.resolved) return null;
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<PopoverFrame
|
|
157
|
+
key={thread.id}
|
|
158
|
+
reference={reference}
|
|
159
|
+
onClose={close}
|
|
160
|
+
keepOpen={false}
|
|
161
|
+
focusFrame
|
|
162
|
+
label="Comment thread"
|
|
163
|
+
tools={
|
|
164
|
+
<>
|
|
165
|
+
{model.readOnly ? null : (
|
|
166
|
+
<CtlButton
|
|
167
|
+
tone="resolve"
|
|
168
|
+
icon="check"
|
|
169
|
+
label="Resolve thread"
|
|
170
|
+
disabled={model.writesDisabled}
|
|
171
|
+
onClick={() => {
|
|
172
|
+
void model.actions.setResolved(thread.id, true).then((saved) => {
|
|
173
|
+
if (saved && shownId.current === thread.id) close();
|
|
174
|
+
});
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
)}
|
|
178
|
+
<CtlButton
|
|
179
|
+
icon="panel-right"
|
|
180
|
+
label="Open in sidebar"
|
|
181
|
+
onClick={() => model.openInSidebar(thread.id)}
|
|
182
|
+
/>
|
|
183
|
+
<CtlButton icon="x" label="Close" onClick={close} />
|
|
184
|
+
</>
|
|
185
|
+
}
|
|
186
|
+
>
|
|
187
|
+
<Thread
|
|
188
|
+
key={`${model.path}:${thread.id}`}
|
|
189
|
+
thread={thread}
|
|
190
|
+
view={view}
|
|
191
|
+
active
|
|
192
|
+
variant="popover"
|
|
193
|
+
model={model}
|
|
194
|
+
/>
|
|
195
|
+
</PopoverFrame>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
2
|
+
import { useAtomValue } from "jotai";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { TRANSITIONS } from "../motion";
|
|
5
|
+
import { CommentsPanel } from "./CommentsPanel";
|
|
6
|
+
import type { CommentsModel } from "./model";
|
|
7
|
+
import { draftAtom } from "./state";
|
|
8
|
+
|
|
9
|
+
/** Phone-width panel: rises from the bottom, 70% of the screen at most, list scrolls inside. Same header and threads as the sidebar. */
|
|
10
|
+
export function CommentsSheet({
|
|
11
|
+
model,
|
|
12
|
+
open,
|
|
13
|
+
onClose,
|
|
14
|
+
}: {
|
|
15
|
+
model: CommentsModel;
|
|
16
|
+
open: boolean;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
}) {
|
|
19
|
+
const hasDraft = useAtomValue(draftAtom) !== null;
|
|
20
|
+
|
|
21
|
+
// Escape discards a draft first (SelectionButton); the sheet closes on the next one.
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!open || hasDraft) return;
|
|
24
|
+
function onKeyDown(event: KeyboardEvent) {
|
|
25
|
+
if (event.key === "Escape") onClose();
|
|
26
|
+
}
|
|
27
|
+
window.addEventListener("keydown", onKeyDown);
|
|
28
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
29
|
+
}, [open, hasDraft, onClose]);
|
|
30
|
+
|
|
31
|
+
// Reserve scroll room so text at the end of the doc can be scrolled above the sheet.
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!open) return;
|
|
34
|
+
const previous = document.body.style.paddingBottom;
|
|
35
|
+
document.body.style.paddingBottom = "70vh";
|
|
36
|
+
return () => {
|
|
37
|
+
document.body.style.paddingBottom = previous;
|
|
38
|
+
};
|
|
39
|
+
}, [open]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<AnimatePresence>
|
|
43
|
+
{open ? (
|
|
44
|
+
<motion.aside
|
|
45
|
+
key="comments-sheet"
|
|
46
|
+
data-print-hide
|
|
47
|
+
aria-label="Comments"
|
|
48
|
+
initial={{ y: "100%" }}
|
|
49
|
+
animate={{ y: 0 }}
|
|
50
|
+
exit={{ y: "100%" }}
|
|
51
|
+
transition={TRANSITIONS.glide}
|
|
52
|
+
className="fixed inset-x-0 bottom-0 z-[var(--z-modal)] flex max-h-[70vh] flex-col rounded-t-[16px] bg-surface-card shadow-lg md:hidden"
|
|
53
|
+
>
|
|
54
|
+
<span
|
|
55
|
+
aria-hidden
|
|
56
|
+
className="mx-auto mt-2 mb-0.5 h-1 w-9 shrink-0 rounded-full bg-border-strong"
|
|
57
|
+
/>
|
|
58
|
+
<CommentsPanel model={model} variant="sheet" onClose={onClose} />
|
|
59
|
+
</motion.aside>
|
|
60
|
+
) : null}
|
|
61
|
+
</AnimatePresence>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CommentsPanel } from "./CommentsPanel";
|
|
2
|
+
import type { CommentsModel } from "./model";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Desktop column: 348px, full height under the top bar, flush to the window's
|
|
6
|
+
* right edge. A sibling of `<main>` in AppShell, so the doc column narrows to make room.
|
|
7
|
+
*/
|
|
8
|
+
export function CommentsSidebar({ model, onClose }: { model: CommentsModel; onClose: () => void }) {
|
|
9
|
+
return (
|
|
10
|
+
<aside
|
|
11
|
+
data-print-hide
|
|
12
|
+
aria-label="Comments"
|
|
13
|
+
className="sticky top-topbar flex h-[calc(100vh-var(--topbar-height))] w-[348px] shrink-0 flex-col border-l border-border-default bg-surface-page"
|
|
14
|
+
>
|
|
15
|
+
<CommentsPanel model={model} variant="sidebar" onClose={onClose} />
|
|
16
|
+
</aside>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { forwardRef, type ButtonHTMLAttributes } from "react";
|
|
2
|
+
import { Icon } from "../ui/Icon";
|
|
3
|
+
|
|
4
|
+
export interface CtlButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
icon: string;
|
|
6
|
+
/** Accessible name; also the tooltip. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** `resolve` turns green on hover: the checkmark that closes a thread. */
|
|
9
|
+
tone?: "plain" | "resolve";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The 26px borderless icon button used in thread headers and the panel header. */
|
|
13
|
+
export const CtlButton = forwardRef<HTMLButtonElement, CtlButtonProps>(function CtlButton(
|
|
14
|
+
{ icon, label, tone = "plain", className, ...rest },
|
|
15
|
+
ref,
|
|
16
|
+
) {
|
|
17
|
+
return (
|
|
18
|
+
<button
|
|
19
|
+
ref={ref}
|
|
20
|
+
type="button"
|
|
21
|
+
aria-label={label}
|
|
22
|
+
title={label}
|
|
23
|
+
className={
|
|
24
|
+
"inline-grid h-[26px] w-[26px] shrink-0 cursor-pointer place-items-center rounded-md border-0 bg-transparent p-0 text-text-subtle transition-colors hover:bg-surface-hover hover:text-text-heading disabled:cursor-not-allowed disabled:opacity-45 disabled:hover:bg-transparent disabled:hover:text-text-subtle " +
|
|
25
|
+
(tone === "resolve" ? "hover:bg-status-ok-bg hover:text-status-ok-fg " : "") +
|
|
26
|
+
(className ?? "")
|
|
27
|
+
}
|
|
28
|
+
{...rest}
|
|
29
|
+
>
|
|
30
|
+
<Icon name={icon} size={15} />
|
|
31
|
+
</button>
|
|
32
|
+
);
|
|
33
|
+
});
|