@widgetic/file-browser 0.5.44 → 0.5.46
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/components/FolderTree.svelte.d.ts +2 -1
- package/dist/components/core/Dropzone.svelte +15 -28
- package/dist/components/core/FileBrowser.svelte +86 -110
- package/dist/components/core/Header.svelte +30 -39
- package/dist/components/core/RecentFiles.svelte +7 -37
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +88 -26
- package/dist/components/core/SearchDropdown.svelte.d.ts +2 -0
- package/dist/components/core/UploadPanel.svelte +19 -24
- package/dist/components/items/FileItem.svelte +2 -2
- package/dist/components/items/FolderItem.svelte +1 -1
- package/dist/components/previews/FilePreview.svelte +44 -64
- package/dist/components/previews/PreviewHeaderBar.svelte +1 -1
- package/dist/components/ui/DragSelect.svelte +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/types.d.ts +2 -0
- package/dist/utils/brandKitLibraryTree.d.ts +23 -0
- package/dist/utils/brandKitLibraryTree.js +135 -0
- package/dist/utils/fileGoneProbe.d.ts +21 -0
- package/dist/utils/fileGoneProbe.js +37 -0
- package/dist/utils/gridLayout.d.ts +14 -1
- package/dist/utils/gridLayout.js +27 -2
- package/dist/utils/libraryTree.js +13 -2
- package/dist/utils/previewListNavigation.d.ts +10 -0
- package/dist/utils/previewListNavigation.js +39 -0
- package/dist/utils/recentFilesLimit.js +2 -5
- package/dist/utils/searchDropdownPhase.d.ts +17 -0
- package/dist/utils/searchDropdownPhase.js +23 -0
- package/dist/utils/widgeticUpload.js +2 -0
- package/package.json +1 -1
|
@@ -27,11 +27,17 @@
|
|
|
27
27
|
searchResultIds,
|
|
28
28
|
shouldResetActiveIndex
|
|
29
29
|
} from '../../utils/searchNavigation';
|
|
30
|
+
import { previewNavigationFiles } from '../../utils/previewListNavigation';
|
|
31
|
+
import {
|
|
32
|
+
resolveSearchDropdownPhase,
|
|
33
|
+
shouldShowSearchEmptyState,
|
|
34
|
+
shouldShowSearchResultsList
|
|
35
|
+
} from '../../utils/searchDropdownPhase';
|
|
30
36
|
import { useI18n } from '../../i18n';
|
|
31
37
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
32
38
|
|
|
33
39
|
const dispatch = createEventDispatcher<{
|
|
34
|
-
navigate: { path: string[]; preview?: FileSystemItem };
|
|
40
|
+
navigate: { path: string[]; preview?: FileSystemItem; previewNavigationList?: FileSystemItem[] };
|
|
35
41
|
}>();
|
|
36
42
|
|
|
37
43
|
const { t } = useI18n();
|
|
@@ -44,6 +50,8 @@
|
|
|
44
50
|
/** First segment of the location line: e.g. translated `library.defaultLabel` or `breadcrumbs.root`. */
|
|
45
51
|
export let rootDisplayLabel = '';
|
|
46
52
|
export let showLogs = false;
|
|
53
|
+
/** Overrides default debounce (150ms). Harness sets `window.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS`. */
|
|
54
|
+
export let searchDebounceMs: number | undefined = undefined;
|
|
47
55
|
|
|
48
56
|
const matchHighlightClass = 'rounded-sm bg-brand-subtle px-0.5 text-body-medium';
|
|
49
57
|
const resultsScrollMaxHeightPx = 400;
|
|
@@ -67,14 +75,39 @@
|
|
|
67
75
|
|
|
68
76
|
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
69
77
|
let debouncedResultIds = '';
|
|
78
|
+
let settledSearchTerm = '';
|
|
79
|
+
let queryInFlight = false;
|
|
80
|
+
let searchGeneration = 0;
|
|
70
81
|
let lastPointerClientX = -1;
|
|
71
82
|
let lastPointerClientY = -1;
|
|
72
83
|
let keyboardNavigationActive = false;
|
|
73
84
|
let keyboardNavigationClearTimer: ReturnType<typeof setTimeout> | null = null;
|
|
74
85
|
const searchPageStep = 10;
|
|
75
86
|
|
|
76
|
-
$:
|
|
77
|
-
$: showPanel = panelOpen &&
|
|
87
|
+
$: trimmedSearchTerm = searchValue.trim();
|
|
88
|
+
$: showPanel = panelOpen && !!trimmedSearchTerm;
|
|
89
|
+
$: searchDropdownPhase = resolveSearchDropdownPhase({
|
|
90
|
+
panelOpen: showPanel,
|
|
91
|
+
trimmedTerm: trimmedSearchTerm,
|
|
92
|
+
settledTerm: settledSearchTerm,
|
|
93
|
+
queryInFlight,
|
|
94
|
+
resultCount: debouncedResults.length
|
|
95
|
+
});
|
|
96
|
+
$: showSearchEmpty = shouldShowSearchEmptyState(searchDropdownPhase);
|
|
97
|
+
$: showResultsList = shouldShowSearchResultsList(searchDropdownPhase, debouncedResults.length);
|
|
98
|
+
$: showSearchLoadingRow = searchDropdownPhase === 'loading' && debouncedResults.length === 0;
|
|
99
|
+
|
|
100
|
+
function searchTiming() {
|
|
101
|
+
if (typeof window === 'undefined') return { debounceMs: searchDebounceMs ?? 150, slowMs: 0 };
|
|
102
|
+
const w = window as typeof window & {
|
|
103
|
+
__WIDGETIC_FB_SEARCH_DEBOUNCE_MS?: number;
|
|
104
|
+
__WIDGETIC_FB_SEARCH_SLOW_MS?: number;
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
debounceMs: searchDebounceMs ?? w.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS ?? 150,
|
|
108
|
+
slowMs: w.__WIDGETIC_FB_SEARCH_SLOW_MS ?? 0
|
|
109
|
+
};
|
|
110
|
+
}
|
|
78
111
|
|
|
79
112
|
function queueDebouncedSearch(term: string) {
|
|
80
113
|
if (searchDebounceTimer) {
|
|
@@ -82,31 +115,47 @@
|
|
|
82
115
|
searchDebounceTimer = null;
|
|
83
116
|
}
|
|
84
117
|
if (!term || !root) {
|
|
118
|
+
queryInFlight = false;
|
|
119
|
+
settledSearchTerm = term;
|
|
85
120
|
debouncedResults = [];
|
|
86
121
|
debouncedResultIds = '';
|
|
87
122
|
activeIndex = -1;
|
|
88
123
|
return;
|
|
89
124
|
}
|
|
125
|
+
const generation = ++searchGeneration;
|
|
126
|
+
queryInFlight = true;
|
|
127
|
+
const { debounceMs, slowMs } = searchTiming();
|
|
90
128
|
searchDebounceTimer = setTimeout(() => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
129
|
+
searchDebounceTimer = null;
|
|
130
|
+
void (async () => {
|
|
131
|
+
try {
|
|
132
|
+
if (slowMs > 0) await new Promise((resolve) => setTimeout(resolve, slowMs));
|
|
133
|
+
if (generation !== searchGeneration) return;
|
|
134
|
+
const termLower = term.toLowerCase();
|
|
135
|
+
const raw = searchFileSystem(root, termLower, currentFilter);
|
|
136
|
+
const nextResults = filterSearchResults(raw, currentFilter);
|
|
137
|
+
if (generation !== searchGeneration) return;
|
|
138
|
+
const nextIds = searchResultIds(nextResults);
|
|
139
|
+
debouncedResults = nextResults;
|
|
140
|
+
if (shouldResetActiveIndex(debouncedResultIds, nextIds)) {
|
|
141
|
+
activeIndex = firstSearchIndex(nextResults.length);
|
|
142
|
+
} else if (activeIndex >= nextResults.length) {
|
|
143
|
+
activeIndex = lastSearchIndex(nextResults.length);
|
|
144
|
+
}
|
|
145
|
+
debouncedResultIds = nextIds;
|
|
146
|
+
settledSearchTerm = term;
|
|
147
|
+
queryInFlight = false;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (generation !== searchGeneration) return;
|
|
150
|
+
if (showLogs) console.error('[SearchDropdown] search failed:', error);
|
|
151
|
+
debouncedResults = [];
|
|
152
|
+
debouncedResultIds = '';
|
|
153
|
+
activeIndex = -1;
|
|
154
|
+
settledSearchTerm = term;
|
|
155
|
+
queryInFlight = false;
|
|
101
156
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (showLogs) console.error('[SearchDropdown] search failed:', error);
|
|
105
|
-
debouncedResults = [];
|
|
106
|
-
debouncedResultIds = '';
|
|
107
|
-
activeIndex = -1;
|
|
108
|
-
}
|
|
109
|
-
}, 150);
|
|
157
|
+
})();
|
|
158
|
+
}, debounceMs);
|
|
110
159
|
}
|
|
111
160
|
|
|
112
161
|
$: {
|
|
@@ -181,7 +230,13 @@
|
|
|
181
230
|
if (item.type === 'file') {
|
|
182
231
|
folderPath.pop();
|
|
183
232
|
}
|
|
184
|
-
|
|
233
|
+
const previewNavigationList = previewNavigationFiles(debouncedResults);
|
|
234
|
+
dispatch('navigate', {
|
|
235
|
+
path: folderPath,
|
|
236
|
+
...(item.type === 'file'
|
|
237
|
+
? { preview: item, previewNavigationList }
|
|
238
|
+
: {})
|
|
239
|
+
});
|
|
185
240
|
} catch (error) {
|
|
186
241
|
if (showLogs) console.error('[SearchDropdown] openResult failed:', error);
|
|
187
242
|
}
|
|
@@ -206,6 +261,9 @@
|
|
|
206
261
|
searchValue = '';
|
|
207
262
|
debouncedResults = [];
|
|
208
263
|
debouncedResultIds = '';
|
|
264
|
+
settledSearchTerm = '';
|
|
265
|
+
queryInFlight = false;
|
|
266
|
+
searchGeneration += 1;
|
|
209
267
|
activeIndex = -1;
|
|
210
268
|
panelOpen = false;
|
|
211
269
|
searchInputElement?.focus();
|
|
@@ -343,9 +401,9 @@
|
|
|
343
401
|
id={listboxId}
|
|
344
402
|
role="listbox"
|
|
345
403
|
aria-label={$t('search.placeholder')}
|
|
346
|
-
class="bg-popover text-popover-foreground border-border absolute start-0 top-full z-[60] mt-1 w-full overflow-hidden rounded-xl border shadow-md outline-hidden"
|
|
404
|
+
class="bg-popover text-popover-foreground border-border absolute start-0 top-full z-[60] mt-1 w-full overflow-hidden rounded-xl border border-border p-1 shadow-md outline-hidden"
|
|
347
405
|
>
|
|
348
|
-
{#if
|
|
406
|
+
{#if showResultsList}
|
|
349
407
|
<WScrollArea
|
|
350
408
|
class="search-dropdown-scroll w-full"
|
|
351
409
|
style="max-height: {resultsScrollMaxHeightPx}px;"
|
|
@@ -400,8 +458,12 @@
|
|
|
400
458
|
{/each}
|
|
401
459
|
</div>
|
|
402
460
|
</WScrollArea>
|
|
403
|
-
{:else}
|
|
404
|
-
<div class="flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
|
|
461
|
+
{:else if showSearchLoadingRow}
|
|
462
|
+
<div class="search-dropdown-loading flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
|
|
463
|
+
<p class="text-caption text-muted-foreground">{$t('preview.loading')}</p>
|
|
464
|
+
</div>
|
|
465
|
+
{:else if showSearchEmpty}
|
|
466
|
+
<div class="search-dropdown-empty flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
|
|
405
467
|
<EmptyState message={$t('searchModal.empty')} />
|
|
406
468
|
</div>
|
|
407
469
|
{/if}
|
|
@@ -18,10 +18,12 @@ declare const SearchDropdown: $$__sveltets_2_IsomorphicComponent<{
|
|
|
18
18
|
/** Tree root (Widgetic file store). */ root?: FileSystemItem | null;
|
|
19
19
|
/** First segment of the location line: e.g. translated `library.defaultLabel` or `breadcrumbs.root`. */ rootDisplayLabel?: string;
|
|
20
20
|
showLogs?: boolean;
|
|
21
|
+
/** Overrides default debounce (150ms). Harness sets `window.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS`. */ searchDebounceMs?: number | undefined;
|
|
21
22
|
}, {
|
|
22
23
|
navigate: CustomEvent<{
|
|
23
24
|
path: string[];
|
|
24
25
|
preview?: FileSystemItem;
|
|
26
|
+
previewNavigationList?: FileSystemItem[];
|
|
25
27
|
}>;
|
|
26
28
|
} & {
|
|
27
29
|
[evt: string]: CustomEvent<any>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
-->
|
|
4
4
|
<script lang="ts">
|
|
5
5
|
import UploadRow, { type UploadRowScope, type UploadRowState } from './UploadRow.svelte';
|
|
6
|
-
import { IconButton, Progress,
|
|
6
|
+
import { IconButton, Progress, HintTooltip } from '@widgetic/design-system/components';
|
|
7
7
|
import { IconChevronDown } from '@widgetic/design-system/icons';
|
|
8
8
|
import { useI18n } from '../../i18n/context';
|
|
9
9
|
|
|
@@ -93,29 +93,24 @@
|
|
|
93
93
|
</div>
|
|
94
94
|
{#if items.length > 1}
|
|
95
95
|
<div class="flex shrink-0 items-center">
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
</
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<p class="text-caption">{expanded ? $t('upload.collapseUploader') : $t('upload.expandUploader')}</p>
|
|
115
|
-
</Tooltip.Content>
|
|
116
|
-
</Tooltip.Portal>
|
|
117
|
-
</Tooltip.Root>
|
|
118
|
-
</Tooltip.Provider>
|
|
96
|
+
<HintTooltip
|
|
97
|
+
content={expanded ? $t('upload.collapseUploader') : $t('upload.expandUploader')}
|
|
98
|
+
side="top"
|
|
99
|
+
sideOffset={6}
|
|
100
|
+
contentClass="z-[99999]"
|
|
101
|
+
>
|
|
102
|
+
{#snippet trigger({ props })}
|
|
103
|
+
<IconButton
|
|
104
|
+
{...props}
|
|
105
|
+
variant="ghost"
|
|
106
|
+
size="default"
|
|
107
|
+
label={expanded ? $t('upload.collapsePanel') : $t('upload.expandPanel')}
|
|
108
|
+
onclick={onToggleExpand}
|
|
109
|
+
>
|
|
110
|
+
<IconChevronDown class="size-4 stroke-2 transition-transform duration-base {expanded ? '' : 'rotate-180'}" aria-hidden="true" />
|
|
111
|
+
</IconButton>
|
|
112
|
+
{/snippet}
|
|
113
|
+
</HintTooltip>
|
|
119
114
|
</div>
|
|
120
115
|
{/if}
|
|
121
116
|
</div>
|
|
@@ -230,10 +230,10 @@
|
|
|
230
230
|
'flex w-full items-center gap-3 rounded-xl border border-border bg-background p-2 transition-colors duration-fast',
|
|
231
231
|
thumbnailOnly ? 'h-auto w-auto border-0 bg-transparent p-0' : 'h-16',
|
|
232
232
|
!thumbnailOnly && !effectiveIsMobile && !isSelected
|
|
233
|
-
? 'hover:bg-
|
|
233
|
+
? 'hover:bg-accent group-data-[drag-hover=true]/file-tile:bg-brand-subtle! has-[[data-state=open]]:bg-accent'
|
|
234
234
|
: '',
|
|
235
235
|
!thumbnailOnly && !effectiveIsMobile && isSelected
|
|
236
|
-
? 'group-data-[drag-hover=true]/file-tile:bg-brand-subtle'
|
|
236
|
+
? 'group-data-[drag-hover=true]/file-tile:bg-brand-subtle!'
|
|
237
237
|
: '',
|
|
238
238
|
!thumbnailOnly && isSelected ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand' : '',
|
|
239
239
|
!thumbnailOnly && (!isMissing || allowSelecting) ? 'cursor-pointer' : ''
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
>
|
|
76
76
|
<!-- Tile activation mirrors the folder thumb; keyboard users use the existing open-folder control. -->
|
|
77
77
|
<div
|
|
78
|
-
class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-all duration-fast hover:bg-
|
|
78
|
+
class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-all duration-fast hover:bg-accent has-[[data-state=open]]:bg-accent group-data-[folder-drop-hover=true]:bg-brand-subtle! group-data-[folder-drop-hover=true]:ring-2 group-data-[folder-drop-hover=true]:ring-inset group-data-[folder-drop-hover=true]:ring-brand"
|
|
79
79
|
onclick={handleTileClick}
|
|
80
80
|
role="presentation"
|
|
81
81
|
>
|
|
@@ -35,8 +35,12 @@
|
|
|
35
35
|
|
|
36
36
|
// Utils
|
|
37
37
|
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
hasPreviewNavigation,
|
|
40
|
+
stepPreviewNavigation
|
|
41
|
+
} from '../../utils/previewListNavigation';
|
|
39
42
|
import { toSafeFontFamilyName } from '../../utils/safeText';
|
|
43
|
+
import { isFileGone } from '../../utils/fileGoneProbe';
|
|
40
44
|
import { previewKeyAction } from '../../utils/previewKeys';
|
|
41
45
|
import { getCachedImageNaturalSize, preloadImageUrl, probeDecodedImage } from '../../utils/imagePreviewCache';
|
|
42
46
|
import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
|
|
@@ -371,7 +375,7 @@
|
|
|
371
375
|
function preloadNeighborPreviewImages() {
|
|
372
376
|
if (!open || fileType !== 'image') return;
|
|
373
377
|
for (const direction of ['prev', 'next'] as const) {
|
|
374
|
-
const neighbor = findNextAvailableFile(
|
|
378
|
+
const neighbor = findNextAvailableFile(direction);
|
|
375
379
|
if (!neighbor?.url) continue;
|
|
376
380
|
if (getFileTypeOf(neighbor) !== 'image') continue;
|
|
377
381
|
void preloadImageUrl(neighbor.url);
|
|
@@ -380,38 +384,11 @@
|
|
|
380
384
|
|
|
381
385
|
$: currentIndex = currentFiles.findIndex((f: FileSystemItem) => f.id === file.id);
|
|
382
386
|
|
|
383
|
-
function findNextAvailableFile(
|
|
384
|
-
|
|
385
|
-
let index = startIndex;
|
|
386
|
-
const totalFiles = currentFiles.length;
|
|
387
|
-
|
|
388
|
-
// Check up to one full cycle through the files
|
|
389
|
-
for (let i = 0; i < totalFiles; i++) {
|
|
390
|
-
if (direction === 'next') {
|
|
391
|
-
index = (index + 1) % totalFiles;
|
|
392
|
-
} else {
|
|
393
|
-
index = index > 0 ? index - 1 : totalFiles - 1;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const candidateFile = currentFiles[index];
|
|
397
|
-
if(showLogs) console.log('Checking file:', {
|
|
398
|
-
index,
|
|
399
|
-
name: candidateFile.name,
|
|
400
|
-
isMissing: $missingFiles.has(candidateFile.id)
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
if (candidateFile.id !== file.id && !$missingFiles.has(candidateFile.id)) {
|
|
404
|
-
if(showLogs) console.log('Found available file:', candidateFile.name);
|
|
405
|
-
return candidateFile;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if(showLogs) console.log('No available files found');
|
|
409
|
-
return null;
|
|
387
|
+
function findNextAvailableFile(direction: 'next' | 'prev'): FileSystemItem | null {
|
|
388
|
+
return stepPreviewNavigation(currentFiles, file.id, direction, $missingFiles);
|
|
410
389
|
}
|
|
411
390
|
|
|
412
|
-
$: showNavigation =
|
|
413
|
-
allowSelecting &&
|
|
414
|
-
countPreviewNavigationPeers(currentFiles, file, $missingFiles) > 0;
|
|
391
|
+
$: showNavigation = hasPreviewNavigation(currentFiles, $missingFiles);
|
|
415
392
|
|
|
416
393
|
// A new file starts with its own reveal state: nothing shown, nothing loaded, a fresh slow-loader clock. This block sits
|
|
417
394
|
// ABOVE the one that sizes the card on purpose, and that one reads `imageStateForFileId`, so when the file changes the reset
|
|
@@ -444,27 +421,27 @@
|
|
|
444
421
|
? fittedImage
|
|
445
422
|
: getModalDimensions(fileType);
|
|
446
423
|
|
|
424
|
+
function isTypingTarget(target: EventTarget | null): boolean {
|
|
425
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
426
|
+
const tag = target.tagName;
|
|
427
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
|
|
428
|
+
return target.isContentEditable;
|
|
429
|
+
}
|
|
430
|
+
|
|
447
431
|
function handleKeydown(event: KeyboardEvent) {
|
|
448
|
-
if (!open || !
|
|
449
|
-
|
|
432
|
+
if (!open || !showNavigation) return;
|
|
433
|
+
if (isTypingTarget(event.target)) return;
|
|
434
|
+
|
|
450
435
|
// The arrow keys follow the reading direction: the left arrow is "previous" in English and "next" in Arabic.
|
|
451
436
|
const keyAction = previewKeyAction(event.key, $textDirection);
|
|
452
437
|
if (keyAction === 'previous') {
|
|
453
438
|
event.preventDefault();
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (prevFile) {
|
|
457
|
-
// console.log('Navigating to previous file:', prevFile.name);
|
|
458
|
-
dispatch('navigate', prevFile);
|
|
459
|
-
}
|
|
439
|
+
const prevFile = findNextAvailableFile('prev');
|
|
440
|
+
if (prevFile) dispatch('navigate', prevFile);
|
|
460
441
|
} else if (keyAction === 'next') {
|
|
461
442
|
event.preventDefault();
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (nextFile) {
|
|
465
|
-
// console.log('Navigating to next file:', nextFile.name);
|
|
466
|
-
dispatch('navigate', nextFile);
|
|
467
|
-
}
|
|
443
|
+
const nextFile = findNextAvailableFile('next');
|
|
444
|
+
if (nextFile) dispatch('navigate', nextFile);
|
|
468
445
|
}
|
|
469
446
|
}
|
|
470
447
|
|
|
@@ -535,14 +512,28 @@
|
|
|
535
512
|
dispatch('fileUnavailable', { id: fileId });
|
|
536
513
|
}
|
|
537
514
|
|
|
515
|
+
/**
|
|
516
|
+
* The font could not be drawn. That alone is not a reason to remove it from the list (a corrupt or unsupported font, a blocked
|
|
517
|
+
* request): the preview shows its error state and the file stays. It is removed only when the server confirms it is gone.
|
|
518
|
+
*/
|
|
519
|
+
async function handleFontLoadFailed(failedFile: FileSystemItem) {
|
|
520
|
+
try {
|
|
521
|
+
if (await isFileGone(failedFile.url)) reportFileUnavailable(failedFile.id);
|
|
522
|
+
} catch (error) {
|
|
523
|
+
console.error('FilePreview: Could not check whether the font still exists:', failedFile.name, error);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
538
527
|
// Autoplay when component mounts
|
|
539
528
|
onMount(() => {
|
|
540
529
|
|
|
541
530
|
if(showLogs) console.log('FilePreview: onMount: file:', file);
|
|
542
531
|
|
|
543
532
|
if (fileType === 'font' && file.url) {
|
|
544
|
-
|
|
545
|
-
|
|
533
|
+
// Only a server answer of 404/410 removes the font from the list; a blocked or failed request keeps it (see fileGoneProbe).
|
|
534
|
+
const checkedFileId = file.id;
|
|
535
|
+
void isFileGone(file.url).then((gone) => {
|
|
536
|
+
if (gone) reportFileUnavailable(checkedFileId);
|
|
546
537
|
});
|
|
547
538
|
}
|
|
548
539
|
|
|
@@ -556,17 +547,6 @@
|
|
|
556
547
|
}
|
|
557
548
|
});
|
|
558
549
|
|
|
559
|
-
// Add the checkFileExists function
|
|
560
|
-
async function checkFileExists(url: string | undefined): Promise<boolean> {
|
|
561
|
-
if (!url) return false;
|
|
562
|
-
try {
|
|
563
|
-
const response = await fetch(url, { method: 'HEAD' });
|
|
564
|
-
return response.ok;
|
|
565
|
-
} catch (error) {
|
|
566
|
-
return false;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
550
|
// Add reactive statement to check if current file is missing
|
|
571
551
|
$: isMissing = $missingFiles.has(file.id);
|
|
572
552
|
|
|
@@ -650,8 +630,8 @@
|
|
|
650
630
|
!pdfLoadError &&
|
|
651
631
|
!(fileType === 'image' && imageRevealForId !== file.id);
|
|
652
632
|
|
|
653
|
-
$: canGoPrevious = showNavigation && findNextAvailableFile(
|
|
654
|
-
$: canGoNext = showNavigation && findNextAvailableFile(
|
|
633
|
+
$: canGoPrevious = showNavigation && findNextAvailableFile('prev') !== null;
|
|
634
|
+
$: canGoNext = showNavigation && findNextAvailableFile('next') !== null;
|
|
655
635
|
|
|
656
636
|
// The spinner: only for a picture that is STILL loading after `IMAGE_SLOW_LOADER_DELAY_MS` (the timer of the file that is
|
|
657
637
|
// open sets `slowLoaderForId`), never for one that was cached or arrived sooner, and never over an error card.
|
|
@@ -662,12 +642,12 @@
|
|
|
662
642
|
!showsErrorState;
|
|
663
643
|
|
|
664
644
|
function goPreviousFile() {
|
|
665
|
-
const prevFile = findNextAvailableFile(
|
|
645
|
+
const prevFile = findNextAvailableFile('prev');
|
|
666
646
|
if (prevFile) dispatch('navigate', prevFile);
|
|
667
647
|
}
|
|
668
648
|
|
|
669
649
|
function goNextFile() {
|
|
670
|
-
const nextFile = findNextAvailableFile(
|
|
650
|
+
const nextFile = findNextAvailableFile('next');
|
|
671
651
|
if (nextFile) dispatch('navigate', nextFile);
|
|
672
652
|
}
|
|
673
653
|
|
|
@@ -751,7 +731,7 @@
|
|
|
751
731
|
src={fileUrl}
|
|
752
732
|
{fontName}
|
|
753
733
|
previewText={file.previewText || undefined}
|
|
754
|
-
on:unavailable={() =>
|
|
734
|
+
on:unavailable={() => handleFontLoadFailed(file)}
|
|
755
735
|
/>
|
|
756
736
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
757
737
|
{#if fileType === 'svg'}
|
|
@@ -622,7 +622,7 @@
|
|
|
622
622
|
{#if enabled && container && !modalOpen}
|
|
623
623
|
<div
|
|
624
624
|
bind:this={selectionBox}
|
|
625
|
-
class="selection-box pointer-events-none absolute rounded-
|
|
625
|
+
class="selection-box pointer-events-none absolute rounded-none border border-brand bg-brand-subtle/20"
|
|
626
626
|
style="display: none; position: absolute;"
|
|
627
627
|
></div>
|
|
628
628
|
{/if}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUplo
|
|
|
5
5
|
export * from './utils';
|
|
6
6
|
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
7
7
|
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
8
|
-
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
8
|
+
export { loadLibraryTreeChildren, removePersistedUploads, replacePersistedUploads, saveLibraryTreeChildren, saveUserUpload, loadUserUploads } from './utils/userUploadsStorage';
|
|
9
|
+
export { BRAND_KIT_FONTS_FOLDER, BRAND_KIT_LOGOS_FOLDER, BRAND_KIT_ROOT_NAME, brandLogoFolderPath, fontFamilyFolderPath, placeBrandKitFileInTree, removeBrandKitFileFromTree, resolveCollisionFileName, treeContainsUploadId } from './utils/brandKitLibraryTree';
|
|
9
10
|
export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
|
|
10
11
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
11
12
|
export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUplo
|
|
|
9
9
|
export * from './utils';
|
|
10
10
|
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
11
11
|
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
12
|
-
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
12
|
+
export { loadLibraryTreeChildren, removePersistedUploads, replacePersistedUploads, saveLibraryTreeChildren, saveUserUpload, loadUserUploads } from './utils/userUploadsStorage';
|
|
13
|
+
export { BRAND_KIT_FONTS_FOLDER, BRAND_KIT_LOGOS_FOLDER, BRAND_KIT_ROOT_NAME, brandLogoFolderPath, fontFamilyFolderPath, placeBrandKitFileInTree, removeBrandKitFileFromTree, resolveCollisionFileName, treeContainsUploadId } from './utils/brandKitLibraryTree';
|
|
13
14
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
14
15
|
// Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
|
|
15
16
|
// a page or a build step can run on its own messages.
|
|
@@ -5,8 +5,8 @@ export declare const fileStore: {
|
|
|
5
5
|
update: (this: void, updater: import("svelte/store").Updater<FileSystemRoot>) => void;
|
|
6
6
|
};
|
|
7
7
|
export declare const currentFolder: import("svelte/store").Writable<string[]>;
|
|
8
|
-
export declare const sortCriteria: import("svelte/store").Writable<"name" | "
|
|
9
|
-
export declare const sortDirection: import("svelte/store").Writable<"
|
|
8
|
+
export declare const sortCriteria: import("svelte/store").Writable<"name" | "date" | "size">;
|
|
9
|
+
export declare const sortDirection: import("svelte/store").Writable<"asc" | "desc">;
|
|
10
10
|
export declare const selectedFiles: import("svelte/store").Writable<FileSystemItem[]>;
|
|
11
11
|
export declare const fileFilter: import("svelte/store").Writable<string[]>;
|
|
12
12
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface FileSystemItem {
|
|
|
14
14
|
matchingFileCount?: number;
|
|
15
15
|
hash?: string;
|
|
16
16
|
mimeType?: string;
|
|
17
|
+
/** Server-owned library folder path (`Brand kit/Fonts/Inter`). */
|
|
18
|
+
libraryFolderPath?: string;
|
|
17
19
|
}
|
|
18
20
|
export type FileSystemRoot = {
|
|
19
21
|
basePath: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Places brand-kit upload ids into the Widgetic library tree with stable folder names.
|
|
3
|
+
*/
|
|
4
|
+
import type { FileSystemItem } from '../types';
|
|
5
|
+
export declare const BRAND_KIT_ROOT_NAME = "Brand kit";
|
|
6
|
+
export declare const BRAND_KIT_FONTS_FOLDER = "Fonts";
|
|
7
|
+
export declare const BRAND_KIT_LOGOS_FOLDER = "Logos";
|
|
8
|
+
/** `name (2).ext` when another file in the folder already uses `name.ext`. */
|
|
9
|
+
export declare function resolveCollisionFileName(desiredName: string, takenLower: Set<string>): string;
|
|
10
|
+
export declare function fontFamilyFolderPath(family: string): string[];
|
|
11
|
+
export declare function brandLogoFolderPath(): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Moves or inserts a file into the tree under `folderPath`, setting `name` to `displayName` (collision suffix applied).
|
|
14
|
+
*/
|
|
15
|
+
export declare function placeBrandKitFileInTree(rootChildren: FileSystemItem[] | null | undefined, input: {
|
|
16
|
+
uploadId: string;
|
|
17
|
+
displayName: string;
|
|
18
|
+
folderPath: string[];
|
|
19
|
+
file?: Partial<FileSystemItem>;
|
|
20
|
+
}): FileSystemItem[];
|
|
21
|
+
/** Removes a file id wherever it sits in the tree (optimistic delete). */
|
|
22
|
+
export declare function removeBrandKitFileFromTree(rootChildren: FileSystemItem[] | null, uploadId: string): FileSystemItem[];
|
|
23
|
+
export declare function treeContainsUploadId(rootChildren: FileSystemItem[] | null, uploadId: string): boolean;
|