@widgetic/file-browser 0.5.42 → 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 +190 -29
- 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 +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/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/userUploadsStorage.js +4 -2
- package/package.json +1 -1
|
@@ -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
|
} & {
|
|
@@ -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
|
*/
|
|
@@ -338,6 +338,78 @@ export function moveItem(itemId, targetFolderId) {
|
|
|
338
338
|
}
|
|
339
339
|
return success;
|
|
340
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Moves multiple items in one `fileStore` update (folders and files).
|
|
343
|
+
* @returns ids that were moved in the tree
|
|
344
|
+
*/
|
|
345
|
+
export function moveItems(itemIds, targetFolderId) {
|
|
346
|
+
if (itemIds.length === 0)
|
|
347
|
+
return [];
|
|
348
|
+
const updatedTime = new Date().toISOString();
|
|
349
|
+
const idSet = new Set(itemIds);
|
|
350
|
+
const collected = [];
|
|
351
|
+
const movedIds = [];
|
|
352
|
+
fileStore.update((store) => {
|
|
353
|
+
const removeCollected = (items) => {
|
|
354
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
355
|
+
const entry = items[i];
|
|
356
|
+
if (idSet.has(entry.id)) {
|
|
357
|
+
collected.push({ ...entry, modified: updatedTime });
|
|
358
|
+
movedIds.push(entry.id);
|
|
359
|
+
items.splice(i, 1);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (entry.type === 'folder' && entry.children) {
|
|
363
|
+
removeCollected(entry.children);
|
|
364
|
+
entry.modified = updatedTime;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const rootChildren = store.root.children ?? [];
|
|
369
|
+
removeCollected(rootChildren);
|
|
370
|
+
store.root.children = rootChildren;
|
|
371
|
+
if (collected.length === 0)
|
|
372
|
+
return store;
|
|
373
|
+
const isTargetRoot = targetFolderId === '' ||
|
|
374
|
+
targetFolderId === 'root' ||
|
|
375
|
+
Boolean(store.root && targetFolderId === store.root.id);
|
|
376
|
+
if (isTargetRoot) {
|
|
377
|
+
store.root.children.push(...collected);
|
|
378
|
+
store.root.modified = updatedTime;
|
|
379
|
+
sortFolderContents(store.root.children);
|
|
380
|
+
return store;
|
|
381
|
+
}
|
|
382
|
+
const addToTarget = (items) => {
|
|
383
|
+
for (let i = 0; i < items.length; i++) {
|
|
384
|
+
if (items[i].id === targetFolderId && items[i].type === 'folder') {
|
|
385
|
+
const targetFolder = items[i];
|
|
386
|
+
targetFolder.children = targetFolder.children ?? [];
|
|
387
|
+
targetFolder.children.push(...collected);
|
|
388
|
+
targetFolder.modified = updatedTime;
|
|
389
|
+
sortFolderContents(targetFolder.children);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (items[i].type === 'folder') {
|
|
393
|
+
const children = items[i].children ?? [];
|
|
394
|
+
if (addToTarget(children))
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return false;
|
|
399
|
+
};
|
|
400
|
+
addToTarget(rootChildren);
|
|
401
|
+
return store;
|
|
402
|
+
});
|
|
403
|
+
if (movedIds.length > 0) {
|
|
404
|
+
const store = get(fileStore);
|
|
405
|
+
const currentFilter = get(fileFilter);
|
|
406
|
+
const filterValue = typeof currentFilter === 'string' && ['all', 'image', 'video', 'document'].includes(currentFilter)
|
|
407
|
+
? currentFilter
|
|
408
|
+
: 'all';
|
|
409
|
+
updateFolderCounts(store.root, filterValue);
|
|
410
|
+
}
|
|
411
|
+
return movedIds;
|
|
412
|
+
}
|
|
341
413
|
/**
|
|
342
414
|
* Mock API function for delete
|
|
343
415
|
*/
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const DEFAULTS = {
|
|
2
|
+
sideMargin: 24,
|
|
3
|
+
dialogHorizontalPad: 50,
|
|
4
|
+
headerBlock: 52,
|
|
5
|
+
verticalPad: 50,
|
|
6
|
+
contentVerticalGutter: 48,
|
|
7
|
+
minDialogWidth: 320,
|
|
8
|
+
maxHostFraction: 0.92
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Sizes an image preview card to fit the host frame while keeping chrome visible.
|
|
12
|
+
* Pictures are not upscaled beyond their natural size.
|
|
13
|
+
*/
|
|
14
|
+
export function computeImagePreviewModalFrame(naturalWidth, naturalHeight, insets) {
|
|
15
|
+
const { hostWidth, hostHeight, sideMargin = DEFAULTS.sideMargin, dialogHorizontalPad = DEFAULTS.dialogHorizontalPad, headerBlock = DEFAULTS.headerBlock, verticalPad = DEFAULTS.verticalPad, contentVerticalGutter = DEFAULTS.contentVerticalGutter, minDialogWidth = DEFAULTS.minDialogWidth, maxHostFraction = DEFAULTS.maxHostFraction } = insets;
|
|
16
|
+
const totalVerticalSpace = verticalPad + headerBlock;
|
|
17
|
+
const maxPictureWidth = Math.max(100, hostWidth * maxHostFraction - 2 * sideMargin - dialogHorizontalPad);
|
|
18
|
+
const maxPictureHeight = Math.max(100, hostHeight * maxHostFraction - totalVerticalSpace - contentVerticalGutter);
|
|
19
|
+
const scale = Math.min(1, maxPictureWidth / naturalWidth, maxPictureHeight / naturalHeight);
|
|
20
|
+
const pictureWidth = Math.max(68, Math.round(naturalWidth * scale));
|
|
21
|
+
const pictureHeight = Math.max(68, Math.round(naturalHeight * scale));
|
|
22
|
+
const cardWidth = Math.min(Math.max(minDialogWidth, pictureWidth + dialogHorizontalPad), Math.max(pictureWidth + dialogHorizontalPad, hostWidth * maxHostFraction - 2 * sideMargin));
|
|
23
|
+
return {
|
|
24
|
+
width: `${cardWidth}px`,
|
|
25
|
+
height: `${pictureHeight + totalVerticalSpace}px`,
|
|
26
|
+
pictureWidth,
|
|
27
|
+
pictureHeight
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MediaLibraryCapabilities } from '../mediaLibrary/types';
|
|
2
|
+
export type ItemMenuCapabilitiesInput = {
|
|
3
|
+
readonly capabilities: MediaLibraryCapabilities;
|
|
4
|
+
readonly isFolder: boolean;
|
|
5
|
+
readonly isMissing: boolean;
|
|
6
|
+
readonly fileUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
export type ItemMenuCapabilities = {
|
|
9
|
+
readonly canRename: boolean;
|
|
10
|
+
readonly canMove: boolean;
|
|
11
|
+
readonly canDownload: boolean;
|
|
12
|
+
readonly canDelete: boolean;
|
|
13
|
+
readonly hasAnyAction: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Which row actions the item "…" menu may show. Folders never offer Download; missing items lose destructive actions.
|
|
17
|
+
* The legacy Uploads folder (`folder_my_uploads`) is treated like any other folder — nothing here is reserved.
|
|
18
|
+
*/
|
|
19
|
+
export declare function itemMenuCapabilities(input: ItemMenuCapabilitiesInput): ItemMenuCapabilities;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which row actions the item "…" menu may show. Folders never offer Download; missing items lose destructive actions.
|
|
3
|
+
* The legacy Uploads folder (`folder_my_uploads`) is treated like any other folder — nothing here is reserved.
|
|
4
|
+
*/
|
|
5
|
+
export function itemMenuCapabilities(input) {
|
|
6
|
+
const { capabilities, isFolder, isMissing, fileUrl } = input;
|
|
7
|
+
const canRename = capabilities.rename && !isMissing;
|
|
8
|
+
const canMove = capabilities.folders && !isMissing;
|
|
9
|
+
const canDownload = capabilities.download && !isMissing && !isFolder && Boolean(fileUrl);
|
|
10
|
+
const canDelete = capabilities.delete;
|
|
11
|
+
const hasAnyAction = canRename || canMove || canDownload || canDelete;
|
|
12
|
+
return { canRename, canMove, canDownload, canDelete, hasAnyAction };
|
|
13
|
+
}
|
|
@@ -12,9 +12,12 @@ export declare function findItemByIdInTree(root: FileSystemItem, id: string): Fi
|
|
|
12
12
|
export declare function dedupeTreeIds(items: FileSystemItem[]): FileSystemItem[];
|
|
13
13
|
/**
|
|
14
14
|
* Merges flat API file list into a saved tree: known ids refresh in place (their saved, possibly renamed, name is kept);
|
|
15
|
-
* unknown files
|
|
15
|
+
* unknown files appear at the root. The legacy `folder_my_uploads` folder is kept only when the visitor still has it in
|
|
16
|
+
* their saved tree (it is never recreated after delete).
|
|
16
17
|
*/
|
|
17
|
-
export declare function mergeApiFilesIntoSavedTree(rootChildren: FileSystemItem[] | null, apiFiles: FileSystemItem[],
|
|
18
|
+
export declare function mergeApiFilesIntoSavedTree(rootChildren: FileSystemItem[] | null, apiFiles: FileSystemItem[], _myUploadsName: string): FileSystemItem[];
|
|
19
|
+
/** Saved tree held only files with no folder wrapper (pre–whole-tree persistence). */
|
|
20
|
+
export declare function isLegacyUploadsOnlyChildren(children: FileSystemItem[]): boolean;
|
|
18
21
|
/**
|
|
19
22
|
* One-step legacy migration: old persist stored only My Uploads' children under key `current`.
|
|
20
23
|
* Wraps them inside `folder_my_uploads` at the root.
|
|
@@ -87,36 +87,13 @@ export function dedupeTreeIds(items) {
|
|
|
87
87
|
}
|
|
88
88
|
return walk(items);
|
|
89
89
|
}
|
|
90
|
-
function getOrCreateMyUploadsFolder(rootChildren, myUploadsName) {
|
|
91
|
-
let myUploads = rootChildren.find((c) => c.id === BUILTIN_UPLOADS_ID && c.type === 'folder');
|
|
92
|
-
if (!myUploads) {
|
|
93
|
-
myUploads = {
|
|
94
|
-
id: BUILTIN_UPLOADS_ID,
|
|
95
|
-
name: myUploadsName,
|
|
96
|
-
type: 'folder',
|
|
97
|
-
children: [],
|
|
98
|
-
modified: new Date().toISOString()
|
|
99
|
-
};
|
|
100
|
-
return { rootChildren: [...rootChildren, myUploads].sort(sortRootLevelItems), myUploads };
|
|
101
|
-
}
|
|
102
|
-
if (myUploads.name !== myUploadsName) {
|
|
103
|
-
const updated = { ...myUploads, name: myUploadsName };
|
|
104
|
-
return {
|
|
105
|
-
rootChildren: rootChildren.map((c) => (c === myUploads ? updated : c)),
|
|
106
|
-
myUploads: updated
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return { rootChildren, myUploads };
|
|
110
|
-
}
|
|
111
90
|
/**
|
|
112
91
|
* Merges flat API file list into a saved tree: known ids refresh in place (their saved, possibly renamed, name is kept);
|
|
113
|
-
* unknown files
|
|
92
|
+
* unknown files appear at the root. The legacy `folder_my_uploads` folder is kept only when the visitor still has it in
|
|
93
|
+
* their saved tree (it is never recreated after delete).
|
|
114
94
|
*/
|
|
115
|
-
export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles,
|
|
95
|
+
export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsName) {
|
|
116
96
|
let children = dedupeTreeIds(reviveFileSystemDates(rootChildren ?? []));
|
|
117
|
-
const ensured = getOrCreateMyUploadsFolder(children, myUploadsName);
|
|
118
|
-
children = ensured.rootChildren;
|
|
119
|
-
const myUploads = ensured.myUploads;
|
|
120
97
|
function replaceFileById(items, id, file) {
|
|
121
98
|
for (let i = 0; i < items.length; i++) {
|
|
122
99
|
const it = items[i];
|
|
@@ -148,19 +125,22 @@ export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, myUploadsName
|
|
|
148
125
|
if (findItemByIdInTree(rootFolder, file.id)) {
|
|
149
126
|
replaceFileById(rootFolder.children, file.id, normalized);
|
|
150
127
|
}
|
|
151
|
-
else {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
direction: 'asc'
|
|
158
|
-
});
|
|
159
|
-
}
|
|
128
|
+
else if (!rootFolder.children.some((c) => c.type === 'file' && c.id === file.id)) {
|
|
129
|
+
rootFolder.children.push(normalized);
|
|
130
|
+
sortFolderContentsLikeGrid(rootFolder.children, {
|
|
131
|
+
criteria: 'name',
|
|
132
|
+
direction: 'asc'
|
|
133
|
+
});
|
|
160
134
|
}
|
|
161
135
|
}
|
|
162
136
|
return dedupeTreeIds(rootFolder.children);
|
|
163
137
|
}
|
|
138
|
+
/** Saved tree held only files with no folder wrapper (pre–whole-tree persistence). */
|
|
139
|
+
export function isLegacyUploadsOnlyChildren(children) {
|
|
140
|
+
if (!children.length)
|
|
141
|
+
return false;
|
|
142
|
+
return children.every((c) => c.type === 'file');
|
|
143
|
+
}
|
|
164
144
|
/**
|
|
165
145
|
* One-step legacy migration: old persist stored only My Uploads' children under key `current`.
|
|
166
146
|
* Wraps them inside `folder_my_uploads` at the root.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeApiFilesIntoSavedTree, migrateLegacyUploadsOnlyChildren } from './libraryTree';
|
|
1
|
+
import { isLegacyUploadsOnlyChildren, mergeApiFilesIntoSavedTree, migrateLegacyUploadsOnlyChildren } from './libraryTree';
|
|
2
2
|
import { CACHE_POLICIES, getCacheOwner, readEntity, writeEntity } from '@widgetic/cache-layer';
|
|
3
3
|
// Legacy localStorage keys, read once for migration then superseded by L1.
|
|
4
4
|
const LEGACY_STORAGE_KEY = 'widgetic-file-browser-uploads';
|
|
@@ -206,7 +206,9 @@ export async function createUserUploadsFileSystemRoot(files, myUploadsName = 'Up
|
|
|
206
206
|
const hasBuiltInUploads = savedRaw.some((c) => c.id === 'folder_my_uploads' && c.type === 'folder');
|
|
207
207
|
savedChildren = hasBuiltInUploads
|
|
208
208
|
? savedRaw
|
|
209
|
-
:
|
|
209
|
+
: isLegacyUploadsOnlyChildren(savedRaw)
|
|
210
|
+
? migrateLegacyUploadsOnlyChildren(savedRaw, myUploadsName)
|
|
211
|
+
: savedRaw;
|
|
210
212
|
}
|
|
211
213
|
const children = mergeApiFilesIntoSavedTree(savedChildren, files, myUploadsName);
|
|
212
214
|
return {
|