@classic-homes/files-svelte 0.5.0 → 0.6.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 +49 -1
- package/dist/lib/FileBranch.svelte +278 -0
- package/dist/lib/FileBranch.svelte.d.ts +39 -0
- package/dist/lib/FileBrowser.svelte +414 -83
- package/dist/lib/FileBrowser.svelte.d.ts +21 -2
- package/dist/lib/FileList.svelte +103 -62
- package/dist/lib/FileList.svelte.d.ts +7 -0
- package/dist/lib/FilePreview.svelte +110 -11
- package/dist/lib/FilePreview.svelte.d.ts +14 -1
- package/dist/lib/FileTree.svelte +13 -18
- package/dist/lib/tree-rows.d.ts +18 -0
- package/dist/lib/tree-rows.js +26 -0
- package/dist/lib/utils.d.ts +13 -0
- package/dist/lib/utils.js +37 -0
- package/package.json +1 -1
|
@@ -20,14 +20,18 @@
|
|
|
20
20
|
filterEntries,
|
|
21
21
|
isAbortError,
|
|
22
22
|
isFilesError,
|
|
23
|
+
joinPath,
|
|
23
24
|
normalizePath,
|
|
24
25
|
parentPath,
|
|
26
|
+
pathSegments,
|
|
27
|
+
sortEntries,
|
|
25
28
|
writeCapabilities,
|
|
26
29
|
type FileEntry,
|
|
27
30
|
type FileRoot,
|
|
28
31
|
type FileSort,
|
|
29
32
|
type FilesSource,
|
|
30
33
|
} from '@classic-homes/files-core';
|
|
34
|
+
import FileBranch from './FileBranch.svelte';
|
|
31
35
|
import FileBreadcrumbs from './FileBreadcrumbs.svelte';
|
|
32
36
|
import FileErrorState from './FileErrorState.svelte';
|
|
33
37
|
import FileList from './FileList.svelte';
|
|
@@ -51,9 +55,27 @@
|
|
|
51
55
|
* The location changed (drive, folder or both), in one call. Use this to
|
|
52
56
|
* keep the location in the URL: on a drive change `onrootchange` and
|
|
53
57
|
* `onpathchange` fire back to back, and a URL built from the current page
|
|
54
|
-
* in each would lose the first change.
|
|
58
|
+
* in each would lose the first change. In pane mode it also fires when a
|
|
59
|
+
* file opens, changes or closes, with `file` set to the open file's name.
|
|
55
60
|
*/
|
|
56
|
-
onnavigate?: (location: { rootId: string; path: string }) => void;
|
|
61
|
+
onnavigate?: (location: { rootId: string; path: string; file?: string }) => void;
|
|
62
|
+
/**
|
|
63
|
+
* How a file opens: `'dialog'` (a modal over the list) or `'pane'` (in place
|
|
64
|
+
* of the list, with the folder tree beside it focused on the open folder's
|
|
65
|
+
* branch). Default `'dialog'`.
|
|
66
|
+
*/
|
|
67
|
+
preview?: 'dialog' | 'pane';
|
|
68
|
+
/**
|
|
69
|
+
* Name of the open file in the current folder. Bindable. Setting it opens
|
|
70
|
+
* that file (a deep link); `undefined` closes it. A name that doesn't resolve
|
|
71
|
+
* to a file in the folder is cleared and reported through `onfilechange`
|
|
72
|
+
* (and, in pane mode, `onnavigate` without `file`).
|
|
73
|
+
*/
|
|
74
|
+
file?: string;
|
|
75
|
+
/** The user opened, switched or closed a file: its name, or `undefined`. */
|
|
76
|
+
onfilechange?: (file: string | undefined) => void;
|
|
77
|
+
/** Draw the rounded border. Set false when the browser fills its container edge to edge. Default true. */
|
|
78
|
+
frame?: boolean;
|
|
57
79
|
/** Document viewers for previews, as lazy imports keyed by format. */
|
|
58
80
|
viewers?: ViewerRegistry;
|
|
59
81
|
/** Entries per page. Default 200. */
|
|
@@ -102,6 +124,10 @@
|
|
|
102
124
|
onrootchange,
|
|
103
125
|
onpathchange,
|
|
104
126
|
onnavigate,
|
|
127
|
+
preview = 'dialog',
|
|
128
|
+
file = $bindable(),
|
|
129
|
+
onfilechange,
|
|
130
|
+
frame = true,
|
|
105
131
|
viewers = {},
|
|
106
132
|
pageSize = 200,
|
|
107
133
|
autoLoad = false,
|
|
@@ -125,6 +151,7 @@
|
|
|
125
151
|
// The folder pane sits beside the list from md up; phones get a sheet instead.
|
|
126
152
|
const wide = new MediaQuery('(min-width: 768px)', false);
|
|
127
153
|
let foldersOpen = $state(false);
|
|
154
|
+
let filesOpen = $state(false);
|
|
128
155
|
const filterId = `${uid}-filter`;
|
|
129
156
|
const hiddenId = `${uid}-hidden`;
|
|
130
157
|
|
|
@@ -158,6 +185,11 @@
|
|
|
158
185
|
let announcement = $state('');
|
|
159
186
|
let online = $state(typeof navigator === 'undefined' ? true : navigator.onLine !== false);
|
|
160
187
|
let list = $state<FileList>();
|
|
188
|
+
let previewer = $state<FilePreview>();
|
|
189
|
+
let sideBranch = $state<FileBranch>();
|
|
190
|
+
let sectionEl = $state<HTMLElement>();
|
|
191
|
+
/** Root + folder whose first page is in `entries` (resolves `file` against it). */
|
|
192
|
+
let listedKey = $state<string>();
|
|
161
193
|
/** Focus the list once the next listing lands (keyboard navigation). */
|
|
162
194
|
let focusAfterLoad = false;
|
|
163
195
|
|
|
@@ -177,6 +209,20 @@
|
|
|
177
209
|
const searching = $derived(!!source.search && filter.trim() !== '');
|
|
178
210
|
const shown = $derived(searching ? (searchResults ?? []) : filterEntries(entries, filter));
|
|
179
211
|
const hasMore = $derived(!searching && !!nextCursor);
|
|
212
|
+
// Pane mode: the open file and its neighbours, in display order.
|
|
213
|
+
const docOpen = $derived(
|
|
214
|
+
preview === 'pane' && previewOpen && !!previewEntry && rootId !== undefined
|
|
215
|
+
);
|
|
216
|
+
/** The entries in the list's order: the left pane's branch and previous / next follow it. */
|
|
217
|
+
const docEntries = $derived(sort ? sortEntries(shown, sort) : shown);
|
|
218
|
+
const docFiles = $derived(docEntries.filter((e) => e.type === 'file'));
|
|
219
|
+
const docIndex = $derived(
|
|
220
|
+
previewEntry ? docFiles.findIndex((e) => e.path === previewEntry?.path) : -1
|
|
221
|
+
);
|
|
222
|
+
const prevFile = $derived(docIndex > 0 ? docFiles[docIndex - 1] : undefined);
|
|
223
|
+
const nextFile = $derived(
|
|
224
|
+
docIndex >= 0 && docIndex < docFiles.length - 1 ? docFiles[docIndex + 1] : undefined
|
|
225
|
+
);
|
|
180
226
|
const nf = $derived(new Intl.NumberFormat(locale));
|
|
181
227
|
|
|
182
228
|
const context: FileBrowserContext = {
|
|
@@ -256,6 +302,7 @@
|
|
|
256
302
|
entries = [];
|
|
257
303
|
total = undefined;
|
|
258
304
|
nextCursor = null;
|
|
305
|
+
listedKey = undefined;
|
|
259
306
|
announcement = `Loading ${folderName}…`;
|
|
260
307
|
});
|
|
261
308
|
|
|
@@ -266,6 +313,7 @@
|
|
|
266
313
|
total = page.total;
|
|
267
314
|
nextCursor = page.nextCursor ?? null;
|
|
268
315
|
status = 'ready';
|
|
316
|
+
listedKey = locationKey(id, folder);
|
|
269
317
|
announce();
|
|
270
318
|
if (focusAfterLoad) {
|
|
271
319
|
focusAfterLoad = false;
|
|
@@ -372,6 +420,122 @@
|
|
|
372
420
|
};
|
|
373
421
|
});
|
|
374
422
|
|
|
423
|
+
const locationKey = (id: string | undefined, folder: string) => `${id ?? ''}\u0000${folder}`;
|
|
424
|
+
|
|
425
|
+
/** Show a file. `notify` reports it as the user's choice; a `file` prop change doesn't. */
|
|
426
|
+
function show(entry: FileEntry, notify: boolean) {
|
|
427
|
+
const same = previewOpen && previewEntry?.path === entry.path;
|
|
428
|
+
previewEntry = entry;
|
|
429
|
+
previewOpen = true;
|
|
430
|
+
selected = entry.path;
|
|
431
|
+
if (same) return;
|
|
432
|
+
file = entry.name;
|
|
433
|
+
onpreview?.(entry);
|
|
434
|
+
if (!notify) return;
|
|
435
|
+
onfilechange?.(entry.name);
|
|
436
|
+
if (preview === 'pane' && rootId !== undefined)
|
|
437
|
+
onnavigate?.({ rootId, path: currentPath, file: entry.name });
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Hide the open file. In pane mode focus inside the preview goes back to the list. */
|
|
441
|
+
function hidePreview() {
|
|
442
|
+
if (!previewOpen) return;
|
|
443
|
+
const refocus = preview === 'pane' && !!sectionEl && sectionEl.contains(document.activeElement);
|
|
444
|
+
previewOpen = false;
|
|
445
|
+
filesOpen = false;
|
|
446
|
+
// The dialog keeps its entry while it animates out.
|
|
447
|
+
if (preview === 'pane') previewEntry = undefined;
|
|
448
|
+
if (refocus) void tick().then(() => list?.focus());
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function closePreview(notify: boolean) {
|
|
452
|
+
const had = file !== undefined;
|
|
453
|
+
hidePreview();
|
|
454
|
+
file = undefined;
|
|
455
|
+
if (!notify || !had) return;
|
|
456
|
+
onfilechange?.(undefined);
|
|
457
|
+
if (preview === 'pane' && rootId !== undefined) onnavigate?.({ rootId, path: currentPath });
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Leaving the folder closes its file; the caller reports the new location. */
|
|
461
|
+
function leaveFile() {
|
|
462
|
+
const had = file !== undefined;
|
|
463
|
+
closePreview(false);
|
|
464
|
+
if (had) onfilechange?.(undefined);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// `file` from outside (a deep link, Back/Forward): open or close to match. A
|
|
468
|
+
// location change closes the open file; a new `file` then resolves in the new folder.
|
|
469
|
+
let lastLocation: string | undefined;
|
|
470
|
+
let resolveController: AbortController | undefined;
|
|
471
|
+
$effect(() => {
|
|
472
|
+
const want = file;
|
|
473
|
+
const id = rootId;
|
|
474
|
+
const folder = currentPath;
|
|
475
|
+
const listed = listedKey;
|
|
476
|
+
const key = locationKey(id, folder);
|
|
477
|
+
untrack(() => {
|
|
478
|
+
if (lastLocation !== undefined && key !== lastLocation) hidePreview();
|
|
479
|
+
lastLocation = key;
|
|
480
|
+
const openName = previewOpen ? previewEntry?.name : undefined;
|
|
481
|
+
if (want === openName) return;
|
|
482
|
+
resolveController?.abort();
|
|
483
|
+
if (want === undefined) {
|
|
484
|
+
hidePreview();
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (id === undefined || listed !== key) return; // wait for this folder's listing
|
|
488
|
+
resolveFile(want, id, folder);
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* `file` named something that isn't a file in this folder: clear the binding
|
|
494
|
+
* and say so, so the caller drops a stale `?file=` from its URL.
|
|
495
|
+
*/
|
|
496
|
+
function unresolved(name: string) {
|
|
497
|
+
if (file !== name) return;
|
|
498
|
+
file = undefined;
|
|
499
|
+
onfilechange?.(undefined);
|
|
500
|
+
if (preview === 'pane' && rootId !== undefined) onnavigate?.({ rootId, path: currentPath });
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** Errors from `info()` that settle it: the name isn't a file here. Others are transient. */
|
|
504
|
+
const CONCLUSIVE = new Set(['not_found', 'invalid_path', 'is_directory', 'not_a_directory']);
|
|
505
|
+
|
|
506
|
+
function resolveFile(name: string, id: string, folder: string) {
|
|
507
|
+
if (name.includes('/')) return unresolved(name);
|
|
508
|
+
const hit = entries.find((e) => e.name === name);
|
|
509
|
+
if (hit) {
|
|
510
|
+
if (hit.type === 'file') show(hit, false);
|
|
511
|
+
else unresolved(name);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (!nextCursor) return unresolved(name); // the whole folder is listed: it isn't here
|
|
515
|
+
// Beyond the first page: ask for it directly.
|
|
516
|
+
let target: string;
|
|
517
|
+
try {
|
|
518
|
+
target = joinPath(folder, name);
|
|
519
|
+
} catch {
|
|
520
|
+
return unresolved(name);
|
|
521
|
+
}
|
|
522
|
+
const controller = new AbortController();
|
|
523
|
+
resolveController = controller;
|
|
524
|
+
source.info(id, target, controller.signal).then(
|
|
525
|
+
(entry) => {
|
|
526
|
+
if (controller.signal.aborted || file !== name) return;
|
|
527
|
+
if (entry.type === 'file') show(entry, false);
|
|
528
|
+
else unresolved(name);
|
|
529
|
+
},
|
|
530
|
+
(err) => {
|
|
531
|
+
if (controller.signal.aborted || isAbortError(err)) return;
|
|
532
|
+
// A file that isn't there clears the link; anything else (network, 401…) is reported.
|
|
533
|
+
if (isFilesError(err) && CONCLUSIVE.has(err.code)) unresolved(name);
|
|
534
|
+
else report(err);
|
|
535
|
+
}
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
375
539
|
function navigate(next: string, focusChild?: string) {
|
|
376
540
|
let target: string;
|
|
377
541
|
try {
|
|
@@ -379,6 +543,7 @@
|
|
|
379
543
|
} catch {
|
|
380
544
|
target = '';
|
|
381
545
|
}
|
|
546
|
+
leaveFile();
|
|
382
547
|
filter = '';
|
|
383
548
|
sort = null;
|
|
384
549
|
selected = focusChild;
|
|
@@ -399,6 +564,7 @@
|
|
|
399
564
|
|
|
400
565
|
function changeRoot(id: string, nextPath = '') {
|
|
401
566
|
if (id === rootId) return;
|
|
567
|
+
leaveFile();
|
|
402
568
|
rootId = id;
|
|
403
569
|
filter = '';
|
|
404
570
|
sort = null;
|
|
@@ -424,7 +590,10 @@
|
|
|
424
590
|
|
|
425
591
|
// A sheet left open on a phone must not reappear when the view narrows again.
|
|
426
592
|
$effect(() => {
|
|
427
|
-
if (wide.current)
|
|
593
|
+
if (wide.current) {
|
|
594
|
+
foldersOpen = false;
|
|
595
|
+
filesOpen = false;
|
|
596
|
+
}
|
|
428
597
|
});
|
|
429
598
|
|
|
430
599
|
function refresh() {
|
|
@@ -436,14 +605,63 @@
|
|
|
436
605
|
focusAfterLoad = true;
|
|
437
606
|
navigate(entry.path);
|
|
438
607
|
} else if (entry.type === 'file') {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
608
|
+
show(entry, true);
|
|
609
|
+
// The preview replaces the list that had focus.
|
|
610
|
+
if (preview === 'pane') void tick().then(() => previewer?.focus());
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* The branch beside (or, on phones, over) an open document: a folder on it
|
|
616
|
+
* closes the document. The current folder just closes it; any other folder
|
|
617
|
+
* opens, and an ancestor selects the folder the user came from.
|
|
618
|
+
*/
|
|
619
|
+
function branchFolder(target: string) {
|
|
620
|
+
const inSheet = filesOpen;
|
|
621
|
+
filesOpen = false;
|
|
622
|
+
if (target === currentPath) {
|
|
623
|
+
closePreview(true);
|
|
624
|
+
// From the phone sheet focus isn't in the browser: put it on the list.
|
|
625
|
+
if (inSheet) void tick().then(() => list?.focus());
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
let from: string | undefined;
|
|
629
|
+
try {
|
|
630
|
+
from = pathSegments(currentPath).find((s) => parentPath(s.path) === target)?.path;
|
|
631
|
+
} catch {
|
|
632
|
+
from = undefined;
|
|
442
633
|
}
|
|
634
|
+
focusAfterLoad = true;
|
|
635
|
+
navigate(target, from);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function branchFile(entry: FileEntry) {
|
|
639
|
+
filesOpen = false;
|
|
640
|
+
show(entry, true);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/** Arrowing onto a file in the branch switches the document as it goes. */
|
|
644
|
+
function branchStep(entry: FileEntry) {
|
|
645
|
+
if (!filesOpen) show(entry, true);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** The side pane's "Clear": the full folder again, the open document kept. */
|
|
649
|
+
function clearSideFilter() {
|
|
650
|
+
filter = '';
|
|
651
|
+
// The strip (and its button) goes: keep focus in the tree, on the open file.
|
|
652
|
+
void tick().then(() => sideBranch?.focus());
|
|
443
653
|
}
|
|
444
654
|
|
|
445
655
|
function onkeydown(event: KeyboardEvent) {
|
|
446
656
|
if (event.defaultPrevented) return;
|
|
657
|
+
if (docOpen) {
|
|
658
|
+
// Esc in a field (the viewer's page box) only leaves the field.
|
|
659
|
+
if (event.key === 'Escape' && !isTextInput(event.target)) {
|
|
660
|
+
event.preventDefault();
|
|
661
|
+
closePreview(true);
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
447
665
|
if (previewOpen) return;
|
|
448
666
|
const typing = isTextInput(event.target);
|
|
449
667
|
if (event.key === '/' && !typing && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
@@ -488,6 +706,8 @@
|
|
|
488
706
|
});
|
|
489
707
|
|
|
490
708
|
const showPane = $derived(navigationPane && wide.current && roots.length > 0);
|
|
709
|
+
// Two panes: the folder tree beside the list, or the folder's branch beside a document.
|
|
710
|
+
const split = $derived(wide.current && roots.length > 0 && (navigationPane || docOpen));
|
|
491
711
|
const rootOptions = $derived(roots.map((r) => ({ value: r.id, label: r.label })));
|
|
492
712
|
const listLabel = $derived(`${folderName} contents`);
|
|
493
713
|
|
|
@@ -514,8 +734,13 @@
|
|
|
514
734
|
|
|
515
735
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
516
736
|
<section
|
|
737
|
+
bind:this={sectionEl}
|
|
517
738
|
aria-label={label}
|
|
518
|
-
class={cn(
|
|
739
|
+
class={cn(
|
|
740
|
+
'flex min-h-0 flex-col bg-background',
|
|
741
|
+
frame && 'rounded-lg border border-border',
|
|
742
|
+
className
|
|
743
|
+
)}
|
|
519
744
|
{onkeydown}
|
|
520
745
|
data-file-browser
|
|
521
746
|
>
|
|
@@ -535,101 +760,123 @@
|
|
|
535
760
|
class="py-12"
|
|
536
761
|
/>
|
|
537
762
|
{:else}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
763
|
+
<!-- The open document's header carries the name; the branch beside it carries navigation. -->
|
|
764
|
+
{#if !docOpen}
|
|
765
|
+
<div
|
|
766
|
+
class="flex flex-col gap-3 border-b border-border p-3 md:flex-row md:flex-wrap md:items-center md:gap-x-4 md:gap-y-2"
|
|
767
|
+
data-file-browser-header
|
|
768
|
+
>
|
|
769
|
+
<div class="flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center md:flex-[1_1_16rem]">
|
|
770
|
+
{#if roots.length > 1 && !showPane}
|
|
771
|
+
<div class="sm:w-64">
|
|
772
|
+
<Select
|
|
773
|
+
label="Drive"
|
|
774
|
+
value={rootId}
|
|
775
|
+
options={rootOptions}
|
|
776
|
+
onValueChange={changeRoot}
|
|
777
|
+
hint={root?.description ?? undefined}
|
|
778
|
+
/>
|
|
779
|
+
</div>
|
|
780
|
+
{/if}
|
|
781
|
+
{#if root}
|
|
782
|
+
<FileBreadcrumbs
|
|
783
|
+
rootLabel={root.label}
|
|
784
|
+
path={currentPath}
|
|
785
|
+
onnavigate={(p) => navigate(p)}
|
|
786
|
+
class="min-w-0 flex-1"
|
|
548
787
|
/>
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
{#if root}
|
|
552
|
-
<
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
onnavigate={(p) => navigate(p)}
|
|
556
|
-
class="min-w-0 flex-1"
|
|
557
|
-
/>
|
|
788
|
+
{/if}
|
|
789
|
+
</div>
|
|
790
|
+
{#if root?.description && (roots.length === 1 || showPane)}
|
|
791
|
+
<p class="-mt-1 text-xs text-muted-foreground md:order-last md:basis-full">
|
|
792
|
+
{root.description}
|
|
793
|
+
</p>
|
|
558
794
|
{/if}
|
|
559
|
-
</div>
|
|
560
|
-
{#if root?.description && (roots.length === 1 || showPane)}
|
|
561
|
-
<p class="-mt-1 text-xs text-muted-foreground">{root.description}</p>
|
|
562
|
-
{/if}
|
|
563
795
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
</div>
|
|
588
|
-
<div class="flex items-center gap-2">
|
|
589
|
-
<Switch id={hiddenId} checked={showHidden} onchange={(v) => (showHidden = v)} />
|
|
590
|
-
<label for={hiddenId} class="text-sm">Show hidden files</label>
|
|
591
|
-
</div>
|
|
592
|
-
{#if toolbar && caps.any}
|
|
593
|
-
<div class="flex items-center gap-2" data-file-browser-toolbar>
|
|
594
|
-
{@render toolbar(context)}
|
|
796
|
+
<div class="flex flex-wrap items-center gap-x-4 gap-y-2 md:flex-[0_1_auto]">
|
|
797
|
+
<div class="relative min-w-[12rem] flex-1 md:w-56 md:flex-none">
|
|
798
|
+
<label for={filterId} class="sr-only"
|
|
799
|
+
>{source.search ? 'Search files' : 'Filter files in this folder'}</label
|
|
800
|
+
>
|
|
801
|
+
<Icon
|
|
802
|
+
name={source.search ? 'search' : 'filter'}
|
|
803
|
+
size={16}
|
|
804
|
+
class="pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"
|
|
805
|
+
/>
|
|
806
|
+
<input
|
|
807
|
+
id={filterId}
|
|
808
|
+
type="search"
|
|
809
|
+
bind:value={filter}
|
|
810
|
+
placeholder={source.search ? 'Search files' : 'Filter this folder'}
|
|
811
|
+
autocomplete="off"
|
|
812
|
+
aria-keyshortcuts="/"
|
|
813
|
+
class="flex h-9 w-full rounded-md border border-input bg-background py-1 pl-8 pr-10 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
814
|
+
/>
|
|
815
|
+
<kbd
|
|
816
|
+
class="pointer-events-none absolute right-2 top-1/2 hidden -translate-y-1/2 rounded border border-border px-1.5 text-xs text-muted-foreground sm:block"
|
|
817
|
+
aria-hidden="true">/</kbd
|
|
818
|
+
>
|
|
595
819
|
</div>
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
820
|
+
<div class="flex items-center gap-2">
|
|
821
|
+
<Switch id={hiddenId} checked={showHidden} onchange={(v) => (showHidden = v)} />
|
|
822
|
+
<label for={hiddenId} class="whitespace-nowrap text-sm">Show hidden files</label>
|
|
823
|
+
</div>
|
|
824
|
+
{#if toolbar && caps.any}
|
|
825
|
+
<div class="flex items-center gap-2" data-file-browser-toolbar>
|
|
826
|
+
{@render toolbar(context)}
|
|
827
|
+
</div>
|
|
828
|
+
{/if}
|
|
829
|
+
{#if navigationPane && !wide.current && roots.length > 0}
|
|
830
|
+
<Button
|
|
831
|
+
variant="outline"
|
|
832
|
+
size="sm"
|
|
833
|
+
onclick={() => (foldersOpen = true)}
|
|
834
|
+
aria-haspopup="dialog"
|
|
835
|
+
>
|
|
836
|
+
<Icon name="sidebar" size={16} />
|
|
837
|
+
Folders
|
|
838
|
+
</Button>
|
|
839
|
+
{/if}
|
|
840
|
+
<Button variant="ghost" size="icon" onclick={refresh} aria-label="Refresh">
|
|
841
|
+
<Icon name="refresh" size={16} />
|
|
606
842
|
</Button>
|
|
607
|
-
|
|
608
|
-
<Button variant="ghost" size="icon" onclick={refresh} aria-label="Refresh">
|
|
609
|
-
<Icon name="refresh" size={16} />
|
|
610
|
-
</Button>
|
|
843
|
+
</div>
|
|
611
844
|
</div>
|
|
612
|
-
|
|
845
|
+
{/if}
|
|
613
846
|
|
|
614
|
-
{#if
|
|
847
|
+
{#if split}
|
|
615
848
|
<ResizablePanes
|
|
616
849
|
bind:size={paneSize}
|
|
617
850
|
min={12}
|
|
618
851
|
max={50}
|
|
619
852
|
persistKey={paneKey}
|
|
620
|
-
handleLabel=
|
|
853
|
+
handleLabel={docOpen ? 'Resize file list' : 'Resize folder pane'}
|
|
621
854
|
class="min-h-0 flex-1"
|
|
622
855
|
startClass="bg-muted/20"
|
|
623
856
|
>
|
|
624
857
|
{#snippet start()}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
858
|
+
{#if docOpen}
|
|
859
|
+
<div class="h-full overflow-auto" data-file-side-list>
|
|
860
|
+
{@render sideList()}
|
|
861
|
+
</div>
|
|
862
|
+
{:else}
|
|
863
|
+
<div class="h-full overflow-auto px-1" data-file-tree-scroll>
|
|
864
|
+
{@render tree()}
|
|
865
|
+
</div>
|
|
866
|
+
{/if}
|
|
628
867
|
{/snippet}
|
|
629
868
|
{#snippet end()}
|
|
630
|
-
<div class="flex h-full min-h-0 flex-col">
|
|
869
|
+
<div class="flex h-full min-h-0 flex-col">
|
|
870
|
+
{#if docOpen}
|
|
871
|
+
{@render docPane()}
|
|
872
|
+
{:else}
|
|
873
|
+
{@render listArea()}
|
|
874
|
+
{/if}
|
|
875
|
+
</div>
|
|
631
876
|
{/snippet}
|
|
632
877
|
</ResizablePanes>
|
|
878
|
+
{:else if docOpen}
|
|
879
|
+
{@render docPane()}
|
|
633
880
|
{:else}
|
|
634
881
|
{@render listArea()}
|
|
635
882
|
{/if}
|
|
@@ -699,6 +946,79 @@
|
|
|
699
946
|
</div>
|
|
700
947
|
{/snippet}
|
|
701
948
|
|
|
949
|
+
{#snippet docPane()}
|
|
950
|
+
{#if previewEntry && rootId !== undefined}
|
|
951
|
+
<FilePreview
|
|
952
|
+
bind:this={previewer}
|
|
953
|
+
{source}
|
|
954
|
+
{rootId}
|
|
955
|
+
{rootLabel}
|
|
956
|
+
entry={previewEntry}
|
|
957
|
+
{viewers}
|
|
958
|
+
maxBytes={maxPreviewBytes}
|
|
959
|
+
{locale}
|
|
960
|
+
ondownload={(_, err) => {
|
|
961
|
+
if (err) report(err);
|
|
962
|
+
}}
|
|
963
|
+
onerror={report}
|
|
964
|
+
onclose={() => closePreview(true)}
|
|
965
|
+
onprev={prevFile ? () => prevFile && show(prevFile, true) : undefined}
|
|
966
|
+
onnext={nextFile ? () => nextFile && show(nextFile, true) : undefined}
|
|
967
|
+
start={wide.current ? undefined : filesButton}
|
|
968
|
+
class="min-h-0 flex-1"
|
|
969
|
+
/>
|
|
970
|
+
{/if}
|
|
971
|
+
{/snippet}
|
|
972
|
+
|
|
973
|
+
{#snippet filesButton()}
|
|
974
|
+
<Button variant="outline" size="sm" onclick={() => (filesOpen = true)} aria-haspopup="dialog">
|
|
975
|
+
<Icon name="list" size={16} />
|
|
976
|
+
Files
|
|
977
|
+
</Button>
|
|
978
|
+
{/snippet}
|
|
979
|
+
|
|
980
|
+
{#snippet sideList()}
|
|
981
|
+
{#if filter.trim()}
|
|
982
|
+
<!-- The filter box hides while a document is open: say why the list is short. -->
|
|
983
|
+
<div
|
|
984
|
+
class="sticky top-0 z-10 flex items-center gap-2 border-b border-border bg-background px-3 py-1.5 text-xs text-muted-foreground"
|
|
985
|
+
data-file-side-filter
|
|
986
|
+
>
|
|
987
|
+
<Icon name={source.search ? 'search' : 'filter'} size={14} class="shrink-0" />
|
|
988
|
+
<span class="min-w-0 flex-1 truncate" title={filter.trim()}>
|
|
989
|
+
<span class="sr-only">{source.search ? 'Search results for' : 'Filtered by'}</span>
|
|
990
|
+
“{filter.trim()}”
|
|
991
|
+
</span>
|
|
992
|
+
<Button
|
|
993
|
+
variant="ghost"
|
|
994
|
+
size="sm"
|
|
995
|
+
class="h-7 shrink-0 px-2"
|
|
996
|
+
aria-label={source.search ? 'Clear search' : 'Clear filter'}
|
|
997
|
+
onclick={clearSideFilter}
|
|
998
|
+
>
|
|
999
|
+
Clear
|
|
1000
|
+
</Button>
|
|
1001
|
+
</div>
|
|
1002
|
+
{/if}
|
|
1003
|
+
<FileBranch
|
|
1004
|
+
bind:this={sideBranch}
|
|
1005
|
+
{rootLabel}
|
|
1006
|
+
path={currentPath}
|
|
1007
|
+
entries={docEntries}
|
|
1008
|
+
current={previewEntry?.path}
|
|
1009
|
+
loading={status !== 'ready' || (searching && searchStatus === 'loading')}
|
|
1010
|
+
{loadingMore}
|
|
1011
|
+
{hasMore}
|
|
1012
|
+
onloadmore={loadMore}
|
|
1013
|
+
onfolder={branchFolder}
|
|
1014
|
+
onfile={branchFile}
|
|
1015
|
+
onstep={branchStep}
|
|
1016
|
+
emptyText={filter.trim() ? `Nothing matches “${filter.trim()}”` : 'This folder is empty'}
|
|
1017
|
+
label={`Files in ${folderName}`}
|
|
1018
|
+
class={wide.current ? 'px-1' : undefined}
|
|
1019
|
+
/>
|
|
1020
|
+
{/snippet}
|
|
1021
|
+
|
|
702
1022
|
{#snippet tree()}
|
|
703
1023
|
<FileTree
|
|
704
1024
|
{source}
|
|
@@ -724,9 +1044,20 @@
|
|
|
724
1044
|
</Sheet>
|
|
725
1045
|
{/if}
|
|
726
1046
|
|
|
727
|
-
{#if
|
|
1047
|
+
{#if preview === 'pane' && !wide.current && docOpen}
|
|
1048
|
+
<Sheet bind:open={filesOpen} side="left" size="sm" title="Files">
|
|
1049
|
+
<div data-file-side-list class="-mx-2">
|
|
1050
|
+
{@render sideList()}
|
|
1051
|
+
</div>
|
|
1052
|
+
</Sheet>
|
|
1053
|
+
{/if}
|
|
1054
|
+
|
|
1055
|
+
{#if preview === 'dialog' && previewEntry && rootId !== undefined}
|
|
728
1056
|
<Dialog
|
|
729
1057
|
bind:open={previewOpen}
|
|
1058
|
+
onOpenChange={(open) => {
|
|
1059
|
+
if (!open) closePreview(true);
|
|
1060
|
+
}}
|
|
730
1061
|
title={previewEntry.name}
|
|
731
1062
|
size="full"
|
|
732
1063
|
class="h-[100dvh] max-h-[100dvh] max-w-[100vw] gap-0 rounded-none sm:h-[90dvh] sm:max-h-[90dvh] sm:max-w-5xl sm:rounded-lg [&_.dialog-content]:flex [&_.dialog-content]:flex-col [&_.dialog-content]:p-0"
|