@peaske7/readit 0.1.8 → 0.2.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/.claude/CLAUDE.md +118 -76
- package/.claude/commands/review.md +1 -1
- package/.claude/roadmap.md +32 -9
- package/.claude/user-stories.md +100 -15
- package/AGENTS.md +30 -26
- package/Makefile +32 -0
- package/README.md +90 -5
- package/biome.json +18 -8
- package/bun.lock +426 -710
- package/bunfig.toml +2 -0
- package/docs/perf-baseline.md +130 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
- package/e2e/comments.spec.ts +14 -58
- package/e2e/document-load.spec.ts +1 -23
- package/e2e/export.spec.ts +4 -4
- package/e2e/perf/add-comment.spec.ts +116 -0
- package/e2e/perf/fixtures/generate.ts +327 -0
- package/e2e/perf/initial-load.spec.ts +49 -0
- package/e2e/perf/perf.setup.ts +23 -0
- package/e2e/perf/perf.teardown.ts +9 -0
- package/e2e/perf/screenshot-final.png +0 -0
- package/e2e/perf/scroll.spec.ts +39 -0
- package/e2e/perf/tab-switch.spec.ts +69 -0
- package/e2e/perf/text-selection.spec.ts +119 -0
- package/e2e/perf/utils/metrics.ts +350 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/e2e/persistence-file.spec.ts +41 -26
- package/e2e/utils/selection.ts +17 -73
- package/go/cmd/readit/main.go +416 -0
- package/go/go.mod +20 -0
- package/go/go.sum +41 -0
- package/go/internal/server/anchor.go +302 -0
- package/go/internal/server/anchor_test.go +111 -0
- package/go/internal/server/comments.go +390 -0
- package/go/internal/server/documents.go +113 -0
- package/go/internal/server/embed.go +17 -0
- package/go/internal/server/headings.go +33 -0
- package/go/internal/server/headings_test.go +75 -0
- package/go/internal/server/htmltext.go +123 -0
- package/go/internal/server/markdown.go +157 -0
- package/go/internal/server/markdown_bench_test.go +42 -0
- package/go/internal/server/markdown_test.go +79 -0
- package/go/internal/server/server.go +453 -0
- package/go/internal/server/server_bench_test.go +122 -0
- package/go/internal/server/settings.go +110 -0
- package/go/internal/server/sse.go +140 -0
- package/go/internal/server/storage.go +275 -0
- package/go/internal/server/storage_test.go +118 -0
- package/go/internal/server/template.go +66 -0
- package/go/internal/server/types.go +101 -0
- package/go/internal/server/watcher.go +74 -0
- package/index.html +4 -14
- package/nvim-readit/lua/readit/health.lua +64 -0
- package/nvim-readit/lua/readit/init.lua +463 -0
- package/nvim-readit/plugin/readit.lua +19 -0
- package/package.json +24 -41
- package/playwright.config.ts +12 -0
- package/shell/_readit +158 -0
- package/shell/readit.zsh +87 -0
- package/src/App.svelte +881 -0
- package/src/{cli/index.ts → cli.ts} +216 -70
- package/src/components/ActionsMenu.svelte +95 -0
- package/src/components/CommentBadge.svelte +67 -0
- package/src/components/CommentErrorBanner.svelte +33 -0
- package/src/components/CommentInput.svelte +75 -0
- package/src/components/CommentListItem.svelte +95 -0
- package/src/components/CommentManager.svelte +129 -0
- package/src/components/CommentNav.svelte +109 -0
- package/src/components/DocumentViewer.svelte +218 -0
- package/src/components/FloatingComment.svelte +107 -0
- package/src/components/Header.svelte +76 -0
- package/src/components/InlineEditor.svelte +72 -0
- package/src/components/MarginNote.svelte +167 -0
- package/src/components/MarginNotesContainer.svelte +33 -0
- package/src/components/RawModal.svelte +126 -0
- package/src/components/ReanchorConfirm.svelte +30 -0
- package/src/components/SettingsModal.svelte +220 -0
- package/src/components/ShortcutCapture.svelte +82 -0
- package/src/components/ShortcutList.svelte +145 -0
- package/src/components/TabBar.svelte +52 -0
- package/src/components/TableOfContents.svelte +125 -0
- package/src/components/ui/ActionLink.svelte +40 -0
- package/src/components/ui/Button.svelte +53 -0
- package/src/components/ui/Dialog.svelte +97 -0
- package/src/components/ui/DropdownMenu.svelte +85 -0
- package/src/components/ui/DropdownMenuItem.svelte +38 -0
- package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
- package/src/components/ui/Text.svelte +42 -0
- package/src/env.d.ts +6 -0
- package/src/index.css +36 -166
- package/src/lib/__fixtures__/bench-data.ts +1 -54
- package/src/lib/anchor.bench.ts +47 -68
- package/src/lib/anchor.test.ts +5 -9
- package/src/lib/anchor.ts +9 -93
- package/src/lib/comment-storage.bench.ts +6 -20
- package/src/lib/comment-storage.test.ts +45 -37
- package/src/lib/comment-storage.ts +23 -64
- package/src/lib/export.bench.ts +9 -23
- package/src/lib/export.ts +7 -14
- package/src/lib/headings.test.ts +103 -0
- package/src/lib/headings.ts +44 -0
- package/src/lib/highlight/core.test.ts +1 -6
- package/src/lib/highlight/dom.ts +53 -280
- package/src/lib/highlight/highlight-registry.ts +221 -0
- package/src/lib/highlight/highlight.bench.ts +92 -0
- package/src/lib/highlight/highlighter.ts +122 -302
- package/src/lib/highlight/{core.ts → resolver.ts} +3 -19
- package/src/lib/highlight/types.ts +0 -40
- package/src/lib/html-text.test.ts +162 -0
- package/src/lib/html-text.ts +161 -0
- package/src/lib/i18n/en.ts +13 -36
- package/src/lib/i18n/ja.ts +14 -37
- package/src/lib/i18n/types.ts +13 -36
- package/src/lib/margin-layout.bench.ts +48 -15
- package/src/lib/margin-layout.ts +2 -31
- package/src/lib/markdown-renderer.test.ts +154 -0
- package/src/lib/markdown-renderer.ts +177 -0
- package/src/lib/mermaid-config.ts +38 -0
- package/src/lib/mermaid-renderer.ts +162 -0
- package/src/lib/mermaid-worker.ts +60 -0
- package/src/lib/positions.ts +157 -0
- package/src/lib/shortcut-registry.ts +138 -103
- package/src/lib/utils.ts +2 -48
- package/src/main.ts +16 -0
- package/src/schema.ts +92 -0
- package/src/{server/index.ts → server.ts} +427 -163
- package/src/stores/app.svelte.ts +231 -0
- package/src/stores/locale.svelte.ts +46 -0
- package/src/stores/settings.svelte.ts +90 -0
- package/src/stores/shortcuts.svelte.ts +104 -0
- package/src/stores/ui.svelte.ts +12 -0
- package/src/template.ts +104 -0
- package/src/test-setup.ts +47 -0
- package/svelte.config.js +5 -0
- package/tsconfig.json +2 -2
- package/vite.config.ts +31 -3
- package/vscode-readit/.mcp.json +7 -0
- package/vscode-readit/.vscodeignore +7 -0
- package/vscode-readit/bun.lock +78 -0
- package/vscode-readit/icon.svg +10 -0
- package/vscode-readit/package.json +110 -0
- package/vscode-readit/src/extension.ts +117 -0
- package/vscode-readit/src/server-manager.ts +272 -0
- package/vscode-readit/src/webview-provider.ts +204 -0
- package/vscode-readit/tsconfig.json +20 -0
- package/e2e/fixtures/sample.html +0 -13
- package/src/App.tsx +0 -416
- package/src/components/ActionsMenu.tsx +0 -112
- package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
- package/src/components/DocumentViewer/DocumentViewer.tsx +0 -259
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -137
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/Header.tsx +0 -65
- package/src/components/InlineEditor.tsx +0 -74
- package/src/components/MarginNote.tsx +0 -207
- package/src/components/MarginNotes.tsx +0 -50
- package/src/components/RawModal.tsx +0 -143
- package/src/components/ReanchorConfirm.tsx +0 -36
- package/src/components/SettingsModal.tsx +0 -310
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/TabBar.tsx +0 -60
- package/src/components/TableOfContents.tsx +0 -108
- package/src/components/comments/CommentBadge.tsx +0 -49
- package/src/components/comments/CommentInput.tsx +0 -114
- package/src/components/comments/CommentListItem.tsx +0 -92
- package/src/components/comments/CommentManager.tsx +0 -113
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/comments/CommentNav.tsx +0 -109
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/ActionLink.tsx +0 -32
- package/src/components/ui/Button.tsx +0 -55
- package/src/components/ui/Dialog.tsx +0 -156
- package/src/components/ui/DropdownMenu.tsx +0 -114
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/components/ui/Text.tsx +0 -54
- package/src/contexts/CommentContext.tsx +0 -229
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/contexts/LocaleContext.tsx +0 -35
- package/src/hooks/useClickOutside.ts +0 -35
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useCommentNavigation.ts +0 -130
- package/src/hooks/useComments.ts +0 -323
- package/src/hooks/useDocument.ts +0 -156
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- package/src/hooks/useHeadings.test.ts +0 -159
- package/src/hooks/useHeadings.ts +0 -129
- package/src/hooks/useKeybindings.ts +0 -108
- package/src/hooks/useKeyboardShortcuts.ts +0 -63
- package/src/hooks/useLayoutMode.ts +0 -44
- package/src/hooks/useLocalePreference.ts +0 -42
- package/src/hooks/useReanchorMode.ts +0 -33
- package/src/hooks/useScrollMetrics.ts +0 -56
- package/src/hooks/useScrollSpy.ts +0 -81
- package/src/hooks/useTextSelection.ts +0 -123
- package/src/hooks/useThemePreference.ts +0 -66
- package/src/lib/context.bench.ts +0 -41
- package/src/lib/context.test.ts +0 -224
- package/src/lib/context.ts +0 -193
- package/src/lib/editor-links.ts +0 -59
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/index.ts +0 -23
- package/src/lib/highlight/script-builder.ts +0 -485
- package/src/lib/html-processor.test.tsx +0 -170
- package/src/lib/html-processor.tsx +0 -95
- package/src/lib/i18n/completeness.test.ts +0 -51
- package/src/lib/i18n/translations.test.ts +0 -39
- package/src/lib/layout-constants.ts +0 -12
- package/src/lib/scroll.test.ts +0 -118
- package/src/lib/scroll.ts +0 -47
- package/src/lib/shortcut-registry.test.ts +0 -173
- package/src/lib/utils.test.ts +0 -110
- package/src/main.tsx +0 -13
- package/src/store/index.test.ts +0 -242
- package/src/store/index.ts +0 -254
- package/src/types/index.ts +0 -127
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { cva } from "class-variance-authority";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { useCommentContext } from "../contexts/CommentContext";
|
|
4
|
-
import { useLayoutContext } from "../contexts/LayoutContext";
|
|
5
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
6
|
-
import { cn } from "../lib/utils";
|
|
7
|
-
import { type Comment, FontFamilies } from "../types";
|
|
8
|
-
import { InlineEditor } from "./InlineEditor";
|
|
9
|
-
import { ActionBar } from "./ui/ActionBar";
|
|
10
|
-
import { ActionLink } from "./ui/ActionLink";
|
|
11
|
-
import { SeparatorDot } from "./ui/SeparatorDot";
|
|
12
|
-
|
|
13
|
-
interface MarginNoteProps {
|
|
14
|
-
comment: Comment;
|
|
15
|
-
top: number;
|
|
16
|
-
commentIndex?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const selectedTextVariants = cva(
|
|
20
|
-
"text-sm italic mb-1 line-clamp-1 flex items-center gap-1 transition-colors duration-150",
|
|
21
|
-
{
|
|
22
|
-
variants: {
|
|
23
|
-
hovered: {
|
|
24
|
-
true: "text-zinc-600 dark:text-zinc-400",
|
|
25
|
-
false: "text-zinc-400 dark:text-zinc-500",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
defaultVariants: { hovered: false },
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const commentTextVariants = cva(
|
|
33
|
-
"text-sm whitespace-pre-wrap transition-colors duration-150",
|
|
34
|
-
{
|
|
35
|
-
variants: {
|
|
36
|
-
hovered: {
|
|
37
|
-
true: "text-zinc-800 dark:text-zinc-200",
|
|
38
|
-
false: "text-zinc-500 dark:text-zinc-400",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
defaultVariants: { hovered: false },
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const badgeVariants = cva(
|
|
46
|
-
"absolute -left-4 top-2 text-xs tabular-nums transition-colors duration-150",
|
|
47
|
-
{
|
|
48
|
-
variants: {
|
|
49
|
-
hovered: {
|
|
50
|
-
true: "text-zinc-600 dark:text-zinc-400",
|
|
51
|
-
false: "text-zinc-400 dark:text-zinc-500",
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
defaultVariants: { hovered: false },
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
export function MarginNote({
|
|
59
|
-
comment,
|
|
60
|
-
top,
|
|
61
|
-
commentIndex = 0,
|
|
62
|
-
}: MarginNoteProps) {
|
|
63
|
-
const { fontFamily } = useLayoutContext();
|
|
64
|
-
const { t } = useLocale();
|
|
65
|
-
const {
|
|
66
|
-
editComment,
|
|
67
|
-
deleteComment,
|
|
68
|
-
copyCommentRaw,
|
|
69
|
-
copyCommentForLLM,
|
|
70
|
-
hoveredCommentId,
|
|
71
|
-
setHoveredCommentId,
|
|
72
|
-
scrollToHighlight,
|
|
73
|
-
} = useCommentContext();
|
|
74
|
-
|
|
75
|
-
const isHovered = hoveredCommentId === comment.id;
|
|
76
|
-
const fontClass =
|
|
77
|
-
fontFamily === FontFamilies.SANS_SERIF ? "font-sans" : "font-serif";
|
|
78
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
79
|
-
|
|
80
|
-
const hasNote = comment.comment.trim().length > 0;
|
|
81
|
-
|
|
82
|
-
const handleCopy = () => {
|
|
83
|
-
copyCommentRaw(comment);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const createdAtFormatted = new Date(comment.createdAt).toLocaleString();
|
|
87
|
-
|
|
88
|
-
// Highlight-only (no note): minimal em-dash marker
|
|
89
|
-
if (!hasNote && !isEditing) {
|
|
90
|
-
return (
|
|
91
|
-
<article
|
|
92
|
-
className="absolute left-0 right-0 group"
|
|
93
|
-
style={{ top }}
|
|
94
|
-
title={`Added: ${createdAtFormatted}`}
|
|
95
|
-
data-comment-id={comment.id}
|
|
96
|
-
onMouseEnter={() => setHoveredCommentId(comment.id)}
|
|
97
|
-
onMouseLeave={() => setHoveredCommentId(undefined)}
|
|
98
|
-
>
|
|
99
|
-
<span className={badgeVariants({ hovered: isHovered })}>—</span>
|
|
100
|
-
|
|
101
|
-
<div className="pt-2 pb-2 pl-3">
|
|
102
|
-
<ActionBar
|
|
103
|
-
className={cn("gap-1.5 duration-150", isHovered && "opacity-100")}
|
|
104
|
-
>
|
|
105
|
-
<ActionLink onClick={() => setIsEditing(true)}>
|
|
106
|
-
{t("marginNote.addNote")}
|
|
107
|
-
</ActionLink>
|
|
108
|
-
<SeparatorDot />
|
|
109
|
-
<ActionLink
|
|
110
|
-
variant="destructive"
|
|
111
|
-
onClick={() => deleteComment(comment.id)}
|
|
112
|
-
>
|
|
113
|
-
{t("marginNote.delete")}
|
|
114
|
-
</ActionLink>
|
|
115
|
-
</ActionBar>
|
|
116
|
-
</div>
|
|
117
|
-
</article>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<article
|
|
123
|
-
className="absolute left-0 right-0 group"
|
|
124
|
-
style={{ top }}
|
|
125
|
-
title={`Added: ${createdAtFormatted}`}
|
|
126
|
-
data-comment-id={comment.id}
|
|
127
|
-
onMouseEnter={() => setHoveredCommentId(comment.id)}
|
|
128
|
-
onMouseLeave={() => setHoveredCommentId(undefined)}
|
|
129
|
-
>
|
|
130
|
-
<span className={badgeVariants({ hovered: isHovered })}>
|
|
131
|
-
{commentIndex + 1}
|
|
132
|
-
</span>
|
|
133
|
-
|
|
134
|
-
<div
|
|
135
|
-
className={cn(
|
|
136
|
-
"relative border-t border-zinc-100 dark:border-zinc-800 pt-3 pb-2 pl-3 transition-colors duration-150",
|
|
137
|
-
comment.anchorConfidence === "unresolved" && "opacity-60",
|
|
138
|
-
)}
|
|
139
|
-
>
|
|
140
|
-
{!isEditing && (
|
|
141
|
-
<div
|
|
142
|
-
className={cn(
|
|
143
|
-
fontClass,
|
|
144
|
-
selectedTextVariants({ hovered: isHovered }),
|
|
145
|
-
)}
|
|
146
|
-
>
|
|
147
|
-
<button
|
|
148
|
-
type="button"
|
|
149
|
-
onClick={() => scrollToHighlight(comment.id)}
|
|
150
|
-
className="cursor-pointer hover:underline text-left"
|
|
151
|
-
>
|
|
152
|
-
"{comment.selectedText}"
|
|
153
|
-
</button>
|
|
154
|
-
</div>
|
|
155
|
-
)}
|
|
156
|
-
|
|
157
|
-
{isEditing ? (
|
|
158
|
-
<InlineEditor
|
|
159
|
-
initialText={comment.comment}
|
|
160
|
-
onSave={(text) => {
|
|
161
|
-
editComment(comment.id, text);
|
|
162
|
-
setIsEditing(false);
|
|
163
|
-
}}
|
|
164
|
-
onCancel={() => setIsEditing(false)}
|
|
165
|
-
/>
|
|
166
|
-
) : (
|
|
167
|
-
<>
|
|
168
|
-
<p
|
|
169
|
-
className={cn(
|
|
170
|
-
fontClass,
|
|
171
|
-
commentTextVariants({ hovered: isHovered }),
|
|
172
|
-
)}
|
|
173
|
-
>
|
|
174
|
-
{comment.comment}
|
|
175
|
-
</p>
|
|
176
|
-
<ActionBar className="gap-1.5 mt-2">
|
|
177
|
-
<ActionLink onClick={() => setIsEditing(true)}>
|
|
178
|
-
{t("marginNote.edit")}
|
|
179
|
-
</ActionLink>
|
|
180
|
-
<SeparatorDot />
|
|
181
|
-
<ActionLink
|
|
182
|
-
variant="destructive"
|
|
183
|
-
onClick={() => deleteComment(comment.id)}
|
|
184
|
-
>
|
|
185
|
-
{t("marginNote.delete")}
|
|
186
|
-
</ActionLink>
|
|
187
|
-
<SeparatorDot />
|
|
188
|
-
<ActionLink
|
|
189
|
-
onClick={handleCopy}
|
|
190
|
-
title={t("marginNote.copyTitle")}
|
|
191
|
-
>
|
|
192
|
-
{t("marginNote.copy")}
|
|
193
|
-
</ActionLink>
|
|
194
|
-
<SeparatorDot />
|
|
195
|
-
<ActionLink
|
|
196
|
-
onClick={() => copyCommentForLLM(comment)}
|
|
197
|
-
title={t("marginNote.llmTitle")}
|
|
198
|
-
>
|
|
199
|
-
{t("marginNote.llm")}
|
|
200
|
-
</ActionLink>
|
|
201
|
-
</ActionBar>
|
|
202
|
-
</>
|
|
203
|
-
)}
|
|
204
|
-
</div>
|
|
205
|
-
</article>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { resolveMarginNotePositions } from "../lib/margin-layout";
|
|
3
|
-
import type { Comment } from "../types";
|
|
4
|
-
import { MarginNote } from "./MarginNote";
|
|
5
|
-
|
|
6
|
-
interface MarginNotesProps {
|
|
7
|
-
/** Comments pre-sorted by startOffset */
|
|
8
|
-
sortedComments: Comment[];
|
|
9
|
-
highlightPositions: Record<string, number>;
|
|
10
|
-
pendingSelectionTop?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function MarginNotes({
|
|
14
|
-
sortedComments,
|
|
15
|
-
highlightPositions,
|
|
16
|
-
pendingSelectionTop,
|
|
17
|
-
}: MarginNotesProps) {
|
|
18
|
-
// Calculate resolved positions (avoiding overlaps with input and other notes)
|
|
19
|
-
const resolvedPositions = useMemo(
|
|
20
|
-
() =>
|
|
21
|
-
resolveMarginNotePositions(
|
|
22
|
-
sortedComments.map((c) => c.id),
|
|
23
|
-
highlightPositions,
|
|
24
|
-
pendingSelectionTop,
|
|
25
|
-
),
|
|
26
|
-
[sortedComments, highlightPositions, pendingSelectionTop],
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
if (sortedComments.length === 0) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div className="relative w-64">
|
|
35
|
-
{sortedComments.map((comment, index) => {
|
|
36
|
-
const top = resolvedPositions.get(comment.id);
|
|
37
|
-
if (top === undefined) return null;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<MarginNote
|
|
41
|
-
key={comment.id}
|
|
42
|
-
comment={comment}
|
|
43
|
-
top={top}
|
|
44
|
-
commentIndex={index}
|
|
45
|
-
/>
|
|
46
|
-
);
|
|
47
|
-
})}
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Copy } from "lucide-react";
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
3
|
-
import { toast } from "sonner";
|
|
4
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
5
|
-
import { useAppStore } from "../store";
|
|
6
|
-
import { Button } from "./ui/Button";
|
|
7
|
-
import {
|
|
8
|
-
Dialog,
|
|
9
|
-
DialogBody,
|
|
10
|
-
DialogContent,
|
|
11
|
-
DialogDescription,
|
|
12
|
-
DialogHeader,
|
|
13
|
-
DialogTitle,
|
|
14
|
-
} from "./ui/Dialog";
|
|
15
|
-
import { Text } from "./ui/Text";
|
|
16
|
-
|
|
17
|
-
interface RawModalProps {
|
|
18
|
-
isOpen: boolean;
|
|
19
|
-
onClose: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type ModalState =
|
|
23
|
-
| { status: "idle" }
|
|
24
|
-
| { status: "loading" }
|
|
25
|
-
| { status: "error"; error: string }
|
|
26
|
-
| { status: "empty"; path: string }
|
|
27
|
-
| { status: "success"; content: string; path: string };
|
|
28
|
-
|
|
29
|
-
export function RawModal({ isOpen, onClose }: RawModalProps) {
|
|
30
|
-
const { t } = useLocale();
|
|
31
|
-
const [state, setState] = useState<ModalState>({ status: "idle" });
|
|
32
|
-
const activeDocumentPath = useAppStore((s) => s.activeDocumentPath);
|
|
33
|
-
|
|
34
|
-
// Fetch raw comments when modal opens
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (!isOpen) {
|
|
37
|
-
setState({ status: "idle" });
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setState({ status: "loading" });
|
|
42
|
-
|
|
43
|
-
const fetchRawComments = async () => {
|
|
44
|
-
try {
|
|
45
|
-
const query = activeDocumentPath
|
|
46
|
-
? `?path=${encodeURIComponent(activeDocumentPath)}`
|
|
47
|
-
: "";
|
|
48
|
-
const response = await fetch(`/api/comments/raw${query}`);
|
|
49
|
-
if (!response.ok) {
|
|
50
|
-
throw new Error("Failed to fetch raw comments");
|
|
51
|
-
}
|
|
52
|
-
const result = await response.json();
|
|
53
|
-
if (result.content === null) {
|
|
54
|
-
setState({ status: "empty", path: result.path });
|
|
55
|
-
} else {
|
|
56
|
-
setState({
|
|
57
|
-
status: "success",
|
|
58
|
-
content: result.content,
|
|
59
|
-
path: result.path,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
setState({
|
|
64
|
-
status: "error",
|
|
65
|
-
error: err instanceof Error ? err.message : "Unknown error",
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
fetchRawComments();
|
|
71
|
-
}, [isOpen, activeDocumentPath]);
|
|
72
|
-
|
|
73
|
-
const handleCopy = useCallback(async () => {
|
|
74
|
-
if (state.status !== "success") return;
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
await navigator.clipboard.writeText(state.content);
|
|
78
|
-
toast.success(t("rawModal.copiedToClipboard"));
|
|
79
|
-
} catch {
|
|
80
|
-
toast.error(t("rawModal.failedToCopy"));
|
|
81
|
-
}
|
|
82
|
-
}, [state, t]);
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<Dialog
|
|
86
|
-
open={isOpen}
|
|
87
|
-
onOpenChange={(open) => {
|
|
88
|
-
if (!open) onClose();
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
91
|
-
<DialogContent className="max-w-2xl max-h-[80vh]">
|
|
92
|
-
<DialogHeader>
|
|
93
|
-
<DialogTitle>{t("rawModal.title")}</DialogTitle>
|
|
94
|
-
{state.status === "success" && (
|
|
95
|
-
<Button
|
|
96
|
-
variant="ghost"
|
|
97
|
-
size="icon"
|
|
98
|
-
className="size-7"
|
|
99
|
-
onClick={handleCopy}
|
|
100
|
-
title={t("rawModal.copyTitle")}
|
|
101
|
-
>
|
|
102
|
-
<Copy className="w-4 h-4" />
|
|
103
|
-
</Button>
|
|
104
|
-
)}
|
|
105
|
-
</DialogHeader>
|
|
106
|
-
|
|
107
|
-
{(state.status === "success" || state.status === "empty") && (
|
|
108
|
-
<DialogDescription className="px-4 py-2 border-b border-zinc-50 dark:border-zinc-800 text-xs text-zinc-400 dark:text-zinc-500 font-mono truncate">
|
|
109
|
-
{state.path}
|
|
110
|
-
</DialogDescription>
|
|
111
|
-
)}
|
|
112
|
-
|
|
113
|
-
<DialogBody>
|
|
114
|
-
{state.status === "loading" && (
|
|
115
|
-
<Text variant="caption" className="text-center py-8">
|
|
116
|
-
{t("rawModal.loading")}
|
|
117
|
-
</Text>
|
|
118
|
-
)}
|
|
119
|
-
|
|
120
|
-
{state.status === "error" && (
|
|
121
|
-
<Text variant="body" className="text-red-500 text-center py-8">
|
|
122
|
-
{state.error}
|
|
123
|
-
</Text>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
{state.status === "empty" && (
|
|
127
|
-
<Text variant="caption" className="text-center py-8">
|
|
128
|
-
{t("rawModal.noComments")}
|
|
129
|
-
</Text>
|
|
130
|
-
)}
|
|
131
|
-
|
|
132
|
-
{state.status === "success" && (
|
|
133
|
-
<Text variant="body" asChild>
|
|
134
|
-
<pre className="text-xs font-mono whitespace-pre-wrap break-words leading-relaxed">
|
|
135
|
-
{state.content}
|
|
136
|
-
</pre>
|
|
137
|
-
</Text>
|
|
138
|
-
)}
|
|
139
|
-
</DialogBody>
|
|
140
|
-
</DialogContent>
|
|
141
|
-
</Dialog>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
2
|
-
import { Button } from "./ui/Button";
|
|
3
|
-
import { Text } from "./ui/Text";
|
|
4
|
-
|
|
5
|
-
interface ReanchorConfirmProps {
|
|
6
|
-
selectionText: string;
|
|
7
|
-
onConfirm: () => void;
|
|
8
|
-
onCancel: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function ReanchorConfirm({
|
|
12
|
-
selectionText,
|
|
13
|
-
onConfirm,
|
|
14
|
-
onCancel,
|
|
15
|
-
}: ReanchorConfirmProps) {
|
|
16
|
-
const { t } = useLocale();
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div className="border-t border-zinc-200 dark:border-zinc-700 pt-2 pb-3 pl-6">
|
|
20
|
-
<Text variant="body" className="mb-2">
|
|
21
|
-
{t("reanchor.question")}
|
|
22
|
-
</Text>
|
|
23
|
-
<Text variant="caption" asChild>
|
|
24
|
-
<p className="italic line-clamp-2 mb-2">"{selectionText}"</p>
|
|
25
|
-
</Text>
|
|
26
|
-
<div className="flex gap-3 text-sm">
|
|
27
|
-
<Button variant="link" size="sm" onClick={onConfirm}>
|
|
28
|
-
{t("reanchor.confirm")}
|
|
29
|
-
</Button>
|
|
30
|
-
<Button variant="ghost" size="sm" onClick={onCancel}>
|
|
31
|
-
{t("reanchor.cancel")}
|
|
32
|
-
</Button>
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
}
|