@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
|
@@ -1,59 +1,3 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
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);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
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;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
-
if (ar || !(i in from)) {
|
|
51
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
-
};
|
|
57
1
|
import { deleteEntity, ensureCacheOwnerFromSessionHint, getCacheOwner, readAllEntitiesForKind, writeEntity } from '@widgetic/cache-layer';
|
|
58
2
|
/**
|
|
59
3
|
* The deletes the API has still to hear about.
|
|
@@ -72,18 +16,18 @@ import { deleteEntity, ensureCacheOwnerFromSessionHint, getCacheOwner, readAllEn
|
|
|
72
16
|
* row of another kind would be read by the wrong code.
|
|
73
17
|
*/
|
|
74
18
|
/** The kind of entity the records are saved under (the key is `{owner}:fileBrowserPendingDeletes:{uploadId}`). */
|
|
75
|
-
export
|
|
19
|
+
export const PENDING_DELETES_KIND = 'fileBrowserPendingDeletes';
|
|
76
20
|
/** After this many failed tries the API is taken to be unreachable for good, and the delete is given up. */
|
|
77
|
-
export
|
|
21
|
+
export const PENDING_DELETE_MAX_ATTEMPTS = 8;
|
|
78
22
|
/** How many deletes are sent at the same time. */
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
23
|
+
export const PENDING_DELETE_CONCURRENCY = 4;
|
|
24
|
+
const BACKOFF_FIRST_MS = 1000;
|
|
25
|
+
const BACKOFF_CAP_MS = 60_000;
|
|
82
26
|
/** The queue never wakes up more often than this to look at records that are not due yet. */
|
|
83
|
-
|
|
27
|
+
const MIN_WAKE_UP_MS = 250;
|
|
84
28
|
/** How long to wait before asking again, after `attempts` tries have failed: 1 s, 2 s, 4 s … never more than a minute. */
|
|
85
29
|
export function deleteBackoffMs(attempts) {
|
|
86
|
-
return Math.min(BACKOFF_FIRST_MS *
|
|
30
|
+
return Math.min(BACKOFF_FIRST_MS * 2 ** Math.max(0, attempts - 1), BACKOFF_CAP_MS);
|
|
87
31
|
}
|
|
88
32
|
/**
|
|
89
33
|
* What an HTTP answer means for a delete. 404 and 410 mean the upload is already gone, which is what was wanted. The other
|
|
@@ -104,179 +48,104 @@ export function classifyDeleteStatus(status) {
|
|
|
104
48
|
return 'ok';
|
|
105
49
|
}
|
|
106
50
|
export function createMemoryPendingDeleteStore() {
|
|
107
|
-
|
|
51
|
+
const records = new Map();
|
|
108
52
|
return {
|
|
109
|
-
list
|
|
110
|
-
return
|
|
111
|
-
return __generator(this, function (_a) {
|
|
112
|
-
return [2 /*return*/, __spreadArray([], records.values(), true).map(function (record) { return (__assign({}, record)); })];
|
|
113
|
-
});
|
|
114
|
-
});
|
|
53
|
+
async list() {
|
|
54
|
+
return [...records.values()].map((record) => ({ ...record }));
|
|
115
55
|
},
|
|
116
|
-
put
|
|
117
|
-
|
|
118
|
-
return __generator(this, function (_a) {
|
|
119
|
-
records.set(record.uploadId, __assign({}, record));
|
|
120
|
-
return [2 /*return*/];
|
|
121
|
-
});
|
|
122
|
-
});
|
|
56
|
+
async put(record) {
|
|
57
|
+
records.set(record.uploadId, { ...record });
|
|
123
58
|
},
|
|
124
|
-
remove
|
|
125
|
-
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
records.delete(uploadId);
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
});
|
|
130
|
-
});
|
|
59
|
+
async remove(uploadId) {
|
|
60
|
+
records.delete(uploadId);
|
|
131
61
|
}
|
|
132
62
|
};
|
|
133
63
|
}
|
|
134
64
|
function isPendingUploadDelete(value) {
|
|
135
65
|
if (!value || typeof value !== 'object')
|
|
136
66
|
return false;
|
|
137
|
-
|
|
67
|
+
const record = value;
|
|
138
68
|
return typeof record.uploadId === 'string' && typeof record.attempts === 'number' && typeof record.nextAttemptAt === 'number';
|
|
139
69
|
}
|
|
140
70
|
/** The records of one owner (one signed-in person), kept in Dexie through the entity store of the cache layer. */
|
|
141
71
|
export function createCacheLayerPendingDeleteStore(ownerId) {
|
|
142
72
|
return {
|
|
143
|
-
list
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return __generator(this, function (_a) {
|
|
147
|
-
switch (_a.label) {
|
|
148
|
-
case 0: return [4 /*yield*/, readAllEntitiesForKind(ownerId, PENDING_DELETES_KIND)];
|
|
149
|
-
case 1:
|
|
150
|
-
all = _a.sent();
|
|
151
|
-
return [2 /*return*/, Object.values(all).filter(isPendingUploadDelete)];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
73
|
+
async list() {
|
|
74
|
+
const all = await readAllEntitiesForKind(ownerId, PENDING_DELETES_KIND);
|
|
75
|
+
return Object.values(all).filter(isPendingUploadDelete);
|
|
155
76
|
},
|
|
156
|
-
put
|
|
157
|
-
|
|
158
|
-
return __generator(this, function (_a) {
|
|
159
|
-
switch (_a.label) {
|
|
160
|
-
case 0: return [4 /*yield*/, writeEntity(ownerId, PENDING_DELETES_KIND, record.uploadId, record)];
|
|
161
|
-
case 1:
|
|
162
|
-
_a.sent();
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
77
|
+
async put(record) {
|
|
78
|
+
await writeEntity(ownerId, PENDING_DELETES_KIND, record.uploadId, record);
|
|
167
79
|
},
|
|
168
|
-
remove
|
|
169
|
-
|
|
170
|
-
return __generator(this, function (_a) {
|
|
171
|
-
switch (_a.label) {
|
|
172
|
-
case 0: return [4 /*yield*/, deleteEntity(ownerId, PENDING_DELETES_KIND, uploadId)];
|
|
173
|
-
case 1:
|
|
174
|
-
_a.sent();
|
|
175
|
-
return [2 /*return*/];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
80
|
+
async remove(uploadId) {
|
|
81
|
+
await deleteEntity(ownerId, PENDING_DELETES_KIND, uploadId);
|
|
179
82
|
}
|
|
180
83
|
};
|
|
181
84
|
}
|
|
182
85
|
export function createPendingDeleteQueue(options) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var wakeUp = null;
|
|
86
|
+
const { store } = options;
|
|
87
|
+
const now = options.now ?? (() => Date.now());
|
|
88
|
+
const maxAttempts = options.maxAttempts ?? PENDING_DELETE_MAX_ATTEMPTS;
|
|
89
|
+
const concurrency = Math.max(1, options.concurrency ?? PENDING_DELETE_CONCURRENCY);
|
|
90
|
+
const schedule = options.schedule ?? ((callback, delayMs) => setTimeout(callback, delayMs));
|
|
91
|
+
const cancel = options.cancel ?? ((handle) => clearTimeout(handle));
|
|
92
|
+
let running = null;
|
|
93
|
+
let passRequested = false;
|
|
94
|
+
let wakeUp = null;
|
|
193
95
|
// What the timer runs again: the latest processor and hooks anyone gave.
|
|
194
|
-
|
|
195
|
-
|
|
96
|
+
let lastProcess = null;
|
|
97
|
+
let lastHooks = {};
|
|
196
98
|
function clearWakeUp() {
|
|
197
99
|
if (wakeUp !== null)
|
|
198
100
|
cancel(wakeUp);
|
|
199
101
|
wakeUp = null;
|
|
200
102
|
}
|
|
201
|
-
function settleRecord(record, process, hooks) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return [2 /*return*/];
|
|
224
|
-
case 5:
|
|
225
|
-
message = (_b = attempt.message) !== null && _b !== void 0 ? _b : '';
|
|
226
|
-
attempts = record.attempts + 1;
|
|
227
|
-
if (!(attempt.result === 'permanent' || attempts >= maxAttempts)) return [3 /*break*/, 7];
|
|
228
|
-
return [4 /*yield*/, store.remove(record.uploadId)];
|
|
229
|
-
case 6:
|
|
230
|
-
_d.sent();
|
|
231
|
-
console.warn("[FileBrowser] Giving up on deleting \"".concat(record.name, "\" (").concat(attempt.result, ", after ").concat(attempts, " tries): ").concat(message));
|
|
232
|
-
(_c = hooks.onGaveUp) === null || _c === void 0 ? void 0 : _c.call(hooks, record, message);
|
|
233
|
-
return [2 /*return*/];
|
|
234
|
-
case 7: return [4 /*yield*/, store.put(__assign(__assign({}, record), { attempts: attempts, nextAttemptAt: now() + deleteBackoffMs(attempts), lastError: message || null }))];
|
|
235
|
-
case 8:
|
|
236
|
-
_d.sent();
|
|
237
|
-
return [2 /*return*/];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
103
|
+
async function settleRecord(record, process, hooks) {
|
|
104
|
+
let attempt;
|
|
105
|
+
try {
|
|
106
|
+
attempt = await process(record);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
attempt = { result: 'retry', message: error instanceof Error ? error.message : String(error) };
|
|
110
|
+
}
|
|
111
|
+
if (attempt.result === 'ok') {
|
|
112
|
+
await store.remove(record.uploadId);
|
|
113
|
+
hooks.onDeleted?.(record);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const message = attempt.message ?? '';
|
|
117
|
+
const attempts = record.attempts + 1;
|
|
118
|
+
if (attempt.result === 'permanent' || attempts >= maxAttempts) {
|
|
119
|
+
await store.remove(record.uploadId);
|
|
120
|
+
console.warn(`[FileBrowser] Giving up on deleting "${record.name}" (${attempt.result}, after ${attempts} tries): ${message}`);
|
|
121
|
+
hooks.onGaveUp?.(record, message);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await store.put({ ...record, attempts, nextAttemptAt: now() + deleteBackoffMs(attempts), lastError: message || null });
|
|
241
125
|
}
|
|
242
|
-
function runOnce(process, hooks) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (waiting.length > 0) {
|
|
264
|
-
earliest = Math.min.apply(Math, waiting.map(function (record) { return record.nextAttemptAt; }));
|
|
265
|
-
clearWakeUp();
|
|
266
|
-
wakeUp = schedule(function () {
|
|
267
|
-
wakeUp = null;
|
|
268
|
-
if (lastProcess)
|
|
269
|
-
void drain(lastProcess, lastHooks);
|
|
270
|
-
}, Math.max(earliest - now(), MIN_WAKE_UP_MS));
|
|
271
|
-
}
|
|
272
|
-
return [2 /*return*/];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
126
|
+
async function runOnce(process, hooks) {
|
|
127
|
+
for (;;) {
|
|
128
|
+
const due = (await store.list())
|
|
129
|
+
.filter((record) => record.nextAttemptAt <= now())
|
|
130
|
+
.sort((a, b) => a.createdAt - b.createdAt)
|
|
131
|
+
.slice(0, concurrency);
|
|
132
|
+
if (due.length === 0)
|
|
133
|
+
break;
|
|
134
|
+
await Promise.all(due.map((record) => settleRecord(record, process, hooks)));
|
|
135
|
+
}
|
|
136
|
+
// Records that failed and wait for their turn: wake up when the first one is due.
|
|
137
|
+
const waiting = await store.list();
|
|
138
|
+
if (waiting.length > 0) {
|
|
139
|
+
const earliest = Math.min(...waiting.map((record) => record.nextAttemptAt));
|
|
140
|
+
clearWakeUp();
|
|
141
|
+
wakeUp = schedule(() => {
|
|
142
|
+
wakeUp = null;
|
|
143
|
+
if (lastProcess)
|
|
144
|
+
void drain(lastProcess, lastHooks);
|
|
145
|
+
}, Math.max(earliest - now(), MIN_WAKE_UP_MS));
|
|
146
|
+
}
|
|
276
147
|
}
|
|
277
|
-
function drain(process, hooks) {
|
|
278
|
-
var _this = this;
|
|
279
|
-
if (hooks === void 0) { hooks = {}; }
|
|
148
|
+
function drain(process, hooks = {}) {
|
|
280
149
|
lastProcess = process;
|
|
281
150
|
lastHooks = hooks;
|
|
282
151
|
if (running) {
|
|
@@ -285,103 +154,58 @@ export function createPendingDeleteQueue(options) {
|
|
|
285
154
|
return running;
|
|
286
155
|
}
|
|
287
156
|
clearWakeUp();
|
|
288
|
-
running = (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (passRequested) return [3 /*break*/, 1];
|
|
303
|
-
_a.label = 4;
|
|
304
|
-
case 4: return [3 /*break*/, 7];
|
|
305
|
-
case 5:
|
|
306
|
-
error_2 = _a.sent();
|
|
307
|
-
console.warn('[FileBrowser] The queue of deletes stopped:', error_2);
|
|
308
|
-
return [3 /*break*/, 7];
|
|
309
|
-
case 6:
|
|
310
|
-
running = null;
|
|
311
|
-
return [7 /*endfinally*/];
|
|
312
|
-
case 7: return [2 /*return*/];
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}); })();
|
|
157
|
+
running = (async () => {
|
|
158
|
+
try {
|
|
159
|
+
do {
|
|
160
|
+
passRequested = false;
|
|
161
|
+
await runOnce(lastProcess ?? process, lastHooks);
|
|
162
|
+
} while (passRequested);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.warn('[FileBrowser] The queue of deletes stopped:', error);
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
running = null;
|
|
169
|
+
}
|
|
170
|
+
})();
|
|
316
171
|
return running;
|
|
317
172
|
}
|
|
318
173
|
return {
|
|
319
|
-
enqueue
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (!(_i < uploads_1.length)) return [3 /*break*/, 5];
|
|
334
|
-
upload = uploads_1[_i];
|
|
335
|
-
if (existing.has(upload.uploadId))
|
|
336
|
-
return [3 /*break*/, 4];
|
|
337
|
-
existing.add(upload.uploadId);
|
|
338
|
-
return [4 /*yield*/, store.put({
|
|
339
|
-
uploadId: upload.uploadId,
|
|
340
|
-
name: upload.name,
|
|
341
|
-
attempts: 0,
|
|
342
|
-
nextAttemptAt: createdAt,
|
|
343
|
-
createdAt: createdAt,
|
|
344
|
-
lastError: null
|
|
345
|
-
})];
|
|
346
|
-
case 3:
|
|
347
|
-
_b.sent();
|
|
348
|
-
_b.label = 4;
|
|
349
|
-
case 4:
|
|
350
|
-
_i++;
|
|
351
|
-
return [3 /*break*/, 2];
|
|
352
|
-
case 5: return [2 /*return*/];
|
|
353
|
-
}
|
|
174
|
+
async enqueue(uploads) {
|
|
175
|
+
const existing = new Set((await store.list()).map((record) => record.uploadId));
|
|
176
|
+
const createdAt = now();
|
|
177
|
+
for (const upload of uploads) {
|
|
178
|
+
if (existing.has(upload.uploadId))
|
|
179
|
+
continue;
|
|
180
|
+
existing.add(upload.uploadId);
|
|
181
|
+
await store.put({
|
|
182
|
+
uploadId: upload.uploadId,
|
|
183
|
+
name: upload.name,
|
|
184
|
+
attempts: 0,
|
|
185
|
+
nextAttemptAt: createdAt,
|
|
186
|
+
createdAt,
|
|
187
|
+
lastError: null
|
|
354
188
|
});
|
|
355
|
-
}
|
|
189
|
+
}
|
|
356
190
|
},
|
|
357
|
-
pendingIds
|
|
358
|
-
return
|
|
359
|
-
var _a;
|
|
360
|
-
return __generator(this, function (_b) {
|
|
361
|
-
switch (_b.label) {
|
|
362
|
-
case 0:
|
|
363
|
-
_a = Set.bind;
|
|
364
|
-
return [4 /*yield*/, store.list()];
|
|
365
|
-
case 1: return [2 /*return*/, new (_a.apply(Set, [void 0, (_b.sent()).map(function (record) { return record.uploadId; })]))()];
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
});
|
|
191
|
+
async pendingIds() {
|
|
192
|
+
return new Set((await store.list()).map((record) => record.uploadId));
|
|
369
193
|
},
|
|
370
|
-
drain
|
|
194
|
+
drain,
|
|
371
195
|
stop: clearWakeUp
|
|
372
196
|
};
|
|
373
197
|
}
|
|
374
198
|
// ----------------------------------------------------------------------------------------------------------------
|
|
375
199
|
// The queue of this page
|
|
376
|
-
|
|
377
|
-
|
|
200
|
+
let sharedQueue = null;
|
|
201
|
+
let sharedQueueOwner;
|
|
378
202
|
/**
|
|
379
203
|
* The queue of the signed-in person (the cache owner). Without an owner there is nowhere to keep the records for the next
|
|
380
204
|
* visit, so they are kept in memory: the files still leave the screen at once and the deletes are still retried, but a reload
|
|
381
205
|
* before the API answers forgets them.
|
|
382
206
|
*/
|
|
383
207
|
export function getPendingUploadDeleteQueue() {
|
|
384
|
-
|
|
208
|
+
let ownerId = null;
|
|
385
209
|
try {
|
|
386
210
|
ensureCacheOwnerFromSessionHint();
|
|
387
211
|
ownerId = getCacheOwner();
|
|
@@ -390,7 +214,7 @@ export function getPendingUploadDeleteQueue() {
|
|
|
390
214
|
console.warn('[FileBrowser] No cache owner for the queue of deletes; keeping it in memory:', error);
|
|
391
215
|
}
|
|
392
216
|
if (!sharedQueue || sharedQueueOwner !== ownerId) {
|
|
393
|
-
sharedQueue
|
|
217
|
+
sharedQueue?.stop();
|
|
394
218
|
sharedQueue = createPendingDeleteQueue({
|
|
395
219
|
store: ownerId ? createCacheLayerPendingDeleteStore(ownerId) : createMemoryPendingDeleteStore()
|
|
396
220
|
});
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
export function previewKeyAction(key, direction) {
|
|
10
10
|
if (key !== 'ArrowLeft' && key !== 'ArrowRight')
|
|
11
11
|
return null;
|
|
12
|
-
|
|
12
|
+
const keyPointsToStart = (key === 'ArrowLeft') === (direction !== 'rtl');
|
|
13
13
|
return keyPointsToStart ? 'previous' : 'next';
|
|
14
14
|
}
|
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
/** Previewable items in display order (folders omitted). */
|
|
2
2
|
export function previewNavigationFiles(items) {
|
|
3
|
-
return items.filter(
|
|
3
|
+
return items.filter((item) => item.type === 'file');
|
|
4
4
|
}
|
|
5
5
|
export function previewNavigationIndex(list, fileId) {
|
|
6
|
-
return list.findIndex(
|
|
6
|
+
return list.findIndex((item) => item.id === fileId);
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Next file in the preview list, wrapping at both ends. Skips missing ids when provided.
|
|
10
10
|
* Returns null when there is no navigable file (empty list or every peer missing).
|
|
11
11
|
*/
|
|
12
|
-
export function stepPreviewNavigation(list, currentId, direction, missingIds) {
|
|
13
|
-
|
|
14
|
-
var files = previewNavigationFiles(list);
|
|
12
|
+
export function stepPreviewNavigation(list, currentId, direction, missingIds = new Set()) {
|
|
13
|
+
const files = previewNavigationFiles(list);
|
|
15
14
|
if (files.length <= 1)
|
|
16
15
|
return null;
|
|
17
|
-
|
|
16
|
+
let index = previewNavigationIndex(files, currentId);
|
|
18
17
|
if (index < 0)
|
|
19
18
|
index = 0;
|
|
20
|
-
|
|
21
|
-
for (
|
|
19
|
+
const total = files.length;
|
|
20
|
+
for (let step = 0; step < total; step++) {
|
|
22
21
|
if (direction === 'next') {
|
|
23
22
|
index = (index + 1) % total;
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
25
|
index = index > 0 ? index - 1 : total - 1;
|
|
27
26
|
}
|
|
28
|
-
|
|
27
|
+
const candidate = files[index];
|
|
29
28
|
if (candidate.id !== currentId && !missingIds.has(candidate.id)) {
|
|
30
29
|
return candidate;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
// Wrapped full cycle with only the current file available
|
|
34
|
-
|
|
33
|
+
const current = files.find((f) => f.id === currentId);
|
|
35
34
|
return current && !missingIds.has(current.id) ? current : null;
|
|
36
35
|
}
|
|
37
|
-
export function hasPreviewNavigation(list, missingIds) {
|
|
38
|
-
|
|
39
|
-
var files = previewNavigationFiles(list).filter(function (f) { return !missingIds.has(f.id); });
|
|
36
|
+
export function hasPreviewNavigation(list, missingIds = new Set()) {
|
|
37
|
+
const files = previewNavigationFiles(list).filter((f) => !missingIds.has(f.id));
|
|
40
38
|
return files.length > 1;
|
|
41
39
|
}
|
|
@@ -3,18 +3,15 @@ import { getFileTypeOf } from './fileKinds';
|
|
|
3
3
|
export function isSamePreviewLane(file, candidate) {
|
|
4
4
|
if (candidate.type !== 'file')
|
|
5
5
|
return false;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const kind = getFileTypeOf(file);
|
|
7
|
+
const other = getFileTypeOf(candidate);
|
|
8
8
|
if (kind === 'image' || kind === 'svg')
|
|
9
9
|
return other === 'image' || other === 'svg';
|
|
10
10
|
return other === kind;
|
|
11
11
|
}
|
|
12
|
-
export function countPreviewNavigationPeers(files, current, missingIds) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
!missingIds.has(item.id) &&
|
|
18
|
-
isSamePreviewLane(current, item);
|
|
19
|
-
}).length;
|
|
12
|
+
export function countPreviewNavigationPeers(files, current, missingIds = new Set()) {
|
|
13
|
+
return files.filter((item) => item.type === 'file' &&
|
|
14
|
+
item.id !== current.id &&
|
|
15
|
+
!missingIds.has(item.id) &&
|
|
16
|
+
isSamePreviewLane(current, item)).length;
|
|
20
17
|
}
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
1
|
/**
|
|
11
2
|
* Stable recent-files list: newest first, one row per resolved picture URL (fallback: file id).
|
|
12
3
|
*/
|
|
13
4
|
export function buildDeduplicatedRecentFiles(files, resolveUrl, limit) {
|
|
14
5
|
if (limit <= 0 || files.length === 0)
|
|
15
6
|
return [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var dedupeKey = urlKey || file.id;
|
|
7
|
+
const sorted = [...files].sort((a, b) => new Date(b.modified || 0).getTime() - new Date(a.modified || 0).getTime());
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
const result = [];
|
|
10
|
+
for (const file of sorted) {
|
|
11
|
+
const urlKey = file.url ? resolveUrl(file) : file.id;
|
|
12
|
+
const dedupeKey = urlKey || file.id;
|
|
23
13
|
if (seen.has(dedupeKey))
|
|
24
14
|
continue;
|
|
25
15
|
seen.add(dedupeKey);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { recentGridColumnsForWidth } from './gridLayout';
|
|
2
2
|
/** Breakpoints shared by the main grid and the Recent strip (Figma desktop / tablet). */
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export const RECENT_FILES_DESKTOP_BREAKPOINT = 1156;
|
|
4
|
+
export const RECENT_FILES_TABLET_BREAKPOINT = 744;
|
|
5
5
|
/**
|
|
6
6
|
* How many recent file cards to prepare and show for a container width.
|
|
7
7
|
* One rule for FileBrowser and RecentFiles so the strip matches `getRecentFiles()`.
|