@widgetic/file-browser 0.5.39 → 0.5.41
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 +1 -1
- package/dist/components/FolderTree.svelte.d.ts +6 -2
- package/dist/components/core/Dropzone.svelte +147 -109
- package/dist/components/core/FileBrowser.svelte +128 -99
- package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
- package/dist/components/core/FileUploader.svelte +80 -51
- package/dist/components/core/Header.svelte +1 -1
- package/dist/components/core/RecentFiles.svelte +23 -11
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +125 -27
- package/dist/components/core/UploadPanel.svelte +2 -2
- package/dist/components/core/UploadRow.svelte +5 -5
- package/dist/components/items/FileItem.svelte +13 -3
- package/dist/components/items/FolderItem.svelte +8 -1
- package/dist/components/modals/MoveDialog.svelte +1 -1
- package/dist/components/modals/SelectedFilesModal.svelte +2 -2
- package/dist/components/modals/index.d.ts +0 -1
- package/dist/components/modals/index.js +0 -1
- package/dist/components/previews/FilePreview.svelte +198 -31
- package/dist/components/previews/FilePreview.svelte.d.ts +1 -0
- package/dist/components/previews/ImagePreview.svelte +60 -31
- package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +34 -26
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
- package/dist/components/previews/TextPreview.svelte +1 -1
- package/dist/components/previews/VideoPlayer.svelte +4 -4
- package/dist/components/ui/ControlToolbar.svelte +10 -10
- package/dist/components/ui/DragSelect.svelte +85 -67
- package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
- package/dist/components/ui/DropdownMenu.svelte +5 -5
- package/dist/components/ui/FileIcon.svelte +2 -2
- package/dist/data/demoContent.json +13 -11
- package/dist/i18n/messages.d.ts +0 -1
- package/dist/i18n/messages.js +0 -1
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/stores/navigationStore.d.ts +6 -1
- package/dist/stores/navigationStore.js +40 -67
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/utils/escapeSelectionAction.d.ts +18 -0
- package/dist/utils/escapeSelectionAction.js +18 -0
- package/dist/utils/imagePreviewCache.d.ts +16 -0
- package/dist/utils/imagePreviewCache.js +78 -0
- package/dist/utils/imagePreviewVisualState.d.ts +19 -0
- package/dist/utils/imagePreviewVisualState.js +22 -0
- package/dist/utils/menuKeydownBubble.d.ts +9 -0
- package/dist/utils/menuKeydownBubble.js +11 -0
- package/dist/utils/previewNavigation.d.ts +4 -0
- package/dist/utils/previewNavigation.js +17 -0
- package/dist/utils/recentFiles.d.ts +6 -0
- package/dist/utils/recentFiles.js +21 -0
- package/dist/utils/recentFilesLimit.d.ts +8 -0
- package/dist/utils/recentFilesLimit.js +17 -0
- package/dist/utils/searchEscapeAction.d.ts +10 -0
- package/dist/utils/searchEscapeAction.js +12 -0
- package/dist/utils/searchItems.d.ts +2 -4
- package/dist/utils/searchItems.js +12 -5
- package/dist/utils/searchNavigation.d.ts +12 -0
- package/dist/utils/searchNavigation.js +42 -0
- package/dist/utils/uploadDisplayProgress.d.ts +4 -0
- package/dist/utils/uploadDisplayProgress.js +9 -0
- package/dist/utils/uploadPanelProgress.d.ts +5 -0
- package/dist/utils/uploadPanelProgress.js +17 -0
- package/package.json +1 -1
- package/dist/components/modals/SearchModal.svelte +0 -296
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Panel-level upload bar must never visually regress (CSS width transitions amplify brief dips).
|
|
3
|
+
*/
|
|
4
|
+
export function monotonicPanelProgress(previousPeak, nextOverall, allSuccess) {
|
|
5
|
+
const safeNext = Number.isFinite(nextOverall) ? Math.min(100, Math.max(0, nextOverall)) : 0;
|
|
6
|
+
const safePeak = Number.isFinite(previousPeak) ? Math.min(100, Math.max(0, previousPeak)) : 0;
|
|
7
|
+
if (allSuccess)
|
|
8
|
+
return 100;
|
|
9
|
+
return Math.max(safePeak, safeNext);
|
|
10
|
+
}
|
|
11
|
+
export function nextUploadPanelPeak(previousPeak, displayProgress) {
|
|
12
|
+
const safeDisplay = Number.isFinite(displayProgress)
|
|
13
|
+
? Math.min(100, Math.max(0, displayProgress))
|
|
14
|
+
: 0;
|
|
15
|
+
const safePeak = Number.isFinite(previousPeak) ? Math.min(100, Math.max(0, previousPeak)) : 0;
|
|
16
|
+
return Math.max(safePeak, safeDisplay);
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* SearchModal Component
|
|
4
|
-
*
|
|
5
|
-
* Kept for hosts that mount this modal themselves. The File Browser uses inline SearchDropdown instead.
|
|
6
|
-
* Provides real-time search functionality for files and folders with keyboard navigation
|
|
7
|
-
* Features:
|
|
8
|
-
* - Instant search results as user types
|
|
9
|
-
* - Keyboard navigation (up/down arrows, enter)
|
|
10
|
-
* - Mouse hover interactions
|
|
11
|
-
* - File/folder path navigation
|
|
12
|
-
* - Filter support for different file types
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// Svelte imports
|
|
16
|
-
import { onDestroy } from 'svelte';
|
|
17
|
-
import { createEventDispatcher } from 'svelte';
|
|
18
|
-
const dispatch = createEventDispatcher();
|
|
19
|
-
|
|
20
|
-
// Design system imports
|
|
21
|
-
import { BaseModal, WScrollArea, EmptyState, IconButton } from '@widgetic/design-system/components';
|
|
22
|
-
import { IconSearch, IconX, IconCornerUpRight } from '@widgetic/design-system/icons';
|
|
23
|
-
|
|
24
|
-
// Local components imports
|
|
25
|
-
import { FileIcon } from '../ui';
|
|
26
|
-
|
|
27
|
-
// Local stores imports
|
|
28
|
-
import { fileStore } from '../../stores/fileStore';
|
|
29
|
-
import { searchTermStore } from '../../stores/searchStore';
|
|
30
|
-
|
|
31
|
-
// Local types imports
|
|
32
|
-
import type { FileSystemItem } from '../../types';
|
|
33
|
-
|
|
34
|
-
// Local utils imports
|
|
35
|
-
import { type FileFilterType } from '../../utils/fileTypes';
|
|
36
|
-
import { highlightMatchesAsHtml } from '../../utils/safeText';
|
|
37
|
-
import { filterSearchResults, findItemPath, searchFileSystem } from '../../utils/searchItems';
|
|
38
|
-
import { useI18n } from '../../i18n';
|
|
39
|
-
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
40
|
-
|
|
41
|
-
const { t } = useI18n();
|
|
42
|
-
const textDirection = useTextDirection();
|
|
43
|
-
$: nameDirection = dirForUserText($textDirection);
|
|
44
|
-
|
|
45
|
-
export let currentFilter: FileFilterType = 'all';
|
|
46
|
-
export let open = true;
|
|
47
|
-
export let target: string = 'search-modal'; // target for Portal
|
|
48
|
-
|
|
49
|
-
const resultsScrollMaxHeightPx = 400;
|
|
50
|
-
const matchHighlightClass = 'rounded-sm bg-brand-subtle px-0.5 text-body-medium';
|
|
51
|
-
|
|
52
|
-
let searchResults: FileSystemItem[] = [];
|
|
53
|
-
let activeIndex = 0;
|
|
54
|
-
let searchContainer: HTMLDivElement;
|
|
55
|
-
let resultsContainer: HTMLDivElement;
|
|
56
|
-
let queryInput: HTMLInputElement;
|
|
57
|
-
|
|
58
|
-
$: if (open && searchContainer) {
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
queryInput?.focus();
|
|
61
|
-
}, 0);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function handleClose() {
|
|
65
|
-
open = false;
|
|
66
|
-
dispatch('close');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function handleMouseEnter(index: number) {
|
|
70
|
-
activeIndex = index;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
74
|
-
|
|
75
|
-
onDestroy(() => {
|
|
76
|
-
if (searchDebounceTimer) {
|
|
77
|
-
clearTimeout(searchDebounceTimer);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
$: {
|
|
82
|
-
const term = $searchTermStore?.trim().toLowerCase();
|
|
83
|
-
const filter = currentFilter;
|
|
84
|
-
const root = $fileStore.root;
|
|
85
|
-
|
|
86
|
-
if (searchDebounceTimer) {
|
|
87
|
-
clearTimeout(searchDebounceTimer);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (term) {
|
|
91
|
-
searchDebounceTimer = setTimeout(() => {
|
|
92
|
-
searchResults = filterSearchResults(searchFileSystem(root, term, filter), filter);
|
|
93
|
-
activeIndex = 0;
|
|
94
|
-
}, 150);
|
|
95
|
-
} else {
|
|
96
|
-
searchResults = [];
|
|
97
|
-
activeIndex = -1;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function handleKeydown(event: KeyboardEvent) {
|
|
102
|
-
if (!searchResults.length) return;
|
|
103
|
-
|
|
104
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
105
|
-
event.preventDefault();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (event.key === 'ArrowDown') {
|
|
109
|
-
activeIndex = (activeIndex + 1) % searchResults.length;
|
|
110
|
-
setTimeout(() => scrollActiveItemIntoView(), 0);
|
|
111
|
-
} else if (event.key === 'ArrowUp') {
|
|
112
|
-
activeIndex = activeIndex <= 0 ? searchResults.length - 1 : activeIndex - 1;
|
|
113
|
-
setTimeout(() => scrollActiveItemIntoView(), 0);
|
|
114
|
-
} else if (event.key === 'Enter' && activeIndex >= 0) {
|
|
115
|
-
event.preventDefault();
|
|
116
|
-
handleResultClick(searchResults[activeIndex]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function scrollActiveItemIntoView() {
|
|
121
|
-
if (!resultsContainer) return;
|
|
122
|
-
|
|
123
|
-
const activeItem = resultsContainer.querySelector(
|
|
124
|
-
`.search-result-item:nth-child(${activeIndex + 1})`
|
|
125
|
-
) as HTMLElement;
|
|
126
|
-
|
|
127
|
-
if (activeItem) {
|
|
128
|
-
activeItem.scrollIntoView({
|
|
129
|
-
behavior: 'smooth',
|
|
130
|
-
block: 'nearest'
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function highlightMatch(name: string, term: string): string {
|
|
136
|
-
return highlightMatchesAsHtml(name, term, matchHighlightClass);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function handleResultClick(item: FileSystemItem) {
|
|
140
|
-
const idPath = findItemPath($fileStore.root, item);
|
|
141
|
-
|
|
142
|
-
if (idPath) {
|
|
143
|
-
const folderPath = idPath[0] === $fileStore.root.id ? idPath.slice(1) : idPath;
|
|
144
|
-
|
|
145
|
-
if (item.type === 'file') {
|
|
146
|
-
folderPath.pop();
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
dispatch('preview', item);
|
|
149
|
-
}, 100);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
dispatch('navigate', { path: folderPath });
|
|
153
|
-
} else {
|
|
154
|
-
console.error('Path not found for item:', item);
|
|
155
|
-
}
|
|
156
|
-
dispatch('close');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function handleSearchInput(event: Event) {
|
|
160
|
-
const input = event.target as HTMLInputElement;
|
|
161
|
-
input.value = input.value.replace(/^\s+/, '');
|
|
162
|
-
searchTermStore.set(input.value);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function handleInputKeydown(e: KeyboardEvent) {
|
|
166
|
-
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
167
|
-
handleKeydown(e);
|
|
168
|
-
} else if (e.key === 'Enter' && searchResults.length > 0) {
|
|
169
|
-
e.preventDefault();
|
|
170
|
-
handleResultClick(searchResults[activeIndex]);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function clearQuery() {
|
|
175
|
-
searchTermStore.set('');
|
|
176
|
-
queryInput?.focus();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
$: modalHeight =
|
|
180
|
-
!$searchTermStore?.trim()
|
|
181
|
-
? '64px'
|
|
182
|
-
: searchResults.length > 0
|
|
183
|
-
? 'auto'
|
|
184
|
-
: '305px';
|
|
185
|
-
</script>
|
|
186
|
-
|
|
187
|
-
<BaseModal
|
|
188
|
-
class="search-modal"
|
|
189
|
-
bind:open
|
|
190
|
-
bare
|
|
191
|
-
on:close={handleClose}
|
|
192
|
-
{target}
|
|
193
|
-
width="566px"
|
|
194
|
-
height={modalHeight}
|
|
195
|
-
animateSize={true}
|
|
196
|
-
showScroll={false}
|
|
197
|
-
modalType="search"
|
|
198
|
-
modalData={{ searchTerm: $searchTermStore }}
|
|
199
|
-
on:restore={(event) => {
|
|
200
|
-
if (event.detail?.searchTerm) {
|
|
201
|
-
searchTermStore.set(event.detail.searchTerm);
|
|
202
|
-
}
|
|
203
|
-
}}
|
|
204
|
-
>
|
|
205
|
-
<div class="flex w-full flex-col">
|
|
206
|
-
<div
|
|
207
|
-
class="flex h-16 w-full items-center gap-3 ps-6 pe-4"
|
|
208
|
-
bind:this={searchContainer}
|
|
209
|
-
>
|
|
210
|
-
<IconSearch class="size-5 shrink-0 stroke-[1.667] text-foreground" aria-hidden="true" />
|
|
211
|
-
<input
|
|
212
|
-
bind:this={queryInput}
|
|
213
|
-
type="search"
|
|
214
|
-
value={$searchTermStore}
|
|
215
|
-
on:input={handleSearchInput}
|
|
216
|
-
placeholder={$t('searchModal.placeholder')}
|
|
217
|
-
class="min-w-0 flex-1 appearance-none border-0 bg-transparent text-heading-page text-foreground placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-0 [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden"
|
|
218
|
-
on:keydown={(e) => {
|
|
219
|
-
if (e.key === 'Escape') {
|
|
220
|
-
handleClose();
|
|
221
|
-
} else {
|
|
222
|
-
e.stopPropagation();
|
|
223
|
-
if (
|
|
224
|
-
e.key === 'ArrowDown' ||
|
|
225
|
-
e.key === 'ArrowUp' ||
|
|
226
|
-
(e.key === 'Enter' && searchResults.length > 0)
|
|
227
|
-
) {
|
|
228
|
-
handleInputKeydown(e);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}}
|
|
232
|
-
autocomplete="off"
|
|
233
|
-
spellcheck="false"
|
|
234
|
-
/>
|
|
235
|
-
{#if $searchTermStore}
|
|
236
|
-
<IconButton variant="ghost" label={$t('searchModal.clearQuery')} class="size-8 shrink-0" onclick={clearQuery}>
|
|
237
|
-
<IconX class="size-4 stroke-[1.333]" />
|
|
238
|
-
</IconButton>
|
|
239
|
-
{/if}
|
|
240
|
-
</div>
|
|
241
|
-
|
|
242
|
-
{#if $searchTermStore?.trim()}
|
|
243
|
-
{#if searchResults.length > 0}
|
|
244
|
-
<div class="border-t border-border" role="separator"></div>
|
|
245
|
-
<WScrollArea
|
|
246
|
-
class="search-results-scroll-area w-full"
|
|
247
|
-
style="max-height: {resultsScrollMaxHeightPx}px;"
|
|
248
|
-
scrollOutside={true}
|
|
249
|
-
>
|
|
250
|
-
<div class="flex flex-col py-2" bind:this={resultsContainer}>
|
|
251
|
-
{#each searchResults as result, index (result.id || `${result.type}-${index}`)}
|
|
252
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
253
|
-
<div
|
|
254
|
-
class="search-result-item mx-2 flex min-h-12 items-center gap-3 rounded-xl py-2 ps-2 pe-3 transition-colors duration-fast
|
|
255
|
-
{index === activeIndex ? 'bg-accent' : 'hover:bg-accent'}"
|
|
256
|
-
on:mouseenter={() => handleMouseEnter(index)}
|
|
257
|
-
>
|
|
258
|
-
<button
|
|
259
|
-
type="button"
|
|
260
|
-
class="flex min-w-0 flex-1 items-center gap-3 text-start focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
261
|
-
on:click={() => handleResultClick(result)}
|
|
262
|
-
>
|
|
263
|
-
<FileIcon
|
|
264
|
-
file={result}
|
|
265
|
-
kind={result.isMissing ? 'missing' : result.type === 'folder' ? 'folder' : undefined}
|
|
266
|
-
size="sm"
|
|
267
|
-
class="shrink-0"
|
|
268
|
-
/>
|
|
269
|
-
<div class="min-w-0 flex-1">
|
|
270
|
-
<div dir={nameDirection} class="truncate text-body">
|
|
271
|
-
{@html highlightMatch(result.name, $searchTermStore.trim())}
|
|
272
|
-
</div>
|
|
273
|
-
</div>
|
|
274
|
-
</button>
|
|
275
|
-
{#if index === activeIndex}
|
|
276
|
-
<span class="hidden shrink-0 items-center gap-1 text-caption text-muted-foreground sm:flex">
|
|
277
|
-
{$t('searchModal.jumpToFolder')}
|
|
278
|
-
<IconCornerUpRight class="size-4 stroke-[1.333] rtl:rotate-180" aria-hidden="true" />
|
|
279
|
-
</span>
|
|
280
|
-
{/if}
|
|
281
|
-
</div>
|
|
282
|
-
{/each}
|
|
283
|
-
</div>
|
|
284
|
-
</WScrollArea>
|
|
285
|
-
{:else}
|
|
286
|
-
<div class="border-t border-border"></div>
|
|
287
|
-
<div
|
|
288
|
-
class="flex flex-col items-center justify-center px-6 py-8"
|
|
289
|
-
style="min-height: 200px;"
|
|
290
|
-
>
|
|
291
|
-
<EmptyState message={$t('searchModal.empty')} />
|
|
292
|
-
</div>
|
|
293
|
-
{/if}
|
|
294
|
-
{/if}
|
|
295
|
-
</div>
|
|
296
|
-
</BaseModal>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type FileFilterType } from '../../utils/fileTypes';
|
|
2
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const SearchModal: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
-
currentFilter?: FileFilterType;
|
|
17
|
-
open?: boolean;
|
|
18
|
-
target?: string;
|
|
19
|
-
}, {
|
|
20
|
-
close: CustomEvent<any>;
|
|
21
|
-
preview: CustomEvent<any>;
|
|
22
|
-
navigate: CustomEvent<any>;
|
|
23
|
-
} & {
|
|
24
|
-
[evt: string]: CustomEvent<any>;
|
|
25
|
-
}, {}, {}, string>;
|
|
26
|
-
type SearchModal = InstanceType<typeof SearchModal>;
|
|
27
|
-
export default SearchModal;
|