@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.
- package/dist/actions/dragSelectedToFolder.js +104 -115
- package/dist/components/FolderTree.svelte.d.ts +2 -6
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +249 -32
- package/dist/components/core/FileUploader.svelte +134 -54
- package/dist/components/core/RecentFiles.svelte +74 -19
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +6 -8
- package/dist/components/core/UploadPanel.svelte +7 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
- package/dist/components/core/UploadRow.svelte +9 -4
- package/dist/components/core/UploadRow.svelte.d.ts +2 -0
- package/dist/components/core/dropzoneClick.d.ts +28 -0
- package/dist/components/core/dropzoneClick.js +32 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/config.js +4 -3
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +2 -1
- package/dist/i18n/messages.d.ts +15 -1
- package/dist/i18n/messages.js +17 -3
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +4 -3
- package/dist/mediaLibrary/context.js +4 -3
- package/dist/mediaLibrary/errors.js +46 -35
- package/dist/mediaLibrary/normalize.js +45 -42
- package/dist/mediaLibrary/paging.js +100 -45
- package/dist/mediaLibrary/resolve.js +214 -95
- package/dist/mediaLibrary/treeOps.js +40 -20
- package/dist/mediaLibrary/urls.js +12 -10
- package/dist/mediaLibrary/widgetic.js +140 -54
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +1 -1
- package/dist/stores/fileStore.js +44 -37
- package/dist/stores/folderCountStore.js +12 -11
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +217 -178
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +117 -94
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.d.ts +10 -0
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +0 -1
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +57 -42
- package/dist/utils/dateUtils.js +11 -9
- package/dist/utils/deleteSelectionAction.d.ts +26 -0
- package/dist/utils/deleteSelectionAction.js +23 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
- package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
- package/dist/utils/dragToFolder/springStep.js +4 -3
- package/dist/utils/fileGoneProbe.js +65 -16
- package/dist/utils/fileKinds.js +14 -13
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +440 -333
- package/dist/utils/fileTypes.js +19 -14
- package/dist/utils/fileUtils.js +85 -31
- package/dist/utils/folderUtils.js +5 -4
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +26 -15
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +5 -4
- package/dist/utils/imageTransform.js +27 -14
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +55 -39
- package/dist/utils/pendingUploadDeletes.d.ts +102 -0
- package/dist/utils/pendingUploadDeletes.js +400 -0
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +13 -11
- package/dist/utils/previewNavigation.js +10 -7
- package/dist/utils/recentFiles.js +16 -6
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.d.ts +30 -0
- package/dist/utils/removeItems.js +124 -0
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +14 -12
- package/dist/utils/searchDropdownPhase.d.ts +14 -3
- package/dist/utils/searchDropdownPhase.js +13 -9
- package/dist/utils/searchItems.js +30 -14
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.d.ts +24 -0
- package/dist/utils/uploadAuth.js +140 -0
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.d.ts +76 -0
- package/dist/utils/uploadLimits.js +242 -0
- package/dist/utils/uploadListReconcile.js +24 -11
- package/dist/utils/uploadPanelDismiss.d.ts +13 -0
- package/dist/utils/uploadPanelDismiss.js +11 -0
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +13 -11
- package/dist/utils/uploadRefusals.d.ts +42 -0
- package/dist/utils/uploadRefusals.js +86 -0
- package/dist/utils/uploadResponseMapping.js +9 -8
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +270 -133
- package/dist/utils/videoFrame.d.ts +23 -0
- package/dist/utils/videoFrame.js +26 -0
- package/dist/utils/widgeticDelete.js +103 -28
- package/dist/utils/widgeticTusUpload.js +189 -105
- package/dist/utils/widgeticUpload.js +133 -59
- package/dist/utils/xhrMultipartUpload.js +164 -116
- package/package.json +3 -3
|
@@ -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[]) => any[]>;
|
|
28
28
|
export {};
|
|
@@ -1,19 +1,39 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
1
21
|
import { writable, derived, get } from 'svelte/store';
|
|
2
22
|
import { missingFiles } from './missingFilesStore';
|
|
3
23
|
// Remove $app/environment import
|
|
4
24
|
// import { browser } from '$app/environment';
|
|
5
25
|
// Browser detection that works across bundlers
|
|
6
|
-
|
|
26
|
+
var browser = typeof window !== 'undefined';
|
|
7
27
|
// Debug flag to enable/disable logging
|
|
8
|
-
|
|
9
|
-
|
|
28
|
+
var DEBUG_LOGGING = false;
|
|
29
|
+
var STORAGE_KEY = 'fileBrowser.selectedFiles';
|
|
10
30
|
// Initialize from localStorage or empty object
|
|
11
31
|
function getStoredSelections() {
|
|
12
32
|
if (!browser) {
|
|
13
33
|
return {};
|
|
14
34
|
}
|
|
15
35
|
try {
|
|
16
|
-
|
|
36
|
+
var stored = localStorage.getItem(STORAGE_KEY);
|
|
17
37
|
return stored ? JSON.parse(stored) : {};
|
|
18
38
|
}
|
|
19
39
|
catch (error) {
|
|
@@ -22,18 +42,18 @@ function getStoredSelections() {
|
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
44
|
// Whether the selection is kept in this browser's localStorage. On by default, as it has always been.
|
|
25
|
-
|
|
45
|
+
var persistenceEnabled = true;
|
|
26
46
|
// Create the base store
|
|
27
47
|
function createPersistentSelectStore() {
|
|
28
|
-
|
|
48
|
+
var selections = writable(getStoredSelections());
|
|
29
49
|
// Save to localStorage whenever the store changes
|
|
30
50
|
if (browser) {
|
|
31
51
|
// A subscriber is called once as soon as it subscribes, with what was just read from localStorage. That is not
|
|
32
52
|
// a change, so it is not written back (it would also write to a page that never stored anything).
|
|
33
|
-
|
|
34
|
-
selections.subscribe(value
|
|
35
|
-
if (
|
|
36
|
-
|
|
53
|
+
var isFirstValue_1 = true;
|
|
54
|
+
selections.subscribe(function (value) {
|
|
55
|
+
if (isFirstValue_1) {
|
|
56
|
+
isFirstValue_1 = false;
|
|
37
57
|
return;
|
|
38
58
|
}
|
|
39
59
|
if (!persistenceEnabled)
|
|
@@ -46,8 +66,7 @@ function createPersistentSelectStore() {
|
|
|
46
66
|
}
|
|
47
67
|
});
|
|
48
68
|
}
|
|
49
|
-
return {
|
|
50
|
-
...selections,
|
|
69
|
+
return __assign(__assign({}, selections), {
|
|
51
70
|
/**
|
|
52
71
|
* Turns the localStorage copy of the selection on or off.
|
|
53
72
|
*
|
|
@@ -57,163 +76,167 @@ function createPersistentSelectStore() {
|
|
|
57
76
|
*
|
|
58
77
|
* This is a setting of the page, not of one File Browser: the last one to set it wins.
|
|
59
78
|
*/
|
|
60
|
-
configurePersistence: (enabled)
|
|
79
|
+
configurePersistence: function (enabled) {
|
|
61
80
|
if (enabled === persistenceEnabled)
|
|
62
81
|
return;
|
|
63
82
|
persistenceEnabled = enabled;
|
|
64
83
|
selections.set(enabled ? getStoredSelections() : {});
|
|
65
|
-
},
|
|
84
|
+
},
|
|
66
85
|
// Get selected files for a specific filter type
|
|
67
|
-
getSelected: (filterType)
|
|
68
|
-
|
|
86
|
+
getSelected: function (filterType) {
|
|
87
|
+
var stored = get(selections);
|
|
69
88
|
return stored[filterType] || [];
|
|
70
|
-
},
|
|
89
|
+
},
|
|
71
90
|
// Toggle selection for a file
|
|
72
|
-
toggleSelection: (file, filterType)
|
|
73
|
-
selections.update(stored
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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);
|
|
79
100
|
// For deselection, we need to also remove this item from all other filters
|
|
80
101
|
if (isDeselecting) {
|
|
81
102
|
if (DEBUG_LOGGING)
|
|
82
|
-
console.log(
|
|
103
|
+
console.log("Deselecting file ".concat(file.id, " from ").concat(filterType, " filter"));
|
|
83
104
|
// Create a new object to update all filter selections
|
|
84
|
-
|
|
105
|
+
var updatedSelections_1 = __assign({}, stored);
|
|
85
106
|
// Update the current filter
|
|
86
|
-
|
|
107
|
+
updatedSelections_1[filterType] = newSelections;
|
|
87
108
|
// If deselecting in a specific filter, also deselect in "all" filter
|
|
88
|
-
if (filterType !== 'all' && stored['all']
|
|
109
|
+
if (filterType !== 'all' && ((_b = stored['all']) === null || _b === void 0 ? void 0 : _b.includes(file.id))) {
|
|
89
110
|
if (DEBUG_LOGGING)
|
|
90
|
-
console.log(
|
|
91
|
-
|
|
111
|
+
console.log("Also deselecting from \"all\" filter");
|
|
112
|
+
updatedSelections_1['all'] = stored['all'].filter(function (id) { return id !== file.id; });
|
|
92
113
|
}
|
|
93
114
|
// If deselecting in "all" filter, deselect in all specific filters too
|
|
94
115
|
if (filterType === 'all') {
|
|
95
116
|
// Update all other filter types
|
|
96
|
-
Object.keys(stored).forEach(otherFilterType
|
|
97
|
-
|
|
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))) {
|
|
98
120
|
if (DEBUG_LOGGING)
|
|
99
|
-
console.log(
|
|
100
|
-
|
|
121
|
+
console.log("Also deselecting from \"".concat(otherFilterType, "\" filter"));
|
|
122
|
+
updatedSelections_1[otherFilterType] = stored[otherFilterType].filter(function (id) { return id !== file.id; });
|
|
101
123
|
}
|
|
102
124
|
});
|
|
103
125
|
}
|
|
104
|
-
return
|
|
126
|
+
return updatedSelections_1;
|
|
105
127
|
}
|
|
106
128
|
else {
|
|
107
129
|
// For selection, keep the existing behavior
|
|
108
|
-
return {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
all: stored.all ?
|
|
114
|
-
stored.all.includes(file.id) ? stored.all : [...stored.all, file.id]
|
|
115
|
-
: [file.id]
|
|
116
|
-
})
|
|
117
|
-
};
|
|
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
|
+
}));
|
|
118
135
|
}
|
|
119
136
|
});
|
|
120
|
-
},
|
|
137
|
+
},
|
|
121
138
|
// Set selections for a filter type
|
|
122
|
-
setSelections: (filterType, selectedIds)
|
|
123
|
-
selections.update(stored
|
|
124
|
-
|
|
125
|
-
[filterType]
|
|
126
|
-
})
|
|
127
|
-
},
|
|
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
|
+
},
|
|
128
145
|
// Remove a single selection for a filter type without toggling
|
|
129
|
-
removeSelection: (fileId, filterType)
|
|
130
|
-
selections.update(stored
|
|
131
|
-
|
|
146
|
+
removeSelection: function (fileId, filterType) {
|
|
147
|
+
selections.update(function (stored) {
|
|
148
|
+
var _a;
|
|
149
|
+
var currentSelections = stored[filterType] || [];
|
|
132
150
|
if (!currentSelections.includes(fileId))
|
|
133
151
|
return stored;
|
|
134
|
-
|
|
135
|
-
updatedSelections[filterType] = currentSelections.filter(id
|
|
152
|
+
var updatedSelections = __assign({}, stored);
|
|
153
|
+
updatedSelections[filterType] = currentSelections.filter(function (id) { return id !== fileId; });
|
|
136
154
|
// Also remove from 'all' if present
|
|
137
|
-
if (filterType !== 'all' && stored['all']
|
|
138
|
-
updatedSelections['all'] = stored['all'].filter(id
|
|
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; });
|
|
139
157
|
}
|
|
140
158
|
// If removing from 'all', remove from all other filters as well
|
|
141
159
|
if (filterType === 'all') {
|
|
142
|
-
Object.keys(stored).forEach(key
|
|
143
|
-
|
|
144
|
-
|
|
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; });
|
|
145
164
|
}
|
|
146
165
|
});
|
|
147
166
|
}
|
|
148
167
|
return updatedSelections;
|
|
149
168
|
});
|
|
150
|
-
},
|
|
169
|
+
},
|
|
151
170
|
// Clear selections for a filter type
|
|
152
|
-
clearSelections: (filterType)
|
|
153
|
-
selections.update(stored
|
|
171
|
+
clearSelections: function (filterType) {
|
|
172
|
+
selections.update(function (stored) {
|
|
154
173
|
// If clearing all selections, just clear the current filter
|
|
155
174
|
if (filterType === 'all') {
|
|
156
175
|
if (DEBUG_LOGGING)
|
|
157
176
|
console.log('Clearing all selections from all filters');
|
|
158
177
|
// Clear all filter types
|
|
159
|
-
|
|
160
|
-
Object.keys(stored).forEach(key
|
|
161
|
-
|
|
178
|
+
var updatedSelections_2 = {};
|
|
179
|
+
Object.keys(stored).forEach(function (key) {
|
|
180
|
+
updatedSelections_2[key] = [];
|
|
162
181
|
});
|
|
163
|
-
return
|
|
182
|
+
return updatedSelections_2;
|
|
164
183
|
}
|
|
165
184
|
else {
|
|
166
185
|
if (DEBUG_LOGGING)
|
|
167
|
-
console.log(
|
|
186
|
+
console.log("Clearing selections from ".concat(filterType, " filter"));
|
|
168
187
|
// Get the IDs that were selected in this filter
|
|
169
|
-
|
|
188
|
+
var idsToRemove_1 = stored[filterType] || [];
|
|
170
189
|
// Create a new object with updated filter selections
|
|
171
|
-
|
|
190
|
+
var updatedSelections = __assign({}, stored);
|
|
172
191
|
// Clear the current filter
|
|
173
192
|
updatedSelections[filterType] = [];
|
|
174
193
|
// Also remove these IDs from the 'all' filter if they exist there
|
|
175
|
-
if (
|
|
194
|
+
if (idsToRemove_1.length > 0 && stored['all']) {
|
|
176
195
|
if (DEBUG_LOGGING)
|
|
177
|
-
console.log(
|
|
178
|
-
updatedSelections['all'] = stored['all'].filter(id
|
|
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); });
|
|
179
198
|
}
|
|
180
199
|
return updatedSelections;
|
|
181
200
|
}
|
|
182
201
|
});
|
|
183
|
-
},
|
|
202
|
+
},
|
|
184
203
|
// Get valid selections (excluding missing files)
|
|
185
|
-
getValidSelections: (filterType, files)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
204
|
+
getValidSelections: function (filterType, files) {
|
|
205
|
+
var stored = get(selections);
|
|
206
|
+
var missingFileIds = get(missingFiles);
|
|
207
|
+
var selectedIds = stored[filterType] || [];
|
|
189
208
|
// Create a map of valid file IDs for quick lookup
|
|
190
|
-
|
|
209
|
+
var validFileIds = new Set(files.map(function (f) { return f.id; }));
|
|
191
210
|
// Filter out missing and invalid files
|
|
192
|
-
return selectedIds.filter(
|
|
193
|
-
|
|
194
|
-
|
|
211
|
+
return selectedIds.filter(function (id) {
|
|
212
|
+
return !missingFileIds.has(id) && validFileIds.has(id);
|
|
213
|
+
});
|
|
214
|
+
} });
|
|
195
215
|
}
|
|
196
|
-
export
|
|
216
|
+
export var persistentSelectStore = createPersistentSelectStore();
|
|
197
217
|
// Add this function to map IDs back to FileSystemItem objects
|
|
198
218
|
function getSelectedFiles(selectedIds, files) {
|
|
199
219
|
// Create a map for O(1) lookup of files by ID
|
|
200
|
-
|
|
201
|
-
return selectedIds.filter(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); });
|
|
202
222
|
}
|
|
203
223
|
// Update the derived store to return FileSystemItem[] instead of string[]
|
|
204
|
-
export
|
|
205
|
-
|
|
224
|
+
export var validSelections = derived([persistentSelectStore, missingFiles], function (_a) {
|
|
225
|
+
var $selections = _a[0], $missingFiles = _a[1];
|
|
226
|
+
return function (filterType, files) {
|
|
206
227
|
// Get IDs of selected files for current filter
|
|
207
|
-
|
|
228
|
+
var selectedIds = $selections[filterType] || [];
|
|
208
229
|
// Create a map of files by ID for quick lookup
|
|
209
|
-
|
|
230
|
+
var fileMap = new Map(files.map(function (file) { return [file.id, file]; }));
|
|
210
231
|
// Filter out missing files and files not present in the provided files array
|
|
211
|
-
|
|
232
|
+
var validIds = selectedIds.filter(function (id) {
|
|
233
|
+
return !$missingFiles.has(id) && fileMap.has(id);
|
|
234
|
+
});
|
|
212
235
|
// Get the file objects for valid IDs
|
|
213
|
-
|
|
236
|
+
var validFiles = validIds.map(function (id) { return fileMap.get(id); });
|
|
214
237
|
// Log the results for debugging
|
|
215
238
|
if (DEBUG_LOGGING)
|
|
216
|
-
console.log(
|
|
239
|
+
console.log("validSelections for ".concat(filterType, ": ").concat(validFiles.length, " files out of ").concat(selectedIds.length, " selected IDs"));
|
|
217
240
|
return validFiles;
|
|
218
241
|
};
|
|
219
242
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { writable } from 'svelte/store';
|
|
2
|
-
export
|
|
2
|
+
export var searchTermStore = writable('');
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/** Why the Widgetic API is about to be called with a token. `expired` means the API just refused the previous one. */
|
|
2
|
+
export type UploadTokenReason = 'initial' | 'expired';
|
|
1
3
|
export type FileBrowserUploadConfig = {
|
|
2
4
|
apiBasePath: string;
|
|
3
5
|
accessToken: string;
|
|
6
|
+
/**
|
|
7
|
+
* Gives the token to call the API with, so a page whose session is renewed while the File Browser is open never
|
|
8
|
+
* sends a stale one (the `accessToken` above is only what the page held when it set the config). Called before every
|
|
9
|
+
* request, and again with `'expired'` (and the token that was refused) when the API answers 401: the request is then
|
|
10
|
+
* tried once more with the token that comes back. Same contract as `getAccessToken` of `createWidgeticMediaLibrary`.
|
|
11
|
+
* Left out, `accessToken` is used as it is.
|
|
12
|
+
*/
|
|
13
|
+
getAccessToken?: (reason: UploadTokenReason, refusedToken?: string) => Promise<string> | string;
|
|
4
14
|
contextType?: 'widget-codegen' | 'browser-ic' | 'content-property';
|
|
5
15
|
source?: string;
|
|
6
16
|
widgetId?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writable, get } from 'svelte/store';
|
|
2
2
|
import { setCacheOwner } from '@widgetic/cache-layer';
|
|
3
|
-
export
|
|
3
|
+
export var 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
|
+
var payloadPart = accessToken.split('.')[1];
|
|
13
13
|
if (!payloadPart)
|
|
14
14
|
return null;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
var normalized = payloadPart.replace(/-/g, '+').replace(/_/g, '/');
|
|
16
|
+
var payload = JSON.parse(atob(normalized));
|
|
17
17
|
return payload.sub || payload.userId || null;
|
|
18
18
|
}
|
|
19
|
-
catch {
|
|
19
|
+
catch (_a) {
|
|
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
|
|
27
|
+
if (!(config === null || config === void 0 ? void 0 : config.enableLocalCache))
|
|
28
28
|
return;
|
|
29
|
-
|
|
29
|
+
var 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 var isMobileStore = readable(browser ? window.innerWidth <= 768 : false, function (set) {
|
|
8
8
|
if (!browser)
|
|
9
9
|
return;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
var mediaQueryList = window.matchMedia('(max-width: 768px)');
|
|
11
|
+
var handleMediaQueryChange = function (event) {
|
|
12
12
|
set(event.matches);
|
|
13
13
|
};
|
|
14
14
|
set(mediaQueryList.matches);
|
|
15
15
|
mediaQueryList.addEventListener('change', handleMediaQueryChange);
|
|
16
|
-
return ()
|
|
16
|
+
return function () {
|
|
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
|
+
var API_HOST = import.meta.env.VITE_API_HOST || 'localhost';
|
|
4
|
+
var API_PORT = import.meta.env.VITE_API_PORT || '5201';
|
|
5
5
|
// Base API URL construction
|
|
6
|
-
export
|
|
6
|
+
export var API_BASE_URL = "http://".concat(API_HOST, ":").concat(API_PORT);
|
|
7
7
|
// API endpoints
|
|
8
|
-
export
|
|
9
|
-
FILES:
|
|
10
|
-
FILE:
|
|
11
|
-
FILE_MOVE:
|
|
12
|
-
CREATE_FOLDER:
|
|
13
|
-
UPLOAD:
|
|
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
|
|
14
14
|
// Add other endpoints as needed
|
|
15
15
|
};
|
|
16
16
|
// Logging helper for debugging
|
|
@@ -1,22 +1,31 @@
|
|
|
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
|
+
};
|
|
4
15
|
import { dedupeTreeIds, findItemByIdInTree } from './libraryTree';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
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';
|
|
8
19
|
function folderIdFor(path) {
|
|
9
|
-
return
|
|
20
|
+
return "fld_brand_".concat(path.map(function (p) { return p.toLowerCase().replace(/\s+/g, '_'); }).join('/'));
|
|
10
21
|
}
|
|
11
22
|
function cloneChildren(children) {
|
|
12
|
-
return children.map((item)
|
|
13
|
-
...item,
|
|
14
|
-
children: item.children ? cloneChildren(item.children) : undefined
|
|
15
|
-
}));
|
|
23
|
+
return children.map(function (item) { return (__assign(__assign({}, item), { children: item.children ? cloneChildren(item.children) : undefined })); });
|
|
16
24
|
}
|
|
17
25
|
function namesInFolder(children) {
|
|
18
|
-
|
|
19
|
-
for (
|
|
26
|
+
var out = new Set();
|
|
27
|
+
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
28
|
+
var item = children_1[_i];
|
|
20
29
|
if (item.type === 'file')
|
|
21
30
|
out.add(item.name.toLowerCase());
|
|
22
31
|
}
|
|
@@ -24,33 +33,35 @@ function namesInFolder(children) {
|
|
|
24
33
|
}
|
|
25
34
|
/** `name (2).ext` when another file in the folder already uses `name.ext`. */
|
|
26
35
|
export function resolveCollisionFileName(desiredName, takenLower) {
|
|
36
|
+
var _a, _b;
|
|
27
37
|
if (!takenLower.has(desiredName.toLowerCase()))
|
|
28
38
|
return desiredName;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
|
33
43
|
for (;;) {
|
|
34
|
-
|
|
44
|
+
var candidate = "".concat(stem, " (").concat(n, ")").concat(ext);
|
|
35
45
|
if (!takenLower.has(candidate.toLowerCase()))
|
|
36
46
|
return candidate;
|
|
37
47
|
n += 1;
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
function findChildFolder(children, name) {
|
|
41
|
-
|
|
42
|
-
for (
|
|
51
|
+
var lower = name.toLowerCase();
|
|
52
|
+
for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
|
|
53
|
+
var child = children_2[_i];
|
|
43
54
|
if (child.type === 'folder' && child.name.toLowerCase() === lower)
|
|
44
55
|
return child;
|
|
45
56
|
}
|
|
46
57
|
return null;
|
|
47
58
|
}
|
|
48
59
|
function ensureFolderPath(rootChildren, path) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
54
65
|
if (!folder) {
|
|
55
66
|
folder = {
|
|
56
67
|
id: folderIdFor(path.slice(0, i + 1)),
|
|
@@ -67,12 +78,14 @@ function ensureFolderPath(rootChildren, path) {
|
|
|
67
78
|
return next;
|
|
68
79
|
}
|
|
69
80
|
function removeFileById(items, id) {
|
|
70
|
-
|
|
71
|
-
|
|
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];
|
|
72
85
|
if (item.type === 'file' && item.id === id)
|
|
73
86
|
continue;
|
|
74
|
-
if (item.type === 'folder' && item.children
|
|
75
|
-
out.push({
|
|
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) }));
|
|
76
89
|
}
|
|
77
90
|
else {
|
|
78
91
|
out.push(item);
|
|
@@ -81,9 +94,10 @@ function removeFileById(items, id) {
|
|
|
81
94
|
return out;
|
|
82
95
|
}
|
|
83
96
|
function folderChildrenAtPath(rootChildren, path) {
|
|
84
|
-
|
|
85
|
-
for (
|
|
86
|
-
|
|
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);
|
|
87
101
|
if (!folder)
|
|
88
102
|
return null;
|
|
89
103
|
if (!folder.children)
|
|
@@ -102,34 +116,35 @@ export function brandLogoFolderPath() {
|
|
|
102
116
|
* Moves or inserts a file into the tree under `folderPath`, setting `name` to `displayName` (collision suffix applied).
|
|
103
117
|
*/
|
|
104
118
|
export function placeBrandKitFileInTree(rootChildren, input) {
|
|
105
|
-
|
|
119
|
+
var _a, _b, _c, _d, _e;
|
|
120
|
+
var tree = ensureFolderPath(rootChildren !== null && rootChildren !== void 0 ? rootChildren : [], input.folderPath);
|
|
106
121
|
tree = removeFileById(tree, input.uploadId);
|
|
107
|
-
|
|
122
|
+
var targetChildren = folderChildrenAtPath(tree, input.folderPath);
|
|
108
123
|
if (!targetChildren)
|
|
109
124
|
return tree;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
var taken = namesInFolder(targetChildren);
|
|
126
|
+
var name = resolveCollisionFileName(input.displayName, taken);
|
|
127
|
+
var file = {
|
|
113
128
|
id: input.uploadId,
|
|
114
|
-
name,
|
|
129
|
+
name: name,
|
|
115
130
|
type: 'file',
|
|
116
|
-
modified: input.file
|
|
117
|
-
size: input.file
|
|
118
|
-
url: input.file
|
|
119
|
-
mimeType: input.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
|
|
120
135
|
};
|
|
121
136
|
targetChildren.push(file);
|
|
122
137
|
return dedupeTreeIds(tree);
|
|
123
138
|
}
|
|
124
139
|
/** Removes a file id wherever it sits in the tree (optimistic delete). */
|
|
125
140
|
export function removeBrandKitFileFromTree(rootChildren, uploadId) {
|
|
126
|
-
if (!rootChildren
|
|
141
|
+
if (!(rootChildren === null || rootChildren === void 0 ? void 0 : rootChildren.length))
|
|
127
142
|
return [];
|
|
128
143
|
return dedupeTreeIds(removeFileById(rootChildren, uploadId));
|
|
129
144
|
}
|
|
130
145
|
export function treeContainsUploadId(rootChildren, uploadId) {
|
|
131
|
-
if (!rootChildren
|
|
146
|
+
if (!(rootChildren === null || rootChildren === void 0 ? void 0 : rootChildren.length))
|
|
132
147
|
return false;
|
|
133
|
-
|
|
148
|
+
var root = { id: 'root', name: 'Root', type: 'folder', children: rootChildren };
|
|
134
149
|
return Boolean(findItemByIdInTree(root, uploadId));
|
|
135
150
|
}
|