@classic-homes/files-svelte 0.0.0-stage → 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.
@@ -0,0 +1,58 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { ViewerRegistry } from '@classic-homes/viewer-svelte';
3
+ import { type FileEntry, type FilesSource } from '@classic-homes/files-core';
4
+ import type { FileBrowserContext } from './types.js';
5
+ interface Props {
6
+ /** Where the data comes from: `createChapiFilesSource()`, `createMemoryFilesSource()` or your own. */
7
+ source: FilesSource;
8
+ /** Current root. Bindable; defaults to the first root the caller can read. */
9
+ rootId?: string;
10
+ /** Current folder, root-relative (`''` = the root). Bindable. */
11
+ path?: string;
12
+ /** The user picked another root. Put it in the URL to make Back/Forward work. */
13
+ onrootchange?: (rootId: string) => void;
14
+ /** The user opened another folder. */
15
+ onpathchange?: (path: string) => void;
16
+ /** Document viewers for previews, as lazy imports keyed by format. */
17
+ viewers?: ViewerRegistry;
18
+ /** Entries per page. Default 200. */
19
+ pageSize?: number;
20
+ /** Load the next page on scroll instead of only with "Load more". Default false. */
21
+ autoLoad?: boolean;
22
+ /** "Show hidden files". Bindable. */
23
+ showHidden?: boolean;
24
+ /** Filter text. Bindable. Narrows the loaded entries (or searches, when the source can). */
25
+ filter?: string;
26
+ /** Larger files are not fetched for preview. Default 100 MB. */
27
+ maxPreviewBytes?: number;
28
+ /** A request got a 401: hand it to the app's auth (re-login). */
29
+ onunauthorized?: (error: unknown) => void;
30
+ /** Any listing or preview error, for logging. */
31
+ onerror?: (error: unknown) => void;
32
+ /** A file was opened for preview. */
33
+ onpreview?: (entry: FileEntry) => void;
34
+ /**
35
+ * Write toolbar (upload, new folder…). Rendered only when the source has a
36
+ * write method AND the root's `canWrite` is true. The pilot shows nothing.
37
+ */
38
+ toolbar?: Snippet<[FileBrowserContext]>;
39
+ /** Per-row write actions, under the same rule as `toolbar`. */
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;
51
+ /** Accessible name of the browser region. Default "File browser". */
52
+ label?: string;
53
+ locale?: string | string[];
54
+ class?: string;
55
+ }
56
+ declare const FileBrowser: import("svelte").Component<Props, {}, "path" | "filter" | "rootId" | "showHidden" | "paneSize">;
57
+ type FileBrowser = ReturnType<typeof FileBrowser>;
58
+ export default FileBrowser;
@@ -0,0 +1,68 @@
1
+ <script lang="ts">
2
+ import { CopyButton } from '@classic-homes/theme-svelte';
3
+ import {
4
+ KIND_LABELS,
5
+ displayPath,
6
+ fileExtension,
7
+ formatBytes,
8
+ formatDateTime,
9
+ kindForEntry,
10
+ parentPath,
11
+ type FileEntry,
12
+ } from '@classic-homes/files-core';
13
+ import { cn } from './utils.js';
14
+
15
+ interface Props {
16
+ entry: FileEntry;
17
+ /** Root label, used for the location and "Copy path". */
18
+ rootLabel: string;
19
+ locale?: string | string[];
20
+ class?: string;
21
+ }
22
+
23
+ let { entry, rootLabel, locale, class: className }: Props = $props();
24
+
25
+ const nf = $derived(new Intl.NumberFormat(locale));
26
+ const kind = $derived(kindForEntry(entry));
27
+ const ext = $derived(entry.type === 'file' ? fileExtension(entry.name) : '');
28
+ const typeLabel = $derived(
29
+ kind === 'generic' && ext ? `${ext.toUpperCase()} file` : KIND_LABELS[kind]
30
+ );
31
+ // Root label plus path, for pasting into chat. Never a UNC path: staff never see server names.
32
+ const copyText = $derived(displayPath(rootLabel, entry.path));
33
+ </script>
34
+
35
+ <div class={cn('space-y-4 text-sm', className)} data-file-details>
36
+ <dl class="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-2">
37
+ <dt class="text-muted-foreground">Name</dt>
38
+ <dd class="break-all font-medium">{entry.name}</dd>
39
+ <dt class="text-muted-foreground">Location</dt>
40
+ <dd class="break-words">{displayPath(rootLabel, parentPath(entry.path))}</dd>
41
+ <dt class="text-muted-foreground">Type</dt>
42
+ <dd>{typeLabel}{entry.hidden ? ' (hidden)' : ''}</dd>
43
+ {#if entry.type === 'file'}
44
+ <dt class="text-muted-foreground">Size</dt>
45
+ <dd>
46
+ {formatBytes(entry.size, { locale })}
47
+ <span class="text-muted-foreground">({nf.format(entry.size)} bytes)</span>
48
+ </dd>
49
+ {/if}
50
+ {#if entry.modified}
51
+ <dt class="text-muted-foreground">Modified</dt>
52
+ <dd>
53
+ <time datetime={entry.modified}
54
+ >{formatDateTime(entry.modified, locale, { dateStyle: 'full', timeStyle: 'short' })}</time
55
+ >
56
+ </dd>
57
+ {/if}
58
+ </dl>
59
+ <CopyButton
60
+ value={copyText}
61
+ variant="outline"
62
+ size="sm"
63
+ label="Copy path"
64
+ copiedLabel="Path copied"
65
+ >
66
+ Copy path
67
+ </CopyButton>
68
+ </div>
@@ -0,0 +1,11 @@
1
+ import { type FileEntry } from '@classic-homes/files-core';
2
+ interface Props {
3
+ entry: FileEntry;
4
+ /** Root label, used for the location and "Copy path". */
5
+ rootLabel: string;
6
+ locale?: string | string[];
7
+ class?: string;
8
+ }
9
+ declare const FileDetails: import("svelte").Component<Props, {}, "">;
10
+ type FileDetails = ReturnType<typeof FileDetails>;
11
+ export default FileDetails;
@@ -0,0 +1,73 @@
1
+ <script lang="ts">
2
+ import { onDestroy } from 'svelte';
3
+ import { Button, EmptyState, type IconName } from '@classic-homes/theme-svelte';
4
+ import { describeFilesError, isFilesError, type FilesErrorCode } from '@classic-homes/files-core';
5
+
6
+ interface Props {
7
+ error: unknown;
8
+ /** Offer "Try again" (for retryable errors). */
9
+ onretry?: () => void;
10
+ /** Offer "Back to the top folder" (for bad or missing paths). */
11
+ onroot?: () => void;
12
+ /** Label of the root, for the back button. */
13
+ rootLabel?: string;
14
+ size?: 'sm' | 'md';
15
+ class?: string;
16
+ }
17
+
18
+ let { error, onretry, onroot, rootLabel, size = 'md', class: className }: Props = $props();
19
+
20
+ const info = $derived(describeFilesError(error));
21
+ const code = $derived<FilesErrorCode>(isFilesError(error) ? error.code : 'unknown');
22
+
23
+ const ICONS: Partial<Record<FilesErrorCode, IconName>> = {
24
+ link_not_followed: 'link',
25
+ access_denied: 'lock',
26
+ not_found: 'folder-minus',
27
+ locked: 'lock',
28
+ unauthorized: 'user-x',
29
+ unavailable: 'alert-triangle',
30
+ timeout: 'alert-triangle',
31
+ file_server_error: 'alert-triangle',
32
+ network: 'alert-triangle',
33
+ };
34
+
35
+ // Retry-After: hold the button until the server says to try again.
36
+ let wait = $state(0);
37
+ let timer: ReturnType<typeof setInterval> | undefined;
38
+ $effect(() => {
39
+ clearInterval(timer);
40
+ // Read `error` only: reading `wait` here would restart the countdown every tick.
41
+ const seconds = isFilesError(error) && error.retryAfter ? Math.min(error.retryAfter, 600) : 0;
42
+ wait = seconds;
43
+ if (seconds > 0) {
44
+ timer = setInterval(() => {
45
+ wait = Math.max(0, wait - 1);
46
+ if (wait === 0) clearInterval(timer);
47
+ }, 1000);
48
+ }
49
+ return () => clearInterval(timer);
50
+ });
51
+ onDestroy(() => clearInterval(timer));
52
+ </script>
53
+
54
+ <EmptyState
55
+ title={info.title}
56
+ description={info.description}
57
+ icon={ICONS[code] ?? 'alert-circle'}
58
+ {size}
59
+ headingLevel="h3"
60
+ class={className}
61
+ >
62
+ {#snippet actions()}
63
+ {#if info.action === 'retry' && onretry}
64
+ <Button variant="outline" disabled={wait > 0} onclick={() => onretry?.()}>
65
+ {wait > 0 ? `Try again in ${wait}s` : 'Try again'}
66
+ </Button>
67
+ {:else if info.action === 'root' && onroot}
68
+ <Button variant="outline" onclick={() => onroot?.()}>
69
+ Back to {rootLabel ?? 'the top folder'}
70
+ </Button>
71
+ {/if}
72
+ {/snippet}
73
+ </EmptyState>
@@ -0,0 +1,14 @@
1
+ interface Props {
2
+ error: unknown;
3
+ /** Offer "Try again" (for retryable errors). */
4
+ onretry?: () => void;
5
+ /** Offer "Back to the top folder" (for bad or missing paths). */
6
+ onroot?: () => void;
7
+ /** Label of the root, for the back button. */
8
+ rootLabel?: string;
9
+ size?: 'sm' | 'md';
10
+ class?: string;
11
+ }
12
+ declare const FileErrorState: import("svelte").Component<Props, {}, "">;
13
+ type FileErrorState = ReturnType<typeof FileErrorState>;
14
+ export default FileErrorState;
@@ -0,0 +1,48 @@
1
+ <script lang="ts">
2
+ import { Icon, type IconName } from '@classic-homes/theme-svelte';
3
+ import { kindForEntry, type FileEntryType, type FileKind } from '@classic-homes/files-core';
4
+ import { cn } from './utils.js';
5
+
6
+ interface Props {
7
+ /** Kind to show. Derived from `name` and `type` when omitted. */
8
+ kind?: FileKind;
9
+ /** File name, for the extension. */
10
+ name?: string;
11
+ /** Entry type. Default `'file'`. */
12
+ type?: FileEntryType;
13
+ /** Pixel size. Default 20. */
14
+ size?: number;
15
+ /** Accessible label. Omit for a decorative icon (the usual case next to a name). */
16
+ label?: string;
17
+ class?: string;
18
+ }
19
+
20
+ let { kind, name = '', type = 'file', size = 20, label, class: className }: Props = $props();
21
+
22
+ const resolved = $derived<FileKind>(kind ?? kindForEntry({ name, type }));
23
+
24
+ // Shape tells kinds apart; colour only reinforces it.
25
+ const ICONS: Record<FileKind, { icon: IconName; tone: string }> = {
26
+ folder: { icon: 'folder', tone: 'text-warning' },
27
+ link: { icon: 'link', tone: 'text-muted-foreground' },
28
+ pdf: { icon: 'file-text', tone: 'text-destructive' },
29
+ word: { icon: 'file-text', tone: 'text-info' },
30
+ excel: { icon: 'grid', tone: 'text-success' },
31
+ csv: { icon: 'list', tone: 'text-success' },
32
+ cad: { icon: 'layers', tone: 'text-chart-4' },
33
+ image: { icon: 'image', tone: 'text-chart-2' },
34
+ archive: { icon: 'archive', tone: 'text-muted-foreground' },
35
+ text: { icon: 'file-code', tone: 'text-muted-foreground' },
36
+ generic: { icon: 'file', tone: 'text-muted-foreground' },
37
+ };
38
+
39
+ const spec = $derived(ICONS[resolved]);
40
+ </script>
41
+
42
+ <span
43
+ class={cn('inline-flex shrink-0 items-center justify-center', spec.tone, className)}
44
+ data-file-kind={resolved}
45
+ aria-hidden={label ? undefined : 'true'}
46
+ >
47
+ <Icon name={spec.icon} {size} {label} strokeWidth={1.75} />
48
+ </span>
@@ -0,0 +1,17 @@
1
+ import { type FileEntryType, type FileKind } from '@classic-homes/files-core';
2
+ interface Props {
3
+ /** Kind to show. Derived from `name` and `type` when omitted. */
4
+ kind?: FileKind;
5
+ /** File name, for the extension. */
6
+ name?: string;
7
+ /** Entry type. Default `'file'`. */
8
+ type?: FileEntryType;
9
+ /** Pixel size. Default 20. */
10
+ size?: number;
11
+ /** Accessible label. Omit for a decorative icon (the usual case next to a name). */
12
+ label?: string;
13
+ class?: string;
14
+ }
15
+ declare const FileIcon: import("svelte").Component<Props, {}, "">;
16
+ type FileIcon = ReturnType<typeof FileIcon>;
17
+ export default FileIcon;
@@ -0,0 +1,393 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { tick } from 'svelte';
4
+ import { Button, EmptyState, Icon, Skeleton } from '@classic-homes/theme-svelte';
5
+ import {
6
+ formatBytes,
7
+ formatDateTime,
8
+ formatRelativeTime,
9
+ sortEntries,
10
+ type FileEntry,
11
+ type FileSort,
12
+ type FileSortKey,
13
+ } from '@classic-homes/files-core';
14
+ import FileIcon from './FileIcon.svelte';
15
+ import { cn } from './utils.js';
16
+
17
+ interface Props {
18
+ /** Entries to show, in display order (the server's order unless `sort` is set). */
19
+ entries: FileEntry[];
20
+ /** Path of the selected (focused) row. Bindable. */
21
+ selected?: string;
22
+ /** A folder or file was opened (click, tap or Enter). Never called for links. */
23
+ onopen?: (entry: FileEntry) => void;
24
+ /** The selected row changed. */
25
+ onselect?: (entry: FileEntry | undefined) => void;
26
+ /** Backspace or Alt+Up inside the list. */
27
+ onup?: () => void;
28
+ /** Client-side column sort over the loaded entries; `null` keeps the given order. Bindable. */
29
+ sort?: FileSort | null;
30
+ /** Offer sortable column headers. Default true. */
31
+ sortable?: boolean;
32
+ /** First page loading: shows skeleton rows. */
33
+ loading?: boolean;
34
+ /** A further page is loading. */
35
+ loadingMore?: boolean;
36
+ /** More pages exist on the server. */
37
+ hasMore?: boolean;
38
+ /** Load the next page ("Load more", or automatically with `autoLoad`). */
39
+ onloadmore?: () => void;
40
+ /** Load the next page when the end of the list scrolls into view. Default false. */
41
+ autoLoad?: boolean;
42
+ /** Entries in the whole folder, for "Showing N of total". */
43
+ total?: number;
44
+ /** Show "Showing N of total" under the list. Default true. */
45
+ showCount?: boolean;
46
+ /** Accessible name of the grid. Default "Files". */
47
+ label?: string;
48
+ locale?: string | string[];
49
+ /** Reference time for relative dates (tests). */
50
+ now?: number;
51
+ /** Title of the empty state. Default "This folder is empty". */
52
+ emptyTitle?: string;
53
+ /** Replaces the empty state. */
54
+ empty?: Snippet;
55
+ /** Per-row actions (write actions later). Rendered at the end of each row. */
56
+ rowActions?: Snippet<[FileEntry]>;
57
+ /** Explanation for links. */
58
+ linkMessage?: string;
59
+ class?: string;
60
+ }
61
+
62
+ let {
63
+ entries,
64
+ selected = $bindable(),
65
+ onopen,
66
+ onselect,
67
+ onup,
68
+ sort = $bindable(null),
69
+ sortable = true,
70
+ loading = false,
71
+ loadingMore = false,
72
+ hasMore = false,
73
+ onloadmore,
74
+ autoLoad = false,
75
+ total,
76
+ showCount = true,
77
+ label = 'Files',
78
+ locale,
79
+ now,
80
+ emptyTitle = 'This folder is empty',
81
+ empty,
82
+ rowActions,
83
+ linkMessage = "This is a shortcut to another location and can't be opened here.",
84
+ class: className,
85
+ }: Props = $props();
86
+
87
+ const uid = $props.id();
88
+ const linkNoteId = `${uid}-link-note`;
89
+
90
+ let grid = $state<HTMLTableElement>();
91
+ let sentinel = $state<HTMLElement>();
92
+
93
+ const rows = $derived(sort ? sortEntries(entries, sort) : entries);
94
+ const activeIndex = $derived.by(() => {
95
+ const i = selected === undefined ? -1 : rows.findIndex((e) => e.path === selected);
96
+ return i < 0 ? 0 : i;
97
+ });
98
+
99
+ const columns: { key: FileSortKey; label: string; class: string }[] = [
100
+ { key: 'name', label: 'Name', class: '' },
101
+ { key: 'modified', label: 'Modified', class: 'hidden sm:table-cell w-40' },
102
+ { key: 'size', label: 'Size', class: 'hidden sm:table-cell w-28 text-right' },
103
+ ];
104
+
105
+ function ariaSort(key: FileSortKey): 'ascending' | 'descending' | 'none' {
106
+ if (!sort || sort.key !== key) return 'none';
107
+ return sort.direction === 'asc' ? 'ascending' : 'descending';
108
+ }
109
+
110
+ /** Name → asc → desc → server order. */
111
+ function toggleSort(key: FileSortKey) {
112
+ if (!sort || sort.key !== key) sort = { key, direction: 'asc' };
113
+ else if (sort.direction === 'asc') sort = { key, direction: 'desc' };
114
+ else sort = null;
115
+ }
116
+
117
+ function rowEl(index: number): HTMLElement | null {
118
+ return grid?.querySelector<HTMLElement>(`tbody tr[data-index="${index}"]`) ?? null;
119
+ }
120
+
121
+ async function select(index: number, focus = true) {
122
+ const entry = rows[index];
123
+ if (!entry) return;
124
+ if (selected !== entry.path) {
125
+ selected = entry.path;
126
+ onselect?.(entry);
127
+ }
128
+ if (focus) {
129
+ await tick();
130
+ rowEl(index)?.focus();
131
+ }
132
+ }
133
+
134
+ function open(entry: FileEntry) {
135
+ if (entry.type === 'link') return;
136
+ onopen?.(entry);
137
+ }
138
+
139
+ /** Focus the selected row (or the first), e.g. after a folder loads. */
140
+ export function focus() {
141
+ rowEl(activeIndex)?.focus();
142
+ }
143
+
144
+ let typeahead = '';
145
+ let typeaheadTimer: ReturnType<typeof setTimeout> | undefined;
146
+
147
+ function onRowKeydown(event: KeyboardEvent, index: number) {
148
+ const entry = rows[index];
149
+ const page = 10;
150
+ switch (event.key) {
151
+ case 'ArrowDown':
152
+ event.preventDefault();
153
+ void select(Math.min(rows.length - 1, index + 1));
154
+ return;
155
+ case 'ArrowUp':
156
+ if (event.altKey) {
157
+ // Without onup, let it bubble to an enclosing FileBrowser.
158
+ if (onup) {
159
+ event.preventDefault();
160
+ onup();
161
+ }
162
+ return;
163
+ }
164
+ event.preventDefault();
165
+ void select(Math.max(0, index - 1));
166
+ return;
167
+ case 'Home':
168
+ event.preventDefault();
169
+ void select(0);
170
+ return;
171
+ case 'End':
172
+ event.preventDefault();
173
+ void select(rows.length - 1);
174
+ return;
175
+ case 'PageDown':
176
+ event.preventDefault();
177
+ void select(Math.min(rows.length - 1, index + page));
178
+ return;
179
+ case 'PageUp':
180
+ event.preventDefault();
181
+ void select(Math.max(0, index - page));
182
+ return;
183
+ case 'Enter':
184
+ event.preventDefault();
185
+ if (entry) open(entry);
186
+ return;
187
+ case 'Backspace':
188
+ if (onup) {
189
+ event.preventDefault();
190
+ onup();
191
+ }
192
+ return;
193
+ }
194
+ // Type-ahead: jump to the next name starting with the typed letters.
195
+ if (
196
+ event.key.length === 1 &&
197
+ !event.ctrlKey &&
198
+ !event.metaKey &&
199
+ !event.altKey &&
200
+ event.key !== '/'
201
+ ) {
202
+ if (event.key === ' ' && !typeahead) return;
203
+ clearTimeout(typeaheadTimer);
204
+ typeahead += event.key.toLowerCase();
205
+ typeaheadTimer = setTimeout(() => (typeahead = ''), 600);
206
+ const start = typeahead.length === 1 ? index + 1 : index;
207
+ for (let n = 0; n < rows.length; n++) {
208
+ const i = (start + n) % rows.length;
209
+ if (rows[i].name.toLowerCase().startsWith(typeahead)) {
210
+ void select(i);
211
+ break;
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ // Infinite scroll: load the next page when the sentinel comes into view.
218
+ $effect(() => {
219
+ if (!autoLoad || !sentinel || !hasMore || typeof IntersectionObserver === 'undefined') return;
220
+ const observer = new IntersectionObserver((items) => {
221
+ if (items.some((i) => i.isIntersecting) && !loadingMore) onloadmore?.();
222
+ });
223
+ observer.observe(sentinel);
224
+ return () => observer.disconnect();
225
+ });
226
+
227
+ const nf = $derived(new Intl.NumberFormat(locale));
228
+ </script>
229
+
230
+ <div class={cn('flex min-h-0 flex-col', className)} data-file-list>
231
+ {#if loading && entries.length === 0}
232
+ <div class="divide-y divide-border" aria-hidden="true" data-file-list-skeleton>
233
+ {#each { length: 8 } as _, i (i)}
234
+ <div class="flex items-center gap-3 px-3 py-2.5">
235
+ <Skeleton class="h-5 w-5 rounded" />
236
+ <Skeleton class="h-4 flex-1 max-w-[16rem]" />
237
+ <Skeleton class="hidden h-4 w-24 sm:block" />
238
+ <Skeleton class="hidden h-4 w-16 sm:block" />
239
+ </div>
240
+ {/each}
241
+ </div>
242
+ {:else if entries.length === 0}
243
+ {#if empty}
244
+ {@render empty()}
245
+ {:else}
246
+ <EmptyState title={emptyTitle} icon="folder-open" size="sm" class="py-10" />
247
+ {/if}
248
+ {:else}
249
+ <span id={linkNoteId} class="sr-only">{linkMessage}</span>
250
+ <table
251
+ bind:this={grid}
252
+ role="grid"
253
+ aria-label={label}
254
+ aria-rowcount={total !== undefined ? total + 1 : hasMore ? -1 : rows.length + 1}
255
+ aria-busy={loading || loadingMore ? 'true' : undefined}
256
+ class="w-full table-fixed border-collapse text-sm"
257
+ >
258
+ <thead class="sticky top-0 z-10 bg-background">
259
+ <tr aria-rowindex={1} class="border-b border-border text-left text-muted-foreground">
260
+ {#each columns as col (col.key)}
261
+ <th
262
+ role="columnheader"
263
+ scope="col"
264
+ aria-sort={sortable ? ariaSort(col.key) : undefined}
265
+ class={cn('px-3 py-2 font-medium', col.class)}
266
+ >
267
+ {#if sortable}
268
+ <button
269
+ type="button"
270
+ class={cn(
271
+ 'inline-flex items-center gap-1 rounded hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
272
+ col.key === 'size' && 'flex-row-reverse'
273
+ )}
274
+ onclick={() => toggleSort(col.key)}
275
+ >
276
+ {col.label}
277
+ {#if sort?.key === col.key}
278
+ <Icon name={sort.direction === 'asc' ? 'sort-asc' : 'sort-desc'} size={14} />
279
+ {/if}
280
+ </button>
281
+ {:else}
282
+ {col.label}
283
+ {/if}
284
+ </th>
285
+ {/each}
286
+ {#if rowActions}
287
+ <th role="columnheader" scope="col" class="w-12 px-3 py-2"
288
+ ><span class="sr-only">Actions</span></th
289
+ >
290
+ {/if}
291
+ </tr>
292
+ </thead>
293
+ <tbody>
294
+ {#each rows as entry, index (entry.path)}
295
+ {@const isLink = entry.type === 'link'}
296
+ {@const isSelected = index === activeIndex}
297
+ {@const modified = formatRelativeTime(entry.modified, { locale, now })}
298
+ {@const modifiedFull = formatDateTime(entry.modified, locale)}
299
+ {@const size = entry.type === 'file' ? formatBytes(entry.size, { locale }) : ''}
300
+ <tr
301
+ data-index={index}
302
+ data-path={entry.path}
303
+ data-type={entry.type}
304
+ aria-rowindex={index + 2}
305
+ aria-selected={isSelected ? 'true' : 'false'}
306
+ aria-disabled={isLink ? 'true' : undefined}
307
+ aria-describedby={isLink ? linkNoteId : undefined}
308
+ tabindex={isSelected ? 0 : -1}
309
+ title={isLink ? linkMessage : undefined}
310
+ class={cn(
311
+ 'group border-b border-border/60 outline-none transition-none',
312
+ 'focus-visible:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring',
313
+ isSelected && 'bg-muted/50',
314
+ isLink
315
+ ? 'cursor-not-allowed text-muted-foreground'
316
+ : 'cursor-pointer hover:bg-muted/60',
317
+ entry.hidden && 'opacity-70'
318
+ )}
319
+ onclick={() => {
320
+ void select(index, false);
321
+ open(entry);
322
+ }}
323
+ onkeydown={(e) => onRowKeydown(e, index)}
324
+ onfocus={() => {
325
+ if (selected !== entry.path) {
326
+ selected = entry.path;
327
+ onselect?.(entry);
328
+ }
329
+ }}
330
+ >
331
+ <td role="gridcell" class="px-3 py-2">
332
+ <div class="flex min-w-0 items-center gap-3">
333
+ <FileIcon name={entry.name} type={entry.type} />
334
+ <div class="min-w-0 flex-1">
335
+ <div class="flex min-w-0 items-center gap-2">
336
+ <span class="truncate font-medium" title={entry.name}>{entry.name}</span>
337
+ {#if isLink}
338
+ <span
339
+ class="shrink-0 rounded border border-border px-1.5 text-xs font-normal text-muted-foreground"
340
+ >Shortcut</span
341
+ >
342
+ {/if}
343
+ {#if entry.hidden}
344
+ <span class="sr-only">(hidden)</span>
345
+ {/if}
346
+ </div>
347
+ <!-- Phones: size · modified under the name -->
348
+ <div class="truncate text-xs text-muted-foreground sm:hidden" aria-hidden="true">
349
+ {[size, modified].filter(Boolean).join(' · ')}
350
+ </div>
351
+ </div>
352
+ </div>
353
+ </td>
354
+ <td role="gridcell" class="hidden px-3 py-2 text-muted-foreground sm:table-cell">
355
+ {#if modified}
356
+ <time datetime={entry.modified} title={modifiedFull}
357
+ >{modified}<span class="sr-only">, {modifiedFull}</span></time
358
+ >
359
+ {/if}
360
+ </td>
361
+ <td
362
+ role="gridcell"
363
+ class="hidden px-3 py-2 text-right tabular-nums text-muted-foreground sm:table-cell"
364
+ >
365
+ {size}
366
+ </td>
367
+ {#if rowActions}
368
+ <td role="gridcell" class="px-3 py-1 text-right">{@render rowActions(entry)}</td>
369
+ {/if}
370
+ </tr>
371
+ {/each}
372
+ </tbody>
373
+ </table>
374
+
375
+ <div class="flex flex-col items-center gap-2 px-3 py-3 text-sm text-muted-foreground">
376
+ {#if sort && hasMore}
377
+ <p data-file-list-sort-note>
378
+ Sorted within the {nf.format(entries.length)} loaded items. Load more to include the rest.
379
+ </p>
380
+ {/if}
381
+ {#if showCount && total !== undefined}
382
+ <p>Showing {nf.format(entries.length)} of {nf.format(total)}</p>
383
+ {/if}
384
+ {#if hasMore}
385
+ <div bind:this={sentinel}>
386
+ <Button variant="outline" size="sm" loading={loadingMore} onclick={() => onloadmore?.()}>
387
+ Load more
388
+ </Button>
389
+ </div>
390
+ {/if}
391
+ </div>
392
+ {/if}
393
+ </div>