@classic-homes/files-svelte 0.1.0 → 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 CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Svelte 5 network-drive file browser for Classic Theme.
4
4
 
5
- - `FileBrowser`: root picker, breadcrumbs, paged listing, filter, hidden files, preview dialog, download, details, every error state, offline banner
6
- - Building blocks: `FileList`, `FileBreadcrumbs`, `FileIcon`, `FilePreview`, `FileDetails`, `FileErrorState`
5
+ - `FileBrowser`: Explorer-style folder pane (drives, open folder's parents expanded, resizable), root picker, breadcrumbs, paged listing, filter, hidden files, preview dialog, download, details, every error state, offline banner
6
+ - Building blocks: `FileTree`, `FileList`, `FileBreadcrumbs`, `FileIcon`, `FilePreview`, `FileDetails`, `FileErrorState`
7
7
  - Previews reuse [`@classic-homes/viewer-svelte`](../viewer-svelte): pass a `viewers` registry of lazy imports
8
8
  - Re-exports the [`@classic-homes/files-core`](../files-core) sources and helpers
9
9
 
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
3
  import { tick, untrack } from 'svelte';
4
+ import { MediaQuery } from 'svelte/reactivity';
4
5
  import {
5
6
  Alert,
6
7
  Button,
@@ -8,7 +9,9 @@
8
9
  EmptyState,
9
10
  Icon,
10
11
  LiveRegion,
12
+ ResizablePanes,
11
13
  Select,
14
+ Sheet,
12
15
  Switch,
13
16
  } from '@classic-homes/theme-svelte';
14
17
  import type { ViewerRegistry } from '@classic-homes/viewer-svelte';
@@ -29,6 +32,7 @@
29
32
  import FileErrorState from './FileErrorState.svelte';
30
33
  import FileList from './FileList.svelte';
31
34
  import FilePreview from './FilePreview.svelte';
35
+ import FileTree from './FileTree.svelte';
32
36
  import type { FileBrowserContext } from './types.js';
33
37
  import { cn, isTextInput } from './utils.js';
34
38
 
@@ -68,6 +72,16 @@
68
72
  toolbar?: Snippet<[FileBrowserContext]>;
69
73
  /** Per-row write actions, under the same rule as `toolbar`. */
70
74
  rowActions?: Snippet<[FileEntry, FileBrowserContext]>;
75
+ /**
76
+ * Explorer-style folder tree beside the list (drives at the top, the open
77
+ * folder's parents expanded). On phones it opens from a "Folders" button.
78
+ * Default true.
79
+ */
80
+ navigationPane?: boolean;
81
+ /** Starting width of the folder pane, in percent. Default 25. */
82
+ paneSize?: number;
83
+ /** Remember the pane width in localStorage under this key. */
84
+ paneKey?: string;
71
85
  /** Accessible name of the browser region. Default "File browser". */
72
86
  label?: string;
73
87
  locale?: string | string[];
@@ -91,12 +105,18 @@
91
105
  onpreview,
92
106
  toolbar,
93
107
  rowActions,
108
+ navigationPane = true,
109
+ paneSize = $bindable(25),
110
+ paneKey,
94
111
  label = 'File browser',
95
112
  locale,
96
113
  class: className,
97
114
  }: Props = $props();
98
115
 
99
116
  const uid = $props.id();
117
+ // The folder pane sits beside the list from md up; phones get a sheet instead.
118
+ const wide = new MediaQuery('(min-width: 768px)', false);
119
+ let foldersOpen = $state(false);
100
120
  const filterId = `${uid}-filter`;
101
121
  const hiddenId = `${uid}-hidden`;
102
122
 
@@ -356,19 +376,26 @@
356
376
  navigate(parentPath(currentPath), currentPath);
357
377
  }
358
378
 
359
- function changeRoot(id: string) {
379
+ function changeRoot(id: string, nextPath = '') {
360
380
  if (id === rootId) return;
361
381
  rootId = id;
362
382
  filter = '';
363
383
  sort = null;
364
384
  selected = undefined;
365
385
  onrootchange?.(id);
366
- if (currentPath !== '') {
367
- path = '';
368
- onpathchange?.('');
386
+ if (currentPath !== nextPath) {
387
+ path = nextPath;
388
+ onpathchange?.(nextPath);
369
389
  }
370
390
  }
371
391
 
392
+ /** From the folder tree: a folder in this drive, or another drive (and folder). */
393
+ function treeNavigate(id: string, next: string) {
394
+ foldersOpen = false;
395
+ if (id !== rootId) changeRoot(id, next);
396
+ else navigate(next);
397
+ }
398
+
372
399
  function refresh() {
373
400
  attempt++;
374
401
  }
@@ -429,6 +456,7 @@
429
456
  };
430
457
  });
431
458
 
459
+ const showPane = $derived(navigationPane && wide.current && roots.length > 0);
432
460
  const rootOptions = $derived(roots.map((r) => ({ value: r.id, label: r.label })));
433
461
  const listLabel = $derived(`${folderName} contents`);
434
462
 
@@ -477,7 +505,7 @@
477
505
  {:else}
478
506
  <div class="flex flex-col gap-3 border-b border-border p-3">
479
507
  <div class="flex flex-col gap-2 sm:flex-row sm:items-center">
480
- {#if roots.length > 1}
508
+ {#if roots.length > 1 && !showPane}
481
509
  <div class="sm:w-64">
482
510
  <Select
483
511
  label="Drive"
@@ -497,7 +525,7 @@
497
525
  />
498
526
  {/if}
499
527
  </div>
500
- {#if roots.length === 1 && root?.description}
528
+ {#if root?.description && (roots.length === 1 || showPane)}
501
529
  <p class="-mt-1 text-xs text-muted-foreground">{root.description}</p>
502
530
  {/if}
503
531
 
@@ -534,77 +562,125 @@
534
562
  {@render toolbar(context)}
535
563
  </div>
536
564
  {/if}
565
+ {#if navigationPane && !wide.current && roots.length > 0}
566
+ <Button
567
+ variant="outline"
568
+ size="sm"
569
+ onclick={() => (foldersOpen = true)}
570
+ aria-haspopup="dialog"
571
+ >
572
+ <Icon name="sidebar" size={16} />
573
+ Folders
574
+ </Button>
575
+ {/if}
537
576
  <Button variant="ghost" size="icon" onclick={refresh} aria-label="Refresh">
538
577
  <Icon name="refresh" size={16} />
539
578
  </Button>
540
579
  </div>
541
580
  </div>
542
581
 
543
- <div class="flex items-center justify-between gap-2 px-3 pt-2 text-xs text-muted-foreground">
544
- <span data-file-browser-count>{countText}</span>
545
- {#if currentPath}
546
- <button
547
- type="button"
548
- class="inline-flex items-center gap-1 rounded px-1 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
549
- onclick={goUp}
550
- aria-keyshortcuts="Alt+ArrowUp Backspace"
551
- >
552
- <Icon name="corner-up-left" size={14} />
553
- Up a folder
554
- </button>
555
- {/if}
556
- </div>
557
-
558
- <div class="min-h-0 flex-1 overflow-auto">
559
- {#if status === 'error'}
560
- <FileErrorState
561
- error={listError}
562
- onretry={refresh}
563
- onroot={() => navigate('')}
564
- rootLabel={currentPath ? rootLabel : undefined}
565
- class="py-12"
566
- />
567
- {:else}
568
- <FileList
569
- bind:this={list}
570
- bind:selected
571
- bind:sort
572
- entries={shown}
573
- loading={rootsStatus === 'loading' ||
574
- status === 'loading' ||
575
- status === 'idle' ||
576
- (searching && searchStatus === 'loading' && !searchResults)}
577
- {loadingMore}
578
- {hasMore}
579
- {autoLoad}
580
- onloadmore={loadMore}
581
- onopen={open}
582
- {total}
583
- showCount={false}
584
- label={listLabel}
585
- {locale}
586
- emptyTitle={filter.trim() ? `Nothing matches “${filter.trim()}”` : 'This folder is empty'}
587
- rowActions={rowActions && caps.any ? actions : undefined}
588
- />
589
- {#if moreError}
590
- <div class="px-3 pb-3">
591
- <Alert variant="destructive">
592
- {describeFilesError(moreError).title}.
593
- <Button variant="link" size="sm" onclick={loadMore}>Try again</Button>
594
- </Alert>
582
+ {#if showPane}
583
+ <ResizablePanes
584
+ bind:size={paneSize}
585
+ min={12}
586
+ max={50}
587
+ persistKey={paneKey}
588
+ handleLabel="Resize folder pane"
589
+ class="min-h-0 flex-1"
590
+ startClass="bg-muted/20"
591
+ >
592
+ {#snippet start()}
593
+ <div class="h-full overflow-auto px-1" data-file-tree-scroll>
594
+ {@render tree()}
595
595
  </div>
596
- {/if}
597
- {/if}
598
- </div>
596
+ {/snippet}
597
+ {#snippet end()}
598
+ <div class="flex h-full min-h-0 flex-col">{@render listArea()}</div>
599
+ {/snippet}
600
+ </ResizablePanes>
601
+ {:else}
602
+ {@render listArea()}
603
+ {/if}
599
604
  {/if}
600
605
 
601
606
  <LiveRegion message={announcement} />
602
607
  </section>
603
608
 
609
+ {#snippet listArea()}
610
+ <div class="flex items-center justify-between gap-2 px-3 pt-2 text-xs text-muted-foreground">
611
+ <span data-file-browser-count>{countText}</span>
612
+ {#if currentPath}
613
+ <button
614
+ type="button"
615
+ class="inline-flex items-center gap-1 rounded px-1 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
616
+ onclick={goUp}
617
+ aria-keyshortcuts="Alt+ArrowUp Backspace"
618
+ >
619
+ <Icon name="corner-up-left" size={14} />
620
+ Up a folder
621
+ </button>
622
+ {/if}
623
+ </div>
624
+
625
+ <div class="min-h-0 flex-1 overflow-auto">
626
+ {#if status === 'error'}
627
+ <FileErrorState
628
+ error={listError}
629
+ onretry={refresh}
630
+ onroot={() => navigate('')}
631
+ rootLabel={currentPath ? rootLabel : undefined}
632
+ class="py-12"
633
+ />
634
+ {:else}
635
+ <FileList
636
+ bind:this={list}
637
+ bind:selected
638
+ bind:sort
639
+ entries={shown}
640
+ loading={rootsStatus === 'loading' ||
641
+ status === 'loading' ||
642
+ status === 'idle' ||
643
+ (searching && searchStatus === 'loading' && !searchResults)}
644
+ {loadingMore}
645
+ {hasMore}
646
+ {autoLoad}
647
+ onloadmore={loadMore}
648
+ onopen={open}
649
+ {total}
650
+ showCount={false}
651
+ label={listLabel}
652
+ {locale}
653
+ emptyTitle={filter.trim() ? `Nothing matches “${filter.trim()}”` : 'This folder is empty'}
654
+ rowActions={rowActions && caps.any ? actions : undefined}
655
+ />
656
+ {#if moreError}
657
+ <div class="px-3 pb-3">
658
+ <Alert variant="destructive">
659
+ {describeFilesError(moreError).title}.
660
+ <Button variant="link" size="sm" onclick={loadMore}>Try again</Button>
661
+ </Alert>
662
+ </div>
663
+ {/if}
664
+ {/if}
665
+ </div>
666
+ {/snippet}
667
+
668
+ {#snippet tree()}
669
+ <FileTree {source} {roots} {rootId} path={currentPath} {showHidden} onnavigate={treeNavigate} />
670
+ {/snippet}
671
+
604
672
  {#snippet actions(entry: FileEntry)}
605
673
  {@render rowActions?.(entry, context)}
606
674
  {/snippet}
607
675
 
676
+ {#if navigationPane && !wide.current}
677
+ <Sheet bind:open={foldersOpen} side="left" size="sm" title="Folders">
678
+ <div data-file-tree-scroll class="-mx-2">
679
+ {@render tree()}
680
+ </div>
681
+ </Sheet>
682
+ {/if}
683
+
608
684
  {#if previewEntry && rootId !== undefined}
609
685
  <Dialog
610
686
  bind:open={previewOpen}
@@ -38,11 +38,21 @@ interface Props {
38
38
  toolbar?: Snippet<[FileBrowserContext]>;
39
39
  /** Per-row write actions, under the same rule as `toolbar`. */
40
40
  rowActions?: Snippet<[FileEntry, FileBrowserContext]>;
41
+ /**
42
+ * Explorer-style folder tree beside the list (drives at the top, the open
43
+ * folder's parents expanded). On phones it opens from a "Folders" button.
44
+ * Default true.
45
+ */
46
+ navigationPane?: boolean;
47
+ /** Starting width of the folder pane, in percent. Default 25. */
48
+ paneSize?: number;
49
+ /** Remember the pane width in localStorage under this key. */
50
+ paneKey?: string;
41
51
  /** Accessible name of the browser region. Default "File browser". */
42
52
  label?: string;
43
53
  locale?: string | string[];
44
54
  class?: string;
45
55
  }
46
- declare const FileBrowser: import("svelte").Component<Props, {}, "path" | "filter" | "rootId" | "showHidden">;
56
+ declare const FileBrowser: import("svelte").Component<Props, {}, "path" | "filter" | "rootId" | "showHidden" | "paneSize">;
47
57
  type FileBrowser = ReturnType<typeof FileBrowser>;
48
58
  export default FileBrowser;
@@ -0,0 +1,396 @@
1
+ <!--
2
+ @component
3
+ Explorer-style navigation pane: drives at the top level, their folders
4
+ below, loaded lazily as they expand. The open folder is highlighted and
5
+ its ancestors are expanded, so its parent and siblings are always in view.
6
+ -->
7
+ <script lang="ts">
8
+ import { tick, untrack } from 'svelte';
9
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity';
10
+ import { Icon } from '@classic-homes/theme-svelte';
11
+ import {
12
+ isAbortError,
13
+ normalizePath,
14
+ pathSegments,
15
+ type FileEntry,
16
+ type FileRoot,
17
+ type FilesSource,
18
+ } from '@classic-homes/files-core';
19
+ import FileIcon from './FileIcon.svelte';
20
+ import { cn } from './utils.js';
21
+
22
+ interface Props {
23
+ source: FilesSource;
24
+ /** Drives shown at the top level. */
25
+ roots: FileRoot[];
26
+ /** Drive of the open folder. */
27
+ rootId?: string;
28
+ /** Open folder, root-relative (`''` = the drive itself). */
29
+ path?: string;
30
+ /** Include hidden folders. */
31
+ showHidden?: boolean;
32
+ /** A folder (or a drive, with `path` `''`) was chosen. */
33
+ onnavigate?: (rootId: string, path: string) => void;
34
+ /** Accessible name of the tree. Default "Folders". */
35
+ label?: string;
36
+ class?: string;
37
+ }
38
+
39
+ let {
40
+ source,
41
+ roots,
42
+ rootId,
43
+ path = '',
44
+ showHidden = false,
45
+ onnavigate,
46
+ label = 'Folders',
47
+ class: className,
48
+ }: Props = $props();
49
+
50
+ type Status = 'loading' | 'ready' | 'error';
51
+ interface Children {
52
+ status: Status;
53
+ folders: FileEntry[];
54
+ }
55
+
56
+ /** `${rootId}|${path}` → its subfolders (`|` can't occur in SMB names). */
57
+ const children = new SvelteMap<string, Children>();
58
+ const expanded = new SvelteSet<string>();
59
+ const controllers = new Map<string, AbortController>();
60
+
61
+ const keyOf = (r: string, p: string) => `${r}|${p}`;
62
+ const currentPath = $derived.by(() => {
63
+ try {
64
+ return normalizePath(path);
65
+ } catch {
66
+ return '';
67
+ }
68
+ });
69
+ const currentKey = $derived(rootId === undefined ? '' : keyOf(rootId, currentPath));
70
+
71
+ let focusedKey = $state<string>();
72
+ let tree = $state<HTMLElement>();
73
+
74
+ /** Load every subfolder (directories come first, so stop at the first file). */
75
+ async function load(r: string, p: string) {
76
+ const key = keyOf(r, p);
77
+ const state = children.get(key);
78
+ if (state && state.status !== 'error') return;
79
+ const controller = new AbortController();
80
+ controllers.set(key, controller);
81
+ children.set(key, { status: 'loading', folders: state?.folders ?? [] });
82
+ const folders: FileEntry[] = [];
83
+ try {
84
+ let cursor: string | undefined;
85
+ for (;;) {
86
+ const page = await source.list(r, p, {
87
+ limit: 1000,
88
+ cursor,
89
+ includeHidden: showHidden,
90
+ signal: controller.signal,
91
+ });
92
+ const dirs = page.entries.filter((e) => e.type === 'dir');
93
+ folders.push(...dirs);
94
+ if (!page.nextCursor || dirs.length < page.entries.length) break;
95
+ cursor = page.nextCursor;
96
+ }
97
+ if (!controller.signal.aborted) children.set(key, { status: 'ready', folders });
98
+ } catch (err) {
99
+ if (controller.signal.aborted || isAbortError(err)) return;
100
+ children.set(key, { status: 'error', folders: [] });
101
+ } finally {
102
+ if (controllers.get(key) === controller) controllers.delete(key);
103
+ }
104
+ }
105
+
106
+ // Start over when the source or the hidden-files setting changes.
107
+ $effect(() => {
108
+ void source;
109
+ void showHidden;
110
+ return () => {
111
+ for (const c of controllers.values()) c.abort();
112
+ controllers.clear();
113
+ children.clear();
114
+ };
115
+ });
116
+
117
+ // Reveal the open folder: expand its drive and every ancestor, and load them.
118
+ $effect(() => {
119
+ const r = rootId;
120
+ const p = currentPath;
121
+ void source;
122
+ void showHidden;
123
+ if (r === undefined || !roots.some((root) => root.id === r)) return;
124
+ untrack(() => {
125
+ const ancestors = ['', ...pathSegments(p).map((s) => s.path)];
126
+ // The open folder itself is listed by the browser; expand it here too so
127
+ // its subfolders show, as in Explorer.
128
+ for (const a of ancestors) {
129
+ expanded.add(keyOf(r, a));
130
+ void load(r, a);
131
+ }
132
+ focusedKey = keyOf(r, p);
133
+ });
134
+ void tick().then(revealCurrent);
135
+ });
136
+
137
+ interface Item {
138
+ key: string;
139
+ rootId: string;
140
+ path: string;
141
+ name: string;
142
+ level: number;
143
+ isRoot: boolean;
144
+ hidden: boolean;
145
+ setsize: number;
146
+ posinset: number;
147
+ }
148
+ type Row =
149
+ | { kind: 'item'; item: Item }
150
+ | { kind: 'note'; key: string; level: number; text: string; retry?: () => void };
151
+
152
+ const rows = $derived.by<Row[]>(() => {
153
+ const out: Row[] = [];
154
+ const walk = (r: string, p: string, level: number) => {
155
+ const state = children.get(keyOf(r, p));
156
+ if (!state || (state.status === 'loading' && state.folders.length === 0)) {
157
+ out.push({ kind: 'note', key: `${keyOf(r, p)}:loading`, level, text: 'Loading…' });
158
+ return;
159
+ }
160
+ if (state.status === 'error') {
161
+ out.push({
162
+ kind: 'note',
163
+ key: `${keyOf(r, p)}:error`,
164
+ level,
165
+ text: "Couldn't open. Try again",
166
+ retry: () => void load(r, p),
167
+ });
168
+ return;
169
+ }
170
+ state.folders.forEach((f, i) => {
171
+ const key = keyOf(r, f.path);
172
+ out.push({
173
+ kind: 'item',
174
+ item: {
175
+ key,
176
+ rootId: r,
177
+ path: f.path,
178
+ name: f.name,
179
+ level,
180
+ isRoot: false,
181
+ hidden: f.hidden,
182
+ setsize: state.folders.length,
183
+ posinset: i + 1,
184
+ },
185
+ });
186
+ if (expanded.has(key)) walk(r, f.path, level + 1);
187
+ });
188
+ };
189
+ roots.forEach((root, i) => {
190
+ const key = keyOf(root.id, '');
191
+ out.push({
192
+ kind: 'item',
193
+ item: {
194
+ key,
195
+ rootId: root.id,
196
+ path: '',
197
+ name: root.label,
198
+ level: 1,
199
+ isRoot: true,
200
+ hidden: false,
201
+ setsize: roots.length,
202
+ posinset: i + 1,
203
+ },
204
+ });
205
+ if (expanded.has(key)) walk(root.id, '', 2);
206
+ });
207
+ return out;
208
+ });
209
+
210
+ const items = $derived(rows.flatMap((r) => (r.kind === 'item' ? [r.item] : [])));
211
+ const tabKey = $derived(
212
+ items.some((i) => i.key === focusedKey)
213
+ ? focusedKey
214
+ : (items.find((i) => i.key === currentKey) ?? items[0])?.key
215
+ );
216
+
217
+ /** Known to have no subfolders (loaded and empty). */
218
+ function isLeaf(item: Item): boolean {
219
+ const state = children.get(item.key);
220
+ return state?.status === 'ready' && state.folders.length === 0;
221
+ }
222
+
223
+ function toggle(item: Item, open?: boolean) {
224
+ const willOpen = open ?? !expanded.has(item.key);
225
+ if (willOpen) {
226
+ expanded.add(item.key);
227
+ void load(item.rootId, item.path);
228
+ } else {
229
+ expanded.delete(item.key);
230
+ }
231
+ }
232
+
233
+ function choose(item: Item) {
234
+ focusedKey = item.key;
235
+ onnavigate?.(item.rootId, item.path);
236
+ }
237
+
238
+ function el(key: string | undefined): HTMLElement | null {
239
+ if (!tree || key === undefined) return null;
240
+ for (const node of tree.querySelectorAll<HTMLElement>('[role="treeitem"]')) {
241
+ if (node.dataset.key === key) return node;
242
+ }
243
+ return null;
244
+ }
245
+
246
+ async function focusItem(item: Item | undefined) {
247
+ if (!item) return;
248
+ focusedKey = item.key;
249
+ await tick();
250
+ const node = el(item.key);
251
+ node?.focus({ preventScroll: true });
252
+ if (node) scrollIntoPane(node);
253
+ }
254
+
255
+ /** Scroll inside the pane only, never the page. */
256
+ function scrollIntoPane(node: HTMLElement) {
257
+ const pane = tree?.closest<HTMLElement>('[data-file-tree-scroll]') ?? tree?.parentElement;
258
+ if (!pane) return;
259
+ const p = pane.getBoundingClientRect();
260
+ const r = node.getBoundingClientRect();
261
+ if (r.top < p.top) pane.scrollTop -= p.top - r.top + 8;
262
+ else if (r.bottom > p.bottom) pane.scrollTop += r.bottom - p.bottom + 8;
263
+ }
264
+
265
+ function revealCurrent() {
266
+ const node = el(currentKey);
267
+ if (node) scrollIntoPane(node);
268
+ }
269
+
270
+ function onkeydown(event: KeyboardEvent, item: Item) {
271
+ const index = items.findIndex((i) => i.key === item.key);
272
+ const open = expanded.has(item.key);
273
+ switch (event.key) {
274
+ case 'ArrowDown':
275
+ event.preventDefault();
276
+ void focusItem(items[index + 1]);
277
+ break;
278
+ case 'ArrowUp':
279
+ if (event.altKey) return; // "up a folder" belongs to the browser
280
+ event.preventDefault();
281
+ void focusItem(items[index - 1]);
282
+ break;
283
+ case 'Home':
284
+ event.preventDefault();
285
+ void focusItem(items[0]);
286
+ break;
287
+ case 'End':
288
+ event.preventDefault();
289
+ void focusItem(items[items.length - 1]);
290
+ break;
291
+ case 'ArrowRight':
292
+ event.preventDefault();
293
+ if (isLeaf(item)) break;
294
+ if (!open) toggle(item, true);
295
+ else if (items[index + 1]?.level === item.level + 1) void focusItem(items[index + 1]);
296
+ break;
297
+ case 'ArrowLeft': {
298
+ event.preventDefault();
299
+ if (open && !isLeaf(item)) {
300
+ toggle(item, false);
301
+ break;
302
+ }
303
+ for (let i = index - 1; i >= 0; i--) {
304
+ if (items[i].level === item.level - 1) {
305
+ void focusItem(items[i]);
306
+ break;
307
+ }
308
+ }
309
+ break;
310
+ }
311
+ case 'Enter':
312
+ case ' ':
313
+ event.preventDefault();
314
+ choose(item);
315
+ break;
316
+ }
317
+ }
318
+ </script>
319
+
320
+ <ul
321
+ bind:this={tree}
322
+ role="tree"
323
+ aria-label={label}
324
+ class={cn('select-none py-1 text-sm', className)}
325
+ data-file-tree
326
+ >
327
+ {#each rows as row (row.kind === 'item' ? row.item.key : row.key)}
328
+ {#if row.kind === 'note'}
329
+ <li
330
+ role="none"
331
+ style:padding-left="{row.level * 0.875 + 0.5}rem"
332
+ class="py-1 text-xs text-muted-foreground"
333
+ >
334
+ {#if row.retry}
335
+ <button
336
+ type="button"
337
+ class="underline hover:text-foreground"
338
+ tabindex="-1"
339
+ onclick={row.retry}>{row.text}</button
340
+ >
341
+ {:else}
342
+ {row.text}
343
+ {/if}
344
+ </li>
345
+ {:else}
346
+ {@const item = row.item}
347
+ {@const open = expanded.has(item.key)}
348
+ {@const leaf = isLeaf(item)}
349
+ {@const current = item.key === currentKey}
350
+ <li
351
+ role="treeitem"
352
+ data-key={item.key}
353
+ aria-level={item.level}
354
+ aria-setsize={item.setsize}
355
+ aria-posinset={item.posinset}
356
+ aria-expanded={leaf ? undefined : open}
357
+ aria-selected={current}
358
+ aria-current={current ? 'location' : undefined}
359
+ tabindex={item.key === tabKey ? 0 : -1}
360
+ class={cn(
361
+ 'flex cursor-pointer items-center gap-1 rounded-sm py-1 pr-2 outline-none',
362
+ 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring',
363
+ current ? 'bg-chart-1/15 font-medium text-foreground' : 'hover:bg-muted/60',
364
+ item.hidden && 'opacity-70'
365
+ )}
366
+ style:padding-left="{(item.level - 1) * 0.875 + 0.25}rem"
367
+ title={item.name}
368
+ onclick={() => choose(item)}
369
+ onkeydown={(e) => onkeydown(e, item)}
370
+ onfocus={() => (focusedKey = item.key)}
371
+ >
372
+ <!-- Chevron: expand/collapse without opening (as in Explorer). Keyboard: Right/Left. -->
373
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
374
+ <span
375
+ class={cn(
376
+ 'flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted',
377
+ leaf && 'invisible'
378
+ )}
379
+ aria-hidden="true"
380
+ onclick={(e) => {
381
+ e.stopPropagation();
382
+ toggle(item);
383
+ }}
384
+ >
385
+ <Icon name={open ? 'chevron-down' : 'chevron-right'} size={14} />
386
+ </span>
387
+ {#if item.isRoot}
388
+ <Icon name="home" size={16} class="shrink-0 text-muted-foreground" />
389
+ {:else}
390
+ <FileIcon type="dir" size={16} />
391
+ {/if}
392
+ <span class="truncate">{item.name}</span>
393
+ </li>
394
+ {/if}
395
+ {/each}
396
+ </ul>
@@ -0,0 +1,25 @@
1
+ import { type FileRoot, type FilesSource } from '@classic-homes/files-core';
2
+ interface Props {
3
+ source: FilesSource;
4
+ /** Drives shown at the top level. */
5
+ roots: FileRoot[];
6
+ /** Drive of the open folder. */
7
+ rootId?: string;
8
+ /** Open folder, root-relative (`''` = the drive itself). */
9
+ path?: string;
10
+ /** Include hidden folders. */
11
+ showHidden?: boolean;
12
+ /** A folder (or a drive, with `path` `''`) was chosen. */
13
+ onnavigate?: (rootId: string, path: string) => void;
14
+ /** Accessible name of the tree. Default "Folders". */
15
+ label?: string;
16
+ class?: string;
17
+ }
18
+ /**
19
+ * Explorer-style navigation pane: drives at the top level, their folders
20
+ * below, loaded lazily as they expand. The open folder is highlighted and
21
+ * its ancestors are expanded, so its parent and siblings are always in view.
22
+ */
23
+ declare const FileTree: import("svelte").Component<Props, {}, "">;
24
+ type FileTree = ReturnType<typeof FileTree>;
25
+ export default FileTree;
@@ -1,6 +1,7 @@
1
1
  export { default as FileBrowser } from './FileBrowser.svelte';
2
2
  export { default as FileList } from './FileList.svelte';
3
3
  export { default as FileBreadcrumbs } from './FileBreadcrumbs.svelte';
4
+ export { default as FileTree } from './FileTree.svelte';
4
5
  export { default as FileIcon } from './FileIcon.svelte';
5
6
  export { default as FilePreview } from './FilePreview.svelte';
6
7
  export { default as FileDetails } from './FileDetails.svelte';
package/dist/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as FileBrowser } from './FileBrowser.svelte';
2
2
  export { default as FileList } from './FileList.svelte';
3
3
  export { default as FileBreadcrumbs } from './FileBreadcrumbs.svelte';
4
+ export { default as FileTree } from './FileTree.svelte';
4
5
  export { default as FileIcon } from './FileIcon.svelte';
5
6
  export { default as FilePreview } from './FilePreview.svelte';
6
7
  export { default as FileDetails } from './FileDetails.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/files-svelte",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Svelte network-drive file browser for Classic Theme: FileBrowser plus FileList, FileBreadcrumbs, FileIcon, FilePreview and FileDetails, with previews through the document viewers",
5
5
  "type": "module",
6
6
  "svelte": "./dist/lib/index.js",