@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
|
@@ -17,12 +17,31 @@ interface Props {
|
|
|
17
17
|
* The location changed (drive, folder or both), in one call. Use this to
|
|
18
18
|
* keep the location in the URL: on a drive change `onrootchange` and
|
|
19
19
|
* `onpathchange` fire back to back, and a URL built from the current page
|
|
20
|
-
* in each would lose the first change.
|
|
20
|
+
* in each would lose the first change. In pane mode it also fires when a
|
|
21
|
+
* file opens, changes or closes, with `file` set to the open file's name.
|
|
21
22
|
*/
|
|
22
23
|
onnavigate?: (location: {
|
|
23
24
|
rootId: string;
|
|
24
25
|
path: string;
|
|
26
|
+
file?: string;
|
|
25
27
|
}) => void;
|
|
28
|
+
/**
|
|
29
|
+
* How a file opens: `'dialog'` (a modal over the list) or `'pane'` (in place
|
|
30
|
+
* of the list, with the folder tree beside it focused on the open folder's
|
|
31
|
+
* branch). Default `'dialog'`.
|
|
32
|
+
*/
|
|
33
|
+
preview?: 'dialog' | 'pane';
|
|
34
|
+
/**
|
|
35
|
+
* Name of the open file in the current folder. Bindable. Setting it opens
|
|
36
|
+
* that file (a deep link); `undefined` closes it. A name that doesn't resolve
|
|
37
|
+
* to a file in the folder is cleared and reported through `onfilechange`
|
|
38
|
+
* (and, in pane mode, `onnavigate` without `file`).
|
|
39
|
+
*/
|
|
40
|
+
file?: string;
|
|
41
|
+
/** The user opened, switched or closed a file: its name, or `undefined`. */
|
|
42
|
+
onfilechange?: (file: string | undefined) => void;
|
|
43
|
+
/** Draw the rounded border. Set false when the browser fills its container edge to edge. Default true. */
|
|
44
|
+
frame?: boolean;
|
|
26
45
|
/** Document viewers for previews, as lazy imports keyed by format. */
|
|
27
46
|
viewers?: ViewerRegistry;
|
|
28
47
|
/** Entries per page. Default 200. */
|
|
@@ -63,6 +82,6 @@ interface Props {
|
|
|
63
82
|
locale?: string | string[];
|
|
64
83
|
class?: string;
|
|
65
84
|
}
|
|
66
|
-
declare const FileBrowser: import("svelte").Component<Props, {}, "
|
|
85
|
+
declare const FileBrowser: import("svelte").Component<Props, {}, "file" | "filter" | "path" | "rootId" | "showHidden" | "paneSize">;
|
|
67
86
|
type FileBrowser = ReturnType<typeof FileBrowser>;
|
|
68
87
|
export default FileBrowser;
|
package/dist/lib/FileList.svelte
CHANGED
|
@@ -56,6 +56,13 @@
|
|
|
56
56
|
rowActions?: Snippet<[FileEntry]>;
|
|
57
57
|
/** Explanation for links. */
|
|
58
58
|
linkMessage?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Name column only: no header row, no size/date columns or row actions, tighter
|
|
61
|
+
* rows. For a narrow side list. Default false.
|
|
62
|
+
*/
|
|
63
|
+
compact?: boolean;
|
|
64
|
+
/** Path of the open file: marked `aria-current`, highlighted and kept in view. */
|
|
65
|
+
current?: string;
|
|
59
66
|
class?: string;
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -81,6 +88,8 @@
|
|
|
81
88
|
empty,
|
|
82
89
|
rowActions,
|
|
83
90
|
linkMessage = "This is a shortcut to another location and can't be opened here.",
|
|
91
|
+
compact = false,
|
|
92
|
+
current,
|
|
84
93
|
class: className,
|
|
85
94
|
}: Props = $props();
|
|
86
95
|
|
|
@@ -97,6 +106,10 @@
|
|
|
97
106
|
return i < 0 ? 0 : i;
|
|
98
107
|
});
|
|
99
108
|
|
|
109
|
+
// Without the header row, data rows start at aria-rowindex 1.
|
|
110
|
+
const headerRows = $derived(compact ? 0 : 1);
|
|
111
|
+
const showActions = $derived(!!rowActions && !compact);
|
|
112
|
+
|
|
100
113
|
const columns: { key: FileSortKey; label: string; class: string }[] = [
|
|
101
114
|
{ key: 'name', label: 'Name', class: '' },
|
|
102
115
|
{ key: 'modified', label: 'Modified', class: 'hidden sm:table-cell w-40' },
|
|
@@ -252,6 +265,13 @@
|
|
|
252
265
|
return () => observer.disconnect();
|
|
253
266
|
});
|
|
254
267
|
|
|
268
|
+
// Keep the open file in view (a long folder, or a file opened from elsewhere).
|
|
269
|
+
$effect(() => {
|
|
270
|
+
if (current === undefined || !grid) return;
|
|
271
|
+
const index = rows.findIndex((e) => e.path === current);
|
|
272
|
+
if (index >= 0) rowEl(index)?.scrollIntoView({ block: 'nearest' });
|
|
273
|
+
});
|
|
274
|
+
|
|
255
275
|
const nf = $derived(new Intl.NumberFormat(locale));
|
|
256
276
|
</script>
|
|
257
277
|
|
|
@@ -261,7 +281,12 @@
|
|
|
261
281
|
tabindex={entries.length === 0 ? -1 : undefined}
|
|
262
282
|
role={entries.length === 0 ? 'group' : undefined}
|
|
263
283
|
aria-label={entries.length === 0 ? label : undefined}
|
|
264
|
-
class={cn(
|
|
284
|
+
class={cn(
|
|
285
|
+
// Positioned, so the rows' sr-only text (absolute) scrolls with the list
|
|
286
|
+
// instead of stretching the page past the list's scroll container.
|
|
287
|
+
'relative flex min-h-0 flex-col outline-none',
|
|
288
|
+
className
|
|
289
|
+
)}
|
|
265
290
|
data-file-list
|
|
266
291
|
>
|
|
267
292
|
{#if loading && entries.length === 0}
|
|
@@ -287,49 +312,56 @@
|
|
|
287
312
|
bind:this={grid}
|
|
288
313
|
role="grid"
|
|
289
314
|
aria-label={label}
|
|
290
|
-
aria-rowcount={total !== undefined
|
|
315
|
+
aria-rowcount={total !== undefined
|
|
316
|
+
? total + headerRows
|
|
317
|
+
: hasMore
|
|
318
|
+
? -1
|
|
319
|
+
: rows.length + headerRows}
|
|
291
320
|
aria-busy={loading || loadingMore ? 'true' : undefined}
|
|
292
321
|
class="w-full table-fixed border-collapse text-sm"
|
|
293
322
|
>
|
|
294
|
-
|
|
295
|
-
<
|
|
296
|
-
{
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
323
|
+
{#if !compact}
|
|
324
|
+
<thead class="sticky top-0 z-10 bg-background">
|
|
325
|
+
<tr aria-rowindex={1} class="border-b border-border text-left text-muted-foreground">
|
|
326
|
+
{#each columns as col (col.key)}
|
|
327
|
+
<th
|
|
328
|
+
role="columnheader"
|
|
329
|
+
scope="col"
|
|
330
|
+
aria-sort={sortable ? ariaSort(col.key) : undefined}
|
|
331
|
+
class={cn('px-3 py-2 font-medium', col.class)}
|
|
332
|
+
>
|
|
333
|
+
{#if sortable}
|
|
334
|
+
<button
|
|
335
|
+
type="button"
|
|
336
|
+
class={cn(
|
|
337
|
+
'inline-flex items-center gap-1 rounded hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
338
|
+
col.key === 'size' && 'flex-row-reverse'
|
|
339
|
+
)}
|
|
340
|
+
onclick={() => toggleSort(col.key)}
|
|
341
|
+
>
|
|
342
|
+
{col.label}
|
|
343
|
+
{#if sort?.key === col.key}
|
|
344
|
+
<Icon name={sort.direction === 'asc' ? 'sort-asc' : 'sort-desc'} size={14} />
|
|
345
|
+
{/if}
|
|
346
|
+
</button>
|
|
347
|
+
{:else}
|
|
312
348
|
{col.label}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
><span class="sr-only">Actions</span></th
|
|
325
|
-
>
|
|
326
|
-
{/if}
|
|
327
|
-
</tr>
|
|
328
|
-
</thead>
|
|
349
|
+
{/if}
|
|
350
|
+
</th>
|
|
351
|
+
{/each}
|
|
352
|
+
{#if showActions}
|
|
353
|
+
<th role="columnheader" scope="col" class="w-12 px-3 py-2"
|
|
354
|
+
><span class="sr-only">Actions</span></th
|
|
355
|
+
>
|
|
356
|
+
{/if}
|
|
357
|
+
</tr>
|
|
358
|
+
</thead>
|
|
359
|
+
{/if}
|
|
329
360
|
<tbody>
|
|
330
361
|
{#each rows as entry, index (entry.path)}
|
|
331
362
|
{@const isLink = entry.type === 'link'}
|
|
332
363
|
{@const isSelected = index === activeIndex}
|
|
364
|
+
{@const isCurrent = current !== undefined && entry.path === current}
|
|
333
365
|
{@const modified = formatRelativeTime(entry.modified, { locale, now })}
|
|
334
366
|
{@const modifiedFull = formatDateTime(entry.modified, locale)}
|
|
335
367
|
{@const size = entry.type === 'file' ? formatBytes(entry.size, { locale }) : ''}
|
|
@@ -337,8 +369,9 @@
|
|
|
337
369
|
data-index={index}
|
|
338
370
|
data-path={entry.path}
|
|
339
371
|
data-type={entry.type}
|
|
340
|
-
aria-rowindex={index +
|
|
372
|
+
aria-rowindex={index + 1 + headerRows}
|
|
341
373
|
aria-selected={isSelected ? 'true' : 'false'}
|
|
374
|
+
aria-current={isCurrent ? 'true' : undefined}
|
|
342
375
|
aria-disabled={isLink ? 'true' : undefined}
|
|
343
376
|
aria-describedby={isLink ? linkNoteId : undefined}
|
|
344
377
|
tabindex={isSelected ? 0 : -1}
|
|
@@ -347,6 +380,7 @@
|
|
|
347
380
|
'group border-b border-border/60 outline-none transition-none',
|
|
348
381
|
'focus-visible:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring',
|
|
349
382
|
isSelected && 'bg-muted/50',
|
|
383
|
+
isCurrent && 'bg-primary/10 hover:bg-primary/15',
|
|
350
384
|
isLink
|
|
351
385
|
? 'cursor-not-allowed text-muted-foreground'
|
|
352
386
|
: 'cursor-pointer hover:bg-muted/60',
|
|
@@ -366,12 +400,15 @@
|
|
|
366
400
|
}
|
|
367
401
|
}}
|
|
368
402
|
>
|
|
369
|
-
<td role="gridcell" class=
|
|
370
|
-
<div class=
|
|
403
|
+
<td role="gridcell" class={compact ? 'px-3 py-1.5' : 'px-3 py-2'}>
|
|
404
|
+
<div class={cn('flex min-w-0 items-center', compact ? 'gap-2' : 'gap-3')}>
|
|
371
405
|
<FileIcon name={entry.name} type={entry.type} />
|
|
372
406
|
<div class="min-w-0 flex-1">
|
|
373
407
|
<div class="flex min-w-0 items-center gap-2">
|
|
374
|
-
<span
|
|
408
|
+
<span
|
|
409
|
+
class={cn('truncate', (!compact || isCurrent) && 'font-medium')}
|
|
410
|
+
title={entry.name}>{entry.name}</span
|
|
411
|
+
>
|
|
375
412
|
{#if isLink}
|
|
376
413
|
<span
|
|
377
414
|
class="shrink-0 rounded border border-border px-1.5 text-xs font-normal text-muted-foreground"
|
|
@@ -382,32 +419,36 @@
|
|
|
382
419
|
<span class="sr-only">(hidden)</span>
|
|
383
420
|
{/if}
|
|
384
421
|
</div>
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
422
|
+
{#if !compact}
|
|
423
|
+
<!-- Phones: size · modified under the name -->
|
|
424
|
+
<!-- Not aria-hidden: below sm it is the only place size and date are shown. -->
|
|
425
|
+
<div class="truncate text-xs text-muted-foreground sm:hidden">
|
|
426
|
+
{[size, modified].filter(Boolean).join(' · ')}
|
|
427
|
+
</div>
|
|
428
|
+
{/if}
|
|
390
429
|
</div>
|
|
391
430
|
</div>
|
|
392
431
|
</td>
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
432
|
+
{#if !compact}
|
|
433
|
+
<td role="gridcell" class="hidden px-3 py-2 text-muted-foreground sm:table-cell">
|
|
434
|
+
{#if modified}
|
|
435
|
+
<time datetime={entry.modified} title={modifiedFull}
|
|
436
|
+
>{modified}{#if !modifiedFull.startsWith(modified)}<span class="sr-only"
|
|
437
|
+
>, {modifiedFull}</span
|
|
438
|
+
>{/if}</time
|
|
439
|
+
>
|
|
440
|
+
{/if}
|
|
441
|
+
</td>
|
|
442
|
+
<td
|
|
443
|
+
role="gridcell"
|
|
444
|
+
class="hidden px-3 py-2 text-right tabular-nums text-muted-foreground sm:table-cell"
|
|
445
|
+
>
|
|
446
|
+
{size}
|
|
447
|
+
</td>
|
|
448
|
+
{/if}
|
|
449
|
+
{#if showActions}
|
|
409
450
|
<td role="gridcell" class="px-3 py-1 text-right" data-row-actions>
|
|
410
|
-
{@render rowActions(entry)}
|
|
451
|
+
{@render rowActions?.(entry)}
|
|
411
452
|
</td>
|
|
412
453
|
{/if}
|
|
413
454
|
</tr>
|
|
@@ -42,6 +42,13 @@ interface Props {
|
|
|
42
42
|
rowActions?: Snippet<[FileEntry]>;
|
|
43
43
|
/** Explanation for links. */
|
|
44
44
|
linkMessage?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name column only: no header row, no size/date columns or row actions, tighter
|
|
47
|
+
* rows. For a narrow side list. Default false.
|
|
48
|
+
*/
|
|
49
|
+
compact?: boolean;
|
|
50
|
+
/** Path of the open file: marked `aria-current`, highlighted and kept in view. */
|
|
51
|
+
current?: string;
|
|
45
52
|
class?: string;
|
|
46
53
|
}
|
|
47
54
|
declare const FileList: import("svelte").Component<Props, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
import { untrack } from 'svelte';
|
|
3
4
|
import { Alert, Button, EmptyState, Icon, Spinner } from '@classic-homes/theme-svelte';
|
|
4
5
|
import { DocumentViewer, type ViewerRegistry } from '@classic-homes/viewer-svelte';
|
|
@@ -39,6 +40,16 @@
|
|
|
39
40
|
ondownload?: (entry: FileEntry, error?: unknown) => void;
|
|
40
41
|
/** The file couldn't be loaded for preview (a 401 included), for logging or re-login. */
|
|
41
42
|
onerror?: (error: unknown) => void;
|
|
43
|
+
/** Show a trailing Close button that calls this; the preview becomes a region named after the file. */
|
|
44
|
+
onclose?: () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Previous / next file. The buttons show when either is set; the missing one
|
|
47
|
+
* is disabled (first or last file).
|
|
48
|
+
*/
|
|
49
|
+
onprev?: () => void;
|
|
50
|
+
onnext?: () => void;
|
|
51
|
+
/** Extra controls at the start of the header, before the name (e.g. a phone "Files" button). */
|
|
52
|
+
start?: Snippet;
|
|
42
53
|
class?: string;
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -64,9 +75,20 @@
|
|
|
64
75
|
locale,
|
|
65
76
|
ondownload,
|
|
66
77
|
onerror,
|
|
78
|
+
onclose,
|
|
79
|
+
onprev,
|
|
80
|
+
onnext,
|
|
81
|
+
start,
|
|
67
82
|
class: className,
|
|
68
83
|
}: Props = $props();
|
|
69
84
|
|
|
85
|
+
let rootEl = $state<HTMLElement>();
|
|
86
|
+
|
|
87
|
+
/** Move focus into the preview, e.g. after it replaces the list that had it. */
|
|
88
|
+
export function focus() {
|
|
89
|
+
rootEl?.focus();
|
|
90
|
+
}
|
|
91
|
+
|
|
70
92
|
/** Real size when the bytes exceed the cap (the listing's size was stale or missing). */
|
|
71
93
|
let oversize = $state<number>();
|
|
72
94
|
const route = $derived(previewRoute(entry, Object.keys(viewers)));
|
|
@@ -160,33 +182,93 @@
|
|
|
160
182
|
}
|
|
161
183
|
</script>
|
|
162
184
|
|
|
185
|
+
<!-- Focusable (not a tab stop) so a host can move focus here when the preview opens. -->
|
|
163
186
|
<div
|
|
164
|
-
|
|
187
|
+
bind:this={rootEl}
|
|
188
|
+
tabindex="-1"
|
|
189
|
+
role={onclose ? 'region' : undefined}
|
|
190
|
+
aria-label={onclose ? entry.name : undefined}
|
|
191
|
+
class={cn('flex h-full min-h-0 flex-col outline-none', className)}
|
|
165
192
|
data-file-preview
|
|
166
193
|
data-route={route.kind}
|
|
167
194
|
>
|
|
168
|
-
|
|
195
|
+
<!-- One row at any width: the name truncates, and below sm Details and Download
|
|
196
|
+
drop their labels. Nothing here wraps. -->
|
|
197
|
+
<div
|
|
198
|
+
class="flex min-w-0 items-center gap-1 border-b border-border px-2 py-2 sm:gap-2 sm:px-3"
|
|
199
|
+
data-file-preview-header
|
|
200
|
+
>
|
|
201
|
+
{#if start}
|
|
202
|
+
<div class="flex shrink-0 items-center">{@render start()}</div>
|
|
203
|
+
{/if}
|
|
169
204
|
{#if showTitle}
|
|
170
205
|
<FileIcon name={entry.name} type={entry.type} />
|
|
171
206
|
<h3 class="min-w-0 flex-1 truncate text-sm font-medium" title={entry.name}>{entry.name}</h3>
|
|
172
207
|
{:else}
|
|
173
208
|
<span class="flex-1"></span>
|
|
174
209
|
{/if}
|
|
210
|
+
{#if onprev || onnext}
|
|
211
|
+
<div class="flex shrink-0 items-center">
|
|
212
|
+
<Button
|
|
213
|
+
variant="ghost"
|
|
214
|
+
size="icon"
|
|
215
|
+
class="h-8 w-8"
|
|
216
|
+
aria-label="Previous file"
|
|
217
|
+
disabled={!onprev}
|
|
218
|
+
onclick={() => onprev?.()}
|
|
219
|
+
>
|
|
220
|
+
<Icon name="chevron-left" size={16} />
|
|
221
|
+
</Button>
|
|
222
|
+
<Button
|
|
223
|
+
variant="ghost"
|
|
224
|
+
size="icon"
|
|
225
|
+
class="h-8 w-8"
|
|
226
|
+
aria-label="Next file"
|
|
227
|
+
disabled={!onnext}
|
|
228
|
+
onclick={() => onnext?.()}
|
|
229
|
+
>
|
|
230
|
+
<Icon name="chevron-right" size={16} />
|
|
231
|
+
</Button>
|
|
232
|
+
</div>
|
|
233
|
+
{/if}
|
|
175
234
|
{#if willPreview}
|
|
176
235
|
<Button
|
|
177
236
|
variant="ghost"
|
|
178
237
|
size="sm"
|
|
238
|
+
class="shrink-0 px-2 sm:px-3"
|
|
239
|
+
aria-label="Details"
|
|
240
|
+
title="Details"
|
|
179
241
|
onclick={() => (showDetails = !showDetails)}
|
|
180
242
|
aria-expanded={showDetails}
|
|
181
243
|
>
|
|
182
244
|
<Icon name="info" size={16} />
|
|
183
|
-
Details
|
|
245
|
+
<span class="hidden sm:inline">Details</span>
|
|
184
246
|
</Button>
|
|
185
247
|
{/if}
|
|
186
|
-
<Button
|
|
248
|
+
<Button
|
|
249
|
+
variant="outline"
|
|
250
|
+
size="sm"
|
|
251
|
+
class="shrink-0 px-2 sm:px-3"
|
|
252
|
+
aria-label="Download"
|
|
253
|
+
title="Download"
|
|
254
|
+
loading={downloading}
|
|
255
|
+
onclick={download}
|
|
256
|
+
>
|
|
187
257
|
<Icon name="download" size={16} />
|
|
188
|
-
Download
|
|
258
|
+
<span class="hidden sm:inline">Download</span>
|
|
189
259
|
</Button>
|
|
260
|
+
{#if onclose}
|
|
261
|
+
<Button
|
|
262
|
+
variant="ghost"
|
|
263
|
+
size="icon"
|
|
264
|
+
class="h-8 w-8 shrink-0"
|
|
265
|
+
aria-label="Close preview"
|
|
266
|
+
title="Close preview"
|
|
267
|
+
onclick={onclose}
|
|
268
|
+
>
|
|
269
|
+
<Icon name="close" size={16} />
|
|
270
|
+
</Button>
|
|
271
|
+
{/if}
|
|
190
272
|
</div>
|
|
191
273
|
|
|
192
274
|
{#if downloadError}
|
|
@@ -195,9 +277,17 @@
|
|
|
195
277
|
</Alert>
|
|
196
278
|
{/if}
|
|
197
279
|
|
|
198
|
-
|
|
280
|
+
<!-- A shown file fills the body and scrolls itself (the viewer's viewport is the
|
|
281
|
+
only scroller); the other states scroll here. -->
|
|
282
|
+
<div
|
|
283
|
+
class={cn(
|
|
284
|
+
'relative flex min-h-0 flex-1 flex-col',
|
|
285
|
+
willPreview && status === 'ready' ? 'overflow-hidden' : 'overflow-auto'
|
|
286
|
+
)}
|
|
287
|
+
data-file-preview-body
|
|
288
|
+
>
|
|
199
289
|
{#if !willPreview}
|
|
200
|
-
<div class="mx-auto max-w-lg space-y-6 p-6">
|
|
290
|
+
<div class="mx-auto w-full max-w-lg space-y-6 p-6">
|
|
201
291
|
{#if tooLarge}
|
|
202
292
|
<EmptyState
|
|
203
293
|
title="Too large to preview"
|
|
@@ -218,7 +308,7 @@
|
|
|
218
308
|
<FileDetails {entry} {rootLabel} {locale} />
|
|
219
309
|
</div>
|
|
220
310
|
{:else if status === 'loading'}
|
|
221
|
-
<div class="flex
|
|
311
|
+
<div class="flex min-h-48 flex-1 items-center justify-center" role="status">
|
|
222
312
|
<Spinner />
|
|
223
313
|
<span class="sr-only">Loading {entry.name}…</span>
|
|
224
314
|
</div>
|
|
@@ -226,24 +316,33 @@
|
|
|
226
316
|
<FileErrorState {error} onretry={() => attempt++} class="py-10" />
|
|
227
317
|
{:else if status === 'ready' && blob}
|
|
228
318
|
{#if showDetails}
|
|
229
|
-
<div
|
|
319
|
+
<div
|
|
320
|
+
class="max-h-[35vh] shrink-0 overflow-auto border-b border-border p-4"
|
|
321
|
+
data-file-preview-details
|
|
322
|
+
>
|
|
230
323
|
<FileDetails {entry} {rootLabel} {locale} />
|
|
231
324
|
</div>
|
|
232
325
|
{/if}
|
|
233
326
|
{#if route.kind === 'image'}
|
|
234
327
|
{#if imageUrl}
|
|
235
|
-
<div
|
|
328
|
+
<div
|
|
329
|
+
class="flex min-h-0 flex-1 items-center justify-center overflow-auto bg-muted/30 p-4"
|
|
330
|
+
>
|
|
236
331
|
<img src={imageUrl} alt={entry.name} class="max-h-full max-w-full object-contain" />
|
|
237
332
|
</div>
|
|
238
333
|
{/if}
|
|
239
334
|
{:else if route.kind === 'document'}
|
|
335
|
+
<!-- The header above owns the name and Download: no second frame, title or button. -->
|
|
240
336
|
<DocumentViewer
|
|
241
337
|
source={blob}
|
|
242
338
|
{viewers}
|
|
243
339
|
name={entry.name}
|
|
244
340
|
mime={blob.type || undefined}
|
|
245
341
|
{maxBytes}
|
|
246
|
-
|
|
342
|
+
frame={false}
|
|
343
|
+
hideTitle
|
|
344
|
+
allowDownload={false}
|
|
345
|
+
class="min-h-0 flex-1"
|
|
247
346
|
/>
|
|
248
347
|
{/if}
|
|
249
348
|
{/if}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import { type ViewerRegistry } from '@classic-homes/viewer-svelte';
|
|
2
3
|
import { type FileEntry, type FilesSource } from '@classic-homes/files-core';
|
|
3
4
|
interface Props {
|
|
@@ -21,8 +22,20 @@ interface Props {
|
|
|
21
22
|
ondownload?: (entry: FileEntry, error?: unknown) => void;
|
|
22
23
|
/** The file couldn't be loaded for preview (a 401 included), for logging or re-login. */
|
|
23
24
|
onerror?: (error: unknown) => void;
|
|
25
|
+
/** Show a trailing Close button that calls this; the preview becomes a region named after the file. */
|
|
26
|
+
onclose?: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Previous / next file. The buttons show when either is set; the missing one
|
|
29
|
+
* is disabled (first or last file).
|
|
30
|
+
*/
|
|
31
|
+
onprev?: () => void;
|
|
32
|
+
onnext?: () => void;
|
|
33
|
+
/** Extra controls at the start of the header, before the name (e.g. a phone "Files" button). */
|
|
34
|
+
start?: Snippet;
|
|
24
35
|
class?: string;
|
|
25
36
|
}
|
|
26
|
-
declare const FilePreview: import("svelte").Component<Props, {
|
|
37
|
+
declare const FilePreview: import("svelte").Component<Props, {
|
|
38
|
+
focus: () => void;
|
|
39
|
+
}, "">;
|
|
27
40
|
type FilePreview = ReturnType<typeof FilePreview>;
|
|
28
41
|
export default FilePreview;
|
package/dist/lib/FileTree.svelte
CHANGED
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
type FilesSource,
|
|
18
18
|
} from '@classic-homes/files-core';
|
|
19
19
|
import FileIcon from './FileIcon.svelte';
|
|
20
|
+
import {
|
|
21
|
+
noteIndent,
|
|
22
|
+
treeChevronClass,
|
|
23
|
+
treeIndent,
|
|
24
|
+
treeRowClass,
|
|
25
|
+
TREE_CLASS,
|
|
26
|
+
TREE_NOTE_CLASS,
|
|
27
|
+
} from './tree-rows.js';
|
|
20
28
|
import { cn } from './utils.js';
|
|
21
29
|
|
|
22
30
|
interface Props {
|
|
@@ -406,16 +414,12 @@
|
|
|
406
414
|
bind:this={tree}
|
|
407
415
|
role="tree"
|
|
408
416
|
aria-label={label}
|
|
409
|
-
class={cn(
|
|
417
|
+
class={cn(TREE_CLASS, className)}
|
|
410
418
|
data-file-tree
|
|
411
419
|
>
|
|
412
420
|
{#each rows as row (row.kind === 'item' ? row.item.key : row.key)}
|
|
413
421
|
{#if row.kind === 'note'}
|
|
414
|
-
<li
|
|
415
|
-
role="none"
|
|
416
|
-
style:padding-left="{row.level * 0.875 + 0.5}rem"
|
|
417
|
-
class="py-1 text-xs text-muted-foreground"
|
|
418
|
-
>
|
|
422
|
+
<li role="none" style:padding-left={noteIndent(row.level)} class={TREE_NOTE_CLASS}>
|
|
419
423
|
{row.text}
|
|
420
424
|
</li>
|
|
421
425
|
{:else}
|
|
@@ -433,14 +437,8 @@
|
|
|
433
437
|
aria-selected={current}
|
|
434
438
|
aria-current={current ? 'location' : undefined}
|
|
435
439
|
tabindex={item.key === tabKey ? 0 : -1}
|
|
436
|
-
class={
|
|
437
|
-
|
|
438
|
-
'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring',
|
|
439
|
-
current ? 'bg-chart-1/15 font-medium text-foreground' : 'hover:bg-muted/60',
|
|
440
|
-
// Hidden folders: muted and italic, not faded (opacity fails contrast).
|
|
441
|
-
item.hidden && 'italic text-muted-foreground'
|
|
442
|
-
)}
|
|
443
|
-
style:padding-left="{(item.level - 1) * 0.875 + 0.25}rem"
|
|
440
|
+
class={treeRowClass({ current, hidden: item.hidden })}
|
|
441
|
+
style:padding-left={treeIndent(item.level)}
|
|
444
442
|
title={item.name}
|
|
445
443
|
onclick={() => choose(item)}
|
|
446
444
|
onkeydown={(e) => onkeydown(e, item)}
|
|
@@ -449,10 +447,7 @@
|
|
|
449
447
|
<!-- Chevron: expand/collapse without opening (as in Explorer). Keyboard: Right/Left. -->
|
|
450
448
|
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
451
449
|
<span
|
|
452
|
-
class={
|
|
453
|
-
'flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted',
|
|
454
|
-
leaf && 'invisible'
|
|
455
|
-
)}
|
|
450
|
+
class={treeChevronClass(leaf)}
|
|
456
451
|
aria-hidden="true"
|
|
457
452
|
onclick={(e) => {
|
|
458
453
|
e.stopPropagation();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tree itself. Positioned, so absolutely positioned sr-only text in its rows
|
|
3
|
+
* scrolls with the pane instead of stretching the page past the scroll container.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TREE_CLASS = "relative select-none py-1 text-sm";
|
|
6
|
+
/** Left padding of a treeitem at `level` (1 = a drive). */
|
|
7
|
+
export declare const treeIndent: (level: number) => string;
|
|
8
|
+
/** Left padding of a note row (Loading…, empty) under items at `level`. */
|
|
9
|
+
export declare const noteIndent: (level: number) => string;
|
|
10
|
+
export declare const TREE_NOTE_CLASS = "py-1 text-xs text-muted-foreground";
|
|
11
|
+
/** A treeitem: `current` is the highlighted row (open folder, or open file). */
|
|
12
|
+
export declare function treeRowClass(opts: {
|
|
13
|
+
current?: boolean;
|
|
14
|
+
hidden?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
/** The chevron slot before the icon; `leaf` keeps its space but hides it. */
|
|
18
|
+
export declare function treeChevronClass(leaf: boolean): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row styling shared by the folder tree (FileTree) and the open document's
|
|
3
|
+
* branch (FileBranch), so the left pane looks the same with or without a file
|
|
4
|
+
* open.
|
|
5
|
+
*/
|
|
6
|
+
import { cn } from './utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* The tree itself. Positioned, so absolutely positioned sr-only text in its rows
|
|
9
|
+
* scrolls with the pane instead of stretching the page past the scroll container.
|
|
10
|
+
*/
|
|
11
|
+
export const TREE_CLASS = 'relative select-none py-1 text-sm';
|
|
12
|
+
/** Left padding of a treeitem at `level` (1 = a drive). */
|
|
13
|
+
export const treeIndent = (level) => `${(level - 1) * 0.875 + 0.25}rem`;
|
|
14
|
+
/** Left padding of a note row (Loading…, empty) under items at `level`. */
|
|
15
|
+
export const noteIndent = (level) => `${level * 0.875 + 0.5}rem`;
|
|
16
|
+
export const TREE_NOTE_CLASS = 'py-1 text-xs text-muted-foreground';
|
|
17
|
+
/** A treeitem: `current` is the highlighted row (open folder, or open file). */
|
|
18
|
+
export function treeRowClass(opts) {
|
|
19
|
+
return cn('flex items-center gap-1 rounded-sm py-1 pr-2 outline-none', 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring', opts.current ? 'bg-chart-1/15 font-medium text-foreground' : 'hover:bg-muted/60', opts.disabled ? 'cursor-not-allowed text-muted-foreground' : 'cursor-pointer',
|
|
20
|
+
// Hidden entries: muted and italic, not faded (opacity fails contrast).
|
|
21
|
+
opts.hidden && 'italic text-muted-foreground');
|
|
22
|
+
}
|
|
23
|
+
/** The chevron slot before the icon; `leaf` keeps its space but hides it. */
|
|
24
|
+
export function treeChevronClass(leaf) {
|
|
25
|
+
return cn('flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted', leaf && 'invisible');
|
|
26
|
+
}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -14,3 +14,16 @@ export declare function downloadEntry(source: FilesSource, rootId: string, entry
|
|
|
14
14
|
}): Promise<void>;
|
|
15
15
|
/** True when a key event comes from a place that types text. */
|
|
16
16
|
export declare function isTextInput(target: EventTarget | null): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Split a file name for middle truncation: the head shrinks (ellipsis), the
|
|
19
|
+
* tail always shows. The tail is the extension (from the last dot, unless the
|
|
20
|
+
* dot leads the name or the extension is over 10 characters) plus the 6
|
|
21
|
+
* characters before it, never splitting a character (grapheme). The split moves
|
|
22
|
+
* left off whitespace, so neither part starts or ends with a space and the
|
|
23
|
+
* name renders exactly as one span would. `null` for names of 16 characters or
|
|
24
|
+
* fewer, or when no head would be left.
|
|
25
|
+
*/
|
|
26
|
+
export declare function splitNameTail(name: string): {
|
|
27
|
+
head: string;
|
|
28
|
+
tail: string;
|
|
29
|
+
} | null;
|