@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.
Files changed (81) hide show
  1. package/dist/actions/dragSelectedToFolder.js +115 -104
  2. package/dist/components/FolderTree.svelte.d.ts +7 -4
  3. package/dist/components/core/FileBrowser.svelte +1 -3
  4. package/dist/components/core/dropzoneClick.js +2 -3
  5. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  6. package/dist/config.js +3 -4
  7. package/dist/i18n/context.js +2 -2
  8. package/dist/i18n/errors.js +1 -2
  9. package/dist/i18n/messages.js +2 -2
  10. package/dist/i18n/text.js +2 -2
  11. package/dist/mediaLibrary/capabilities.js +3 -4
  12. package/dist/mediaLibrary/context.js +3 -4
  13. package/dist/mediaLibrary/errors.js +35 -46
  14. package/dist/mediaLibrary/normalize.js +42 -45
  15. package/dist/mediaLibrary/paging.js +45 -100
  16. package/dist/mediaLibrary/resolve.js +95 -214
  17. package/dist/mediaLibrary/treeOps.js +20 -40
  18. package/dist/mediaLibrary/urls.js +10 -12
  19. package/dist/mediaLibrary/widgetic.js +54 -140
  20. package/dist/stores/dragStore.js +1 -1
  21. package/dist/stores/fileStore.d.ts +3 -3
  22. package/dist/stores/fileStore.js +37 -44
  23. package/dist/stores/folderCountStore.js +11 -12
  24. package/dist/stores/missingFilesStore.js +3 -3
  25. package/dist/stores/navigationStore.d.ts +1 -1
  26. package/dist/stores/navigationStore.js +178 -217
  27. package/dist/stores/persistentSelectStore.d.ts +1 -1
  28. package/dist/stores/persistentSelectStore.js +94 -117
  29. package/dist/stores/searchStore.js +1 -1
  30. package/dist/stores/uploadApiStore.js +7 -7
  31. package/dist/stores/viewportStore.js +4 -4
  32. package/dist/types/index.js +1 -0
  33. package/dist/utils/apiConfig.js +9 -9
  34. package/dist/utils/brandKitLibraryTree.js +42 -57
  35. package/dist/utils/dateUtils.js +9 -11
  36. package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
  37. package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
  38. package/dist/utils/dragToFolder/springStep.js +3 -4
  39. package/dist/utils/fileGoneProbe.js +16 -65
  40. package/dist/utils/fileKinds.js +13 -14
  41. package/dist/utils/fileNames.js +7 -7
  42. package/dist/utils/fileOperations.js +332 -440
  43. package/dist/utils/fileTypes.js +14 -19
  44. package/dist/utils/fileUtils.js +31 -85
  45. package/dist/utils/folderUtils.js +4 -5
  46. package/dist/utils/gridLayout.js +7 -7
  47. package/dist/utils/imagePreviewCache.js +15 -26
  48. package/dist/utils/imagePreviewFrame.js +13 -13
  49. package/dist/utils/imagePreviewVisualState.js +4 -5
  50. package/dist/utils/imageTransform.js +14 -27
  51. package/dist/utils/itemMenuCapabilities.js +7 -7
  52. package/dist/utils/libraryTree.js +39 -55
  53. package/dist/utils/pendingUploadDeletes.js +113 -289
  54. package/dist/utils/previewKeys.js +1 -1
  55. package/dist/utils/previewListNavigation.js +11 -13
  56. package/dist/utils/previewNavigation.js +7 -10
  57. package/dist/utils/recentFiles.js +6 -16
  58. package/dist/utils/recentFilesLimit.js +2 -2
  59. package/dist/utils/removeItems.js +29 -61
  60. package/dist/utils/resolveFileUrl.js +6 -6
  61. package/dist/utils/safeText.js +12 -14
  62. package/dist/utils/searchDropdownPhase.js +2 -2
  63. package/dist/utils/searchItems.js +14 -30
  64. package/dist/utils/searchNavigation.js +5 -5
  65. package/dist/utils/uploadAuth.js +36 -111
  66. package/dist/utils/uploadDisplayProgress.js +1 -1
  67. package/dist/utils/uploadLimits.js +66 -138
  68. package/dist/utils/uploadListReconcile.js +11 -24
  69. package/dist/utils/uploadPanelDismiss.js +1 -1
  70. package/dist/utils/uploadPanelProgress.js +4 -4
  71. package/dist/utils/uploadProgressMath.js +11 -13
  72. package/dist/utils/uploadRefusals.js +24 -40
  73. package/dist/utils/uploadResponseMapping.js +8 -9
  74. package/dist/utils/uploadUiHelpers.js +17 -17
  75. package/dist/utils/userUploadsStorage.js +133 -270
  76. package/dist/utils/videoFrame.js +2 -2
  77. package/dist/utils/widgeticDelete.js +30 -103
  78. package/dist/utils/widgeticTusUpload.js +105 -189
  79. package/dist/utils/widgeticUpload.js +62 -130
  80. package/dist/utils/xhrMultipartUpload.js +116 -164
  81. package/package.json +1 -1
@@ -1,39 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { fetchUserUploadsFromApi, uploadToWidgeticApi } from '../utils/widgeticUpload';
38
2
  import { WIDGETIC_MULTIPART_MAX_BYTES, shouldUseTusUpload } from '../utils/widgeticTusUpload';
39
3
  import { MediaLibraryError, codeForHttpStatus, isUnauthorized, toMediaLibraryError } from './errors';
@@ -52,124 +16,74 @@ export function createWidgeticMediaLibrary(options) {
52
16
  if (typeof options.getAccessToken !== 'function') {
53
17
  throw new TypeError('createWidgeticMediaLibrary needs a getAccessToken function');
54
18
  }
55
- var apiBasePath = options.apiBasePath.trim().replace(/\/+$/, '');
56
- var allowResumableUploads = options.allowResumableUploads !== false;
19
+ const apiBasePath = options.apiBasePath.trim().replace(/\/+$/, '');
20
+ const allowResumableUploads = options.allowResumableUploads !== false;
57
21
  /** Builds the settings the existing upload functions take, around one token. */
58
- var configAround = function (accessToken) { return ({
59
- apiBasePath: apiBasePath,
60
- accessToken: accessToken,
22
+ const configAround = (accessToken) => ({
23
+ apiBasePath,
24
+ accessToken,
61
25
  contextType: options.contextType,
62
26
  source: options.source,
63
27
  widgetId: options.widgetId,
64
28
  conversationId: options.conversationId
65
- }); };
29
+ });
66
30
  /** Runs a request with the host's token; when the API refuses that token, asks for a fresh one and runs it once more. */
67
- function withTokenRetriedOnce(request) {
68
- return __awaiter(this, void 0, Promise, function () {
69
- var accessToken, error_1, error_2, renewedToken, renewError_1;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0:
73
- _a.trys.push([0, 2, , 3]);
74
- return [4 /*yield*/, options.getAccessToken('initial')];
75
- case 1:
76
- accessToken = _a.sent();
77
- return [3 /*break*/, 3];
78
- case 2:
79
- error_1 = _a.sent();
80
- throw toMediaLibraryError(error_1, 'Could not get an access token from the page', 'libraryError.accessToken');
81
- case 3:
82
- _a.trys.push([3, 5, , 11]);
83
- return [4 /*yield*/, request(accessToken)];
84
- case 4: return [2 /*return*/, _a.sent()];
85
- case 5:
86
- error_2 = _a.sent();
87
- if (!isUnauthorized(error_2))
88
- throw error_2;
89
- console.warn('[FileBrowser] The Widgetic API refused the access token; asking the page for a fresh one');
90
- renewedToken = void 0;
91
- _a.label = 6;
92
- case 6:
93
- _a.trys.push([6, 8, , 9]);
94
- return [4 /*yield*/, options.getAccessToken('expired', accessToken)];
95
- case 7:
96
- renewedToken = _a.sent();
97
- return [3 /*break*/, 9];
98
- case 8:
99
- renewError_1 = _a.sent();
100
- throw toMediaLibraryError(renewError_1, 'Could not get a fresh access token from the page', 'libraryError.accessTokenRenew');
101
- case 9: return [4 /*yield*/, request(renewedToken)];
102
- case 10: return [2 /*return*/, _a.sent()];
103
- case 11: return [2 /*return*/];
104
- }
105
- });
106
- });
31
+ async function withTokenRetriedOnce(request) {
32
+ let accessToken;
33
+ try {
34
+ accessToken = await options.getAccessToken('initial');
35
+ }
36
+ catch (error) {
37
+ throw toMediaLibraryError(error, 'Could not get an access token from the page', 'libraryError.accessToken');
38
+ }
39
+ try {
40
+ return await request(accessToken);
41
+ }
42
+ catch (error) {
43
+ if (!isUnauthorized(error))
44
+ throw error;
45
+ console.warn('[FileBrowser] The Widgetic API refused the access token; asking the page for a fresh one');
46
+ let renewedToken;
47
+ try {
48
+ renewedToken = await options.getAccessToken('expired', accessToken);
49
+ }
50
+ catch (renewError) {
51
+ throw toMediaLibraryError(renewError, 'Could not get a fresh access token from the page', 'libraryError.accessTokenRenew');
52
+ }
53
+ return await request(renewedToken);
54
+ }
107
55
  }
108
56
  return {
109
57
  id: 'widgetic',
110
58
  label: options.label,
111
59
  capabilities: options.capabilities,
112
- list: function (_a) {
113
- return __awaiter(this, arguments, void 0, function (_b) {
114
- var items;
115
- var limit = _b.limit, signal = _b.signal;
116
- return __generator(this, function (_c) {
117
- switch (_c.label) {
118
- case 0: return [4 /*yield*/, withTokenRetriedOnce(function (accessToken) {
119
- return fetchUserUploadsFromApi(configAround(accessToken), { limit: limit, signal: signal });
120
- })];
121
- case 1:
122
- items = _c.sent();
123
- // The API lists the newest uploads up to `limit` and has no cursor yet, so there is never a next page.
124
- // Every row listed has an id and a url (rows without are dropped by the function), which the item type cannot say.
125
- return [2 /*return*/, { items: items, nextCursor: null }];
126
- }
127
- });
128
- });
60
+ async list({ limit, signal }) {
61
+ const items = await withTokenRetriedOnce((accessToken) => fetchUserUploadsFromApi(configAround(accessToken), { limit, signal }));
62
+ // The API lists the newest uploads up to `limit` and has no cursor yet, so there is never a next page.
63
+ // Every row listed has an id and a url (rows without are dropped by the function), which the item type cannot say.
64
+ return { items: items, nextCursor: null };
129
65
  },
130
- upload: function (_a) {
131
- return __awaiter(this, arguments, void 0, function (_b) {
132
- var limitInMegabytes, uploaded;
133
- var _this = this;
134
- var file = _b.file, onProgress = _b.onProgress, signal = _b.signal;
135
- return __generator(this, function (_c) {
136
- switch (_c.label) {
137
- case 0:
138
- if (!allowResumableUploads && shouldUseTusUpload(file)) {
139
- limitInMegabytes = Math.round(WIDGETIC_MULTIPART_MAX_BYTES / (1024 * 1024));
140
- throw new MediaLibraryError('NOT_SUPPORTED', "Files over ".concat(limitInMegabytes, " MB cannot be uploaded here yet"), { messageKey: 'libraryError.fileTooLarge', messageValues: { limit: limitInMegabytes } });
141
- }
142
- return [4 /*yield*/, withTokenRetriedOnce(function (accessToken) { return __awaiter(_this, void 0, void 0, function () {
143
- var result, message;
144
- return __generator(this, function (_a) {
145
- switch (_a.label) {
146
- case 0: return [4 /*yield*/, uploadToWidgeticApi(file, configAround(accessToken), {
147
- abortSignal: signal,
148
- onProgress: function (_a) {
149
- var percentage = _a.percentage;
150
- return onProgress(percentage);
151
- }
152
- })];
153
- case 1:
154
- result = _a.sent();
155
- if (!result.success || !result.file) {
156
- message = result.error || 'The upload failed';
157
- throw new MediaLibraryError(result.status !== undefined ? codeForHttpStatus(result.status) : 'FAILED', message, {
158
- status: result.status,
159
- // The API's own reason is shown as it is; without one, the File Browser's sentence is.
160
- messageKey: result.error ? undefined : 'libraryError.uploadFailed'
161
- });
162
- }
163
- return [2 /*return*/, result.file];
164
- }
165
- });
166
- }); })];
167
- case 1:
168
- uploaded = _c.sent();
169
- return [2 /*return*/, uploaded];
170
- }
66
+ async upload({ file, onProgress, signal }) {
67
+ if (!allowResumableUploads && shouldUseTusUpload(file)) {
68
+ const limitInMegabytes = Math.round(WIDGETIC_MULTIPART_MAX_BYTES / (1024 * 1024));
69
+ throw new MediaLibraryError('NOT_SUPPORTED', `Files over ${limitInMegabytes} MB cannot be uploaded here yet`, { messageKey: 'libraryError.fileTooLarge', messageValues: { limit: limitInMegabytes } });
70
+ }
71
+ const uploaded = await withTokenRetriedOnce(async (accessToken) => {
72
+ const result = await uploadToWidgeticApi(file, configAround(accessToken), {
73
+ abortSignal: signal,
74
+ onProgress: ({ percentage }) => onProgress(percentage)
171
75
  });
76
+ if (!result.success || !result.file) {
77
+ const message = result.error || 'The upload failed';
78
+ throw new MediaLibraryError(result.status !== undefined ? codeForHttpStatus(result.status) : 'FAILED', message, {
79
+ status: result.status,
80
+ // The API's own reason is shown as it is; without one, the File Browser's sentence is.
81
+ messageKey: result.error ? undefined : 'libraryError.uploadFailed'
82
+ });
83
+ }
84
+ return result.file;
172
85
  });
86
+ return uploaded;
173
87
  }
174
88
  };
175
89
  }
@@ -1,2 +1,2 @@
1
1
  import { writable } from 'svelte/store';
2
- export var isDraggingFiles = writable(false);
2
+ export const isDraggingFiles = writable(false);
@@ -5,15 +5,15 @@ export declare const fileStore: {
5
5
  update: (this: void, updater: import("svelte/store").Updater<FileSystemRoot>) => void;
6
6
  };
7
7
  export declare const currentFolder: import("svelte/store").Writable<string[]>;
8
- export declare const sortCriteria: import("svelte/store").Writable<"name" | "date" | "size">;
9
- export declare const sortDirection: import("svelte/store").Writable<"asc" | "desc">;
8
+ export declare const sortCriteria: import("svelte/store").Writable<"name" | "size" | "date">;
9
+ export declare const sortDirection: import("svelte/store").Writable<"desc" | "asc">;
10
10
  export declare const selectedFiles: import("svelte/store").Writable<FileSystemItem[]>;
11
11
  export declare const fileFilter: import("svelte/store").Writable<string[]>;
12
12
  /**
13
13
  * Derived store that automatically sorts files based on criteria
14
14
  * Maintains folder priority (folders always appear before files)
15
15
  */
16
- export declare const sortedFiles: import("svelte/store").Readable<any>;
16
+ export declare const sortedFiles: import("svelte/store").Readable<FileSystemRoot>;
17
17
  /**
18
18
  * Initializes or updates the file store with new data
19
19
  * Includes validation and error handling
@@ -1,31 +1,11 @@
1
1
  // console.time('fileStore initialization');
2
2
  // console.log('Starting fileStore initialization');
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
15
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
16
- if (ar || !(i in from)) {
17
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
18
- ar[i] = from[i];
19
- }
20
- }
21
- return to.concat(ar || Array.prototype.slice.call(from));
22
- };
23
3
  import { writable, derived } from 'svelte/store';
24
4
  /**
25
5
  * Initial state for the file system store
26
6
  * Provides a base structure with an empty root folder
27
7
  */
28
- var initialState = {
8
+ const initialState = {
29
9
  basePath: '',
30
10
  root: {
31
11
  id: 'root',
@@ -40,41 +20,40 @@ import { buildFileUrl } from '../utils/resolveFileUrl';
40
20
  * @returns A writable store with custom set method
41
21
  */
42
22
  function createFileStore() {
43
- var _a = writable(initialState), subscribe = _a.subscribe, internalSet = _a.set, update = _a.update;
23
+ const { subscribe, set: internalSet, update } = writable(initialState);
44
24
  // Override set method to ensure proper initialization
45
25
  function set(newValue) {
46
26
  initializeFileStore(newValue);
47
27
  }
48
28
  return {
49
- subscribe: subscribe,
50
- set: set,
51
- update: update
29
+ subscribe,
30
+ set,
31
+ update
52
32
  };
53
33
  }
54
34
  // Store creation
55
- export var fileStore = createFileStore();
56
- export var currentFolder = writable([]);
57
- export var sortCriteria = writable('name');
58
- export var sortDirection = writable('asc');
59
- export var selectedFiles = writable([]);
60
- export var fileFilter = writable(['jpg', 'png', 'gif']); // Default to image files
35
+ export const fileStore = createFileStore();
36
+ export const currentFolder = writable([]);
37
+ export const sortCriteria = writable('name');
38
+ export const sortDirection = writable('asc');
39
+ export const selectedFiles = writable([]);
40
+ export const fileFilter = writable(['jpg', 'png', 'gif']); // Default to image files
61
41
  // console.log('Basic stores created');
62
42
  /**
63
43
  * Derived store that automatically sorts files based on criteria
64
44
  * Maintains folder priority (folders always appear before files)
65
45
  */
66
- export var sortedFiles = derived([fileStore, sortCriteria, sortDirection], function (_a) {
67
- var $fileStore = _a[0], $sortCriteria = _a[1], $sortDirection = _a[2];
46
+ export const sortedFiles = derived([fileStore, sortCriteria, sortDirection], ([$fileStore, $sortCriteria, $sortDirection]) => {
68
47
  if (!$fileStore.root)
69
48
  return $fileStore;
70
49
  // console.time('sortedFiles derivation');
71
- var sortedChildren = __spreadArray([], ($fileStore.root.children || []), true).sort(function (a, b) {
50
+ const sortedChildren = [...($fileStore.root.children || [])].sort((a, b) => {
72
51
  // Ensure folders are always displayed before files
73
52
  if (a.type === 'folder' && b.type !== 'folder')
74
53
  return -1;
75
54
  if (a.type !== 'folder' && b.type === 'folder')
76
55
  return 1;
77
- var comparison = 0;
56
+ let comparison = 0;
78
57
  // Sort based on selected criteria
79
58
  switch ($sortCriteria) {
80
59
  case 'name':
@@ -89,7 +68,13 @@ export var sortedFiles = derived([fileStore, sortCriteria, sortDirection], funct
89
68
  }
90
69
  return $sortDirection === 'asc' ? comparison : -comparison;
91
70
  });
92
- var result = __assign(__assign({}, $fileStore), { root: __assign(__assign({}, $fileStore.root), { children: sortedChildren }) });
71
+ const result = {
72
+ ...$fileStore,
73
+ root: {
74
+ ...$fileStore.root,
75
+ children: sortedChildren
76
+ }
77
+ };
93
78
  // console.timeEnd('sortedFiles derivation');
94
79
  return result;
95
80
  });
@@ -111,8 +96,12 @@ function generateId() {
111
96
  * @returns Processed array of file system items
112
97
  */
113
98
  function processItems(items, basePath) {
114
- return items.map(function (item) {
115
- var newItem = __assign(__assign({}, item), { id: item.id || generateId(), modified: item.modified ? new Date(item.modified).toISOString() : undefined });
99
+ return items.map(item => {
100
+ let newItem = {
101
+ ...item,
102
+ id: item.id || generateId(),
103
+ modified: item.modified ? new Date(item.modified).toISOString() : undefined
104
+ };
116
105
  // Process file-specific properties
117
106
  if (item.type === 'file') {
118
107
  // update url with basePath
@@ -140,10 +129,14 @@ export function initializeFileStore(data) {
140
129
  // console.error('Invalid data structure passed to initializeFileStore');
141
130
  return;
142
131
  }
143
- var basePath_1 = data.basePath;
144
- var processedChildren = processItems(data.root.children || [], basePath_1);
145
- var processedRoot_1 = __assign(__assign({}, data.root), { id: 'root', children: processedChildren });
146
- fileStore.update(function (store) { return ({ basePath: basePath_1, root: processedRoot_1 }); });
132
+ let basePath = data.basePath;
133
+ const processedChildren = processItems(data.root.children || [], basePath);
134
+ const processedRoot = {
135
+ ...data.root,
136
+ id: 'root',
137
+ children: processedChildren
138
+ };
139
+ fileStore.update(store => ({ basePath, root: processedRoot }));
147
140
  }
148
141
  catch (error) {
149
142
  // console.error('Error initializing file store:', error);
@@ -154,14 +147,14 @@ export function initializeFileStore(data) {
154
147
  * @param file File to add to selection
155
148
  */
156
149
  export function addFile(file) {
157
- selectedFiles.update(function (files) { return __spreadArray(__spreadArray([], files, true), [file], false); });
150
+ selectedFiles.update(files => [...files, file]);
158
151
  }
159
152
  /**
160
153
  * Removes a file from the selected files collection
161
154
  * @param fileId ID of file to remove
162
155
  */
163
156
  export function removeFile(fileId) {
164
- selectedFiles.update(function (files) { return files.filter(function (file) { return file.id !== fileId; }); });
157
+ selectedFiles.update(files => files.filter(file => file.id !== fileId));
165
158
  }
166
159
  /**
167
160
  * Resets the file store to its initial state
@@ -1,14 +1,13 @@
1
- import { writable } from 'svelte/store';
1
+ import { writable, derived } from 'svelte/store';
2
2
  import { fileStore } from './fileStore';
3
3
  import { getFileTypeOf } from '../utils/fileKinds';
4
4
  // Store to keep track of file counts for each folder
5
- export var folderCounts = writable(new Map());
5
+ export const folderCounts = writable(new Map());
6
6
  // Helper function to count files in a folder
7
7
  function countFiles(folder, filter) {
8
- var count = 0;
8
+ let count = 0;
9
9
  if (folder.children) {
10
- for (var _i = 0, _a = folder.children; _i < _a.length; _i++) {
11
- var item = _a[_i];
10
+ for (const item of folder.children) {
12
11
  if (item.type === 'folder') {
13
12
  count += 1;
14
13
  }
@@ -21,13 +20,13 @@ function countFiles(folder, filter) {
21
20
  }
22
21
  // Update counts whenever the file system or filter changes
23
22
  export function updateFolderCounts(fileSystem, filter) {
24
- var newCounts = new Map();
23
+ const newCounts = new Map();
25
24
  function traverse(folder) {
26
- var count = countFiles(folder, filter);
25
+ const count = countFiles(folder, filter);
27
26
  newCounts.set(folder.id, count);
28
27
  if (folder.children) {
29
28
  folder.children
30
- .filter(function (item) { return item.type === 'folder'; })
29
+ .filter(item => item.type === 'folder')
31
30
  .forEach(traverse);
32
31
  }
33
32
  }
@@ -35,15 +34,15 @@ export function updateFolderCounts(fileSystem, filter) {
35
34
  folderCounts.set(newCounts);
36
35
  }
37
36
  // Subscribe to fileStore changes to keep counts updated
38
- fileStore.subscribe(function ($fileStore) {
39
- if ($fileStore === null || $fileStore === void 0 ? void 0 : $fileStore.root) {
37
+ fileStore.subscribe(($fileStore) => {
38
+ if ($fileStore?.root) {
40
39
  updateFolderCounts($fileStore.root, 'all');
41
40
  }
42
41
  });
43
42
  // Helper function to get count for a specific folder
44
43
  export function getFolderCount(folderId) {
45
- var count = 0;
46
- folderCounts.subscribe(function (counts) {
44
+ let count = 0;
45
+ folderCounts.subscribe(counts => {
47
46
  count = counts.get(folderId) || 0;
48
47
  })();
49
48
  return count;
@@ -1,13 +1,13 @@
1
1
  import { writable } from 'svelte/store';
2
- export var missingFiles = writable(new Set());
2
+ export const missingFiles = writable(new Set());
3
3
  export function addMissingFile(id) {
4
- missingFiles.update(function (files) {
4
+ missingFiles.update(files => {
5
5
  files.add(id);
6
6
  return files;
7
7
  });
8
8
  }
9
9
  export function removeMissingFile(id) {
10
- missingFiles.update(function (files) {
10
+ missingFiles.update(files => {
11
11
  files.delete(id);
12
12
  return files;
13
13
  });
@@ -1,5 +1,5 @@
1
1
  import { currentFolder } from './fileStore';
2
- export declare const currentPathNames: import("svelte/store").Readable<any>;
2
+ export declare const currentPathNames: import("svelte/store").Readable<string[]>;
3
3
  export { currentFolder };
4
4
  export declare const navigationActions: import("svelte/store").Writable<{
5
5
  navigateToPath: (path: string[]) => void;