@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.
- package/dist/actions/dragSelectedToFolder.js +115 -104
- package/dist/components/FolderTree.svelte.d.ts +7 -4
- package/dist/components/core/FileBrowser.svelte +1 -3
- package/dist/components/core/dropzoneClick.js +2 -3
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/config.js +3 -4
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +3 -4
- package/dist/mediaLibrary/context.js +3 -4
- package/dist/mediaLibrary/errors.js +35 -46
- package/dist/mediaLibrary/normalize.js +42 -45
- package/dist/mediaLibrary/paging.js +45 -100
- package/dist/mediaLibrary/resolve.js +95 -214
- package/dist/mediaLibrary/treeOps.js +20 -40
- package/dist/mediaLibrary/urls.js +10 -12
- package/dist/mediaLibrary/widgetic.js +54 -140
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +37 -44
- package/dist/stores/folderCountStore.js +11 -12
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +178 -217
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +94 -117
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +1 -0
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +42 -57
- package/dist/utils/dateUtils.js +9 -11
- package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
- package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
- package/dist/utils/dragToFolder/springStep.js +3 -4
- package/dist/utils/fileGoneProbe.js +16 -65
- package/dist/utils/fileKinds.js +13 -14
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +332 -440
- package/dist/utils/fileTypes.js +14 -19
- package/dist/utils/fileUtils.js +31 -85
- package/dist/utils/folderUtils.js +4 -5
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +15 -26
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +4 -5
- package/dist/utils/imageTransform.js +14 -27
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +39 -55
- package/dist/utils/pendingUploadDeletes.js +113 -289
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +11 -13
- package/dist/utils/previewNavigation.js +7 -10
- package/dist/utils/recentFiles.js +6 -16
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.js +29 -61
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +12 -14
- package/dist/utils/searchDropdownPhase.js +2 -2
- package/dist/utils/searchItems.js +14 -30
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.js +36 -111
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.js +66 -138
- package/dist/utils/uploadListReconcile.js +11 -24
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +11 -13
- package/dist/utils/uploadRefusals.js +24 -40
- package/dist/utils/uploadResponseMapping.js +8 -9
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +133 -270
- package/dist/utils/videoFrame.js +2 -2
- package/dist/utils/widgeticDelete.js +30 -103
- package/dist/utils/widgeticTusUpload.js +105 -189
- package/dist/utils/widgeticUpload.js +62 -130
- package/dist/utils/xhrMultipartUpload.js +116 -164
- 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[]) =>
|
|
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
|
-
|
|
6
|
+
const browser = typeof window !== 'undefined';
|
|
27
7
|
// Debug flag to enable/disable logging
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
let persistenceEnabled = true;
|
|
46
26
|
// Create the base store
|
|
47
27
|
function createPersistentSelectStore() {
|
|
48
|
-
|
|
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
|
-
|
|
54
|
-
selections.subscribe(
|
|
55
|
-
if (
|
|
56
|
-
|
|
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
|
|
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:
|
|
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:
|
|
87
|
-
|
|
67
|
+
getSelected: (filterType) => {
|
|
68
|
+
const stored = get(selections);
|
|
88
69
|
return stored[filterType] || [];
|
|
89
|
-
},
|
|
70
|
+
},
|
|
90
71
|
// Toggle selection for a file
|
|
91
|
-
toggleSelection:
|
|
92
|
-
selections.update(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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(
|
|
82
|
+
console.log(`Deselecting file ${file.id} from ${filterType} filter`);
|
|
104
83
|
// Create a new object to update all filter selections
|
|
105
|
-
|
|
84
|
+
const updatedSelections = { ...stored };
|
|
106
85
|
// Update the current filter
|
|
107
|
-
|
|
86
|
+
updatedSelections[filterType] = newSelections;
|
|
108
87
|
// If deselecting in a specific filter, also deselect in "all" filter
|
|
109
|
-
if (filterType !== 'all' &&
|
|
88
|
+
if (filterType !== 'all' && stored['all']?.includes(file.id)) {
|
|
110
89
|
if (DEBUG_LOGGING)
|
|
111
|
-
console.log(
|
|
112
|
-
|
|
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(
|
|
118
|
-
|
|
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(
|
|
122
|
-
|
|
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
|
|
104
|
+
return updatedSelections;
|
|
127
105
|
}
|
|
128
106
|
else {
|
|
129
107
|
// For selection, keep the existing behavior
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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:
|
|
140
|
-
selections.update(
|
|
141
|
-
|
|
142
|
-
|
|
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:
|
|
147
|
-
selections.update(
|
|
148
|
-
|
|
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
|
-
|
|
153
|
-
updatedSelections[filterType] = currentSelections.filter(
|
|
134
|
+
const updatedSelections = { ...stored };
|
|
135
|
+
updatedSelections[filterType] = currentSelections.filter(id => id !== fileId);
|
|
154
136
|
// Also remove from 'all' if present
|
|
155
|
-
if (filterType !== 'all' &&
|
|
156
|
-
updatedSelections['all'] = stored['all'].filter(
|
|
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(
|
|
161
|
-
|
|
162
|
-
|
|
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:
|
|
172
|
-
selections.update(
|
|
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
|
-
|
|
179
|
-
Object.keys(stored).forEach(
|
|
180
|
-
|
|
159
|
+
const updatedSelections = {};
|
|
160
|
+
Object.keys(stored).forEach(key => {
|
|
161
|
+
updatedSelections[key] = [];
|
|
181
162
|
});
|
|
182
|
-
return
|
|
163
|
+
return updatedSelections;
|
|
183
164
|
}
|
|
184
165
|
else {
|
|
185
166
|
if (DEBUG_LOGGING)
|
|
186
|
-
console.log(
|
|
167
|
+
console.log(`Clearing selections from ${filterType} filter`);
|
|
187
168
|
// Get the IDs that were selected in this filter
|
|
188
|
-
|
|
169
|
+
const idsToRemove = stored[filterType] || [];
|
|
189
170
|
// Create a new object with updated filter selections
|
|
190
|
-
|
|
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 (
|
|
175
|
+
if (idsToRemove.length > 0 && stored['all']) {
|
|
195
176
|
if (DEBUG_LOGGING)
|
|
196
|
-
console.log(
|
|
197
|
-
updatedSelections['all'] = stored['all'].filter(
|
|
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:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
190
|
+
const validFileIds = new Set(files.map(f => f.id));
|
|
210
191
|
// Filter out missing and invalid files
|
|
211
|
-
return selectedIds.filter(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
} });
|
|
192
|
+
return selectedIds.filter(id => !missingFileIds.has(id) && validFileIds.has(id));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
215
195
|
}
|
|
216
|
-
export
|
|
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
|
-
|
|
221
|
-
return selectedIds.filter(
|
|
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
|
|
225
|
-
|
|
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
|
-
|
|
207
|
+
const selectedIds = $selections[filterType] || [];
|
|
229
208
|
// Create a map of files by ID for quick lookup
|
|
230
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
+
const validFiles = validIds.map(id => fileMap.get(id));
|
|
237
214
|
// Log the results for debugging
|
|
238
215
|
if (DEBUG_LOGGING)
|
|
239
|
-
console.log(
|
|
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
|
|
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
|
|
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
|
-
|
|
12
|
+
const payloadPart = accessToken.split('.')[1];
|
|
13
13
|
if (!payloadPart)
|
|
14
14
|
return null;
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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 (!
|
|
27
|
+
if (!config?.enableLocalCache)
|
|
28
28
|
return;
|
|
29
|
-
|
|
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
|
|
7
|
+
export const isMobileStore = readable(browser ? window.innerWidth <= 768 : false, (set) => {
|
|
8
8
|
if (!browser)
|
|
9
9
|
return;
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
16
|
+
return () => {
|
|
17
17
|
mediaQueryList.removeEventListener('change', handleMediaQueryChange);
|
|
18
18
|
};
|
|
19
19
|
});
|
package/dist/types/index.js
CHANGED
package/dist/utils/apiConfig.js
CHANGED
|
@@ -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
|
-
|
|
4
|
-
|
|
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
|
|
6
|
+
export const API_BASE_URL = `http://${API_HOST}:${API_PORT}`;
|
|
7
7
|
// API endpoints
|
|
8
|
-
export
|
|
9
|
-
FILES:
|
|
10
|
-
FILE:
|
|
11
|
-
FILE_MOVE:
|
|
12
|
-
CREATE_FOLDER:
|
|
13
|
-
UPLOAD:
|
|
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
|
|
17
|
-
export
|
|
18
|
-
export
|
|
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
|
|
9
|
+
return `fld_brand_${path.map((p) => p.toLowerCase().replace(/\s+/g, '_')).join('/')}`;
|
|
21
10
|
}
|
|
22
11
|
function cloneChildren(children) {
|
|
23
|
-
return children.map(
|
|
12
|
+
return children.map((item) => ({
|
|
13
|
+
...item,
|
|
14
|
+
children: item.children ? cloneChildren(item.children) : undefined
|
|
15
|
+
}));
|
|
24
16
|
}
|
|
25
17
|
function namesInFolder(children) {
|
|
26
|
-
|
|
27
|
-
for (
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const match = /^(.+?)(\.[^.]+)?$/.exec(desiredName);
|
|
30
|
+
const stem = match?.[1] ?? desiredName;
|
|
31
|
+
const ext = match?.[2] ?? '';
|
|
32
|
+
let n = 2;
|
|
43
33
|
for (;;) {
|
|
44
|
-
|
|
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
|
-
|
|
52
|
-
for (
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
82
|
-
|
|
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' &&
|
|
88
|
-
out.push(
|
|
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
|
-
|
|
98
|
-
for (
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
+
const targetChildren = folderChildrenAtPath(tree, input.folderPath);
|
|
123
108
|
if (!targetChildren)
|
|
124
109
|
return tree;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
110
|
+
const taken = namesInFolder(targetChildren);
|
|
111
|
+
const name = resolveCollisionFileName(input.displayName, taken);
|
|
112
|
+
const file = {
|
|
128
113
|
id: input.uploadId,
|
|
129
|
-
name
|
|
114
|
+
name,
|
|
130
115
|
type: 'file',
|
|
131
|
-
modified:
|
|
132
|
-
size:
|
|
133
|
-
url:
|
|
134
|
-
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 (!
|
|
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 (!
|
|
131
|
+
if (!rootChildren?.length)
|
|
147
132
|
return false;
|
|
148
|
-
|
|
133
|
+
const root = { id: 'root', name: 'Root', type: 'folder', children: rootChildren };
|
|
149
134
|
return Boolean(findItemByIdInTree(root, uploadId));
|
|
150
135
|
}
|