@widgetic/file-browser 0.5.47 → 0.5.48
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.js +104 -115
- package/dist/components/FolderTree.svelte.d.ts +4 -7
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +224 -14
- package/dist/components/core/FileUploader.svelte +124 -41
- package/dist/components/core/RecentFiles.svelte +54 -16
- package/dist/components/core/SearchDropdown.svelte +6 -8
- package/dist/components/core/UploadPanel.svelte +7 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
- package/dist/components/core/UploadRow.svelte +9 -4
- package/dist/components/core/UploadRow.svelte.d.ts +2 -0
- package/dist/components/core/dropzoneClick.d.ts +28 -0
- package/dist/components/core/dropzoneClick.js +32 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/config.js +4 -3
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +2 -1
- package/dist/i18n/messages.d.ts +13 -0
- package/dist/i18n/messages.js +15 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +4 -3
- package/dist/mediaLibrary/context.js +4 -3
- package/dist/mediaLibrary/errors.js +46 -35
- package/dist/mediaLibrary/normalize.js +45 -42
- package/dist/mediaLibrary/paging.js +100 -45
- package/dist/mediaLibrary/resolve.js +214 -95
- package/dist/mediaLibrary/treeOps.js +40 -20
- package/dist/mediaLibrary/urls.js +12 -10
- package/dist/mediaLibrary/widgetic.js +140 -54
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +44 -37
- package/dist/stores/folderCountStore.js +12 -11
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +217 -178
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +117 -94
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.d.ts +10 -0
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +0 -1
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +57 -42
- package/dist/utils/dateUtils.js +11 -9
- package/dist/utils/deleteSelectionAction.d.ts +26 -0
- package/dist/utils/deleteSelectionAction.js +23 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
- package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
- package/dist/utils/dragToFolder/springStep.js +4 -3
- package/dist/utils/fileGoneProbe.js +65 -16
- package/dist/utils/fileKinds.js +14 -13
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +440 -332
- package/dist/utils/fileTypes.js +19 -14
- package/dist/utils/fileUtils.js +85 -31
- package/dist/utils/folderUtils.js +5 -4
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +26 -15
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +5 -4
- package/dist/utils/imageTransform.js +27 -14
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +55 -39
- package/dist/utils/pendingUploadDeletes.d.ts +102 -0
- package/dist/utils/pendingUploadDeletes.js +400 -0
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +13 -11
- package/dist/utils/previewNavigation.js +10 -7
- package/dist/utils/recentFiles.js +16 -6
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.d.ts +30 -0
- package/dist/utils/removeItems.js +124 -0
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +14 -12
- package/dist/utils/searchDropdownPhase.d.ts +14 -3
- package/dist/utils/searchDropdownPhase.js +13 -9
- package/dist/utils/searchItems.js +30 -14
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.d.ts +24 -0
- package/dist/utils/uploadAuth.js +140 -0
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.d.ts +76 -0
- package/dist/utils/uploadLimits.js +242 -0
- package/dist/utils/uploadListReconcile.js +24 -11
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +13 -11
- package/dist/utils/uploadRefusals.d.ts +42 -0
- package/dist/utils/uploadRefusals.js +86 -0
- package/dist/utils/uploadResponseMapping.js +9 -8
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +270 -133
- package/dist/utils/videoFrame.d.ts +23 -0
- package/dist/utils/videoFrame.js +26 -0
- package/dist/utils/widgeticDelete.js +103 -28
- package/dist/utils/widgeticTusUpload.js +189 -105
- package/dist/utils/widgeticUpload.js +133 -59
- package/dist/utils/xhrMultipartUpload.js +164 -116
- package/package.json +3 -3
package/dist/utils/dateUtils.js
CHANGED
|
@@ -4,21 +4,23 @@ import { translateEnglish } from '../i18n/context';
|
|
|
4
4
|
* Format a date as month, day and year ("Oct 5, 2026"). The month's name and the order of the three follow `locale`
|
|
5
5
|
* (a BCP 47 tag like "de" or "pt-BR"; the File Browser's own locale when called from a screen).
|
|
6
6
|
*/
|
|
7
|
-
export function formatDate(date, locale
|
|
8
|
-
|
|
7
|
+
export function formatDate(date, locale) {
|
|
8
|
+
if (locale === void 0) { locale = 'en-US'; }
|
|
9
|
+
var dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
9
10
|
return new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', year: 'numeric' }).format(dateObj);
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Format a date relative to the current time ("2 days ago"). The words come from the File Browser's messages: pass the
|
|
13
14
|
* `t` of the screen to have them in the page's language (English when left out).
|
|
14
15
|
*/
|
|
15
|
-
export function formatRelativeDate(date, translate
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
export function formatRelativeDate(date, translate) {
|
|
17
|
+
if (translate === void 0) { translate = translateEnglish; }
|
|
18
|
+
var now = new Date();
|
|
19
|
+
var inputDate = new Date(date);
|
|
20
|
+
var hoursAgo = differenceInHours(now, inputDate);
|
|
21
|
+
var daysAgo = differenceInDays(now, inputDate);
|
|
22
|
+
var weeksAgo = differenceInWeeks(now, inputDate);
|
|
23
|
+
var monthsAgo = differenceInMonths(now, inputDate);
|
|
22
24
|
if (hoursAgo < 1) {
|
|
23
25
|
return translate('date.fewSecondsAgo');
|
|
24
26
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type DeleteSelectionAction = 'open-delete-dialog' | 'none';
|
|
2
|
+
export interface DeleteSelectionContext {
|
|
3
|
+
/** `KeyboardEvent.key`: "Delete", or "Backspace", which is the key a Mac keyboard labels "delete". */
|
|
4
|
+
key: string;
|
|
5
|
+
altKey: boolean;
|
|
6
|
+
shiftKey: boolean;
|
|
7
|
+
defaultPrevented: boolean;
|
|
8
|
+
/** The File Browser lets the visitor select files. */
|
|
9
|
+
allowSelecting: boolean;
|
|
10
|
+
/** The media library (or the legacy settings) offers Delete: the button of the selection bar is there. */
|
|
11
|
+
canDelete: boolean;
|
|
12
|
+
/** How many files are selected (the selection bar acts on these). */
|
|
13
|
+
selectionCount: number;
|
|
14
|
+
previewOpen: boolean;
|
|
15
|
+
designSystemModalOpen: boolean;
|
|
16
|
+
/** The visitor is typing in a field (search, a rename): the key edits the text. */
|
|
17
|
+
inputFocused: boolean;
|
|
18
|
+
/** A dialog or a dropdown of the File Browser is open (rename, new folder, move, delete, filter, sort): the key is theirs. */
|
|
19
|
+
innerUiOpen: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the Delete key (or Backspace) opens the delete dialog for the selected files. It is the same dialog the Delete
|
|
23
|
+
* button of the selection bar opens, so the keyboard and the button cannot disagree. With nothing selected the key does what
|
|
24
|
+
* it always did (Backspace goes back one folder); in a field, a dialog or the preview it is left alone.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteSelectionAction(context: DeleteSelectionContext): DeleteSelectionAction;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the Delete key (or Backspace) opens the delete dialog for the selected files. It is the same dialog the Delete
|
|
3
|
+
* button of the selection bar opens, so the keyboard and the button cannot disagree. With nothing selected the key does what
|
|
4
|
+
* it always did (Backspace goes back one folder); in a field, a dialog or the preview it is left alone.
|
|
5
|
+
*/
|
|
6
|
+
export function deleteSelectionAction(context) {
|
|
7
|
+
if (context.key !== 'Delete' && context.key !== 'Backspace')
|
|
8
|
+
return 'none';
|
|
9
|
+
if (context.defaultPrevented)
|
|
10
|
+
return 'none';
|
|
11
|
+
// Option+Delete deletes a word and Shift+Delete is the browser's own: neither is "delete the files".
|
|
12
|
+
if (context.altKey || context.shiftKey)
|
|
13
|
+
return 'none';
|
|
14
|
+
if (!context.allowSelecting || !context.canDelete)
|
|
15
|
+
return 'none';
|
|
16
|
+
if (context.selectionCount <= 0)
|
|
17
|
+
return 'none';
|
|
18
|
+
if (context.previewOpen || context.designSystemModalOpen)
|
|
19
|
+
return 'none';
|
|
20
|
+
if (context.inputFocused || context.innerUiOpen)
|
|
21
|
+
return 'none';
|
|
22
|
+
return 'open-delete-dialog';
|
|
23
|
+
}
|
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
1
46
|
import { ENDPOINTS } from '../apiConfig';
|
|
2
47
|
import { findItemById, moveItems } from '../fileOperations';
|
|
3
48
|
import { MediaLibraryError } from '../../mediaLibrary/errors';
|
|
@@ -6,20 +51,22 @@ import { fileStore } from '../../stores/fileStore';
|
|
|
6
51
|
import { getNavigationStore } from '../../stores/navigationStore';
|
|
7
52
|
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
8
53
|
function actualTargetId(targetFolderId) {
|
|
9
|
-
|
|
54
|
+
var root = get(fileStore).root;
|
|
10
55
|
if (targetFolderId === 'root' || (root && targetFolderId === root.id)) {
|
|
11
56
|
return '';
|
|
12
57
|
}
|
|
13
58
|
return targetFolderId;
|
|
14
59
|
}
|
|
15
60
|
function findFolderPath(root, targetId) {
|
|
16
|
-
|
|
61
|
+
var search = function (folder, path) {
|
|
62
|
+
if (path === void 0) { path = []; }
|
|
17
63
|
if (folder.id === targetId)
|
|
18
64
|
return path;
|
|
19
65
|
if (folder.children) {
|
|
20
|
-
for (
|
|
66
|
+
for (var _i = 0, _a = folder.children; _i < _a.length; _i++) {
|
|
67
|
+
var child = _a[_i];
|
|
21
68
|
if (child.type === 'folder') {
|
|
22
|
-
|
|
69
|
+
var result = search(child, __spreadArray(__spreadArray([], path, true), [child.id], false));
|
|
23
70
|
if (result !== null)
|
|
24
71
|
return result;
|
|
25
72
|
}
|
|
@@ -33,55 +80,68 @@ function findFolderPath(root, targetId) {
|
|
|
33
80
|
* Commits a batch move (API when needed, then one atomic tree update).
|
|
34
81
|
* Mirrors MoveDialog semantics.
|
|
35
82
|
*/
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
export function commitBatchMove(args) {
|
|
84
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
85
|
+
var sourceItems, targetFolderId, localOnly, currentFilter, navigationStoreId, actualTarget, navigationStore, moveEndpoint, apiResults, idsToMove, failedCount, movedIds, root, targetPath, _i, movedIds_1, id, movedItem, newParentPath;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
sourceItems = args.sourceItems, targetFolderId = args.targetFolderId, localOnly = args.localOnly, currentFilter = args.currentFilter, navigationStoreId = args.navigationStoreId;
|
|
90
|
+
if (sourceItems.length === 0) {
|
|
91
|
+
return [2 /*return*/, { ok: false, movedIds: [], failedCount: 0 }];
|
|
92
|
+
}
|
|
93
|
+
actualTarget = actualTargetId(targetFolderId);
|
|
94
|
+
navigationStore = getNavigationStore(navigationStoreId);
|
|
95
|
+
moveEndpoint = typeof window !== 'undefined' && import.meta.env.DEV
|
|
96
|
+
? '/api/files/move'
|
|
97
|
+
: ENDPOINTS.FILE_MOVE;
|
|
98
|
+
return [4 /*yield*/, Promise.allSettled(sourceItems.map(function (sourceItem) {
|
|
99
|
+
return localOnly
|
|
100
|
+
? Promise.resolve({ success: true })
|
|
101
|
+
: fetch(moveEndpoint, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { 'Content-Type': 'application/json' },
|
|
104
|
+
body: JSON.stringify({
|
|
105
|
+
itemId: sourceItem.id,
|
|
106
|
+
targetFolderId: actualTarget
|
|
107
|
+
})
|
|
108
|
+
}).then(function (response) { return response.json(); });
|
|
109
|
+
}))];
|
|
110
|
+
case 1:
|
|
111
|
+
apiResults = _a.sent();
|
|
112
|
+
idsToMove = [];
|
|
113
|
+
failedCount = 0;
|
|
114
|
+
apiResults.forEach(function (result, index) {
|
|
115
|
+
var sourceItem = sourceItems[index];
|
|
116
|
+
if (result.status === 'fulfilled' && result.value.success) {
|
|
117
|
+
idsToMove.push(sourceItem.id);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
failedCount += 1;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (idsToMove.length === 0) {
|
|
124
|
+
return [2 /*return*/, { ok: false, movedIds: [], failedCount: failedCount }];
|
|
125
|
+
}
|
|
126
|
+
movedIds = moveItems(idsToMove, actualTarget);
|
|
127
|
+
if (movedIds.length === 0) {
|
|
128
|
+
throw new MediaLibraryError('FAILED', 'Tree update failed after move', {
|
|
129
|
+
messageKey: 'moveDialog.noneMoved'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
root = get(fileStore).root;
|
|
133
|
+
targetPath = actualTarget ? findFolderPath(root, actualTarget) : [];
|
|
134
|
+
for (_i = 0, movedIds_1 = movedIds; _i < movedIds_1.length; _i++) {
|
|
135
|
+
id = movedIds_1[_i];
|
|
136
|
+
movedItem = findItemById(id);
|
|
137
|
+
if ((movedItem === null || movedItem === void 0 ? void 0 : movedItem.type) === 'folder') {
|
|
138
|
+
newParentPath = targetPath !== null && targetPath !== void 0 ? targetPath : [];
|
|
139
|
+
navigationStore.updateMovedFolderPaths(movedItem.id, newParentPath);
|
|
140
|
+
}
|
|
141
|
+
persistentSelectStore.removeSelection(id, currentFilter);
|
|
142
|
+
}
|
|
143
|
+
return [2 /*return*/, { ok: failedCount === 0, movedIds: movedIds, failedCount: failedCount }];
|
|
144
|
+
}
|
|
74
145
|
});
|
|
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 };
|
|
146
|
+
});
|
|
87
147
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
var FOLDER_TARGET_ATTR = 'data-folder-drop-target';
|
|
2
2
|
/** Walk `elementsFromPoint` and return the nearest folder drop target. */
|
|
3
|
-
export function resolveFolderDropTarget(clientX, clientY, root
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export function resolveFolderDropTarget(clientX, clientY, root) {
|
|
4
|
+
var _a;
|
|
5
|
+
if (root === void 0) { root = document; }
|
|
6
|
+
var doc = root instanceof Document ? root : (_a = root.ownerDocument) !== null && _a !== void 0 ? _a : document;
|
|
7
|
+
var elements = doc.elementsFromPoint(clientX, clientY);
|
|
8
|
+
for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
|
|
9
|
+
var el = elements_1[_i];
|
|
7
10
|
if (!(el instanceof HTMLElement))
|
|
8
11
|
continue;
|
|
9
|
-
|
|
12
|
+
var match = el.closest("[".concat(FOLDER_TARGET_ATTR, "]"));
|
|
10
13
|
if (match instanceof HTMLElement) {
|
|
11
|
-
|
|
14
|
+
var folderId = match.getAttribute(FOLDER_TARGET_ATTR);
|
|
12
15
|
if (folderId) {
|
|
13
|
-
return { folderId, element: match };
|
|
16
|
+
return { folderId: folderId, element: match };
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -19,7 +22,8 @@ export function resolveFolderDropTarget(clientX, clientY, root = document) {
|
|
|
19
22
|
function folderDescendantIds(folder, into) {
|
|
20
23
|
if (folder.type !== 'folder' || !folder.children)
|
|
21
24
|
return;
|
|
22
|
-
for (
|
|
25
|
+
for (var _i = 0, _a = folder.children; _i < _a.length; _i++) {
|
|
26
|
+
var child = _a[_i];
|
|
23
27
|
if (child.type === 'folder') {
|
|
24
28
|
into.add(child.id);
|
|
25
29
|
folderDescendantIds(child, into);
|
|
@@ -27,15 +31,16 @@ function folderDescendantIds(folder, into) {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
function isDescendantOf(folderId, ancestorId, root) {
|
|
30
|
-
|
|
34
|
+
var walk = function (node) {
|
|
31
35
|
if (node.id === ancestorId) {
|
|
32
|
-
|
|
36
|
+
var descendants = new Set();
|
|
33
37
|
if (node.type === 'folder')
|
|
34
38
|
folderDescendantIds(node, descendants);
|
|
35
39
|
return descendants.has(folderId) || node.id === folderId;
|
|
36
40
|
}
|
|
37
41
|
if (node.children) {
|
|
38
|
-
for (
|
|
42
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
43
|
+
var child = _a[_i];
|
|
39
44
|
if (walk(child))
|
|
40
45
|
return true;
|
|
41
46
|
}
|
|
@@ -52,19 +57,20 @@ function isDescendantOf(folderId, ancestorId, root) {
|
|
|
52
57
|
export function canDropOnFolder(targetFolderId, sourceItems, immediateParentId, root) {
|
|
53
58
|
if (!targetFolderId)
|
|
54
59
|
return false;
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
var normalizedTarget = targetFolderId === 'root' || targetFolderId === root.id ? '' : targetFolderId;
|
|
61
|
+
var normalizedParent = immediateParentId !== null && immediateParentId !== void 0 ? immediateParentId : '';
|
|
57
62
|
// Same folder as current location
|
|
58
63
|
if (normalizedTarget === normalizedParent)
|
|
59
64
|
return false;
|
|
60
|
-
|
|
61
|
-
for (
|
|
65
|
+
var sourceFolderIds = sourceItems.filter(function (i) { return i.type === 'folder'; }).map(function (i) { return i.id; });
|
|
66
|
+
for (var _i = 0, sourceFolderIds_1 = sourceFolderIds; _i < sourceFolderIds_1.length; _i++) {
|
|
67
|
+
var sourceFolderId = sourceFolderIds_1[_i];
|
|
62
68
|
if (normalizedTarget === sourceFolderId)
|
|
63
69
|
return false;
|
|
64
70
|
if (normalizedTarget && isDescendantOf(normalizedTarget, sourceFolderId, root))
|
|
65
71
|
return false;
|
|
66
72
|
}
|
|
67
|
-
if (sourceFolderIds.some((id)
|
|
73
|
+
if (sourceFolderIds.some(function (id) { return id === normalizedTarget; }))
|
|
68
74
|
return false;
|
|
69
75
|
return true;
|
|
70
76
|
}
|
|
@@ -13,9 +13,10 @@ export function springLerpPoint(current, target, factor) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
/** Default follow strength for the ghost stack anchor (spec ~0.18). */
|
|
16
|
-
export
|
|
16
|
+
export var DEFAULT_GHOST_FOLLOW_FACTOR = 0.18;
|
|
17
17
|
/** Deeper stack cards lag slightly more than the front card. */
|
|
18
|
-
export function layerFollowFactor(layerIndex, baseFactor
|
|
19
|
-
|
|
18
|
+
export function layerFollowFactor(layerIndex, baseFactor) {
|
|
19
|
+
if (baseFactor === void 0) { baseFactor = DEFAULT_GHOST_FOLLOW_FACTOR; }
|
|
20
|
+
var lag = 1 - layerIndex * 0.045;
|
|
20
21
|
return Math.max(0.08, baseFactor * lag);
|
|
21
22
|
}
|
|
@@ -10,28 +10,77 @@
|
|
|
10
10
|
* blocked, a network error or any other status says nothing about the file, so the file stays and its preview shows the error state.
|
|
11
11
|
* The request is a GET for the first byte (CORS is allowed for GET) so it works across origins.
|
|
12
12
|
*/
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
/** Status codes that say the file is no longer at its address. */
|
|
14
|
-
|
|
50
|
+
var GONE_STATUS_CODES = new Set([404, 410]);
|
|
15
51
|
/**
|
|
16
52
|
* `true` only when the server answered that the file does not exist; `false` for every other outcome (found, blocked, offline).
|
|
17
53
|
*
|
|
18
54
|
* @param fileUrl - The address of the file.
|
|
19
55
|
* @param fetchImplementation - `fetch`, replaceable in tests.
|
|
20
56
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
57
|
+
export function isFileGone(fileUrl_1) {
|
|
58
|
+
return __awaiter(this, arguments, Promise, function (fileUrl, fetchImplementation) {
|
|
59
|
+
var response, error_1;
|
|
60
|
+
if (fetchImplementation === void 0) { fetchImplementation = function (input, init) { return fetch(input, init); }; }
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
// Without an address there is nothing to ask: the file is not proven gone, and nothing is removed because of it.
|
|
65
|
+
if (!fileUrl)
|
|
66
|
+
return [2 /*return*/, false];
|
|
67
|
+
_a.label = 1;
|
|
68
|
+
case 1:
|
|
69
|
+
_a.trys.push([1, 3, , 4]);
|
|
70
|
+
return [4 /*yield*/, fetchImplementation(fileUrl, {
|
|
71
|
+
method: 'GET',
|
|
72
|
+
headers: { Range: 'bytes=0-0' }
|
|
73
|
+
})];
|
|
74
|
+
case 2:
|
|
75
|
+
response = _a.sent();
|
|
76
|
+
return [2 /*return*/, GONE_STATUS_CODES.has(response.status)];
|
|
77
|
+
case 3:
|
|
78
|
+
error_1 = _a.sent();
|
|
79
|
+
// A blocked or failed request is not proof: keep the file.
|
|
80
|
+
console.warn('[fileGoneProbe] Could not ask whether the file still exists; keeping it:', fileUrl, error_1);
|
|
81
|
+
return [2 /*return*/, false];
|
|
82
|
+
case 4: return [2 /*return*/];
|
|
83
|
+
}
|
|
29
84
|
});
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
// A blocked or failed request is not proof: keep the file.
|
|
34
|
-
console.warn('[fileGoneProbe] Could not ask whether the file still exists; keeping it:', fileUrl, error);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
85
|
+
});
|
|
37
86
|
}
|
package/dist/utils/fileKinds.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FILE_TYPES } from './fileTypes';
|
|
|
3
3
|
* Types a host sends when it does not really know what a file is.
|
|
4
4
|
* They say nothing about the file, so the file name decides instead.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
var UNINFORMATIVE_MIME_TYPES = new Set([
|
|
7
7
|
'application/octet-stream',
|
|
8
8
|
'binary/octet-stream',
|
|
9
9
|
'application/unknown',
|
|
@@ -11,8 +11,9 @@ const UNINFORMATIVE_MIME_TYPES = new Set([
|
|
|
11
11
|
]);
|
|
12
12
|
/** The extension of a file name or URL path, with its dot and in lower case ("" when there is none). */
|
|
13
13
|
function extensionOf(fileName) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
var lastSegment = (_a = fileName.split(/[?#]/)[0].split('/').pop()) !== null && _a !== void 0 ? _a : '';
|
|
16
|
+
var dotIndex = lastSegment.lastIndexOf('.');
|
|
16
17
|
// A leading dot (".env") is part of the name, not an extension.
|
|
17
18
|
return dotIndex > 0 ? lastSegment.slice(dotIndex).toLowerCase() : '';
|
|
18
19
|
}
|
|
@@ -27,14 +28,15 @@ function extensionOf(fileName) {
|
|
|
27
28
|
* reported here, so it keeps being tried as a picture.
|
|
28
29
|
*/
|
|
29
30
|
export function isKnownNonImageFile(file) {
|
|
30
|
-
|
|
31
|
+
var _a, _b;
|
|
32
|
+
var mimeType = ((_a = file.mimeType) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
|
|
31
33
|
if (mimeType !== '' && !UNINFORMATIVE_MIME_TYPES.has(mimeType)) {
|
|
32
34
|
return !mimeType.startsWith('image/');
|
|
33
35
|
}
|
|
34
|
-
return FILE_TYPES.document.includes(extensionOf(file.name
|
|
36
|
+
return FILE_TYPES.document.includes(extensionOf((_b = file.name) !== null && _b !== void 0 ? _b : ''));
|
|
35
37
|
}
|
|
36
38
|
/** Mime types of font files that do not start with `font/` (older servers still send these). */
|
|
37
|
-
|
|
39
|
+
var LEGACY_FONT_MIME_TYPES = new Set([
|
|
38
40
|
'application/font-woff',
|
|
39
41
|
'application/font-woff2',
|
|
40
42
|
'application/font-sfnt',
|
|
@@ -48,8 +50,9 @@ const LEGACY_FONT_MIME_TYPES = new Set([
|
|
|
48
50
|
* or `null` when there is no extension or the tabs do not know it.
|
|
49
51
|
*/
|
|
50
52
|
export function fileKindFromExtension(nameOrAddress) {
|
|
51
|
-
|
|
52
|
-
for (
|
|
53
|
+
var extension = extensionOf(nameOrAddress !== null && nameOrAddress !== void 0 ? nameOrAddress : '');
|
|
54
|
+
for (var _i = 0, _a = Object.entries(FILE_TYPES); _i < _a.length; _i++) {
|
|
55
|
+
var _b = _a[_i], kind = _b[0], extensions = _b[1];
|
|
53
56
|
if (extensions.includes(extension))
|
|
54
57
|
return kind;
|
|
55
58
|
}
|
|
@@ -62,7 +65,7 @@ export function fileKindFromExtension(nameOrAddress) {
|
|
|
62
65
|
export function fileKindFromMimeType(mimeType) {
|
|
63
66
|
// "image/png; charset=binary" is still image/png. A missing or "binary, who knows" type matches none of the
|
|
64
67
|
// kinds below, so it ends up as null like any other type the tabs have no kind for.
|
|
65
|
-
|
|
68
|
+
var mime = (mimeType !== null && mimeType !== void 0 ? mimeType : '').split(';')[0].trim().toLowerCase();
|
|
66
69
|
if (mime === 'image/svg+xml')
|
|
67
70
|
return 'svg';
|
|
68
71
|
if (mime.startsWith('image/'))
|
|
@@ -89,8 +92,6 @@ export function fileKindFromMimeType(mimeType) {
|
|
|
89
92
|
* A file nothing says anything about is a document.
|
|
90
93
|
*/
|
|
91
94
|
export function getFileTypeOf(file) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
fileKindFromMimeType(file.mimeType) ??
|
|
95
|
-
'document');
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
return ((_c = (_b = (_a = fileKindFromExtension(file.url)) !== null && _a !== void 0 ? _a : fileKindFromExtension(file.name)) !== null && _b !== void 0 ? _b : fileKindFromMimeType(file.mimeType)) !== null && _c !== void 0 ? _c : 'document');
|
|
96
97
|
}
|
package/dist/utils/fileNames.js
CHANGED
|
@@ -7,14 +7,14 @@ export function splitFileName(name) {
|
|
|
7
7
|
if (/^\.[^.]+$/.test(name)) {
|
|
8
8
|
return { baseName: name, extension: '' };
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
var parts = name.split('.');
|
|
11
11
|
if (parts.length <= 1) {
|
|
12
12
|
return { baseName: name, extension: '' };
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
var originalExtension = parts[parts.length - 1];
|
|
15
15
|
return {
|
|
16
16
|
baseName: parts.slice(0, -1).join('.'),
|
|
17
|
-
extension: originalExtension
|
|
17
|
+
extension: originalExtension !== null && originalExtension !== void 0 ? originalExtension : ''
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -24,15 +24,15 @@ export function splitFileName(name) {
|
|
|
24
24
|
* never changes what kind of file it is.
|
|
25
25
|
*/
|
|
26
26
|
export function getRenamedFileName(currentName, typedName) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var currentNameParts = currentName.split('.');
|
|
28
|
+
var newNameParts = typedName.split('.');
|
|
29
29
|
// If current file has an extension but new name doesn't (or has a different one)
|
|
30
30
|
if (currentNameParts.length > 1 &&
|
|
31
31
|
(newNameParts.length === 1 ||
|
|
32
32
|
newNameParts[newNameParts.length - 1] !== currentNameParts[currentNameParts.length - 1])) {
|
|
33
33
|
// Preserve the original extension
|
|
34
|
-
|
|
35
|
-
return
|
|
34
|
+
var originalExtension = currentNameParts[currentNameParts.length - 1];
|
|
35
|
+
return "".concat(typedName, ".").concat(originalExtension);
|
|
36
36
|
}
|
|
37
37
|
return typedName;
|
|
38
38
|
}
|