@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.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # @classic-homes/files-svelte
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Svelte 5 network-drive file browser for Classic Theme.
4
+
5
+ - `FileBrowser`: Explorer-style folder pane (drives, open folder's parents expanded, resizable), root picker, breadcrumbs, paged listing, filter, hidden files, preview dialog, download, details, every error state, offline banner
6
+ - Building blocks: `FileTree`, `FileList`, `FileBreadcrumbs`, `FileIcon`, `FilePreview`, `FileDetails`, `FileErrorState`
7
+ - Previews reuse [`@classic-homes/viewer-svelte`](../viewer-svelte): pass a `viewers` registry of lazy imports
8
+ - Re-exports the [`@classic-homes/files-core`](../files-core) sources and helpers
9
+
10
+ ```svelte
11
+ <script lang="ts">
12
+ import { FileBrowser, createChapiFilesSource } from '@classic-homes/files-svelte';
13
+ import { getAccessToken } from '@classic-homes/auth/core';
14
+
15
+ const source = createChapiFilesSource({
16
+ baseUrl: 'https://api.classichomes.com',
17
+ getAccessToken,
18
+ });
19
+ const viewers = {
20
+ pdf: () => import('@classic-homes/viewer-svelte/pdf'),
21
+ xlsx: () => import('@classic-homes/viewer-svelte/xlsx'),
22
+ };
23
+ </script>
24
+
25
+ <FileBrowser {source} {viewers} class="h-[80vh]" />
26
+ ```
27
+
28
+ Add `./node_modules/@classic-homes/files-svelte/dist/**/*.{js,svelte}` to your Tailwind `content`. Read-only for now: write slots (`toolbar`, `rowActions`) render only when the source implements writes and the root's `canWrite` is true.
29
+
30
+ Docs: `/docs/files/file-browser`; demo: `/examples/file-browser`.
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import { Icon } from '@classic-homes/theme-svelte';
3
+ import { pathSegments, type PathSegment } from '@classic-homes/files-core';
4
+ import { cn } from './utils.js';
5
+
6
+ interface Props {
7
+ /** Label of the root crumb, e.g. the drive's name. */
8
+ rootLabel: string;
9
+ /** Current folder, root-relative. */
10
+ path: string;
11
+ /** Called with the crumb's path (`''` for the root). */
12
+ onnavigate?: (path: string) => void;
13
+ /** Crumbs to show before the middle collapses into "…". Default 4. */
14
+ maxItems?: number;
15
+ /** Accessible name of the nav landmark. Default "Folder path". */
16
+ label?: string;
17
+ class?: string;
18
+ }
19
+
20
+ let {
21
+ rootLabel,
22
+ path,
23
+ onnavigate,
24
+ maxItems = 4,
25
+ label = 'Folder path',
26
+ class: className,
27
+ }: Props = $props();
28
+
29
+ let expanded = $state(false);
30
+ const segments = $derived(pathSegments(path));
31
+
32
+ // Collapse again whenever the folder changes.
33
+ $effect(() => {
34
+ void path;
35
+ expanded = false;
36
+ });
37
+
38
+ type Crumb = { kind: 'crumb'; segment: PathSegment } | { kind: 'more'; hidden: number };
39
+
40
+ const crumbs = $derived.by<Crumb[]>(() => {
41
+ const keep = Math.max(1, maxItems - 1);
42
+ if (expanded || segments.length <= keep + 1) {
43
+ return segments.map((segment) => ({ kind: 'crumb', segment }));
44
+ }
45
+ return [
46
+ { kind: 'more', hidden: segments.length - keep },
47
+ ...segments.slice(-keep).map((segment): Crumb => ({ kind: 'crumb', segment })),
48
+ ];
49
+ });
50
+
51
+ const crumbClass =
52
+ 'inline-flex max-w-[16rem] items-center gap-1.5 truncate rounded px-1.5 py-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
53
+ </script>
54
+
55
+ <nav aria-label={label} class={cn('min-w-0', className)}>
56
+ <ol class="flex min-w-0 items-center gap-0.5 overflow-x-auto whitespace-nowrap text-sm">
57
+ <li class="flex shrink-0 items-center">
58
+ {#if segments.length === 0}
59
+ <span
60
+ aria-current="page"
61
+ class="inline-flex items-center gap-1.5 px-1.5 py-1 font-medium text-foreground"
62
+ >
63
+ <Icon name="home" size={16} />
64
+ {rootLabel}
65
+ </span>
66
+ {:else}
67
+ <button type="button" class={crumbClass} onclick={() => onnavigate?.('')}>
68
+ <Icon name="home" size={16} />
69
+ <span class="truncate">{rootLabel}</span>
70
+ </button>
71
+ {/if}
72
+ </li>
73
+ {#each crumbs as crumb, i (crumb.kind === 'more' ? '…' : crumb.segment.path)}
74
+ <li class="flex min-w-0 items-center">
75
+ <Icon name="chevron-right" size={14} class="mx-0.5 shrink-0 text-muted-foreground/70" />
76
+ {#if crumb.kind === 'more'}
77
+ <button
78
+ type="button"
79
+ class={crumbClass}
80
+ aria-label={`Show ${crumb.hidden} more folder${crumb.hidden === 1 ? '' : 's'}`}
81
+ onclick={() => (expanded = true)}>…</button
82
+ >
83
+ {:else if i === crumbs.length - 1}
84
+ <span
85
+ aria-current="page"
86
+ class="max-w-[20rem] truncate px-1.5 py-1 font-medium text-foreground"
87
+ title={crumb.segment.name}>{crumb.segment.name}</span
88
+ >
89
+ {:else}
90
+ {@const target = crumb.segment.path}
91
+ <button
92
+ type="button"
93
+ class={crumbClass}
94
+ title={crumb.segment.name}
95
+ onclick={() => onnavigate?.(target)}
96
+ >
97
+ <span class="truncate">{crumb.segment.name}</span>
98
+ </button>
99
+ {/if}
100
+ </li>
101
+ {/each}
102
+ </ol>
103
+ </nav>
@@ -0,0 +1,16 @@
1
+ interface Props {
2
+ /** Label of the root crumb, e.g. the drive's name. */
3
+ rootLabel: string;
4
+ /** Current folder, root-relative. */
5
+ path: string;
6
+ /** Called with the crumb's path (`''` for the root). */
7
+ onnavigate?: (path: string) => void;
8
+ /** Crumbs to show before the middle collapses into "…". Default 4. */
9
+ maxItems?: number;
10
+ /** Accessible name of the nav landmark. Default "Folder path". */
11
+ label?: string;
12
+ class?: string;
13
+ }
14
+ declare const FileBreadcrumbs: import("svelte").Component<Props, {}, "">;
15
+ type FileBreadcrumbs = ReturnType<typeof FileBreadcrumbs>;
16
+ export default FileBreadcrumbs;