@peaske7/readit 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/biome.json +1 -1
- package/bun.lock +43 -185
- package/docs/perf-baseline.md +75 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/e2e/perf/add-comment.spec.ts +118 -0
- package/e2e/perf/fixtures/generate.ts +331 -0
- package/e2e/perf/initial-load.spec.ts +49 -0
- package/e2e/perf/perf.setup.ts +23 -0
- package/e2e/perf/perf.teardown.ts +9 -0
- package/e2e/perf/scroll.spec.ts +39 -0
- package/e2e/perf/tab-switch.spec.ts +69 -0
- package/e2e/perf/text-selection.spec.ts +119 -0
- package/e2e/perf/utils/metrics.ts +286 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/package.json +9 -18
- package/playwright.config.ts +12 -0
- package/src/App.tsx +124 -172
- package/src/{cli/index.ts → cli.ts} +37 -53
- package/src/components/ActionsMenu.tsx +6 -27
- package/src/components/DocumentViewer/DocumentViewer.tsx +77 -106
- package/src/components/DocumentViewer/MermaidDiagram.tsx +6 -7
- package/src/components/Header.tsx +9 -20
- package/src/components/InlineEditor.tsx +5 -5
- package/src/components/MarginNote.tsx +71 -93
- package/src/components/MarginNotes.tsx +7 -34
- package/src/components/RawModal.tsx +9 -8
- package/src/components/ReanchorConfirm.tsx +2 -2
- package/src/components/SettingsModal.tsx +11 -89
- package/src/components/TabBar.tsx +4 -4
- package/src/components/TableOfContents.tsx +5 -5
- package/src/components/comments/CommentInput.tsx +7 -35
- package/src/components/comments/CommentListItem.tsx +9 -11
- package/src/components/comments/CommentManager.tsx +53 -37
- package/src/components/comments/CommentNav.tsx +14 -14
- package/src/components/ui/ActionLink.tsx +14 -18
- package/src/components/ui/Button.tsx +42 -43
- package/src/components/ui/Dialog.tsx +73 -113
- package/src/components/ui/DropdownMenu.tsx +113 -69
- package/src/components/ui/Text.tsx +30 -37
- package/src/contexts/CommentContext.tsx +75 -106
- package/src/contexts/LocaleContext.tsx +45 -4
- package/src/contexts/PositionsContext.tsx +16 -0
- package/src/contexts/SettingsContext.tsx +133 -0
- package/src/hooks/useClickOutside.ts +0 -4
- package/src/hooks/useCommentNavigation.ts +6 -29
- package/src/hooks/useComments.ts +6 -18
- package/src/hooks/useDocument.ts +35 -34
- package/src/hooks/useHeadings.test.ts +8 -50
- package/src/hooks/useHeadings.ts +5 -88
- package/src/hooks/useScrollSpy.ts +10 -14
- package/src/hooks/useTextSelection.ts +1 -38
- package/src/lib/__fixtures__/bench-data.ts +1 -41
- package/src/lib/anchor.bench.ts +57 -67
- package/src/lib/anchor.test.ts +5 -1
- package/src/lib/anchor.ts +13 -93
- package/src/lib/comment-storage.test.ts +4 -4
- package/src/lib/comment-storage.ts +2 -46
- package/src/lib/export.ts +7 -13
- package/src/lib/highlight/core.test.ts +1 -1
- package/src/lib/highlight/dom.ts +5 -68
- package/src/lib/highlight/highlighter.ts +102 -262
- package/src/lib/highlight/resolver.ts +112 -0
- package/src/lib/highlight/types.ts +0 -35
- package/src/lib/highlight/worker.ts +45 -0
- package/src/lib/i18n/en.ts +1 -50
- package/src/lib/i18n/ja.ts +1 -50
- package/src/lib/i18n/types.ts +1 -49
- package/src/lib/margin-layout.ts +5 -27
- package/src/lib/positions.ts +150 -0
- package/src/lib/utils.ts +2 -19
- package/src/schema.ts +81 -0
- package/src/{server/index.ts → server.ts} +74 -74
- package/src/{store/index.ts → store.ts} +14 -46
- package/vite.config.ts +8 -0
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- package/src/hooks/useKeybindings.ts +0 -108
- package/src/hooks/useKeyboardShortcuts.ts +0 -63
- package/src/hooks/useLayoutMode.ts +0 -44
- package/src/hooks/useLocalePreference.ts +0 -42
- package/src/hooks/useReanchorMode.ts +0 -33
- package/src/hooks/useScrollMetrics.ts +0 -56
- package/src/hooks/useThemePreference.ts +0 -66
- package/src/lib/comment-storage.bench.ts +0 -63
- package/src/lib/context.bench.ts +0 -41
- package/src/lib/context.test.ts +0 -224
- package/src/lib/context.ts +0 -193
- package/src/lib/editor-links.ts +0 -59
- package/src/lib/export.bench.ts +0 -35
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/core.ts +0 -54
- package/src/lib/highlight/index.ts +0 -23
- package/src/lib/highlight/script-builder.ts +0 -485
- package/src/lib/html-processor.test.tsx +0 -170
- package/src/lib/html-processor.tsx +0 -95
- package/src/lib/i18n/completeness.test.ts +0 -51
- package/src/lib/i18n/translations.test.ts +0 -39
- package/src/lib/layout-constants.ts +0 -12
- package/src/lib/margin-layout.bench.ts +0 -28
- package/src/lib/scroll.test.ts +0 -118
- package/src/lib/scroll.ts +0 -47
- package/src/lib/shortcut-registry.test.ts +0 -173
- package/src/lib/shortcut-registry.ts +0 -209
- package/src/lib/utils.test.ts +0 -110
- package/src/store/index.test.ts +0 -242
- package/src/types/index.ts +0 -127
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import type { KeybindingOverride, ShortcutBinding } from "../types";
|
|
2
|
-
|
|
3
|
-
export type { KeybindingOverride, ShortcutBinding };
|
|
4
|
-
|
|
5
|
-
export const ShortcutActions = {
|
|
6
|
-
COPY_ALL: "copyAll",
|
|
7
|
-
COPY_ALL_RAW: "copyAllRaw",
|
|
8
|
-
NAVIGATE_NEXT: "navigateNext",
|
|
9
|
-
NAVIGATE_PREVIOUS: "navigatePrevious",
|
|
10
|
-
COPY_SELECTION_RAW: "copySelectionRaw",
|
|
11
|
-
COPY_SELECTION_LLM: "copySelectionLLM",
|
|
12
|
-
CLEAR_SELECTION: "clearSelection",
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
export type ShortcutAction =
|
|
16
|
-
(typeof ShortcutActions)[keyof typeof ShortcutActions];
|
|
17
|
-
|
|
18
|
-
export interface ShortcutDefinition {
|
|
19
|
-
id: ShortcutAction;
|
|
20
|
-
label: string;
|
|
21
|
-
description: string;
|
|
22
|
-
defaultBinding: ShortcutBinding;
|
|
23
|
-
binding: ShortcutBinding; // resolved (default or user override)
|
|
24
|
-
enabled: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const DEFAULT_SHORTCUTS: ShortcutDefinition[] = [
|
|
28
|
-
{
|
|
29
|
-
id: ShortcutActions.COPY_ALL,
|
|
30
|
-
label: "Copy All (AI)",
|
|
31
|
-
description: "Copy all comments in AI prompt format",
|
|
32
|
-
defaultBinding: { key: "c", alt: true },
|
|
33
|
-
binding: { key: "c", alt: true },
|
|
34
|
-
enabled: true,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: ShortcutActions.COPY_ALL_RAW,
|
|
38
|
-
label: "Copy All (Raw)",
|
|
39
|
-
description: "Copy all comments as raw text",
|
|
40
|
-
defaultBinding: { key: "c", alt: true, shift: true },
|
|
41
|
-
binding: { key: "c", alt: true, shift: true },
|
|
42
|
-
enabled: true,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: ShortcutActions.NAVIGATE_NEXT,
|
|
46
|
-
label: "Next Comment",
|
|
47
|
-
description: "Navigate to next comment",
|
|
48
|
-
defaultBinding: { key: "ArrowDown", alt: true },
|
|
49
|
-
binding: { key: "ArrowDown", alt: true },
|
|
50
|
-
enabled: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: ShortcutActions.NAVIGATE_PREVIOUS,
|
|
54
|
-
label: "Previous Comment",
|
|
55
|
-
description: "Navigate to previous comment",
|
|
56
|
-
defaultBinding: { key: "ArrowUp", alt: true },
|
|
57
|
-
binding: { key: "ArrowUp", alt: true },
|
|
58
|
-
enabled: true,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: ShortcutActions.COPY_SELECTION_RAW,
|
|
62
|
-
label: "Copy Selection",
|
|
63
|
-
description: "Copy selected text",
|
|
64
|
-
defaultBinding: { key: "c", meta: true },
|
|
65
|
-
binding: { key: "c", meta: true },
|
|
66
|
-
enabled: true,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: ShortcutActions.COPY_SELECTION_LLM,
|
|
70
|
-
label: "Copy Selection (LLM)",
|
|
71
|
-
description: "Copy selected text with context for LLM",
|
|
72
|
-
defaultBinding: { key: "c", meta: true, shift: true },
|
|
73
|
-
binding: { key: "c", meta: true, shift: true },
|
|
74
|
-
enabled: true,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: ShortcutActions.CLEAR_SELECTION,
|
|
78
|
-
label: "Clear Selection",
|
|
79
|
-
description: "Clear text selection",
|
|
80
|
-
defaultBinding: { key: "Escape" },
|
|
81
|
-
binding: { key: "Escape" },
|
|
82
|
-
enabled: true,
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Check if a KeyboardEvent matches a ShortcutBinding.
|
|
88
|
-
* All modifier flags must match exactly (no extra modifiers allowed).
|
|
89
|
-
*/
|
|
90
|
-
export function matchesBinding(
|
|
91
|
-
event: KeyboardEvent,
|
|
92
|
-
binding: ShortcutBinding,
|
|
93
|
-
): boolean {
|
|
94
|
-
if (event.key.toLowerCase() !== binding.key.toLowerCase()) return false;
|
|
95
|
-
if (event.altKey !== (binding.alt ?? false)) return false;
|
|
96
|
-
if (event.metaKey !== (binding.meta ?? false)) return false;
|
|
97
|
-
if (event.shiftKey !== (binding.shift ?? false)) return false;
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const KEY_DISPLAY: Record<string, string> = {
|
|
102
|
-
ArrowUp: "↑",
|
|
103
|
-
ArrowDown: "↓",
|
|
104
|
-
ArrowLeft: "←",
|
|
105
|
-
ArrowRight: "→",
|
|
106
|
-
Escape: "Esc",
|
|
107
|
-
" ": "Space",
|
|
108
|
-
Enter: "Enter",
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Format a ShortcutBinding for display.
|
|
113
|
-
* Shows ⌘ on Mac, Ctrl on other platforms.
|
|
114
|
-
*/
|
|
115
|
-
export function formatBinding(
|
|
116
|
-
binding: ShortcutBinding,
|
|
117
|
-
isMac: boolean,
|
|
118
|
-
): string {
|
|
119
|
-
const parts: string[] = [];
|
|
120
|
-
|
|
121
|
-
if (binding.meta) parts.push(isMac ? "⌘" : "Ctrl");
|
|
122
|
-
if (binding.alt) parts.push("Alt");
|
|
123
|
-
if (binding.shift) parts.push("Shift");
|
|
124
|
-
|
|
125
|
-
const keyDisplay = KEY_DISPLAY[binding.key] ?? binding.key.toUpperCase();
|
|
126
|
-
parts.push(keyDisplay);
|
|
127
|
-
|
|
128
|
-
return parts.join("+");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Merge user overrides with default shortcuts.
|
|
133
|
-
* Unknown override IDs are ignored.
|
|
134
|
-
*/
|
|
135
|
-
export function resolveShortcuts(
|
|
136
|
-
overrides: KeybindingOverride[],
|
|
137
|
-
): ShortcutDefinition[] {
|
|
138
|
-
if (overrides.length === 0) return DEFAULT_SHORTCUTS;
|
|
139
|
-
|
|
140
|
-
const overrideMap = new Map(overrides.map((o) => [o.id, o]));
|
|
141
|
-
|
|
142
|
-
return DEFAULT_SHORTCUTS.map((shortcut) => {
|
|
143
|
-
const override = overrideMap.get(shortcut.id);
|
|
144
|
-
if (!override) return shortcut;
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
...shortcut,
|
|
148
|
-
binding: override.binding ?? shortcut.defaultBinding,
|
|
149
|
-
enabled: override.enabled,
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Browser-reserved key combos that cannot be rebound.
|
|
156
|
-
*/
|
|
157
|
-
export const RESERVED_BINDINGS: ShortcutBinding[] = [
|
|
158
|
-
{ key: "w", meta: true },
|
|
159
|
-
{ key: "t", meta: true },
|
|
160
|
-
{ key: "n", meta: true },
|
|
161
|
-
{ key: "q", meta: true },
|
|
162
|
-
{ key: "l", meta: true },
|
|
163
|
-
{ key: "r", meta: true },
|
|
164
|
-
{ key: "F5" },
|
|
165
|
-
{ key: "F11" },
|
|
166
|
-
{ key: "F12" },
|
|
167
|
-
];
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Check if a binding conflicts with browser-reserved shortcuts.
|
|
171
|
-
*/
|
|
172
|
-
export function isReservedBinding(binding: ShortcutBinding): boolean {
|
|
173
|
-
return RESERVED_BINDINGS.some(
|
|
174
|
-
(reserved) =>
|
|
175
|
-
reserved.key.toLowerCase() === binding.key.toLowerCase() &&
|
|
176
|
-
(reserved.meta ?? false) === (binding.meta ?? false) &&
|
|
177
|
-
(reserved.alt ?? false) === (binding.alt ?? false) &&
|
|
178
|
-
(reserved.shift ?? false) === (binding.shift ?? false),
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Convert a KeyboardEvent to a ShortcutBinding (for the capture UI).
|
|
184
|
-
*/
|
|
185
|
-
export function eventToBinding(
|
|
186
|
-
event: KeyboardEvent,
|
|
187
|
-
): ShortcutBinding | undefined {
|
|
188
|
-
// Ignore standalone modifier keys
|
|
189
|
-
if (["Alt", "Shift", "Control", "Meta"].includes(event.key)) return undefined;
|
|
190
|
-
|
|
191
|
-
const binding: ShortcutBinding = { key: event.key };
|
|
192
|
-
if (event.altKey) binding.alt = true;
|
|
193
|
-
if (event.metaKey) binding.meta = true;
|
|
194
|
-
if (event.shiftKey) binding.shift = true;
|
|
195
|
-
|
|
196
|
-
return binding;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Check if two bindings are equal.
|
|
201
|
-
*/
|
|
202
|
-
export function bindingsEqual(a: ShortcutBinding, b: ShortcutBinding): boolean {
|
|
203
|
-
return (
|
|
204
|
-
a.key.toLowerCase() === b.key.toLowerCase() &&
|
|
205
|
-
(a.alt ?? false) === (b.alt ?? false) &&
|
|
206
|
-
(a.meta ?? false) === (b.meta ?? false) &&
|
|
207
|
-
(a.shift ?? false) === (b.shift ?? false)
|
|
208
|
-
);
|
|
209
|
-
}
|
package/src/lib/utils.test.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { getTextContent, slugify } from "./utils";
|
|
4
|
-
|
|
5
|
-
describe("slugify", () => {
|
|
6
|
-
it("converts text to lowercase", () => {
|
|
7
|
-
expect(slugify("Hello World")).toBe("hello-world");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("replaces spaces with hyphens", () => {
|
|
11
|
-
expect(slugify("hello world")).toBe("hello-world");
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("removes special characters", () => {
|
|
15
|
-
expect(slugify("Hello, World!")).toBe("hello-world");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("handles multiple spaces", () => {
|
|
19
|
-
expect(slugify("hello world")).toBe("hello-world");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("handles leading/trailing whitespace", () => {
|
|
23
|
-
expect(slugify(" hello world ")).toBe("hello-world");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("preserves underscores", () => {
|
|
27
|
-
expect(slugify("hello_world")).toBe("hello_world");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("handles hyphens", () => {
|
|
31
|
-
expect(slugify("hello-world")).toBe("hello-world");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("collapses multiple hyphens", () => {
|
|
35
|
-
expect(slugify("hello---world")).toBe("hello-world");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("getTextContent", () => {
|
|
40
|
-
it("returns string children directly", () => {
|
|
41
|
-
expect(getTextContent("Hello")).toBe("Hello");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("converts number children to string", () => {
|
|
45
|
-
expect(getTextContent(123)).toBe("123");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("joins array of strings", () => {
|
|
49
|
-
expect(getTextContent(["Hello", " ", "World"])).toBe("Hello World");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("extracts text from React element", () => {
|
|
53
|
-
const element = createElement("strong", null, "Bold");
|
|
54
|
-
expect(getTextContent(element)).toBe("Bold");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("extracts text from nested React elements", () => {
|
|
58
|
-
const element = createElement(
|
|
59
|
-
"span",
|
|
60
|
-
null,
|
|
61
|
-
"Hello ",
|
|
62
|
-
createElement("strong", null, "World"),
|
|
63
|
-
);
|
|
64
|
-
expect(getTextContent(element)).toBe("Hello World");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("handles mixed array of strings and elements", () => {
|
|
68
|
-
const children = ["Hello ", createElement("strong", null, "World"), "!"];
|
|
69
|
-
expect(getTextContent(children)).toBe("Hello World!");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("handles deeply nested elements", () => {
|
|
73
|
-
const element = createElement(
|
|
74
|
-
"div",
|
|
75
|
-
null,
|
|
76
|
-
createElement("span", null, createElement("strong", null, "Deep")),
|
|
77
|
-
);
|
|
78
|
-
expect(getTextContent(element)).toBe("Deep");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("returns empty string for null", () => {
|
|
82
|
-
expect(getTextContent(null)).toBe("");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("returns empty string for undefined", () => {
|
|
86
|
-
expect(getTextContent(undefined)).toBe("");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("returns empty string for boolean", () => {
|
|
90
|
-
expect(getTextContent(true)).toBe("");
|
|
91
|
-
expect(getTextContent(false)).toBe("");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("handles markdown-style inline formatting", () => {
|
|
95
|
-
// Simulates what react-markdown produces for "## Hello **World**"
|
|
96
|
-
const children = ["Hello ", createElement("strong", null, "World")];
|
|
97
|
-
expect(getTextContent(children)).toBe("Hello World");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("handles complex markdown with multiple formatting", () => {
|
|
101
|
-
// Simulates "## Hello **World** and _italic_"
|
|
102
|
-
const children = [
|
|
103
|
-
"Hello ",
|
|
104
|
-
createElement("strong", null, "World"),
|
|
105
|
-
" and ",
|
|
106
|
-
createElement("em", null, "italic"),
|
|
107
|
-
];
|
|
108
|
-
expect(getTextContent(children)).toBe("Hello World and italic");
|
|
109
|
-
});
|
|
110
|
-
});
|
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/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
|
-
}
|