@widgetic/file-browser 0.5.41 → 0.5.43
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/actions/dragSelectedToFolder.d.ts +41 -0
- package/dist/actions/dragSelectedToFolder.js +320 -0
- package/dist/components/core/FileBrowser.svelte +239 -36
- package/dist/components/core/Header.svelte +4 -0
- package/dist/components/core/Header.svelte.d.ts +2 -0
- package/dist/components/drag/DragGhostStack.svelte +69 -0
- package/dist/components/drag/DragGhostStack.svelte.d.ts +21 -0
- package/dist/components/items/FolderItem.svelte +5 -2
- package/dist/components/previews/FilePreview.svelte +87 -26
- package/dist/components/previews/FilePreview.svelte.d.ts +6 -3
- package/dist/components/previews/FontPreview.svelte +4 -1
- package/dist/components/previews/FontPreview.svelte.d.ts +2 -0
- package/dist/components/ui/DragSelect.svelte +8 -0
- package/dist/components/ui/DropdownMenu.svelte +9 -8
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/utils/dragToFolder/batchMoveResult.d.ts +18 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +87 -0
- package/dist/utils/dragToFolder/folderDropTarget.d.ts +15 -0
- package/dist/utils/dragToFolder/folderDropTarget.js +71 -0
- package/dist/utils/dragToFolder/springStep.d.ts +16 -0
- package/dist/utils/dragToFolder/springStep.js +21 -0
- package/dist/utils/fileOperations.d.ts +5 -0
- package/dist/utils/fileOperations.js +72 -0
- package/dist/utils/imagePreviewFrame.d.ts +22 -0
- package/dist/utils/imagePreviewFrame.js +29 -0
- package/dist/utils/itemMenuCapabilities.d.ts +19 -0
- package/dist/utils/itemMenuCapabilities.js +13 -0
- package/dist/utils/libraryTree.d.ts +5 -2
- package/dist/utils/libraryTree.js +15 -35
- package/dist/utils/uploadListReconcile.d.ts +11 -0
- package/dist/utils/uploadListReconcile.js +30 -0
- package/dist/utils/userUploadsStorage.d.ts +8 -0
- package/dist/utils/userUploadsStorage.js +36 -2
- package/package.json +3 -3
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
// Svelte imports
|
|
8
8
|
import { onMount } from 'svelte';
|
|
9
9
|
import { createEventDispatcher } from 'svelte';
|
|
10
|
-
const dispatch = createEventDispatcher
|
|
10
|
+
const dispatch = createEventDispatcher<{
|
|
11
|
+
navigate: FileSystemItem;
|
|
12
|
+
select: FileSystemItem;
|
|
13
|
+
close: void;
|
|
14
|
+
fileUnavailable: { id: string };
|
|
15
|
+
}>();
|
|
11
16
|
|
|
12
17
|
// Design System Components imports
|
|
13
18
|
import { BaseModal, PDFViewer, EmptyState } from '@widgetic/design-system/components';
|
|
@@ -35,10 +40,11 @@
|
|
|
35
40
|
import { previewKeyAction } from '../../utils/previewKeys';
|
|
36
41
|
import { getCachedImageNaturalSize, preloadImageUrl, probeDecodedImage } from '../../utils/imagePreviewCache';
|
|
37
42
|
import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
|
|
43
|
+
import { computeImagePreviewModalFrame } from '../../utils/imagePreviewFrame';
|
|
38
44
|
|
|
39
45
|
// Stores
|
|
40
|
-
import { missingFiles } from '../../stores/missingFilesStore';
|
|
41
|
-
import {
|
|
46
|
+
import { addMissingFile, missingFiles } from '../../stores/missingFilesStore';
|
|
47
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
42
48
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
43
49
|
import { useI18n } from '../../i18n';
|
|
44
50
|
import { formatFileSize } from '../../utils/fileUtils';
|
|
@@ -65,6 +71,8 @@
|
|
|
65
71
|
/** Shell vertical padding (p-6 top + bottom, and the 1px border of the card on each side). */
|
|
66
72
|
const MODAL_VERTICAL_PAD = 50;
|
|
67
73
|
const TOTAL_VERTICAL_SPACE = MODAL_VERTICAL_PAD + HEADER_BLOCK;
|
|
74
|
+
/** Image cards open once at their final size (BaseModal still fades / slides in). */
|
|
75
|
+
const IMAGE_PREVIEW_ANIMATES_SIZE = false;
|
|
68
76
|
|
|
69
77
|
// STATE VARS
|
|
70
78
|
let showLogs = false;
|
|
@@ -194,7 +202,8 @@
|
|
|
194
202
|
};
|
|
195
203
|
}
|
|
196
204
|
|
|
197
|
-
$: isSelected =
|
|
205
|
+
$: isSelected =
|
|
206
|
+
allowSelecting && ($persistentSelectStore[currentFilter] ?? []).includes(file.id);
|
|
198
207
|
let fittedImage: { width: string; height: string } | null = null;
|
|
199
208
|
let fittedImageForId = '';
|
|
200
209
|
|
|
@@ -243,7 +252,10 @@
|
|
|
243
252
|
if (file.id !== fileId || imageRevealForId === fileId || imageBitmapReadyForId !== fileId) return;
|
|
244
253
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
245
254
|
// A card that never got a size (the picture reported none) has no move to wait for
|
|
246
|
-
const waitMs =
|
|
255
|
+
const waitMs =
|
|
256
|
+
IMAGE_PREVIEW_ANIMATES_SIZE && frameSizedForId === fileId
|
|
257
|
+
? imageRevealDelayMs(frameSizedAtMs, performance.now())
|
|
258
|
+
: 0;
|
|
247
259
|
imageRevealTimer = setTimeout(() => {
|
|
248
260
|
imageRevealTimer = undefined;
|
|
249
261
|
if (file.id !== fileId || imageBitmapReadyForId !== fileId) return;
|
|
@@ -281,19 +293,16 @@
|
|
|
281
293
|
const styles = getComputedStyle(element);
|
|
282
294
|
margin = parseInt(styles.getPropertyValue('--app-margin').trim()) || margin;
|
|
283
295
|
}
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
);
|
|
293
|
-
const next = {
|
|
294
|
-
width: `${cardWidth}px`,
|
|
295
|
-
height: `${Math.max(100, Math.round(height * scale) + TOTAL_VERTICAL_SPACE)}px`
|
|
296
|
-
};
|
|
296
|
+
const computed = computeImagePreviewModalFrame(width, height, {
|
|
297
|
+
hostWidth: frame.width,
|
|
298
|
+
hostHeight: frame.height,
|
|
299
|
+
sideMargin: margin,
|
|
300
|
+
dialogHorizontalPad: DIALOG_HORIZONTAL_PAD,
|
|
301
|
+
headerBlock: HEADER_BLOCK,
|
|
302
|
+
verticalPad: MODAL_VERTICAL_PAD,
|
|
303
|
+
minDialogWidth: MIN_IMAGE_DIALOG_WIDTH
|
|
304
|
+
});
|
|
305
|
+
const next = { width: computed.width, height: computed.height };
|
|
297
306
|
const id = file.id;
|
|
298
307
|
fittedImageForId = id;
|
|
299
308
|
fittedImage = next;
|
|
@@ -301,19 +310,47 @@
|
|
|
301
310
|
frameSizedAtMs = performance.now();
|
|
302
311
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
303
312
|
imageRevealTimer = undefined;
|
|
304
|
-
|
|
305
|
-
|
|
313
|
+
const revealNow =
|
|
314
|
+
options?.revealImmediately || !IMAGE_PREVIEW_ANIMATES_SIZE;
|
|
315
|
+
if (revealNow) {
|
|
306
316
|
imageBitmapReadyForId = id;
|
|
307
317
|
imageRevealForId = id;
|
|
308
318
|
slowLoaderForId = '';
|
|
309
319
|
return;
|
|
310
320
|
}
|
|
311
|
-
// The card eases to this size first. The picture stays hidden until it has loaded AND the card has made that move
|
|
312
|
-
// (if it loaded already, it appears when the move is over; if not, `handleImageBitmapLoaded` shows it when it arrives).
|
|
313
321
|
imageRevealForId = '';
|
|
314
322
|
revealImageWhenReady(id);
|
|
315
323
|
}
|
|
316
324
|
|
|
325
|
+
async function ensureImageFrameBeforeOpen() {
|
|
326
|
+
if (!open || fileType !== 'image' || !fileUrl || fittedImageForId === file.id) return;
|
|
327
|
+
let width = file.width;
|
|
328
|
+
let height = file.height;
|
|
329
|
+
if (!width || !height) {
|
|
330
|
+
const cached = getCachedImageNaturalSize(fileUrl) ?? probeDecodedImage(fileUrl);
|
|
331
|
+
if (cached) {
|
|
332
|
+
width = cached.width;
|
|
333
|
+
height = cached.height;
|
|
334
|
+
} else {
|
|
335
|
+
await preloadImageUrl(fileUrl);
|
|
336
|
+
const afterLoad = getCachedImageNaturalSize(fileUrl);
|
|
337
|
+
if (afterLoad) {
|
|
338
|
+
width = afterLoad.width;
|
|
339
|
+
height = afterLoad.height;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (file.id !== imageStateForFileId || fittedImageForId === file.id) return;
|
|
344
|
+
if (width && height) {
|
|
345
|
+
fitImageFrame(width, height, { revealImmediately: true });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const frame = hostFrame();
|
|
349
|
+
fitImageFrame(Math.round(frame.width * 0.55), Math.round(frame.height * 0.45), {
|
|
350
|
+
revealImmediately: true
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
317
354
|
function revealCachedImageIfReady() {
|
|
318
355
|
if (!open || fileType !== 'image' || !hasValidUrl || !fileUrl) return;
|
|
319
356
|
const id = file.id;
|
|
@@ -323,7 +360,7 @@
|
|
|
323
360
|
// The browser may still hold the picture decoded (opened before, or loaded as a neighbour): then it is shown at once
|
|
324
361
|
const cached = probeDecodedImage(fileUrl);
|
|
325
362
|
if (file.width && file.height) {
|
|
326
|
-
fitImageFrame(file.width, file.height, { revealImmediately:
|
|
363
|
+
fitImageFrame(file.width, file.height, { revealImmediately: true });
|
|
327
364
|
return;
|
|
328
365
|
}
|
|
329
366
|
if (cached) {
|
|
@@ -387,10 +424,14 @@
|
|
|
387
424
|
|
|
388
425
|
/** Size the shell from catalogued dimensions or a warm decoder cache before the bitmap loads. */
|
|
389
426
|
$: if (open && file?.id && fileUrl && fileType === 'image' && imageStateForFileId === file.id) {
|
|
427
|
+
void ensureImageFrameBeforeOpen();
|
|
390
428
|
revealCachedImageIfReady();
|
|
391
429
|
preloadNeighborPreviewImages();
|
|
392
430
|
}
|
|
393
431
|
|
|
432
|
+
$: modalPanelShown =
|
|
433
|
+
fileType !== 'image' || showsErrorState || fittedImageForId === file.id;
|
|
434
|
+
|
|
394
435
|
// The card's size. It stays BELOW the block above on purpose: that block sets `fittedImage` and `fittedImageForId`
|
|
395
436
|
// inside a function, so Svelte cannot order the two statements by their assignments. A statement placed above it reads
|
|
396
437
|
// the frame of the previous file in the same update (the small loading card) and does not run again, so a file that
|
|
@@ -485,11 +526,26 @@
|
|
|
485
526
|
$: isPDF = fileType === 'document' && file.name.toLowerCase().endsWith('.pdf');
|
|
486
527
|
$: isPreviewableText = fileType === 'document' && isPreviewableTextFile(file.name);
|
|
487
528
|
|
|
529
|
+
let reportedUnavailableForId = '';
|
|
530
|
+
|
|
531
|
+
function reportFileUnavailable(fileId: string) {
|
|
532
|
+
if (reportedUnavailableForId === fileId) return;
|
|
533
|
+
reportedUnavailableForId = fileId;
|
|
534
|
+
addMissingFile(fileId);
|
|
535
|
+
dispatch('fileUnavailable', { id: fileId });
|
|
536
|
+
}
|
|
537
|
+
|
|
488
538
|
// Autoplay when component mounts
|
|
489
539
|
onMount(() => {
|
|
490
540
|
|
|
491
541
|
if(showLogs) console.log('FilePreview: onMount: file:', file);
|
|
492
542
|
|
|
543
|
+
if (fileType === 'font' && file.url) {
|
|
544
|
+
void checkFileExists(file.url).then((ok) => {
|
|
545
|
+
if (!ok) reportFileUnavailable(file.id);
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
493
549
|
// Autoplay media when component mounts
|
|
494
550
|
if (videoElement || audioElement) {
|
|
495
551
|
const mediaElement = videoElement || audioElement;
|
|
@@ -631,7 +687,8 @@
|
|
|
631
687
|
ariaLabel={file.name}
|
|
632
688
|
width={modalDimensions.width}
|
|
633
689
|
height={modalDimensions.height}
|
|
634
|
-
animateSize={fileType === '
|
|
690
|
+
animateSize={fileType === 'video'}
|
|
691
|
+
shown={modalPanelShown}
|
|
635
692
|
{target}
|
|
636
693
|
showScroll={false}
|
|
637
694
|
on:close={handleClose}
|
|
@@ -693,7 +750,8 @@
|
|
|
693
750
|
<FontPreview
|
|
694
751
|
src={fileUrl}
|
|
695
752
|
{fontName}
|
|
696
|
-
previewText={file.previewText || undefined}
|
|
753
|
+
previewText={file.previewText || undefined}
|
|
754
|
+
on:unavailable={() => reportFileUnavailable(file.id)}
|
|
697
755
|
/>
|
|
698
756
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
699
757
|
{#if fileType === 'svg'}
|
|
@@ -724,7 +782,10 @@
|
|
|
724
782
|
maxContentHeight={hostFrame().height - TOTAL_VERTICAL_SPACE - 48}
|
|
725
783
|
initiallyLoaded={imageLoaded}
|
|
726
784
|
on:load={handleImageBitmapLoaded}
|
|
727
|
-
on:error={() =>
|
|
785
|
+
on:error={() => {
|
|
786
|
+
imageFailed = true;
|
|
787
|
+
reportFileUnavailable(file.id);
|
|
788
|
+
}}
|
|
728
789
|
on:dimensions={(event) => {
|
|
729
790
|
const { width, height } = event.detail;
|
|
730
791
|
if (!width || !height) return;
|
|
@@ -22,9 +22,12 @@ declare const FilePreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
22
22
|
currentFilter?: FileFilterType;
|
|
23
23
|
target?: string;
|
|
24
24
|
}, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
close: CustomEvent<
|
|
25
|
+
navigate: CustomEvent<FileSystemItem>;
|
|
26
|
+
select: CustomEvent<FileSystemItem>;
|
|
27
|
+
close: CustomEvent<void>;
|
|
28
|
+
fileUnavailable: CustomEvent<{
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
28
31
|
} & {
|
|
29
32
|
[evt: string]: CustomEvent<any>;
|
|
30
33
|
}, {}, {}, string>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { onMount } from 'svelte';
|
|
2
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
3
3
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
4
|
+
|
|
5
|
+
const dispatch = createEventDispatcher<{ unavailable: void }>();
|
|
4
6
|
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
5
7
|
import { useI18n } from '../../i18n';
|
|
6
8
|
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
} catch (error) {
|
|
28
30
|
console.error('FontPreview: Error loading font from url:', src, error);
|
|
29
31
|
hasError = true;
|
|
32
|
+
dispatch('unavailable');
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
35
|
</script>
|
|
@@ -16,6 +16,8 @@ declare const FontPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
16
16
|
fontName: string;
|
|
17
17
|
/** The sentence shown in the font. Left out, a pangram in the page's language ("The quick brown fox jumps over the lazy dog"). */ previewText?: string | undefined;
|
|
18
18
|
}, {
|
|
19
|
+
unavailable: CustomEvent<void>;
|
|
20
|
+
} & {
|
|
19
21
|
[evt: string]: CustomEvent<any>;
|
|
20
22
|
}, {}, {}, string>;
|
|
21
23
|
type FontPreview = InstanceType<typeof FontPreview>;
|
|
@@ -206,6 +206,14 @@
|
|
|
206
206
|
|
|
207
207
|
const itemContainer = target.closest('.item-container');
|
|
208
208
|
startItemId = itemContainer?.getAttribute('data-item-id') || null;
|
|
209
|
+
|
|
210
|
+
// Selected file tiles use drag-to-folder; do not start rubber-band on that press.
|
|
211
|
+
if (
|
|
212
|
+
itemContainer?.getAttribute('data-selected') === 'true' &&
|
|
213
|
+
!itemContainer.querySelector('[data-fb-action="open-folder"]')
|
|
214
|
+
) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
209
217
|
|
|
210
218
|
mouseIsDown = true;
|
|
211
219
|
dragStartTime = Date.now();
|
|
@@ -15,24 +15,25 @@
|
|
|
15
15
|
} from '@widgetic/design-system/icons';
|
|
16
16
|
import { useMediaLibraryContext } from '../../mediaLibrary/context';
|
|
17
17
|
import { useI18n } from '../../i18n';
|
|
18
|
+
import { itemMenuCapabilities } from '../../utils/itemMenuCapabilities';
|
|
18
19
|
|
|
19
20
|
const { t } = useI18n();
|
|
20
21
|
|
|
21
22
|
export let isFolder: boolean;
|
|
22
23
|
export let fileUrl: string | undefined = undefined;
|
|
23
24
|
export let isMissing: boolean = false;
|
|
24
|
-
/**
|
|
25
|
+
/** Folder or file id (used by callers; kept for future capability rules). */
|
|
26
|
+
// svelte-ignore export_let_unused
|
|
25
27
|
export let itemId: string | undefined = undefined;
|
|
26
28
|
|
|
27
29
|
const { capabilities } = useMediaLibraryContext();
|
|
28
30
|
|
|
29
|
-
$:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
$: hasAnyAction = canRename || canMove || canDownload || canDelete;
|
|
31
|
+
$: ({ canRename, canMove, canDownload, canDelete, hasAnyAction } = itemMenuCapabilities({
|
|
32
|
+
capabilities,
|
|
33
|
+
isFolder,
|
|
34
|
+
isMissing,
|
|
35
|
+
fileUrl
|
|
36
|
+
}));
|
|
36
37
|
|
|
37
38
|
const triggerClass =
|
|
38
39
|
'inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-foreground transition-colors duration-fast hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background';
|
|
@@ -16,7 +16,7 @@ declare const DropdownMenu: $$__sveltets_2_IsomorphicComponent<{
|
|
|
16
16
|
isFolder: boolean;
|
|
17
17
|
fileUrl?: string | undefined;
|
|
18
18
|
isMissing?: boolean;
|
|
19
|
-
/**
|
|
19
|
+
/** Folder or file id (used by callers; kept for future capability rules). */ itemId?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
action: CustomEvent<any>;
|
|
22
22
|
} & {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export * from './components';
|
|
|
3
3
|
export * from './stores';
|
|
4
4
|
export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, type FileBrowserUploadConfig, } from './stores/uploadApiStore';
|
|
5
5
|
export * from './utils';
|
|
6
|
+
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
7
|
+
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
8
|
+
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
6
9
|
export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
|
|
7
10
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
8
11
|
export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,9 @@ export * from './stores';
|
|
|
7
7
|
export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, } from './stores/uploadApiStore';
|
|
8
8
|
// Export all utilities
|
|
9
9
|
export * from './utils';
|
|
10
|
+
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
11
|
+
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
12
|
+
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
10
13
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
11
14
|
// Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
|
|
12
15
|
// a page or a build step can run on its own messages.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../../types';
|
|
2
|
+
import type { FileFilterType } from '../fileTypes';
|
|
3
|
+
export type BatchMoveCommitResult = {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
movedIds: string[];
|
|
6
|
+
failedCount: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Commits a batch move (API when needed, then one atomic tree update).
|
|
10
|
+
* Mirrors MoveDialog semantics.
|
|
11
|
+
*/
|
|
12
|
+
export declare function commitBatchMove(args: {
|
|
13
|
+
sourceItems: FileSystemItem[];
|
|
14
|
+
targetFolderId: string;
|
|
15
|
+
localOnly: boolean;
|
|
16
|
+
currentFilter: FileFilterType;
|
|
17
|
+
navigationStoreId?: string;
|
|
18
|
+
}): Promise<BatchMoveCommitResult>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ENDPOINTS } from '../apiConfig';
|
|
2
|
+
import { findItemById, moveItems } from '../fileOperations';
|
|
3
|
+
import { MediaLibraryError } from '../../mediaLibrary/errors';
|
|
4
|
+
import { get } from 'svelte/store';
|
|
5
|
+
import { fileStore } from '../../stores/fileStore';
|
|
6
|
+
import { getNavigationStore } from '../../stores/navigationStore';
|
|
7
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
8
|
+
function actualTargetId(targetFolderId) {
|
|
9
|
+
const root = get(fileStore).root;
|
|
10
|
+
if (targetFolderId === 'root' || (root && targetFolderId === root.id)) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
return targetFolderId;
|
|
14
|
+
}
|
|
15
|
+
function findFolderPath(root, targetId) {
|
|
16
|
+
const search = (folder, path = []) => {
|
|
17
|
+
if (folder.id === targetId)
|
|
18
|
+
return path;
|
|
19
|
+
if (folder.children) {
|
|
20
|
+
for (const child of folder.children) {
|
|
21
|
+
if (child.type === 'folder') {
|
|
22
|
+
const result = search(child, [...path, child.id]);
|
|
23
|
+
if (result !== null)
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
return targetId ? search(root) : [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Commits a batch move (API when needed, then one atomic tree update).
|
|
34
|
+
* Mirrors MoveDialog semantics.
|
|
35
|
+
*/
|
|
36
|
+
export async function commitBatchMove(args) {
|
|
37
|
+
const { sourceItems, targetFolderId, localOnly, currentFilter, navigationStoreId } = args;
|
|
38
|
+
if (sourceItems.length === 0) {
|
|
39
|
+
return { ok: false, movedIds: [], failedCount: 0 };
|
|
40
|
+
}
|
|
41
|
+
const actualTarget = actualTargetId(targetFolderId);
|
|
42
|
+
const navigationStore = getNavigationStore(navigationStoreId);
|
|
43
|
+
const moveEndpoint = typeof window !== 'undefined' && import.meta.env.DEV
|
|
44
|
+
? '/api/files/move'
|
|
45
|
+
: ENDPOINTS.FILE_MOVE;
|
|
46
|
+
const apiResults = await Promise.allSettled(sourceItems.map((sourceItem) => localOnly
|
|
47
|
+
? Promise.resolve({ success: true })
|
|
48
|
+
: fetch(moveEndpoint, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
itemId: sourceItem.id,
|
|
53
|
+
targetFolderId: actualTarget
|
|
54
|
+
})
|
|
55
|
+
}).then((response) => response.json())));
|
|
56
|
+
const idsToMove = [];
|
|
57
|
+
let failedCount = 0;
|
|
58
|
+
apiResults.forEach((result, index) => {
|
|
59
|
+
const sourceItem = sourceItems[index];
|
|
60
|
+
if (result.status === 'fulfilled' && result.value.success) {
|
|
61
|
+
idsToMove.push(sourceItem.id);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
failedCount += 1;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (idsToMove.length === 0) {
|
|
68
|
+
return { ok: false, movedIds: [], failedCount };
|
|
69
|
+
}
|
|
70
|
+
const movedIds = moveItems(idsToMove, actualTarget);
|
|
71
|
+
if (movedIds.length === 0) {
|
|
72
|
+
throw new MediaLibraryError('FAILED', 'Tree update failed after move', {
|
|
73
|
+
messageKey: 'moveDialog.noneMoved'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const root = get(fileStore).root;
|
|
77
|
+
const targetPath = actualTarget ? findFolderPath(root, actualTarget) : [];
|
|
78
|
+
for (const id of movedIds) {
|
|
79
|
+
const movedItem = findItemById(id);
|
|
80
|
+
if (movedItem?.type === 'folder') {
|
|
81
|
+
const newParentPath = targetPath ?? [];
|
|
82
|
+
navigationStore.updateMovedFolderPaths(movedItem.id, newParentPath);
|
|
83
|
+
}
|
|
84
|
+
persistentSelectStore.removeSelection(id, currentFilter);
|
|
85
|
+
}
|
|
86
|
+
return { ok: failedCount === 0, movedIds, failedCount };
|
|
87
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../../types';
|
|
2
|
+
declare const FOLDER_TARGET_ATTR = "data-folder-drop-target";
|
|
3
|
+
export interface ResolvedFolderDropTarget {
|
|
4
|
+
folderId: string;
|
|
5
|
+
element: HTMLElement;
|
|
6
|
+
}
|
|
7
|
+
/** Walk `elementsFromPoint` and return the nearest folder drop target. */
|
|
8
|
+
export declare function resolveFolderDropTarget(clientX: number, clientY: number, root?: Document | ShadowRoot): ResolvedFolderDropTarget | null;
|
|
9
|
+
/**
|
|
10
|
+
* Whether selected items may be dropped on `targetFolderId`.
|
|
11
|
+
*
|
|
12
|
+
* @param immediateParentId - folder id containing the sources, or `null` at virtual root
|
|
13
|
+
*/
|
|
14
|
+
export declare function canDropOnFolder(targetFolderId: string, sourceItems: FileSystemItem[], immediateParentId: string | null, root: FileSystemItem): boolean;
|
|
15
|
+
export { FOLDER_TARGET_ATTR };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const FOLDER_TARGET_ATTR = 'data-folder-drop-target';
|
|
2
|
+
/** Walk `elementsFromPoint` and return the nearest folder drop target. */
|
|
3
|
+
export function resolveFolderDropTarget(clientX, clientY, root = document) {
|
|
4
|
+
const doc = root instanceof Document ? root : root.ownerDocument ?? document;
|
|
5
|
+
const elements = doc.elementsFromPoint(clientX, clientY);
|
|
6
|
+
for (const el of elements) {
|
|
7
|
+
if (!(el instanceof HTMLElement))
|
|
8
|
+
continue;
|
|
9
|
+
const match = el.closest(`[${FOLDER_TARGET_ATTR}]`);
|
|
10
|
+
if (match instanceof HTMLElement) {
|
|
11
|
+
const folderId = match.getAttribute(FOLDER_TARGET_ATTR);
|
|
12
|
+
if (folderId) {
|
|
13
|
+
return { folderId, element: match };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function folderDescendantIds(folder, into) {
|
|
20
|
+
if (folder.type !== 'folder' || !folder.children)
|
|
21
|
+
return;
|
|
22
|
+
for (const child of folder.children) {
|
|
23
|
+
if (child.type === 'folder') {
|
|
24
|
+
into.add(child.id);
|
|
25
|
+
folderDescendantIds(child, into);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isDescendantOf(folderId, ancestorId, root) {
|
|
30
|
+
const walk = (node) => {
|
|
31
|
+
if (node.id === ancestorId) {
|
|
32
|
+
const descendants = new Set();
|
|
33
|
+
if (node.type === 'folder')
|
|
34
|
+
folderDescendantIds(node, descendants);
|
|
35
|
+
return descendants.has(folderId) || node.id === folderId;
|
|
36
|
+
}
|
|
37
|
+
if (node.children) {
|
|
38
|
+
for (const child of node.children) {
|
|
39
|
+
if (walk(child))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
return walk(root);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether selected items may be dropped on `targetFolderId`.
|
|
49
|
+
*
|
|
50
|
+
* @param immediateParentId - folder id containing the sources, or `null` at virtual root
|
|
51
|
+
*/
|
|
52
|
+
export function canDropOnFolder(targetFolderId, sourceItems, immediateParentId, root) {
|
|
53
|
+
if (!targetFolderId)
|
|
54
|
+
return false;
|
|
55
|
+
const normalizedTarget = targetFolderId === 'root' || targetFolderId === root.id ? '' : targetFolderId;
|
|
56
|
+
const normalizedParent = immediateParentId ?? '';
|
|
57
|
+
// Same folder as current location
|
|
58
|
+
if (normalizedTarget === normalizedParent)
|
|
59
|
+
return false;
|
|
60
|
+
const sourceFolderIds = sourceItems.filter((i) => i.type === 'folder').map((i) => i.id);
|
|
61
|
+
for (const sourceFolderId of sourceFolderIds) {
|
|
62
|
+
if (normalizedTarget === sourceFolderId)
|
|
63
|
+
return false;
|
|
64
|
+
if (normalizedTarget && isDescendantOf(normalizedTarget, sourceFolderId, root))
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (sourceFolderIds.some((id) => id === normalizedTarget))
|
|
68
|
+
return false;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
export { FOLDER_TARGET_ATTR };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Critically-damped style follow: `current` eases toward `target` each frame. */
|
|
2
|
+
export declare function springLerpStep(current: number, target: number, factor: number): number;
|
|
3
|
+
export declare function springLerpPoint(current: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}, target: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}, factor: number): {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
/** Default follow strength for the ghost stack anchor (spec ~0.18). */
|
|
14
|
+
export declare const DEFAULT_GHOST_FOLLOW_FACTOR = 0.18;
|
|
15
|
+
/** Deeper stack cards lag slightly more than the front card. */
|
|
16
|
+
export declare function layerFollowFactor(layerIndex: number, baseFactor?: number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Critically-damped style follow: `current` eases toward `target` each frame. */
|
|
2
|
+
export function springLerpStep(current, target, factor) {
|
|
3
|
+
if (factor <= 0)
|
|
4
|
+
return target;
|
|
5
|
+
if (factor >= 1)
|
|
6
|
+
return target;
|
|
7
|
+
return current + (target - current) * factor;
|
|
8
|
+
}
|
|
9
|
+
export function springLerpPoint(current, target, factor) {
|
|
10
|
+
return {
|
|
11
|
+
x: springLerpStep(current.x, target.x, factor),
|
|
12
|
+
y: springLerpStep(current.y, target.y, factor)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Default follow strength for the ghost stack anchor (spec ~0.18). */
|
|
16
|
+
export const DEFAULT_GHOST_FOLLOW_FACTOR = 0.18;
|
|
17
|
+
/** Deeper stack cards lag slightly more than the front card. */
|
|
18
|
+
export function layerFollowFactor(layerIndex, baseFactor = DEFAULT_GHOST_FOLLOW_FACTOR) {
|
|
19
|
+
const lag = 1 - layerIndex * 0.045;
|
|
20
|
+
return Math.max(0.08, baseFactor * lag);
|
|
21
|
+
}
|
|
@@ -18,6 +18,11 @@ export declare function renameItem(itemId: string, newName: string): Promise<boo
|
|
|
18
18
|
* Moves an item (file or folder) to a new location
|
|
19
19
|
*/
|
|
20
20
|
export declare function moveItem(itemId: string, targetFolderId: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Moves multiple items in one `fileStore` update (folders and files).
|
|
23
|
+
* @returns ids that were moved in the tree
|
|
24
|
+
*/
|
|
25
|
+
export declare function moveItems(itemIds: string[], targetFolderId: string): string[];
|
|
21
26
|
/**
|
|
22
27
|
* Deletes a file or folder (and its contents)
|
|
23
28
|
*/
|