@classic-homes/files-svelte 0.4.0 → 0.5.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/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/utils.d.ts +5 -2
- package/dist/lib/utils.js +19 -3
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ import { type ClassValue } from 'clsx';
|
|
|
2
2
|
import { type FileEntry, type FilesSource } from '@classic-homes/files-core';
|
|
3
3
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
4
4
|
/**
|
|
5
|
-
* Download an entry
|
|
6
|
-
* the
|
|
5
|
+
* Download an entry and save it under its name. Pass an already-loaded Blob
|
|
6
|
+
* to skip the request. Otherwise a source with `downloadUrl()` (CHAPI) hands
|
|
7
|
+
* the browser a short-lived link, so the file streams to disk instead of
|
|
8
|
+
* sitting in memory; without it, or if the link can't be had, the bytes come
|
|
9
|
+
* through `read({ download: true })`, which sends auth.
|
|
7
10
|
*/
|
|
8
11
|
export declare function downloadEntry(source: FilesSource, rootId: string, entry: FileEntry, options?: {
|
|
9
12
|
blob?: Blob;
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { twMerge } from 'tailwind-merge';
|
|
3
|
-
import { saveBlob } from '@classic-homes/files-core';
|
|
3
|
+
import { isAbortError, isFilesError, openDownloadLink, saveBlob, } from '@classic-homes/files-core';
|
|
4
4
|
export function cn(...inputs) {
|
|
5
5
|
return twMerge(clsx(inputs));
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Download an entry
|
|
9
|
-
* the
|
|
8
|
+
* Download an entry and save it under its name. Pass an already-loaded Blob
|
|
9
|
+
* to skip the request. Otherwise a source with `downloadUrl()` (CHAPI) hands
|
|
10
|
+
* the browser a short-lived link, so the file streams to disk instead of
|
|
11
|
+
* sitting in memory; without it, or if the link can't be had, the bytes come
|
|
12
|
+
* through `read({ download: true })`, which sends auth.
|
|
10
13
|
*/
|
|
11
14
|
export async function downloadEntry(source, rootId, entry, options = {}) {
|
|
15
|
+
if (!options.blob && source.downloadUrl) {
|
|
16
|
+
try {
|
|
17
|
+
const link = await source.downloadUrl(rootId, entry.path, options.signal);
|
|
18
|
+
openDownloadLink(link.url);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
// A signed-out session or an abort is final; anything else (an older
|
|
23
|
+
// server without links, a hiccup) falls back to reading the bytes.
|
|
24
|
+
if (isAbortError(err) || (isFilesError(err) && err.code === 'unauthorized'))
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
12
28
|
const blob = options.blob ??
|
|
13
29
|
(await source.read(rootId, entry.path, { download: true, signal: options.signal }));
|
|
14
30
|
saveBlob(blob, entry.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/files-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Svelte network-drive file browser for Classic Theme: FileBrowser plus FileList, FileBreadcrumbs, FileIcon, FilePreview and FileDetails, with previews through the document viewers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/lib/index.js",
|