@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,15 +1,26 @@
1
1
  /**
2
2
  * Pure helpers for the Widgetic library-mode tree: persistence covers the whole root and API hydration merges by id.
3
3
  */
4
+ var __assign = (this && this.__assign) || function () {
5
+ __assign = Object.assign || function(t) {
6
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
7
+ s = arguments[i];
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9
+ t[p] = s[p];
10
+ }
11
+ return t;
12
+ };
13
+ return __assign.apply(this, arguments);
14
+ };
4
15
  import { placeBrandKitFileInTree } from './brandKitLibraryTree.js';
5
- export const BUILTIN_UPLOADS_ID = 'folder_my_uploads';
16
+ export var BUILTIN_UPLOADS_ID = 'folder_my_uploads';
6
17
  function sortFolderContentsLikeGrid(items, sort) {
7
- items.sort((a, b) => {
18
+ items.sort(function (a, b) {
8
19
  if (a.type === 'folder' && b.type !== 'folder')
9
20
  return -1;
10
21
  if (a.type !== 'folder' && b.type === 'folder')
11
22
  return 1;
12
- let comparison = 0;
23
+ var comparison = 0;
13
24
  switch (sort.criteria) {
14
25
  case 'name':
15
26
  comparison = a.name.localeCompare(b.name);
@@ -43,12 +54,10 @@ function ensureDate(value) {
43
54
  }
44
55
  /** Deep clone with Date revival for `modified` fields (JSON persistence). */
45
56
  export function reviveFileSystemDates(items) {
46
- return items.map((item) => {
47
- const revived = {
48
- ...item,
49
- modified: item.modified !== undefined ? new Date(item.modified) : undefined
50
- };
51
- if (item.children?.length) {
57
+ return items.map(function (item) {
58
+ var _a;
59
+ var revived = __assign(__assign({}, item), { modified: item.modified !== undefined ? new Date(item.modified) : undefined });
60
+ if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
52
61
  revived.children = reviveFileSystemDates(item.children);
53
62
  }
54
63
  return revived;
@@ -59,8 +68,9 @@ export function findItemByIdInTree(root, id) {
59
68
  return root;
60
69
  if (!root.children)
61
70
  return null;
62
- for (const child of root.children) {
63
- const found = findItemByIdInTree(child, id);
71
+ for (var _i = 0, _a = root.children; _i < _a.length; _i++) {
72
+ var child = _a[_i];
73
+ var found = findItemByIdInTree(child, id);
64
74
  if (found)
65
75
  return found;
66
76
  }
@@ -71,15 +81,17 @@ export function findItemByIdInTree(root, id) {
71
81
  * Why: legacy data could list the same file id twice.
72
82
  */
73
83
  export function dedupeTreeIds(items) {
74
- const seen = new Set();
84
+ var seen = new Set();
75
85
  function walk(list) {
76
- const out = [];
77
- for (const item of list) {
86
+ var _a;
87
+ var out = [];
88
+ for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
89
+ var item = list_1[_i];
78
90
  if (seen.has(item.id))
79
91
  continue;
80
92
  seen.add(item.id);
81
- const next = { ...item };
82
- if (item.children?.length) {
93
+ var next = __assign({}, item);
94
+ if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
83
95
  next.children = walk(item.children);
84
96
  }
85
97
  out.push(next);
@@ -94,41 +106,39 @@ export function dedupeTreeIds(items) {
94
106
  * their saved tree (it is never recreated after delete).
95
107
  */
96
108
  export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsName) {
97
- let children = dedupeTreeIds(reviveFileSystemDates(rootChildren ?? []));
109
+ var children = dedupeTreeIds(reviveFileSystemDates(rootChildren !== null && rootChildren !== void 0 ? rootChildren : []));
98
110
  function replaceFileById(items, id, file) {
99
- for (let i = 0; i < items.length; i++) {
100
- const it = items[i];
111
+ var _a;
112
+ for (var i = 0; i < items.length; i++) {
113
+ var it = items[i];
101
114
  if (it.type === 'file' && it.id === id) {
102
115
  // Brand-kit uploads keep the server file name; other files keep a visitor rename.
103
- const name = file.libraryFolderPath ? file.name : it.name;
104
- items[i] = { ...file, name, modified: ensureDate(file.modified) };
116
+ var name = file.libraryFolderPath ? file.name : it.name;
117
+ items[i] = __assign(__assign({}, file), { name: name, modified: ensureDate(file.modified) });
105
118
  return true;
106
119
  }
107
- if (it.type === 'folder' && it.children?.length) {
120
+ if (it.type === 'folder' && ((_a = it.children) === null || _a === void 0 ? void 0 : _a.length)) {
108
121
  if (replaceFileById(it.children, id, file))
109
122
  return true;
110
123
  }
111
124
  }
112
125
  return false;
113
126
  }
114
- const rootFolder = {
127
+ var rootFolder = {
115
128
  id: 'root',
116
129
  name: 'Root',
117
130
  type: 'folder',
118
- children
131
+ children: children
119
132
  };
120
- for (const file of apiFiles) {
133
+ var _loop_1 = function (file) {
121
134
  if (file.type !== 'file')
122
- continue;
123
- const normalized = {
124
- ...file,
125
- modified: ensureDate(file.modified)
126
- };
135
+ return "continue";
136
+ var normalized = __assign(__assign({}, file), { modified: ensureDate(file.modified) });
127
137
  if (findItemByIdInTree(rootFolder, file.id)) {
128
138
  replaceFileById(rootFolder.children, file.id, normalized);
129
139
  }
130
140
  else if (file.libraryFolderPath) {
131
- const placed = placeBrandKitFileInTree(rootFolder.children, {
141
+ var placed = placeBrandKitFileInTree(rootFolder.children, {
132
142
  uploadId: file.id,
133
143
  displayName: file.name,
134
144
  folderPath: file.libraryFolderPath.split('/').filter(Boolean),
@@ -136,13 +146,17 @@ export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsNam
136
146
  });
137
147
  rootFolder.children = placed;
138
148
  }
139
- else if (!rootFolder.children.some((c) => c.type === 'file' && c.id === file.id)) {
149
+ else if (!rootFolder.children.some(function (c) { return c.type === 'file' && c.id === file.id; })) {
140
150
  rootFolder.children.push(normalized);
141
151
  sortFolderContentsLikeGrid(rootFolder.children, {
142
152
  criteria: 'name',
143
153
  direction: 'asc'
144
154
  });
145
155
  }
156
+ };
157
+ for (var _i = 0, apiFiles_1 = apiFiles; _i < apiFiles_1.length; _i++) {
158
+ var file = apiFiles_1[_i];
159
+ _loop_1(file);
146
160
  }
147
161
  return dedupeTreeIds(rootFolder.children);
148
162
  }
@@ -150,7 +164,7 @@ export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsNam
150
164
  export function isLegacyUploadsOnlyChildren(children) {
151
165
  if (!children.length)
152
166
  return false;
153
- return children.every((c) => c.type === 'file');
167
+ return children.every(function (c) { return c.type === 'file'; });
154
168
  }
155
169
  /**
156
170
  * One-step legacy migration: old persist stored only upload files under key `current` with no folder wrapper.
@@ -163,16 +177,18 @@ export function migrateLegacyUploadsOnlyChildren(legacyChildren, _myUploadsName)
163
177
  * Unwraps the legacy built-in `folder_my_uploads` (and any nested uploads shells) so children live at the root.
164
178
  */
165
179
  export function flattenLegacyBuiltinUploads(children) {
166
- const out = [];
167
- for (const child of dedupeTreeIds(reviveFileSystemDates(children))) {
180
+ var _a, _b;
181
+ var out = [];
182
+ for (var _i = 0, _c = dedupeTreeIds(reviveFileSystemDates(children)); _i < _c.length; _i++) {
183
+ var child = _c[_i];
168
184
  if (child.type === 'folder' && child.id === BUILTIN_UPLOADS_ID) {
169
- if (child.children?.length) {
170
- out.push(...flattenLegacyBuiltinUploads(child.children));
185
+ if ((_a = child.children) === null || _a === void 0 ? void 0 : _a.length) {
186
+ out.push.apply(out, flattenLegacyBuiltinUploads(child.children));
171
187
  }
172
188
  continue;
173
189
  }
174
- if (child.type === 'folder' && child.children?.length) {
175
- out.push({ ...child, children: flattenLegacyBuiltinUploads(child.children) });
190
+ if (child.type === 'folder' && ((_b = child.children) === null || _b === void 0 ? void 0 : _b.length)) {
191
+ out.push(__assign(__assign({}, child), { children: flattenLegacyBuiltinUploads(child.children) }));
176
192
  }
177
193
  else {
178
194
  out.push(child);
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The deletes the API has still to hear about.
3
+ *
4
+ * When the visitor deletes files they leave the screen at once; the API is told afterwards, in the background. This queue
5
+ * is what makes "afterwards" safe: every upload that was taken off the screen is written down in Dexie (the local database
6
+ * of `@widgetic/cache-layer`) before anything is sent, one record per upload, and is only forgotten once the API has
7
+ * answered. So a reload, a closed tab or a network that comes and goes neither brings the files back nor loses the delete:
8
+ * - the next time the File Browser opens it finishes the queue, and does not list a file whose delete is still waiting;
9
+ * - 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);
10
+ * - an answer that will never change (the API says "not allowed", say) ends the record and tells the File Browser, which
11
+ * puts the file back and says so.
12
+ *
13
+ * It keeps its own kind of record next to the others in the entity store rather than using the shared mutation outbox of the
14
+ * cache layer: that outbox hands every row, whatever its kind, to the one processor that drains it (the brand kit's), so a
15
+ * row of another kind would be read by the wrong code.
16
+ */
17
+ /** The kind of entity the records are saved under (the key is `{owner}:fileBrowserPendingDeletes:{uploadId}`). */
18
+ export declare const PENDING_DELETES_KIND = "fileBrowserPendingDeletes";
19
+ /** After this many failed tries the API is taken to be unreachable for good, and the delete is given up. */
20
+ export declare const PENDING_DELETE_MAX_ATTEMPTS = 8;
21
+ /** How many deletes are sent at the same time. */
22
+ export declare const PENDING_DELETE_CONCURRENCY = 4;
23
+ export interface PendingUploadDelete {
24
+ uploadId: string;
25
+ /** What the visitor knew the file as, to name it if the delete cannot be done. */
26
+ name: string;
27
+ /** How many times the API was asked and could not do it. */
28
+ attempts: number;
29
+ /** The earliest time (epoch ms) to ask again. */
30
+ nextAttemptAt: number;
31
+ createdAt: number;
32
+ lastError: string | null;
33
+ }
34
+ /** Where the records are kept. Dexie in the browser; a Map when there is no owner to keep them for, and in tests. */
35
+ export interface PendingDeleteStore {
36
+ list(): Promise<PendingUploadDelete[]>;
37
+ put(record: PendingUploadDelete): Promise<void>;
38
+ remove(uploadId: string): Promise<void>;
39
+ }
40
+ /** What asking the API came to. */
41
+ export type DeleteAttemptResult = {
42
+ result: 'ok';
43
+ }
44
+ /** Worth asking again later (offline, a 5xx, a session that is being renewed). */
45
+ | {
46
+ result: 'retry';
47
+ message?: string;
48
+ }
49
+ /** The answer will not change (the API refuses): give up and say so. */
50
+ | {
51
+ result: 'permanent';
52
+ message?: string;
53
+ };
54
+ export type DeleteProcessor = (record: PendingUploadDelete) => Promise<DeleteAttemptResult>;
55
+ /** Told when a record is finished one way or the other. */
56
+ export interface DrainHooks {
57
+ onDeleted?: (record: PendingUploadDelete) => void;
58
+ onGaveUp?: (record: PendingUploadDelete, message: string) => void;
59
+ }
60
+ /** How long to wait before asking again, after `attempts` tries have failed: 1 s, 2 s, 4 s … never more than a minute. */
61
+ export declare function deleteBackoffMs(attempts: number): number;
62
+ /**
63
+ * What an HTTP answer means for a delete. 404 and 410 mean the upload is already gone, which is what was wanted. The other
64
+ * 4xx answers (not allowed, malformed) will not change by asking again; 401 (the session is being renewed), 408, 425, 429 and
65
+ * every 5xx will. No status at all is a network error: the same.
66
+ */
67
+ export declare function classifyDeleteStatus(status: number | undefined): 'ok' | 'retry' | 'permanent';
68
+ export declare function createMemoryPendingDeleteStore(): PendingDeleteStore;
69
+ /** The records of one owner (one signed-in person), kept in Dexie through the entity store of the cache layer. */
70
+ export declare function createCacheLayerPendingDeleteStore(ownerId: string): PendingDeleteStore;
71
+ export interface PendingDeleteQueueOptions {
72
+ store: PendingDeleteStore;
73
+ now?: () => number;
74
+ maxAttempts?: number;
75
+ concurrency?: number;
76
+ /** Runs `callback` after `delayMs` (default: `setTimeout`). */
77
+ schedule?: (callback: () => void, delayMs: number) => unknown;
78
+ cancel?: (handle: unknown) => void;
79
+ }
80
+ export interface PendingDeleteQueue {
81
+ /** Writes the uploads down. Ids that are already waiting are kept as they are. */
82
+ enqueue(uploads: ReadonlyArray<{
83
+ uploadId: string;
84
+ name: string;
85
+ }>): Promise<void>;
86
+ /** The ids whose delete is waiting (due or not): the File Browser does not list these. */
87
+ pendingIds(): Promise<Set<string>>;
88
+ /**
89
+ * Sends the deletes that are due, a few at a time, until none is. Records that have to be tried again are picked up
90
+ * later by the queue itself (a timer), with the same `process` and `hooks`. Calls that overlap share one run.
91
+ */
92
+ drain(process: DeleteProcessor, hooks?: DrainHooks): Promise<void>;
93
+ /** Stops the timer that wakes the queue (the records stay in the store). */
94
+ stop(): void;
95
+ }
96
+ export declare function createPendingDeleteQueue(options: PendingDeleteQueueOptions): PendingDeleteQueue;
97
+ /**
98
+ * The queue of the signed-in person (the cache owner). Without an owner there is nowhere to keep the records for the next
99
+ * visit, so they are kept in memory: the files still leave the screen at once and the deletes are still retried, but a reload
100
+ * before the API answers forgets them.
101
+ */
102
+ export declare function getPendingUploadDeleteQueue(): PendingDeleteQueue;