@@ -3,7 +3,6 @@ import type { FileStatus } from "./github.svelte";
33import type { TreeNode } from "$lib/components/tree/index.svelte" ;
44import type { BundledLanguage , SpecialLanguage } from "shiki" ;
55import { onMount } from "svelte" ;
6- import type { ReadableBox } from "svelte-toolbelt" ;
76import { on } from "svelte/events" ;
87import { type Attachment } from "svelte/attachments" ;
98
@@ -191,10 +190,15 @@ export function splitMultiFilePatch(patchContent: string): [BasicHeader, string]
191190 return patches ;
192191}
193192
194- export type FileTreeNodeData = {
195- data : FileDetails | string ;
196- type : "file" | "directory" ;
197- } ;
193+ export type FileTreeNodeData =
194+ | {
195+ type : "file" ;
196+ file : FileDetails ;
197+ }
198+ | {
199+ type : "directory" ;
200+ name : string ;
201+ } ;
198202
199203export function makeFileTree ( paths : FileDetails [ ] ) : TreeNode < FileTreeNodeData > [ ] {
200204 if ( paths . length === 0 ) {
@@ -203,24 +207,30 @@ export function makeFileTree(paths: FileDetails[]): TreeNode<FileTreeNodeData>[]
203207
204208 const root : TreeNode < FileTreeNodeData > = {
205209 children : [ ] ,
206- data : { type : "directory" , data : "" } ,
210+ data : { type : "directory" , name : "" } ,
207211 } ;
208212
209213 for ( const details of paths ) {
210214 const parts = details . toFile . split ( "/" ) ;
211215 let current = root ;
212216 for ( let i = 0 ; i < parts . length ; i ++ ) {
213217 const part = parts [ i ] ;
214- const existingChild = current . children . find ( ( child ) => child . data . data === part ) ;
218+ const existingChild = current . children . find ( ( child ) => child . data . type === "directory" && child . data . name === part ) ;
215219 if ( existingChild ) {
216220 current = existingChild ;
217221 } else {
218222 const file = i === parts . length - 1 ;
219- const data : FileDetails | string = file ? details : part ;
220- const type = file ? "file" : "directory" ;
221223 const newChild : TreeNode < FileTreeNodeData > = {
222224 children : [ ] ,
223- data : { data, type } ,
225+ data : file
226+ ? {
227+ type : "file" ,
228+ file : details ,
229+ }
230+ : {
231+ type : "directory" ,
232+ name : part ,
233+ } ,
224234 } ;
225235 current . children . push ( newChild ) ;
226236 current = newChild ;
@@ -234,18 +244,18 @@ export function makeFileTree(paths: FileDetails[]): TreeNode<FileTreeNodeData>[]
234244 }
235245
236246 if ( node . children . length === 1 && node . data . type === "directory" && node . children [ 0 ] . data . type === "directory" ) {
237- if ( node . data . data !== "" ) {
238- node . data . data = `${ node . data . data } /${ node . children [ 0 ] . data . data } ` ;
247+ if ( node . data . name !== "" ) {
248+ node . data . name = `${ node . data . name } /${ node . children [ 0 ] . data . name } ` ;
239249 } else {
240- node . data . data = node . children [ 0 ] . data . data ;
250+ node . data . name = node . children [ 0 ] . data . name ;
241251 }
242252 node . children = node . children [ 0 ] . children ;
243253 }
244254 }
245255
246256 mergeRedundantDirectories ( root ) ;
247257
248- if ( root . data . type === "directory" && root . data . data === "" ) {
258+ if ( root . data . type === "directory" && root . data . name === "" ) {
249259 return root . children ;
250260 }
251261 return [ root ] ;
@@ -482,8 +492,3 @@ export function animationFramePromise() {
482492export async function yieldToBrowser ( ) {
483493 await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
484494}
485-
486- // from bits-ui internals
487- export type ReadableBoxedValues < T > = {
488- [ K in keyof T ] : ReadableBox < T [ K ] > ;
489- } ;
0 commit comments