@peaske7/readit 0.1.7 → 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.
Files changed (118) hide show
  1. package/README.md +0 -3
  2. package/biome.json +1 -1
  3. package/bun.lock +43 -185
  4. package/docs/perf-baseline.md +75 -0
  5. package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
  6. package/e2e/perf/add-comment.spec.ts +118 -0
  7. package/e2e/perf/fixtures/generate.ts +331 -0
  8. package/e2e/perf/initial-load.spec.ts +49 -0
  9. package/e2e/perf/perf.setup.ts +23 -0
  10. package/e2e/perf/perf.teardown.ts +9 -0
  11. package/e2e/perf/scroll.spec.ts +39 -0
  12. package/e2e/perf/tab-switch.spec.ts +69 -0
  13. package/e2e/perf/text-selection.spec.ts +119 -0
  14. package/e2e/perf/utils/metrics.ts +286 -0
  15. package/e2e/perf/utils/perf-cli.ts +86 -0
  16. package/package.json +9 -18
  17. package/playwright.config.ts +12 -0
  18. package/src/App.tsx +133 -178
  19. package/src/{cli/index.ts → cli.ts} +211 -107
  20. package/src/components/ActionsMenu.tsx +6 -27
  21. package/src/components/DocumentViewer/DocumentViewer.tsx +78 -105
  22. package/src/components/DocumentViewer/MermaidDiagram.tsx +6 -7
  23. package/src/components/Header.tsx +9 -20
  24. package/src/components/InlineEditor.tsx +5 -5
  25. package/src/components/MarginNote.tsx +71 -93
  26. package/src/components/MarginNotes.tsx +7 -34
  27. package/src/components/RawModal.tsx +9 -8
  28. package/src/components/ReanchorConfirm.tsx +2 -2
  29. package/src/components/SettingsModal.tsx +11 -89
  30. package/src/components/TabBar.tsx +4 -4
  31. package/src/components/TableOfContents.tsx +5 -5
  32. package/src/components/comments/CommentInput.tsx +7 -35
  33. package/src/components/comments/CommentListItem.tsx +9 -11
  34. package/src/components/comments/CommentManager.tsx +53 -37
  35. package/src/components/comments/CommentNav.tsx +14 -14
  36. package/src/components/ui/ActionLink.tsx +14 -18
  37. package/src/components/ui/Button.tsx +42 -43
  38. package/src/components/ui/Dialog.tsx +73 -113
  39. package/src/components/ui/DropdownMenu.tsx +113 -69
  40. package/src/components/ui/Text.tsx +30 -37
  41. package/src/contexts/CommentContext.tsx +75 -106
  42. package/src/contexts/LocaleContext.tsx +45 -4
  43. package/src/contexts/PositionsContext.tsx +16 -0
  44. package/src/contexts/SettingsContext.tsx +133 -0
  45. package/src/hooks/useClickOutside.ts +0 -4
  46. package/src/hooks/useCommentNavigation.ts +6 -29
  47. package/src/hooks/useComments.ts +6 -18
  48. package/src/hooks/useDocument.ts +35 -34
  49. package/src/hooks/useHeadings.test.ts +8 -50
  50. package/src/hooks/useHeadings.ts +5 -88
  51. package/src/hooks/useScrollSpy.ts +10 -14
  52. package/src/hooks/useTextSelection.ts +1 -38
  53. package/src/lib/__fixtures__/bench-data.ts +1 -41
  54. package/src/lib/anchor.bench.ts +57 -67
  55. package/src/lib/anchor.test.ts +5 -1
  56. package/src/lib/anchor.ts +13 -93
  57. package/src/lib/comment-storage.test.ts +4 -4
  58. package/src/lib/comment-storage.ts +2 -46
  59. package/src/lib/export.ts +7 -13
  60. package/src/lib/highlight/core.test.ts +1 -1
  61. package/src/lib/highlight/dom.ts +5 -68
  62. package/src/lib/highlight/highlighter.ts +102 -262
  63. package/src/lib/highlight/resolver.ts +112 -0
  64. package/src/lib/highlight/types.ts +0 -35
  65. package/src/lib/highlight/worker.ts +45 -0
  66. package/src/lib/i18n/en.ts +1 -50
  67. package/src/lib/i18n/ja.ts +1 -50
  68. package/src/lib/i18n/types.ts +1 -49
  69. package/src/lib/margin-layout.ts +5 -27
  70. package/src/lib/positions.ts +150 -0
  71. package/src/lib/utils.ts +2 -19
  72. package/src/schema.ts +81 -0
  73. package/src/{server/index.ts → server.ts} +111 -81
  74. package/src/{store/index.ts → store.ts} +14 -46
  75. package/vite.config.ts +8 -0
  76. package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
  77. package/src/components/DocumentViewer/InlineCode.tsx +0 -60
  78. package/src/components/DocumentViewer/index.ts +0 -1
  79. package/src/components/FloatingTOC.tsx +0 -61
  80. package/src/components/ShortcutCapture.tsx +0 -48
  81. package/src/components/ShortcutList.tsx +0 -198
  82. package/src/components/comments/CommentMinimap.tsx +0 -62
  83. package/src/components/ui/ActionBar.tsx +0 -16
  84. package/src/components/ui/SeparatorDot.tsx +0 -9
  85. package/src/contexts/LayoutContext.tsx +0 -88
  86. package/src/hooks/useClipboard.ts +0 -82
  87. package/src/hooks/useEditorScheme.ts +0 -51
  88. package/src/hooks/useFontPreference.ts +0 -59
  89. package/src/hooks/useKeybindings.ts +0 -108
  90. package/src/hooks/useKeyboardShortcuts.ts +0 -63
  91. package/src/hooks/useLayoutMode.ts +0 -44
  92. package/src/hooks/useLocalePreference.ts +0 -42
  93. package/src/hooks/useReanchorMode.ts +0 -33
  94. package/src/hooks/useScrollMetrics.ts +0 -56
  95. package/src/hooks/useThemePreference.ts +0 -66
  96. package/src/lib/comment-storage.bench.ts +0 -63
  97. package/src/lib/context.bench.ts +0 -41
  98. package/src/lib/context.test.ts +0 -224
  99. package/src/lib/context.ts +0 -193
  100. package/src/lib/editor-links.ts +0 -59
  101. package/src/lib/export.bench.ts +0 -35
  102. package/src/lib/highlight/colors.ts +0 -37
  103. package/src/lib/highlight/core.ts +0 -54
  104. package/src/lib/highlight/index.ts +0 -23
  105. package/src/lib/highlight/script-builder.ts +0 -485
  106. package/src/lib/html-processor.test.tsx +0 -170
  107. package/src/lib/html-processor.tsx +0 -95
  108. package/src/lib/i18n/completeness.test.ts +0 -51
  109. package/src/lib/i18n/translations.test.ts +0 -39
  110. package/src/lib/layout-constants.ts +0 -12
  111. package/src/lib/margin-layout.bench.ts +0 -28
  112. package/src/lib/scroll.test.ts +0 -118
  113. package/src/lib/scroll.ts +0 -47
  114. package/src/lib/shortcut-registry.test.ts +0 -173
  115. package/src/lib/shortcut-registry.ts +0 -209
  116. package/src/lib/utils.test.ts +0 -110
  117. package/src/store/index.test.ts +0 -242
  118. package/src/types/index.ts +0 -127
@@ -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, "&lt;/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
- }
@@ -1,198 +0,0 @@
1
- import { useCallback, useMemo, useState } from "react";
2
- import { useLocale } from "../contexts/LocaleContext";
3
- import type { TranslationKey } from "../lib/i18n";
4
- import {
5
- bindingsEqual,
6
- formatBinding,
7
- type ShortcutAction,
8
- type ShortcutBinding,
9
- type ShortcutDefinition,
10
- } from "../lib/shortcut-registry";
11
- import { ShortcutCapture } from "./ShortcutCapture";
12
-
13
- interface ShortcutListProps {
14
- shortcuts: ShortcutDefinition[];
15
- onUpdateBinding: (id: string, binding: ShortcutBinding) => Promise<void>;
16
- onToggleEnabled: (id: string) => Promise<void>;
17
- onResetToDefaults: () => Promise<void>;
18
- }
19
-
20
- const SHORTCUT_GROUPS = [
21
- {
22
- labelKey: "shortcutGroup.copy" as const,
23
- ids: ["copyAll", "copyAllRaw", "copySelectionRaw", "copySelectionLLM"],
24
- },
25
- {
26
- labelKey: "shortcutGroup.navigate" as const,
27
- ids: ["navigateNext", "navigatePrevious"],
28
- },
29
- { labelKey: "shortcutGroup.other" as const, ids: ["clearSelection"] },
30
- ] as const;
31
-
32
- const SHORTCUT_LABEL_KEYS: Record<
33
- ShortcutAction,
34
- { label: TranslationKey; description: TranslationKey }
35
- > = {
36
- copyAll: {
37
- label: "shortcut.copyAll.label",
38
- description: "shortcut.copyAll.description",
39
- },
40
- copyAllRaw: {
41
- label: "shortcut.copyAllRaw.label",
42
- description: "shortcut.copyAllRaw.description",
43
- },
44
- navigateNext: {
45
- label: "shortcut.navigateNext.label",
46
- description: "shortcut.navigateNext.description",
47
- },
48
- navigatePrevious: {
49
- label: "shortcut.navigatePrevious.label",
50
- description: "shortcut.navigatePrevious.description",
51
- },
52
- copySelectionRaw: {
53
- label: "shortcut.copySelectionRaw.label",
54
- description: "shortcut.copySelectionRaw.description",
55
- },
56
- copySelectionLLM: {
57
- label: "shortcut.copySelectionLLM.label",
58
- description: "shortcut.copySelectionLLM.description",
59
- },
60
- clearSelection: {
61
- label: "shortcut.clearSelection.label",
62
- description: "shortcut.clearSelection.description",
63
- },
64
- };
65
-
66
- const isMac =
67
- typeof navigator !== "undefined" &&
68
- /Mac|iPod|iPhone|iPad/.test(navigator.platform);
69
-
70
- export function ShortcutList({
71
- shortcuts,
72
- onUpdateBinding,
73
- onToggleEnabled,
74
- onResetToDefaults,
75
- }: ShortcutListProps) {
76
- const { t } = useLocale();
77
- const [capturingId, setCapturingId] = useState<string | undefined>();
78
-
79
- const hasOverrides = useMemo(
80
- () =>
81
- shortcuts.some(
82
- (s) => !s.enabled || !bindingsEqual(s.binding, s.defaultBinding),
83
- ),
84
- [shortcuts],
85
- );
86
-
87
- const shortcutMap = useMemo(
88
- () => new Map(shortcuts.map((s) => [s.id, s])),
89
- [shortcuts],
90
- );
91
-
92
- const handleCapture = useCallback(
93
- async (id: string, binding: ShortcutBinding) => {
94
- const conflict = shortcuts.find(
95
- (s) => s.id !== id && s.enabled && bindingsEqual(s.binding, binding),
96
- );
97
-
98
- if (conflict) {
99
- const currentShortcut = shortcuts.find((s) => s.id === id);
100
- if (currentShortcut) {
101
- await onUpdateBinding(conflict.id, currentShortcut.binding);
102
- }
103
- }
104
-
105
- await onUpdateBinding(id, binding);
106
- setCapturingId(undefined);
107
- },
108
- [shortcuts, onUpdateBinding],
109
- );
110
-
111
- return (
112
- <div className="space-y-4">
113
- {SHORTCUT_GROUPS.map((group) => {
114
- const groupShortcuts = group.ids
115
- .map((id) => shortcutMap.get(id))
116
- .filter((s): s is ShortcutDefinition => s !== undefined);
117
-
118
- if (groupShortcuts.length === 0) return null;
119
-
120
- return (
121
- <div key={group.labelKey}>
122
- <span className="text-[11px] font-medium text-zinc-400 dark:text-zinc-500 uppercase tracking-wider">
123
- {t(group.labelKey)}
124
- </span>
125
- <div className="mt-1 space-y-0.5">
126
- {groupShortcuts.map((shortcut) => (
127
- <div
128
- key={shortcut.id}
129
- className="flex items-center gap-3 py-1.5"
130
- >
131
- <span
132
- className="flex-1 text-sm text-zinc-700 dark:text-zinc-300 truncate"
133
- title={t(SHORTCUT_LABEL_KEYS[shortcut.id].description)}
134
- >
135
- {t(SHORTCUT_LABEL_KEYS[shortcut.id].label)}
136
- </span>
137
-
138
- <div className="flex items-center gap-2.5">
139
- {capturingId === shortcut.id ? (
140
- <ShortcutCapture
141
- onCapture={(binding) =>
142
- handleCapture(shortcut.id, binding)
143
- }
144
- onCancel={() => setCapturingId(undefined)}
145
- />
146
- ) : (
147
- <button
148
- type="button"
149
- onClick={() => setCapturingId(shortcut.id)}
150
- className="inline-flex items-center px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-600 dark:text-zinc-400 text-xs font-mono cursor-pointer hover:bg-zinc-200 hover:border-zinc-300 dark:hover:bg-zinc-700 dark:hover:border-zinc-600 transition-colors"
151
- >
152
- {formatBinding(shortcut.binding, isMac)}
153
- </button>
154
- )}
155
-
156
- <button
157
- type="button"
158
- role="switch"
159
- aria-checked={shortcut.enabled}
160
- onClick={() => onToggleEnabled(shortcut.id)}
161
- title={t("shortcuts.enableDisable")}
162
- className={`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors cursor-pointer ${
163
- shortcut.enabled
164
- ? "bg-zinc-600 dark:bg-zinc-400"
165
- : "bg-zinc-300 dark:bg-zinc-700"
166
- }`}
167
- >
168
- <span
169
- className={`inline-block size-3 rounded-full bg-white dark:bg-zinc-900 shadow-sm transition-transform ${
170
- shortcut.enabled
171
- ? "translate-x-3.5"
172
- : "translate-x-0.5"
173
- }`}
174
- />
175
- </button>
176
- </div>
177
- </div>
178
- ))}
179
- </div>
180
- </div>
181
- );
182
- })}
183
-
184
- <button
185
- type="button"
186
- onClick={hasOverrides ? onResetToDefaults : undefined}
187
- disabled={!hasOverrides}
188
- className={
189
- hasOverrides
190
- ? "text-xs text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 transition-colors cursor-pointer"
191
- : "text-xs text-zinc-300 dark:text-zinc-600 cursor-default"
192
- }
193
- >
194
- {t("shortcuts.resetToDefaults")}
195
- </button>
196
- </div>
197
- );
198
- }
@@ -1,62 +0,0 @@
1
- import { useCommentContext } from "../../contexts/CommentContext";
2
- import { MINIMAP_HEADER_OFFSET_PX } from "../../lib/layout-constants";
3
- import { cn } from "../../lib/utils";
4
-
5
- interface CommentMinimapProps {
6
- /** Absolute Y-positions from document top for each comment */
7
- documentPositions: Record<string, number>;
8
- documentHeight: number;
9
- viewportHeight: number;
10
- }
11
-
12
- export function CommentMinimap({
13
- documentPositions,
14
- documentHeight,
15
- viewportHeight,
16
- }: CommentMinimapProps) {
17
- const { sortedComments, hoveredCommentId, navigateToComment } =
18
- useCommentContext();
19
-
20
- // Don't render if no comments or document height is 0
21
- if (sortedComments.length === 0 || documentHeight === 0) {
22
- return null;
23
- }
24
-
25
- // Minimap height is the viewport height minus header
26
- const minimapHeight = viewportHeight - MINIMAP_HEADER_OFFSET_PX;
27
-
28
- return (
29
- <div
30
- className="fixed right-0 top-12 w-3 z-40"
31
- style={{ height: minimapHeight }}
32
- >
33
- {sortedComments.map((comment) => {
34
- const position = documentPositions[comment.id];
35
- if (position === undefined) return null;
36
-
37
- // Scale absolute position to minimap height
38
- const indicatorTop = (position / documentHeight) * minimapHeight;
39
-
40
- const isHovered = hoveredCommentId === comment.id;
41
-
42
- return (
43
- <button
44
- type="button"
45
- key={comment.id}
46
- className={cn(
47
- "absolute left-0 right-0 h-1.5 rounded-l transition-all duration-150 cursor-pointer",
48
- isHovered
49
- ? "bg-amber-500 w-4 -translate-x-1"
50
- : "bg-amber-500 hover:bg-amber-600 hover:w-4 hover:-translate-x-1",
51
- )}
52
- style={{
53
- top: Math.max(0, Math.min(indicatorTop, minimapHeight - 6)),
54
- }}
55
- onClick={() => navigateToComment(comment.id)}
56
- title={`"${comment.selectedText.slice(0, 30)}${comment.selectedText.length > 30 ? "..." : ""}"`}
57
- />
58
- );
59
- })}
60
- </div>
61
- );
62
- }
@@ -1,16 +0,0 @@
1
- import { cn } from "../../lib/utils";
2
-
3
- function ActionBar({ className, ...props }: React.ComponentProps<"div">) {
4
- return (
5
- <div
6
- data-slot="action-bar"
7
- className={cn(
8
- "flex items-center text-xs text-zinc-400 opacity-0 group-hover:opacity-100 transition-opacity",
9
- className,
10
- )}
11
- {...props}
12
- />
13
- );
14
- }
15
-
16
- export { ActionBar };