@widgetic/file-browser 0.5.35 → 0.5.37
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 +1 -0
- package/dist/components/FolderTree.svelte +46 -97
- package/dist/components/FolderTree.svelte.d.ts +5 -1
- package/dist/components/core/Dropzone.svelte +127 -0
- package/dist/components/core/Dropzone.svelte.d.ts +15 -0
- package/dist/components/core/FileBrowser.css +11 -79
- package/dist/components/core/FileBrowser.svelte +277 -149
- package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
- package/dist/components/core/FileUploader.svelte +204 -418
- package/dist/components/core/FileUploader.svelte.d.ts +1 -0
- package/dist/components/core/Header.svelte +51 -68
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +135 -562
- package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
- package/dist/components/core/UploadPanel.svelte +169 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
- package/dist/components/core/UploadRow.svelte +90 -0
- package/dist/components/core/UploadRow.svelte.d.ts +21 -0
- package/dist/components/core/UploadStatus.svelte +34 -128
- package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
- package/dist/components/core/UploadStatusList.svelte +61 -77
- package/dist/components/items/FileItem.svelte +190 -532
- package/dist/components/items/FileItem.svelte.d.ts +1 -1
- package/dist/components/items/FolderItem.svelte +46 -36
- package/dist/components/items/FolderItem.svelte.d.ts +1 -1
- package/dist/components/modals/MoveDialog.svelte +142 -281
- package/dist/components/modals/NewFolderButton.svelte +13 -14
- package/dist/components/modals/SearchModal.svelte +112 -264
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
- package/dist/components/modals/SelectedFilesModal.svelte +91 -167
- package/dist/components/previews/AudioPlayer.svelte +75 -58
- package/dist/components/previews/ErrorPreview.svelte +9 -6
- package/dist/components/previews/FilePreview.svelte +173 -53
- package/dist/components/previews/FontPreview.svelte +37 -54
- package/dist/components/previews/ImagePreview.svelte +9 -2
- package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
- package/dist/components/previews/TextPreview.svelte +32 -40
- package/dist/components/previews/VideoPlayer.svelte +124 -149
- package/dist/components/previews/WaveformVisualizer.svelte +42 -222
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
- package/dist/components/ui/ControlToolbar.svelte +113 -288
- package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
- package/dist/components/ui/DragSelect.svelte +41 -248
- package/dist/components/ui/DropdownMenu.svelte +56 -55
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/components/ui/FileIcon.svelte +168 -51
- package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
- package/dist/components/ui/FileMetadata.svelte +20 -9
- package/dist/components/ui/LoadingSkeleton.svelte +5 -20
- package/dist/components/ui/SearchResults.svelte +50 -26
- package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
- package/dist/components/ui/SelectedBadge.svelte +25 -0
- package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TileSkeleton.svelte +15 -0
- package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
- package/dist/components/ui/VirtualList.svelte +3 -0
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/i18n/messages.d.ts +38 -25
- package/dist/i18n/messages.js +39 -26
- package/dist/utils/gridLayout.d.ts +2 -0
- package/dist/utils/gridLayout.js +10 -0
- package/package.json +3 -4
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Figma "Item Menu" (271:1228): ghost dots trigger + flat 200px menu (Rename, Download, Move, Delete).
|
|
4
|
+
*/
|
|
3
5
|
import { createEventDispatcher } from 'svelte';
|
|
4
6
|
const dispatch = createEventDispatcher();
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { DropdownMenu } from '@widgetic/design-system/components';
|
|
9
|
+
import {
|
|
10
|
+
IconArrowsMove,
|
|
11
|
+
IconDots,
|
|
12
|
+
IconDownload,
|
|
13
|
+
IconPencil,
|
|
14
|
+
IconTrash
|
|
15
|
+
} from '@widgetic/design-system/icons';
|
|
11
16
|
import { useMediaLibraryContext } from '../../mediaLibrary/context';
|
|
12
17
|
import { useI18n } from '../../i18n';
|
|
13
18
|
|
|
14
19
|
const { t } = useI18n();
|
|
15
20
|
|
|
16
|
-
// Props
|
|
17
21
|
export let isFolder: boolean;
|
|
18
22
|
export let fileUrl: string | undefined = undefined;
|
|
19
23
|
export let isMissing: boolean = false;
|
|
20
24
|
|
|
21
|
-
// Which actions the media library allows. Everything, when the File Browser works from its own settings.
|
|
22
25
|
const { capabilities } = useMediaLibraryContext();
|
|
23
26
|
|
|
24
|
-
// The actions this item gets: an action the library cannot do is not offered, rather than offered and failing.
|
|
25
27
|
$: canRename = capabilities.rename && !isMissing;
|
|
26
28
|
$: canMove = capabilities.folders && !isMissing;
|
|
27
29
|
$: canDownload = capabilities.download && !isMissing && !isFolder && !!fileUrl;
|
|
28
30
|
$: canDelete = capabilities.delete;
|
|
29
31
|
$: hasAnyAction = canRename || canMove || canDownload || canDelete;
|
|
30
32
|
|
|
33
|
+
const triggerClass =
|
|
34
|
+
'inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-foreground transition-colors duration-fast hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background';
|
|
35
|
+
|
|
31
36
|
function handleAction(action: string) {
|
|
32
37
|
if (action === 'download' && fileUrl) {
|
|
33
|
-
// noopener/noreferrer: the opened page gets no handle on this page (the file's host is not trusted).
|
|
34
38
|
window.open(fileUrl, '_blank', 'noopener,noreferrer');
|
|
35
39
|
} else {
|
|
36
40
|
dispatch('action', { action });
|
|
@@ -39,46 +43,46 @@
|
|
|
39
43
|
</script>
|
|
40
44
|
|
|
41
45
|
{#if hasAnyAction}
|
|
42
|
-
<div class="dropdown-wrapper">
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
</div>
|
|
46
|
+
<div class="dropdown-wrapper relative">
|
|
47
|
+
<DropdownMenu.Root>
|
|
48
|
+
<DropdownMenu.Trigger class={triggerClass} aria-label={$t('menu.open')}>
|
|
49
|
+
<IconDots class="size-4 stroke-[1.333]" aria-hidden="true" />
|
|
50
|
+
<span class="sr-only">{$t('menu.moreOptions')}</span>
|
|
51
|
+
</DropdownMenu.Trigger>
|
|
52
|
+
<DropdownMenu.Content class="more-options-content w-[200px]" align="end" sideOffset={4}>
|
|
53
|
+
{#if canRename}
|
|
54
|
+
<DropdownMenu.Item onclick={() => handleAction('rename')}>
|
|
55
|
+
<IconPencil class="stroke-[1.333]" />
|
|
56
|
+
{$t('action.rename')}
|
|
57
|
+
</DropdownMenu.Item>
|
|
58
|
+
{/if}
|
|
59
|
+
{#if canDownload}
|
|
60
|
+
<DropdownMenu.Item onclick={() => handleAction('download')}>
|
|
61
|
+
<IconDownload class="stroke-[1.333]" />
|
|
62
|
+
{$t('action.download')}
|
|
63
|
+
</DropdownMenu.Item>
|
|
64
|
+
{/if}
|
|
65
|
+
{#if canMove}
|
|
66
|
+
<DropdownMenu.Item onclick={() => handleAction('move')}>
|
|
67
|
+
<IconArrowsMove class="stroke-[1.333]" />
|
|
68
|
+
{$t('action.move')}
|
|
69
|
+
</DropdownMenu.Item>
|
|
70
|
+
{/if}
|
|
71
|
+
{#if canDelete && (canRename || canDownload || canMove)}
|
|
72
|
+
<DropdownMenu.Separator />
|
|
73
|
+
{/if}
|
|
74
|
+
{#if canDelete}
|
|
75
|
+
<DropdownMenu.Item
|
|
76
|
+
class="text-destructive data-highlighted:text-destructive"
|
|
77
|
+
onclick={() => handleAction('delete')}
|
|
78
|
+
>
|
|
79
|
+
<IconTrash class="stroke-[1.333]" />
|
|
80
|
+
{$t('action.delete')}
|
|
81
|
+
</DropdownMenu.Item>
|
|
82
|
+
{/if}
|
|
83
|
+
</DropdownMenu.Content>
|
|
84
|
+
</DropdownMenu.Root>
|
|
85
|
+
</div>
|
|
82
86
|
{/if}
|
|
83
87
|
|
|
84
88
|
<style>
|
|
@@ -87,17 +91,14 @@
|
|
|
87
91
|
z-index: 9999;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
/* Target the dropdown content globally to override any existing styles */
|
|
91
94
|
:global(.more-options-content) {
|
|
92
95
|
z-index: 9999 !important;
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
/* Target the dropdown wrapper added by radix/shadcn */
|
|
97
|
+
|
|
96
98
|
:global([data-radix-popper-content-wrapper]) {
|
|
97
99
|
z-index: 9999 !important;
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
/* Ensure our dropdown stays above virtual list elements */
|
|
101
|
+
|
|
101
102
|
:global(.virtual-list) {
|
|
102
103
|
z-index: 1;
|
|
103
104
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DropdownMenu } from
|
|
1
|
+
import { DropdownMenu } from '@widgetic/design-system/components';
|
|
2
2
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
4
|
$$bindings?: Bindings;
|
|
@@ -1,68 +1,185 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* FileIcon: the square picture that stands for a file or a folder.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the Figma component set "File Thumb" (page File Browser, node 266:169):
|
|
6
|
+
* Kind = Folder | Image | Video | Audio | Document | Font | Vector | Missing | File | New
|
|
7
|
+
* Size = Large 48 | Medium 40 | Small 32 (here `lg` | `md` | `sm`, the names this component always had)
|
|
8
|
+
* The kind is read from the file (name, address, media type) unless `kind` forces one: a folder, a file that is
|
|
9
|
+
* missing, a generic file, or the dashed "New" tile have no file to read it from.
|
|
10
|
+
*
|
|
11
|
+
* Colours: a folder sits on `brand-subtle`, every other kind on `muted`, a vector on the page background with a
|
|
12
|
+
* 1px border, and the "New" tile is a dashed outline. Icons are Tabler outline icons (20px on Large, 16px otherwise).
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
IconAlertTriangle,
|
|
16
|
+
IconFile,
|
|
17
|
+
IconFileText,
|
|
18
|
+
IconFolder,
|
|
19
|
+
IconMusic,
|
|
20
|
+
IconPlayerPlayFilled,
|
|
21
|
+
IconPlus
|
|
22
|
+
} from '@widgetic/design-system/icons';
|
|
4
23
|
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
5
24
|
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
|
|
26
|
+
/** The kinds a thumb can be forced to (the ones that do not come from a file). */
|
|
27
|
+
type ForcedKind = 'folder' | 'missing' | 'file' | 'new';
|
|
28
|
+
/** Every kind of the Figma set. */
|
|
29
|
+
type ThumbKind = ForcedKind | 'image' | 'video' | 'audio' | 'document' | 'font' | 'vector';
|
|
30
|
+
|
|
31
|
+
type Props = {
|
|
32
|
+
/** The file to draw. Left out for the kinds that have no file behind them. */
|
|
33
|
+
file?: { url?: string; name: string; thumbnail?: string; mimeType?: string };
|
|
34
|
+
/** Forces a kind that has no file behind it. Left out, the kind is read from `file`. */
|
|
35
|
+
kind?: ForcedKind;
|
|
36
|
+
size?: 'sm' | 'md' | 'lg';
|
|
37
|
+
/** Extra classes for the square (a different radius, a ring ...). */
|
|
38
|
+
class?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let { file = { name: '' }, kind = undefined, size = 'md', class: className = '' }: Props = $props();
|
|
42
|
+
|
|
43
|
+
// The address whose picture failed to load: the thumb falls back to the "Missing" kind for that address only.
|
|
44
|
+
let failedPictureSource = $state<string | undefined>(undefined);
|
|
45
|
+
// The addresses of the font that loaded, or failed to load.
|
|
46
|
+
let loadedFontUrl = $state<string | undefined>(undefined);
|
|
47
|
+
let failedFontUrl = $state<string | undefined>(undefined);
|
|
48
|
+
|
|
49
|
+
const fileType = $derived(getFileTypeOf(file));
|
|
17
50
|
// The name a font is registered and styled under; safe to put inside CSS (see safeText.ts).
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
const fontName = $derived(toSafeFontFamilyName(file.name));
|
|
52
|
+
/**
|
|
53
|
+
* The address drawn as a picture: the thumbnail when there is one, else the file itself for an image or a vector.
|
|
54
|
+
* A thumbnail that is the file's own address says nothing about a video, a PDF or a sound (the grid fills it in
|
|
55
|
+
* for every file that came without one), so it is not drawn: those files get their file-type icon instead.
|
|
56
|
+
*/
|
|
57
|
+
const pictureSource = $derived.by((): string | undefined => {
|
|
58
|
+
const isPictureFile = fileType === 'image' || fileType === 'svg';
|
|
59
|
+
if (file.thumbnail && (isPictureFile || file.thumbnail !== file.url)) return file.thumbnail;
|
|
60
|
+
return isPictureFile ? file.url : undefined;
|
|
61
|
+
});
|
|
62
|
+
const pictureFailed = $derived(pictureSource !== undefined && failedPictureSource === pictureSource);
|
|
63
|
+
const fontReady = $derived(file.url !== undefined && (loadedFontUrl === file.url || failedFontUrl === file.url));
|
|
64
|
+
const fontLoaded = $derived(file.url !== undefined && loadedFontUrl === file.url);
|
|
65
|
+
|
|
66
|
+
/** What the thumb shows, as one of the Figma kinds. */
|
|
67
|
+
const resolvedKind = $derived.by((): ThumbKind => {
|
|
68
|
+
if (kind) return kind;
|
|
69
|
+
if (fileType === 'font') return 'font';
|
|
70
|
+
// A picture file whose picture cannot be loaded is a missing file. A poster or a cover that cannot be loaded
|
|
71
|
+
// only costs the file its picture: it falls back to the icon of its type.
|
|
72
|
+
if (pictureSource && pictureFailed && (fileType === 'image' || fileType === 'svg')) return 'missing';
|
|
73
|
+
if (pictureSource && !pictureFailed) {
|
|
74
|
+
if (fileType === 'svg') return 'vector';
|
|
75
|
+
if (fileType === 'video') return 'video';
|
|
76
|
+
return 'image';
|
|
77
|
+
}
|
|
78
|
+
if (fileType === 'audio') return 'audio';
|
|
79
|
+
return 'document';
|
|
80
|
+
});
|
|
25
81
|
|
|
26
|
-
|
|
27
|
-
|
|
82
|
+
// Side of the square, and what sits inside it, for each size of the Figma set.
|
|
83
|
+
const SQUARE_CLASSES = { lg: 'size-12', md: 'size-10', sm: 'size-8' } as const;
|
|
84
|
+
const ICON_CLASSES = {
|
|
85
|
+
lg: 'size-5 stroke-[1.667]',
|
|
86
|
+
md: 'size-4 stroke-[1.333]',
|
|
87
|
+
sm: 'size-4 stroke-[1.333]'
|
|
88
|
+
} as const;
|
|
89
|
+
const GLYPH_CLASSES = {
|
|
90
|
+
lg: 'text-heading-page',
|
|
91
|
+
md: 'text-heading-section',
|
|
92
|
+
sm: 'text-body-medium'
|
|
93
|
+
} as const;
|
|
94
|
+
const PLAY_DISC_CLASSES = { lg: 'size-5', md: 'size-4', sm: 'size-4' } as const;
|
|
95
|
+
const PLAY_ICON_CLASSES = { lg: 'size-2.5', md: 'size-2', sm: 'size-2' } as const;
|
|
96
|
+
// Surface and ink of each kind (a vector is drawn on the page background, a new tile is only an outline).
|
|
97
|
+
const KIND_CLASSES: Record<ThumbKind, string> = {
|
|
98
|
+
folder: 'bg-brand-subtle text-foreground',
|
|
99
|
+
vector: 'border border-border bg-background text-foreground',
|
|
100
|
+
new: 'border border-dashed border-input text-muted-foreground',
|
|
101
|
+
missing: 'bg-muted text-destructive',
|
|
102
|
+
font: 'bg-muted text-foreground',
|
|
103
|
+
image: 'bg-muted text-muted-foreground',
|
|
104
|
+
video: 'bg-muted text-muted-foreground',
|
|
105
|
+
audio: 'bg-muted text-muted-foreground',
|
|
106
|
+
document: 'bg-muted text-muted-foreground',
|
|
107
|
+
file: 'bg-muted text-muted-foreground'
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// A font file shows "Aa" set in the font itself, so the font has to be loaded first.
|
|
111
|
+
$effect(() => {
|
|
112
|
+
const fontUrl = file.url;
|
|
113
|
+
const familyName = fontName;
|
|
114
|
+
if (resolvedKind !== 'font' || !fontUrl || typeof FontFace === 'undefined') return;
|
|
115
|
+
|
|
116
|
+
let isCancelled = false;
|
|
117
|
+
(async () => {
|
|
28
118
|
try {
|
|
29
|
-
fontFace = new FontFace(
|
|
119
|
+
const fontFace = new FontFace(familyName, toCssUrlLiteral(fontUrl));
|
|
30
120
|
await fontFace.load();
|
|
121
|
+
if (isCancelled) return;
|
|
31
122
|
document.fonts.add(fontFace);
|
|
32
|
-
|
|
123
|
+
loadedFontUrl = fontUrl;
|
|
33
124
|
} catch (error) {
|
|
34
|
-
|
|
35
|
-
|
|
125
|
+
if (isCancelled) return;
|
|
126
|
+
console.error('FileIcon: Error loading font from url:', fontUrl, error);
|
|
127
|
+
failedFontUrl = fontUrl;
|
|
36
128
|
}
|
|
37
|
-
}
|
|
129
|
+
})();
|
|
130
|
+
|
|
131
|
+
return () => {
|
|
132
|
+
isCancelled = true;
|
|
133
|
+
};
|
|
38
134
|
});
|
|
39
135
|
</script>
|
|
40
136
|
|
|
41
|
-
<div
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
137
|
+
<div
|
|
138
|
+
class="relative flex shrink-0 items-center justify-center overflow-hidden rounded-lg {SQUARE_CLASSES[size]} {KIND_CLASSES[resolvedKind]} {className}"
|
|
139
|
+
data-file-icon-kind={resolvedKind}
|
|
140
|
+
aria-hidden="true"
|
|
141
|
+
>
|
|
142
|
+
{#if resolvedKind === 'folder'}
|
|
143
|
+
<IconFolder class={ICON_CLASSES[size]} />
|
|
144
|
+
{:else if resolvedKind === 'image' || resolvedKind === 'video'}
|
|
145
|
+
<img
|
|
146
|
+
src={pictureSource}
|
|
147
|
+
alt=""
|
|
148
|
+
class="size-full object-cover"
|
|
149
|
+
onerror={() => (failedPictureSource = pictureSource)}
|
|
54
150
|
/>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
151
|
+
{#if resolvedKind === 'video'}
|
|
152
|
+
<!-- The play mark sits on the poster, the way the Figma Video thumb draws it. -->
|
|
153
|
+
<span
|
|
154
|
+
class="absolute flex items-center justify-center rounded-full bg-foreground/60 text-primary-foreground {PLAY_DISC_CLASSES[size]}"
|
|
155
|
+
>
|
|
156
|
+
<IconPlayerPlayFilled class={PLAY_ICON_CLASSES[size]} />
|
|
157
|
+
</span>
|
|
158
|
+
{/if}
|
|
159
|
+
{:else if resolvedKind === 'vector'}
|
|
160
|
+
<img
|
|
161
|
+
src={pictureSource}
|
|
162
|
+
alt=""
|
|
163
|
+
class="size-full object-contain {size === 'lg' ? 'p-1.5' : 'p-1'}"
|
|
164
|
+
onerror={() => (failedPictureSource = pictureSource)}
|
|
60
165
|
/>
|
|
166
|
+
{:else if resolvedKind === 'font'}
|
|
167
|
+
<!-- The letters stay hidden until the font is there (or failed), so the specimen does not flash in another font. -->
|
|
168
|
+
<span
|
|
169
|
+
class="{GLYPH_CLASSES[size]} transition-opacity duration-base {fontReady || !file.url ? '' : 'opacity-0'}"
|
|
170
|
+
style={fontLoaded ? `font-family: '${fontName}', sans-serif;` : undefined}
|
|
171
|
+
>
|
|
172
|
+
Aa
|
|
173
|
+
</span>
|
|
174
|
+
{:else if resolvedKind === 'audio'}
|
|
175
|
+
<IconMusic class={ICON_CLASSES[size]} />
|
|
176
|
+
{:else if resolvedKind === 'missing'}
|
|
177
|
+
<IconAlertTriangle class={ICON_CLASSES[size]} />
|
|
178
|
+
{:else if resolvedKind === 'file'}
|
|
179
|
+
<IconFile class={ICON_CLASSES[size]} />
|
|
180
|
+
{:else if resolvedKind === 'new'}
|
|
181
|
+
<IconPlus class={ICON_CLASSES[size]} />
|
|
61
182
|
{:else}
|
|
62
|
-
<
|
|
63
|
-
src={getFileIcon(file.name)}
|
|
64
|
-
alt=""
|
|
65
|
-
class="w-full h-full object-contain"
|
|
66
|
-
/>
|
|
183
|
+
<IconFileText class={ICON_CLASSES[size]} />
|
|
67
184
|
{/if}
|
|
68
|
-
</div>
|
|
185
|
+
</div>
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const FileIcon: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
-
file: {
|
|
1
|
+
/** The kinds a thumb can be forced to (the ones that do not come from a file). */
|
|
2
|
+
type ForcedKind = 'folder' | 'missing' | 'file' | 'new';
|
|
3
|
+
type Props = {
|
|
4
|
+
/** The file to draw. Left out for the kinds that have no file behind them. */
|
|
5
|
+
file?: {
|
|
16
6
|
url?: string;
|
|
17
7
|
name: string;
|
|
18
8
|
thumbnail?: string;
|
|
19
9
|
mimeType?: string;
|
|
20
10
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
/** Forces a kind that has no file behind it. Left out, the kind is read from `file`. */
|
|
12
|
+
kind?: ForcedKind;
|
|
13
|
+
size?: 'sm' | 'md' | 'lg';
|
|
14
|
+
/** Extra classes for the square (a different radius, a ring ...). */
|
|
15
|
+
class?: string;
|
|
16
|
+
};
|
|
17
|
+
declare const FileIcon: import("svelte").Component<Props, {}, "">;
|
|
18
|
+
type FileIcon = ReturnType<typeof FileIcon>;
|
|
26
19
|
export default FileIcon;
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import { kindWord } from '../../i18n/text';
|
|
8
8
|
|
|
9
9
|
const { t, locale } = useI18n();
|
|
10
|
-
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
11
10
|
const textDirection = useTextDirection();
|
|
12
11
|
$: nameDirection = dirForUserText($textDirection);
|
|
13
12
|
|
|
@@ -16,12 +15,24 @@
|
|
|
16
15
|
$: fileType = getFileTypeOf(file);
|
|
17
16
|
</script>
|
|
18
17
|
|
|
19
|
-
<div class="
|
|
20
|
-
<h3 class="text-
|
|
21
|
-
<ul class="space-y-2">
|
|
22
|
-
<li
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
<div class="rounded-xl border border-border bg-muted/40 p-4">
|
|
19
|
+
<h3 class="text-body-medium mb-2 text-foreground">{$t('metadata.title')}</h3>
|
|
20
|
+
<ul class="space-y-2 text-body text-foreground">
|
|
21
|
+
<li>
|
|
22
|
+
<strong class="text-body-medium">{$t('metadata.name')}</strong>
|
|
23
|
+
<span dir={nameDirection}>{file.name}</span>
|
|
24
|
+
</li>
|
|
25
|
+
<li>
|
|
26
|
+
<strong class="text-body-medium">{$t('metadata.type')}</strong>
|
|
27
|
+
{kindWord(fileType, $t)}
|
|
28
|
+
</li>
|
|
29
|
+
<li>
|
|
30
|
+
<strong class="text-body-medium">{$t('metadata.size')}</strong>
|
|
31
|
+
{file.size ? formatFileSize(file.size, $t, $locale) : $t('metadata.notAvailable')}
|
|
32
|
+
</li>
|
|
33
|
+
<li>
|
|
34
|
+
<strong class="text-body-medium">{$t('metadata.modified')}</strong>
|
|
35
|
+
{file.modified ? new Date(file.modified).toLocaleString($locale) : $t('metadata.notAvailable')}
|
|
36
|
+
</li>
|
|
26
37
|
</ul>
|
|
27
|
-
</div>
|
|
38
|
+
</div>
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
export let width: string =
|
|
3
|
-
export let height: string =
|
|
4
|
-
export let className: string =
|
|
2
|
+
export let width: string = '100%';
|
|
3
|
+
export let height: string = '100%';
|
|
4
|
+
export let className: string = '';
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<!-- svelte-ignore element_invalid_self_closing_tag -->
|
|
8
|
-
<div
|
|
9
|
-
class="animate-pulse
|
|
8
|
+
<div
|
|
9
|
+
class="animate-pulse rounded-lg bg-muted {className}"
|
|
10
10
|
style="width: {width}; height: {height};"
|
|
11
11
|
/>
|
|
12
|
-
|
|
13
|
-
<style>
|
|
14
|
-
.animate-pulse {
|
|
15
|
-
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@keyframes pulse {
|
|
19
|
-
0%, 100% {
|
|
20
|
-
opacity: 1;
|
|
21
|
-
}
|
|
22
|
-
50% {
|
|
23
|
-
opacity: .5;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
</style>
|
|
@@ -1,44 +1,68 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Compact search results list (same row look as Search Dialog — Figma Search Result 275:1523).
|
|
4
|
+
*/
|
|
5
|
+
import type { FileSystemItem } from '../../types';
|
|
3
6
|
import { FileIcon } from './';
|
|
4
|
-
import { FolderItem } from '../items';
|
|
5
7
|
import { useI18n } from '../../i18n';
|
|
6
8
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
9
|
+
import { highlightMatchesAsHtml } from '../../utils/safeText';
|
|
10
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
11
|
+
import { kindWord } from '../../i18n/text';
|
|
12
|
+
import { formatFileSize } from '../../utils/fileUtils';
|
|
7
13
|
|
|
8
|
-
const { t } = useI18n();
|
|
9
|
-
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
14
|
+
const { t, locale } = useI18n();
|
|
10
15
|
const textDirection = useTextDirection();
|
|
11
16
|
$: nameDirection = dirForUserText($textDirection);
|
|
12
17
|
|
|
13
|
-
// Props
|
|
14
18
|
export let results: FileSystemItem[];
|
|
19
|
+
/** When set, highlights matches in names (plain text, not HTML). */
|
|
20
|
+
export let searchTerm = '';
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const matchHighlightClass = 'rounded-sm bg-brand-subtle px-0.5 text-body-medium';
|
|
23
|
+
|
|
24
|
+
function highlightMatch(name: string, term: string): string {
|
|
25
|
+
return highlightMatchesAsHtml(name, term, matchHighlightClass);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resultMeta(item: FileSystemItem): string {
|
|
29
|
+
if (item.type === 'folder') {
|
|
30
|
+
return $t('item.folder');
|
|
31
|
+
}
|
|
32
|
+
const kind = getFileTypeOf(item);
|
|
33
|
+
const kindLabel = kindWord(kind, $t);
|
|
34
|
+
if (item.size != null && item.size > 0) {
|
|
35
|
+
return `${kindLabel} · ${formatFileSize(item.size, $t, $locale)}`;
|
|
36
|
+
}
|
|
37
|
+
return kindLabel;
|
|
25
38
|
}
|
|
26
39
|
</script>
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
<div class="space-y-2">
|
|
41
|
+
<div class="flex flex-col">
|
|
30
42
|
{#if results.length === 0}
|
|
31
|
-
<p class="text-center text-
|
|
43
|
+
<p class="text-center text-caption text-muted-foreground">{$t('search.noResults')}</p>
|
|
32
44
|
{:else}
|
|
33
|
-
{#each results as item (item.name)}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
{#each results as item (item.id ?? item.name)}
|
|
46
|
+
<div
|
|
47
|
+
class="flex h-12 w-full items-center gap-3 rounded-xl py-2 ps-3 pe-2 text-start"
|
|
48
|
+
>
|
|
49
|
+
<FileIcon
|
|
50
|
+
file={item}
|
|
51
|
+
kind={item.isMissing ? 'missing' : item.type === 'folder' ? 'folder' : undefined}
|
|
52
|
+
size="sm"
|
|
53
|
+
class="shrink-0"
|
|
54
|
+
/>
|
|
55
|
+
<div class="min-w-0 flex-1">
|
|
56
|
+
<div dir={nameDirection} class="truncate text-body">
|
|
57
|
+
{#if searchTerm.trim()}
|
|
58
|
+
{@html highlightMatch(item.name, searchTerm.trim())}
|
|
59
|
+
{:else}
|
|
60
|
+
<span class="text-body-medium text-foreground">{item.name}</span>
|
|
61
|
+
{/if}
|
|
62
|
+
</div>
|
|
63
|
+
<p class="truncate text-caption text-muted-foreground">{resultMeta(item)}</p>
|
|
40
64
|
</div>
|
|
41
|
-
|
|
65
|
+
</div>
|
|
42
66
|
{/each}
|
|
43
67
|
{/if}
|
|
44
|
-
</div>
|
|
68
|
+
</div>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact search results list (same row look as Search Dialog — Figma Search Result 275:1523).
|
|
3
|
+
*/
|
|
1
4
|
import type { FileSystemItem } from '../../types';
|
|
2
5
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
6
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
@@ -14,6 +17,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
14
17
|
}
|
|
15
18
|
declare const SearchResults: $$__sveltets_2_IsomorphicComponent<{
|
|
16
19
|
results: FileSystemItem[];
|
|
20
|
+
/** When set, highlights matches in names (plain text, not HTML). */ searchTerm?: string;
|
|
17
21
|
}, {
|
|
18
22
|
[evt: string]: CustomEvent<any>;
|
|
19
23
|
}, {}, {}, string>;
|