@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
package/src/store/index.test.ts
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import type { Comment, Document } from "../types";
|
|
3
|
-
import { createAppStore } from "./index";
|
|
4
|
-
|
|
5
|
-
const mockDoc: Document = {
|
|
6
|
-
content: "# Hello",
|
|
7
|
-
type: "markdown",
|
|
8
|
-
filePath: "/test/file.md",
|
|
9
|
-
fileName: "file.md",
|
|
10
|
-
clean: false,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const mockDoc2: Document = {
|
|
14
|
-
content: "<h1>Hello</h1>",
|
|
15
|
-
type: "html",
|
|
16
|
-
filePath: "/test/file.html",
|
|
17
|
-
fileName: "file.html",
|
|
18
|
-
clean: false,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const mockComment = {
|
|
22
|
-
id: "c1",
|
|
23
|
-
selectedText: "hello",
|
|
24
|
-
comment: "note",
|
|
25
|
-
startOffset: 0,
|
|
26
|
-
endOffset: 5,
|
|
27
|
-
createdAt: "2026-03-13T00:00:00Z",
|
|
28
|
-
} as Comment;
|
|
29
|
-
|
|
30
|
-
describe("AppStore", () => {
|
|
31
|
-
let store: ReturnType<typeof createAppStore>;
|
|
32
|
-
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
store = createAppStore();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("openDocument", () => {
|
|
38
|
-
it("adds document to store and sets as active", () => {
|
|
39
|
-
store.getState().openDocument(mockDoc);
|
|
40
|
-
const state = store.getState();
|
|
41
|
-
expect(state.documents.has("/test/file.md")).toBe(true);
|
|
42
|
-
expect(state.activeDocumentPath).toBe("/test/file.md");
|
|
43
|
-
expect(state.documentOrder).toEqual(["/test/file.md"]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("does not overwrite existing document state", () => {
|
|
47
|
-
store.getState().openDocument(mockDoc);
|
|
48
|
-
store.getState().setComments([mockComment]);
|
|
49
|
-
store.getState().openDocument(mockDoc);
|
|
50
|
-
expect(
|
|
51
|
-
store.getState().documents.get("/test/file.md")!.comments,
|
|
52
|
-
).toHaveLength(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("activates existing document without overwriting", () => {
|
|
56
|
-
store.getState().openDocument(mockDoc);
|
|
57
|
-
store.getState().openDocument(mockDoc2);
|
|
58
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.html");
|
|
59
|
-
store.getState().openDocument(mockDoc);
|
|
60
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.md");
|
|
61
|
-
// Order unchanged
|
|
62
|
-
expect(store.getState().documentOrder).toEqual([
|
|
63
|
-
"/test/file.md",
|
|
64
|
-
"/test/file.html",
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("adds document without activating when active is false", () => {
|
|
69
|
-
store.getState().openDocument(mockDoc);
|
|
70
|
-
store.getState().openDocument(mockDoc2, { active: false });
|
|
71
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.md");
|
|
72
|
-
expect(store.getState().documentOrder).toEqual([
|
|
73
|
-
"/test/file.md",
|
|
74
|
-
"/test/file.html",
|
|
75
|
-
]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("updates existing document without stealing focus when active is false", () => {
|
|
79
|
-
store.getState().openDocument(mockDoc);
|
|
80
|
-
store.getState().openDocument(mockDoc2);
|
|
81
|
-
store
|
|
82
|
-
.getState()
|
|
83
|
-
.openDocument({ ...mockDoc, content: "# Updated" }, { active: false });
|
|
84
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.html");
|
|
85
|
-
expect(
|
|
86
|
-
store.getState().documents.get("/test/file.md")!.document.content,
|
|
87
|
-
).toBe("# Updated");
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("closeDocument", () => {
|
|
92
|
-
it("removes document and activates right neighbor", () => {
|
|
93
|
-
store.getState().openDocument(mockDoc);
|
|
94
|
-
store.getState().openDocument(mockDoc2);
|
|
95
|
-
store.getState().setActiveDocument("/test/file.md");
|
|
96
|
-
store.getState().closeDocument("/test/file.md");
|
|
97
|
-
expect(store.getState().documents.has("/test/file.md")).toBe(false);
|
|
98
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.html");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("activates left neighbor when closing last in order", () => {
|
|
102
|
-
store.getState().openDocument(mockDoc);
|
|
103
|
-
store.getState().openDocument(mockDoc2);
|
|
104
|
-
// mockDoc2 is active (last opened)
|
|
105
|
-
store.getState().closeDocument("/test/file.html");
|
|
106
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.md");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("sets null when closing last document", () => {
|
|
110
|
-
store.getState().openDocument(mockDoc);
|
|
111
|
-
store.getState().closeDocument("/test/file.md");
|
|
112
|
-
expect(store.getState().activeDocumentPath).toBeNull();
|
|
113
|
-
expect(store.getState().documentOrder).toEqual([]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("does not change active if closing non-active tab", () => {
|
|
117
|
-
store.getState().openDocument(mockDoc);
|
|
118
|
-
store.getState().openDocument(mockDoc2);
|
|
119
|
-
// mockDoc2 is active
|
|
120
|
-
store.getState().closeDocument("/test/file.md");
|
|
121
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.html");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("activates right neighbor when closing middle tab", () => {
|
|
125
|
-
const mockDoc3: Document = {
|
|
126
|
-
content: "# Third",
|
|
127
|
-
type: "markdown",
|
|
128
|
-
filePath: "/test/third.md",
|
|
129
|
-
fileName: "third.md",
|
|
130
|
-
clean: false,
|
|
131
|
-
};
|
|
132
|
-
store.getState().openDocument(mockDoc);
|
|
133
|
-
store.getState().openDocument(mockDoc2);
|
|
134
|
-
store.getState().openDocument(mockDoc3);
|
|
135
|
-
store.getState().setActiveDocument("/test/file.html");
|
|
136
|
-
store.getState().closeDocument("/test/file.html");
|
|
137
|
-
expect(store.getState().activeDocumentPath).toBe("/test/third.md");
|
|
138
|
-
expect(store.getState().documentOrder).toEqual([
|
|
139
|
-
"/test/file.md",
|
|
140
|
-
"/test/third.md",
|
|
141
|
-
]);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("setActiveDocument", () => {
|
|
146
|
-
it("sets active document", () => {
|
|
147
|
-
store.getState().openDocument(mockDoc);
|
|
148
|
-
store.getState().openDocument(mockDoc2);
|
|
149
|
-
store.getState().setActiveDocument("/test/file.md");
|
|
150
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.md");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("ignores unknown file paths", () => {
|
|
154
|
-
store.getState().openDocument(mockDoc);
|
|
155
|
-
store.getState().setActiveDocument("/nonexistent.md");
|
|
156
|
-
expect(store.getState().activeDocumentPath).toBe("/test/file.md");
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe("per-document setters default to active doc", () => {
|
|
161
|
-
it("setComments operates on active document", () => {
|
|
162
|
-
store.getState().openDocument(mockDoc);
|
|
163
|
-
store.getState().setComments([mockComment]);
|
|
164
|
-
const docState = store.getState().documents.get("/test/file.md")!;
|
|
165
|
-
expect(docState.comments).toEqual([mockComment]);
|
|
166
|
-
expect(docState.sortedComments).toEqual([mockComment]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("setComments with explicit filePath targets that document", () => {
|
|
170
|
-
store.getState().openDocument(mockDoc);
|
|
171
|
-
store.getState().openDocument(mockDoc2);
|
|
172
|
-
store.getState().setComments([mockComment], "/test/file.html");
|
|
173
|
-
expect(
|
|
174
|
-
store.getState().documents.get("/test/file.html")!.comments,
|
|
175
|
-
).toEqual([mockComment]);
|
|
176
|
-
expect(store.getState().documents.get("/test/file.md")!.comments).toEqual(
|
|
177
|
-
[],
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("sortedComments sorts by startOffset", () => {
|
|
182
|
-
store.getState().openDocument(mockDoc);
|
|
183
|
-
const c1 = { ...mockComment, id: "c1", startOffset: 10 };
|
|
184
|
-
const c2 = { ...mockComment, id: "c2", startOffset: 2 };
|
|
185
|
-
const c3 = { ...mockComment, id: "c3", startOffset: 5 };
|
|
186
|
-
store.getState().setComments([c1, c2, c3]);
|
|
187
|
-
const docState = store.getState().documents.get("/test/file.md")!;
|
|
188
|
-
expect(docState.sortedComments.map((c) => c.id)).toEqual([
|
|
189
|
-
"c2",
|
|
190
|
-
"c3",
|
|
191
|
-
"c1",
|
|
192
|
-
]);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("setSelection operates on active document", () => {
|
|
196
|
-
store.getState().openDocument(mockDoc);
|
|
197
|
-
const sel = { text: "hello", startOffset: 0, endOffset: 5 };
|
|
198
|
-
store.getState().setSelection(sel);
|
|
199
|
-
expect(
|
|
200
|
-
store.getState().documents.get("/test/file.md")!.selection,
|
|
201
|
-
).toEqual(sel);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("setScrollY operates on active document", () => {
|
|
205
|
-
store.getState().openDocument(mockDoc);
|
|
206
|
-
store.getState().setScrollY(150);
|
|
207
|
-
expect(store.getState().documents.get("/test/file.md")!.scrollY).toBe(
|
|
208
|
-
150,
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("setters no-op when no active document", () => {
|
|
213
|
-
// No document opened
|
|
214
|
-
store.getState().setComments([mockComment]);
|
|
215
|
-
// Should not throw, just no-op
|
|
216
|
-
expect(store.getState().documents.size).toBe(0);
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe("getActiveDocumentState", () => {
|
|
221
|
-
it("returns undefined when no active document", () => {
|
|
222
|
-
expect(store.getState().getActiveDocumentState()).toBeUndefined();
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("returns active document state", () => {
|
|
226
|
-
store.getState().openDocument(mockDoc);
|
|
227
|
-
const state = store.getState().getActiveDocumentState();
|
|
228
|
-
expect(state).toBeDefined();
|
|
229
|
-
expect(state!.document.filePath).toBe("/test/file.md");
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe("updateDocumentContent", () => {
|
|
234
|
-
it("updates document content in place", () => {
|
|
235
|
-
store.getState().openDocument(mockDoc);
|
|
236
|
-
store.getState().updateDocumentContent("# Updated");
|
|
237
|
-
expect(
|
|
238
|
-
store.getState().documents.get("/test/file.md")!.document.content,
|
|
239
|
-
).toBe("# Updated");
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
});
|
package/src/store/index.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { createStore, useStore } from "zustand";
|
|
2
|
-
import type { Comment, Document, Selection } from "../types";
|
|
3
|
-
|
|
4
|
-
// ─── Types ───────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
export interface DocumentState {
|
|
7
|
-
document: Document;
|
|
8
|
-
comments: Comment[];
|
|
9
|
-
commentsError: string | null;
|
|
10
|
-
sortedComments: Comment[];
|
|
11
|
-
selection: Selection | null;
|
|
12
|
-
pendingSelectionTop: number | undefined;
|
|
13
|
-
pendingCommentText: string;
|
|
14
|
-
highlightPositions: Record<string, number>;
|
|
15
|
-
documentPositions: Record<string, number>;
|
|
16
|
-
scrollY: number;
|
|
17
|
-
hoveredCommentId: string | undefined;
|
|
18
|
-
reanchorTarget: { commentId: string } | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AppStore {
|
|
22
|
-
// Multi-document state
|
|
23
|
-
documents: Map<string, DocumentState>;
|
|
24
|
-
activeDocumentPath: string | null;
|
|
25
|
-
documentOrder: string[];
|
|
26
|
-
workingDirectory: string | null;
|
|
27
|
-
|
|
28
|
-
// Global actions
|
|
29
|
-
setWorkingDirectory: (dir: string) => void;
|
|
30
|
-
openDocument: (doc: Document, opts?: { active?: boolean }) => void;
|
|
31
|
-
closeDocument: (filePath: string) => void;
|
|
32
|
-
setActiveDocument: (filePath: string) => void;
|
|
33
|
-
|
|
34
|
-
// Per-document setters (default to active doc)
|
|
35
|
-
setComments: (comments: Comment[], filePath?: string) => void;
|
|
36
|
-
setCommentsError: (error: string | null, filePath?: string) => void;
|
|
37
|
-
setSelection: (selection: Selection | null, filePath?: string) => void;
|
|
38
|
-
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
|
-
setScrollY: (y: number, filePath?: string) => void;
|
|
48
|
-
setHoveredCommentId: (id: string | undefined, filePath?: string) => void;
|
|
49
|
-
setReanchorTarget: (
|
|
50
|
-
target: { commentId: string } | null,
|
|
51
|
-
filePath?: string,
|
|
52
|
-
) => void;
|
|
53
|
-
setPendingCommentText: (text: string, filePath?: string) => void;
|
|
54
|
-
updateDocumentContent: (content: string, filePath?: string) => void;
|
|
55
|
-
|
|
56
|
-
// Helpers
|
|
57
|
-
getActiveDocumentState: () => DocumentState | undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
function createInitialDocumentState(doc: Document): DocumentState {
|
|
63
|
-
return {
|
|
64
|
-
document: doc,
|
|
65
|
-
comments: [],
|
|
66
|
-
commentsError: null,
|
|
67
|
-
sortedComments: [],
|
|
68
|
-
selection: null,
|
|
69
|
-
pendingSelectionTop: undefined,
|
|
70
|
-
pendingCommentText: "",
|
|
71
|
-
highlightPositions: {},
|
|
72
|
-
documentPositions: {},
|
|
73
|
-
scrollY: 0,
|
|
74
|
-
hoveredCommentId: undefined,
|
|
75
|
-
reanchorTarget: null,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function sortComments(comments: Comment[]): Comment[] {
|
|
80
|
-
return [...comments].sort((a, b) => a.startOffset - b.startOffset);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ─── Store Factory ───────────────────────────────────────────────────
|
|
84
|
-
|
|
85
|
-
export function createAppStore() {
|
|
86
|
-
return createStore<AppStore>((set, get) => {
|
|
87
|
-
const resolveFilePath = (filePath?: string): string | null =>
|
|
88
|
-
filePath ?? get().activeDocumentPath;
|
|
89
|
-
|
|
90
|
-
const updateDocState = (
|
|
91
|
-
filePath: string,
|
|
92
|
-
updater: (state: DocumentState) => Partial<DocumentState>,
|
|
93
|
-
) => {
|
|
94
|
-
set((prev) => {
|
|
95
|
-
const docState = prev.documents.get(filePath);
|
|
96
|
-
if (!docState) return prev;
|
|
97
|
-
const updates = updater(docState);
|
|
98
|
-
const newDocs = new Map(prev.documents);
|
|
99
|
-
newDocs.set(filePath, { ...docState, ...updates });
|
|
100
|
-
return { documents: newDocs };
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
documents: new Map(),
|
|
106
|
-
activeDocumentPath: null,
|
|
107
|
-
documentOrder: [],
|
|
108
|
-
workingDirectory: null,
|
|
109
|
-
|
|
110
|
-
setWorkingDirectory: (dir) => set({ workingDirectory: dir }),
|
|
111
|
-
|
|
112
|
-
openDocument: (doc, opts) => {
|
|
113
|
-
set((prev) => {
|
|
114
|
-
const active = opts?.active ?? true;
|
|
115
|
-
const nextActive =
|
|
116
|
-
active || !prev.activeDocumentPath
|
|
117
|
-
? doc.filePath
|
|
118
|
-
: prev.activeDocumentPath;
|
|
119
|
-
|
|
120
|
-
if (prev.documents.has(doc.filePath)) {
|
|
121
|
-
const newDocs = new Map(prev.documents);
|
|
122
|
-
const prevDoc = newDocs.get(doc.filePath)!;
|
|
123
|
-
newDocs.set(doc.filePath, {
|
|
124
|
-
...prevDoc,
|
|
125
|
-
document: { ...prevDoc.document, ...doc },
|
|
126
|
-
});
|
|
127
|
-
return {
|
|
128
|
-
documents: newDocs,
|
|
129
|
-
activeDocumentPath: nextActive,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
const newDocs = new Map(prev.documents);
|
|
133
|
-
newDocs.set(doc.filePath, createInitialDocumentState(doc));
|
|
134
|
-
return {
|
|
135
|
-
documents: newDocs,
|
|
136
|
-
activeDocumentPath: nextActive,
|
|
137
|
-
documentOrder: [...prev.documentOrder, doc.filePath],
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
closeDocument: (filePath) => {
|
|
143
|
-
set((prev) => {
|
|
144
|
-
const newDocs = new Map(prev.documents);
|
|
145
|
-
newDocs.delete(filePath);
|
|
146
|
-
const newOrder = prev.documentOrder.filter((p) => p !== filePath);
|
|
147
|
-
|
|
148
|
-
let newActive = prev.activeDocumentPath;
|
|
149
|
-
if (prev.activeDocumentPath === filePath) {
|
|
150
|
-
const oldIndex = prev.documentOrder.indexOf(filePath);
|
|
151
|
-
newActive = newOrder[oldIndex] ?? newOrder[oldIndex - 1] ?? null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
documents: newDocs,
|
|
156
|
-
activeDocumentPath: newActive,
|
|
157
|
-
documentOrder: newOrder,
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
setActiveDocument: (filePath) => {
|
|
163
|
-
if (get().documents.has(filePath)) {
|
|
164
|
-
set({ activeDocumentPath: filePath });
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
setComments: (comments, filePath?) => {
|
|
169
|
-
const path = resolveFilePath(filePath);
|
|
170
|
-
if (!path) return;
|
|
171
|
-
updateDocState(path, () => ({
|
|
172
|
-
comments,
|
|
173
|
-
sortedComments: sortComments(comments),
|
|
174
|
-
}));
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
setCommentsError: (error, filePath?) => {
|
|
178
|
-
const path = resolveFilePath(filePath);
|
|
179
|
-
if (!path) return;
|
|
180
|
-
updateDocState(path, () => ({ commentsError: error }));
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
setSelection: (selection, filePath?) => {
|
|
184
|
-
const path = resolveFilePath(filePath);
|
|
185
|
-
if (!path) return;
|
|
186
|
-
updateDocState(path, () => ({ selection }));
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
setPendingSelectionTop: (top, filePath?) => {
|
|
190
|
-
const path = resolveFilePath(filePath);
|
|
191
|
-
if (!path) return;
|
|
192
|
-
updateDocState(path, () => ({ pendingSelectionTop: top }));
|
|
193
|
-
},
|
|
194
|
-
|
|
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
|
-
setScrollY: (y, filePath?) => {
|
|
208
|
-
const path = resolveFilePath(filePath);
|
|
209
|
-
if (!path) return;
|
|
210
|
-
updateDocState(path, () => ({ scrollY: y }));
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
setHoveredCommentId: (id, filePath?) => {
|
|
214
|
-
const path = resolveFilePath(filePath);
|
|
215
|
-
if (!path) return;
|
|
216
|
-
updateDocState(path, () => ({ hoveredCommentId: id }));
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
setReanchorTarget: (target, filePath?) => {
|
|
220
|
-
const path = resolveFilePath(filePath);
|
|
221
|
-
if (!path) return;
|
|
222
|
-
updateDocState(path, () => ({ reanchorTarget: target }));
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
setPendingCommentText: (text, filePath?) => {
|
|
226
|
-
const path = resolveFilePath(filePath);
|
|
227
|
-
if (!path) return;
|
|
228
|
-
updateDocState(path, () => ({ pendingCommentText: text }));
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
updateDocumentContent: (content, filePath?) => {
|
|
232
|
-
const path = resolveFilePath(filePath);
|
|
233
|
-
if (!path) return;
|
|
234
|
-
updateDocState(path, (s) => ({
|
|
235
|
-
document: { ...s.document, content },
|
|
236
|
-
}));
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
getActiveDocumentState: () => {
|
|
240
|
-
const { documents, activeDocumentPath } = get();
|
|
241
|
-
if (!activeDocumentPath) return undefined;
|
|
242
|
-
return documents.get(activeDocumentPath);
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ─── Singleton + React Hook ─────────────────────────────────────────
|
|
249
|
-
|
|
250
|
-
export const appStore = createAppStore();
|
|
251
|
-
|
|
252
|
-
export function useAppStore<T>(selector: (state: AppStore) => T): T {
|
|
253
|
-
return useStore(appStore, selector);
|
|
254
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// Anchor confidence levels - const object pattern per style guide 6.3
|
|
2
|
-
export const AnchorConfidences = {
|
|
3
|
-
EXACT: "exact",
|
|
4
|
-
NORMALIZED: "normalized",
|
|
5
|
-
FUZZY: "fuzzy",
|
|
6
|
-
UNRESOLVED: "unresolved",
|
|
7
|
-
} as const;
|
|
8
|
-
|
|
9
|
-
export type AnchorConfidence =
|
|
10
|
-
(typeof AnchorConfidences)[keyof typeof AnchorConfidences];
|
|
11
|
-
|
|
12
|
-
// Subset excluding "unresolved" for resolved anchors
|
|
13
|
-
export type ResolvedAnchorConfidence = Exclude<
|
|
14
|
-
AnchorConfidence,
|
|
15
|
-
typeof AnchorConfidences.UNRESOLVED
|
|
16
|
-
>;
|
|
17
|
-
|
|
18
|
-
export interface Comment {
|
|
19
|
-
id: string;
|
|
20
|
-
selectedText: string;
|
|
21
|
-
comment: string;
|
|
22
|
-
createdAt: string;
|
|
23
|
-
// Position info for highlighting
|
|
24
|
-
startOffset: number;
|
|
25
|
-
endOffset: number;
|
|
26
|
-
// Line hint for text-based anchoring (e.g., "L42" or "L42-45")
|
|
27
|
-
lineHint?: string;
|
|
28
|
-
// Confidence level of anchor resolution
|
|
29
|
-
anchorConfidence?: AnchorConfidence;
|
|
30
|
-
// First N chars of original text for anchor matching when selectedText is truncated
|
|
31
|
-
anchorPrefix?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Parsed comment file structure
|
|
35
|
-
export interface CommentFile {
|
|
36
|
-
source: string; // Absolute path to source file
|
|
37
|
-
hash: string; // SHA-256 prefix (16 chars) of source content
|
|
38
|
-
version: number; // Format version
|
|
39
|
-
comments: Comment[];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Anchor match result
|
|
43
|
-
export interface Anchor {
|
|
44
|
-
start: number;
|
|
45
|
-
end: number;
|
|
46
|
-
line: number;
|
|
47
|
-
confidence: ResolvedAnchorConfidence;
|
|
48
|
-
distance?: number; // Levenshtein distance for fuzzy matches
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface SelectionRange {
|
|
52
|
-
startOffset: number;
|
|
53
|
-
endOffset: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface Selection extends SelectionRange {
|
|
57
|
-
text: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type DocumentType = "markdown" | "html";
|
|
61
|
-
|
|
62
|
-
export interface Document {
|
|
63
|
-
content: string;
|
|
64
|
-
type: DocumentType;
|
|
65
|
-
filePath: string;
|
|
66
|
-
fileName: string;
|
|
67
|
-
clean: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Editor scheme options - const object pattern per style guide 6.3
|
|
71
|
-
export const EditorSchemes = {
|
|
72
|
-
NONE: "none",
|
|
73
|
-
VSCODE: "vscode",
|
|
74
|
-
VSCODE_INSIDERS: "vscode-insiders",
|
|
75
|
-
CURSOR: "cursor",
|
|
76
|
-
} as const;
|
|
77
|
-
|
|
78
|
-
export type EditorScheme = (typeof EditorSchemes)[keyof typeof EditorSchemes];
|
|
79
|
-
|
|
80
|
-
// Font family options - const object pattern per style guide 6.3
|
|
81
|
-
export const FontFamilies = {
|
|
82
|
-
SERIF: "serif",
|
|
83
|
-
SANS_SERIF: "sans-serif",
|
|
84
|
-
} as const;
|
|
85
|
-
|
|
86
|
-
export type FontFamily = (typeof FontFamilies)[keyof typeof FontFamilies];
|
|
87
|
-
|
|
88
|
-
// Theme mode options - const object pattern per style guide 6.3
|
|
89
|
-
export const ThemeModes = {
|
|
90
|
-
LIGHT: "light",
|
|
91
|
-
DARK: "dark",
|
|
92
|
-
SYSTEM: "system",
|
|
93
|
-
} as const;
|
|
94
|
-
|
|
95
|
-
export type ThemeMode = (typeof ThemeModes)[keyof typeof ThemeModes];
|
|
96
|
-
|
|
97
|
-
// Layout mode options - const object pattern per style guide 6.3
|
|
98
|
-
export const LayoutModes = {
|
|
99
|
-
CENTERED: "centered",
|
|
100
|
-
FULLSCREEN: "fullscreen",
|
|
101
|
-
} as const;
|
|
102
|
-
|
|
103
|
-
export type LayoutMode = (typeof LayoutModes)[keyof typeof LayoutModes];
|
|
104
|
-
|
|
105
|
-
// Keyboard shortcut binding
|
|
106
|
-
export interface ShortcutBinding {
|
|
107
|
-
key: string; // KeyboardEvent.key value, e.g. "c", "ArrowUp"
|
|
108
|
-
alt?: boolean;
|
|
109
|
-
meta?: boolean; // ⌘ on Mac, Ctrl on Windows/Linux
|
|
110
|
-
shift?: boolean;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// User override for a shortcut
|
|
114
|
-
export interface KeybindingOverride {
|
|
115
|
-
id: string;
|
|
116
|
-
binding?: ShortcutBinding; // undefined = use default
|
|
117
|
-
enabled: boolean;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Document settings stored per-file
|
|
121
|
-
export interface DocumentSettings {
|
|
122
|
-
version: number;
|
|
123
|
-
fontFamily: FontFamily;
|
|
124
|
-
editorScheme?: EditorScheme;
|
|
125
|
-
keybindings?: KeybindingOverride[];
|
|
126
|
-
onboarded?: boolean;
|
|
127
|
-
}
|