@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
|
@@ -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
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Pure helpers for the Widgetic library-mode tree: persistence covers the whole root and API hydration merges by id.
|
|
3
3
|
*/
|
|
4
4
|
import type { FileSystemItem } from '../types';
|
|
5
|
+
export declare const BUILTIN_UPLOADS_ID = "folder_my_uploads";
|
|
5
6
|
/** Deep clone with Date revival for `modified` fields (JSON persistence). */
|
|
6
7
|
export declare function reviveFileSystemDates(items: FileSystemItem[]): FileSystemItem[];
|
|
7
8
|
export declare function findItemByIdInTree(root: FileSystemItem, id: string): FileSystemItem | null;
|
|
@@ -12,11 +13,18 @@ export declare function findItemByIdInTree(root: FileSystemItem, id: string): Fi
|
|
|
12
13
|
export declare function dedupeTreeIds(items: FileSystemItem[]): FileSystemItem[];
|
|
13
14
|
/**
|
|
14
15
|
* Merges flat API file list into a saved tree: known ids refresh in place (their saved, possibly renamed, name is kept);
|
|
15
|
-
* unknown files
|
|
16
|
+
* unknown files appear at the root. The legacy `folder_my_uploads` folder is kept only when the visitor still has it in
|
|
17
|
+
* their saved tree (it is never recreated after delete).
|
|
16
18
|
*/
|
|
17
|
-
export declare function mergeApiFilesIntoSavedTree(rootChildren: FileSystemItem[] | null, apiFiles: FileSystemItem[],
|
|
19
|
+
export declare function mergeApiFilesIntoSavedTree(rootChildren: FileSystemItem[] | null, apiFiles: FileSystemItem[], _myUploadsName: string): FileSystemItem[];
|
|
20
|
+
/** Saved tree held only files with no folder wrapper (pre–whole-tree persistence). */
|
|
21
|
+
export declare function isLegacyUploadsOnlyChildren(children: FileSystemItem[]): boolean;
|
|
18
22
|
/**
|
|
19
|
-
* One-step legacy migration: old persist stored only
|
|
20
|
-
*
|
|
23
|
+
* One-step legacy migration: old persist stored only upload files under key `current` with no folder wrapper.
|
|
24
|
+
* They become loose files at the root — there is no built-in Uploads folder anymore.
|
|
21
25
|
*/
|
|
22
|
-
export declare function migrateLegacyUploadsOnlyChildren(legacyChildren: FileSystemItem[],
|
|
26
|
+
export declare function migrateLegacyUploadsOnlyChildren(legacyChildren: FileSystemItem[], _myUploadsName: string): FileSystemItem[];
|
|
27
|
+
/**
|
|
28
|
+
* Unwraps the legacy built-in `folder_my_uploads` (and any nested uploads shells) so children live at the root.
|
|
29
|
+
*/
|
|
30
|
+
export declare function flattenLegacyBuiltinUploads(children: FileSystemItem[]): FileSystemItem[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure helpers for the Widgetic library-mode tree: persistence covers the whole root and API hydration merges by id.
|
|
3
3
|
*/
|
|
4
|
-
const BUILTIN_UPLOADS_ID = 'folder_my_uploads';
|
|
4
|
+
export const BUILTIN_UPLOADS_ID = 'folder_my_uploads';
|
|
5
5
|
function sortFolderContentsLikeGrid(items, sort) {
|
|
6
6
|
items.sort((a, b) => {
|
|
7
7
|
if (a.type === 'folder' && b.type !== 'folder')
|
|
@@ -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,30 +125,47 @@ 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
|
-
* One-step legacy migration: old persist stored only
|
|
166
|
-
*
|
|
145
|
+
* One-step legacy migration: old persist stored only upload files under key `current` with no folder wrapper.
|
|
146
|
+
* They become loose files at the root — there is no built-in Uploads folder anymore.
|
|
167
147
|
*/
|
|
168
|
-
export function migrateLegacyUploadsOnlyChildren(legacyChildren,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
148
|
+
export function migrateLegacyUploadsOnlyChildren(legacyChildren, _myUploadsName) {
|
|
149
|
+
return dedupeTreeIds(reviveFileSystemDates(legacyChildren));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Unwraps the legacy built-in `folder_my_uploads` (and any nested uploads shells) so children live at the root.
|
|
153
|
+
*/
|
|
154
|
+
export function flattenLegacyBuiltinUploads(children) {
|
|
155
|
+
const out = [];
|
|
156
|
+
for (const child of dedupeTreeIds(reviveFileSystemDates(children))) {
|
|
157
|
+
if (child.type === 'folder' && child.id === BUILTIN_UPLOADS_ID) {
|
|
158
|
+
if (child.children?.length) {
|
|
159
|
+
out.push(...flattenLegacyBuiltinUploads(child.children));
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (child.type === 'folder' && child.children?.length) {
|
|
164
|
+
out.push({ ...child, children: flattenLegacyBuiltinUploads(child.children) });
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
out.push(child);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
177
171
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mergeApiFilesIntoSavedTree, migrateLegacyUploadsOnlyChildren } from './libraryTree';
|
|
2
|
-
import { CACHE_POLICIES, getCacheOwner, readEntity, writeEntity } from '@widgetic/cache-layer';
|
|
1
|
+
import { flattenLegacyBuiltinUploads, isLegacyUploadsOnlyChildren, mergeApiFilesIntoSavedTree, migrateLegacyUploadsOnlyChildren } from './libraryTree';
|
|
2
|
+
import { CACHE_POLICIES, ensureCacheOwnerFromSessionHint, 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';
|
|
5
5
|
const LEGACY_LIBRARY_TREE_KEY = 'widgetic-file-browser-library-tree';
|
|
@@ -13,6 +13,7 @@ function entityKey() {
|
|
|
13
13
|
return 'current';
|
|
14
14
|
}
|
|
15
15
|
function ownerIdOrNull() {
|
|
16
|
+
ensureCacheOwnerFromSessionHint();
|
|
16
17
|
return getCacheOwner();
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
@@ -203,10 +204,9 @@ export async function createUserUploadsFileSystemRoot(files, myUploadsName = 'Up
|
|
|
203
204
|
const savedRaw = await loadLibraryTreeChildren();
|
|
204
205
|
let savedChildren = null;
|
|
205
206
|
if (savedRaw && savedRaw.length > 0) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
: migrateLegacyUploadsOnlyChildren(savedRaw, myUploadsName);
|
|
207
|
+
savedChildren = isLegacyUploadsOnlyChildren(savedRaw)
|
|
208
|
+
? migrateLegacyUploadsOnlyChildren(savedRaw, myUploadsName)
|
|
209
|
+
: flattenLegacyBuiltinUploads(savedRaw);
|
|
210
210
|
}
|
|
211
211
|
const children = mergeApiFilesIntoSavedTree(savedChildren, files, myUploadsName);
|
|
212
212
|
return {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FileBrowserUploadConfig } from '../stores/uploadApiStore';
|
|
2
|
+
import type { FileSystemItem } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Soft-deletes one upload row via DELETE /v1/uploads/:id.
|
|
5
|
+
*/
|
|
6
|
+
export declare function deleteUploadFromWidgeticApi(config: FileBrowserUploadConfig, uploadId: string, options?: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
/** Every file id in a folder subtree (depth-first). */
|
|
10
|
+
export declare function collectFileIdsInSubtree(item: FileSystemItem): string[];
|
|
11
|
+
/** Deletes each upload in a folder tree via the Widgetic API, then returns all file ids removed. */
|
|
12
|
+
export declare function deleteSubtreeUploadsOnApi(config: FileBrowserUploadConfig, item: FileSystemItem, options?: {
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}): Promise<string[]>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MediaLibraryError, codeForHttpStatus } from '../mediaLibrary/errors';
|
|
2
|
+
function authHeaders(token) {
|
|
3
|
+
return { Authorization: `Bearer ${token.replace(/^Bearer\s+/i, '')}` };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Soft-deletes one upload row via DELETE /v1/uploads/:id.
|
|
7
|
+
*/
|
|
8
|
+
export async function deleteUploadFromWidgeticApi(config, uploadId, options = {}) {
|
|
9
|
+
const basePath = config.apiBasePath.replace(/\/+$/, '');
|
|
10
|
+
const response = await fetch(`${basePath}/uploads/${encodeURIComponent(uploadId)}`, {
|
|
11
|
+
method: 'DELETE',
|
|
12
|
+
headers: authHeaders(config.accessToken),
|
|
13
|
+
signal: options.signal,
|
|
14
|
+
});
|
|
15
|
+
if (response.status === 404)
|
|
16
|
+
return;
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
let detail = `Delete upload failed (${response.status})`;
|
|
19
|
+
try {
|
|
20
|
+
const errJson = await response.json();
|
|
21
|
+
detail = errJson?.message || errJson?.error?.message || detail;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
/* ignore */
|
|
25
|
+
}
|
|
26
|
+
throw new MediaLibraryError(codeForHttpStatus(response.status), detail, { status: response.status });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Every file id in a folder subtree (depth-first). */
|
|
30
|
+
export function collectFileIdsInSubtree(item) {
|
|
31
|
+
const ids = [];
|
|
32
|
+
function walk(node) {
|
|
33
|
+
if (node.type === 'file') {
|
|
34
|
+
ids.push(node.id);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (node.type === 'folder' && node.children) {
|
|
38
|
+
for (const child of node.children)
|
|
39
|
+
walk(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
walk(item);
|
|
43
|
+
return ids;
|
|
44
|
+
}
|
|
45
|
+
/** Deletes each upload in a folder tree via the Widgetic API, then returns all file ids removed. */
|
|
46
|
+
export async function deleteSubtreeUploadsOnApi(config, item, options = {}) {
|
|
47
|
+
const fileIds = collectFileIdsInSubtree(item);
|
|
48
|
+
for (const id of fileIds) {
|
|
49
|
+
await deleteUploadFromWidgeticApi(config, id, options);
|
|
50
|
+
}
|
|
51
|
+
return fileIds;
|
|
52
|
+
}
|