@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.
Files changed (104) hide show
  1. package/dist/actions/dragSelectedToFolder.js +104 -115
  2. package/dist/components/FolderTree.svelte.d.ts +2 -6
  3. package/dist/components/core/Dropzone.svelte +42 -2
  4. package/dist/components/core/FileBrowser.svelte +249 -32
  5. package/dist/components/core/FileUploader.svelte +134 -54
  6. package/dist/components/core/RecentFiles.svelte +74 -19
  7. package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
  8. package/dist/components/core/SearchDropdown.svelte +6 -8
  9. package/dist/components/core/UploadPanel.svelte +7 -0
  10. package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
  11. package/dist/components/core/UploadRow.svelte +9 -4
  12. package/dist/components/core/UploadRow.svelte.d.ts +2 -0
  13. package/dist/components/core/dropzoneClick.d.ts +28 -0
  14. package/dist/components/core/dropzoneClick.js +32 -0
  15. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  16. package/dist/components/ui/DropdownMenu.svelte +1 -1
  17. package/dist/config.js +4 -3
  18. package/dist/i18n/context.js +2 -2
  19. package/dist/i18n/errors.js +2 -1
  20. package/dist/i18n/messages.d.ts +15 -1
  21. package/dist/i18n/messages.js +17 -3
  22. package/dist/i18n/text.js +2 -2
  23. package/dist/mediaLibrary/capabilities.js +4 -3
  24. package/dist/mediaLibrary/context.js +4 -3
  25. package/dist/mediaLibrary/errors.js +46 -35
  26. package/dist/mediaLibrary/normalize.js +45 -42
  27. package/dist/mediaLibrary/paging.js +100 -45
  28. package/dist/mediaLibrary/resolve.js +214 -95
  29. package/dist/mediaLibrary/treeOps.js +40 -20
  30. package/dist/mediaLibrary/urls.js +12 -10
  31. package/dist/mediaLibrary/widgetic.js +140 -54
  32. package/dist/stores/dragStore.js +1 -1
  33. package/dist/stores/fileStore.d.ts +1 -1
  34. package/dist/stores/fileStore.js +44 -37
  35. package/dist/stores/folderCountStore.js +12 -11
  36. package/dist/stores/missingFilesStore.js +3 -3
  37. package/dist/stores/navigationStore.d.ts +1 -1
  38. package/dist/stores/navigationStore.js +217 -178
  39. package/dist/stores/persistentSelectStore.d.ts +1 -1
  40. package/dist/stores/persistentSelectStore.js +117 -94
  41. package/dist/stores/searchStore.js +1 -1
  42. package/dist/stores/uploadApiStore.d.ts +10 -0
  43. package/dist/stores/uploadApiStore.js +7 -7
  44. package/dist/stores/viewportStore.js +4 -4
  45. package/dist/types/index.js +0 -1
  46. package/dist/utils/apiConfig.js +9 -9
  47. package/dist/utils/brandKitLibraryTree.js +57 -42
  48. package/dist/utils/dateUtils.js +11 -9
  49. package/dist/utils/deleteSelectionAction.d.ts +26 -0
  50. package/dist/utils/deleteSelectionAction.js +23 -0
  51. package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
  52. package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
  53. package/dist/utils/dragToFolder/springStep.js +4 -3
  54. package/dist/utils/fileGoneProbe.js +65 -16
  55. package/dist/utils/fileKinds.js +14 -13
  56. package/dist/utils/fileNames.js +7 -7
  57. package/dist/utils/fileOperations.js +440 -333
  58. package/dist/utils/fileTypes.js +19 -14
  59. package/dist/utils/fileUtils.js +85 -31
  60. package/dist/utils/folderUtils.js +5 -4
  61. package/dist/utils/gridLayout.js +7 -7
  62. package/dist/utils/imagePreviewCache.js +26 -15
  63. package/dist/utils/imagePreviewFrame.js +13 -13
  64. package/dist/utils/imagePreviewVisualState.js +5 -4
  65. package/dist/utils/imageTransform.js +27 -14
  66. package/dist/utils/itemMenuCapabilities.js +7 -7
  67. package/dist/utils/libraryTree.js +55 -39
  68. package/dist/utils/pendingUploadDeletes.d.ts +102 -0
  69. package/dist/utils/pendingUploadDeletes.js +400 -0
  70. package/dist/utils/previewKeys.js +1 -1
  71. package/dist/utils/previewListNavigation.js +13 -11
  72. package/dist/utils/previewNavigation.js +10 -7
  73. package/dist/utils/recentFiles.js +16 -6
  74. package/dist/utils/recentFilesLimit.js +2 -2
  75. package/dist/utils/removeItems.d.ts +30 -0
  76. package/dist/utils/removeItems.js +124 -0
  77. package/dist/utils/resolveFileUrl.js +6 -6
  78. package/dist/utils/safeText.js +14 -12
  79. package/dist/utils/searchDropdownPhase.d.ts +14 -3
  80. package/dist/utils/searchDropdownPhase.js +13 -9
  81. package/dist/utils/searchItems.js +30 -14
  82. package/dist/utils/searchNavigation.js +5 -5
  83. package/dist/utils/uploadAuth.d.ts +24 -0
  84. package/dist/utils/uploadAuth.js +140 -0
  85. package/dist/utils/uploadDisplayProgress.js +1 -1
  86. package/dist/utils/uploadLimits.d.ts +76 -0
  87. package/dist/utils/uploadLimits.js +242 -0
  88. package/dist/utils/uploadListReconcile.js +24 -11
  89. package/dist/utils/uploadPanelDismiss.d.ts +13 -0
  90. package/dist/utils/uploadPanelDismiss.js +11 -0
  91. package/dist/utils/uploadPanelProgress.js +4 -4
  92. package/dist/utils/uploadProgressMath.js +13 -11
  93. package/dist/utils/uploadRefusals.d.ts +42 -0
  94. package/dist/utils/uploadRefusals.js +86 -0
  95. package/dist/utils/uploadResponseMapping.js +9 -8
  96. package/dist/utils/uploadUiHelpers.js +17 -17
  97. package/dist/utils/userUploadsStorage.js +270 -133
  98. package/dist/utils/videoFrame.d.ts +23 -0
  99. package/dist/utils/videoFrame.js +26 -0
  100. package/dist/utils/widgeticDelete.js +103 -28
  101. package/dist/utils/widgeticTusUpload.js +189 -105
  102. package/dist/utils/widgeticUpload.js +133 -59
  103. package/dist/utils/xhrMultipartUpload.js +164 -116
  104. package/package.json +3 -3
@@ -1,13 +1,49 @@
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
+ };
1
37
  import { MediaLibraryError, toMediaLibraryError } from './errors';
2
38
  /** How many files the File Browser asks for per page. */
3
- export const DEFAULT_PAGE_SIZE = 100;
39
+ export var DEFAULT_PAGE_SIZE = 100;
4
40
  /**
5
41
  * The most files the File Browser loads. Files beyond it are not shown (search and filters only look at the files
6
42
  * that were loaded), so a library with more files should list the ones a visitor is most likely to want first.
7
43
  */
8
- export const DEFAULT_MAX_ITEMS = 1000;
44
+ export var DEFAULT_MAX_ITEMS = 1000;
9
45
  /** A safety stop: no library is read for more pages than this, whatever it says about having more. */
10
- export const DEFAULT_MAX_PAGES = 50;
46
+ export var DEFAULT_MAX_PAGES = 50;
11
47
  /**
12
48
  * Reads a library page by page, newest first, until it runs out or a limit is reached.
13
49
  *
@@ -17,46 +53,65 @@ export const DEFAULT_MAX_PAGES = 50;
17
53
  * The first page failing throws (there is nothing to show). A later page failing returns what was loaded with the
18
54
  * failure attached, because most of the library is better than none of it.
19
55
  */
20
- export async function loadLibraryPages(library, options) {
21
- const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
22
- const maxItems = options.maxItems ?? DEFAULT_MAX_ITEMS;
23
- const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
24
- const items = [];
25
- const seenIds = new Set();
26
- const usedCursors = new Set();
27
- let cursor;
28
- for (let pageNumber = 1; pageNumber <= maxPages; pageNumber += 1) {
29
- let page;
30
- try {
31
- page = await library.listPage({ cursor, limit: pageSize, signal: options.signal });
32
- }
33
- catch (error) {
34
- const failure = toMediaLibraryError(error, 'Could not load the files', 'libraryError.loadFailed');
35
- if (pageNumber === 1 || failure.code === 'ABORTED')
36
- throw failure;
37
- console.warn(`[FileBrowser] Page ${pageNumber} of the media library "${library.id}" failed; showing the ${items.length} files already loaded:`, failure.message);
38
- return { items, truncated: true, failure };
39
- }
40
- if (page.skipped > 0) {
41
- console.warn(`[FileBrowser] The media library "${library.id}" gave ${page.skipped} file(s) on page ${pageNumber} that cannot be shown:`, page.skippedReasons);
42
- }
43
- const newItems = page.items.filter((item) => !seenIds.has(item.id));
44
- newItems.forEach((item) => seenIds.add(item.id));
45
- items.push(...newItems);
46
- if (newItems.length > 0)
47
- options.onPage?.(newItems, pageNumber);
48
- if (page.nextCursor === null)
49
- return { items, truncated: false };
50
- // The library says there is more. Make sure it is not going in circles before asking again.
51
- if (newItems.length === 0 || usedCursors.has(page.nextCursor) || page.nextCursor === cursor) {
52
- const failure = new MediaLibraryError('INVALID_RESPONSE', 'The media library keeps returning the same files, so the rest was not loaded', { messageKey: 'libraryError.repeatedPage' });
53
- console.warn(`[FileBrowser] The media library "${library.id}" returned a page with nothing new or a repeated cursor; stopping at ${items.length} files`);
54
- return { items, truncated: true, failure };
55
- }
56
- if (items.length >= maxItems)
57
- return { items, truncated: true };
58
- usedCursors.add(page.nextCursor);
59
- cursor = page.nextCursor;
60
- }
61
- return { items, truncated: true };
56
+ export function loadLibraryPages(library, options) {
57
+ return __awaiter(this, void 0, Promise, function () {
58
+ var pageSize, maxItems, maxPages, items, seenIds, usedCursors, cursor, pageNumber, page, error_1, failure, newItems, failure;
59
+ var _a, _b, _c, _d;
60
+ return __generator(this, function (_e) {
61
+ switch (_e.label) {
62
+ case 0:
63
+ pageSize = (_a = options.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
64
+ maxItems = (_b = options.maxItems) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ITEMS;
65
+ maxPages = (_c = options.maxPages) !== null && _c !== void 0 ? _c : DEFAULT_MAX_PAGES;
66
+ items = [];
67
+ seenIds = new Set();
68
+ usedCursors = new Set();
69
+ pageNumber = 1;
70
+ _e.label = 1;
71
+ case 1:
72
+ if (!(pageNumber <= maxPages)) return [3 /*break*/, 7];
73
+ page = void 0;
74
+ _e.label = 2;
75
+ case 2:
76
+ _e.trys.push([2, 4, , 5]);
77
+ return [4 /*yield*/, library.listPage({ cursor: cursor, limit: pageSize, signal: options.signal })];
78
+ case 3:
79
+ page = _e.sent();
80
+ return [3 /*break*/, 5];
81
+ case 4:
82
+ error_1 = _e.sent();
83
+ failure = toMediaLibraryError(error_1, 'Could not load the files', 'libraryError.loadFailed');
84
+ if (pageNumber === 1 || failure.code === 'ABORTED')
85
+ throw failure;
86
+ console.warn("[FileBrowser] Page ".concat(pageNumber, " of the media library \"").concat(library.id, "\" failed; showing the ").concat(items.length, " files already loaded:"), failure.message);
87
+ return [2 /*return*/, { items: items, truncated: true, failure: failure }];
88
+ case 5:
89
+ if (page.skipped > 0) {
90
+ console.warn("[FileBrowser] The media library \"".concat(library.id, "\" gave ").concat(page.skipped, " file(s) on page ").concat(pageNumber, " that cannot be shown:"), page.skippedReasons);
91
+ }
92
+ newItems = page.items.filter(function (item) { return !seenIds.has(item.id); });
93
+ newItems.forEach(function (item) { return seenIds.add(item.id); });
94
+ items.push.apply(items, newItems);
95
+ if (newItems.length > 0)
96
+ (_d = options.onPage) === null || _d === void 0 ? void 0 : _d.call(options, newItems, pageNumber);
97
+ if (page.nextCursor === null)
98
+ return [2 /*return*/, { items: items, truncated: false }];
99
+ // The library says there is more. Make sure it is not going in circles before asking again.
100
+ if (newItems.length === 0 || usedCursors.has(page.nextCursor) || page.nextCursor === cursor) {
101
+ failure = new MediaLibraryError('INVALID_RESPONSE', 'The media library keeps returning the same files, so the rest was not loaded', { messageKey: 'libraryError.repeatedPage' });
102
+ console.warn("[FileBrowser] The media library \"".concat(library.id, "\" returned a page with nothing new or a repeated cursor; stopping at ").concat(items.length, " files"));
103
+ return [2 /*return*/, { items: items, truncated: true, failure: failure }];
104
+ }
105
+ if (items.length >= maxItems)
106
+ return [2 /*return*/, { items: items, truncated: true }];
107
+ usedCursors.add(page.nextCursor);
108
+ cursor = page.nextCursor;
109
+ _e.label = 6;
110
+ case 6:
111
+ pageNumber += 1;
112
+ return [3 /*break*/, 1];
113
+ case 7: return [2 /*return*/, { items: items, truncated: true }];
114
+ }
115
+ });
116
+ });
62
117
  }
@@ -1,43 +1,100 @@
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
+ };
1
48
  import { capabilitiesOf } from './capabilities';
2
49
  import { MediaLibraryError, toMediaLibraryError } from './errors';
3
50
  import { normalizeMediaLibraryFile, normalizeMediaLibraryPage } from './normalize';
4
51
  /** How long a library gets to answer `list`, `rename` and `delete` before the File Browser gives up on it. */
5
- export const DEFAULT_CALL_TIMEOUT_MS = 30_000;
52
+ export var DEFAULT_CALL_TIMEOUT_MS = 30000;
6
53
  /** The name of the folder the library's files are shown in, unless the library names it. */
7
- export const DEFAULT_LIBRARY_LABEL = 'Uploads';
54
+ export var DEFAULT_LIBRARY_LABEL = 'Uploads';
8
55
  /** What the visitor is told when a library does not answer in time. */
9
- const TIMEOUT_MESSAGE = 'The media library did not answer in time';
56
+ var TIMEOUT_MESSAGE = 'The media library did not answer in time';
10
57
  /**
11
58
  * Runs one call of a library with a time limit. The library gets an `AbortSignal` that fires on timeout or when the
12
59
  * caller gives up; a library that ignores it is still let go of, so the screen never waits forever.
13
60
  */
14
- async function callWithTimeout(run, callerSignal, timeoutMs) {
15
- if (callerSignal.aborted)
16
- throw new MediaLibraryError('ABORTED', 'The request was cancelled');
17
- const callController = new AbortController();
18
- const forwardAbort = () => callController.abort();
19
- callerSignal.addEventListener('abort', forwardAbort, { once: true });
20
- let timer;
21
- const timedOut = new Promise((_, reject) => {
22
- timer = setTimeout(() => {
23
- callController.abort();
24
- reject(new MediaLibraryError('NETWORK', TIMEOUT_MESSAGE, { messageKey: 'libraryError.timeout' }));
25
- }, timeoutMs);
26
- });
27
- const cancelled = new Promise((_, reject) => {
28
- callController.signal.addEventListener('abort', () => {
29
- if (callerSignal.aborted)
30
- reject(new MediaLibraryError('ABORTED', 'The request was cancelled'));
31
- }, { once: true });
61
+ function callWithTimeout(run, callerSignal, timeoutMs) {
62
+ return __awaiter(this, void 0, Promise, function () {
63
+ var callController, forwardAbort, timer, timedOut, cancelled;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ if (callerSignal.aborted)
68
+ throw new MediaLibraryError('ABORTED', 'The request was cancelled');
69
+ callController = new AbortController();
70
+ forwardAbort = function () { return callController.abort(); };
71
+ callerSignal.addEventListener('abort', forwardAbort, { once: true });
72
+ timedOut = new Promise(function (_, reject) {
73
+ timer = setTimeout(function () {
74
+ callController.abort();
75
+ reject(new MediaLibraryError('NETWORK', TIMEOUT_MESSAGE, { messageKey: 'libraryError.timeout' }));
76
+ }, timeoutMs);
77
+ });
78
+ cancelled = new Promise(function (_, reject) {
79
+ callController.signal.addEventListener('abort', function () {
80
+ if (callerSignal.aborted)
81
+ reject(new MediaLibraryError('ABORTED', 'The request was cancelled'));
82
+ }, { once: true });
83
+ });
84
+ _a.label = 1;
85
+ case 1:
86
+ _a.trys.push([1, , 3, 4]);
87
+ return [4 /*yield*/, Promise.race([run(callController.signal), timedOut, cancelled])];
88
+ case 2: return [2 /*return*/, _a.sent()];
89
+ case 3:
90
+ if (timer !== undefined)
91
+ clearTimeout(timer);
92
+ callerSignal.removeEventListener('abort', forwardAbort);
93
+ return [7 /*endfinally*/];
94
+ case 4: return [2 /*return*/];
95
+ }
96
+ });
32
97
  });
33
- try {
34
- return await Promise.race([run(callController.signal), timedOut, cancelled]);
35
- }
36
- finally {
37
- if (timer !== undefined)
38
- clearTimeout(timer);
39
- callerSignal.removeEventListener('abort', forwardAbort);
40
- }
41
98
  }
42
99
  function isObject(value) {
43
100
  return value !== null && typeof value === 'object';
@@ -48,90 +105,152 @@ function isObject(value) {
48
105
  * Throws a `TypeError` naming the problem when it is not a provider (no `list` function), so a partner's mistake
49
106
  * shows up at mount time with a clear message instead of as an empty screen.
50
107
  */
51
- export function resolveMediaLibrary(provider, options = {}) {
108
+ export function resolveMediaLibrary(provider, options) {
109
+ var _this = this;
110
+ var _a;
111
+ if (options === void 0) { options = {}; }
52
112
  if (!isObject(provider) || typeof provider.list !== 'function') {
53
113
  throw new TypeError('mediaLibrary must be an object with a list({ cursor, limit, signal }) function');
54
114
  }
55
- for (const optionalFunction of ['upload', 'rename', 'delete']) {
115
+ for (var _i = 0, _b = ['upload', 'rename', 'delete']; _i < _b.length; _i++) {
116
+ var optionalFunction = _b[_i];
56
117
  if (provider[optionalFunction] !== undefined &&
57
118
  typeof provider[optionalFunction] !== 'function') {
58
- throw new TypeError(`mediaLibrary.${optionalFunction} must be a function when it is given`);
119
+ throw new TypeError("mediaLibrary.".concat(optionalFunction, " must be a function when it is given"));
59
120
  }
60
121
  }
61
- const library = provider;
62
- const callTimeoutMs = options.callTimeoutMs ?? DEFAULT_CALL_TIMEOUT_MS;
63
- const normalizeOptions = { baseHref: options.baseHref };
64
- const id = typeof library.id === 'string' && library.id.trim() !== ''
122
+ var library = provider;
123
+ var callTimeoutMs = (_a = options.callTimeoutMs) !== null && _a !== void 0 ? _a : DEFAULT_CALL_TIMEOUT_MS;
124
+ var normalizeOptions = { baseHref: options.baseHref };
125
+ var id = typeof library.id === 'string' && library.id.trim() !== ''
65
126
  ? library.id.trim().slice(0, 64)
66
127
  : 'host';
67
- const hasOwnLabel = typeof library.label === 'string' && library.label.trim() !== '';
68
- const label = hasOwnLabel ? library.label.trim().slice(0, 64) : DEFAULT_LIBRARY_LABEL;
69
- const capabilities = capabilitiesOf(library);
70
- const resolved = {
71
- id,
72
- label,
73
- hasOwnLabel,
74
- capabilities,
75
- async listPage(request) {
76
- const raw = await callWithTimeout(async (signal) => {
77
- try {
78
- return await library.list({ ...request, signal });
79
- }
80
- catch (error) {
81
- throw toMediaLibraryError(error, 'Could not load the files', 'libraryError.loadFailed');
82
- }
83
- }, request.signal, callTimeoutMs);
84
- return normalizeMediaLibraryPage(raw, normalizeOptions);
128
+ var hasOwnLabel = typeof library.label === 'string' && library.label.trim() !== '';
129
+ var label = hasOwnLabel ? library.label.trim().slice(0, 64) : DEFAULT_LIBRARY_LABEL;
130
+ var capabilities = capabilitiesOf(library);
131
+ var resolved = {
132
+ id: id,
133
+ label: label,
134
+ hasOwnLabel: hasOwnLabel,
135
+ capabilities: capabilities,
136
+ listPage: function (request) {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var raw;
139
+ var _this = this;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
143
+ var error_1;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0:
147
+ _a.trys.push([0, 2, , 3]);
148
+ return [4 /*yield*/, library.list(__assign(__assign({}, request), { signal: signal }))];
149
+ case 1: return [2 /*return*/, _a.sent()];
150
+ case 2:
151
+ error_1 = _a.sent();
152
+ throw toMediaLibraryError(error_1, 'Could not load the files', 'libraryError.loadFailed');
153
+ case 3: return [2 /*return*/];
154
+ }
155
+ });
156
+ }); }, request.signal, callTimeoutMs)];
157
+ case 1:
158
+ raw = _a.sent();
159
+ return [2 /*return*/, normalizeMediaLibraryPage(raw, normalizeOptions)];
160
+ }
161
+ });
162
+ });
85
163
  }
86
164
  };
87
165
  if (capabilities.upload && typeof library.upload === 'function') {
88
- resolved.upload = async (request) => {
89
- let raw;
90
- try {
91
- raw = await library.upload(request);
92
- }
93
- catch (error) {
94
- throw toMediaLibraryError(error, 'The upload failed', 'libraryError.uploadFailed');
95
- }
96
- // An upload the library accepted but described badly is reported, not shown: the visitor must not believe a
97
- // file is there when the grid cannot show it.
98
- return normalizeMediaLibraryFile(raw, normalizeOptions);
99
- };
166
+ resolved.upload = function (request) { return __awaiter(_this, void 0, void 0, function () {
167
+ var raw, error_2;
168
+ return __generator(this, function (_a) {
169
+ switch (_a.label) {
170
+ case 0:
171
+ _a.trys.push([0, 2, , 3]);
172
+ return [4 /*yield*/, library.upload(request)];
173
+ case 1:
174
+ raw = _a.sent();
175
+ return [3 /*break*/, 3];
176
+ case 2:
177
+ error_2 = _a.sent();
178
+ throw toMediaLibraryError(error_2, 'The upload failed', 'libraryError.uploadFailed');
179
+ case 3:
180
+ // An upload the library accepted but described badly is reported, not shown: the visitor must not believe a
181
+ // file is there when the grid cannot show it.
182
+ return [2 /*return*/, normalizeMediaLibraryFile(raw, normalizeOptions)];
183
+ }
184
+ });
185
+ }); };
100
186
  }
101
187
  if (capabilities.rename && typeof library.rename === 'function') {
102
- resolved.rename = async (request) => {
103
- const raw = await callWithTimeout(async (signal) => {
104
- try {
105
- return await library.rename({ ...request, signal });
188
+ resolved.rename = function (request) { return __awaiter(_this, void 0, void 0, function () {
189
+ var raw;
190
+ var _this = this;
191
+ return __generator(this, function (_a) {
192
+ switch (_a.label) {
193
+ case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
194
+ var error_3;
195
+ return __generator(this, function (_a) {
196
+ switch (_a.label) {
197
+ case 0:
198
+ _a.trys.push([0, 2, , 3]);
199
+ return [4 /*yield*/, library.rename(__assign(__assign({}, request), { signal: signal }))];
200
+ case 1: return [2 /*return*/, _a.sent()];
201
+ case 2:
202
+ error_3 = _a.sent();
203
+ throw toMediaLibraryError(error_3, 'Could not rename the file', 'libraryError.renameFailed');
204
+ case 3: return [2 /*return*/];
205
+ }
206
+ });
207
+ }); }, request.signal, callTimeoutMs)];
208
+ case 1:
209
+ raw = _a.sent();
210
+ if (raw === undefined || raw === null)
211
+ return [2 /*return*/, null];
212
+ try {
213
+ return [2 /*return*/, normalizeMediaLibraryFile(raw, normalizeOptions)];
214
+ }
215
+ catch (error) {
216
+ // The rename itself worked; only the description of the result is wrong, so the File Browser keeps the name
217
+ // the visitor typed.
218
+ console.warn("[FileBrowser] The media library \"".concat(id, "\" renamed the file but described the result badly:"), error);
219
+ return [2 /*return*/, null];
220
+ }
221
+ return [2 /*return*/];
106
222
  }
107
- catch (error) {
108
- throw toMediaLibraryError(error, 'Could not rename the file', 'libraryError.renameFailed');
109
- }
110
- }, request.signal, callTimeoutMs);
111
- if (raw === undefined || raw === null)
112
- return null;
113
- try {
114
- return normalizeMediaLibraryFile(raw, normalizeOptions);
115
- }
116
- catch (error) {
117
- // The rename itself worked; only the description of the result is wrong, so the File Browser keeps the name
118
- // the visitor typed.
119
- console.warn(`[FileBrowser] The media library "${id}" renamed the file but described the result badly:`, error);
120
- return null;
121
- }
122
- };
223
+ });
224
+ }); };
123
225
  }
124
226
  if (capabilities.delete && typeof library.delete === 'function') {
125
- resolved.remove = async (request) => {
126
- await callWithTimeout(async (signal) => {
127
- try {
128
- await library.delete({ ...request, signal });
129
- }
130
- catch (error) {
131
- throw toMediaLibraryError(error, 'Could not delete the file', 'libraryError.deleteFailed');
227
+ resolved.remove = function (request) { return __awaiter(_this, void 0, void 0, function () {
228
+ var _this = this;
229
+ return __generator(this, function (_a) {
230
+ switch (_a.label) {
231
+ case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
232
+ var error_4;
233
+ return __generator(this, function (_a) {
234
+ switch (_a.label) {
235
+ case 0:
236
+ _a.trys.push([0, 2, , 3]);
237
+ return [4 /*yield*/, library.delete(__assign(__assign({}, request), { signal: signal }))];
238
+ case 1:
239
+ _a.sent();
240
+ return [3 /*break*/, 3];
241
+ case 2:
242
+ error_4 = _a.sent();
243
+ throw toMediaLibraryError(error_4, 'Could not delete the file', 'libraryError.deleteFailed');
244
+ case 3: return [2 /*return*/];
245
+ }
246
+ });
247
+ }); }, request.signal, callTimeoutMs)];
248
+ case 1:
249
+ _a.sent();
250
+ return [2 /*return*/];
132
251
  }
133
- }, request.signal, callTimeoutMs);
134
- };
252
+ });
253
+ }); };
135
254
  }
136
255
  return resolved;
137
256
  }
@@ -1,3 +1,23 @@
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
1
21
  /**
2
22
  * A media library is one flat list of files, so the File Browser's tree for it is a root folder whose children are
3
23
  * the files. These helpers change that list the way the library's own answers do (a file arrives, is renamed, is
@@ -9,13 +29,15 @@ export function createLibraryRoot(files) {
9
29
  return { id: 'root', name: 'Root', type: 'folder', children: files };
10
30
  }
11
31
  function childrenOf(root) {
12
- return root.children ?? [];
32
+ var _a;
33
+ return (_a = root.children) !== null && _a !== void 0 ? _a : [];
13
34
  }
14
35
  /** Adds the files whose id is not in the list yet. A file already in the list is left exactly as it is. */
15
36
  export function appendNewFiles(root, files) {
16
- const knownIds = new Set(childrenOf(root).map((item) => item.id));
17
- const newFiles = [];
18
- for (const file of files) {
37
+ var knownIds = new Set(childrenOf(root).map(function (item) { return item.id; }));
38
+ var newFiles = [];
39
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
40
+ var file = files_1[_i];
19
41
  if (knownIds.has(file.id))
20
42
  continue;
21
43
  knownIds.add(file.id);
@@ -23,21 +45,18 @@ export function appendNewFiles(root, files) {
23
45
  }
24
46
  if (newFiles.length === 0)
25
47
  return root;
26
- return { ...root, children: [...childrenOf(root), ...newFiles] };
48
+ return __assign(__assign({}, root), { children: __spreadArray(__spreadArray([], childrenOf(root), true), newFiles, true) });
27
49
  }
28
50
  /**
29
51
  * Puts a file in the list: replaces the file with the same id (a library may answer an upload with a file it
30
52
  * already had), or adds it when it is new.
31
53
  */
32
54
  export function upsertFile(root, file) {
33
- const children = childrenOf(root);
34
- const index = children.findIndex((item) => item.id === file.id);
55
+ var children = childrenOf(root);
56
+ var index = children.findIndex(function (item) { return item.id === file.id; });
35
57
  if (index === -1)
36
- return { ...root, children: [...children, file] };
37
- return {
38
- ...root,
39
- children: children.map((item, position) => (position === index ? file : item))
40
- };
58
+ return __assign(__assign({}, root), { children: __spreadArray(__spreadArray([], children, true), [file], false) });
59
+ return __assign(__assign({}, root), { children: children.map(function (item, position) { return (position === index ? file : item); }) });
41
60
  }
42
61
  /**
43
62
  * Replaces the file `id` with `file`. The new file may have another id (a library can name files by their path, and
@@ -45,23 +64,24 @@ export function upsertFile(root, file) {
45
64
  * says the id is now this file, and the list never holds two files with one id. An unknown `id` changes nothing.
46
65
  */
47
66
  export function replaceFile(root, id, file) {
48
- const children = childrenOf(root);
49
- if (!children.some((item) => item.id === id))
67
+ var children = childrenOf(root);
68
+ if (!children.some(function (item) { return item.id === id; }))
50
69
  return root;
51
- const replaced = [];
52
- for (const item of children) {
70
+ var replaced = [];
71
+ for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
72
+ var item = children_1[_i];
53
73
  if (item.id === id)
54
74
  replaced.push(file);
55
75
  else if (item.id !== file.id)
56
76
  replaced.push(item);
57
77
  }
58
- return { ...root, children: replaced };
78
+ return __assign(__assign({}, root), { children: replaced });
59
79
  }
60
80
  /** Takes the files with these ids out of the list. */
61
81
  export function removeFiles(root, ids) {
62
- const children = childrenOf(root);
63
- const kept = children.filter((item) => !ids.has(item.id));
82
+ var children = childrenOf(root);
83
+ var kept = children.filter(function (item) { return !ids.has(item.id); });
64
84
  if (kept.length === children.length)
65
85
  return root;
66
- return { ...root, children: kept };
86
+ return __assign(__assign({}, root), { children: kept });
67
87
  }