@widgetic/file-browser 0.5.35 → 0.5.36
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 +7 -7
- 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 -150
- 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/stores/fileStore.d.ts +2 -2
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/utils/gridLayout.d.ts +2 -0
- package/dist/utils/gridLayout.js +10 -0
- package/package.json +3 -4
|
@@ -4,18 +4,17 @@
|
|
|
4
4
|
const dispatch = createEventDispatcher();
|
|
5
5
|
|
|
6
6
|
// Design system imports
|
|
7
|
-
import { Button, toast, BaseModal, WScrollArea, EmptyState } from '@widgetic/design-system/components';
|
|
8
|
-
import { IconCornerUpRight, IconCircleMinus
|
|
7
|
+
import { Button, toast, BaseModal, WScrollArea, EmptyState, IconButton } from '@widgetic/design-system/components';
|
|
8
|
+
import { IconCornerUpRight, IconCircleMinus } from '@widgetic/design-system/icons';
|
|
9
9
|
|
|
10
10
|
// Local utils imports
|
|
11
11
|
import type { FileSystemItem } from '../../types';
|
|
12
12
|
|
|
13
13
|
// Local components imports
|
|
14
|
-
import {
|
|
14
|
+
import { FileIcon } from '../ui';
|
|
15
15
|
|
|
16
16
|
// Local stores imports
|
|
17
17
|
import { fileStore, currentFolder } from '../../stores/fileStore';
|
|
18
|
-
import { missingFiles } from '../../stores/missingFilesStore';
|
|
19
18
|
import { persistentSelectStore, validSelections } from '../../stores/persistentSelectStore';
|
|
20
19
|
|
|
21
20
|
// Local utils imports
|
|
@@ -24,7 +23,6 @@
|
|
|
24
23
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
25
24
|
|
|
26
25
|
const { t } = useI18n();
|
|
27
|
-
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
28
26
|
const textDirection = useTextDirection();
|
|
29
27
|
$: nameDirection = dirForUserText($textDirection);
|
|
30
28
|
|
|
@@ -35,14 +33,9 @@
|
|
|
35
33
|
/** The words of the button that sends the files on. Left out, the File Browser's own ("Add to Editor", or the page's language's). */
|
|
36
34
|
export let addToEditorLabel: string | undefined = undefined;
|
|
37
35
|
export let target: string = 'selected-files-modal'; // target for Portal
|
|
38
|
-
|
|
39
|
-
// Consts
|
|
40
|
-
const scrolledAreaMaxHeight = 420;
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
let buttonsContainerHeight = 0;
|
|
37
|
+
const listScrollHeightPx = 348;
|
|
44
38
|
|
|
45
|
-
// Get selected files from persistentSelectStore
|
|
46
39
|
$: selectedFiles = $validSelections(currentFilter, allFiles);
|
|
47
40
|
$: currentPath = $currentFolder;
|
|
48
41
|
$: allowedTypes = getAllowedFileTypes(currentFilter);
|
|
@@ -57,21 +50,18 @@
|
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
function handleSend() {
|
|
60
|
-
|
|
61
|
-
const selectedFilesWithPaths = selectedFiles.map(file => {
|
|
53
|
+
const selectedFilesWithPaths = selectedFiles.map((file) => {
|
|
62
54
|
const idPath = findItemPath($fileStore.root, file);
|
|
63
55
|
return {
|
|
64
56
|
id: file.id,
|
|
65
|
-
path: idPath ? idPath.slice(1) : []
|
|
57
|
+
path: idPath ? idPath.slice(1) : []
|
|
66
58
|
};
|
|
67
59
|
});
|
|
68
60
|
|
|
69
|
-
// Show sonar toast instead of alert
|
|
70
61
|
toast.success($t('toast.filesAdded'), {
|
|
71
62
|
description: $t('toast.filesAddedDetail', { count: selectedFiles.length })
|
|
72
63
|
});
|
|
73
64
|
|
|
74
|
-
// Clear selections and close modal
|
|
75
65
|
persistentSelectStore.clearSelections(currentFilter);
|
|
76
66
|
dispatch('send');
|
|
77
67
|
open = false;
|
|
@@ -90,19 +80,12 @@
|
|
|
90
80
|
}
|
|
91
81
|
|
|
92
82
|
function removeFile(fileId: string) {
|
|
93
|
-
// Update the persistent store instead of the fileStore
|
|
94
83
|
persistentSelectStore.toggleSelection(
|
|
95
|
-
selectedFiles.find(f => f.id === fileId)!,
|
|
84
|
+
selectedFiles.find((f) => f.id === fileId)!,
|
|
96
85
|
currentFilter
|
|
97
86
|
);
|
|
98
87
|
}
|
|
99
88
|
|
|
100
|
-
/**
|
|
101
|
-
* Finds the path of IDs to a file in the file system
|
|
102
|
-
* @param root Root folder to start search from
|
|
103
|
-
* @param target Target file to find
|
|
104
|
-
* @returns Array of folder IDs or null if not found
|
|
105
|
-
*/
|
|
106
89
|
function findItemPath(root: FileSystemItem, target: FileSystemItem): string[] | null {
|
|
107
90
|
if (root.id === target.id) {
|
|
108
91
|
return [root.id];
|
|
@@ -120,28 +103,17 @@
|
|
|
120
103
|
return null;
|
|
121
104
|
}
|
|
122
105
|
|
|
123
|
-
/**
|
|
124
|
-
* Navigates to the folder containing the file and opens preview
|
|
125
|
-
* @param file File to navigate to
|
|
126
|
-
*/
|
|
127
106
|
function jumpToFolder(file: FileSystemItem) {
|
|
128
107
|
const idPath = findItemPath($fileStore.root, file);
|
|
129
108
|
if (idPath) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
: idPath.slice(0, -1); // Just remove file ID
|
|
134
|
-
|
|
135
|
-
// console.log('Found ID path:', idPath);
|
|
136
|
-
// console.log('Folder path to navigate to:', folderPath);
|
|
137
|
-
|
|
138
|
-
// Close the modal first
|
|
109
|
+
const folderPath =
|
|
110
|
+
idPath[0] === $fileStore.root.id ? idPath.slice(1, -1) : idPath.slice(0, -1);
|
|
111
|
+
|
|
139
112
|
dispatch('close');
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
dispatch('navigate', {
|
|
113
|
+
|
|
114
|
+
dispatch('navigate', {
|
|
143
115
|
path: folderPath,
|
|
144
|
-
preview: file
|
|
116
|
+
preview: file
|
|
145
117
|
});
|
|
146
118
|
} else {
|
|
147
119
|
console.error('Could not find path for file:', file);
|
|
@@ -149,14 +121,14 @@
|
|
|
149
121
|
}
|
|
150
122
|
</script>
|
|
151
123
|
|
|
152
|
-
<BaseModal
|
|
124
|
+
<BaseModal
|
|
153
125
|
bind:open
|
|
154
|
-
title={$t('selectedFiles.title')}
|
|
126
|
+
title={$t('selectedFiles.title')}
|
|
155
127
|
closeLabel={$t('dialog.close')}
|
|
156
128
|
on:close={handleClose}
|
|
129
|
+
class="selected-files-modal"
|
|
157
130
|
width="566px"
|
|
158
131
|
height="496px"
|
|
159
|
-
titlePadding="small"
|
|
160
132
|
{target}
|
|
161
133
|
showScroll={false}
|
|
162
134
|
modalType="selectedFiles"
|
|
@@ -164,137 +136,89 @@
|
|
|
164
136
|
on:restore={(event) => {
|
|
165
137
|
if (event.detail) {
|
|
166
138
|
currentFilter = event.detail.currentFilter;
|
|
167
|
-
// No need to restore selectedFiles as they are managed by the persistentSelectStore
|
|
168
139
|
}
|
|
169
140
|
}}
|
|
170
141
|
>
|
|
171
|
-
<div class="
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
142
|
+
<div class="flex min-h-0 w-full flex-col gap-4">
|
|
143
|
+
{#if selectedFiles.length === 0}
|
|
144
|
+
<div
|
|
145
|
+
class="flex flex-col items-center justify-center overflow-hidden"
|
|
146
|
+
style="height: {listScrollHeightPx}px; min-height: 70px;"
|
|
147
|
+
>
|
|
148
|
+
<EmptyState message={$t('selectedFiles.empty')} />
|
|
176
149
|
</div>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
thumbnailOnly={true}
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
<span dir={nameDirection} class="body-medium truncate {file.isMissing ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{file.name}</span>
|
|
200
|
-
</div>
|
|
201
|
-
|
|
202
|
-
<div class="selected-file-item-actions flex shrink-0 items-center gap-3 ps-2">
|
|
203
|
-
<IconCornerUpRight
|
|
204
|
-
class="h-6 w-6 shrink-0 text-[hsl(var(--grey7))] rtl:-scale-x-100"
|
|
150
|
+
{:else}
|
|
151
|
+
<!-- A fixed 348px window onto the list (Figma Selected Files Dialog). shrink-0, not flex-1: in a column that is as
|
|
152
|
+
tall as its content, flex-1 would give the height away. -->
|
|
153
|
+
<WScrollArea
|
|
154
|
+
class="shrink-0"
|
|
155
|
+
style="height: {listScrollHeightPx}px;"
|
|
156
|
+
scrollbarWidth={12}
|
|
157
|
+
type="always"
|
|
158
|
+
>
|
|
159
|
+
<ul class="flex flex-col" role="list">
|
|
160
|
+
{#each selectedFiles as file (file.id)}
|
|
161
|
+
<li
|
|
162
|
+
class="group flex h-12 items-center gap-3 rounded-xl py-2 ps-2 pe-2 transition-colors duration-fast hover:bg-accent"
|
|
163
|
+
>
|
|
164
|
+
<FileIcon
|
|
165
|
+
file={file}
|
|
166
|
+
kind={file.isMissing ? 'missing' : undefined}
|
|
167
|
+
size="sm"
|
|
168
|
+
class="shrink-0"
|
|
205
169
|
/>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
e.stopPropagation();
|
|
212
|
-
removeFile(file.id);
|
|
213
|
-
}}
|
|
170
|
+
<span
|
|
171
|
+
dir={nameDirection}
|
|
172
|
+
class="min-w-0 flex-1 truncate text-body-medium {file.isMissing
|
|
173
|
+
? 'text-destructive'
|
|
174
|
+
: 'text-foreground'}"
|
|
214
175
|
>
|
|
215
|
-
|
|
216
|
-
</
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
176
|
+
{file.name}
|
|
177
|
+
</span>
|
|
178
|
+
<div class="flex shrink-0 items-center gap-0">
|
|
179
|
+
<IconButton
|
|
180
|
+
variant="ghost"
|
|
181
|
+
label={$t('searchModal.jumpToFolder')}
|
|
182
|
+
class="size-8"
|
|
183
|
+
onclick={() => jumpToFolder(file)}
|
|
184
|
+
>
|
|
185
|
+
<IconCornerUpRight class="size-4 stroke-[1.333] rtl:rotate-180" />
|
|
186
|
+
</IconButton>
|
|
187
|
+
<IconButton
|
|
188
|
+
variant="ghost"
|
|
189
|
+
label={$t('selectedFiles.remove')}
|
|
190
|
+
class="size-8"
|
|
191
|
+
onclick={() => removeFile(file.id)}
|
|
192
|
+
>
|
|
193
|
+
<IconCircleMinus class="size-4 stroke-[1.333]" />
|
|
194
|
+
</IconButton>
|
|
195
|
+
</div>
|
|
196
|
+
</li>
|
|
197
|
+
{/each}
|
|
198
|
+
</ul>
|
|
199
|
+
</WScrollArea>
|
|
200
|
+
{/if}
|
|
201
|
+
|
|
202
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
203
|
+
<p class="min-w-0 flex-1 truncate text-caption text-muted-foreground">
|
|
232
204
|
{$t('selectedFiles.count', { count: selectedFiles.length })}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
<!-- Cancel Button -->
|
|
238
|
-
<Button
|
|
239
|
-
type="button"
|
|
240
|
-
class="modal-btn-secondary !h-[34px]"
|
|
241
|
-
onclick={handleClose}
|
|
242
|
-
>
|
|
243
|
-
<span>{$t('action.cancel')}</span>
|
|
244
|
-
</Button>
|
|
245
|
-
|
|
246
|
-
<!-- Add to Editor Button -->
|
|
247
|
-
{#if showAddToEditor}
|
|
248
|
-
<Button
|
|
249
|
-
type="submit"
|
|
250
|
-
class="modal-btn-primary !h-[34px]"
|
|
251
|
-
onclick={sendToEditor}
|
|
252
|
-
disabled={selectedFiles.length === 0}
|
|
253
|
-
>
|
|
254
|
-
<span>{confirmAddLabel}</span>
|
|
205
|
+
</p>
|
|
206
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
207
|
+
<Button type="button" variant="outline" class="h-9" onclick={handleClose}>
|
|
208
|
+
{$t('action.cancel')}
|
|
255
209
|
</Button>
|
|
256
|
-
|
|
210
|
+
{#if showAddToEditor}
|
|
211
|
+
<Button
|
|
212
|
+
type="button"
|
|
213
|
+
variant="default"
|
|
214
|
+
class="h-9"
|
|
215
|
+
onclick={sendToEditor}
|
|
216
|
+
disabled={selectedFiles.length === 0}
|
|
217
|
+
>
|
|
218
|
+
{confirmAddLabel}
|
|
219
|
+
</Button>
|
|
220
|
+
{/if}
|
|
221
|
+
</div>
|
|
257
222
|
</div>
|
|
258
223
|
</div>
|
|
259
|
-
</div>
|
|
260
224
|
</BaseModal>
|
|
261
|
-
|
|
262
|
-
<style>
|
|
263
|
-
/* Ensure smooth transitions */
|
|
264
|
-
.selected-file-item {
|
|
265
|
-
transition: all 150ms ease;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/* File item hover effect */
|
|
269
|
-
.selected-file-item:hover {
|
|
270
|
-
background-color: hsl(var(--grey2));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/* Thumbnail container styling */
|
|
274
|
-
.thumbnail-container {
|
|
275
|
-
position: relative;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/* Make the FileItem have no pointer events so clicks pass through to the parent */
|
|
279
|
-
.thumbnail-container :global(*) {
|
|
280
|
-
pointer-events: none;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/* Match the exact animation from FileItem.svelte */
|
|
284
|
-
.thumbnail-container :global(.thumbnail-button) {
|
|
285
|
-
transform: scale(1);
|
|
286
|
-
transform-origin: top left;
|
|
287
|
-
will-change: transform;
|
|
288
|
-
backface-visibility: hidden;
|
|
289
|
-
-webkit-font-smoothing: antialiased;
|
|
290
|
-
transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
291
|
-
opacity 150ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
292
|
-
border-radius 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/* Apply the same hover animation as in FileItem.svelte */
|
|
296
|
-
.selected-file-item:hover .thumbnail-container :global(.thumbnail-button) {
|
|
297
|
-
transform: scale(0.81) translate(6px, 6px);
|
|
298
|
-
opacity: 0.8;
|
|
299
|
-
}
|
|
300
|
-
</style>
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// Svelte imports
|
|
3
2
|
import { onMount } from 'svelte';
|
|
4
|
-
|
|
5
|
-
// Design system imports
|
|
6
|
-
import { Button } from '@widgetic/design-system/components';
|
|
3
|
+
import { IconButton } from '@widgetic/design-system/components';
|
|
7
4
|
import { IconPlayerPlayFilled, IconPlayerPauseFilled } from '@widgetic/design-system/icons';
|
|
8
|
-
|
|
9
|
-
// Local components imports
|
|
10
5
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
11
6
|
import WaveformVisualizer from './WaveformVisualizer.svelte';
|
|
12
7
|
import { useI18n } from '../../i18n';
|
|
@@ -20,31 +15,36 @@
|
|
|
20
15
|
let isPlaying = false;
|
|
21
16
|
let hasError = false;
|
|
22
17
|
let isLoading = true;
|
|
18
|
+
let currentTime = 0;
|
|
19
|
+
let duration = 0;
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setTimeout(() => {
|
|
31
|
-
isLoading = false;
|
|
32
|
-
}, 100);
|
|
33
|
-
});
|
|
21
|
+
function formatTime(seconds: number): string {
|
|
22
|
+
if (!Number.isFinite(seconds) || seconds < 0) return '0:00';
|
|
23
|
+
const minutes = Math.floor(seconds / 60);
|
|
24
|
+
const remainingSeconds = Math.floor(seconds % 60);
|
|
25
|
+
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
26
|
+
}
|
|
34
27
|
|
|
35
|
-
function togglePlay() {
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
function togglePlay(event?: Event) {
|
|
29
|
+
event?.stopPropagation();
|
|
30
|
+
if (!mediaElement) return;
|
|
31
|
+
if (mediaElement.paused) {
|
|
32
|
+
mediaElement.play().catch((error) => {
|
|
33
|
+
console.error('Error playing audio:', error);
|
|
34
|
+
});
|
|
38
35
|
} else {
|
|
39
|
-
mediaElement
|
|
36
|
+
mediaElement.pause();
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
function handleSeek(event: MouseEvent) {
|
|
41
|
+
if (!mediaElement) return;
|
|
42
|
+
const target = event.currentTarget as HTMLElement;
|
|
43
|
+
const rect = target.getBoundingClientRect();
|
|
44
|
+
const ratio = Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width));
|
|
45
|
+
if (mediaElement.duration) {
|
|
46
|
+
mediaElement.currentTime = ratio * mediaElement.duration;
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
function handleError() {
|
|
@@ -60,61 +60,78 @@
|
|
|
60
60
|
isPlaying = false;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function handleTimeUpdate() {
|
|
64
|
+
if (!mediaElement) return;
|
|
65
|
+
currentTime = mediaElement.currentTime;
|
|
66
|
+
duration = mediaElement.duration || duration;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function handleLoadedMetadata() {
|
|
70
|
+
if (!mediaElement) return;
|
|
71
|
+
duration = mediaElement.duration || 0;
|
|
72
|
+
isLoading = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
onMount(() => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
if (mediaElement && autoplay) {
|
|
77
|
+
mediaElement.play().catch(() => {});
|
|
78
|
+
}
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
isLoading = false;
|
|
81
|
+
}, 100);
|
|
68
82
|
});
|
|
69
83
|
</script>
|
|
70
84
|
|
|
71
85
|
{#if hasError}
|
|
72
86
|
<ErrorPreview message={$t('preview.audioFailed')} />
|
|
73
87
|
{:else}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
<div class="audio-preview-container flex w-full flex-col items-center gap-4 px-0">
|
|
89
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
90
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
91
|
+
<div
|
|
92
|
+
class="audio-wave-hit w-full max-w-[22.625rem] cursor-pointer"
|
|
93
|
+
onclick={handleSeek}
|
|
94
|
+
role="presentation"
|
|
95
|
+
>
|
|
82
96
|
{#if mediaElement}
|
|
83
97
|
<WaveformVisualizer {mediaElement} />
|
|
84
98
|
{/if}
|
|
85
99
|
</div>
|
|
86
100
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
<div class="flex w-full max-w-[22.625rem] items-center justify-between gap-3">
|
|
102
|
+
<span class="text-caption-medium text-foreground tabular-nums">{formatTime(currentTime)}</span>
|
|
103
|
+
|
|
104
|
+
{#if !isLoading}
|
|
105
|
+
<IconButton
|
|
106
|
+
variant="primary"
|
|
107
|
+
class="press-feedback size-12 rounded-full"
|
|
108
|
+
label={isPlaying ? $t('action.pause') : $t('action.play')}
|
|
109
|
+
onclick={togglePlay}
|
|
92
110
|
>
|
|
93
111
|
{#if isPlaying}
|
|
94
|
-
<IconPlayerPauseFilled
|
|
95
|
-
class="w-20 h-20 text-[hsl(var(--grey7))] group-hover/button:text-[hsl(var(--deep-forest-green))] transition-colors duration-200"
|
|
96
|
-
/>
|
|
112
|
+
<IconPlayerPauseFilled class="size-5" />
|
|
97
113
|
{:else}
|
|
98
|
-
<IconPlayerPlayFilled
|
|
99
|
-
class="w-20 h-20 text-[hsl(var(--grey7))] group-hover/button:text-[hsl(var(--deep-forest-green))] transition-colors duration-200"
|
|
100
|
-
/>
|
|
114
|
+
<IconPlayerPlayFilled class="size-5" />
|
|
101
115
|
{/if}
|
|
102
|
-
</
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{
|
|
116
|
+
</IconButton>
|
|
117
|
+
{/if}
|
|
118
|
+
|
|
119
|
+
<span class="text-caption-medium text-foreground tabular-nums">{formatTime(duration)}</span>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<audio
|
|
123
|
+
bind:this={mediaElement}
|
|
124
|
+
{src}
|
|
110
125
|
{autoplay}
|
|
111
126
|
crossorigin="anonymous"
|
|
112
|
-
class="hidden"
|
|
127
|
+
class="hidden"
|
|
113
128
|
onerror={handleError}
|
|
114
129
|
onplay={handlePlay}
|
|
115
130
|
onpause={handlePause}
|
|
131
|
+
ontimeupdate={handleTimeUpdate}
|
|
132
|
+
onloadedmetadata={handleLoadedMetadata}
|
|
116
133
|
>
|
|
117
134
|
{$t('preview.audioUnsupported')}
|
|
118
135
|
</audio>
|
|
119
136
|
</div>
|
|
120
|
-
{/if}
|
|
137
|
+
{/if}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
// Design system imports
|
|
3
|
+
import { EmptyState } from '@widgetic/design-system/components';
|
|
4
|
+
import { IconAlertTriangle } from '@widgetic/design-system/icons';
|
|
5
|
+
|
|
2
6
|
// Local utils imports
|
|
3
|
-
import { getAssetUrl } from '../../utils/fileUtils';
|
|
4
7
|
import { useI18n } from '../../i18n';
|
|
5
8
|
|
|
6
9
|
const { t } = useI18n();
|
|
7
10
|
|
|
8
|
-
// Component props: the
|
|
11
|
+
// Component props: the title of the state. Left out, "File not found" (in the page's language).
|
|
9
12
|
export let message: string | undefined = undefined;
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
</div>
|
|
15
|
+
<!-- Figma "Preview Dialog / Error": a holder 160px tall with the state (icon tile and title) centred in it -->
|
|
16
|
+
<div class="error-preview-container flex h-40 w-full items-center justify-center">
|
|
17
|
+
<EmptyState message={message ?? $t('preview.fileNotFound')} icon={IconAlertTriangle} showActions={false} height="auto" />
|
|
18
|
+
</div>
|