@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
@@ -24,5 +24,5 @@ export declare const persistentSelectStore: {
24
24
  update(this: void, updater: import("svelte/store").Updater<StoredSelections>): void;
25
25
  subscribe(this: void, run: import("svelte/store").Subscriber<StoredSelections>, invalidate?: () => void): import("svelte/store").Unsubscriber;
26
26
  };
27
- export declare const validSelections: import("svelte/store").Readable<(filterType: FileFilterType, files: FileSystemItem[]) => any[]>;
27
+ export declare const validSelections: import("svelte/store").Readable<(filterType: FileFilterType, files: FileSystemItem[]) => FileSystemItem[]>;
28
28
  export {};
@@ -1,39 +1,19 @@
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
- };
21
1
  import { writable, derived, get } from 'svelte/store';
22
2
  import { missingFiles } from './missingFilesStore';
23
3
  // Remove $app/environment import
24
4
  // import { browser } from '$app/environment';
25
5
  // Browser detection that works across bundlers
26
- var browser = typeof window !== 'undefined';
6
+ const browser = typeof window !== 'undefined';
27
7
  // Debug flag to enable/disable logging
28
- var DEBUG_LOGGING = false;
29
- var STORAGE_KEY = 'fileBrowser.selectedFiles';
8
+ const DEBUG_LOGGING = false;
9
+ const STORAGE_KEY = 'fileBrowser.selectedFiles';
30
10
  // Initialize from localStorage or empty object
31
11
  function getStoredSelections() {
32
12
  if (!browser) {
33
13
  return {};
34
14
  }
35
15
  try {
36
- var stored = localStorage.getItem(STORAGE_KEY);
16
+ const stored = localStorage.getItem(STORAGE_KEY);
37
17
  return stored ? JSON.parse(stored) : {};
38
18
  }
39
19
  catch (error) {
@@ -42,18 +22,18 @@ function getStoredSelections() {
42
22
  }
43
23
  }
44
24
  // Whether the selection is kept in this browser's localStorage. On by default, as it has always been.
45
- var persistenceEnabled = true;
25
+ let persistenceEnabled = true;
46
26
  // Create the base store
47
27
  function createPersistentSelectStore() {
48
- var selections = writable(getStoredSelections());
28
+ const selections = writable(getStoredSelections());
49
29
  // Save to localStorage whenever the store changes
50
30
  if (browser) {
51
31
  // A subscriber is called once as soon as it subscribes, with what was just read from localStorage. That is not
52
32
  // a change, so it is not written back (it would also write to a page that never stored anything).
53
- var isFirstValue_1 = true;
54
- selections.subscribe(function (value) {
55
- if (isFirstValue_1) {
56
- isFirstValue_1 = false;
33
+ let isFirstValue = true;
34
+ selections.subscribe(value => {
35
+ if (isFirstValue) {
36
+ isFirstValue = false;
57
37
  return;
58
38
  }
59
39
  if (!persistenceEnabled)
@@ -66,7 +46,8 @@ function createPersistentSelectStore() {
66
46
  }
67
47
  });
68
48
  }
69
- return __assign(__assign({}, selections), {
49
+ return {
50
+ ...selections,
70
51
  /**
71
52
  * Turns the localStorage copy of the selection on or off.
72
53
  *
@@ -76,167 +57,163 @@ function createPersistentSelectStore() {
76
57
  *
77
58
  * This is a setting of the page, not of one File Browser: the last one to set it wins.
78
59
  */
79
- configurePersistence: function (enabled) {
60
+ configurePersistence: (enabled) => {
80
61
  if (enabled === persistenceEnabled)
81
62
  return;
82
63
  persistenceEnabled = enabled;
83
64
  selections.set(enabled ? getStoredSelections() : {});
84
- },
65
+ },
85
66
  // Get selected files for a specific filter type
86
- getSelected: function (filterType) {
87
- var stored = get(selections);
67
+ getSelected: (filterType) => {
68
+ const stored = get(selections);
88
69
  return stored[filterType] || [];
89
- },
70
+ },
90
71
  // Toggle selection for a file
91
- toggleSelection: function (file, filterType) {
92
- selections.update(function (stored) {
93
- var _a;
94
- var _b;
95
- var currentSelections = stored[filterType] || [];
96
- var isDeselecting = currentSelections.includes(file.id);
97
- var newSelections = isDeselecting
98
- ? currentSelections.filter(function (id) { return id !== file.id; })
99
- : __spreadArray(__spreadArray([], currentSelections, true), [file.id], false);
72
+ toggleSelection: (file, filterType) => {
73
+ selections.update(stored => {
74
+ const currentSelections = stored[filterType] || [];
75
+ const isDeselecting = currentSelections.includes(file.id);
76
+ const newSelections = isDeselecting
77
+ ? currentSelections.filter(id => id !== file.id)
78
+ : [...currentSelections, file.id];
100
79
  // For deselection, we need to also remove this item from all other filters
101
80
  if (isDeselecting) {
102
81
  if (DEBUG_LOGGING)
103
- console.log("Deselecting file ".concat(file.id, " from ").concat(filterType, " filter"));
82
+ console.log(`Deselecting file ${file.id} from ${filterType} filter`);
104
83
  // Create a new object to update all filter selections
105
- var updatedSelections_1 = __assign({}, stored);
84
+ const updatedSelections = { ...stored };
106
85
  // Update the current filter
107
- updatedSelections_1[filterType] = newSelections;
86
+ updatedSelections[filterType] = newSelections;
108
87
  // If deselecting in a specific filter, also deselect in "all" filter
109
- if (filterType !== 'all' && ((_b = stored['all']) === null || _b === void 0 ? void 0 : _b.includes(file.id))) {
88
+ if (filterType !== 'all' && stored['all']?.includes(file.id)) {
110
89
  if (DEBUG_LOGGING)
111
- console.log("Also deselecting from \"all\" filter");
112
- updatedSelections_1['all'] = stored['all'].filter(function (id) { return id !== file.id; });
90
+ console.log(`Also deselecting from "all" filter`);
91
+ updatedSelections['all'] = stored['all'].filter(id => id !== file.id);
113
92
  }
114
93
  // If deselecting in "all" filter, deselect in all specific filters too
115
94
  if (filterType === 'all') {
116
95
  // Update all other filter types
117
- Object.keys(stored).forEach(function (otherFilterType) {
118
- var _a;
119
- if (otherFilterType !== 'all' && ((_a = stored[otherFilterType]) === null || _a === void 0 ? void 0 : _a.includes(file.id))) {
96
+ Object.keys(stored).forEach(otherFilterType => {
97
+ if (otherFilterType !== 'all' && stored[otherFilterType]?.includes(file.id)) {
120
98
  if (DEBUG_LOGGING)
121
- console.log("Also deselecting from \"".concat(otherFilterType, "\" filter"));
122
- updatedSelections_1[otherFilterType] = stored[otherFilterType].filter(function (id) { return id !== file.id; });
99
+ console.log(`Also deselecting from "${otherFilterType}" filter`);
100
+ updatedSelections[otherFilterType] = stored[otherFilterType].filter(id => id !== file.id);
123
101
  }
124
102
  });
125
103
  }
126
- return updatedSelections_1;
104
+ return updatedSelections;
127
105
  }
128
106
  else {
129
107
  // For selection, keep the existing behavior
130
- return __assign(__assign(__assign({}, stored), (_a = {}, _a[filterType] = newSelections, _a)), (filterType !== 'all' && {
131
- all: stored.all ?
132
- stored.all.includes(file.id) ? stored.all : __spreadArray(__spreadArray([], stored.all, true), [file.id], false)
133
- : [file.id]
134
- }));
108
+ return {
109
+ ...stored,
110
+ [filterType]: newSelections,
111
+ // Also update 'all' filter if it's not the current filter
112
+ ...(filterType !== 'all' && {
113
+ all: stored.all ?
114
+ stored.all.includes(file.id) ? stored.all : [...stored.all, file.id]
115
+ : [file.id]
116
+ })
117
+ };
135
118
  }
136
119
  });
137
- },
120
+ },
138
121
  // Set selections for a filter type
139
- setSelections: function (filterType, selectedIds) {
140
- selections.update(function (stored) {
141
- var _a;
142
- return (__assign(__assign({}, stored), (_a = {}, _a[filterType] = selectedIds, _a)));
143
- });
144
- },
122
+ setSelections: (filterType, selectedIds) => {
123
+ selections.update(stored => ({
124
+ ...stored,
125
+ [filterType]: selectedIds
126
+ }));
127
+ },
145
128
  // Remove a single selection for a filter type without toggling
146
- removeSelection: function (fileId, filterType) {
147
- selections.update(function (stored) {
148
- var _a;
149
- var currentSelections = stored[filterType] || [];
129
+ removeSelection: (fileId, filterType) => {
130
+ selections.update(stored => {
131
+ const currentSelections = stored[filterType] || [];
150
132
  if (!currentSelections.includes(fileId))
151
133
  return stored;
152
- var updatedSelections = __assign({}, stored);
153
- updatedSelections[filterType] = currentSelections.filter(function (id) { return id !== fileId; });
134
+ const updatedSelections = { ...stored };
135
+ updatedSelections[filterType] = currentSelections.filter(id => id !== fileId);
154
136
  // Also remove from 'all' if present
155
- if (filterType !== 'all' && ((_a = stored['all']) === null || _a === void 0 ? void 0 : _a.includes(fileId))) {
156
- updatedSelections['all'] = stored['all'].filter(function (id) { return id !== fileId; });
137
+ if (filterType !== 'all' && stored['all']?.includes(fileId)) {
138
+ updatedSelections['all'] = stored['all'].filter(id => id !== fileId);
157
139
  }
158
140
  // If removing from 'all', remove from all other filters as well
159
141
  if (filterType === 'all') {
160
- Object.keys(stored).forEach(function (key) {
161
- var _a;
162
- if (key !== 'all' && ((_a = stored[key]) === null || _a === void 0 ? void 0 : _a.includes(fileId))) {
163
- updatedSelections[key] = stored[key].filter(function (id) { return id !== fileId; });
142
+ Object.keys(stored).forEach(key => {
143
+ if (key !== 'all' && stored[key]?.includes(fileId)) {
144
+ updatedSelections[key] = stored[key].filter(id => id !== fileId);
164
145
  }
165
146
  });
166
147
  }
167
148
  return updatedSelections;
168
149
  });
169
- },
150
+ },
170
151
  // Clear selections for a filter type
171
- clearSelections: function (filterType) {
172
- selections.update(function (stored) {
152
+ clearSelections: (filterType) => {
153
+ selections.update(stored => {
173
154
  // If clearing all selections, just clear the current filter
174
155
  if (filterType === 'all') {
175
156
  if (DEBUG_LOGGING)
176
157
  console.log('Clearing all selections from all filters');
177
158
  // Clear all filter types
178
- var updatedSelections_2 = {};
179
- Object.keys(stored).forEach(function (key) {
180
- updatedSelections_2[key] = [];
159
+ const updatedSelections = {};
160
+ Object.keys(stored).forEach(key => {
161
+ updatedSelections[key] = [];
181
162
  });
182
- return updatedSelections_2;
163
+ return updatedSelections;
183
164
  }
184
165
  else {
185
166
  if (DEBUG_LOGGING)
186
- console.log("Clearing selections from ".concat(filterType, " filter"));
167
+ console.log(`Clearing selections from ${filterType} filter`);
187
168
  // Get the IDs that were selected in this filter
188
- var idsToRemove_1 = stored[filterType] || [];
169
+ const idsToRemove = stored[filterType] || [];
189
170
  // Create a new object with updated filter selections
190
- var updatedSelections = __assign({}, stored);
171
+ const updatedSelections = { ...stored };
191
172
  // Clear the current filter
192
173
  updatedSelections[filterType] = [];
193
174
  // Also remove these IDs from the 'all' filter if they exist there
194
- if (idsToRemove_1.length > 0 && stored['all']) {
175
+ if (idsToRemove.length > 0 && stored['all']) {
195
176
  if (DEBUG_LOGGING)
196
- console.log("Also removing ".concat(idsToRemove_1.length, " items from \"all\" filter"));
197
- updatedSelections['all'] = stored['all'].filter(function (id) { return !idsToRemove_1.includes(id); });
177
+ console.log(`Also removing ${idsToRemove.length} items from "all" filter`);
178
+ updatedSelections['all'] = stored['all'].filter(id => !idsToRemove.includes(id));
198
179
  }
199
180
  return updatedSelections;
200
181
  }
201
182
  });
202
- },
183
+ },
203
184
  // Get valid selections (excluding missing files)
204
- getValidSelections: function (filterType, files) {
205
- var stored = get(selections);
206
- var missingFileIds = get(missingFiles);
207
- var selectedIds = stored[filterType] || [];
185
+ getValidSelections: (filterType, files) => {
186
+ const stored = get(selections);
187
+ const missingFileIds = get(missingFiles);
188
+ const selectedIds = stored[filterType] || [];
208
189
  // Create a map of valid file IDs for quick lookup
209
- var validFileIds = new Set(files.map(function (f) { return f.id; }));
190
+ const validFileIds = new Set(files.map(f => f.id));
210
191
  // Filter out missing and invalid files
211
- return selectedIds.filter(function (id) {
212
- return !missingFileIds.has(id) && validFileIds.has(id);
213
- });
214
- } });
192
+ return selectedIds.filter(id => !missingFileIds.has(id) && validFileIds.has(id));
193
+ }
194
+ };
215
195
  }
216
- export var persistentSelectStore = createPersistentSelectStore();
196
+ export const persistentSelectStore = createPersistentSelectStore();
217
197
  // Add this function to map IDs back to FileSystemItem objects
218
198
  function getSelectedFiles(selectedIds, files) {
219
199
  // Create a map for O(1) lookup of files by ID
220
- var fileMap = new Map(files.map(function (file) { return [file.id, file]; }));
221
- return selectedIds.filter(function (id) { return fileMap.has(id); }).map(function (id) { return fileMap.get(id); });
200
+ const fileMap = new Map(files.map(file => [file.id, file]));
201
+ return selectedIds.filter(id => fileMap.has(id)).map(id => fileMap.get(id));
222
202
  }
223
203
  // Update the derived store to return FileSystemItem[] instead of string[]
224
- export var validSelections = derived([persistentSelectStore, missingFiles], function (_a) {
225
- var $selections = _a[0], $missingFiles = _a[1];
226
- return function (filterType, files) {
204
+ export const validSelections = derived([persistentSelectStore, missingFiles], ([$selections, $missingFiles]) => {
205
+ return (filterType, files) => {
227
206
  // Get IDs of selected files for current filter
228
- var selectedIds = $selections[filterType] || [];
207
+ const selectedIds = $selections[filterType] || [];
229
208
  // Create a map of files by ID for quick lookup
230
- var fileMap = new Map(files.map(function (file) { return [file.id, file]; }));
209
+ const fileMap = new Map(files.map(file => [file.id, file]));
231
210
  // Filter out missing files and files not present in the provided files array
232
- var validIds = selectedIds.filter(function (id) {
233
- return !$missingFiles.has(id) && fileMap.has(id);
234
- });
211
+ const validIds = selectedIds.filter(id => !$missingFiles.has(id) && fileMap.has(id));
235
212
  // Get the file objects for valid IDs
236
- var validFiles = validIds.map(function (id) { return fileMap.get(id); });
213
+ const validFiles = validIds.map(id => fileMap.get(id));
237
214
  // Log the results for debugging
238
215
  if (DEBUG_LOGGING)
239
- console.log("validSelections for ".concat(filterType, ": ").concat(validFiles.length, " files out of ").concat(selectedIds.length, " selected IDs"));
216
+ console.log(`validSelections for ${filterType}: ${validFiles.length} files out of ${selectedIds.length} selected IDs`);
240
217
  return validFiles;
241
218
  };
242
219
  });
@@ -1,2 +1,2 @@
1
1
  import { writable } from 'svelte/store';
2
- export var searchTermStore = writable('');
2
+ export const searchTermStore = writable('');
@@ -1,6 +1,6 @@
1
1
  import { writable, get } from 'svelte/store';
2
2
  import { setCacheOwner } from '@widgetic/cache-layer';
3
- export var fileBrowserUploadConfig = writable(null);
3
+ export const fileBrowserUploadConfig = writable(null);
4
4
  /**
5
5
  * Extracts the stable user id from a JWT access token payload so durable
6
6
  * caches can be scoped per account without hosts needing to pass it.
@@ -9,14 +9,14 @@ function extractOwnerIdFromAccessToken(accessToken) {
9
9
  if (!accessToken)
10
10
  return null;
11
11
  try {
12
- var payloadPart = accessToken.split('.')[1];
12
+ const payloadPart = accessToken.split('.')[1];
13
13
  if (!payloadPart)
14
14
  return null;
15
- var normalized = payloadPart.replace(/-/g, '+').replace(/_/g, '/');
16
- var payload = JSON.parse(atob(normalized));
15
+ const normalized = payloadPart.replace(/-/g, '+').replace(/_/g, '/');
16
+ const payload = JSON.parse(atob(normalized));
17
17
  return payload.sub || payload.userId || null;
18
18
  }
19
- catch (_a) {
19
+ catch {
20
20
  return null;
21
21
  }
22
22
  }
@@ -24,9 +24,9 @@ export function setFileBrowserUploadConfig(config) {
24
24
  fileBrowserUploadConfig.set(config);
25
25
  // Only scope Dexie when the host opted in — never clearCacheOwner here so a
26
26
  // shared site bundle keeps authStore's owner when FileBrowser leaves cache off.
27
- if (!(config === null || config === void 0 ? void 0 : config.enableLocalCache))
27
+ if (!config?.enableLocalCache)
28
28
  return;
29
- var ownerId = extractOwnerIdFromAccessToken(config.accessToken);
29
+ const ownerId = extractOwnerIdFromAccessToken(config.accessToken);
30
30
  if (ownerId) {
31
31
  setCacheOwner(ownerId);
32
32
  }
@@ -4,16 +4,16 @@ import { browser } from '$app/environment';
4
4
  * Shared media query store tracking whether the viewport is mobile width (<= 768px).
5
5
  * Uses window.matchMedia so it only fires when crossing the breakpoint rather than on every resize pixel.
6
6
  */
7
- export var isMobileStore = readable(browser ? window.innerWidth <= 768 : false, function (set) {
7
+ export const isMobileStore = readable(browser ? window.innerWidth <= 768 : false, (set) => {
8
8
  if (!browser)
9
9
  return;
10
- var mediaQueryList = window.matchMedia('(max-width: 768px)');
11
- var handleMediaQueryChange = function (event) {
10
+ const mediaQueryList = window.matchMedia('(max-width: 768px)');
11
+ const handleMediaQueryChange = (event) => {
12
12
  set(event.matches);
13
13
  };
14
14
  set(mediaQueryList.matches);
15
15
  mediaQueryList.addEventListener('change', handleMediaQueryChange);
16
- return function () {
16
+ return () => {
17
17
  mediaQueryList.removeEventListener('change', handleMediaQueryChange);
18
18
  };
19
19
  });
@@ -1,2 +1,3 @@
1
1
  // Just include reference to PDF types
2
+ // PDF types are defined in pdf.d.ts and available globally
2
3
  export {};
@@ -1,16 +1,16 @@
1
1
  // Utility for centralizing API URL configuration
2
2
  // Read from environment or default to values set in vite.config.ts
3
- var API_HOST = import.meta.env.VITE_API_HOST || 'localhost';
4
- var API_PORT = import.meta.env.VITE_API_PORT || '5201';
3
+ const API_HOST = import.meta.env.VITE_API_HOST || 'localhost';
4
+ const API_PORT = import.meta.env.VITE_API_PORT || '5201';
5
5
  // Base API URL construction
6
- export var API_BASE_URL = "http://".concat(API_HOST, ":").concat(API_PORT);
6
+ export const API_BASE_URL = `http://${API_HOST}:${API_PORT}`;
7
7
  // API endpoints
8
- export var ENDPOINTS = {
9
- FILES: "".concat(API_BASE_URL, "/api/files"), // endpoint to fetch files data from the API
10
- FILE: "".concat(API_BASE_URL, "/api/files/{name}"), // endpoint to fetch a single file from the API
11
- FILE_MOVE: "".concat(API_BASE_URL, "/api/files/move"), // endpoint to move files
12
- CREATE_FOLDER: "".concat(API_BASE_URL, "/api/files/create-folder"), // endpoint to create a new folder
13
- UPLOAD: "".concat(API_BASE_URL, "/api/upload"), // endpoint to upload files
8
+ export const ENDPOINTS = {
9
+ FILES: `${API_BASE_URL}/api/files`, // endpoint to fetch files data from the API
10
+ FILE: `${API_BASE_URL}/api/files/{name}`, // endpoint to fetch a single file from the API
11
+ FILE_MOVE: `${API_BASE_URL}/api/files/move`, // endpoint to move files
12
+ CREATE_FOLDER: `${API_BASE_URL}/api/files/create-folder`, // endpoint to create a new folder
13
+ UPLOAD: `${API_BASE_URL}/api/upload`, // endpoint to upload files
14
14
  // Add other endpoints as needed
15
15
  };
16
16
  // Logging helper for debugging
@@ -1,31 +1,22 @@
1
1
  /**
2
2
  * Places brand-kit upload ids into the Widgetic library tree with stable folder names.
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
- };
15
4
  import { dedupeTreeIds, findItemByIdInTree } from './libraryTree';
16
- export var BRAND_KIT_ROOT_NAME = 'Brand kit';
17
- export var BRAND_KIT_FONTS_FOLDER = 'Fonts';
18
- export var BRAND_KIT_LOGOS_FOLDER = 'Logos';
5
+ export const BRAND_KIT_ROOT_NAME = 'Brand kit';
6
+ export const BRAND_KIT_FONTS_FOLDER = 'Fonts';
7
+ export const BRAND_KIT_LOGOS_FOLDER = 'Logos';
19
8
  function folderIdFor(path) {
20
- return "fld_brand_".concat(path.map(function (p) { return p.toLowerCase().replace(/\s+/g, '_'); }).join('/'));
9
+ return `fld_brand_${path.map((p) => p.toLowerCase().replace(/\s+/g, '_')).join('/')}`;
21
10
  }
22
11
  function cloneChildren(children) {
23
- return children.map(function (item) { return (__assign(__assign({}, item), { children: item.children ? cloneChildren(item.children) : undefined })); });
12
+ return children.map((item) => ({
13
+ ...item,
14
+ children: item.children ? cloneChildren(item.children) : undefined
15
+ }));
24
16
  }
25
17
  function namesInFolder(children) {
26
- var out = new Set();
27
- for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
28
- var item = children_1[_i];
18
+ const out = new Set();
19
+ for (const item of children) {
29
20
  if (item.type === 'file')
30
21
  out.add(item.name.toLowerCase());
31
22
  }
@@ -33,35 +24,33 @@ function namesInFolder(children) {
33
24
  }
34
25
  /** `name (2).ext` when another file in the folder already uses `name.ext`. */
35
26
  export function resolveCollisionFileName(desiredName, takenLower) {
36
- var _a, _b;
37
27
  if (!takenLower.has(desiredName.toLowerCase()))
38
28
  return desiredName;
39
- var match = /^(.+?)(\.[^.]+)?$/.exec(desiredName);
40
- var stem = (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : desiredName;
41
- var ext = (_b = match === null || match === void 0 ? void 0 : match[2]) !== null && _b !== void 0 ? _b : '';
42
- var n = 2;
29
+ const match = /^(.+?)(\.[^.]+)?$/.exec(desiredName);
30
+ const stem = match?.[1] ?? desiredName;
31
+ const ext = match?.[2] ?? '';
32
+ let n = 2;
43
33
  for (;;) {
44
- var candidate = "".concat(stem, " (").concat(n, ")").concat(ext);
34
+ const candidate = `${stem} (${n})${ext}`;
45
35
  if (!takenLower.has(candidate.toLowerCase()))
46
36
  return candidate;
47
37
  n += 1;
48
38
  }
49
39
  }
50
40
  function findChildFolder(children, name) {
51
- var lower = name.toLowerCase();
52
- for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
53
- var child = children_2[_i];
41
+ const lower = name.toLowerCase();
42
+ for (const child of children) {
54
43
  if (child.type === 'folder' && child.name.toLowerCase() === lower)
55
44
  return child;
56
45
  }
57
46
  return null;
58
47
  }
59
48
  function ensureFolderPath(rootChildren, path) {
60
- var next = dedupeTreeIds(cloneChildren(rootChildren));
61
- var children = next;
62
- for (var i = 0; i < path.length; i++) {
63
- var segment = path[i];
64
- var folder = findChildFolder(children, segment);
49
+ const next = dedupeTreeIds(cloneChildren(rootChildren));
50
+ let children = next;
51
+ for (let i = 0; i < path.length; i++) {
52
+ const segment = path[i];
53
+ let folder = findChildFolder(children, segment);
65
54
  if (!folder) {
66
55
  folder = {
67
56
  id: folderIdFor(path.slice(0, i + 1)),
@@ -78,14 +67,12 @@ function ensureFolderPath(rootChildren, path) {
78
67
  return next;
79
68
  }
80
69
  function removeFileById(items, id) {
81
- var _a;
82
- var out = [];
83
- for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
84
- var item = items_1[_i];
70
+ const out = [];
71
+ for (const item of items) {
85
72
  if (item.type === 'file' && item.id === id)
86
73
  continue;
87
- if (item.type === 'folder' && ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length)) {
88
- out.push(__assign(__assign({}, item), { children: removeFileById(item.children, id) }));
74
+ if (item.type === 'folder' && item.children?.length) {
75
+ out.push({ ...item, children: removeFileById(item.children, id) });
89
76
  }
90
77
  else {
91
78
  out.push(item);
@@ -94,10 +81,9 @@ function removeFileById(items, id) {
94
81
  return out;
95
82
  }
96
83
  function folderChildrenAtPath(rootChildren, path) {
97
- var children = rootChildren;
98
- for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
99
- var segment = path_1[_i];
100
- var folder = findChildFolder(children, segment);
84
+ let children = rootChildren;
85
+ for (const segment of path) {
86
+ const folder = findChildFolder(children, segment);
101
87
  if (!folder)
102
88
  return null;
103
89
  if (!folder.children)
@@ -116,35 +102,34 @@ export function brandLogoFolderPath() {
116
102
  * Moves or inserts a file into the tree under `folderPath`, setting `name` to `displayName` (collision suffix applied).
117
103
  */
118
104
  export function placeBrandKitFileInTree(rootChildren, input) {
119
- var _a, _b, _c, _d, _e;
120
- var tree = ensureFolderPath(rootChildren !== null && rootChildren !== void 0 ? rootChildren : [], input.folderPath);
105
+ let tree = ensureFolderPath(rootChildren ?? [], input.folderPath);
121
106
  tree = removeFileById(tree, input.uploadId);
122
- var targetChildren = folderChildrenAtPath(tree, input.folderPath);
107
+ const targetChildren = folderChildrenAtPath(tree, input.folderPath);
123
108
  if (!targetChildren)
124
109
  return tree;
125
- var taken = namesInFolder(targetChildren);
126
- var name = resolveCollisionFileName(input.displayName, taken);
127
- var file = {
110
+ const taken = namesInFolder(targetChildren);
111
+ const name = resolveCollisionFileName(input.displayName, taken);
112
+ const file = {
128
113
  id: input.uploadId,
129
- name: name,
114
+ name,
130
115
  type: 'file',
131
- modified: (_b = (_a = input.file) === null || _a === void 0 ? void 0 : _a.modified) !== null && _b !== void 0 ? _b : new Date(),
132
- size: (_c = input.file) === null || _c === void 0 ? void 0 : _c.size,
133
- url: (_d = input.file) === null || _d === void 0 ? void 0 : _d.url,
134
- mimeType: (_e = input.file) === null || _e === void 0 ? void 0 : _e.mimeType
116
+ modified: input.file?.modified ?? new Date(),
117
+ size: input.file?.size,
118
+ url: input.file?.url,
119
+ mimeType: input.file?.mimeType
135
120
  };
136
121
  targetChildren.push(file);
137
122
  return dedupeTreeIds(tree);
138
123
  }
139
124
  /** Removes a file id wherever it sits in the tree (optimistic delete). */
140
125
  export function removeBrandKitFileFromTree(rootChildren, uploadId) {
141
- if (!(rootChildren === null || rootChildren === void 0 ? void 0 : rootChildren.length))
126
+ if (!rootChildren?.length)
142
127
  return [];
143
128
  return dedupeTreeIds(removeFileById(rootChildren, uploadId));
144
129
  }
145
130
  export function treeContainsUploadId(rootChildren, uploadId) {
146
- if (!(rootChildren === null || rootChildren === void 0 ? void 0 : rootChildren.length))
131
+ if (!rootChildren?.length)
147
132
  return false;
148
- var root = { id: 'root', name: 'Root', type: 'folder', children: rootChildren };
133
+ const root = { id: 'root', name: 'Root', type: 'folder', children: rootChildren };
149
134
  return Boolean(findItemByIdInTree(root, uploadId));
150
135
  }