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