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