@widgetic/file-browser 0.5.45 → 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/previews/FilePreview.svelte +26 -50
- package/dist/components/previews/PreviewHeaderBar.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/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>
|
|
@@ -35,7 +35,10 @@
|
|
|
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';
|
|
40
43
|
import { isFileGone } from '../../utils/fileGoneProbe';
|
|
41
44
|
import { previewKeyAction } from '../../utils/previewKeys';
|
|
@@ -372,7 +375,7 @@
|
|
|
372
375
|
function preloadNeighborPreviewImages() {
|
|
373
376
|
if (!open || fileType !== 'image') return;
|
|
374
377
|
for (const direction of ['prev', 'next'] as const) {
|
|
375
|
-
const neighbor = findNextAvailableFile(
|
|
378
|
+
const neighbor = findNextAvailableFile(direction);
|
|
376
379
|
if (!neighbor?.url) continue;
|
|
377
380
|
if (getFileTypeOf(neighbor) !== 'image') continue;
|
|
378
381
|
void preloadImageUrl(neighbor.url);
|
|
@@ -381,38 +384,11 @@
|
|
|
381
384
|
|
|
382
385
|
$: currentIndex = currentFiles.findIndex((f: FileSystemItem) => f.id === file.id);
|
|
383
386
|
|
|
384
|
-
function findNextAvailableFile(
|
|
385
|
-
|
|
386
|
-
let index = startIndex;
|
|
387
|
-
const totalFiles = currentFiles.length;
|
|
388
|
-
|
|
389
|
-
// Check up to one full cycle through the files
|
|
390
|
-
for (let i = 0; i < totalFiles; i++) {
|
|
391
|
-
if (direction === 'next') {
|
|
392
|
-
index = (index + 1) % totalFiles;
|
|
393
|
-
} else {
|
|
394
|
-
index = index > 0 ? index - 1 : totalFiles - 1;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const candidateFile = currentFiles[index];
|
|
398
|
-
if(showLogs) console.log('Checking file:', {
|
|
399
|
-
index,
|
|
400
|
-
name: candidateFile.name,
|
|
401
|
-
isMissing: $missingFiles.has(candidateFile.id)
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
if (candidateFile.id !== file.id && !$missingFiles.has(candidateFile.id)) {
|
|
405
|
-
if(showLogs) console.log('Found available file:', candidateFile.name);
|
|
406
|
-
return candidateFile;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if(showLogs) console.log('No available files found');
|
|
410
|
-
return null;
|
|
387
|
+
function findNextAvailableFile(direction: 'next' | 'prev'): FileSystemItem | null {
|
|
388
|
+
return stepPreviewNavigation(currentFiles, file.id, direction, $missingFiles);
|
|
411
389
|
}
|
|
412
390
|
|
|
413
|
-
$: showNavigation =
|
|
414
|
-
allowSelecting &&
|
|
415
|
-
countPreviewNavigationPeers(currentFiles, file, $missingFiles) > 0;
|
|
391
|
+
$: showNavigation = hasPreviewNavigation(currentFiles, $missingFiles);
|
|
416
392
|
|
|
417
393
|
// A new file starts with its own reveal state: nothing shown, nothing loaded, a fresh slow-loader clock. This block sits
|
|
418
394
|
// ABOVE the one that sizes the card on purpose, and that one reads `imageStateForFileId`, so when the file changes the reset
|
|
@@ -445,27 +421,27 @@
|
|
|
445
421
|
? fittedImage
|
|
446
422
|
: getModalDimensions(fileType);
|
|
447
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
|
+
|
|
448
431
|
function handleKeydown(event: KeyboardEvent) {
|
|
449
|
-
if (!open || !
|
|
450
|
-
|
|
432
|
+
if (!open || !showNavigation) return;
|
|
433
|
+
if (isTypingTarget(event.target)) return;
|
|
434
|
+
|
|
451
435
|
// The arrow keys follow the reading direction: the left arrow is "previous" in English and "next" in Arabic.
|
|
452
436
|
const keyAction = previewKeyAction(event.key, $textDirection);
|
|
453
437
|
if (keyAction === 'previous') {
|
|
454
438
|
event.preventDefault();
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (prevFile) {
|
|
458
|
-
// console.log('Navigating to previous file:', prevFile.name);
|
|
459
|
-
dispatch('navigate', prevFile);
|
|
460
|
-
}
|
|
439
|
+
const prevFile = findNextAvailableFile('prev');
|
|
440
|
+
if (prevFile) dispatch('navigate', prevFile);
|
|
461
441
|
} else if (keyAction === 'next') {
|
|
462
442
|
event.preventDefault();
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (nextFile) {
|
|
466
|
-
// console.log('Navigating to next file:', nextFile.name);
|
|
467
|
-
dispatch('navigate', nextFile);
|
|
468
|
-
}
|
|
443
|
+
const nextFile = findNextAvailableFile('next');
|
|
444
|
+
if (nextFile) dispatch('navigate', nextFile);
|
|
469
445
|
}
|
|
470
446
|
}
|
|
471
447
|
|
|
@@ -654,8 +630,8 @@
|
|
|
654
630
|
!pdfLoadError &&
|
|
655
631
|
!(fileType === 'image' && imageRevealForId !== file.id);
|
|
656
632
|
|
|
657
|
-
$: canGoPrevious = showNavigation && findNextAvailableFile(
|
|
658
|
-
$: canGoNext = showNavigation && findNextAvailableFile(
|
|
633
|
+
$: canGoPrevious = showNavigation && findNextAvailableFile('prev') !== null;
|
|
634
|
+
$: canGoNext = showNavigation && findNextAvailableFile('next') !== null;
|
|
659
635
|
|
|
660
636
|
// The spinner: only for a picture that is STILL loading after `IMAGE_SLOW_LOADER_DELAY_MS` (the timer of the file that is
|
|
661
637
|
// open sets `slowLoaderForId`), never for one that was cached or arrived sooner, and never over an error card.
|
|
@@ -666,12 +642,12 @@
|
|
|
666
642
|
!showsErrorState;
|
|
667
643
|
|
|
668
644
|
function goPreviousFile() {
|
|
669
|
-
const prevFile = findNextAvailableFile(
|
|
645
|
+
const prevFile = findNextAvailableFile('prev');
|
|
670
646
|
if (prevFile) dispatch('navigate', prevFile);
|
|
671
647
|
}
|
|
672
648
|
|
|
673
649
|
function goNextFile() {
|
|
674
|
-
const nextFile = findNextAvailableFile(
|
|
650
|
+
const nextFile = findNextAvailableFile('next');
|
|
675
651
|
if (nextFile) dispatch('navigate', nextFile);
|
|
676
652
|
}
|
|
677
653
|
|
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;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Places brand-kit upload ids into the Widgetic library tree with stable folder names.
|
|
3
|
+
*/
|
|
4
|
+
import { dedupeTreeIds, findItemByIdInTree } from './libraryTree';
|
|
5
|
+
export const BRAND_KIT_ROOT_NAME = 'Brand kit';
|
|
6
|
+
export const BRAND_KIT_FONTS_FOLDER = 'Fonts';
|
|
7
|
+
export const BRAND_KIT_LOGOS_FOLDER = 'Logos';
|
|
8
|
+
function folderIdFor(path) {
|
|
9
|
+
return `fld_brand_${path.map((p) => p.toLowerCase().replace(/\s+/g, '_')).join('/')}`;
|
|
10
|
+
}
|
|
11
|
+
function cloneChildren(children) {
|
|
12
|
+
return children.map((item) => ({
|
|
13
|
+
...item,
|
|
14
|
+
children: item.children ? cloneChildren(item.children) : undefined
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
function namesInFolder(children) {
|
|
18
|
+
const out = new Set();
|
|
19
|
+
for (const item of children) {
|
|
20
|
+
if (item.type === 'file')
|
|
21
|
+
out.add(item.name.toLowerCase());
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/** `name (2).ext` when another file in the folder already uses `name.ext`. */
|
|
26
|
+
export function resolveCollisionFileName(desiredName, takenLower) {
|
|
27
|
+
if (!takenLower.has(desiredName.toLowerCase()))
|
|
28
|
+
return desiredName;
|
|
29
|
+
const match = /^(.+?)(\.[^.]+)?$/.exec(desiredName);
|
|
30
|
+
const stem = match?.[1] ?? desiredName;
|
|
31
|
+
const ext = match?.[2] ?? '';
|
|
32
|
+
let n = 2;
|
|
33
|
+
for (;;) {
|
|
34
|
+
const candidate = `${stem} (${n})${ext}`;
|
|
35
|
+
if (!takenLower.has(candidate.toLowerCase()))
|
|
36
|
+
return candidate;
|
|
37
|
+
n += 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function findChildFolder(children, name) {
|
|
41
|
+
const lower = name.toLowerCase();
|
|
42
|
+
for (const child of children) {
|
|
43
|
+
if (child.type === 'folder' && child.name.toLowerCase() === lower)
|
|
44
|
+
return child;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function ensureFolderPath(rootChildren, path) {
|
|
49
|
+
const next = dedupeTreeIds(cloneChildren(rootChildren));
|
|
50
|
+
let children = next;
|
|
51
|
+
for (let i = 0; i < path.length; i++) {
|
|
52
|
+
const segment = path[i];
|
|
53
|
+
let folder = findChildFolder(children, segment);
|
|
54
|
+
if (!folder) {
|
|
55
|
+
folder = {
|
|
56
|
+
id: folderIdFor(path.slice(0, i + 1)),
|
|
57
|
+
name: segment,
|
|
58
|
+
type: 'folder',
|
|
59
|
+
children: []
|
|
60
|
+
};
|
|
61
|
+
children.push(folder);
|
|
62
|
+
}
|
|
63
|
+
if (!folder.children)
|
|
64
|
+
folder.children = [];
|
|
65
|
+
children = folder.children;
|
|
66
|
+
}
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
69
|
+
function removeFileById(items, id) {
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
if (item.type === 'file' && item.id === id)
|
|
73
|
+
continue;
|
|
74
|
+
if (item.type === 'folder' && item.children?.length) {
|
|
75
|
+
out.push({ ...item, children: removeFileById(item.children, id) });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
out.push(item);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function folderChildrenAtPath(rootChildren, path) {
|
|
84
|
+
let children = rootChildren;
|
|
85
|
+
for (const segment of path) {
|
|
86
|
+
const folder = findChildFolder(children, segment);
|
|
87
|
+
if (!folder)
|
|
88
|
+
return null;
|
|
89
|
+
if (!folder.children)
|
|
90
|
+
folder.children = [];
|
|
91
|
+
children = folder.children;
|
|
92
|
+
}
|
|
93
|
+
return children;
|
|
94
|
+
}
|
|
95
|
+
export function fontFamilyFolderPath(family) {
|
|
96
|
+
return [BRAND_KIT_ROOT_NAME, BRAND_KIT_FONTS_FOLDER, family];
|
|
97
|
+
}
|
|
98
|
+
export function brandLogoFolderPath() {
|
|
99
|
+
return [BRAND_KIT_ROOT_NAME, BRAND_KIT_LOGOS_FOLDER];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Moves or inserts a file into the tree under `folderPath`, setting `name` to `displayName` (collision suffix applied).
|
|
103
|
+
*/
|
|
104
|
+
export function placeBrandKitFileInTree(rootChildren, input) {
|
|
105
|
+
let tree = ensureFolderPath(rootChildren ?? [], input.folderPath);
|
|
106
|
+
tree = removeFileById(tree, input.uploadId);
|
|
107
|
+
const targetChildren = folderChildrenAtPath(tree, input.folderPath);
|
|
108
|
+
if (!targetChildren)
|
|
109
|
+
return tree;
|
|
110
|
+
const taken = namesInFolder(targetChildren);
|
|
111
|
+
const name = resolveCollisionFileName(input.displayName, taken);
|
|
112
|
+
const file = {
|
|
113
|
+
id: input.uploadId,
|
|
114
|
+
name,
|
|
115
|
+
type: 'file',
|
|
116
|
+
modified: input.file?.modified ?? new Date(),
|
|
117
|
+
size: input.file?.size,
|
|
118
|
+
url: input.file?.url,
|
|
119
|
+
mimeType: input.file?.mimeType
|
|
120
|
+
};
|
|
121
|
+
targetChildren.push(file);
|
|
122
|
+
return dedupeTreeIds(tree);
|
|
123
|
+
}
|
|
124
|
+
/** Removes a file id wherever it sits in the tree (optimistic delete). */
|
|
125
|
+
export function removeBrandKitFileFromTree(rootChildren, uploadId) {
|
|
126
|
+
if (!rootChildren?.length)
|
|
127
|
+
return [];
|
|
128
|
+
return dedupeTreeIds(removeFileById(rootChildren, uploadId));
|
|
129
|
+
}
|
|
130
|
+
export function treeContainsUploadId(rootChildren, uploadId) {
|
|
131
|
+
if (!rootChildren?.length)
|
|
132
|
+
return false;
|
|
133
|
+
const root = { id: 'root', name: 'Root', type: 'folder', children: rootChildren };
|
|
134
|
+
return Boolean(findItemByIdInTree(root, uploadId));
|
|
135
|
+
}
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Grid column count from the file browser panel width (Figma File Tile ~264px, 16px gap).
|
|
3
|
+
* At 1152px panel width → 4 columns; scales up to 6 on very wide panels.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GRID_TILE_MIN_WIDTH_PX = 264;
|
|
6
|
+
export declare const GRID_GAP_PX = 16;
|
|
7
|
+
export declare const GRID_MAX_COLUMNS = 6;
|
|
8
|
+
/** Same rhythm for the recent-files strip (Figma 24px gap, ~3 cards at 1152px). */
|
|
9
|
+
export declare const RECENT_TILE_MIN_WIDTH_PX = 352;
|
|
10
|
+
export declare const RECENT_GAP_PX = 24;
|
|
11
|
+
export declare const RECENT_MAX_COLUMNS = 5;
|
|
12
|
+
/** Main folder/file grid. */
|
|
2
13
|
export declare function gridColumnsForWidth(width: number): number;
|
|
14
|
+
/** Recent files row — fewer columns at the same width (wider cards). */
|
|
15
|
+
export declare function recentGridColumnsForWidth(width: number): number;
|
package/dist/utils/gridLayout.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Grid column count from the file browser panel width (Figma File Tile ~264px, 16px gap).
|
|
3
|
+
* At 1152px panel width → 4 columns; scales up to 6 on very wide panels.
|
|
4
|
+
*/
|
|
5
|
+
export const GRID_TILE_MIN_WIDTH_PX = 264;
|
|
6
|
+
export const GRID_GAP_PX = 16;
|
|
7
|
+
export const GRID_MAX_COLUMNS = 6;
|
|
8
|
+
/** Same rhythm for the recent-files strip (Figma 24px gap, ~3 cards at 1152px). */
|
|
9
|
+
export const RECENT_TILE_MIN_WIDTH_PX = 352;
|
|
10
|
+
export const RECENT_GAP_PX = 24;
|
|
11
|
+
export const RECENT_MAX_COLUMNS = 5;
|
|
12
|
+
function columnsForWidth(width, minTile, gap, maxColumns) {
|
|
13
|
+
if (width < 420)
|
|
14
|
+
return 1;
|
|
15
|
+
const columns = Math.floor((width + gap) / (minTile + gap));
|
|
16
|
+
return Math.min(maxColumns, Math.max(1, columns));
|
|
17
|
+
}
|
|
18
|
+
/** Main folder/file grid. */
|
|
2
19
|
export function gridColumnsForWidth(width) {
|
|
3
20
|
if (width < 420)
|
|
4
21
|
return 1;
|
|
@@ -6,5 +23,13 @@ export function gridColumnsForWidth(width) {
|
|
|
6
23
|
return 2;
|
|
7
24
|
if (width < 1000)
|
|
8
25
|
return 3;
|
|
9
|
-
return
|
|
26
|
+
return columnsForWidth(width, GRID_TILE_MIN_WIDTH_PX, GRID_GAP_PX, GRID_MAX_COLUMNS);
|
|
27
|
+
}
|
|
28
|
+
/** Recent files row — fewer columns at the same width (wider cards). */
|
|
29
|
+
export function recentGridColumnsForWidth(width) {
|
|
30
|
+
if (width < 700)
|
|
31
|
+
return 2;
|
|
32
|
+
if (width < 1000)
|
|
33
|
+
return 3;
|
|
34
|
+
return columnsForWidth(width, RECENT_TILE_MIN_WIDTH_PX, RECENT_GAP_PX, RECENT_MAX_COLUMNS);
|
|
10
35
|
}
|