@widgetic/file-browser 0.5.48 → 0.5.49
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 +115 -104
- package/dist/components/FolderTree.svelte.d.ts +7 -4
- package/dist/components/core/FileBrowser.svelte +1 -3
- package/dist/components/core/dropzoneClick.js +2 -3
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/config.js +3 -4
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +3 -4
- package/dist/mediaLibrary/context.js +3 -4
- package/dist/mediaLibrary/errors.js +35 -46
- package/dist/mediaLibrary/normalize.js +42 -45
- package/dist/mediaLibrary/paging.js +45 -100
- package/dist/mediaLibrary/resolve.js +95 -214
- package/dist/mediaLibrary/treeOps.js +20 -40
- package/dist/mediaLibrary/urls.js +10 -12
- package/dist/mediaLibrary/widgetic.js +54 -140
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +37 -44
- package/dist/stores/folderCountStore.js +11 -12
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +178 -217
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +94 -117
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +1 -0
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +42 -57
- package/dist/utils/dateUtils.js +9 -11
- package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
- package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
- package/dist/utils/dragToFolder/springStep.js +3 -4
- package/dist/utils/fileGoneProbe.js +16 -65
- package/dist/utils/fileKinds.js +13 -14
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +332 -440
- package/dist/utils/fileTypes.js +14 -19
- package/dist/utils/fileUtils.js +31 -85
- package/dist/utils/folderUtils.js +4 -5
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +15 -26
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +4 -5
- package/dist/utils/imageTransform.js +14 -27
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +39 -55
- package/dist/utils/pendingUploadDeletes.js +113 -289
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +11 -13
- package/dist/utils/previewNavigation.js +7 -10
- package/dist/utils/recentFiles.js +6 -16
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.js +29 -61
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +12 -14
- package/dist/utils/searchDropdownPhase.js +2 -2
- package/dist/utils/searchItems.js +14 -30
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.js +36 -111
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.js +66 -138
- package/dist/utils/uploadListReconcile.js +11 -24
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +11 -13
- package/dist/utils/uploadRefusals.js +24 -40
- package/dist/utils/uploadResponseMapping.js +8 -9
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +133 -270
- package/dist/utils/videoFrame.js +2 -2
- package/dist/utils/widgeticDelete.js +30 -103
- package/dist/utils/widgeticTusUpload.js +105 -189
- package/dist/utils/widgeticUpload.js +62 -130
- package/dist/utils/xhrMultipartUpload.js +116 -164
- package/package.json +1 -1
package/dist/utils/fileTypes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { translateEnglish } from '../i18n/context';
|
|
2
2
|
// Define which document types can be displayed as text
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export const PREVIEWABLE_TEXT_EXTENSIONS = ['.txt', '.md', '.csv', '.json', '.xml', '.log'];
|
|
4
|
+
export const FILE_TYPES = {
|
|
5
5
|
image: ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.heic', '.heif'],
|
|
6
6
|
audio: ['.mp3'],
|
|
7
7
|
video: ['.mp4'],
|
|
@@ -9,7 +9,7 @@ export var FILE_TYPES = {
|
|
|
9
9
|
font: ['.ttf', '.otf', '.woff', '.woff2'],
|
|
10
10
|
svg: ['.svg']
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export const FILTER_OPTIONS = ['all', 'image', 'audio', 'video', 'document', 'font', 'svg'];
|
|
13
13
|
export function getAllowedFileTypes(filter) {
|
|
14
14
|
if (filter === 'all') {
|
|
15
15
|
return Object.values(FILE_TYPES).flat();
|
|
@@ -18,9 +18,8 @@ export function getAllowedFileTypes(filter) {
|
|
|
18
18
|
}
|
|
19
19
|
export function getFileTypeFromExtension(extension) {
|
|
20
20
|
extension = extension.toLowerCase();
|
|
21
|
-
for (
|
|
22
|
-
|
|
23
|
-
if (extensions.some(function (ext) { return ext.toLowerCase() === extension; })) {
|
|
21
|
+
for (const [type, extensions] of Object.entries(FILE_TYPES)) {
|
|
22
|
+
if (extensions.some(ext => ext.toLowerCase() === extension)) {
|
|
24
23
|
return type;
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -28,17 +27,15 @@ export function getFileTypeFromExtension(extension) {
|
|
|
28
27
|
}
|
|
29
28
|
// New function to check if a file can be displayed as text
|
|
30
29
|
export function isPreviewableTextFile(filename) {
|
|
31
|
-
|
|
32
|
-
var extension = '.' + ((_a = filename.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
30
|
+
const extension = '.' + filename.split('.').pop()?.toLowerCase();
|
|
33
31
|
return PREVIEWABLE_TEXT_EXTENSIONS.includes(extension);
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* One sentence that lists every kind of file with its extensions ("Add images (.jpg, .png), audio (.mp3) ..."). Pass the
|
|
37
35
|
* `t` of the File Browser to have it in the page's language (English when left out).
|
|
38
36
|
*/
|
|
39
|
-
export function formatFileTypesForDisplay(translate) {
|
|
40
|
-
|
|
41
|
-
var separator = translate('list.separator');
|
|
37
|
+
export function formatFileTypesForDisplay(translate = translateEnglish) {
|
|
38
|
+
const separator = translate('list.separator');
|
|
42
39
|
return translate('fileTypes.addAll', {
|
|
43
40
|
images: FILE_TYPES.image.join(separator),
|
|
44
41
|
audio: FILE_TYPES.audio.join(separator),
|
|
@@ -52,13 +49,12 @@ export function formatFileTypesForDisplay(translate) {
|
|
|
52
49
|
* The help text about what can be uploaded under a filter: "Allowed types: .jpg, .png ...", and for fonts how a font
|
|
53
50
|
* file must be named. Pass the `t` of the File Browser to have it in the page's language (English when left out).
|
|
54
51
|
*/
|
|
55
|
-
export function formatAllowedTypesForDisplay(filter, translate) {
|
|
56
|
-
|
|
57
|
-
var separator = translate('list.separator');
|
|
52
|
+
export function formatAllowedTypesForDisplay(filter, translate = translateEnglish) {
|
|
53
|
+
const separator = translate('list.separator');
|
|
58
54
|
if (filter === 'all') {
|
|
59
55
|
return translate('fileTypes.allowed', { types: Object.values(FILE_TYPES).flat().join(separator) });
|
|
60
56
|
}
|
|
61
|
-
|
|
57
|
+
let allowedTypes = '';
|
|
62
58
|
if (filter === 'svg') {
|
|
63
59
|
allowedTypes = translate('fileTypes.allowedSvg');
|
|
64
60
|
}
|
|
@@ -69,11 +65,11 @@ export function formatAllowedTypesForDisplay(filter, translate) {
|
|
|
69
65
|
allowedTypes = translate('fileTypes.allowed', { types: FILE_TYPES[filter].join(separator) });
|
|
70
66
|
}
|
|
71
67
|
if (filter === 'font') {
|
|
72
|
-
allowedTypes +=
|
|
68
|
+
allowedTypes += `\n\n${translate('fileTypes.fontNaming')}`;
|
|
73
69
|
}
|
|
74
70
|
return allowedTypes;
|
|
75
71
|
}
|
|
76
|
-
export
|
|
72
|
+
export const MIME_TYPES = {
|
|
77
73
|
// Images
|
|
78
74
|
'image/jpeg': '.jpg',
|
|
79
75
|
'image/jpg': '.jpg',
|
|
@@ -116,10 +112,9 @@ export function getMimeTypeExtension(mimeType) {
|
|
|
116
112
|
* uploads declare image/heic.
|
|
117
113
|
*/
|
|
118
114
|
export function normalizeFileMimeType(file) {
|
|
119
|
-
var _a;
|
|
120
115
|
if (file.type)
|
|
121
116
|
return file;
|
|
122
|
-
|
|
117
|
+
const extension = '.' + file.name.split('.').pop()?.toLowerCase();
|
|
123
118
|
if (extension === '.heic' || extension === '.heif') {
|
|
124
119
|
return new File([file], file.name, { type: 'image/heic', lastModified: file.lastModified });
|
|
125
120
|
}
|
package/dist/utils/fileUtils.js
CHANGED
|
@@ -1,39 +1,3 @@
|
|
|
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
1
|
import { FILE_TYPES } from './fileTypes';
|
|
38
2
|
import { isKnownNonImageFile } from './fileKinds';
|
|
39
3
|
import { translateEnglish } from '../i18n/context';
|
|
@@ -52,10 +16,10 @@ import icUnorganizedFolder from '../static/icons/unorganized-folder.svg?url';
|
|
|
52
16
|
* Pattern to match if a path is already an absolute URL
|
|
53
17
|
* This will match http://, https://, data:, etc.
|
|
54
18
|
*/
|
|
55
|
-
|
|
19
|
+
const absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
|
|
56
20
|
// Show logs for debugging
|
|
57
|
-
|
|
58
|
-
|
|
21
|
+
let showLogs = false;
|
|
22
|
+
const bundledIconUrls = {
|
|
59
23
|
'/icons/audio.svg': icAudio,
|
|
60
24
|
'/icons/checked.svg': icChecked,
|
|
61
25
|
'/icons/document.svg': icDocument,
|
|
@@ -69,33 +33,29 @@ var bundledIconUrls = {
|
|
|
69
33
|
'/icons/unorganized-folder.svg': icUnorganizedFolder,
|
|
70
34
|
};
|
|
71
35
|
/** The message for each unit of size, from bytes to terabytes. */
|
|
72
|
-
|
|
36
|
+
const SIZE_MESSAGES = ['size.bytes', 'size.kb', 'size.mb', 'size.gb', 'size.tb'];
|
|
73
37
|
/** A number of a size, written the way `locale` writes numbers, with up to `fractionDigits` decimals and no thousands separator ("1.5", "1,5"). */
|
|
74
38
|
function formatSizeNumber(value, locale, minimumFractionDigits, maximumFractionDigits) {
|
|
75
|
-
return new Intl.NumberFormat(locale, { minimumFractionDigits
|
|
39
|
+
return new Intl.NumberFormat(locale, { minimumFractionDigits, maximumFractionDigits, useGrouping: false }).format(value);
|
|
76
40
|
}
|
|
77
41
|
/**
|
|
78
42
|
* A size in bytes as the biggest unit that keeps it above 1: "0 Bytes", "1.5 MB". The units and the number format
|
|
79
43
|
* follow the language: pass the `t` and the `locale` of the File Browser (English when left out).
|
|
80
44
|
*/
|
|
81
|
-
export function formatFileSize(bytes, translate, locale) {
|
|
82
|
-
if (translate === void 0) { translate = translateEnglish; }
|
|
83
|
-
if (locale === void 0) { locale = 'en'; }
|
|
45
|
+
export function formatFileSize(bytes, translate = translateEnglish, locale = 'en') {
|
|
84
46
|
if (bytes === 0)
|
|
85
47
|
return translate('size.bytes', { size: formatSizeNumber(0, locale, 0, 2) });
|
|
86
|
-
|
|
87
|
-
|
|
48
|
+
const k = 1024;
|
|
49
|
+
const unitIndex = Math.min(SIZE_MESSAGES.length - 1, Math.max(0, Math.floor(Math.log(bytes) / Math.log(k))));
|
|
88
50
|
return translate(SIZE_MESSAGES[unitIndex], { size: formatSizeNumber(bytes / Math.pow(k, unitIndex), locale, 0, 2) });
|
|
89
51
|
}
|
|
90
52
|
/** A size in bytes as kilobytes with one decimal ("12.3 KB"), the way the upload list shows it. */
|
|
91
|
-
export function formatKilobytes(bytes, translate, locale) {
|
|
92
|
-
if (translate === void 0) { translate = translateEnglish; }
|
|
93
|
-
if (locale === void 0) { locale = 'en'; }
|
|
53
|
+
export function formatKilobytes(bytes, translate = translateEnglish, locale = 'en') {
|
|
94
54
|
return translate('size.kb', { size: formatSizeNumber(bytes / 1024, locale, 1, 1) });
|
|
95
55
|
}
|
|
96
56
|
export function getFileIcon(fileName) {
|
|
97
|
-
|
|
98
|
-
|
|
57
|
+
const fileType = getFileType(fileName);
|
|
58
|
+
const extension = getFileExtension(fileName).toLowerCase();
|
|
99
59
|
switch (fileType) {
|
|
100
60
|
case 'audio':
|
|
101
61
|
return getAssetUrl('/icons/audio.svg');
|
|
@@ -115,16 +75,14 @@ export function getFileIcon(fileName) {
|
|
|
115
75
|
}
|
|
116
76
|
}
|
|
117
77
|
export function getFileExtension(fileNameOrUrl) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return extension ? ".".concat(extension) : '';
|
|
78
|
+
const cleanPath = fileNameOrUrl.split(/[?#]/)[0];
|
|
79
|
+
const fileName = cleanPath.split('/').pop() || '';
|
|
80
|
+
const extension = fileName.split('.').pop()?.toLowerCase() || '';
|
|
81
|
+
return extension ? `.${extension}` : '';
|
|
123
82
|
}
|
|
124
83
|
export function getFileType(fileNameOrUrl) {
|
|
125
|
-
|
|
126
|
-
for (
|
|
127
|
-
var _b = _a[_i], type = _b[0], extensions = _b[1];
|
|
84
|
+
const extension = getFileExtension(fileNameOrUrl);
|
|
85
|
+
for (const [type, extensions] of Object.entries(FILE_TYPES)) {
|
|
128
86
|
if (extensions.includes(extension.toLowerCase())) {
|
|
129
87
|
return type;
|
|
130
88
|
}
|
|
@@ -133,14 +91,14 @@ export function getFileType(fileNameOrUrl) {
|
|
|
133
91
|
}
|
|
134
92
|
/** Prefer mime / thumbnail URL when the filename has no real image extension (e.g. IMG_8658). */
|
|
135
93
|
export function getItemFileType(item) {
|
|
136
|
-
|
|
94
|
+
const mime = (item.mimeType || '').toLowerCase();
|
|
137
95
|
if (mime.startsWith('image/'))
|
|
138
96
|
return 'image';
|
|
139
97
|
if (mime.startsWith('video/'))
|
|
140
98
|
return 'video';
|
|
141
99
|
if (mime.startsWith('audio/'))
|
|
142
100
|
return 'audio';
|
|
143
|
-
|
|
101
|
+
const fromName = getFileType(item.name || '');
|
|
144
102
|
if (fromName !== 'document')
|
|
145
103
|
return fromName;
|
|
146
104
|
// A PDF, a text file or any other named non-picture stays that kind. A thumbnail
|
|
@@ -151,34 +109,22 @@ export function getItemFileType(item) {
|
|
|
151
109
|
}
|
|
152
110
|
if (/IMG_\d+/i.test(item.name || ''))
|
|
153
111
|
return 'image';
|
|
154
|
-
|
|
112
|
+
const urlHint = item.thumbnail || item.url || '';
|
|
155
113
|
if (urlHint && (/^data:image\//i.test(urlHint) || /\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(urlHint.split(/[?#]/)[0]))) {
|
|
156
114
|
return 'image';
|
|
157
115
|
}
|
|
158
116
|
return getFileType(item.url || item.name || '');
|
|
159
117
|
}
|
|
160
|
-
export function checkFileExists(url) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
_a.trys.push([1, 3, , 4]);
|
|
171
|
-
return [4 /*yield*/, fetch(url, { method: 'HEAD' })];
|
|
172
|
-
case 2:
|
|
173
|
-
response = _a.sent();
|
|
174
|
-
return [2 /*return*/, response.ok];
|
|
175
|
-
case 3:
|
|
176
|
-
error_1 = _a.sent();
|
|
177
|
-
return [2 /*return*/, false];
|
|
178
|
-
case 4: return [2 /*return*/];
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
118
|
+
export async function checkFileExists(url) {
|
|
119
|
+
if (!url)
|
|
120
|
+
return false;
|
|
121
|
+
try {
|
|
122
|
+
const response = await fetch(url, { method: 'HEAD' });
|
|
123
|
+
return response.ok;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
182
128
|
}
|
|
183
129
|
/**
|
|
184
130
|
* Gets the correct URL for a static asset using SvelteKit's assets path
|
|
@@ -195,7 +141,7 @@ export function getAssetUrl(path) {
|
|
|
195
141
|
if (absoluteUrlPattern.test(path) || /^(?:data|blob):/i.test(path))
|
|
196
142
|
return path;
|
|
197
143
|
// Ensure path starts with a slash
|
|
198
|
-
|
|
144
|
+
let normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
199
145
|
if (bundledIconUrls[normalizedPath]) {
|
|
200
146
|
return bundledIconUrls[normalizedPath];
|
|
201
147
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getAssetUrl } from './fileUtils';
|
|
2
2
|
import { getFileTypeOf } from './fileKinds';
|
|
3
|
-
|
|
3
|
+
const UNORGANIZED_THRESHOLD = 50;
|
|
4
4
|
export function countFilteredItems(folder, filter) {
|
|
5
|
-
|
|
5
|
+
let count = 0;
|
|
6
6
|
if (folder.type === 'folder' && folder.children) {
|
|
7
|
-
for (
|
|
8
|
-
var item = _a[_i];
|
|
7
|
+
for (const item of folder.children) {
|
|
9
8
|
if (item.type === 'folder') {
|
|
10
9
|
count += countFilteredItems(item, filter);
|
|
11
10
|
}
|
|
@@ -17,7 +16,7 @@ export function countFilteredItems(folder, filter) {
|
|
|
17
16
|
return count;
|
|
18
17
|
}
|
|
19
18
|
export function getFolderIcon(folder, filter) {
|
|
20
|
-
|
|
19
|
+
const fileCount = folder.matchingFileCount || countFilteredItems(folder, filter);
|
|
21
20
|
if (fileCount === 0) {
|
|
22
21
|
return getAssetUrl('/icons/empty-folder.svg');
|
|
23
22
|
}
|
package/dist/utils/gridLayout.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Grid column count from the file browser panel width (Figma File Tile ~264px, 16px gap).
|
|
3
3
|
* At 1152px panel width → 4 columns; scales up to 6 on very wide panels.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
5
|
+
export const GRID_TILE_MIN_WIDTH_PX = 264;
|
|
6
|
+
export const GRID_GAP_PX = 16;
|
|
7
|
+
export const GRID_MAX_COLUMNS = 6;
|
|
8
8
|
/** Same rhythm for the recent-files strip (Figma 24px gap, ~3 cards at 1152px). */
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
9
|
+
export const RECENT_TILE_MIN_WIDTH_PX = 352;
|
|
10
|
+
export const RECENT_GAP_PX = 24;
|
|
11
|
+
export const RECENT_MAX_COLUMNS = 5;
|
|
12
12
|
function columnsForWidth(width, minTile, gap, maxColumns) {
|
|
13
13
|
if (width < 420)
|
|
14
14
|
return 1;
|
|
15
|
-
|
|
15
|
+
const columns = Math.floor((width + gap) / (minTile + gap));
|
|
16
16
|
return Math.min(maxColumns, Math.max(1, columns));
|
|
17
17
|
}
|
|
18
18
|
/** Main folder/file grid. */
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
/** Natural pixel size of a picture the preview has already decoded, keyed by its fetch URL. */
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
const MAX_CACHED_URLS = 64;
|
|
3
|
+
const naturalSizeByUrl = new Map();
|
|
15
4
|
export function rememberImageNaturalSize(url, width, height) {
|
|
16
5
|
if (!url || !width || !height)
|
|
17
6
|
return;
|
|
18
7
|
if (naturalSizeByUrl.has(url)) {
|
|
19
8
|
naturalSizeByUrl.delete(url);
|
|
20
9
|
}
|
|
21
|
-
naturalSizeByUrl.set(url, { width
|
|
10
|
+
naturalSizeByUrl.set(url, { width, height });
|
|
22
11
|
while (naturalSizeByUrl.size > MAX_CACHED_URLS) {
|
|
23
|
-
|
|
12
|
+
const oldest = naturalSizeByUrl.keys().next().value;
|
|
24
13
|
if (oldest)
|
|
25
14
|
naturalSizeByUrl.delete(oldest);
|
|
26
15
|
}
|
|
@@ -28,20 +17,20 @@ export function rememberImageNaturalSize(url, width, height) {
|
|
|
28
17
|
export function getCachedImageNaturalSize(url) {
|
|
29
18
|
if (!url)
|
|
30
19
|
return undefined;
|
|
31
|
-
|
|
32
|
-
return hit ?
|
|
20
|
+
const hit = naturalSizeByUrl.get(url);
|
|
21
|
+
return hit ? { ...hit } : undefined;
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
35
24
|
* The natural size of a picture the browser already holds decoded (shown before, in a tile or in this preview), found at once.
|
|
36
25
|
* A picture that is not in the browser's memory is not waited for: it starts loading and this returns nothing.
|
|
37
26
|
*/
|
|
38
27
|
export function probeDecodedImage(url) {
|
|
39
|
-
|
|
28
|
+
const known = getCachedImageNaturalSize(url);
|
|
40
29
|
if (known)
|
|
41
30
|
return known;
|
|
42
31
|
if (!url || typeof Image === 'undefined')
|
|
43
32
|
return undefined;
|
|
44
|
-
|
|
33
|
+
const probe = new Image();
|
|
45
34
|
probe.src = url;
|
|
46
35
|
if (probe.complete && probe.naturalWidth > 0 && probe.naturalHeight > 0) {
|
|
47
36
|
rememberImageNaturalSize(url, probe.naturalWidth, probe.naturalHeight);
|
|
@@ -49,27 +38,27 @@ export function probeDecodedImage(url) {
|
|
|
49
38
|
}
|
|
50
39
|
return undefined;
|
|
51
40
|
}
|
|
52
|
-
|
|
41
|
+
const inFlightByUrl = new Map();
|
|
53
42
|
/** Warm the decoder cache; resolves when decode finishes or the request fails. */
|
|
54
43
|
export function preloadImageUrl(url) {
|
|
55
44
|
if (!url)
|
|
56
45
|
return Promise.resolve();
|
|
57
|
-
|
|
46
|
+
const cached = naturalSizeByUrl.get(url);
|
|
58
47
|
if (cached)
|
|
59
48
|
return Promise.resolve();
|
|
60
|
-
|
|
49
|
+
const pending = inFlightByUrl.get(url);
|
|
61
50
|
if (pending)
|
|
62
51
|
return pending;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
img.onload =
|
|
52
|
+
const job = new Promise((resolve) => {
|
|
53
|
+
const img = new Image();
|
|
54
|
+
img.onload = () => {
|
|
66
55
|
if (img.naturalWidth && img.naturalHeight) {
|
|
67
56
|
rememberImageNaturalSize(url, img.naturalWidth, img.naturalHeight);
|
|
68
57
|
}
|
|
69
58
|
inFlightByUrl.delete(url);
|
|
70
59
|
resolve();
|
|
71
60
|
};
|
|
72
|
-
img.onerror =
|
|
61
|
+
img.onerror = () => {
|
|
73
62
|
inFlightByUrl.delete(url);
|
|
74
63
|
resolve();
|
|
75
64
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULTS = {
|
|
2
2
|
sideMargin: 24,
|
|
3
3
|
dialogHorizontalPad: 50,
|
|
4
4
|
headerBlock: 52,
|
|
@@ -12,18 +12,18 @@ var DEFAULTS = {
|
|
|
12
12
|
* Pictures are not upscaled beyond their natural size.
|
|
13
13
|
*/
|
|
14
14
|
export function computeImagePreviewModalFrame(naturalWidth, naturalHeight, insets) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
23
|
return {
|
|
24
|
-
width:
|
|
25
|
-
height:
|
|
26
|
-
pictureWidth
|
|
27
|
-
pictureHeight
|
|
24
|
+
width: `${cardWidth}px`,
|
|
25
|
+
height: `${pictureHeight + totalVerticalSpace}px`,
|
|
26
|
+
pictureWidth,
|
|
27
|
+
pictureHeight
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -9,15 +9,14 @@
|
|
|
9
9
|
* picture fades in (a picture that arrives long after the card was sized shows at once).
|
|
10
10
|
*/
|
|
11
11
|
/** How long a picture may take before the spinner shows ("more than a few seconds" in the request, round 26). */
|
|
12
|
-
export
|
|
12
|
+
export const IMAGE_SLOW_LOADER_DELAY_MS = 2000;
|
|
13
13
|
/** The card eases to the size of its picture for this long, the picture waits for the end of that move. */
|
|
14
|
-
export
|
|
14
|
+
export const IMAGE_FRAME_EASE_MS = 220;
|
|
15
15
|
/**
|
|
16
16
|
* How much longer the picture has to wait, once it has loaded, so that it appears after the card's move.
|
|
17
17
|
* 0 when the card reached its size long ago; never more than the move itself (a clock that went backwards).
|
|
18
18
|
*/
|
|
19
|
-
export function imageRevealDelayMs(frameSizedAtMs, nowMs, easeMs) {
|
|
20
|
-
|
|
21
|
-
var elapsedMs = nowMs - frameSizedAtMs;
|
|
19
|
+
export function imageRevealDelayMs(frameSizedAtMs, nowMs, easeMs = IMAGE_FRAME_EASE_MS) {
|
|
20
|
+
const elapsedMs = nowMs - frameSizedAtMs;
|
|
22
21
|
return Math.min(easeMs, Math.max(0, easeMs - elapsedMs));
|
|
23
22
|
}
|
|
@@ -4,36 +4,25 @@
|
|
|
4
4
|
* right-sized variant instead of the full-size original. Non-CDN URLs
|
|
5
5
|
* (localhost, blob:, external providers) pass through untouched.
|
|
6
6
|
*/
|
|
7
|
-
var __assign = (this && this.__assign) || function () {
|
|
8
|
-
__assign = Object.assign || function(t) {
|
|
9
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
-
s = arguments[i];
|
|
11
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
12
|
-
t[p] = s[p];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
return __assign.apply(this, arguments);
|
|
17
|
-
};
|
|
18
|
-
var _a;
|
|
19
7
|
/** Hosts allowed for transformation — keeps unique-transformation billing bounded. */
|
|
20
|
-
|
|
8
|
+
const TRANSFORM_HOSTS = (import.meta.env.PUBLIC_IMAGE_TRANSFORM_HOSTS ??
|
|
9
|
+
'static.widgetic.com,cdn.widgetic.com')
|
|
21
10
|
.split(',')
|
|
22
|
-
.map(
|
|
11
|
+
.map((host) => host.trim().toLowerCase())
|
|
23
12
|
.filter(Boolean);
|
|
24
|
-
|
|
13
|
+
const ENABLED = import.meta.env.PUBLIC_IMAGE_TRANSFORMS !== 'false';
|
|
25
14
|
function isTransformable(url) {
|
|
26
15
|
if (!ENABLED || !url)
|
|
27
16
|
return false;
|
|
28
17
|
if (url.startsWith('blob:') || url.startsWith('data:'))
|
|
29
18
|
return false;
|
|
30
19
|
try {
|
|
31
|
-
|
|
20
|
+
const parsed = new URL(url);
|
|
32
21
|
if (parsed.protocol !== 'https:')
|
|
33
22
|
return false;
|
|
34
23
|
return TRANSFORM_HOSTS.includes(parsed.hostname.toLowerCase());
|
|
35
24
|
}
|
|
36
|
-
catch
|
|
25
|
+
catch {
|
|
37
26
|
return false;
|
|
38
27
|
}
|
|
39
28
|
}
|
|
@@ -42,32 +31,30 @@ function isTransformable(url) {
|
|
|
42
31
|
* URL when transformation is disabled or the host is not allowlisted.
|
|
43
32
|
*/
|
|
44
33
|
export function buildTransformedUrl(url, options) {
|
|
45
|
-
|
|
46
|
-
var source = url !== null && url !== void 0 ? url : '';
|
|
34
|
+
const source = url ?? '';
|
|
47
35
|
if (!isTransformable(source))
|
|
48
36
|
return source;
|
|
49
|
-
|
|
37
|
+
const params = new URLSearchParams();
|
|
50
38
|
params.set('width', String(options.width));
|
|
51
39
|
if (options.height)
|
|
52
40
|
params.set('height', String(options.height));
|
|
53
41
|
if (options.fit)
|
|
54
42
|
params.set('fit', options.fit);
|
|
55
|
-
params.set('q', String(
|
|
43
|
+
params.set('q', String(options.quality ?? 75));
|
|
56
44
|
// format=auto lets Cloudflare negotiate AVIF/WebP from the Accept header.
|
|
57
45
|
params.set('format', 'auto');
|
|
58
|
-
|
|
59
|
-
return
|
|
46
|
+
const parsed = new URL(source);
|
|
47
|
+
return `${parsed.origin}/cdn-cgi/image?${params.toString()}/${encodeURIComponent(source)}`;
|
|
60
48
|
}
|
|
61
49
|
/**
|
|
62
50
|
* Builds a srcset across a fixed width ladder. Widths should come from a small
|
|
63
51
|
* allowlist — every unique width is billed as a separate transformation.
|
|
64
52
|
*/
|
|
65
|
-
export function buildImageSrcset(url, widths, options) {
|
|
66
|
-
|
|
67
|
-
var source = url !== null && url !== void 0 ? url : '';
|
|
53
|
+
export function buildImageSrcset(url, widths, options = {}) {
|
|
54
|
+
const source = url ?? '';
|
|
68
55
|
if (!isTransformable(source))
|
|
69
56
|
return undefined;
|
|
70
57
|
return widths
|
|
71
|
-
.map(
|
|
58
|
+
.map((width) => `${buildTransformedUrl(source, { ...options, width })} ${width}w`)
|
|
72
59
|
.join(', ');
|
|
73
60
|
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* The legacy Uploads folder (`folder_my_uploads`) is treated like any other folder — nothing here is reserved.
|
|
4
4
|
*/
|
|
5
5
|
export function itemMenuCapabilities(input) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return { canRename
|
|
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
13
|
}
|