markshelf 0.1.4 → 0.1.5

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 (155) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-path-routes-manifest.json +1 -0
  3. package/.next/standalone/.next/build-manifest.json +3 -3
  4. package/.next/standalone/.next/prerender-manifest.json +3 -3
  5. package/.next/standalone/.next/routes-manifest.json +6 -0
  6. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  14. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  15. package/.next/standalone/.next/server/app/_not-found.rsc +2 -2
  16. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  17. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  19. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  20. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  21. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  22. package/.next/standalone/.next/server/app/api/diff/route.js +3 -2
  23. package/.next/standalone/.next/server/app/api/diff/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/file/route.js +3 -2
  25. package/.next/standalone/.next/server/app/api/file/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/graph/route.js +3 -2
  27. package/.next/standalone/.next/server/app/api/graph/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/history/route.js +3 -2
  29. package/.next/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/search/route.js +3 -2
  31. package/.next/standalone/.next/server/app/api/search/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/timeline/route.js +3 -2
  33. package/.next/standalone/.next/server/app/api/timeline/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/tree/route.js +3 -2
  35. package/.next/standalone/.next/server/app/api/tree/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/watch/route/app-paths-manifest.json +3 -0
  37. package/.next/standalone/.next/server/app/api/watch/route/build-manifest.json +9 -0
  38. package/.next/standalone/.next/server/app/api/watch/route/server-reference-manifest.json +4 -0
  39. package/.next/standalone/.next/server/app/api/watch/route.js +6 -0
  40. package/.next/standalone/.next/server/app/api/watch/route.js.map +5 -0
  41. package/.next/standalone/.next/server/app/api/watch/route.js.nft.json +1 -0
  42. package/.next/standalone/.next/server/app/api/watch/route_client-reference-manifest.js +3 -0
  43. package/.next/standalone/.next/server/app/favicon.ico/route.js +2 -1
  44. package/.next/standalone/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/index.html +1 -1
  46. package/.next/standalone/.next/server/app/index.rsc +3 -3
  47. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  48. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +3 -3
  49. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  50. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  51. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  52. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  54. package/.next/standalone/.next/server/app-paths-manifest.json +1 -0
  55. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0-_k816._.js +3 -0
  56. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__04otwp7._.js → [root-of-the-server]__01e7zo7._.js} +2 -2
  57. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0zoyna0._.js → [root-of-the-server]__053gm34._.js} +2 -2
  58. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0_gt~a4._.js → [root-of-the-server]__0d.-s5p._.js} +2 -2
  59. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0i.wyss._.js +6 -0
  60. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0qnrcw7._.js → [root-of-the-server]__0nr71d2._.js} +2 -2
  61. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0op9af~._.js +3 -0
  62. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__01cq2u6._.js → [root-of-the-server]__0rwylex._.js} +2 -2
  63. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0yvq0sd._.js → [root-of-the-server]__13vatcq._.js} +2 -2
  64. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_watch_route_actions_0go0kk3.js +3 -0
  65. package/.next/standalone/.next/server/chunks/node_modules_next_04~_e52._.js +13 -0
  66. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__05ar4zx._.js +2 -2
  67. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__09qrkq5._.js +5 -5
  68. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0serya4._.js → [root-of-the-server]__11e9~iq._.js} +2 -2
  69. package/.next/standalone/.next/server/chunks/ssr/{node_modules_10cz306._.js → node_modules_02chd8n._.js} +1 -1
  70. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0eva9q1._.js → node_modules_08z1b9i._.js} +1 -1
  71. package/.next/standalone/.next/server/chunks/ssr/{node_modules_05e-8m3._.js → node_modules_0f-9xhq._.js} +1 -1
  72. package/.next/standalone/.next/server/chunks/ssr/{node_modules_06r3o30._.js → node_modules_0u-.0s2._.js} +1 -1
  73. package/.next/standalone/.next/server/chunks/ssr/{node_modules_09.cbx4._.js → node_modules_0vqo_80._.js} +1 -1
  74. package/.next/standalone/.next/server/chunks/ssr/{node_modules_11wp0ye._.js → node_modules_0xmn29o._.js} +1 -1
  75. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0ic-wja._.js → node_modules_0~k33bz._.js} +1 -1
  76. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0w2-q.z._.js → node_modules_10a06qi._.js} +1 -1
  77. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  78. package/.next/standalone/.next/server/pages/404.html +1 -1
  79. package/.next/standalone/.next/server/pages/500.html +1 -1
  80. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  81. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  82. package/.next/standalone/.next/static/chunks/0b42--.p9znhl.css +1 -0
  83. package/.next/standalone/.next/static/chunks/0wy.nfhujao0b.js +11 -0
  84. package/.next/standalone/docs//344/273/225/346/247/230/README.md +9 -0
  85. package/.next/standalone/docs//344/273/225/346/247/230/SPEC1-CLI/README.md +3 -0
  86. package/.next/standalone/docs//344/273/225/346/247/230/SPEC1-CLI/SPEC1.1-bin-cli.md +14 -0
  87. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/README.md +3 -0
  88. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/SPEC2.1-graph-api.md +16 -0
  89. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/SPEC2.2-breadthfirst-layout.md +10 -0
  90. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/README.md +3 -0
  91. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/SPEC3.1-PreviewPopup.md +10 -0
  92. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/SPEC3.2-TreeView.md +10 -0
  93. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Cytoscape.md +5 -0
  94. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Markdown.md +5 -0
  95. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Nextjs.md +5 -0
  96. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/breadthfirst.md +5 -0
  97. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/npx.md +5 -0
  98. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/standalone.md +5 -0
  99. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/204/343/203/252/343/203/274/343/203/223/343/203/245/343/203/274.md +5 -0
  100. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/203/235/343/203/203/343/203/227/343/202/242/343/203/203/343/203/227.md +5 -0
  101. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225.md +5 -0
  102. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/README.md +9 -0
  103. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ1-/343/203/223/343/203/245/343/203/274/343/202/242/350/265/267/345/213/225/README.md +3 -0
  104. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ1-/343/203/223/343/203/245/343/203/274/343/202/242/350/265/267/345/213/225/REQ1.1-npx/350/265/267/345/213/225.md +13 -0
  105. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/README.md +3 -0
  106. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.1-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273.md +11 -0
  107. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.2-/351/232/216/345/261/244/345/210/207/346/233/277.md +10 -0
  108. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.3-/343/203/225/343/202/251/343/203/253/343/203/200/351/231/244/345/244/226.md +10 -0
  109. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/README.md +3 -0
  110. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/REQ3.1-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/203/235/343/203/203/343/203/227/343/202/242/343/203/203/343/203/227.md +15 -0
  111. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/REQ3.2-/343/203/204/343/203/252/343/203/274/343/203/223/343/203/245/343/203/274.md +14 -0
  112. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ4-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/README.md +3 -0
  113. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ4-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/REQ4.1-/346/210/273/343/202/213/351/200/262/343/202/200.md +10 -0
  114. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.1-/347/213/254/347/253/213/343/203/223/343/203/245/343/203/274/343/202/242.md +11 -0
  115. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.2-/345/244/247/347/224/273/351/235/242/350/241/250/347/244/272.md +11 -0
  116. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.3-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/345/261/245/346/255/264.md +9 -0
  117. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/README.md +7 -0
  118. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/R2.1-/344/276/235/345/255/230/351/226/242/344/277/202/343/201/256/346/212/212/346/217/241.md +9 -0
  119. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/R2.2-/345/217/202/347/205/247/345/205/203/343/201/256/346/212/212/346/217/241.md +9 -0
  120. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/README.md +8 -0
  121. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R3-/343/202/252/343/203/263/343/203/234/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/346/224/257/346/217/264/R3.1-/347/224/250/350/252/236/343/201/256/345/215/263/346/231/202/347/242/272/350/252/215.md +11 -0
  122. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R3-/343/202/252/343/203/263/343/203/234/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/346/224/257/346/217/264/README.md +7 -0
  123. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/README.md +9 -0
  124. package/.next/standalone/package.json +1 -1
  125. package/.next/standalone/src/app/api/watch/route.ts +89 -0
  126. package/.next/standalone/src/app/page.tsx +41 -8
  127. package/.next/standalone/src/components/DetailPanel.tsx +38 -6
  128. package/.next/standalone/src/components/HistoryPanel.tsx +3 -1
  129. package/.next/standalone/src/components/LinkGraph.tsx +179 -9
  130. package/.next/standalone/src/components/Markdown.tsx +60 -5
  131. package/.next/standalone/src/components/PreviewPopup.tsx +4 -2
  132. package/.next/standalone/src/components/TimelinePanel.tsx +3 -1
  133. package/.next/standalone/src/components/TreeView.tsx +36 -9
  134. package/.next/standalone/src/lib/links.ts +98 -25
  135. package/.next/standalone/src/lib/useRefreshTick.ts +43 -0
  136. package/.next/standalone/tsconfig.tsbuildinfo +1 -1
  137. package/.next/static/chunks/0b42--.p9znhl.css +1 -0
  138. package/.next/static/chunks/0wy.nfhujao0b.js +11 -0
  139. package/package.json +1 -1
  140. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0j8-xkl._.js +0 -13
  141. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0owpp0l._.js +0 -3
  142. package/.next/standalone/.next/static/chunks/04x.fjh8sw0s1.css +0 -1
  143. package/.next/standalone/.next/static/chunks/0z_707.y37o2..js +0 -11
  144. package/.next/standalone/AGENTS.md +0 -5
  145. package/.next/standalone/CLAUDE.md +0 -1
  146. package/.next/standalone/markshelf-0.1.0.tgz +0 -0
  147. package/.next/standalone/markshelf-0.1.2.tgz +0 -0
  148. package/.next/static/chunks/04x.fjh8sw0s1.css +0 -1
  149. package/.next/static/chunks/0z_707.y37o2..js +0 -11
  150. /package/.next/standalone/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_buildManifest.js +0 -0
  151. /package/.next/standalone/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_clientMiddlewareManifest.js +0 -0
  152. /package/.next/standalone/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_ssgManifest.js +0 -0
  153. /package/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_buildManifest.js +0 -0
  154. /package/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_clientMiddlewareManifest.js +0 -0
  155. /package/.next/static/{JkyieJgBB2eU8MtnlBGvG → pOQs5i4GMjDH6W5XDSjRs}/_ssgManifest.js +0 -0
@@ -6,17 +6,27 @@ import { HistoryPanel } from "./HistoryPanel";
6
6
  import { TableOfContents, HeadingInfo } from "./TableOfContents";
7
7
  import { PreviewPopup } from "./PreviewPopup";
8
8
  import { LinkGraph } from "./LinkGraph";
9
- import { FileText, History, Network, ArrowLeft } from "lucide-react";
9
+ import { useRefreshTick } from "@/lib/useRefreshTick";
10
+ import { FileText, History, Network, ArrowLeft, ArrowRight } from "lucide-react";
11
+
12
+ interface FolderInfo {
13
+ path: string;
14
+ displayName: string;
15
+ depth: number;
16
+ }
10
17
 
11
18
  interface Props {
12
19
  filePath: string;
13
20
  fileRefs?: FileRef[];
21
+ folders?: FolderInfo[];
14
22
  onNavigate?: (path: string) => void;
15
23
  onGoBack?: () => void;
24
+ onGoForward?: () => void;
16
25
  canGoBack?: boolean;
26
+ canGoForward?: boolean;
17
27
  }
18
28
 
19
- export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBack }: Props) {
29
+ export function DetailPanel({ filePath, fileRefs, folders, onNavigate, onGoBack, onGoForward, canGoBack, canGoForward }: Props) {
20
30
  const [content, setContent] = useState<string | null>(null);
21
31
  const [tab, setTab] = useState<"content" | "history" | "links">("content");
22
32
  const [headings, setHeadings] = useState<HeadingInfo[]>([]);
@@ -35,20 +45,23 @@ export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBac
35
45
  const [previewPos, setPreviewPos] = useState<{ x: number; y: number } | null>(null);
36
46
  const showTimer = useRef<ReturnType<typeof setTimeout>>(null);
37
47
  const hideTimer = useRef<ReturnType<typeof setTimeout>>(null);
48
+ const refreshTick = useRefreshTick();
38
49
 
39
50
  useEffect(() => {
40
51
  setContent(null);
41
52
  setHeadings([]);
42
- // Clear preview popup state and cancel any pending timers on navigation
43
53
  if (showTimer.current) clearTimeout(showTimer.current);
44
54
  if (hideTimer.current) clearTimeout(hideTimer.current);
45
55
  setPreviewPath(null);
46
56
  setPreviewPos(null);
57
+ }, [filePath]);
58
+
59
+ useEffect(() => {
47
60
  fetch(`/api/file?path=${encodeURIComponent(filePath)}`)
48
61
  .then((r) => r.json())
49
62
  .then((data) => setContent(data.content ?? null))
50
63
  .catch(() => setContent(null));
51
- }, [filePath]);
64
+ }, [filePath, refreshTick]);
52
65
 
53
66
  const handlePreviewShow = useCallback((path: string, rect: DOMRect) => {
54
67
  if (hideTimer.current) clearTimeout(hideTimer.current);
@@ -113,6 +126,15 @@ export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBac
113
126
  <ArrowLeft size={14} />
114
127
  </button>
115
128
  )}
129
+ {canGoForward && (
130
+ <button
131
+ onClick={onGoForward}
132
+ className="shrink-0 p-0.5 rounded hover:bg-[var(--bg-muted)] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors"
133
+ title="進む"
134
+ >
135
+ <ArrowRight size={14} />
136
+ </button>
137
+ )}
116
138
  <h2 className="font-semibold text-[14px] leading-snug truncate text-[var(--text-primary)]">
117
139
  {fileName}
118
140
  </h2>
@@ -163,7 +185,10 @@ export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBac
163
185
  onHeadingsExtracted={setHeadings}
164
186
  fileRefs={fileRefs}
165
187
  currentPath={filePath}
166
- onNavigate={onNavigate}
188
+ onNavigate={(p) => {
189
+ setTab("content");
190
+ onNavigate?.(p);
191
+ }}
167
192
  onPreviewShow={handlePreviewShow}
168
193
  onPreviewHide={handlePreviewHide}
169
194
  >
@@ -195,7 +220,13 @@ export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBac
195
220
  </div>
196
221
  ) : (
197
222
  <div className="flex-1 overflow-hidden">
198
- <LinkGraph currentPath={filePath} onNavigate={(p) => onNavigate?.(p)} />
223
+ <LinkGraph
224
+ currentPath={filePath}
225
+ folders={folders ?? []}
226
+ onNavigate={(p) => onNavigate?.(p)}
227
+ onPreviewShow={handlePreviewShow}
228
+ onPreviewHide={handlePreviewHide}
229
+ />
199
230
  </div>
200
231
  )}
201
232
 
@@ -205,6 +236,7 @@ export function DetailPanel({ filePath, fileRefs, onNavigate, onGoBack, canGoBac
205
236
  onNavigate={(p) => {
206
237
  setPreviewPath(null);
207
238
  setPreviewPos(null);
239
+ setTab("content");
208
240
  onNavigate?.(p);
209
241
  }}
210
242
  onMouseEnter={handlePreviewEnter}
@@ -3,6 +3,7 @@
3
3
  import { useEffect, useState } from "react";
4
4
  import { GitCommit, ChevronDown, ChevronRight } from "lucide-react";
5
5
  import { DiffView } from "./DiffView";
6
+ import { useRefreshTick } from "@/lib/useRefreshTick";
6
7
 
7
8
  interface CommitEntry {
8
9
  hash: string;
@@ -20,6 +21,7 @@ export function HistoryPanel({ filePath }: Props) {
20
21
  const [history, setHistory] = useState<CommitEntry[]>([]);
21
22
  const [loading, setLoading] = useState(true);
22
23
  const [expandedHash, setExpandedHash] = useState<string | null>(null);
24
+ const refreshTick = useRefreshTick();
23
25
 
24
26
  useEffect(() => {
25
27
  setLoading(true);
@@ -31,7 +33,7 @@ export function HistoryPanel({ filePath }: Props) {
31
33
  setLoading(false);
32
34
  })
33
35
  .catch(() => setLoading(false));
34
- }, [filePath]);
36
+ }, [filePath, refreshTick]);
35
37
 
36
38
  if (loading) {
37
39
  return <div className="p-4 text-[var(--text-muted)] text-[13px]">読み込み中...</div>;
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useRef, useState } from "react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
4
  import cytoscape from "cytoscape";
5
+ import { useRefreshTick } from "@/lib/useRefreshTick";
6
+ import { Filter } from "lucide-react";
5
7
 
6
8
  interface GraphNode {
7
9
  id: string;
@@ -13,12 +15,23 @@ interface GraphEdge {
13
15
  target: string;
14
16
  }
15
17
 
18
+ interface FolderInfo {
19
+ path: string;
20
+ displayName: string;
21
+ depth: number;
22
+ }
23
+
16
24
  interface Props {
17
25
  currentPath: string;
26
+ folders: FolderInfo[];
18
27
  onNavigate: (path: string) => void;
28
+ onPreviewShow?: (path: string, rect: DOMRect) => void;
29
+ onPreviewHide?: () => void;
19
30
  }
20
31
 
21
32
  const DEPTH_KEY = "markshelf:linkGraphDepth";
33
+ const EXCLUDE_KEY = "markshelf:linkGraphExclude";
34
+ const ZOOM_KEY = "markshelf:linkGraphZoom";
22
35
  const DEPTH_OPTIONS: { value: number; label: string }[] = [
23
36
  { value: 1, label: "1階層" },
24
37
  { value: 2, label: "2階層" },
@@ -26,13 +39,17 @@ const DEPTH_OPTIONS: { value: number; label: string }[] = [
26
39
  { value: Infinity, label: "全階層" },
27
40
  ];
28
41
 
29
- export function LinkGraph({ currentPath, onNavigate }: Props) {
42
+ export function LinkGraph({ currentPath, folders, onNavigate, onPreviewShow, onPreviewHide }: Props) {
30
43
  const containerRef = useRef<HTMLDivElement>(null);
31
44
  const cyRef = useRef<cytoscape.Core | null>(null);
45
+ const filterPopoverRef = useRef<HTMLDivElement>(null);
32
46
  const [loading, setLoading] = useState(true);
33
47
  const [empty, setEmpty] = useState(false);
34
48
  const [ready, setReady] = useState(false);
35
49
  const [depth, setDepth] = useState<number>(1);
50
+ const [excluded, setExcluded] = useState<string[]>([]);
51
+ const [showFilter, setShowFilter] = useState(false);
52
+ const refreshTick = useRefreshTick();
36
53
 
37
54
  useEffect(() => {
38
55
  const saved = localStorage.getItem(DEPTH_KEY);
@@ -41,11 +58,65 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
41
58
  if (Number.isFinite(v) || v === Infinity) setDepth(v);
42
59
  }, []);
43
60
 
61
+ useEffect(() => {
62
+ const saved = localStorage.getItem(EXCLUDE_KEY);
63
+ if (!saved) return;
64
+ try {
65
+ const arr = JSON.parse(saved);
66
+ if (Array.isArray(arr)) setExcluded(arr.filter((s) => typeof s === "string"));
67
+ } catch {
68
+ /* ignore */
69
+ }
70
+ }, []);
71
+
72
+ useEffect(() => {
73
+ if (!showFilter) return;
74
+ const onClick = (e: MouseEvent) => {
75
+ if (filterPopoverRef.current && !filterPopoverRef.current.contains(e.target as Node)) {
76
+ setShowFilter(false);
77
+ }
78
+ };
79
+ document.addEventListener("mousedown", onClick);
80
+ return () => document.removeEventListener("mousedown", onClick);
81
+ }, [showFilter]);
82
+
44
83
  const changeDepth = (d: number) => {
45
84
  setDepth(d);
46
85
  localStorage.setItem(DEPTH_KEY, d === Infinity ? "all" : String(d));
47
86
  };
48
87
 
88
+ const toggleExclude = (folderPath: string) => {
89
+ setExcluded((prev) => {
90
+ const next = prev.includes(folderPath)
91
+ ? prev.filter((p) => p !== folderPath)
92
+ : [...prev, folderPath];
93
+ localStorage.setItem(EXCLUDE_KEY, JSON.stringify(next));
94
+ return next;
95
+ });
96
+ };
97
+
98
+ const isPathExcluded = useMemo(() => {
99
+ const prefixes = excluded.map((f) => f + "/");
100
+ const currentExcluded = excluded.some(
101
+ (f) => currentPath === f || currentPath.startsWith(f + "/"),
102
+ );
103
+ return (p: string): boolean => {
104
+ if (currentExcluded) return false;
105
+ if (p === currentPath) return false;
106
+ return prefixes.some((pre) => p.startsWith(pre));
107
+ };
108
+ }, [excluded, currentPath]);
109
+
110
+ // Latest-callback refs to keep Cytoscape handlers without re-initializing on parent re-renders
111
+ const onNavigateRef = useRef(onNavigate);
112
+ const onPreviewShowRef = useRef(onPreviewShow);
113
+ const onPreviewHideRef = useRef(onPreviewHide);
114
+ useEffect(() => {
115
+ onNavigateRef.current = onNavigate;
116
+ onPreviewShowRef.current = onPreviewShow;
117
+ onPreviewHideRef.current = onPreviewHide;
118
+ });
119
+
49
120
  useEffect(() => {
50
121
  let cancelled = false;
51
122
 
@@ -58,9 +129,15 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
58
129
  .then((data: { nodes: GraphNode[]; edges: GraphEdge[] }) => {
59
130
  if (cancelled || !containerRef.current) return;
60
131
 
132
+ // Apply folder exclusion filter
133
+ const filteredNodes = data.nodes.filter((n) => !isPathExcluded(n.id));
134
+ const filteredEdges = data.edges.filter(
135
+ (e) => !isPathExcluded(e.source) && !isPathExcluded(e.target),
136
+ );
137
+
61
138
  // Show only nodes reachable from currentPath (undirected connected component)
62
139
  const adj = new Map<string, string[]>();
63
- for (const e of data.edges) {
140
+ for (const e of filteredEdges) {
64
141
  (adj.get(e.source) ?? adj.set(e.source, []).get(e.source)!).push(e.target);
65
142
  (adj.get(e.target) ?? adj.set(e.target, []).get(e.target)!).push(e.source);
66
143
  }
@@ -77,8 +154,8 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
77
154
  }
78
155
  }
79
156
 
80
- const localNodes = data.nodes.filter((n) => connectedPaths.has(n.id));
81
- const localEdges = data.edges.filter(
157
+ const localNodes = filteredNodes.filter((n) => connectedPaths.has(n.id));
158
+ const localEdges = filteredEdges.filter(
82
159
  (e) => connectedPaths.has(e.source) && connectedPaths.has(e.target),
83
160
  );
84
161
 
@@ -172,6 +249,7 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
172
249
  directed: true,
173
250
  grid: false,
174
251
  roots: rootPaths.length > 0 ? rootPaths : [currentPath],
252
+ transform: (_node, pos) => ({ x: pos.x, y: -pos.y }),
175
253
  } as cytoscape.BreadthFirstLayoutOptions,
176
254
  userZoomingEnabled: true,
177
255
  userPanningEnabled: true,
@@ -182,12 +260,40 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
182
260
  // Defer fit/center until container has layout dimensions
183
261
  requestAnimationFrame(() => {
184
262
  cy.resize();
185
- cy.fit(undefined, 50);
186
- if (cy.zoom() > 1.2) cy.zoom({ level: 1.2, renderedPosition: { x: containerRef.current!.clientWidth / 2, y: containerRef.current!.clientHeight / 2 } });
263
+ const savedZoom = Number(localStorage.getItem(ZOOM_KEY));
264
+ if (Number.isFinite(savedZoom) && savedZoom > 0) {
265
+ cy.zoom({
266
+ level: savedZoom,
267
+ renderedPosition: {
268
+ x: containerRef.current!.clientWidth / 2,
269
+ y: containerRef.current!.clientHeight / 2,
270
+ },
271
+ });
272
+ } else {
273
+ cy.fit(undefined, 50);
274
+ if (cy.zoom() > 0.9) {
275
+ cy.zoom({
276
+ level: 0.9,
277
+ renderedPosition: {
278
+ x: containerRef.current!.clientWidth / 2,
279
+ y: containerRef.current!.clientHeight / 2,
280
+ },
281
+ });
282
+ }
283
+ }
187
284
  cy.center(cy.nodes("[?isCurrent]"));
188
285
  setReady(true);
189
286
  });
190
287
 
288
+ // Persist zoom level on user interaction (debounced)
289
+ let zoomWriteTimer: ReturnType<typeof setTimeout> | null = null;
290
+ cy.on("zoom", () => {
291
+ if (zoomWriteTimer) clearTimeout(zoomWriteTimer);
292
+ zoomWriteTimer = setTimeout(() => {
293
+ localStorage.setItem(ZOOM_KEY, String(cy.zoom()));
294
+ }, 200);
295
+ });
296
+
191
297
  // Hover effects
192
298
  cy.on("mouseover", "node", (e) => {
193
299
  const node = e.target;
@@ -199,6 +305,26 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
199
305
  });
200
306
  }
201
307
  containerRef.current!.style.cursor = "pointer";
308
+
309
+ const path = node.id();
310
+ if (onPreviewShowRef.current && containerRef.current) {
311
+ const bb = node.renderedBoundingBox();
312
+ const cRect = containerRef.current.getBoundingClientRect();
313
+ const left = cRect.left + bb.x1;
314
+ const top = cRect.top + bb.y1;
315
+ const rect = {
316
+ left,
317
+ top,
318
+ right: cRect.left + bb.x2,
319
+ bottom: cRect.top + bb.y2,
320
+ width: bb.w,
321
+ height: bb.h,
322
+ x: left,
323
+ y: top,
324
+ toJSON: () => ({}),
325
+ } as DOMRect;
326
+ onPreviewShowRef.current(path, rect);
327
+ }
202
328
  });
203
329
 
204
330
  cy.on("mouseout", "node", (e) => {
@@ -211,13 +337,14 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
211
337
  });
212
338
  }
213
339
  containerRef.current!.style.cursor = "default";
340
+ onPreviewHideRef.current?.();
214
341
  });
215
342
 
216
343
  // Click to navigate
217
344
  cy.on("tap", "node", (e) => {
218
345
  const path = e.target.id();
219
346
  if (path !== currentPath) {
220
- onNavigate(path);
347
+ onNavigateRef.current(path);
221
348
  }
222
349
  });
223
350
 
@@ -236,7 +363,7 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
236
363
  cyRef.current?.destroy();
237
364
  cyRef.current = null;
238
365
  };
239
- }, [currentPath, onNavigate, depth]);
366
+ }, [currentPath, depth, isPathExcluded, refreshTick]);
240
367
 
241
368
  return (
242
369
  <div className="h-full flex flex-col relative">
@@ -258,6 +385,49 @@ export function LinkGraph({ currentPath, onNavigate }: Props) {
258
385
  </button>
259
386
  );
260
387
  })}
388
+ <div className="ml-auto relative" ref={filterPopoverRef}>
389
+ <button
390
+ onClick={() => setShowFilter((v) => !v)}
391
+ className={`flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium transition-colors ${
392
+ excluded.length > 0
393
+ ? "bg-[var(--brand-primary)] text-white"
394
+ : "text-[var(--text-muted)] hover:bg-[var(--bg-muted)] hover:text-[var(--text-secondary)]"
395
+ }`}
396
+ title="フォルダを除外"
397
+ >
398
+ <Filter size={11} />
399
+ 除外
400
+ {excluded.length > 0 && <span className="ml-0.5">({excluded.length})</span>}
401
+ </button>
402
+ {showFilter && (
403
+ <div className="absolute right-0 top-full mt-1 w-56 max-h-72 overflow-y-auto bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-md shadow-lg z-20 py-1">
404
+ {folders.length === 0 ? (
405
+ <div className="px-3 py-2 text-[11px] text-[var(--text-muted)]">
406
+ フォルダがありません
407
+ </div>
408
+ ) : (
409
+ folders.map((f) => {
410
+ const checked = excluded.includes(f.path);
411
+ return (
412
+ <label
413
+ key={f.path}
414
+ className="flex items-center gap-2 px-3 py-1 text-[12px] cursor-pointer hover:bg-[var(--bg-muted)]"
415
+ style={{ paddingLeft: `${12 + f.depth * 12}px` }}
416
+ >
417
+ <input
418
+ type="checkbox"
419
+ checked={checked}
420
+ onChange={() => toggleExclude(f.path)}
421
+ className="shrink-0"
422
+ />
423
+ <span className="truncate text-[var(--text-secondary)]">{f.displayName}</span>
424
+ </label>
425
+ );
426
+ })
427
+ )}
428
+ </div>
429
+ )}
430
+ </div>
261
431
  </div>
262
432
  {(loading || empty) && (
263
433
  <div className="absolute inset-0 flex items-center justify-center text-[13px] text-[var(--text-muted)] z-10 bg-[var(--bg-surface)]">
@@ -100,6 +100,53 @@ export function Markdown({
100
100
  return new RegExp(`(${escaped.join("|")})`, "g");
101
101
  }, [autolinkMap]);
102
102
 
103
+ const fileSet = useMemo(
104
+ () => new Set((fileRefs ?? []).map((f) => f.path)),
105
+ [fileRefs],
106
+ );
107
+
108
+ function resolveRelativeLink(href: string): string | null {
109
+ const cleanUrl = href.split("#")[0].split("?")[0].trim();
110
+ if (!cleanUrl) return null;
111
+ if (/^[a-z][a-z0-9+.-]*:/i.test(cleanUrl)) return null;
112
+ if (cleanUrl.startsWith("//")) return null;
113
+
114
+ let decoded: string;
115
+ try {
116
+ decoded = decodeURI(cleanUrl);
117
+ } catch {
118
+ decoded = cleanUrl;
119
+ }
120
+
121
+ const currentDir =
122
+ currentPath && currentPath.includes("/")
123
+ ? currentPath.slice(0, currentPath.lastIndexOf("/"))
124
+ : "";
125
+ const joined = decoded.startsWith("/")
126
+ ? decoded.slice(1)
127
+ : currentDir
128
+ ? currentDir + "/" + decoded
129
+ : decoded;
130
+
131
+ const parts = joined.split("/");
132
+ const normalized: string[] = [];
133
+ for (const p of parts) {
134
+ if (p === "" || p === ".") continue;
135
+ if (p === "..") {
136
+ normalized.pop();
137
+ continue;
138
+ }
139
+ normalized.push(p);
140
+ }
141
+ const resolved = normalized.join("/");
142
+ if (!resolved) return null;
143
+
144
+ if (fileSet.has(resolved)) return resolved;
145
+ if (fileSet.has(resolved + "/README.md")) return resolved + "/README.md";
146
+ if (!/\.md$/i.test(resolved) && fileSet.has(resolved + ".md")) return resolved + ".md";
147
+ return null;
148
+ }
149
+
103
150
  function getIdForHeading(text: string): string {
104
151
  const ids = headingIdMap.get(text);
105
152
  if (!ids) return slugify(text) || "heading";
@@ -153,21 +200,29 @@ export function Markdown({
153
200
  }
154
201
  return <pre>{children}</pre>;
155
202
  },
156
- // Auto-link rendering: intercept <a> with "autolink:" prefix
203
+ // Auto-link rendering: intercept <a> with "autolink:" prefix,
204
+ // and resolve relative markdown links to docs paths so they behave like autolinks.
157
205
  a: ({ href, children: linkChildren, ...rest }) => {
206
+ let targetPath: string | null = null;
158
207
  if (href?.startsWith("autolink:")) {
159
- const targetPath = href.slice("autolink:".length);
208
+ targetPath = href.slice("autolink:".length);
209
+ } else if (href) {
210
+ targetPath = resolveRelativeLink(href);
211
+ }
212
+
213
+ if (targetPath) {
214
+ const resolved = targetPath;
160
215
  return (
161
216
  <span
162
- className="text-[var(--brand-primary)] border-b border-dashed border-[var(--brand-primary)] cursor-pointer hover:bg-blue-50 transition-colors"
217
+ className="text-[var(--brand-primary)] font-medium cursor-pointer hover:underline transition-colors"
163
218
  onClick={(e) => {
164
219
  e.preventDefault();
165
220
  onPreviewHide?.();
166
- onNavigate?.(targetPath);
221
+ onNavigate?.(resolved);
167
222
  }}
168
223
  onMouseEnter={(e) => {
169
224
  const rect = (e.target as HTMLElement).getBoundingClientRect();
170
- onPreviewShow?.(targetPath, rect);
225
+ onPreviewShow?.(resolved, rect);
171
226
  }}
172
227
  onMouseLeave={() => onPreviewHide?.()}
173
228
  >
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useEffect, useState, useRef, useCallback } from "react";
4
4
  import { Markdown, FileRef } from "./Markdown";
5
+ import { useRefreshTick } from "@/lib/useRefreshTick";
5
6
  import { ExternalLink } from "lucide-react";
6
7
 
7
8
  interface Props {
@@ -27,6 +28,7 @@ export function PreviewPopup({ path, position, onNavigate, onMouseEnter, onMouse
27
28
  const [nestedPos, setNestedPos] = useState<{ x: number; y: number } | null>(null);
28
29
  const nestedShowTimer = useRef<ReturnType<typeof setTimeout>>(null);
29
30
  const nestedHideTimer = useRef<ReturnType<typeof setTimeout>>(null);
31
+ const refreshTick = useRefreshTick();
30
32
 
31
33
  useEffect(() => {
32
34
  // Cancel any pending nested popup timers whenever path changes
@@ -48,7 +50,7 @@ export function PreviewPopup({ path, position, onNavigate, onMouseEnter, onMouse
48
50
  .then((data) => setContent(data.content ?? null))
49
51
  .catch(() => setContent(null))
50
52
  .finally(() => setLoading(false));
51
- }, [path]);
53
+ }, [path, refreshTick]);
52
54
 
53
55
  // Adjust position to stay within viewport
54
56
  useEffect(() => {
@@ -113,7 +115,7 @@ export function PreviewPopup({ path, position, onNavigate, onMouseEnter, onMouse
113
115
  // Also hide nested if mouse leaves this popup entirely
114
116
  handleNestedHide();
115
117
  }}
116
- className="fixed bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-lg shadow-xl w-[480px] max-h-[420px] overflow-y-auto"
118
+ className="fixed bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-lg shadow-xl w-[min(480px,30vw)] max-h-[min(420px,30vh)] overflow-y-auto"
117
119
  style={{
118
120
  left: adjustedPos?.x ?? position.x,
119
121
  top: adjustedPos?.y ?? position.y,
@@ -3,6 +3,7 @@
3
3
  import { useEffect, useState } from "react";
4
4
  import { GitCommit, FileText, ChevronDown, ChevronRight, X, Clock } from "lucide-react";
5
5
  import { DiffView } from "./DiffView";
6
+ import { useRefreshTick } from "@/lib/useRefreshTick";
6
7
 
7
8
  interface TimelineEntry {
8
9
  hash: string;
@@ -44,6 +45,7 @@ export function TimelinePanel({ onNavigate, onClose }: Props) {
44
45
  const [loading, setLoading] = useState(true);
45
46
  const [expandedHash, setExpandedHash] = useState<string | null>(null);
46
47
  const [expandedFile, setExpandedFile] = useState<{ hash: string; file: string } | null>(null);
48
+ const refreshTick = useRefreshTick();
47
49
 
48
50
  useEffect(() => {
49
51
  setLoading(true);
@@ -54,7 +56,7 @@ export function TimelinePanel({ onNavigate, onClose }: Props) {
54
56
  setLoading(false);
55
57
  })
56
58
  .catch(() => setLoading(false));
57
- }, []);
59
+ }, [refreshTick]);
58
60
 
59
61
  useEffect(() => {
60
62
  const handleKeyDown = (e: KeyboardEvent) => {
@@ -18,6 +18,8 @@ interface Props {
18
18
  onSelect: (path: string) => void;
19
19
  }
20
20
 
21
+ const EXPANDED_KEY = "markshelf:treeExpanded";
22
+
21
23
  /** Collect all folder paths that are ancestors of targetPath */
22
24
  function getAncestorPaths(entries: TreeEntry[], targetPath: string): Set<string> {
23
25
  const result = new Set<string>();
@@ -47,17 +49,42 @@ function getAncestorPaths(entries: TreeEntry[], targetPath: string): Set<string>
47
49
  }
48
50
 
49
51
  export function TreeView({ entries, selectedPath, onSelect }: Props) {
50
- // Track which folders are expanded (by path)
51
- const [expanded, setExpanded] = useState<Set<string>>(() => {
52
- // Initially expand top-level hasReadme folders
53
- const initial = new Set<string>();
54
- for (const e of entries) {
55
- if (e.type === "folder" && e.hasReadme) {
56
- initial.add(e.path);
52
+ // Track which folders are expanded (by path). Hydrated from localStorage on mount.
53
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
54
+ const hydratedRef = useRef(false);
55
+
56
+ // Load saved state once on mount; if none, default to expanding top-level hasReadme folders.
57
+ useEffect(() => {
58
+ if (hydratedRef.current) return;
59
+ const saved = localStorage.getItem(EXPANDED_KEY);
60
+ if (saved) {
61
+ try {
62
+ const arr = JSON.parse(saved);
63
+ if (Array.isArray(arr)) {
64
+ setExpanded(new Set(arr.filter((s) => typeof s === "string")));
65
+ hydratedRef.current = true;
66
+ return;
67
+ }
68
+ } catch {
69
+ /* ignore */
57
70
  }
58
71
  }
59
- return initial;
60
- });
72
+ // No saved state: expand top-level hasReadme folders as the default.
73
+ if (entries.length > 0) {
74
+ const initial = new Set<string>();
75
+ for (const e of entries) {
76
+ if (e.type === "folder" && e.hasReadme) initial.add(e.path);
77
+ }
78
+ setExpanded(initial);
79
+ hydratedRef.current = true;
80
+ }
81
+ }, [entries]);
82
+
83
+ // Persist expanded state to localStorage (only after hydration, to avoid overwriting with empty set).
84
+ useEffect(() => {
85
+ if (!hydratedRef.current) return;
86
+ localStorage.setItem(EXPANDED_KEY, JSON.stringify([...expanded]));
87
+ }, [expanded]);
61
88
 
62
89
  const scrollContainerRef = useRef<HTMLDivElement>(null);
63
90
  const selectedRef = useRef<HTMLDivElement>(null);