@peaske7/readit 0.1.8 → 0.2.0
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 +0 -3
- package/biome.json +1 -1
- package/bun.lock +43 -185
- package/docs/perf-baseline.md +75 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/e2e/perf/add-comment.spec.ts +118 -0
- package/e2e/perf/fixtures/generate.ts +331 -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/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 +286 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/package.json +9 -18
- package/playwright.config.ts +12 -0
- package/src/App.tsx +124 -172
- package/src/{cli/index.ts → cli.ts} +37 -53
- package/src/components/ActionsMenu.tsx +6 -27
- package/src/components/DocumentViewer/DocumentViewer.tsx +77 -106
- package/src/components/DocumentViewer/MermaidDiagram.tsx +6 -7
- package/src/components/Header.tsx +9 -20
- package/src/components/InlineEditor.tsx +5 -5
- package/src/components/MarginNote.tsx +71 -93
- package/src/components/MarginNotes.tsx +7 -34
- package/src/components/RawModal.tsx +9 -8
- package/src/components/ReanchorConfirm.tsx +2 -2
- package/src/components/SettingsModal.tsx +11 -89
- package/src/components/TabBar.tsx +4 -4
- package/src/components/TableOfContents.tsx +5 -5
- package/src/components/comments/CommentInput.tsx +7 -35
- package/src/components/comments/CommentListItem.tsx +9 -11
- package/src/components/comments/CommentManager.tsx +53 -37
- package/src/components/comments/CommentNav.tsx +14 -14
- package/src/components/ui/ActionLink.tsx +14 -18
- package/src/components/ui/Button.tsx +42 -43
- package/src/components/ui/Dialog.tsx +73 -113
- package/src/components/ui/DropdownMenu.tsx +113 -69
- package/src/components/ui/Text.tsx +30 -37
- package/src/contexts/CommentContext.tsx +75 -106
- package/src/contexts/LocaleContext.tsx +45 -4
- package/src/contexts/PositionsContext.tsx +16 -0
- package/src/contexts/SettingsContext.tsx +133 -0
- package/src/hooks/useClickOutside.ts +0 -4
- package/src/hooks/useCommentNavigation.ts +6 -29
- package/src/hooks/useComments.ts +6 -18
- package/src/hooks/useDocument.ts +35 -34
- package/src/hooks/useHeadings.test.ts +8 -50
- package/src/hooks/useHeadings.ts +5 -88
- package/src/hooks/useScrollSpy.ts +10 -14
- package/src/hooks/useTextSelection.ts +1 -38
- package/src/lib/__fixtures__/bench-data.ts +1 -41
- package/src/lib/anchor.bench.ts +57 -67
- package/src/lib/anchor.test.ts +5 -1
- package/src/lib/anchor.ts +13 -93
- package/src/lib/comment-storage.test.ts +4 -4
- package/src/lib/comment-storage.ts +2 -46
- package/src/lib/export.ts +7 -13
- package/src/lib/highlight/core.test.ts +1 -1
- package/src/lib/highlight/dom.ts +5 -68
- package/src/lib/highlight/highlighter.ts +102 -262
- package/src/lib/highlight/resolver.ts +112 -0
- package/src/lib/highlight/types.ts +0 -35
- package/src/lib/highlight/worker.ts +45 -0
- package/src/lib/i18n/en.ts +1 -50
- package/src/lib/i18n/ja.ts +1 -50
- package/src/lib/i18n/types.ts +1 -49
- package/src/lib/margin-layout.ts +5 -27
- package/src/lib/positions.ts +150 -0
- package/src/lib/utils.ts +2 -19
- package/src/schema.ts +81 -0
- package/src/{server/index.ts → server.ts} +74 -74
- package/src/{store/index.ts → store.ts} +14 -46
- package/vite.config.ts +8 -0
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- 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/useThemePreference.ts +0 -66
- package/src/lib/comment-storage.bench.ts +0 -63
- 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/export.bench.ts +0 -35
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/core.ts +0 -54
- 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/margin-layout.bench.ts +0 -28
- 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/shortcut-registry.ts +0 -209
- package/src/lib/utils.test.ts +0 -110
- package/src/store/index.test.ts +0 -242
- package/src/types/index.ts +0 -127
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { createStore, useStore } from "zustand";
|
|
2
|
-
import type { Comment, Document, Selection } from "
|
|
3
|
-
|
|
4
|
-
// ─── Types ───────────────────────────────────────────────────────────
|
|
2
|
+
import type { Comment, Document, Selection } from "./schema";
|
|
5
3
|
|
|
6
4
|
export interface DocumentState {
|
|
7
5
|
document: Document;
|
|
@@ -11,41 +9,27 @@ export interface DocumentState {
|
|
|
11
9
|
selection: Selection | null;
|
|
12
10
|
pendingSelectionTop: number | undefined;
|
|
13
11
|
pendingCommentText: string;
|
|
14
|
-
highlightPositions: Record<string, number>;
|
|
15
|
-
documentPositions: Record<string, number>;
|
|
16
12
|
scrollY: number;
|
|
17
|
-
hoveredCommentId: string | undefined;
|
|
18
13
|
reanchorTarget: { commentId: string } | null;
|
|
19
14
|
}
|
|
20
15
|
|
|
21
16
|
export interface AppStore {
|
|
22
|
-
// Multi-document state
|
|
23
17
|
documents: Map<string, DocumentState>;
|
|
24
18
|
activeDocumentPath: string | null;
|
|
25
19
|
documentOrder: string[];
|
|
26
20
|
workingDirectory: string | null;
|
|
27
21
|
|
|
28
|
-
// Global actions
|
|
29
22
|
setWorkingDirectory: (dir: string) => void;
|
|
30
23
|
openDocument: (doc: Document, opts?: { active?: boolean }) => void;
|
|
31
24
|
closeDocument: (filePath: string) => void;
|
|
32
25
|
setActiveDocument: (filePath: string) => void;
|
|
33
26
|
|
|
34
|
-
//
|
|
27
|
+
// Setters default to active doc when filePath omitted
|
|
35
28
|
setComments: (comments: Comment[], filePath?: string) => void;
|
|
36
29
|
setCommentsError: (error: string | null, filePath?: string) => void;
|
|
37
30
|
setSelection: (selection: Selection | null, filePath?: string) => void;
|
|
38
31
|
setPendingSelectionTop: (top: number | undefined, filePath?: string) => void;
|
|
39
|
-
setHighlightPositions: (
|
|
40
|
-
positions: Record<string, number>,
|
|
41
|
-
filePath?: string,
|
|
42
|
-
) => void;
|
|
43
|
-
setDocumentPositions: (
|
|
44
|
-
positions: Record<string, number>,
|
|
45
|
-
filePath?: string,
|
|
46
|
-
) => void;
|
|
47
32
|
setScrollY: (y: number, filePath?: string) => void;
|
|
48
|
-
setHoveredCommentId: (id: string | undefined, filePath?: string) => void;
|
|
49
33
|
setReanchorTarget: (
|
|
50
34
|
target: { commentId: string } | null,
|
|
51
35
|
filePath?: string,
|
|
@@ -53,12 +37,9 @@ export interface AppStore {
|
|
|
53
37
|
setPendingCommentText: (text: string, filePath?: string) => void;
|
|
54
38
|
updateDocumentContent: (content: string, filePath?: string) => void;
|
|
55
39
|
|
|
56
|
-
// Helpers
|
|
57
40
|
getActiveDocumentState: () => DocumentState | undefined;
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
43
|
function createInitialDocumentState(doc: Document): DocumentState {
|
|
63
44
|
return {
|
|
64
45
|
document: doc,
|
|
@@ -68,10 +49,7 @@ function createInitialDocumentState(doc: Document): DocumentState {
|
|
|
68
49
|
selection: null,
|
|
69
50
|
pendingSelectionTop: undefined,
|
|
70
51
|
pendingCommentText: "",
|
|
71
|
-
highlightPositions: {},
|
|
72
|
-
documentPositions: {},
|
|
73
52
|
scrollY: 0,
|
|
74
|
-
hoveredCommentId: undefined,
|
|
75
53
|
reanchorTarget: null,
|
|
76
54
|
};
|
|
77
55
|
}
|
|
@@ -80,8 +58,6 @@ function sortComments(comments: Comment[]): Comment[] {
|
|
|
80
58
|
return [...comments].sort((a, b) => a.startOffset - b.startOffset);
|
|
81
59
|
}
|
|
82
60
|
|
|
83
|
-
// ─── Store Factory ───────────────────────────────────────────────────
|
|
84
|
-
|
|
85
61
|
export function createAppStore() {
|
|
86
62
|
return createStore<AppStore>((set, get) => {
|
|
87
63
|
const resolveFilePath = (filePath?: string): string | null =>
|
|
@@ -192,30 +168,12 @@ export function createAppStore() {
|
|
|
192
168
|
updateDocState(path, () => ({ pendingSelectionTop: top }));
|
|
193
169
|
},
|
|
194
170
|
|
|
195
|
-
setHighlightPositions: (positions, filePath?) => {
|
|
196
|
-
const path = resolveFilePath(filePath);
|
|
197
|
-
if (!path) return;
|
|
198
|
-
updateDocState(path, () => ({ highlightPositions: positions }));
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
setDocumentPositions: (positions, filePath?) => {
|
|
202
|
-
const path = resolveFilePath(filePath);
|
|
203
|
-
if (!path) return;
|
|
204
|
-
updateDocState(path, () => ({ documentPositions: positions }));
|
|
205
|
-
},
|
|
206
|
-
|
|
207
171
|
setScrollY: (y, filePath?) => {
|
|
208
172
|
const path = resolveFilePath(filePath);
|
|
209
173
|
if (!path) return;
|
|
210
174
|
updateDocState(path, () => ({ scrollY: y }));
|
|
211
175
|
},
|
|
212
176
|
|
|
213
|
-
setHoveredCommentId: (id, filePath?) => {
|
|
214
|
-
const path = resolveFilePath(filePath);
|
|
215
|
-
if (!path) return;
|
|
216
|
-
updateDocState(path, () => ({ hoveredCommentId: id }));
|
|
217
|
-
},
|
|
218
|
-
|
|
219
177
|
setReanchorTarget: (target, filePath?) => {
|
|
220
178
|
const path = resolveFilePath(filePath);
|
|
221
179
|
if (!path) return;
|
|
@@ -245,10 +203,20 @@ export function createAppStore() {
|
|
|
245
203
|
});
|
|
246
204
|
}
|
|
247
205
|
|
|
248
|
-
// ─── Singleton + React Hook ─────────────────────────────────────────
|
|
249
|
-
|
|
250
206
|
export const appStore = createAppStore();
|
|
251
207
|
|
|
252
208
|
export function useAppStore<T>(selector: (state: AppStore) => T): T {
|
|
253
209
|
return useStore(appStore, selector);
|
|
254
210
|
}
|
|
211
|
+
|
|
212
|
+
interface UIState {
|
|
213
|
+
hoveredCommentId: string | undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export const uiStore = createStore<UIState>(() => ({
|
|
217
|
+
hoveredCommentId: undefined,
|
|
218
|
+
}));
|
|
219
|
+
|
|
220
|
+
export function useUI<T>(selector: (s: UIState) => T): T {
|
|
221
|
+
return useStore(uiStore, selector);
|
|
222
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -5,6 +5,14 @@ import { defineConfig } from "vite";
|
|
|
5
5
|
export default defineConfig({
|
|
6
6
|
plugins: [tailwindcss(), react()],
|
|
7
7
|
server: {
|
|
8
|
+
port: 24678,
|
|
9
|
+
strictPort: true,
|
|
10
|
+
host: "127.0.0.1",
|
|
11
|
+
hmr: {
|
|
12
|
+
host: "127.0.0.1",
|
|
13
|
+
port: 24678,
|
|
14
|
+
clientPort: 24678,
|
|
15
|
+
},
|
|
8
16
|
proxy: {
|
|
9
17
|
"/api": {
|
|
10
18
|
target: "http://localhost:4567",
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import DOMPurify from "dompurify";
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
buildIframeScript,
|
|
5
|
-
createHighlighter,
|
|
6
|
-
type HighlightComment,
|
|
7
|
-
type Highlighter,
|
|
8
|
-
} from "../../lib/highlight";
|
|
9
|
-
import {
|
|
10
|
-
AnchorConfidences,
|
|
11
|
-
type Comment,
|
|
12
|
-
FontFamilies,
|
|
13
|
-
type FontFamily,
|
|
14
|
-
type SelectionRange,
|
|
15
|
-
} from "../../types";
|
|
16
|
-
|
|
17
|
-
interface IframeContainerProps {
|
|
18
|
-
html: string;
|
|
19
|
-
comments: Comment[];
|
|
20
|
-
pendingSelection?: SelectionRange;
|
|
21
|
-
onTextSelect: (
|
|
22
|
-
text: string,
|
|
23
|
-
startOffset: number,
|
|
24
|
-
endOffset: number,
|
|
25
|
-
selectionTop: number,
|
|
26
|
-
) => void;
|
|
27
|
-
onHighlightPositionsChange?: (
|
|
28
|
-
positions: Record<string, number>,
|
|
29
|
-
documentPositions: Record<string, number>,
|
|
30
|
-
pendingTop?: number,
|
|
31
|
-
) => void;
|
|
32
|
-
onHighlightHover?: (commentId: string | undefined) => void;
|
|
33
|
-
onHighlightClick?: (commentId: string) => void;
|
|
34
|
-
fontFamily?: FontFamily;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const FONT_SERIF =
|
|
38
|
-
'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif';
|
|
39
|
-
const FONT_SANS =
|
|
40
|
-
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
|
|
41
|
-
|
|
42
|
-
function getFontStack(fontFamily: FontFamily): string {
|
|
43
|
-
return fontFamily === FontFamilies.SANS_SERIF ? FONT_SANS : FONT_SERIF;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Layout styles use !important; prose styles use :where() for zero specificity
|
|
47
|
-
function getBaseStyles(fontFamily: FontFamily): string {
|
|
48
|
-
const fontStack = getFontStack(fontFamily);
|
|
49
|
-
return `
|
|
50
|
-
/* Critical layout - must override external CSS to ensure proper sizing */
|
|
51
|
-
html {
|
|
52
|
-
width: 100% !important;
|
|
53
|
-
}
|
|
54
|
-
body {
|
|
55
|
-
width: 100% !important;
|
|
56
|
-
min-width: 65ch;
|
|
57
|
-
box-sizing: border-box !important;
|
|
58
|
-
margin: 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/* Prose styles as fallback - zero specificity via :where(), easily overridden */
|
|
62
|
-
:where(body:not([class])) {
|
|
63
|
-
max-width: 65ch;
|
|
64
|
-
margin-left: auto;
|
|
65
|
-
margin-right: auto;
|
|
66
|
-
padding: 2rem 1rem;
|
|
67
|
-
line-height: 1.75;
|
|
68
|
-
color: #3f3f46;
|
|
69
|
-
font-family: ${fontStack};
|
|
70
|
-
}
|
|
71
|
-
:where(body:not([class])) :where(h1, h2, h3, h4, h5, h6) {
|
|
72
|
-
color: #18181b;
|
|
73
|
-
font-weight: 600;
|
|
74
|
-
line-height: 1.25;
|
|
75
|
-
margin-top: 2em;
|
|
76
|
-
margin-bottom: 0.5em;
|
|
77
|
-
}
|
|
78
|
-
:where(body:not([class])) :where(h1) { font-size: 2.25em; margin-top: 0; }
|
|
79
|
-
:where(body:not([class])) :where(h2) { font-size: 1.5em; }
|
|
80
|
-
:where(body:not([class])) :where(h3) { font-size: 1.25em; }
|
|
81
|
-
:where(body:not([class])) :where(h4) { font-size: 1.125em; }
|
|
82
|
-
:where(body:not([class])) :where(p) { margin: 1em 0; }
|
|
83
|
-
:where(body:not([class])) :where(ul, ol) { padding-left: 1.5em; margin: 1em 0; }
|
|
84
|
-
:where(body:not([class])) :where(li) { margin: 0.5em 0; }
|
|
85
|
-
:where(body:not([class])) :where(a) { color: #2563eb; text-decoration: underline; }
|
|
86
|
-
:where(body:not([class])) :where(code) { background: #f4f4f5; padding: 0.2em 0.4em; border-radius: 0.25em; font-size: 0.875em; }
|
|
87
|
-
:where(body:not([class])) :where(pre) { background: #f4f4f5; padding: 1em; border-radius: 0.5em; overflow-x: auto; }
|
|
88
|
-
:where(body:not([class])) :where(pre code) { background: none; padding: 0; }
|
|
89
|
-
:where(body:not([class])) :where(blockquote) { border-left: 4px solid #e4e4e7; padding-left: 1em; color: #71717a; margin: 1em 0; font-style: italic; }
|
|
90
|
-
:where(body:not([class])) :where(hr) { border: none; border-top: 1px solid #e4e4e7; margin: 2em 0; }
|
|
91
|
-
:where(body:not([class])) :where(table) { border-collapse: collapse; width: 100%; margin: 1em 0; }
|
|
92
|
-
:where(body:not([class])) :where(th, td) { border: 1px solid #e4e4e7; padding: 0.5em 1em; text-align: left; }
|
|
93
|
-
:where(body:not([class])) :where(th) { background: #fafafa; font-weight: 600; }
|
|
94
|
-
:where(body:not([class])) :where(img) { max-width: 100%; height: auto; }
|
|
95
|
-
|
|
96
|
-
/* Highlight styles - warm ink palette */
|
|
97
|
-
mark[data-comment-id] {
|
|
98
|
-
background: rgba(245, 222, 160, 0.5);
|
|
99
|
-
cursor: pointer;
|
|
100
|
-
transition: background-color 0.15s ease;
|
|
101
|
-
}
|
|
102
|
-
mark[data-comment-id]:hover {
|
|
103
|
-
background-color: rgba(228, 195, 110, 0.65);
|
|
104
|
-
}
|
|
105
|
-
mark[data-comment-id]:active {
|
|
106
|
-
background-color: rgba(228, 195, 110, 0.75);
|
|
107
|
-
}
|
|
108
|
-
mark[data-pending] { background: rgba(180, 180, 180, 0.3); cursor: text; }
|
|
109
|
-
`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function sanitizeHtml(html: string): string {
|
|
113
|
-
const sanitized = DOMPurify.sanitize(html, {
|
|
114
|
-
ADD_TAGS: ["style"],
|
|
115
|
-
ADD_ATTR: ["style"],
|
|
116
|
-
FORBID_TAGS: ["script", "iframe", "object", "embed", "form"],
|
|
117
|
-
FORBID_ATTR: ["onerror", "onload", "onclick", "onmouseover"],
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Escape </iframe> to prevent breaking out of srcdoc
|
|
121
|
-
return sanitized.replace(/<\/iframe/gi, "</iframe");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function injectStyleTag(html: string, styleTag: string): string {
|
|
125
|
-
if (/<\/head>/i.test(html)) {
|
|
126
|
-
return html.replace(/<\/head>/i, `${styleTag}</head>`);
|
|
127
|
-
}
|
|
128
|
-
if (/<head[^>]*>/i.test(html)) {
|
|
129
|
-
return html.replace(/(<head[^>]*>)/i, `$1${styleTag}`);
|
|
130
|
-
}
|
|
131
|
-
return styleTag + html;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function IframeContainer({
|
|
135
|
-
html,
|
|
136
|
-
comments,
|
|
137
|
-
pendingSelection,
|
|
138
|
-
onTextSelect,
|
|
139
|
-
onHighlightPositionsChange,
|
|
140
|
-
onHighlightHover,
|
|
141
|
-
onHighlightClick,
|
|
142
|
-
fontFamily = FontFamilies.SERIF,
|
|
143
|
-
}: IframeContainerProps) {
|
|
144
|
-
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
145
|
-
const adapterRef = useRef<Highlighter | null>(null);
|
|
146
|
-
const [contentHeight, setContentHeight] = useState<number>(0);
|
|
147
|
-
|
|
148
|
-
const srcdoc = useMemo(() => {
|
|
149
|
-
const sanitized = sanitizeHtml(html);
|
|
150
|
-
const baseStyles = getBaseStyles(fontFamily);
|
|
151
|
-
const styleTag = `<style id="readit-base-styles">${baseStyles}</style>`;
|
|
152
|
-
|
|
153
|
-
const finalHtml = injectStyleTag(sanitized, styleTag);
|
|
154
|
-
|
|
155
|
-
return finalHtml + buildIframeScript(window.location.origin);
|
|
156
|
-
}, [html, fontFamily]);
|
|
157
|
-
|
|
158
|
-
useEffect(() => {
|
|
159
|
-
const adapter = createHighlighter({
|
|
160
|
-
type: "iframe",
|
|
161
|
-
getIframe: () => iframeRef.current,
|
|
162
|
-
onSelect: onTextSelect,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
adapterRef.current = adapter;
|
|
166
|
-
|
|
167
|
-
const unsubPositions = onHighlightPositionsChange
|
|
168
|
-
? adapter.onPositionsChange((pos) => {
|
|
169
|
-
const iframe = iframeRef.current;
|
|
170
|
-
const iframeOffset = iframe
|
|
171
|
-
? iframe.getBoundingClientRect().top + window.scrollY
|
|
172
|
-
: 0;
|
|
173
|
-
|
|
174
|
-
const adjustedDocPositions: Record<string, number> = {};
|
|
175
|
-
for (const [id, iframePos] of Object.entries(pos.documentPositions)) {
|
|
176
|
-
adjustedDocPositions[id] = iframePos + iframeOffset;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
onHighlightPositionsChange(
|
|
180
|
-
pos.positions,
|
|
181
|
-
adjustedDocPositions,
|
|
182
|
-
pos.pendingTop,
|
|
183
|
-
);
|
|
184
|
-
})
|
|
185
|
-
: () => {};
|
|
186
|
-
|
|
187
|
-
const unsubHover = onHighlightHover
|
|
188
|
-
? adapter.onHighlightHover(onHighlightHover)
|
|
189
|
-
: () => {};
|
|
190
|
-
|
|
191
|
-
const unsubClick = onHighlightClick
|
|
192
|
-
? adapter.onHighlightClick(onHighlightClick)
|
|
193
|
-
: () => {};
|
|
194
|
-
|
|
195
|
-
const unsubHeight = adapter.onContentHeightChange?.((height) => {
|
|
196
|
-
setContentHeight(height);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return () => {
|
|
200
|
-
unsubPositions();
|
|
201
|
-
unsubHover();
|
|
202
|
-
unsubClick();
|
|
203
|
-
unsubHeight?.();
|
|
204
|
-
adapter.dispose();
|
|
205
|
-
adapterRef.current = null;
|
|
206
|
-
};
|
|
207
|
-
}, [
|
|
208
|
-
onTextSelect,
|
|
209
|
-
onHighlightPositionsChange,
|
|
210
|
-
onHighlightHover,
|
|
211
|
-
onHighlightClick,
|
|
212
|
-
]);
|
|
213
|
-
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
const adapter = adapterRef.current;
|
|
216
|
-
if (!adapter) return;
|
|
217
|
-
|
|
218
|
-
const highlightComments: HighlightComment[] = comments
|
|
219
|
-
.filter((c) => c.anchorConfidence !== AnchorConfidences.UNRESOLVED)
|
|
220
|
-
.map((c) => ({
|
|
221
|
-
id: c.id,
|
|
222
|
-
selectedText: c.selectedText,
|
|
223
|
-
startOffset: c.startOffset,
|
|
224
|
-
endOffset: c.endOffset,
|
|
225
|
-
}));
|
|
226
|
-
|
|
227
|
-
adapter.applyHighlights(highlightComments, pendingSelection ?? undefined);
|
|
228
|
-
}, [comments, pendingSelection]);
|
|
229
|
-
|
|
230
|
-
useEffect(() => {
|
|
231
|
-
const handleTestSelect = (e: Event) => {
|
|
232
|
-
const { text, startOffset, endOffset } = (e as CustomEvent).detail;
|
|
233
|
-
onTextSelect(text, startOffset, endOffset, 0);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
window.addEventListener("test:select-text", handleTestSelect);
|
|
237
|
-
return () =>
|
|
238
|
-
window.removeEventListener("test:select-text", handleTestSelect);
|
|
239
|
-
}, [onTextSelect]);
|
|
240
|
-
|
|
241
|
-
return (
|
|
242
|
-
<iframe
|
|
243
|
-
ref={iframeRef}
|
|
244
|
-
srcDoc={srcdoc}
|
|
245
|
-
sandbox="allow-scripts allow-same-origin"
|
|
246
|
-
title="Document content"
|
|
247
|
-
className="w-full border-0"
|
|
248
|
-
style={{ height: contentHeight || "100%" }}
|
|
249
|
-
/>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
-
import {
|
|
3
|
-
buildEditorUri,
|
|
4
|
-
parseFilePath,
|
|
5
|
-
resolveAbsolutePath,
|
|
6
|
-
} from "../../lib/editor-links";
|
|
7
|
-
import type { EditorScheme } from "../../types";
|
|
8
|
-
import { EditorSchemes } from "../../types";
|
|
9
|
-
import { CodeBlock } from "./CodeBlock";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a combined code component for react-markdown that:
|
|
13
|
-
* - Routes fenced code blocks to CodeBlock (syntax highlighting)
|
|
14
|
-
* - Wraps inline code containing file paths with editor links
|
|
15
|
-
* - Falls back to plain <code> for non-file-path inline code
|
|
16
|
-
*/
|
|
17
|
-
export function createCodeComponent(
|
|
18
|
-
editorScheme: EditorScheme,
|
|
19
|
-
workingDirectory: string | null,
|
|
20
|
-
) {
|
|
21
|
-
return function CodeComponent({
|
|
22
|
-
children,
|
|
23
|
-
className,
|
|
24
|
-
...props
|
|
25
|
-
}: ComponentPropsWithoutRef<"code">) {
|
|
26
|
-
// Fenced code blocks have className (e.g., "language-ts") or contain newlines
|
|
27
|
-
if (className || String(children).includes("\n")) {
|
|
28
|
-
return <CodeBlock className={className}>{children}</CodeBlock>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Inline code — check for file path patterns
|
|
32
|
-
if (editorScheme === EditorSchemes.NONE || !workingDirectory) {
|
|
33
|
-
return <code {...props}>{children}</code>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const text = typeof children === "string" ? children : "";
|
|
37
|
-
if (!text) {
|
|
38
|
-
return <code {...props}>{children}</code>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const match = parseFilePath(text);
|
|
42
|
-
if (!match) {
|
|
43
|
-
return <code {...props}>{children}</code>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const absolutePath = resolveAbsolutePath(match.path, workingDirectory);
|
|
47
|
-
const uri = buildEditorUri(
|
|
48
|
-
editorScheme,
|
|
49
|
-
absolutePath,
|
|
50
|
-
match.line,
|
|
51
|
-
match.col,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<a href={uri} title={`Open in ${editorScheme}`} className="editor-link">
|
|
56
|
-
<code {...props}>{children}</code>
|
|
57
|
-
</a>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DocumentViewer } from "./DocumentViewer";
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { List } from "lucide-react";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
4
|
-
import type { Heading } from "../hooks/useHeadings";
|
|
5
|
-
import { cn } from "../lib/utils";
|
|
6
|
-
import { TableOfContents } from "./TableOfContents";
|
|
7
|
-
|
|
8
|
-
interface FloatingTOCProps {
|
|
9
|
-
headings: Heading[];
|
|
10
|
-
activeId: string | null;
|
|
11
|
-
onHeadingClick: (id: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function FloatingTOC({
|
|
15
|
-
headings,
|
|
16
|
-
activeId,
|
|
17
|
-
onHeadingClick,
|
|
18
|
-
}: FloatingTOCProps) {
|
|
19
|
-
const { t } = useLocale();
|
|
20
|
-
const [isExpanded, setIsExpanded] = useState(false);
|
|
21
|
-
|
|
22
|
-
if (headings.length === 0) return null;
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<nav
|
|
26
|
-
className="fixed left-4 top-16 z-40"
|
|
27
|
-
onMouseEnter={() => setIsExpanded(true)}
|
|
28
|
-
onMouseLeave={() => setIsExpanded(false)}
|
|
29
|
-
aria-label={t("floatingTOC.label")}
|
|
30
|
-
>
|
|
31
|
-
{/* Collapsed state: circular button */}
|
|
32
|
-
<button
|
|
33
|
-
type="button"
|
|
34
|
-
onClick={() => setIsExpanded(!isExpanded)}
|
|
35
|
-
className={cn(
|
|
36
|
-
"w-10 h-10 rounded-full bg-white dark:bg-zinc-900 shadow-lg border border-zinc-100 dark:border-zinc-800 flex items-center justify-center text-zinc-400 dark:text-zinc-500 hover:text-zinc-600 dark:hover:text-zinc-300 transition-colors duration-150",
|
|
37
|
-
isExpanded && "opacity-0 pointer-events-none",
|
|
38
|
-
)}
|
|
39
|
-
aria-label={t("floatingTOC.label")}
|
|
40
|
-
>
|
|
41
|
-
<List className="w-5 h-5" />
|
|
42
|
-
</button>
|
|
43
|
-
|
|
44
|
-
{/* Expanded state: panel */}
|
|
45
|
-
{isExpanded && (
|
|
46
|
-
<div className="absolute left-0 top-0 w-56 bg-white/95 dark:bg-zinc-900/95 backdrop-blur-sm rounded-lg shadow-lg border border-zinc-200/40 dark:border-zinc-700/40 p-4 floating-toc-panel">
|
|
47
|
-
<div className="max-h-[calc(100vh-8rem)] overflow-y-auto">
|
|
48
|
-
<TableOfContents
|
|
49
|
-
headings={headings}
|
|
50
|
-
activeId={activeId}
|
|
51
|
-
onHeadingClick={(id) => {
|
|
52
|
-
onHeadingClick(id);
|
|
53
|
-
setIsExpanded(false);
|
|
54
|
-
}}
|
|
55
|
-
/>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
)}
|
|
59
|
-
</nav>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect } from "react";
|
|
2
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
3
|
-
import {
|
|
4
|
-
eventToBinding,
|
|
5
|
-
isReservedBinding,
|
|
6
|
-
type ShortcutBinding,
|
|
7
|
-
} from "../lib/shortcut-registry";
|
|
8
|
-
|
|
9
|
-
interface ShortcutCaptureProps {
|
|
10
|
-
onCapture: (binding: ShortcutBinding) => void;
|
|
11
|
-
onCancel: () => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function ShortcutCapture({ onCapture, onCancel }: ShortcutCaptureProps) {
|
|
15
|
-
const { t } = useLocale();
|
|
16
|
-
|
|
17
|
-
const handleKeyDown = useCallback(
|
|
18
|
-
(e: KeyboardEvent) => {
|
|
19
|
-
e.preventDefault();
|
|
20
|
-
e.stopPropagation();
|
|
21
|
-
|
|
22
|
-
if (e.key === "Escape") {
|
|
23
|
-
onCancel();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const binding = eventToBinding(e);
|
|
28
|
-
if (!binding) return;
|
|
29
|
-
|
|
30
|
-
if (isReservedBinding(binding)) return;
|
|
31
|
-
|
|
32
|
-
onCapture(binding);
|
|
33
|
-
},
|
|
34
|
-
[onCapture, onCancel],
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
window.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
39
|
-
return () =>
|
|
40
|
-
window.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
41
|
-
}, [handleKeyDown]);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded bg-amber-50 border border-amber-200 text-amber-700 text-xs font-medium animate-pulse">
|
|
45
|
-
{t("shortcutCapture.pressKeys")}
|
|
46
|
-
</span>
|
|
47
|
-
);
|
|
48
|
-
}
|