@widgetic/file-browser 0.5.25 → 0.5.27
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 +63 -9
- package/dist/components/FolderTree.svelte +12 -8
- package/dist/components/core/FileBrowser.svelte +36 -8
- package/dist/components/core/FileBrowser.svelte.d.ts +16 -1
- package/dist/components/core/FileUploader.svelte +16 -12
- package/dist/components/core/Header.svelte +1 -1
- package/dist/components/core/RecentFiles.svelte +7 -3
- package/dist/components/core/UploadStatus.svelte +6 -2
- package/dist/components/items/FileItem.svelte +9 -5
- package/dist/components/items/FolderItem.svelte +7 -3
- package/dist/components/modals/MoveDialog.svelte +8 -8
- package/dist/components/modals/SearchModal.svelte +9 -5
- package/dist/components/modals/SelectedFilesModal.svelte +9 -5
- package/dist/components/previews/FilePreview.svelte +8 -2
- package/dist/components/previews/VideoPlayer.svelte +3 -2
- package/dist/components/ui/ControlToolbar.svelte +5 -5
- package/dist/components/ui/DragSelect.svelte +1 -0
- package/dist/components/ui/FileMetadata.svelte +5 -1
- package/dist/components/ui/SearchResults.svelte +5 -1
- package/dist/i18n/context.d.ts +10 -20
- package/dist/i18n/context.js +6 -59
- package/dist/i18n/index.d.ts +6 -2
- package/dist/i18n/index.js +4 -4
- package/dist/i18n/messages.d.ts +4 -0
- package/dist/i18n/messages.js +4 -0
- package/dist/mediaLibrary/errors.d.ts +1 -1
- package/dist/utils/previewKeys.d.ts +12 -0
- package/dist/utils/previewKeys.js +14 -0
- package/package.json +3 -2
- package/dist/i18n/translator.d.ts +0 -75
- package/dist/i18n/translator.js +0 -317
|
@@ -374,7 +374,7 @@
|
|
|
374
374
|
<!-- Current Folder Button -->
|
|
375
375
|
<div class="folder-item widgetic-colors widgetic-radius group">
|
|
376
376
|
<button
|
|
377
|
-
class="folder-button flex items-center gap-4 w-full min-h-[70px]
|
|
377
|
+
class="folder-button flex items-center gap-4 w-full min-h-[70px] ps-2 rounded-large cursor-pointer
|
|
378
378
|
{selectedFolder?.id === 'root' ? 'bg-[hsl(var(--light-green))] light-green-bg' : ''}
|
|
379
379
|
{immediateParentId === null ? 'relative' : ''}"
|
|
380
380
|
onclick={() => {
|
|
@@ -419,20 +419,20 @@
|
|
|
419
419
|
/>
|
|
420
420
|
</div>
|
|
421
421
|
</div>
|
|
422
|
-
<span class="body-medium truncate flex-grow text-
|
|
423
|
-
<div class="flex items-center
|
|
422
|
+
<span class="body-medium truncate flex-grow text-start {immediateParentId === null ? 'text-[hsl(var(--grey3))]' : 'text-[hsl(var(--grey7))]'} {selectedFolder?.id === 'root' ? 'font-bold' : 'font-normal'}">{$t('moveDialog.rootName')}</span>
|
|
423
|
+
<div class="flex items-center ms-auto">
|
|
424
424
|
{#if immediateParentId === null}
|
|
425
|
-
<span class="h6 text-[hsl(var(--sage-green))] relative z-10
|
|
425
|
+
<span class="h6 text-[hsl(var(--sage-green))] relative z-10 me-6">{$t('folder.currentLocation')}</span>
|
|
426
426
|
{/if}
|
|
427
427
|
{#if selectedFolder?.id === 'root'}
|
|
428
|
-
<IconArrowBounce class="w-6 h-6 text-[hsl(var(--info))]
|
|
428
|
+
<IconArrowBounce class="w-6 h-6 text-[hsl(var(--info))] me-6 rtl:-scale-x-100" />
|
|
429
429
|
{/if}
|
|
430
430
|
</div>
|
|
431
431
|
</button>
|
|
432
432
|
</div>
|
|
433
433
|
|
|
434
434
|
<!-- Folder Items Container -->
|
|
435
|
-
<div class="folder-tree-container
|
|
435
|
+
<div class="folder-tree-container ps-8 flex flex-col">
|
|
436
436
|
{#each folders as folder}
|
|
437
437
|
{#if folder.type === 'folder'}
|
|
438
438
|
<FolderTree
|
|
@@ -445,7 +445,7 @@
|
|
|
445
445
|
iconSize="40"
|
|
446
446
|
textClass="body-medium truncate text-[hsl(var(--grey7))]"
|
|
447
447
|
selectedIconClass="w-6 h-6 text-[hsl(var(--info))]"
|
|
448
|
-
currentLocationClass="text-sm text-[hsl(var(--info))]
|
|
448
|
+
currentLocationClass="text-sm text-[hsl(var(--info))] me-2"
|
|
449
449
|
selectedIcon={IconArrowBounce}
|
|
450
450
|
/>
|
|
451
451
|
{/if}
|
|
@@ -504,7 +504,7 @@
|
|
|
504
504
|
.folder-item::before {
|
|
505
505
|
content: '';
|
|
506
506
|
position: absolute;
|
|
507
|
-
|
|
507
|
+
inset-inline-start: 0;
|
|
508
508
|
top: 0;
|
|
509
509
|
bottom: 0;
|
|
510
510
|
width: 2px;
|
|
@@ -39,8 +39,12 @@
|
|
|
39
39
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
40
40
|
import { highlightMatchesAsHtml } from '../../utils/safeText';
|
|
41
41
|
import { useI18n } from '../../i18n';
|
|
42
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
42
43
|
|
|
43
44
|
const { t } = useI18n();
|
|
45
|
+
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
46
|
+
const textDirection = useTextDirection();
|
|
47
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
44
48
|
|
|
45
49
|
// Props for filtering search results
|
|
46
50
|
export let currentFilter: FileFilterType = 'all';
|
|
@@ -389,12 +393,12 @@
|
|
|
389
393
|
on:click={() => handleResultClick(result)}
|
|
390
394
|
>
|
|
391
395
|
{#if result.type === 'folder'}
|
|
392
|
-
<div class="flex items-center gap-4 min-w-0
|
|
396
|
+
<div class="flex items-center gap-4 min-w-0 pe-12">
|
|
393
397
|
<img src={getFolderIcon(result, currentFilter)} alt={$t('item.folder')} class="w-[62px] h-[54px] object-contain shrink-0" />
|
|
394
|
-
<span class="body-medium text-[hsl(var(--grey7))] truncate">{@html highlightMatch(result.name, $searchTermStore)}</span>
|
|
398
|
+
<span dir={nameDirection} class="body-medium text-[hsl(var(--grey7))] truncate">{@html highlightMatch(result.name, $searchTermStore)}</span>
|
|
395
399
|
</div>
|
|
396
400
|
{:else}
|
|
397
|
-
<div class="flex items-center gap-4 min-w-0
|
|
401
|
+
<div class="flex items-center gap-4 min-w-0 pe-12">
|
|
398
402
|
<div class="w-[62px] shrink-0 flex items-center justify-center">
|
|
399
403
|
<FileItem
|
|
400
404
|
item={result}
|
|
@@ -405,7 +409,7 @@
|
|
|
405
409
|
on:action
|
|
406
410
|
/>
|
|
407
411
|
</div>
|
|
408
|
-
<span class="body-medium text-[hsl(var(--grey7))] truncate {result.isMissing ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{@html highlightMatch(result.name, $searchTermStore)}</span>
|
|
412
|
+
<span dir={nameDirection} class="body-medium text-[hsl(var(--grey7))] truncate {result.isMissing ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{@html highlightMatch(result.name, $searchTermStore)}</span>
|
|
409
413
|
</div>
|
|
410
414
|
{/if}
|
|
411
415
|
</button>
|
|
@@ -414,7 +418,7 @@
|
|
|
414
418
|
<img
|
|
415
419
|
src={getAssetUrl('/icons/jump-to-folder.svg')}
|
|
416
420
|
alt={$t('searchModal.jumpToFolder')}
|
|
417
|
-
class="jump-to-folder-icon w-6 h-6 absolute
|
|
421
|
+
class="jump-to-folder-icon w-6 h-6 absolute end-6 top-1/2 transform -translate-y-1/2 z-20 pointer-events-none rtl:-scale-x-100"
|
|
418
422
|
class:active={index === activeIndex}
|
|
419
423
|
/>
|
|
420
424
|
</div>
|
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
// Local utils imports
|
|
22
22
|
import { getAllowedFileTypes, type FileFilterType } from '../../utils/fileTypes';
|
|
23
23
|
import { useI18n } from '../../i18n';
|
|
24
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
24
25
|
|
|
25
26
|
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
|
+
const textDirection = useTextDirection();
|
|
29
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
26
30
|
|
|
27
31
|
export let open = true;
|
|
28
32
|
export let currentFilter: FileFilterType = 'all';
|
|
@@ -173,11 +177,11 @@
|
|
|
173
177
|
{:else}
|
|
174
178
|
<!-- Selected Files Container -->
|
|
175
179
|
<WScrollArea class="selected-files-container flex-grow" style="height: {scrolledAreaMaxHeight}px;" scrollOutside={true} type="always">
|
|
176
|
-
<div class="file-items-container
|
|
180
|
+
<div class="file-items-container pe-4">
|
|
177
181
|
{#each selectedFiles as file (file.id)}
|
|
178
182
|
<div class="selected-file-item relative overflow-hidden rounded-large transition-colors duration-200 hover:bg-[hsl(var(--grey2))]">
|
|
179
183
|
<div
|
|
180
|
-
class="selected-file-item-row flex items-center justify-between min-h-[70px] cursor-pointer
|
|
184
|
+
class="selected-file-item-row flex items-center justify-between min-h-[70px] cursor-pointer pe-2 focus-visible:ring-0 focus-visible:ring-offset-0"
|
|
181
185
|
onclick={() => jumpToFolder(file)}
|
|
182
186
|
onkeydown={(e) => e.key === 'Enter' && jumpToFolder(file)}
|
|
183
187
|
role="button"
|
|
@@ -192,12 +196,12 @@
|
|
|
192
196
|
thumbnailOnly={true}
|
|
193
197
|
/>
|
|
194
198
|
</div>
|
|
195
|
-
<span class="body-medium truncate {file.isMissing ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{file.name}</span>
|
|
199
|
+
<span dir={nameDirection} class="body-medium truncate {file.isMissing ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{file.name}</span>
|
|
196
200
|
</div>
|
|
197
201
|
|
|
198
|
-
<div class="selected-file-item-actions flex shrink-0 items-center gap-3
|
|
202
|
+
<div class="selected-file-item-actions flex shrink-0 items-center gap-3 ps-2">
|
|
199
203
|
<IconCornerUpRight
|
|
200
|
-
class="h-6 w-6 shrink-0 text-[hsl(var(--grey7))]"
|
|
204
|
+
class="h-6 w-6 shrink-0 text-[hsl(var(--grey7))] rtl:-scale-x-100"
|
|
201
205
|
/>
|
|
202
206
|
|
|
203
207
|
<button
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
// Design System Components imports
|
|
13
13
|
import { BaseModal, PDFViewer } from '@widgetic/design-system/components';
|
|
14
|
+
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
14
15
|
|
|
15
16
|
// Local Components imports
|
|
16
17
|
import { ImagePreview, VideoPlayer, AudioPlayer, ErrorPreview, FontPreview, TextPreview } from './';
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
// Utils
|
|
23
24
|
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
24
25
|
import { toSafeFontFamilyName } from '../../utils/safeText';
|
|
26
|
+
import { previewKeyAction } from '../../utils/previewKeys';
|
|
25
27
|
|
|
26
28
|
// Stores
|
|
27
29
|
import { missingFiles } from '../../stores/missingFilesStore';
|
|
@@ -30,6 +32,8 @@
|
|
|
30
32
|
import { useI18n } from '../../i18n';
|
|
31
33
|
|
|
32
34
|
const { t } = useI18n();
|
|
35
|
+
// The reading direction the File Browser is laid out in: the arrow keys follow it.
|
|
36
|
+
const textDirection = useTextDirection();
|
|
33
37
|
|
|
34
38
|
// Component props
|
|
35
39
|
export let file: FileSystemItem;
|
|
@@ -179,7 +183,9 @@
|
|
|
179
183
|
function handleKeydown(event: KeyboardEvent) {
|
|
180
184
|
if (!open || !allowSelecting) return;
|
|
181
185
|
|
|
182
|
-
|
|
186
|
+
// The arrow keys follow the reading direction: the left arrow is "previous" in English and "next" in Arabic.
|
|
187
|
+
const keyAction = previewKeyAction(event.key, $textDirection);
|
|
188
|
+
if (keyAction === 'previous') {
|
|
183
189
|
event.preventDefault();
|
|
184
190
|
// console.log('Left arrow pressed, current index:', currentIndex);
|
|
185
191
|
const prevFile = findNextAvailableFile(currentIndex, 'prev');
|
|
@@ -187,7 +193,7 @@
|
|
|
187
193
|
// console.log('Navigating to previous file:', prevFile.name);
|
|
188
194
|
dispatch('navigate', prevFile);
|
|
189
195
|
}
|
|
190
|
-
} else if (
|
|
196
|
+
} else if (keyAction === 'next') {
|
|
191
197
|
event.preventDefault();
|
|
192
198
|
// console.log('Right arrow pressed, current index:', currentIndex);
|
|
193
199
|
const nextFile = findNextAvailableFile(currentIndex, 'next');
|
|
@@ -183,20 +183,21 @@
|
|
|
183
183
|
|
|
184
184
|
<!-- Custom video controls -->
|
|
185
185
|
<div
|
|
186
|
-
class="custom-video-controls absolute bottom-0
|
|
186
|
+
class="custom-video-controls absolute bottom-0 inset-x-0 flex flex-col transition-opacity duration-300 bg-gradient-to-t from-black/60 to-transparent p-2"
|
|
187
187
|
class:opacity-0={!showControls && isPlaying}
|
|
188
188
|
class:pointer-events-none={!showControls && isPlaying}
|
|
189
189
|
>
|
|
190
190
|
<!-- Progress bar -->
|
|
191
191
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
192
192
|
<div
|
|
193
|
+
dir="ltr"
|
|
193
194
|
class="relative h-1 w-full bg-white/30 mb-3 cursor-pointer rounded-full"
|
|
194
195
|
bind:this={progressBarContainer}
|
|
195
196
|
onmousedown={startDragging}
|
|
196
197
|
onclick={handleProgressClick}
|
|
197
198
|
>
|
|
198
199
|
<div
|
|
199
|
-
class="absolute top-0
|
|
200
|
+
class="absolute top-0 start-0 h-full bg-white rounded-full"
|
|
200
201
|
style="width: {(currentTime / duration) * 100}%"
|
|
201
202
|
></div>
|
|
202
203
|
</div>
|
|
@@ -229,7 +229,7 @@
|
|
|
229
229
|
onclick={handleMove}
|
|
230
230
|
aria-label={$t('action.move')}
|
|
231
231
|
>
|
|
232
|
-
<IconArrowBounce class="w-4 h-4 shrink-0" />
|
|
232
|
+
<IconArrowBounce class="w-4 h-4 shrink-0 rtl:-scale-x-100" />
|
|
233
233
|
{#if !compact}{$t('action.move')}{/if}
|
|
234
234
|
</Button>
|
|
235
235
|
{/if}
|
|
@@ -255,12 +255,12 @@
|
|
|
255
255
|
role="button"
|
|
256
256
|
tabindex="0"
|
|
257
257
|
>
|
|
258
|
-
<div class="relative h-6 flex items-center
|
|
258
|
+
<div class="relative h-6 flex items-center pe-2">
|
|
259
259
|
{#if selectedFiles.length > 0}
|
|
260
260
|
{#each selectedFiles.slice(0, 2) as file, i}
|
|
261
261
|
<div
|
|
262
262
|
class="w-6 h-6 rounded-[var(--radius-small)] border border-gray-200 bg-white overflow-hidden absolute widgetic-radius"
|
|
263
|
-
style="
|
|
263
|
+
style="inset-inline-start: {i * 12}px; z-index: {2 - i};"
|
|
264
264
|
>
|
|
265
265
|
{#if getFilePreview(file) === 'font'}
|
|
266
266
|
<div class="w-6 h-6 flex items-center justify-center bg-gray-100">
|
|
@@ -290,7 +290,7 @@
|
|
|
290
290
|
</div>
|
|
291
291
|
{/each}
|
|
292
292
|
{#if selectedFiles.length > 2}
|
|
293
|
-
<div class="
|
|
293
|
+
<div class="ms-[32px] ps-2 caption text-[hsl(var(--grey5))] widgetic-colors group-hover:text-[hsl(var(--grey7))] transition-colors duration-200">
|
|
294
294
|
{$t('toolbar.more', { count: selectedFiles.length - 2 })}
|
|
295
295
|
</div>
|
|
296
296
|
{:else if selectedFiles.length === 2}
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
class="text-[hsl(var(--grey5))] h6 flex items-center gap-2 [&_svg]:size-5 widgetic-colors hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
322
322
|
onclick={handleMove}
|
|
323
323
|
>
|
|
324
|
-
<IconArrowBounce class="w-4 h-4" />
|
|
324
|
+
<IconArrowBounce class="w-4 h-4 rtl:-scale-x-100" />
|
|
325
325
|
{$t('toolbar.moveMany', { count: selectedFiles.length })}
|
|
326
326
|
</Button>
|
|
327
327
|
{/if}
|
|
@@ -665,6 +665,7 @@
|
|
|
665
665
|
|
|
666
666
|
// Apply the calculated position and dimensions
|
|
667
667
|
selectionBox.style.display = 'block';
|
|
668
|
+
// rtl-ok: the box is drawn between two pointer positions, measured from the left edge of the list
|
|
668
669
|
selectionBox.style.left = `${left}px`;
|
|
669
670
|
selectionBox.style.top = `${top}px`;
|
|
670
671
|
selectionBox.style.width = `${width}px`;
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
4
4
|
import { formatFileSize } from '../../utils/fileUtils';
|
|
5
5
|
import { useI18n } from '../../i18n';
|
|
6
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
6
7
|
import { kindWord } from '../../i18n/text';
|
|
7
8
|
|
|
8
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
|
+
const textDirection = useTextDirection();
|
|
12
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
9
13
|
|
|
10
14
|
export let file: FileSystemItem;
|
|
11
15
|
|
|
@@ -15,7 +19,7 @@
|
|
|
15
19
|
<div class="bg-gray-100 p-4 rounded-large widgetic-radius widgetic-colors">
|
|
16
20
|
<h3 class="text-lg subtext mb-2">{$t('metadata.title')}</h3>
|
|
17
21
|
<ul class="space-y-2">
|
|
18
|
-
<li><strong>{$t('metadata.name')}</strong> {file.name}</li>
|
|
22
|
+
<li><strong>{$t('metadata.name')}</strong> <span dir={nameDirection}>{file.name}</span></li>
|
|
19
23
|
<li><strong>{$t('metadata.type')}</strong> {kindWord(fileType, $t)}</li>
|
|
20
24
|
<li><strong>{$t('metadata.size')}</strong> {file.size ? formatFileSize(file.size, $t, $locale) : $t('metadata.notAvailable')}</li>
|
|
21
25
|
<li><strong>{$t('metadata.modified')}</strong> {file.modified ? new Date(file.modified).toLocaleString($locale) : $t('metadata.notAvailable')}</li>
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
import { FileIcon } from './';
|
|
4
4
|
import { FolderItem } from '../items';
|
|
5
5
|
import { useI18n } from '../../i18n';
|
|
6
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
6
7
|
|
|
7
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.
|
|
10
|
+
const textDirection = useTextDirection();
|
|
11
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
8
12
|
|
|
9
13
|
// Props
|
|
10
14
|
export let results: FileSystemItem[];
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
{:else}
|
|
33
37
|
<div class="flex items-center p-2 hover:bg-[hsl(var(--grey3))] rounded-large widgetic-radius widgetic-colors">
|
|
34
38
|
<FileIcon file={item} size="md" />
|
|
35
|
-
<span class="
|
|
39
|
+
<span dir={nameDirection} class="ms-2">{item.name}</span>
|
|
36
40
|
</div>
|
|
37
41
|
{/if}
|
|
38
42
|
{/each}
|
package/dist/i18n/context.d.ts
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type I18nContext as KitI18nContext, type I18nHandle as KitI18nHandle, type I18nSettings as KitI18nSettings, type Translate as KitTranslate } from '@widgetic/design-system/i18n';
|
|
2
2
|
import { type FileBrowserMessageKey } from './messages';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The words of the File Browser are made by the design system's i18n kit (`@widgetic/design-system/i18n`), the same
|
|
5
|
+
* translator and context every Widgetic package uses; this file gives it the File Browser's catalog and name.
|
|
6
|
+
*/
|
|
4
7
|
/** The function a screen calls to get its words: `t('upload.clear')`, `t('toast.deleted', { name })`. */
|
|
5
|
-
export type Translate =
|
|
8
|
+
export type Translate = KitTranslate<FileBrowserMessageKey>;
|
|
6
9
|
/**
|
|
7
10
|
* What the File Browser's parts need to speak the page's language, shared with them through Svelte's component
|
|
8
11
|
* context (the way the media library is, see `mediaLibrary/context.ts`).
|
|
9
12
|
*
|
|
10
13
|
* Both are stores, so a screen that is already open changes its words when the page calls `setLanguage()`.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
/** Turns a key into text. */
|
|
14
|
-
t: Readable<Translate>;
|
|
15
|
-
/** The language tag in use ("en" unless the page asked for another one that this browser knows). */
|
|
16
|
-
locale: Readable<string>;
|
|
17
|
-
}
|
|
15
|
+
export type I18nContext = KitI18nContext<FileBrowserMessageKey>;
|
|
18
16
|
/** What the page chose. Both are optional; a missing language is English. */
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/** The page's own words: any of the catalog's keys. A key it leaves out keeps the English text. */
|
|
23
|
-
messages?: MessageOverrides | null;
|
|
24
|
-
}
|
|
17
|
+
export type I18nSettings = KitI18nSettings;
|
|
18
|
+
/** What {@link provideI18n} gives back to the component that called it. */
|
|
19
|
+
export type I18nHandle = KitI18nHandle<FileBrowserMessageKey>;
|
|
25
20
|
/** The English `t`, for code that has no component around it (a helper called without a translator). */
|
|
26
21
|
export declare const translateEnglish: Translate;
|
|
27
|
-
/** What {@link provideI18n} gives back to the component that called it. */
|
|
28
|
-
export interface I18nHandle extends I18nContext {
|
|
29
|
-
/** Changes the language the parts below speak. Cheap to call on every change of the props. */
|
|
30
|
-
update(settings: I18nSettings): void;
|
|
31
|
-
}
|
|
32
22
|
/**
|
|
33
23
|
* Called by the File Browser while it is created, so everything inside it speaks the page's language.
|
|
34
24
|
* The context belongs to one File Browser, so two File Browsers on a page can speak two languages.
|
package/dist/i18n/context.js
CHANGED
|
@@ -1,70 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { derived, readable, writable } from 'svelte/store';
|
|
1
|
+
import { createI18n } from '@widgetic/design-system/i18n';
|
|
3
2
|
import { FILE_BROWSER_MESSAGES } from './messages';
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
/** How many different problems the console is told about, so a page that keeps changing its messages cannot fill memory. */
|
|
7
|
-
const MAX_REPORTED_PROBLEMS = 200;
|
|
8
|
-
const reportedProblems = new Set();
|
|
9
|
-
/** Says a problem with the page's messages in the console, once per page however often the language is set. */
|
|
10
|
-
function reportProblem(problem) {
|
|
11
|
-
const text = describeMessageProblem(problem);
|
|
12
|
-
if (reportedProblems.has(text) || reportedProblems.size >= MAX_REPORTED_PROBLEMS)
|
|
13
|
-
return;
|
|
14
|
-
reportedProblems.add(text);
|
|
15
|
-
console.warn(`[FileBrowser] ${text}`);
|
|
16
|
-
}
|
|
17
|
-
function translatorFor(settings) {
|
|
18
|
-
return createTranslator({
|
|
19
|
-
catalog: FILE_BROWSER_MESSAGES,
|
|
20
|
-
locale: settings.locale ?? undefined,
|
|
21
|
-
messages: settings.messages,
|
|
22
|
-
onProblem: reportProblem
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/** The English translator that a part of the File Browser uses when nothing above it chose a language. */
|
|
26
|
-
const ENGLISH_TRANSLATOR = translatorFor({});
|
|
27
|
-
const ENGLISH_CONTEXT = Object.freeze({
|
|
28
|
-
t: readable(ENGLISH_TRANSLATOR.t),
|
|
29
|
-
locale: readable(ENGLISH_TRANSLATOR.locale)
|
|
30
|
-
});
|
|
3
|
+
/** The File Browser's words. Problems with the page's messages are said in the console as `[FileBrowser] …`. */
|
|
4
|
+
const fileBrowserI18n = createI18n({ catalog: FILE_BROWSER_MESSAGES, label: 'FileBrowser' });
|
|
31
5
|
/** The English `t`, for code that has no component around it (a helper called without a translator). */
|
|
32
|
-
export const translateEnglish =
|
|
6
|
+
export const translateEnglish = fileBrowserI18n.translateEnglish;
|
|
33
7
|
/**
|
|
34
8
|
* Called by the File Browser while it is created, so everything inside it speaks the page's language.
|
|
35
9
|
* The context belongs to one File Browser, so two File Browsers on a page can speak two languages.
|
|
36
10
|
*/
|
|
37
11
|
export function provideI18n(initial) {
|
|
38
|
-
|
|
39
|
-
const translator = derived(settings, ($settings) => translatorFor($settings));
|
|
40
|
-
const t = derived(translator, ($translator) => $translator.t);
|
|
41
|
-
const locale = derived(translator, ($translator) => $translator.locale);
|
|
42
|
-
const context = { t, locale };
|
|
43
|
-
setContext(I18N_CONTEXT_KEY, context);
|
|
44
|
-
let lastSignature = signatureOf(initial);
|
|
45
|
-
return {
|
|
46
|
-
...context,
|
|
47
|
-
update(next) {
|
|
48
|
-
// Setting the same language again would rebuild every message for nothing.
|
|
49
|
-
const signature = signatureOf(next);
|
|
50
|
-
if (signature === lastSignature)
|
|
51
|
-
return;
|
|
52
|
-
lastSignature = signature;
|
|
53
|
-
settings.set(next);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/** Two settings are the same language when they have the same locale and the same words. */
|
|
58
|
-
function signatureOf(settings) {
|
|
59
|
-
try {
|
|
60
|
-
return JSON.stringify([settings.locale ?? null, settings.messages ?? null]);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// Not serializable (a cycle, a BigInt): treat it as new every time rather than guess.
|
|
64
|
-
return `${Math.random()}`;
|
|
65
|
-
}
|
|
12
|
+
return fileBrowserI18n.provideI18n(initial);
|
|
66
13
|
}
|
|
67
14
|
/** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it speaks English. */
|
|
68
15
|
export function useI18n() {
|
|
69
|
-
return
|
|
16
|
+
return fileBrowserI18n.useI18n();
|
|
70
17
|
}
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The words of the File Browser in the page's language: the English catalog, the translator that fills it in (the
|
|
3
|
+
* design system's, `@widgetic/design-system/i18n`) and the Svelte context the screens use.
|
|
4
|
+
*/
|
|
5
|
+
import { type MessageOverrides, type MessageProblem } from '@widgetic/design-system/i18n';
|
|
2
6
|
export { FILE_BROWSER_MESSAGES, type FileBrowserMessageKey } from './messages';
|
|
3
|
-
export { createTranslator, describeMessageProblem, findMessageProblems, type MessageOverrides, type MessageProblem, type MessageValue, type MessageValues, type Translator, type TranslatorOptions } from '
|
|
7
|
+
export { createTranslator, describeMessageProblem, findMessageProblems, type MessageOverrides, type MessageProblem, type MessageValue, type MessageValues, type Translator, type TranslatorOptions } from '@widgetic/design-system/i18n';
|
|
4
8
|
export { provideI18n, translateEnglish, useI18n, type I18nContext, type I18nHandle, type I18nSettings, type Translate } from './context';
|
|
5
9
|
export { messageForVisitor } from './errors';
|
|
6
10
|
/**
|
package/dist/i18n/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The words of the File Browser in the page's language: the English catalog, the translator that fills it in
|
|
3
|
-
* Svelte context the screens use.
|
|
2
|
+
* The words of the File Browser in the page's language: the English catalog, the translator that fills it in (the
|
|
3
|
+
* design system's, `@widgetic/design-system/i18n`) and the Svelte context the screens use.
|
|
4
4
|
*/
|
|
5
|
+
import { findMessageProblems } from '@widgetic/design-system/i18n';
|
|
5
6
|
import { FILE_BROWSER_MESSAGES } from './messages';
|
|
6
|
-
import { findMessageProblems } from './translator';
|
|
7
7
|
export { FILE_BROWSER_MESSAGES } from './messages';
|
|
8
|
-
export { createTranslator, describeMessageProblem, findMessageProblems } from '
|
|
8
|
+
export { createTranslator, describeMessageProblem, findMessageProblems } from '@widgetic/design-system/i18n';
|
|
9
9
|
export { provideI18n, translateEnglish, useI18n } from './context';
|
|
10
10
|
export { messageForVisitor } from './errors';
|
|
11
11
|
/**
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -33,6 +33,10 @@ export declare const FILE_BROWSER_MESSAGES: {
|
|
|
33
33
|
readonly 'list.separator': ", ";
|
|
34
34
|
readonly 'toast.inBackground': "This will happen in the background";
|
|
35
35
|
readonly 'toast.unknownError': "Unknown error occurred";
|
|
36
|
+
/** What a screen reader hears for the region that holds the pop-ups. The library adds the key that moves focus to it. */
|
|
37
|
+
readonly 'toast.regionLabel': "Notifications";
|
|
38
|
+
/** What a screen reader hears for the button that closes a pop-up. */
|
|
39
|
+
readonly 'toast.closeLabel': "Close notification";
|
|
36
40
|
readonly 'search.placeholder': "Search...";
|
|
37
41
|
readonly 'filter.by': "Filter by {type}";
|
|
38
42
|
readonly 'filterName.all': "All";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -34,6 +34,10 @@ export const FILE_BROWSER_MESSAGES = {
|
|
|
34
34
|
'list.separator': ', ',
|
|
35
35
|
'toast.inBackground': 'This will happen in the background',
|
|
36
36
|
'toast.unknownError': 'Unknown error occurred',
|
|
37
|
+
/** What a screen reader hears for the region that holds the pop-ups. The library adds the key that moves focus to it. */
|
|
38
|
+
'toast.regionLabel': 'Notifications',
|
|
39
|
+
/** What a screen reader hears for the button that closes a pop-up. */
|
|
40
|
+
'toast.closeLabel': 'Close notification',
|
|
37
41
|
// ===== The bar above the files =====
|
|
38
42
|
'search.placeholder': 'Search...',
|
|
39
43
|
'filter.by': 'Filter by {type}',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileBrowserMessageKey } from '../i18n/messages';
|
|
2
|
-
import type { MessageValues } from '
|
|
2
|
+
import type { MessageValues } from '@widgetic/design-system/i18n';
|
|
3
3
|
import type { MediaLibraryErrorCode } from './types';
|
|
4
4
|
/** A failed call to a media library, with a reason the File Browser can act on. */
|
|
5
5
|
export declare class MediaLibraryError extends Error {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TextDirection } from '@widgetic/design-system/components/textDirection';
|
|
2
|
+
/** What a key press does in the file preview: go to the file before this one, or to the file after it. */
|
|
3
|
+
export type PreviewKeyAction = 'previous' | 'next';
|
|
4
|
+
/**
|
|
5
|
+
* What an arrow key does in the file preview, or `null` for any other key.
|
|
6
|
+
*
|
|
7
|
+
* The arrow keys follow the reading direction: the key that points toward the start of the line goes to the previous
|
|
8
|
+
* file and the key that points toward the end of the line goes to the next one. In a left to right screen that is the
|
|
9
|
+
* left arrow and the right arrow; in a right to left screen the two swap, so the arrow points the way the files are
|
|
10
|
+
* laid out on the screen.
|
|
11
|
+
*/
|
|
12
|
+
export declare function previewKeyAction(key: string, direction: TextDirection): PreviewKeyAction | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an arrow key does in the file preview, or `null` for any other key.
|
|
3
|
+
*
|
|
4
|
+
* The arrow keys follow the reading direction: the key that points toward the start of the line goes to the previous
|
|
5
|
+
* file and the key that points toward the end of the line goes to the next one. In a left to right screen that is the
|
|
6
|
+
* left arrow and the right arrow; in a right to left screen the two swap, so the arrow points the way the files are
|
|
7
|
+
* laid out on the screen.
|
|
8
|
+
*/
|
|
9
|
+
export function previewKeyAction(key, direction) {
|
|
10
|
+
if (key !== 'ArrowLeft' && key !== 'ArrowRight')
|
|
11
|
+
return null;
|
|
12
|
+
const keyPointsToStart = (key === 'ArrowLeft') === (direction !== 'rtl');
|
|
13
|
+
return keyPointsToStart ? 'previous' : 'next';
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/file-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"typescript": "^5.0.0",
|
|
112
112
|
"typescript-eslint": "^8.0.0",
|
|
113
113
|
"vite": "^6.4.3",
|
|
114
|
-
"vitest": "^
|
|
114
|
+
"vitest": "^5.0.3"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"@sveltejs/kit": "^2.20.7",
|
|
@@ -131,6 +131,7 @@
|
|
|
131
131
|
"tus-js-client": "^4.2.3"
|
|
132
132
|
},
|
|
133
133
|
"overrides": {
|
|
134
|
+
"shell-quote": "^1.12.0",
|
|
134
135
|
"bits-ui": {
|
|
135
136
|
"@melt-ui/svelte": "^0.86.3"
|
|
136
137
|
},
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The words of the File Browser, as a function.
|
|
3
|
-
*
|
|
4
|
-
* A message is a template in a flat catalog: `'upload.progress': '{done} of {total} uploaded'`. A page can replace any
|
|
5
|
-
* of them (the `messages` option); a key it leaves out keeps the English text, so a partly translated catalog never
|
|
6
|
-
* shows a hole.
|
|
7
|
-
*
|
|
8
|
-
* A template is plain text with two kinds of `{...}`:
|
|
9
|
-
*
|
|
10
|
-
* {name} the value called `name`; a number is written the way the locale
|
|
11
|
-
* writes numbers (1,234 or 1.234)
|
|
12
|
-
* {count, plural, =0 {none} one {# file} other {# files}}
|
|
13
|
-
* one branch, chosen by the locale's plural rules (`Intl.PluralRules`),
|
|
14
|
-
* so a language with more than two forms (Polish, Arabic) can say so.
|
|
15
|
-
* `=0` matches exactly 0; `other` is required; `#` is the number
|
|
16
|
-
*
|
|
17
|
-
* `\{`, `\}`, `\#` and `\\` write the character itself. An apostrophe is just an apostrophe: `Delete '{name}'?` works.
|
|
18
|
-
*
|
|
19
|
-
* Nothing here knows about Svelte or the DOM: the same code runs in a unit test.
|
|
20
|
-
*/
|
|
21
|
-
/** A value a template can show. */
|
|
22
|
-
export type MessageValue = string | number;
|
|
23
|
-
export type MessageValues = Readonly<Record<string, MessageValue>>;
|
|
24
|
-
/** Something wrong in what the page supplied. Reported once, never thrown: a broken message must not break the screen. */
|
|
25
|
-
export type MessageProblem = {
|
|
26
|
-
kind: 'unknown-message';
|
|
27
|
-
key: string;
|
|
28
|
-
suggestion?: string;
|
|
29
|
-
} | {
|
|
30
|
-
kind: 'not-text';
|
|
31
|
-
key: string;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'broken-message';
|
|
34
|
-
key: string;
|
|
35
|
-
reason: string;
|
|
36
|
-
} | {
|
|
37
|
-
kind: 'unknown-value';
|
|
38
|
-
key: string;
|
|
39
|
-
name: string;
|
|
40
|
-
} | {
|
|
41
|
-
kind: 'unknown-locale';
|
|
42
|
-
locale: string;
|
|
43
|
-
};
|
|
44
|
-
/** One line a developer can read in the console about a {@link MessageProblem}. */
|
|
45
|
-
export declare function describeMessageProblem(problem: MessageProblem): string;
|
|
46
|
-
/** The shape the page supplies for `messages`: any of the catalog's keys, with text. */
|
|
47
|
-
export type MessageOverrides = Readonly<Record<string, unknown>>;
|
|
48
|
-
export interface TranslatorOptions<Key extends string> {
|
|
49
|
-
/** A BCP 47 tag ("de", "pt-BR"). It sets plural rules and number formats. The words come from `messages`. Default "en". */
|
|
50
|
-
locale?: string;
|
|
51
|
-
/** The built-in English messages. Every key the screens ask for is here. */
|
|
52
|
-
catalog: Readonly<Record<Key, string>>;
|
|
53
|
-
/** The page's own words: any of the catalog's keys. */
|
|
54
|
-
messages?: MessageOverrides | null;
|
|
55
|
-
/** Told about each problem once. The default is to say nothing. */
|
|
56
|
-
onProblem?: (problem: MessageProblem) => void;
|
|
57
|
-
}
|
|
58
|
-
export interface Translator<Key extends string> {
|
|
59
|
-
/** The message for `key`, with `values` put in. An unknown key comes back as the key itself. */
|
|
60
|
-
t: (key: Key, values?: MessageValues) => string;
|
|
61
|
-
/** The language tag in use, after checking it ("en" when the one given was not a tag). */
|
|
62
|
-
readonly locale: string;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Makes the function that turns keys into text. It never throws for what the page supplied: an unusable message is
|
|
66
|
-
* reported through `onProblem` (once) and the English one is used in its place.
|
|
67
|
-
*/
|
|
68
|
-
export declare function createTranslator<Key extends string>(options: TranslatorOptions<Key>): Translator<Key>;
|
|
69
|
-
/**
|
|
70
|
-
* The names of the values a message asks for: each `{name}` in it, and the number a plural looks at, sorted. For a test
|
|
71
|
-
* or a tool that checks the code gives a message everything it needs. Throws when the template does not parse.
|
|
72
|
-
*/
|
|
73
|
-
export declare function valueNamesOfTemplate(template: string): string[];
|
|
74
|
-
/** Checks `messages` against a catalog without making a translator: what a test, or a build step, can call. */
|
|
75
|
-
export declare function findMessageProblems<Key extends string>(catalog: Readonly<Record<Key, string>>, messages: MessageOverrides): MessageProblem[];
|