@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.
Files changed (221) hide show
  1. package/.claude/CLAUDE.md +118 -76
  2. package/.claude/commands/review.md +1 -1
  3. package/.claude/roadmap.md +32 -9
  4. package/.claude/user-stories.md +100 -15
  5. package/AGENTS.md +30 -26
  6. package/Makefile +32 -0
  7. package/README.md +90 -5
  8. package/biome.json +18 -8
  9. package/bun.lock +426 -710
  10. package/bunfig.toml +2 -0
  11. package/docs/perf-baseline.md +130 -0
  12. package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
  13. package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
  14. package/e2e/comments.spec.ts +14 -58
  15. package/e2e/document-load.spec.ts +1 -23
  16. package/e2e/export.spec.ts +4 -4
  17. package/e2e/perf/add-comment.spec.ts +116 -0
  18. package/e2e/perf/fixtures/generate.ts +327 -0
  19. package/e2e/perf/initial-load.spec.ts +49 -0
  20. package/e2e/perf/perf.setup.ts +23 -0
  21. package/e2e/perf/perf.teardown.ts +9 -0
  22. package/e2e/perf/screenshot-final.png +0 -0
  23. package/e2e/perf/scroll.spec.ts +39 -0
  24. package/e2e/perf/tab-switch.spec.ts +69 -0
  25. package/e2e/perf/text-selection.spec.ts +119 -0
  26. package/e2e/perf/utils/metrics.ts +350 -0
  27. package/e2e/perf/utils/perf-cli.ts +86 -0
  28. package/e2e/persistence-file.spec.ts +41 -26
  29. package/e2e/utils/selection.ts +17 -73
  30. package/go/cmd/readit/main.go +416 -0
  31. package/go/go.mod +20 -0
  32. package/go/go.sum +41 -0
  33. package/go/internal/server/anchor.go +302 -0
  34. package/go/internal/server/anchor_test.go +111 -0
  35. package/go/internal/server/comments.go +390 -0
  36. package/go/internal/server/documents.go +113 -0
  37. package/go/internal/server/embed.go +17 -0
  38. package/go/internal/server/headings.go +33 -0
  39. package/go/internal/server/headings_test.go +75 -0
  40. package/go/internal/server/htmltext.go +123 -0
  41. package/go/internal/server/markdown.go +157 -0
  42. package/go/internal/server/markdown_bench_test.go +42 -0
  43. package/go/internal/server/markdown_test.go +79 -0
  44. package/go/internal/server/server.go +453 -0
  45. package/go/internal/server/server_bench_test.go +122 -0
  46. package/go/internal/server/settings.go +110 -0
  47. package/go/internal/server/sse.go +140 -0
  48. package/go/internal/server/storage.go +275 -0
  49. package/go/internal/server/storage_test.go +118 -0
  50. package/go/internal/server/template.go +66 -0
  51. package/go/internal/server/types.go +101 -0
  52. package/go/internal/server/watcher.go +74 -0
  53. package/index.html +4 -14
  54. package/nvim-readit/lua/readit/health.lua +64 -0
  55. package/nvim-readit/lua/readit/init.lua +463 -0
  56. package/nvim-readit/plugin/readit.lua +19 -0
  57. package/package.json +24 -41
  58. package/playwright.config.ts +12 -0
  59. package/shell/_readit +158 -0
  60. package/shell/readit.zsh +87 -0
  61. package/src/App.svelte +881 -0
  62. package/src/{cli/index.ts → cli.ts} +216 -70
  63. package/src/components/ActionsMenu.svelte +95 -0
  64. package/src/components/CommentBadge.svelte +67 -0
  65. package/src/components/CommentErrorBanner.svelte +33 -0
  66. package/src/components/CommentInput.svelte +75 -0
  67. package/src/components/CommentListItem.svelte +95 -0
  68. package/src/components/CommentManager.svelte +129 -0
  69. package/src/components/CommentNav.svelte +109 -0
  70. package/src/components/DocumentViewer.svelte +218 -0
  71. package/src/components/FloatingComment.svelte +107 -0
  72. package/src/components/Header.svelte +76 -0
  73. package/src/components/InlineEditor.svelte +72 -0
  74. package/src/components/MarginNote.svelte +167 -0
  75. package/src/components/MarginNotesContainer.svelte +33 -0
  76. package/src/components/RawModal.svelte +126 -0
  77. package/src/components/ReanchorConfirm.svelte +30 -0
  78. package/src/components/SettingsModal.svelte +220 -0
  79. package/src/components/ShortcutCapture.svelte +82 -0
  80. package/src/components/ShortcutList.svelte +145 -0
  81. package/src/components/TabBar.svelte +52 -0
  82. package/src/components/TableOfContents.svelte +125 -0
  83. package/src/components/ui/ActionLink.svelte +40 -0
  84. package/src/components/ui/Button.svelte +53 -0
  85. package/src/components/ui/Dialog.svelte +97 -0
  86. package/src/components/ui/DropdownMenu.svelte +85 -0
  87. package/src/components/ui/DropdownMenuItem.svelte +38 -0
  88. package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
  89. package/src/components/ui/Text.svelte +42 -0
  90. package/src/env.d.ts +6 -0
  91. package/src/index.css +36 -166
  92. package/src/lib/__fixtures__/bench-data.ts +1 -54
  93. package/src/lib/anchor.bench.ts +47 -68
  94. package/src/lib/anchor.test.ts +5 -9
  95. package/src/lib/anchor.ts +9 -93
  96. package/src/lib/comment-storage.bench.ts +6 -20
  97. package/src/lib/comment-storage.test.ts +45 -37
  98. package/src/lib/comment-storage.ts +23 -64
  99. package/src/lib/export.bench.ts +9 -23
  100. package/src/lib/export.ts +7 -14
  101. package/src/lib/headings.test.ts +103 -0
  102. package/src/lib/headings.ts +44 -0
  103. package/src/lib/highlight/core.test.ts +1 -6
  104. package/src/lib/highlight/dom.ts +53 -280
  105. package/src/lib/highlight/highlight-registry.ts +221 -0
  106. package/src/lib/highlight/highlight.bench.ts +92 -0
  107. package/src/lib/highlight/highlighter.ts +122 -302
  108. package/src/lib/highlight/{core.ts → resolver.ts} +3 -19
  109. package/src/lib/highlight/types.ts +0 -40
  110. package/src/lib/html-text.test.ts +162 -0
  111. package/src/lib/html-text.ts +161 -0
  112. package/src/lib/i18n/en.ts +13 -36
  113. package/src/lib/i18n/ja.ts +14 -37
  114. package/src/lib/i18n/types.ts +13 -36
  115. package/src/lib/margin-layout.bench.ts +48 -15
  116. package/src/lib/margin-layout.ts +2 -31
  117. package/src/lib/markdown-renderer.test.ts +154 -0
  118. package/src/lib/markdown-renderer.ts +177 -0
  119. package/src/lib/mermaid-config.ts +38 -0
  120. package/src/lib/mermaid-renderer.ts +162 -0
  121. package/src/lib/mermaid-worker.ts +60 -0
  122. package/src/lib/positions.ts +157 -0
  123. package/src/lib/shortcut-registry.ts +138 -103
  124. package/src/lib/utils.ts +2 -48
  125. package/src/main.ts +16 -0
  126. package/src/schema.ts +92 -0
  127. package/src/{server/index.ts → server.ts} +427 -163
  128. package/src/stores/app.svelte.ts +231 -0
  129. package/src/stores/locale.svelte.ts +46 -0
  130. package/src/stores/settings.svelte.ts +90 -0
  131. package/src/stores/shortcuts.svelte.ts +104 -0
  132. package/src/stores/ui.svelte.ts +12 -0
  133. package/src/template.ts +104 -0
  134. package/src/test-setup.ts +47 -0
  135. package/svelte.config.js +5 -0
  136. package/tsconfig.json +2 -2
  137. package/vite.config.ts +31 -3
  138. package/vscode-readit/.mcp.json +7 -0
  139. package/vscode-readit/.vscodeignore +7 -0
  140. package/vscode-readit/bun.lock +78 -0
  141. package/vscode-readit/icon.svg +10 -0
  142. package/vscode-readit/package.json +110 -0
  143. package/vscode-readit/src/extension.ts +117 -0
  144. package/vscode-readit/src/server-manager.ts +272 -0
  145. package/vscode-readit/src/webview-provider.ts +204 -0
  146. package/vscode-readit/tsconfig.json +20 -0
  147. package/e2e/fixtures/sample.html +0 -13
  148. package/src/App.tsx +0 -416
  149. package/src/components/ActionsMenu.tsx +0 -112
  150. package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
  151. package/src/components/DocumentViewer/DocumentViewer.tsx +0 -259
  152. package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
  153. package/src/components/DocumentViewer/InlineCode.tsx +0 -60
  154. package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -137
  155. package/src/components/DocumentViewer/index.ts +0 -1
  156. package/src/components/FloatingTOC.tsx +0 -61
  157. package/src/components/Header.tsx +0 -65
  158. package/src/components/InlineEditor.tsx +0 -74
  159. package/src/components/MarginNote.tsx +0 -207
  160. package/src/components/MarginNotes.tsx +0 -50
  161. package/src/components/RawModal.tsx +0 -143
  162. package/src/components/ReanchorConfirm.tsx +0 -36
  163. package/src/components/SettingsModal.tsx +0 -310
  164. package/src/components/ShortcutCapture.tsx +0 -48
  165. package/src/components/ShortcutList.tsx +0 -198
  166. package/src/components/TabBar.tsx +0 -60
  167. package/src/components/TableOfContents.tsx +0 -108
  168. package/src/components/comments/CommentBadge.tsx +0 -49
  169. package/src/components/comments/CommentInput.tsx +0 -114
  170. package/src/components/comments/CommentListItem.tsx +0 -92
  171. package/src/components/comments/CommentManager.tsx +0 -113
  172. package/src/components/comments/CommentMinimap.tsx +0 -62
  173. package/src/components/comments/CommentNav.tsx +0 -109
  174. package/src/components/ui/ActionBar.tsx +0 -16
  175. package/src/components/ui/ActionLink.tsx +0 -32
  176. package/src/components/ui/Button.tsx +0 -55
  177. package/src/components/ui/Dialog.tsx +0 -156
  178. package/src/components/ui/DropdownMenu.tsx +0 -114
  179. package/src/components/ui/SeparatorDot.tsx +0 -9
  180. package/src/components/ui/Text.tsx +0 -54
  181. package/src/contexts/CommentContext.tsx +0 -229
  182. package/src/contexts/LayoutContext.tsx +0 -88
  183. package/src/contexts/LocaleContext.tsx +0 -35
  184. package/src/hooks/useClickOutside.ts +0 -35
  185. package/src/hooks/useClipboard.ts +0 -82
  186. package/src/hooks/useCommentNavigation.ts +0 -130
  187. package/src/hooks/useComments.ts +0 -323
  188. package/src/hooks/useDocument.ts +0 -156
  189. package/src/hooks/useEditorScheme.ts +0 -51
  190. package/src/hooks/useFontPreference.ts +0 -59
  191. package/src/hooks/useHeadings.test.ts +0 -159
  192. package/src/hooks/useHeadings.ts +0 -129
  193. package/src/hooks/useKeybindings.ts +0 -108
  194. package/src/hooks/useKeyboardShortcuts.ts +0 -63
  195. package/src/hooks/useLayoutMode.ts +0 -44
  196. package/src/hooks/useLocalePreference.ts +0 -42
  197. package/src/hooks/useReanchorMode.ts +0 -33
  198. package/src/hooks/useScrollMetrics.ts +0 -56
  199. package/src/hooks/useScrollSpy.ts +0 -81
  200. package/src/hooks/useTextSelection.ts +0 -123
  201. package/src/hooks/useThemePreference.ts +0 -66
  202. package/src/lib/context.bench.ts +0 -41
  203. package/src/lib/context.test.ts +0 -224
  204. package/src/lib/context.ts +0 -193
  205. package/src/lib/editor-links.ts +0 -59
  206. package/src/lib/highlight/colors.ts +0 -37
  207. package/src/lib/highlight/index.ts +0 -23
  208. package/src/lib/highlight/script-builder.ts +0 -485
  209. package/src/lib/html-processor.test.tsx +0 -170
  210. package/src/lib/html-processor.tsx +0 -95
  211. package/src/lib/i18n/completeness.test.ts +0 -51
  212. package/src/lib/i18n/translations.test.ts +0 -39
  213. package/src/lib/layout-constants.ts +0 -12
  214. package/src/lib/scroll.test.ts +0 -118
  215. package/src/lib/scroll.ts +0 -47
  216. package/src/lib/shortcut-registry.test.ts +0 -173
  217. package/src/lib/utils.test.ts +0 -110
  218. package/src/main.tsx +0 -13
  219. package/src/store/index.test.ts +0 -242
  220. package/src/store/index.ts +0 -254
  221. package/src/types/index.ts +0 -127
@@ -1,310 +0,0 @@
1
- import { Check, ChevronDown, ExternalLink } from "lucide-react";
2
- import { useLayoutContext } from "../contexts/LayoutContext";
3
- import { useLocale } from "../contexts/LocaleContext";
4
- import { type Locale, Locales } from "../lib/i18n";
5
- import { cn } from "../lib/utils";
6
- import {
7
- type EditorScheme,
8
- EditorSchemes,
9
- FontFamilies,
10
- type FontFamily,
11
- type ThemeMode,
12
- ThemeModes,
13
- } from "../types";
14
- import { ShortcutList } from "./ShortcutList";
15
- import {
16
- Dialog,
17
- DialogBody,
18
- DialogContent,
19
- DialogHeader,
20
- DialogTitle,
21
- } from "./ui/Dialog";
22
- import {
23
- DropdownMenu,
24
- DropdownMenuContent,
25
- DropdownMenuItem,
26
- DropdownMenuTrigger,
27
- } from "./ui/DropdownMenu";
28
- import { Text } from "./ui/Text";
29
-
30
- interface SettingsModalProps {
31
- isOpen: boolean;
32
- onClose: () => void;
33
- }
34
-
35
- const LOCALE_OPTIONS = [
36
- { value: Locales.JA, label: "日本語" },
37
- { value: Locales.EN, label: "English" },
38
- ] as const;
39
-
40
- function ThemeDot({
41
- mode,
42
- className,
43
- }: {
44
- mode: ThemeMode;
45
- className?: string;
46
- }) {
47
- if (mode === ThemeModes.SYSTEM) {
48
- return (
49
- <span
50
- className={cn(
51
- "size-2.5 rounded-full bg-gradient-to-r from-amber-400 to-indigo-400",
52
- className,
53
- )}
54
- />
55
- );
56
- }
57
-
58
- return (
59
- <span
60
- className={cn(
61
- "size-2.5 rounded-full",
62
- mode === ThemeModes.LIGHT ? "bg-amber-400" : "bg-indigo-400",
63
- className,
64
- )}
65
- />
66
- );
67
- }
68
-
69
- function ThemePreviewBadge() {
70
- return (
71
- <span className="text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5">
72
- Aa
73
- </span>
74
- );
75
- }
76
-
77
- /* ─── Font selector ──────────────────────────────────────────── */
78
-
79
- function FontPreviewBadge({ fontClass }: { fontClass: string }) {
80
- return (
81
- <span
82
- className={cn(
83
- "text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5",
84
- fontClass,
85
- )}
86
- >
87
- Aa
88
- </span>
89
- );
90
- }
91
-
92
- /* ─── Shared trigger style ───────────────────────────────────── */
93
-
94
- const triggerClassName = cn(
95
- "inline-flex items-center gap-2 px-2.5 py-1.5 rounded-lg text-sm",
96
- "border border-zinc-200 dark:border-zinc-700",
97
- "bg-white dark:bg-zinc-800",
98
- "text-zinc-700 dark:text-zinc-300",
99
- "hover:bg-zinc-50 dark:hover:bg-zinc-700/50",
100
- "transition-colors cursor-pointer",
101
- );
102
-
103
- /* ─── Settings Modal ─────────────────────────────────────────── */
104
-
105
- export function SettingsModal({ isOpen, onClose }: SettingsModalProps) {
106
- const {
107
- fontFamily,
108
- setFontFamily,
109
- editorScheme,
110
- setEditorScheme,
111
- themeMode,
112
- setThemeMode,
113
- shortcuts,
114
- updateBinding,
115
- toggleShortcutEnabled,
116
- resetShortcutsToDefaults,
117
- } = useLayoutContext();
118
- const { locale, setLocale, t } = useLocale();
119
-
120
- const themeOptions = [
121
- { value: ThemeModes.SYSTEM, label: t("settings.theme.system") },
122
- { value: ThemeModes.LIGHT, label: t("settings.theme.light") },
123
- { value: ThemeModes.DARK, label: t("settings.theme.dark") },
124
- ];
125
-
126
- const fontOptions = [
127
- {
128
- value: FontFamilies.SERIF,
129
- label: t("settings.font.serif"),
130
- fontClass: "font-serif",
131
- },
132
- {
133
- value: FontFamilies.SANS_SERIF,
134
- label: t("settings.font.sansSerif"),
135
- fontClass: "font-sans",
136
- },
137
- ];
138
-
139
- const editorOptions = [
140
- { value: EditorSchemes.NONE, label: t("settings.editor.none") },
141
- { value: EditorSchemes.VSCODE, label: t("settings.editor.vscode") },
142
- {
143
- value: EditorSchemes.VSCODE_INSIDERS,
144
- label: t("settings.editor.vscodeInsiders"),
145
- },
146
- { value: EditorSchemes.CURSOR, label: t("settings.editor.cursor") },
147
- ];
148
-
149
- const activeTheme =
150
- themeOptions.find((o) => o.value === themeMode) ?? themeOptions[0];
151
- const activeFont =
152
- fontOptions.find((o) => o.value === fontFamily) ?? fontOptions[0];
153
- const activeEditor =
154
- editorOptions.find((o) => o.value === editorScheme) ?? editorOptions[0];
155
- const activeLocale =
156
- LOCALE_OPTIONS.find((o) => o.value === locale) ?? LOCALE_OPTIONS[0];
157
-
158
- return (
159
- <Dialog
160
- open={isOpen}
161
- onOpenChange={(open) => {
162
- if (!open) onClose();
163
- }}
164
- >
165
- <DialogContent className="max-w-md">
166
- <DialogHeader>
167
- <DialogTitle>{t("settings.title")}</DialogTitle>
168
- </DialogHeader>
169
-
170
- <DialogBody className="space-y-4">
171
- <div>
172
- <Text variant="overline" asChild>
173
- <h3 className="mb-3">{t("settings.theme")}</h3>
174
- </Text>
175
- <DropdownMenu>
176
- <DropdownMenuTrigger asChild>
177
- <button type="button" className={triggerClassName}>
178
- <ThemeDot mode={activeTheme.value} />
179
- <ThemePreviewBadge />
180
- <span>{activeTheme.label}</span>
181
- <ChevronDown className="size-3 text-zinc-400 dark:text-zinc-500" />
182
- </button>
183
- </DropdownMenuTrigger>
184
- <DropdownMenuContent align="start" className="min-w-[160px]">
185
- {themeOptions.map((option) => (
186
- <DropdownMenuItem
187
- key={option.value}
188
- onSelect={() => setThemeMode(option.value)}
189
- className="flex items-center gap-2"
190
- >
191
- <ThemeDot mode={option.value} />
192
- <ThemePreviewBadge />
193
- <span className="flex-1">{option.label}</span>
194
- {themeMode === option.value && (
195
- <Check className="size-3.5 text-zinc-500 dark:text-zinc-400" />
196
- )}
197
- </DropdownMenuItem>
198
- ))}
199
- </DropdownMenuContent>
200
- </DropdownMenu>
201
- </div>
202
-
203
- <div>
204
- <Text variant="overline" asChild>
205
- <h3 className="mb-3">{t("settings.font")}</h3>
206
- </Text>
207
- <DropdownMenu>
208
- <DropdownMenuTrigger asChild>
209
- <button type="button" className={triggerClassName}>
210
- <FontPreviewBadge fontClass={activeFont.fontClass} />
211
- <span>{activeFont.label}</span>
212
- <ChevronDown className="size-3 text-zinc-400 dark:text-zinc-500" />
213
- </button>
214
- </DropdownMenuTrigger>
215
- <DropdownMenuContent align="start" className="min-w-[160px]">
216
- {fontOptions.map((option) => (
217
- <DropdownMenuItem
218
- key={option.value}
219
- onSelect={() => setFontFamily(option.value as FontFamily)}
220
- className="flex items-center gap-2"
221
- >
222
- <FontPreviewBadge fontClass={option.fontClass} />
223
- <span className="flex-1">{option.label}</span>
224
- {fontFamily === option.value && (
225
- <Check className="size-3.5 text-zinc-500 dark:text-zinc-400" />
226
- )}
227
- </DropdownMenuItem>
228
- ))}
229
- </DropdownMenuContent>
230
- </DropdownMenu>
231
- </div>
232
-
233
- <div>
234
- <Text variant="overline" asChild>
235
- <h3 className="mb-3">{t("settings.language")}</h3>
236
- </Text>
237
- <DropdownMenu>
238
- <DropdownMenuTrigger asChild>
239
- <button type="button" className={triggerClassName}>
240
- <span>{activeLocale.label}</span>
241
- <ChevronDown className="size-3 text-zinc-400 dark:text-zinc-500" />
242
- </button>
243
- </DropdownMenuTrigger>
244
- <DropdownMenuContent align="start" className="min-w-[160px]">
245
- {LOCALE_OPTIONS.map((option) => (
246
- <DropdownMenuItem
247
- key={option.value}
248
- onSelect={() => setLocale(option.value as Locale)}
249
- className="flex items-center gap-2"
250
- >
251
- <span className="flex-1">{option.label}</span>
252
- {locale === option.value && (
253
- <Check className="size-3.5 text-zinc-500 dark:text-zinc-400" />
254
- )}
255
- </DropdownMenuItem>
256
- ))}
257
- </DropdownMenuContent>
258
- </DropdownMenu>
259
- </div>
260
-
261
- <div>
262
- <Text variant="overline" asChild>
263
- <h3 className="mb-3">{t("settings.editor")}</h3>
264
- </Text>
265
- <DropdownMenu>
266
- <DropdownMenuTrigger asChild>
267
- <button type="button" className={triggerClassName}>
268
- <ExternalLink className="size-3 text-zinc-400 dark:text-zinc-500" />
269
- <span>{activeEditor.label}</span>
270
- <ChevronDown className="size-3 text-zinc-400 dark:text-zinc-500" />
271
- </button>
272
- </DropdownMenuTrigger>
273
- <DropdownMenuContent align="start" className="min-w-[160px]">
274
- {editorOptions.map((option) => (
275
- <DropdownMenuItem
276
- key={option.value}
277
- onSelect={() =>
278
- setEditorScheme(option.value as EditorScheme)
279
- }
280
- className="flex items-center gap-2"
281
- >
282
- <span className="flex-1">{option.label}</span>
283
- {editorScheme === option.value && (
284
- <Check className="size-3.5 text-zinc-500 dark:text-zinc-400" />
285
- )}
286
- </DropdownMenuItem>
287
- ))}
288
- </DropdownMenuContent>
289
- </DropdownMenu>
290
- </div>
291
-
292
- <div>
293
- <Text variant="overline" asChild>
294
- <h3 className="mb-1">{t("settings.keyboardShortcuts")}</h3>
295
- </Text>
296
- <p className="text-xs text-zinc-400 dark:text-zinc-500 mb-3">
297
- {t("settings.clickToRebind")}
298
- </p>
299
- <ShortcutList
300
- shortcuts={shortcuts}
301
- onUpdateBinding={updateBinding}
302
- onToggleEnabled={toggleShortcutEnabled}
303
- onResetToDefaults={resetShortcutsToDefaults}
304
- />
305
- </div>
306
- </DialogBody>
307
- </DialogContent>
308
- </Dialog>
309
- );
310
- }
@@ -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,60 +0,0 @@
1
- import { X } from "lucide-react";
2
- import { cn } from "../lib/utils";
3
- import { useAppStore } from "../store";
4
-
5
- export function TabBar() {
6
- const documentOrder = useAppStore((s) => s.documentOrder);
7
- const activeDocumentPath = useAppStore((s) => s.activeDocumentPath);
8
- const documents = useAppStore((s) => s.documents);
9
- const setActiveDocument = useAppStore((s) => s.setActiveDocument);
10
- const closeDocument = useAppStore((s) => s.closeDocument);
11
-
12
- if (documentOrder.length <= 1) return null;
13
-
14
- return (
15
- <div
16
- className="flex border-b border-zinc-200 bg-zinc-50 px-2 overflow-x-auto"
17
- role="tablist"
18
- >
19
- {documentOrder.map((filePath) => {
20
- const docState = documents.get(filePath);
21
- if (!docState) return null;
22
- const isActive = filePath === activeDocumentPath;
23
-
24
- return (
25
- <div
26
- key={filePath}
27
- role="tab"
28
- tabIndex={isActive ? 0 : -1}
29
- aria-selected={isActive}
30
- className={cn(
31
- "flex items-center gap-1.5 px-3 py-1.5 text-sm border-b-2 whitespace-nowrap cursor-pointer select-none",
32
- isActive
33
- ? "border-zinc-900 text-zinc-900"
34
- : "border-transparent text-zinc-500 hover:text-zinc-700 hover:bg-zinc-100",
35
- )}
36
- onClick={() => setActiveDocument(filePath)}
37
- onKeyDown={(e) => {
38
- if (e.key === "Enter" || e.key === " ") {
39
- e.preventDefault();
40
- setActiveDocument(filePath);
41
- }
42
- }}
43
- >
44
- <span>{docState.document.fileName}</span>
45
- <button
46
- type="button"
47
- className="ml-1 rounded p-0.5 hover:bg-zinc-200"
48
- onClick={(e) => {
49
- e.stopPropagation();
50
- closeDocument(filePath);
51
- }}
52
- >
53
- <X className="h-3 w-3" />
54
- </button>
55
- </div>
56
- );
57
- })}
58
- </div>
59
- );
60
- }