@widgetic/file-browser 0.5.42 → 0.5.44
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 +210 -50
- 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/FileItem.svelte +8 -7
- package/dist/components/items/FolderItem.svelte +5 -2
- package/dist/components/previews/FilePreview.svelte +59 -22
- 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/i18n/messages.d.ts +1 -1
- package/dist/i18n/messages.js +1 -1
- 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 +89 -17
- 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 +13 -5
- package/dist/utils/libraryTree.js +41 -47
- package/dist/utils/userUploadsStorage.js +6 -6
- package/dist/utils/widgeticDelete.d.ts +14 -0
- package/dist/utils/widgeticDelete.js +52 -0
- package/package.json +1 -1
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
import { previewKeyAction } from '../../utils/previewKeys';
|
|
41
41
|
import { getCachedImageNaturalSize, preloadImageUrl, probeDecodedImage } from '../../utils/imagePreviewCache';
|
|
42
42
|
import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
|
|
43
|
+
import { computeImagePreviewModalFrame } from '../../utils/imagePreviewFrame';
|
|
43
44
|
|
|
44
45
|
// Stores
|
|
45
46
|
import { addMissingFile, missingFiles } from '../../stores/missingFilesStore';
|
|
46
|
-
import {
|
|
47
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
47
48
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
48
49
|
import { useI18n } from '../../i18n';
|
|
49
50
|
import { formatFileSize } from '../../utils/fileUtils';
|
|
@@ -70,6 +71,8 @@
|
|
|
70
71
|
/** Shell vertical padding (p-6 top + bottom, and the 1px border of the card on each side). */
|
|
71
72
|
const MODAL_VERTICAL_PAD = 50;
|
|
72
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;
|
|
73
76
|
|
|
74
77
|
// STATE VARS
|
|
75
78
|
let showLogs = false;
|
|
@@ -199,7 +202,8 @@
|
|
|
199
202
|
};
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
$: isSelected =
|
|
205
|
+
$: isSelected =
|
|
206
|
+
allowSelecting && ($persistentSelectStore[currentFilter] ?? []).includes(file.id);
|
|
203
207
|
let fittedImage: { width: string; height: string } | null = null;
|
|
204
208
|
let fittedImageForId = '';
|
|
205
209
|
|
|
@@ -248,7 +252,10 @@
|
|
|
248
252
|
if (file.id !== fileId || imageRevealForId === fileId || imageBitmapReadyForId !== fileId) return;
|
|
249
253
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
250
254
|
// A card that never got a size (the picture reported none) has no move to wait for
|
|
251
|
-
const waitMs =
|
|
255
|
+
const waitMs =
|
|
256
|
+
IMAGE_PREVIEW_ANIMATES_SIZE && frameSizedForId === fileId
|
|
257
|
+
? imageRevealDelayMs(frameSizedAtMs, performance.now())
|
|
258
|
+
: 0;
|
|
252
259
|
imageRevealTimer = setTimeout(() => {
|
|
253
260
|
imageRevealTimer = undefined;
|
|
254
261
|
if (file.id !== fileId || imageBitmapReadyForId !== fileId) return;
|
|
@@ -286,19 +293,16 @@
|
|
|
286
293
|
const styles = getComputedStyle(element);
|
|
287
294
|
margin = parseInt(styles.getPropertyValue('--app-margin').trim()) || margin;
|
|
288
295
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
);
|
|
298
|
-
const next = {
|
|
299
|
-
width: `${cardWidth}px`,
|
|
300
|
-
height: `${Math.max(100, Math.round(height * scale) + TOTAL_VERTICAL_SPACE)}px`
|
|
301
|
-
};
|
|
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 };
|
|
302
306
|
const id = file.id;
|
|
303
307
|
fittedImageForId = id;
|
|
304
308
|
fittedImage = next;
|
|
@@ -306,19 +310,47 @@
|
|
|
306
310
|
frameSizedAtMs = performance.now();
|
|
307
311
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
308
312
|
imageRevealTimer = undefined;
|
|
309
|
-
|
|
310
|
-
|
|
313
|
+
const revealNow =
|
|
314
|
+
options?.revealImmediately || !IMAGE_PREVIEW_ANIMATES_SIZE;
|
|
315
|
+
if (revealNow) {
|
|
311
316
|
imageBitmapReadyForId = id;
|
|
312
317
|
imageRevealForId = id;
|
|
313
318
|
slowLoaderForId = '';
|
|
314
319
|
return;
|
|
315
320
|
}
|
|
316
|
-
// The card eases to this size first. The picture stays hidden until it has loaded AND the card has made that move
|
|
317
|
-
// (if it loaded already, it appears when the move is over; if not, `handleImageBitmapLoaded` shows it when it arrives).
|
|
318
321
|
imageRevealForId = '';
|
|
319
322
|
revealImageWhenReady(id);
|
|
320
323
|
}
|
|
321
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
|
+
|
|
322
354
|
function revealCachedImageIfReady() {
|
|
323
355
|
if (!open || fileType !== 'image' || !hasValidUrl || !fileUrl) return;
|
|
324
356
|
const id = file.id;
|
|
@@ -328,7 +360,7 @@
|
|
|
328
360
|
// The browser may still hold the picture decoded (opened before, or loaded as a neighbour): then it is shown at once
|
|
329
361
|
const cached = probeDecodedImage(fileUrl);
|
|
330
362
|
if (file.width && file.height) {
|
|
331
|
-
fitImageFrame(file.width, file.height, { revealImmediately:
|
|
363
|
+
fitImageFrame(file.width, file.height, { revealImmediately: true });
|
|
332
364
|
return;
|
|
333
365
|
}
|
|
334
366
|
if (cached) {
|
|
@@ -392,10 +424,14 @@
|
|
|
392
424
|
|
|
393
425
|
/** Size the shell from catalogued dimensions or a warm decoder cache before the bitmap loads. */
|
|
394
426
|
$: if (open && file?.id && fileUrl && fileType === 'image' && imageStateForFileId === file.id) {
|
|
427
|
+
void ensureImageFrameBeforeOpen();
|
|
395
428
|
revealCachedImageIfReady();
|
|
396
429
|
preloadNeighborPreviewImages();
|
|
397
430
|
}
|
|
398
431
|
|
|
432
|
+
$: modalPanelShown =
|
|
433
|
+
fileType !== 'image' || showsErrorState || fittedImageForId === file.id;
|
|
434
|
+
|
|
399
435
|
// The card's size. It stays BELOW the block above on purpose: that block sets `fittedImage` and `fittedImageForId`
|
|
400
436
|
// inside a function, so Svelte cannot order the two statements by their assignments. A statement placed above it reads
|
|
401
437
|
// the frame of the previous file in the same update (the small loading card) and does not run again, so a file that
|
|
@@ -651,7 +687,8 @@
|
|
|
651
687
|
ariaLabel={file.name}
|
|
652
688
|
width={modalDimensions.width}
|
|
653
689
|
height={modalDimensions.height}
|
|
654
|
-
animateSize={fileType === '
|
|
690
|
+
animateSize={fileType === 'video'}
|
|
691
|
+
shown={modalPanelShown}
|
|
655
692
|
{target}
|
|
656
693
|
showScroll={false}
|
|
657
694
|
on:close={handleClose}
|
|
@@ -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/i18n/messages.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ export declare const FILE_BROWSER_MESSAGES: {
|
|
|
193
193
|
readonly 'toast.delete.doneFolder': "Deleted folder \"{name}\"";
|
|
194
194
|
readonly 'toast.delete.doneFile': "Deleted \"{name}\"";
|
|
195
195
|
readonly 'toast.delete.doneMany': "{count, plural, one {Deleted # item} other {Deleted # items}}";
|
|
196
|
-
readonly 'toast.delete.doneFolderDetail': "Folder and its
|
|
196
|
+
readonly 'toast.delete.doneFolderDetail': "Folder and its files were removed from your library";
|
|
197
197
|
readonly 'toast.delete.doneFileDetail': "Item was deleted successfully";
|
|
198
198
|
readonly 'toast.delete.doneManyDetail': "{count, plural, one {# item was deleted successfully} other {# items were deleted successfully}}";
|
|
199
199
|
readonly 'toast.delete.doneNames': "Deleted: {names}";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -202,7 +202,7 @@ export const FILE_BROWSER_MESSAGES = {
|
|
|
202
202
|
'toast.delete.doneFolder': 'Deleted folder "{name}"',
|
|
203
203
|
'toast.delete.doneFile': 'Deleted "{name}"',
|
|
204
204
|
'toast.delete.doneMany': '{count, plural, one {Deleted # item} other {Deleted # items}}',
|
|
205
|
-
'toast.delete.doneFolderDetail': 'Folder and its
|
|
205
|
+
'toast.delete.doneFolderDetail': 'Folder and its files were removed from your library',
|
|
206
206
|
'toast.delete.doneFileDetail': 'Item was deleted successfully',
|
|
207
207
|
'toast.delete.doneManyDetail': '{count, plural, one {# item was deleted successfully} other {# items were deleted successfully}}',
|
|
208
208
|
'toast.delete.doneNames': 'Deleted: {names}',
|
|
@@ -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
|
*/
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { fileStore, sortCriteria, sortDirection, selectedFiles, currentFolder, fileFilter } from '../stores/fileStore';
|
|
2
2
|
import { persistHistory } from '../stores/navigationStore';
|
|
3
|
+
import { getFileBrowserUploadConfig } from '../stores/uploadApiStore';
|
|
3
4
|
import { get } from 'svelte/store';
|
|
4
5
|
import { updateFolderCounts } from '../stores/folderCountStore';
|
|
5
6
|
import { getFileType } from './fileUtils';
|
|
6
7
|
import { getRenamedFileName } from './fileNames';
|
|
7
8
|
import { ENDPOINTS } from './apiConfig';
|
|
9
|
+
import { collectFileIdsInSubtree, deleteSubtreeUploadsOnApi } from './widgeticDelete';
|
|
10
|
+
import { removePersistedUploads } from './userUploadsStorage';
|
|
8
11
|
// Add helper function for sorting folder contents
|
|
9
12
|
function sortFolderContents(items) {
|
|
10
13
|
const currentSortCriteria = get(sortCriteria);
|
|
@@ -338,6 +341,78 @@ export function moveItem(itemId, targetFolderId) {
|
|
|
338
341
|
}
|
|
339
342
|
return success;
|
|
340
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Moves multiple items in one `fileStore` update (folders and files).
|
|
346
|
+
* @returns ids that were moved in the tree
|
|
347
|
+
*/
|
|
348
|
+
export function moveItems(itemIds, targetFolderId) {
|
|
349
|
+
if (itemIds.length === 0)
|
|
350
|
+
return [];
|
|
351
|
+
const updatedTime = new Date().toISOString();
|
|
352
|
+
const idSet = new Set(itemIds);
|
|
353
|
+
const collected = [];
|
|
354
|
+
const movedIds = [];
|
|
355
|
+
fileStore.update((store) => {
|
|
356
|
+
const removeCollected = (items) => {
|
|
357
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
358
|
+
const entry = items[i];
|
|
359
|
+
if (idSet.has(entry.id)) {
|
|
360
|
+
collected.push({ ...entry, modified: updatedTime });
|
|
361
|
+
movedIds.push(entry.id);
|
|
362
|
+
items.splice(i, 1);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (entry.type === 'folder' && entry.children) {
|
|
366
|
+
removeCollected(entry.children);
|
|
367
|
+
entry.modified = updatedTime;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const rootChildren = store.root.children ?? [];
|
|
372
|
+
removeCollected(rootChildren);
|
|
373
|
+
store.root.children = rootChildren;
|
|
374
|
+
if (collected.length === 0)
|
|
375
|
+
return store;
|
|
376
|
+
const isTargetRoot = targetFolderId === '' ||
|
|
377
|
+
targetFolderId === 'root' ||
|
|
378
|
+
Boolean(store.root && targetFolderId === store.root.id);
|
|
379
|
+
if (isTargetRoot) {
|
|
380
|
+
store.root.children.push(...collected);
|
|
381
|
+
store.root.modified = updatedTime;
|
|
382
|
+
sortFolderContents(store.root.children);
|
|
383
|
+
return store;
|
|
384
|
+
}
|
|
385
|
+
const addToTarget = (items) => {
|
|
386
|
+
for (let i = 0; i < items.length; i++) {
|
|
387
|
+
if (items[i].id === targetFolderId && items[i].type === 'folder') {
|
|
388
|
+
const targetFolder = items[i];
|
|
389
|
+
targetFolder.children = targetFolder.children ?? [];
|
|
390
|
+
targetFolder.children.push(...collected);
|
|
391
|
+
targetFolder.modified = updatedTime;
|
|
392
|
+
sortFolderContents(targetFolder.children);
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
if (items[i].type === 'folder') {
|
|
396
|
+
const children = items[i].children ?? [];
|
|
397
|
+
if (addToTarget(children))
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
};
|
|
403
|
+
addToTarget(rootChildren);
|
|
404
|
+
return store;
|
|
405
|
+
});
|
|
406
|
+
if (movedIds.length > 0) {
|
|
407
|
+
const store = get(fileStore);
|
|
408
|
+
const currentFilter = get(fileFilter);
|
|
409
|
+
const filterValue = typeof currentFilter === 'string' && ['all', 'image', 'video', 'document'].includes(currentFilter)
|
|
410
|
+
? currentFilter
|
|
411
|
+
: 'all';
|
|
412
|
+
updateFolderCounts(store.root, filterValue);
|
|
413
|
+
}
|
|
414
|
+
return movedIds;
|
|
415
|
+
}
|
|
341
416
|
/**
|
|
342
417
|
* Mock API function for delete
|
|
343
418
|
*/
|
|
@@ -403,10 +478,16 @@ export async function deleteItem(itemId) {
|
|
|
403
478
|
}
|
|
404
479
|
}
|
|
405
480
|
collectPaths(itemToDelete);
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
|
|
481
|
+
const uploadConfig = getFileBrowserUploadConfig();
|
|
482
|
+
const removedUploadIds = collectFileIdsInSubtree(itemToDelete);
|
|
483
|
+
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
484
|
+
await deleteSubtreeUploadsOnApi(uploadConfig, itemToDelete);
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
const response = await mockDeleteAPI(itemId, Array.from(thumbnailsToDelete).join(','), Array.from(filesToDelete).join(','));
|
|
488
|
+
if (!response.success) {
|
|
489
|
+
throw new Error(response.error || 'Failed to delete item on server');
|
|
490
|
+
}
|
|
410
491
|
}
|
|
411
492
|
fileStore.update(store => {
|
|
412
493
|
const deleteFromStructure = (items) => {
|
|
@@ -432,21 +513,12 @@ export async function deleteItem(itemId) {
|
|
|
432
513
|
store.root.children = rootChildren;
|
|
433
514
|
return store;
|
|
434
515
|
});
|
|
435
|
-
// If item was deleted successfully, remove it from selections
|
|
436
516
|
if (success && itemToDelete) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
fileIdsToRemove.add(item.id);
|
|
442
|
-
}
|
|
443
|
-
else if (item.type === 'folder' && item.children) {
|
|
444
|
-
item.children.forEach(child => collectFileIds(child));
|
|
445
|
-
}
|
|
517
|
+
const fileIdsToRemove = new Set(removedUploadIds);
|
|
518
|
+
selectedFiles.update((files) => files.filter((file) => !fileIdsToRemove.has(file.id)));
|
|
519
|
+
if (uploadConfig?.accessToken && fileIdsToRemove.size > 0) {
|
|
520
|
+
await removePersistedUploads([...fileIdsToRemove]);
|
|
446
521
|
}
|
|
447
|
-
collectFileIds(itemToDelete);
|
|
448
|
-
// Update selected files store
|
|
449
|
-
selectedFiles.update(files => files.filter(file => !fileIdsToRemove.has(file.id)));
|
|
450
522
|
}
|
|
451
523
|
return success;
|
|
452
524
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Layout constants shared with FilePreview (header, padding, min card width). */
|
|
2
|
+
export type ImagePreviewFrameInsets = {
|
|
3
|
+
hostWidth: number;
|
|
4
|
+
hostHeight: number;
|
|
5
|
+
sideMargin?: number;
|
|
6
|
+
dialogHorizontalPad?: number;
|
|
7
|
+
headerBlock?: number;
|
|
8
|
+
verticalPad?: number;
|
|
9
|
+
contentVerticalGutter?: number;
|
|
10
|
+
minDialogWidth?: number;
|
|
11
|
+
maxHostFraction?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Sizes an image preview card to fit the host frame while keeping chrome visible.
|
|
15
|
+
* Pictures are not upscaled beyond their natural size.
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeImagePreviewModalFrame(naturalWidth: number, naturalHeight: number, insets: ImagePreviewFrameInsets): {
|
|
18
|
+
width: string;
|
|
19
|
+
height: string;
|
|
20
|
+
pictureWidth: number;
|
|
21
|
+
pictureHeight: number;
|
|
22
|
+
};
|