@widgetic/file-browser 0.5.46 → 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 +2 -6
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +249 -32
- package/dist/components/core/FileUploader.svelte +134 -54
- package/dist/components/core/RecentFiles.svelte +74 -19
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- 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 +15 -1
- package/dist/i18n/messages.js +17 -3
- 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 +1 -1
- 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 -333
- 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.d.ts +13 -0
- package/dist/utils/uploadPanelDismiss.js +11 -0
- 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
|
@@ -0,0 +1,400 @@
|
|
|
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
|
+
import { deleteEntity, ensureCacheOwnerFromSessionHint, getCacheOwner, readAllEntitiesForKind, writeEntity } from '@widgetic/cache-layer';
|
|
58
|
+
/**
|
|
59
|
+
* The deletes the API has still to hear about.
|
|
60
|
+
*
|
|
61
|
+
* When the visitor deletes files they leave the screen at once; the API is told afterwards, in the background. This queue
|
|
62
|
+
* is what makes "afterwards" safe: every upload that was taken off the screen is written down in Dexie (the local database
|
|
63
|
+
* of `@widgetic/cache-layer`) before anything is sent, one record per upload, and is only forgotten once the API has
|
|
64
|
+
* answered. So a reload, a closed tab or a network that comes and goes neither brings the files back nor loses the delete:
|
|
65
|
+
* - the next time the File Browser opens it finishes the queue, and does not list a file whose delete is still waiting;
|
|
66
|
+
* - a network error, a 5xx or a 401 is tried again, a little later each time (1 s, 2 s, 4 s … up to a minute);
|
|
67
|
+
* - an answer that will never change (the API says "not allowed", say) ends the record and tells the File Browser, which
|
|
68
|
+
* puts the file back and says so.
|
|
69
|
+
*
|
|
70
|
+
* It keeps its own kind of record next to the others in the entity store rather than using the shared mutation outbox of the
|
|
71
|
+
* cache layer: that outbox hands every row, whatever its kind, to the one processor that drains it (the brand kit's), so a
|
|
72
|
+
* row of another kind would be read by the wrong code.
|
|
73
|
+
*/
|
|
74
|
+
/** The kind of entity the records are saved under (the key is `{owner}:fileBrowserPendingDeletes:{uploadId}`). */
|
|
75
|
+
export var PENDING_DELETES_KIND = 'fileBrowserPendingDeletes';
|
|
76
|
+
/** After this many failed tries the API is taken to be unreachable for good, and the delete is given up. */
|
|
77
|
+
export var PENDING_DELETE_MAX_ATTEMPTS = 8;
|
|
78
|
+
/** How many deletes are sent at the same time. */
|
|
79
|
+
export var PENDING_DELETE_CONCURRENCY = 4;
|
|
80
|
+
var BACKOFF_FIRST_MS = 1000;
|
|
81
|
+
var BACKOFF_CAP_MS = 60000;
|
|
82
|
+
/** The queue never wakes up more often than this to look at records that are not due yet. */
|
|
83
|
+
var MIN_WAKE_UP_MS = 250;
|
|
84
|
+
/** How long to wait before asking again, after `attempts` tries have failed: 1 s, 2 s, 4 s … never more than a minute. */
|
|
85
|
+
export function deleteBackoffMs(attempts) {
|
|
86
|
+
return Math.min(BACKOFF_FIRST_MS * Math.pow(2, Math.max(0, attempts - 1)), BACKOFF_CAP_MS);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What an HTTP answer means for a delete. 404 and 410 mean the upload is already gone, which is what was wanted. The other
|
|
90
|
+
* 4xx answers (not allowed, malformed) will not change by asking again; 401 (the session is being renewed), 408, 425, 429 and
|
|
91
|
+
* every 5xx will. No status at all is a network error: the same.
|
|
92
|
+
*/
|
|
93
|
+
export function classifyDeleteStatus(status) {
|
|
94
|
+
if (status === undefined || status === 0)
|
|
95
|
+
return 'retry';
|
|
96
|
+
if (status === 404 || status === 410)
|
|
97
|
+
return 'ok';
|
|
98
|
+
if (status === 401 || status === 408 || status === 425 || status === 429)
|
|
99
|
+
return 'retry';
|
|
100
|
+
if (status >= 500)
|
|
101
|
+
return 'retry';
|
|
102
|
+
if (status >= 400)
|
|
103
|
+
return 'permanent';
|
|
104
|
+
return 'ok';
|
|
105
|
+
}
|
|
106
|
+
export function createMemoryPendingDeleteStore() {
|
|
107
|
+
var records = new Map();
|
|
108
|
+
return {
|
|
109
|
+
list: function () {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
return [2 /*return*/, __spreadArray([], records.values(), true).map(function (record) { return (__assign({}, record)); })];
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
put: function (record) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
records.set(record.uploadId, __assign({}, record));
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
remove: function (uploadId) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
records.delete(uploadId);
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function isPendingUploadDelete(value) {
|
|
135
|
+
if (!value || typeof value !== 'object')
|
|
136
|
+
return false;
|
|
137
|
+
var record = value;
|
|
138
|
+
return typeof record.uploadId === 'string' && typeof record.attempts === 'number' && typeof record.nextAttemptAt === 'number';
|
|
139
|
+
}
|
|
140
|
+
/** The records of one owner (one signed-in person), kept in Dexie through the entity store of the cache layer. */
|
|
141
|
+
export function createCacheLayerPendingDeleteStore(ownerId) {
|
|
142
|
+
return {
|
|
143
|
+
list: function () {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var all;
|
|
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
|
+
});
|
|
155
|
+
},
|
|
156
|
+
put: function (record) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
+
});
|
|
167
|
+
},
|
|
168
|
+
remove: function (uploadId) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function createPendingDeleteQueue(options) {
|
|
183
|
+
var _a, _b, _c, _d, _e;
|
|
184
|
+
var store = options.store;
|
|
185
|
+
var now = (_a = options.now) !== null && _a !== void 0 ? _a : (function () { return Date.now(); });
|
|
186
|
+
var maxAttempts = (_b = options.maxAttempts) !== null && _b !== void 0 ? _b : PENDING_DELETE_MAX_ATTEMPTS;
|
|
187
|
+
var concurrency = Math.max(1, (_c = options.concurrency) !== null && _c !== void 0 ? _c : PENDING_DELETE_CONCURRENCY);
|
|
188
|
+
var schedule = (_d = options.schedule) !== null && _d !== void 0 ? _d : (function (callback, delayMs) { return setTimeout(callback, delayMs); });
|
|
189
|
+
var cancel = (_e = options.cancel) !== null && _e !== void 0 ? _e : (function (handle) { return clearTimeout(handle); });
|
|
190
|
+
var running = null;
|
|
191
|
+
var passRequested = false;
|
|
192
|
+
var wakeUp = null;
|
|
193
|
+
// What the timer runs again: the latest processor and hooks anyone gave.
|
|
194
|
+
var lastProcess = null;
|
|
195
|
+
var lastHooks = {};
|
|
196
|
+
function clearWakeUp() {
|
|
197
|
+
if (wakeUp !== null)
|
|
198
|
+
cancel(wakeUp);
|
|
199
|
+
wakeUp = null;
|
|
200
|
+
}
|
|
201
|
+
function settleRecord(record, process, hooks) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var attempt, error_1, message, attempts;
|
|
204
|
+
var _a, _b, _c;
|
|
205
|
+
return __generator(this, function (_d) {
|
|
206
|
+
switch (_d.label) {
|
|
207
|
+
case 0:
|
|
208
|
+
_d.trys.push([0, 2, , 3]);
|
|
209
|
+
return [4 /*yield*/, process(record)];
|
|
210
|
+
case 1:
|
|
211
|
+
attempt = _d.sent();
|
|
212
|
+
return [3 /*break*/, 3];
|
|
213
|
+
case 2:
|
|
214
|
+
error_1 = _d.sent();
|
|
215
|
+
attempt = { result: 'retry', message: error_1 instanceof Error ? error_1.message : String(error_1) };
|
|
216
|
+
return [3 /*break*/, 3];
|
|
217
|
+
case 3:
|
|
218
|
+
if (!(attempt.result === 'ok')) return [3 /*break*/, 5];
|
|
219
|
+
return [4 /*yield*/, store.remove(record.uploadId)];
|
|
220
|
+
case 4:
|
|
221
|
+
_d.sent();
|
|
222
|
+
(_a = hooks.onDeleted) === null || _a === void 0 ? void 0 : _a.call(hooks, record);
|
|
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
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function runOnce(process, hooks) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
+
var due, waiting, earliest;
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0: return [4 /*yield*/, store.list()];
|
|
248
|
+
case 1:
|
|
249
|
+
due = (_a.sent())
|
|
250
|
+
.filter(function (record) { return record.nextAttemptAt <= now(); })
|
|
251
|
+
.sort(function (a, b) { return a.createdAt - b.createdAt; })
|
|
252
|
+
.slice(0, concurrency);
|
|
253
|
+
if (due.length === 0)
|
|
254
|
+
return [3 /*break*/, 4];
|
|
255
|
+
return [4 /*yield*/, Promise.all(due.map(function (record) { return settleRecord(record, process, hooks); }))];
|
|
256
|
+
case 2:
|
|
257
|
+
_a.sent();
|
|
258
|
+
_a.label = 3;
|
|
259
|
+
case 3: return [3 /*break*/, 0];
|
|
260
|
+
case 4: return [4 /*yield*/, store.list()];
|
|
261
|
+
case 5:
|
|
262
|
+
waiting = _a.sent();
|
|
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
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function drain(process, hooks) {
|
|
278
|
+
var _this = this;
|
|
279
|
+
if (hooks === void 0) { hooks = {}; }
|
|
280
|
+
lastProcess = process;
|
|
281
|
+
lastHooks = hooks;
|
|
282
|
+
if (running) {
|
|
283
|
+
// Something was written down while the run was finishing: it makes one more pass before it ends.
|
|
284
|
+
passRequested = true;
|
|
285
|
+
return running;
|
|
286
|
+
}
|
|
287
|
+
clearWakeUp();
|
|
288
|
+
running = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
289
|
+
var error_2;
|
|
290
|
+
return __generator(this, function (_a) {
|
|
291
|
+
switch (_a.label) {
|
|
292
|
+
case 0:
|
|
293
|
+
_a.trys.push([0, 5, 6, 7]);
|
|
294
|
+
_a.label = 1;
|
|
295
|
+
case 1:
|
|
296
|
+
passRequested = false;
|
|
297
|
+
return [4 /*yield*/, runOnce(lastProcess !== null && lastProcess !== void 0 ? lastProcess : process, lastHooks)];
|
|
298
|
+
case 2:
|
|
299
|
+
_a.sent();
|
|
300
|
+
_a.label = 3;
|
|
301
|
+
case 3:
|
|
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
|
+
}); })();
|
|
316
|
+
return running;
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
enqueue: function (uploads) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
321
|
+
var existing, _a, createdAt, _i, uploads_1, upload;
|
|
322
|
+
return __generator(this, function (_b) {
|
|
323
|
+
switch (_b.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
_a = Set.bind;
|
|
326
|
+
return [4 /*yield*/, store.list()];
|
|
327
|
+
case 1:
|
|
328
|
+
existing = new (_a.apply(Set, [void 0, (_b.sent()).map(function (record) { return record.uploadId; })]))();
|
|
329
|
+
createdAt = now();
|
|
330
|
+
_i = 0, uploads_1 = uploads;
|
|
331
|
+
_b.label = 2;
|
|
332
|
+
case 2:
|
|
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
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
pendingIds: function () {
|
|
358
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
+
});
|
|
369
|
+
},
|
|
370
|
+
drain: drain,
|
|
371
|
+
stop: clearWakeUp
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
// ----------------------------------------------------------------------------------------------------------------
|
|
375
|
+
// The queue of this page
|
|
376
|
+
var sharedQueue = null;
|
|
377
|
+
var sharedQueueOwner;
|
|
378
|
+
/**
|
|
379
|
+
* The queue of the signed-in person (the cache owner). Without an owner there is nowhere to keep the records for the next
|
|
380
|
+
* 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
|
+
* before the API answers forgets them.
|
|
382
|
+
*/
|
|
383
|
+
export function getPendingUploadDeleteQueue() {
|
|
384
|
+
var ownerId = null;
|
|
385
|
+
try {
|
|
386
|
+
ensureCacheOwnerFromSessionHint();
|
|
387
|
+
ownerId = getCacheOwner();
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
console.warn('[FileBrowser] No cache owner for the queue of deletes; keeping it in memory:', error);
|
|
391
|
+
}
|
|
392
|
+
if (!sharedQueue || sharedQueueOwner !== ownerId) {
|
|
393
|
+
sharedQueue === null || sharedQueue === void 0 ? void 0 : sharedQueue.stop();
|
|
394
|
+
sharedQueue = createPendingDeleteQueue({
|
|
395
|
+
store: ownerId ? createCacheLayerPendingDeleteStore(ownerId) : createMemoryPendingDeleteStore()
|
|
396
|
+
});
|
|
397
|
+
sharedQueueOwner = ownerId;
|
|
398
|
+
}
|
|
399
|
+
return sharedQueue;
|
|
400
|
+
}
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
export function previewKeyAction(key, direction) {
|
|
10
10
|
if (key !== 'ArrowLeft' && key !== 'ArrowRight')
|
|
11
11
|
return null;
|
|
12
|
-
|
|
12
|
+
var keyPointsToStart = (key === 'ArrowLeft') === (direction !== 'rtl');
|
|
13
13
|
return keyPointsToStart ? 'previous' : 'next';
|
|
14
14
|
}
|
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
/** Previewable items in display order (folders omitted). */
|
|
2
2
|
export function previewNavigationFiles(items) {
|
|
3
|
-
return items.filter((item)
|
|
3
|
+
return items.filter(function (item) { return item.type === 'file'; });
|
|
4
4
|
}
|
|
5
5
|
export function previewNavigationIndex(list, fileId) {
|
|
6
|
-
return list.findIndex((item)
|
|
6
|
+
return list.findIndex(function (item) { return 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
|
-
|
|
12
|
+
export function stepPreviewNavigation(list, currentId, direction, missingIds) {
|
|
13
|
+
if (missingIds === void 0) { missingIds = new Set(); }
|
|
14
|
+
var files = previewNavigationFiles(list);
|
|
14
15
|
if (files.length <= 1)
|
|
15
16
|
return null;
|
|
16
|
-
|
|
17
|
+
var index = previewNavigationIndex(files, currentId);
|
|
17
18
|
if (index < 0)
|
|
18
19
|
index = 0;
|
|
19
|
-
|
|
20
|
-
for (
|
|
20
|
+
var total = files.length;
|
|
21
|
+
for (var step = 0; step < total; step++) {
|
|
21
22
|
if (direction === 'next') {
|
|
22
23
|
index = (index + 1) % total;
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
26
|
index = index > 0 ? index - 1 : total - 1;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
var candidate = files[index];
|
|
28
29
|
if (candidate.id !== currentId && !missingIds.has(candidate.id)) {
|
|
29
30
|
return candidate;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
// Wrapped full cycle with only the current file available
|
|
33
|
-
|
|
34
|
+
var current = files.find(function (f) { return f.id === currentId; });
|
|
34
35
|
return current && !missingIds.has(current.id) ? current : null;
|
|
35
36
|
}
|
|
36
|
-
export function hasPreviewNavigation(list, missingIds
|
|
37
|
-
|
|
37
|
+
export function hasPreviewNavigation(list, missingIds) {
|
|
38
|
+
if (missingIds === void 0) { missingIds = new Set(); }
|
|
39
|
+
var files = previewNavigationFiles(list).filter(function (f) { return !missingIds.has(f.id); });
|
|
38
40
|
return files.length > 1;
|
|
39
41
|
}
|
|
@@ -3,15 +3,18 @@ import { getFileTypeOf } from './fileKinds';
|
|
|
3
3
|
export function isSamePreviewLane(file, candidate) {
|
|
4
4
|
if (candidate.type !== 'file')
|
|
5
5
|
return false;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
var kind = getFileTypeOf(file);
|
|
7
|
+
var 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
|
-
|
|
12
|
+
export function countPreviewNavigationPeers(files, current, missingIds) {
|
|
13
|
+
if (missingIds === void 0) { missingIds = new Set(); }
|
|
14
|
+
return files.filter(function (item) {
|
|
15
|
+
return item.type === 'file' &&
|
|
16
|
+
item.id !== current.id &&
|
|
17
|
+
!missingIds.has(item.id) &&
|
|
18
|
+
isSamePreviewLane(current, item);
|
|
19
|
+
}).length;
|
|
17
20
|
}
|
|
@@ -1,15 +1,25 @@
|
|
|
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
|
+
};
|
|
1
10
|
/**
|
|
2
11
|
* Stable recent-files list: newest first, one row per resolved picture URL (fallback: file id).
|
|
3
12
|
*/
|
|
4
13
|
export function buildDeduplicatedRecentFiles(files, resolveUrl, limit) {
|
|
5
14
|
if (limit <= 0 || files.length === 0)
|
|
6
15
|
return [];
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
var sorted = __spreadArray([], files, true).sort(function (a, b) { return new Date(b.modified || 0).getTime() - new Date(a.modified || 0).getTime(); });
|
|
17
|
+
var seen = new Set();
|
|
18
|
+
var result = [];
|
|
19
|
+
for (var _i = 0, sorted_1 = sorted; _i < sorted_1.length; _i++) {
|
|
20
|
+
var file = sorted_1[_i];
|
|
21
|
+
var urlKey = file.url ? resolveUrl(file) : file.id;
|
|
22
|
+
var dedupeKey = urlKey || file.id;
|
|
13
23
|
if (seen.has(dedupeKey))
|
|
14
24
|
continue;
|
|
15
25
|
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 var RECENT_FILES_DESKTOP_BREAKPOINT = 1156;
|
|
4
|
+
export var 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()`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Taking files and folders out of the tree in one step, and putting them back when the API refuses the delete.
|
|
4
|
+
*
|
|
5
|
+
* Both functions return a new root and never change the one they were given (the parts of the tree that did not change are
|
|
6
|
+
* shared), so a screen that still holds the old root is not surprised.
|
|
7
|
+
*/
|
|
8
|
+
/** An item that was taken out, and where it sat, so that it can be put back there. */
|
|
9
|
+
export interface RemovedItem {
|
|
10
|
+
item: FileSystemItem;
|
|
11
|
+
/** The id of the folder it sat in, or `null` for the root. */
|
|
12
|
+
parentId: string | null;
|
|
13
|
+
/** Its position among the children of that folder. */
|
|
14
|
+
index: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Takes every item whose id is in `ids` out of the tree, at any depth. A folder goes with everything in it (the files in a
|
|
18
|
+
* folder are not listed on their own: they come back with the folder).
|
|
19
|
+
*/
|
|
20
|
+
export declare function removeItemsFromTree(root: FileSystemItem, ids: ReadonlySet<string>): {
|
|
21
|
+
root: FileSystemItem;
|
|
22
|
+
removed: RemovedItem[];
|
|
23
|
+
};
|
|
24
|
+
/** Every file in an item: the item itself when it is a file, else the files of its folders, at any depth. */
|
|
25
|
+
export declare function filesOfItems(items: ReadonlyArray<FileSystemItem>): FileSystemItem[];
|
|
26
|
+
/**
|
|
27
|
+
* Puts items back where `removeItemsFromTree` took them from: in their folder, at their position. A folder that is gone too
|
|
28
|
+
* is not made again: the item goes to the root. An item whose id is already in the tree is left as it is.
|
|
29
|
+
*/
|
|
30
|
+
export declare function putItemsBackInTree(root: FileSystemItem, removed: ReadonlyArray<RemovedItem>): FileSystemItem;
|