@classic-homes/files-svelte 0.4.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.
@@ -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, {}, "path" | "filter" | "rootId" | "showHidden" | "paneSize">;
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;
@@ -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('flex min-h-0 flex-col outline-none', className)}
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 ? total + 1 : hasMore ? -1 : rows.length + 1}
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
- <thead class="sticky top-0 z-10 bg-background">
295
- <tr aria-rowindex={1} class="border-b border-border text-left text-muted-foreground">
296
- {#each columns as col (col.key)}
297
- <th
298
- role="columnheader"
299
- scope="col"
300
- aria-sort={sortable ? ariaSort(col.key) : undefined}
301
- class={cn('px-3 py-2 font-medium', col.class)}
302
- >
303
- {#if sortable}
304
- <button
305
- type="button"
306
- class={cn(
307
- 'inline-flex items-center gap-1 rounded hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
308
- col.key === 'size' && 'flex-row-reverse'
309
- )}
310
- onclick={() => toggleSort(col.key)}
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
- {#if sort?.key === col.key}
314
- <Icon name={sort.direction === 'asc' ? 'sort-asc' : 'sort-desc'} size={14} />
315
- {/if}
316
- </button>
317
- {:else}
318
- {col.label}
319
- {/if}
320
- </th>
321
- {/each}
322
- {#if rowActions}
323
- <th role="columnheader" scope="col" class="w-12 px-3 py-2"
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 + 2}
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="px-3 py-2">
370
- <div class="flex min-w-0 items-center gap-3">
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 class="truncate font-medium" title={entry.name}>{entry.name}</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
- <!-- Phones: size · modified under the name -->
386
- <!-- Not aria-hidden: below sm it is the only place size and date are shown. -->
387
- <div class="truncate text-xs text-muted-foreground sm:hidden">
388
- {[size, modified].filter(Boolean).join(' · ')}
389
- </div>
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
- <td role="gridcell" class="hidden px-3 py-2 text-muted-foreground sm:table-cell">
394
- {#if modified}
395
- <time datetime={entry.modified} title={modifiedFull}
396
- >{modified}{#if !modifiedFull.startsWith(modified)}<span class="sr-only"
397
- >, {modifiedFull}</span
398
- >{/if}</time
399
- >
400
- {/if}
401
- </td>
402
- <td
403
- role="gridcell"
404
- class="hidden px-3 py-2 text-right tabular-nums text-muted-foreground sm:table-cell"
405
- >
406
- {size}
407
- </td>
408
- {#if rowActions}
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
- class={cn('flex h-full min-h-0 flex-col', className)}
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
- <div class="flex flex-wrap items-center gap-2 border-b border-border px-3 py-2">
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 variant="outline" size="sm" loading={downloading} onclick={download}>
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
- <div class="relative min-h-0 flex-1 overflow-auto">
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 h-full min-h-48 items-center justify-center" role="status">
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 class="border-b border-border p-4">
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 class="flex min-h-full items-center justify-center bg-muted/30 p-4">
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
- class="h-full min-h-[24rem]"
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;
@@ -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('select-none py-1 text-sm', className)}
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={cn(
437
- 'flex cursor-pointer items-center gap-1 rounded-sm py-1 pr-2 outline-none',
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={cn(
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();
@@ -8,5 +8,5 @@ export { default as FileDetails } from './FileDetails.svelte';
8
8
  export { default as FileErrorState } from './FileErrorState.svelte';
9
9
  export type { FileBrowserContext } from './types.js';
10
10
  export { downloadEntry } from './utils.js';
11
- export { createChapiFilesSource, createMemoryFilesSource, FilesError, isFilesError, describeFilesError, writeCapabilities, formatBytes, formatDateTime, formatRelativeTime, joinPath, parentPath, normalizePath, pathSegments, displayPath, baseName, kindForName, kindForEntry, fileExtension, KIND_LABELS, previewRoute, sortEntries, filterEntries, compareEntries, isAbortError, saveBlob, type FileEntry, type FileEntryType, type FileKind, type FileListPage, type FileRoot, type FileSort, type FileSortKey, type FilesErrorCode, type FilesSource, type ListOptions, type SearchOptions, type WriteCapabilities, type PreviewRoute, type ChapiFilesSourceOptions, type MemoryFile, type MemoryRoot, type MemoryFilesSourceOptions, } from '@classic-homes/files-core';
11
+ export { createChapiFilesSource, createMemoryFilesSource, FilesError, isFilesError, describeFilesError, writeCapabilities, formatBytes, formatDateTime, formatRelativeTime, joinPath, parentPath, normalizePath, pathSegments, displayPath, baseName, kindForName, kindForEntry, fileExtension, KIND_LABELS, previewRoute, sortEntries, filterEntries, compareEntries, isAbortError, saveBlob, openDownloadLink, type FileEntry, type FileEntryType, type FileKind, type FileListPage, type FileRoot, type FileSort, type FileSortKey, type FilesErrorCode, type FilesSource, type ListOptions, type SearchOptions, type WriteCapabilities, type PreviewRoute, type DownloadLink, type ChapiFilesSourceOptions, type MemoryFile, type MemoryRoot, type MemoryFilesSourceOptions, } from '@classic-homes/files-core';
12
12
  export type { ViewerRegistry } from '@classic-homes/viewer-svelte';
package/dist/lib/index.js CHANGED
@@ -8,4 +8,4 @@ export { default as FileDetails } from './FileDetails.svelte';
8
8
  export { default as FileErrorState } from './FileErrorState.svelte';
9
9
  export { downloadEntry } from './utils.js';
10
10
  // Core re-exports most consumers need alongside the components
11
- export { createChapiFilesSource, createMemoryFilesSource, FilesError, isFilesError, describeFilesError, writeCapabilities, formatBytes, formatDateTime, formatRelativeTime, joinPath, parentPath, normalizePath, pathSegments, displayPath, baseName, kindForName, kindForEntry, fileExtension, KIND_LABELS, previewRoute, sortEntries, filterEntries, compareEntries, isAbortError, saveBlob, } from '@classic-homes/files-core';
11
+ export { createChapiFilesSource, createMemoryFilesSource, FilesError, isFilesError, describeFilesError, writeCapabilities, formatBytes, formatDateTime, formatRelativeTime, joinPath, parentPath, normalizePath, pathSegments, displayPath, baseName, kindForName, kindForEntry, fileExtension, KIND_LABELS, previewRoute, sortEntries, filterEntries, compareEntries, isAbortError, saveBlob, openDownloadLink, } from '@classic-homes/files-core';
@@ -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;