@noya-app/noya-file-explorer 0.0.19 → 0.0.21
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/.turbo/turbo-build.log +11 -11
- package/CHANGELOG.md +19 -0
- package/dist/index.css +850 -11
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +22 -8
- package/dist/index.d.ts +22 -8
- package/dist/index.js +102 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/MediaCollection.tsx +25 -17
- package/src/ResourceExplorer.tsx +20 -8
- package/src/index.ts +1 -0
- package/src/utils/contentType.ts +99 -0
- package/src/utils/handleFileDrop.ts +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1981,11 +1981,12 @@ var MediaCollection = memo(
|
|
|
1981
1981
|
const parentPath = tree.idToPathMap.get(selectedId);
|
|
1982
1982
|
if (!parentPath) return;
|
|
1983
1983
|
const uploadPromises = files.map(async (file) => {
|
|
1984
|
-
const
|
|
1984
|
+
const created = await assetManager.create(file);
|
|
1985
|
+
const assetStableId = created.id;
|
|
1985
1986
|
const assetPath = path4.join(parentPath, path4.basename(file.name));
|
|
1986
1987
|
return {
|
|
1987
1988
|
assetPath,
|
|
1988
|
-
asset: createMediaAsset({ assetId:
|
|
1989
|
+
asset: createMediaAsset({ assetId: assetStableId })
|
|
1989
1990
|
};
|
|
1990
1991
|
});
|
|
1991
1992
|
setIsUploading(true);
|
|
@@ -2015,7 +2016,7 @@ var MediaCollection = memo(
|
|
|
2015
2016
|
const handleDownload = useCallback(
|
|
2016
2017
|
async (selectedItems) => {
|
|
2017
2018
|
const downloadPromises = selectedItems.filter((item) => item.kind === "asset").map(async (item) => {
|
|
2018
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2019
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2019
2020
|
if (!asset?.url) return;
|
|
2020
2021
|
return downloadUrl(asset.url, tree.getNameForId(item.id));
|
|
2021
2022
|
});
|
|
@@ -2026,7 +2027,7 @@ var MediaCollection = memo(
|
|
|
2026
2027
|
const handlePreview = useCallback(
|
|
2027
2028
|
async (selectedItems) => {
|
|
2028
2029
|
const previewPromises = selectedItems.filter((item) => item.kind === "asset").map(async (item) => {
|
|
2029
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2030
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2030
2031
|
if (!asset?.url) return;
|
|
2031
2032
|
return window?.open(asset.url, "_blank");
|
|
2032
2033
|
});
|
|
@@ -2039,7 +2040,8 @@ var MediaCollection = memo(
|
|
|
2039
2040
|
try {
|
|
2040
2041
|
const file = await fileOpen();
|
|
2041
2042
|
if (!file) return;
|
|
2042
|
-
const
|
|
2043
|
+
const created = await assetManager.create(file);
|
|
2044
|
+
const assetStableId = created.id;
|
|
2043
2045
|
const oldFile = selectedItem;
|
|
2044
2046
|
const oldFilePath = tree.idToPathMap.get(oldFile.id);
|
|
2045
2047
|
if (!oldFilePath || oldFile.kind !== "asset") return;
|
|
@@ -2049,7 +2051,7 @@ var MediaCollection = memo(
|
|
|
2049
2051
|
...media,
|
|
2050
2052
|
[oldFilePath]: createMediaAsset({
|
|
2051
2053
|
...oldFile,
|
|
2052
|
-
assetId:
|
|
2054
|
+
assetId: assetStableId
|
|
2053
2055
|
})
|
|
2054
2056
|
}
|
|
2055
2057
|
);
|
|
@@ -2309,7 +2311,7 @@ var MediaCollection = memo(
|
|
|
2309
2311
|
renderAction,
|
|
2310
2312
|
renderDetail: (file, selected) => {
|
|
2311
2313
|
if (file.kind !== "asset") return null;
|
|
2312
|
-
const asset = assets.find((a) => a.id === file.assetId);
|
|
2314
|
+
const asset = assets.find((a) => a.stableId === file.assetId) ?? assets.find((a) => a.id === file.assetId);
|
|
2313
2315
|
if (!asset) return null;
|
|
2314
2316
|
return /* @__PURE__ */ React.createElement(FileExplorerDetail, { selected, size }, formatByteSize(asset.size));
|
|
2315
2317
|
},
|
|
@@ -2445,6 +2447,82 @@ import {
|
|
|
2445
2447
|
import { path as path6 } from "imfs";
|
|
2446
2448
|
import React2 from "react";
|
|
2447
2449
|
|
|
2450
|
+
// src/utils/contentType.ts
|
|
2451
|
+
function getContentTypeFromFile(file) {
|
|
2452
|
+
if (file.type) {
|
|
2453
|
+
return file.type;
|
|
2454
|
+
}
|
|
2455
|
+
const extension = file.name.split(".").pop()?.toLowerCase();
|
|
2456
|
+
return getContentTypeFromExtension(extension);
|
|
2457
|
+
}
|
|
2458
|
+
function getContentTypeFromExtension(extension) {
|
|
2459
|
+
if (!extension) {
|
|
2460
|
+
return "application/octet-stream";
|
|
2461
|
+
}
|
|
2462
|
+
const extensionToMimeType = {
|
|
2463
|
+
// Text files
|
|
2464
|
+
md: "text/markdown",
|
|
2465
|
+
markdown: "text/markdown",
|
|
2466
|
+
txt: "text/plain",
|
|
2467
|
+
json: "application/json",
|
|
2468
|
+
xml: "application/xml",
|
|
2469
|
+
csv: "text/csv",
|
|
2470
|
+
html: "text/html",
|
|
2471
|
+
htm: "text/html",
|
|
2472
|
+
css: "text/css",
|
|
2473
|
+
js: "text/javascript",
|
|
2474
|
+
mjs: "text/javascript",
|
|
2475
|
+
ts: "text/typescript",
|
|
2476
|
+
tsx: "text/typescript",
|
|
2477
|
+
jsx: "text/javascript",
|
|
2478
|
+
// Images
|
|
2479
|
+
svg: "image/svg+xml",
|
|
2480
|
+
png: "image/png",
|
|
2481
|
+
jpg: "image/jpeg",
|
|
2482
|
+
jpeg: "image/jpeg",
|
|
2483
|
+
gif: "image/gif",
|
|
2484
|
+
webp: "image/webp",
|
|
2485
|
+
bmp: "image/bmp",
|
|
2486
|
+
ico: "image/x-icon",
|
|
2487
|
+
tiff: "image/tiff",
|
|
2488
|
+
tif: "image/tiff",
|
|
2489
|
+
// Documents
|
|
2490
|
+
pdf: "application/pdf",
|
|
2491
|
+
doc: "application/msword",
|
|
2492
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
2493
|
+
xls: "application/vnd.ms-excel",
|
|
2494
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
2495
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
2496
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
2497
|
+
// Audio
|
|
2498
|
+
mp3: "audio/mpeg",
|
|
2499
|
+
wav: "audio/wav",
|
|
2500
|
+
ogg: "audio/ogg",
|
|
2501
|
+
m4a: "audio/mp4",
|
|
2502
|
+
flac: "audio/flac",
|
|
2503
|
+
// Video
|
|
2504
|
+
mp4: "video/mp4",
|
|
2505
|
+
webm: "video/webm",
|
|
2506
|
+
mov: "video/quicktime",
|
|
2507
|
+
avi: "video/x-msvideo",
|
|
2508
|
+
mkv: "video/x-matroska",
|
|
2509
|
+
// Archives
|
|
2510
|
+
zip: "application/zip",
|
|
2511
|
+
tar: "application/x-tar",
|
|
2512
|
+
gz: "application/gzip",
|
|
2513
|
+
"7z": "application/x-7z-compressed",
|
|
2514
|
+
rar: "application/vnd.rar",
|
|
2515
|
+
// Fonts
|
|
2516
|
+
woff: "font/woff",
|
|
2517
|
+
woff2: "font/woff2",
|
|
2518
|
+
ttf: "font/ttf",
|
|
2519
|
+
otf: "font/otf",
|
|
2520
|
+
// Other
|
|
2521
|
+
sketch: "application/x-sketch"
|
|
2522
|
+
};
|
|
2523
|
+
return extensionToMimeType[extension] || "application/octet-stream";
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2448
2526
|
// src/utils/handleFileDrop.ts
|
|
2449
2527
|
import {
|
|
2450
2528
|
createAssetResource,
|
|
@@ -2556,7 +2634,7 @@ async function handleDataTransfer({
|
|
|
2556
2634
|
id: uuid2(),
|
|
2557
2635
|
asset: {
|
|
2558
2636
|
content: Base64.encode(await file.arrayBuffer()),
|
|
2559
|
-
contentType: file
|
|
2637
|
+
contentType: getContentTypeFromFile(file),
|
|
2560
2638
|
encoding: "base64"
|
|
2561
2639
|
},
|
|
2562
2640
|
path: path5.join(rootItemPath, relativePath),
|
|
@@ -2659,7 +2737,8 @@ var ResourceExplorer = memo2(
|
|
|
2659
2737
|
itemStyle,
|
|
2660
2738
|
publishedResources,
|
|
2661
2739
|
virtualized = false,
|
|
2662
|
-
renderUser
|
|
2740
|
+
renderUser,
|
|
2741
|
+
showFileSizes = true
|
|
2663
2742
|
}, ref) {
|
|
2664
2743
|
const setMedia = useCallback2(
|
|
2665
2744
|
(...args) => {
|
|
@@ -2874,7 +2953,7 @@ var ResourceExplorer = memo2(
|
|
|
2874
2953
|
id: uuid3(),
|
|
2875
2954
|
asset: {
|
|
2876
2955
|
content: Base642.encode(await file.arrayBuffer()),
|
|
2877
|
-
contentType: file
|
|
2956
|
+
contentType: getContentTypeFromFile(file),
|
|
2878
2957
|
encoding: "base64"
|
|
2879
2958
|
},
|
|
2880
2959
|
path: assetPath,
|
|
@@ -2910,7 +2989,7 @@ var ResourceExplorer = memo2(
|
|
|
2910
2989
|
const handleDownload = useCallback2(
|
|
2911
2990
|
async (selectedItems) => {
|
|
2912
2991
|
const downloadPromises = selectedItems.filter((item) => item.type === "asset").map(async (item) => {
|
|
2913
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2992
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2914
2993
|
if (!asset?.url) return;
|
|
2915
2994
|
return downloadUrl2(asset.url, tree.getNameForId(item.id));
|
|
2916
2995
|
});
|
|
@@ -2921,7 +3000,7 @@ var ResourceExplorer = memo2(
|
|
|
2921
3000
|
const handlePreview = useCallback2(
|
|
2922
3001
|
async (selectedItems) => {
|
|
2923
3002
|
const previewPromises = selectedItems.filter((item) => item.type === "asset").map(async (item) => {
|
|
2924
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
3003
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2925
3004
|
if (!asset?.url) return;
|
|
2926
3005
|
return window?.open(asset.url, "_blank");
|
|
2927
3006
|
});
|
|
@@ -2934,7 +3013,8 @@ var ResourceExplorer = memo2(
|
|
|
2934
3013
|
try {
|
|
2935
3014
|
const file = await fileOpen2();
|
|
2936
3015
|
if (!file) return;
|
|
2937
|
-
const
|
|
3016
|
+
const created = await assetManager.create(file);
|
|
3017
|
+
const assetStableId = created.id;
|
|
2938
3018
|
const oldFile = selectedItem;
|
|
2939
3019
|
const oldFilePath = tree.idToPathMap.get(oldFile.id);
|
|
2940
3020
|
if (!oldFilePath || oldFile.type !== "asset") return;
|
|
@@ -2944,7 +3024,7 @@ var ResourceExplorer = memo2(
|
|
|
2944
3024
|
...media,
|
|
2945
3025
|
[oldFilePath]: createAssetResource2({
|
|
2946
3026
|
...oldFile,
|
|
2947
|
-
assetId:
|
|
3027
|
+
assetId: assetStableId
|
|
2948
3028
|
})
|
|
2949
3029
|
}
|
|
2950
3030
|
);
|
|
@@ -3190,6 +3270,7 @@ var ResourceExplorer = memo2(
|
|
|
3190
3270
|
},
|
|
3191
3271
|
getExpanded,
|
|
3192
3272
|
setExpanded: handleSetExpanded,
|
|
3273
|
+
renameSelectsBeforeDot: true,
|
|
3193
3274
|
getRenamable: (item) => {
|
|
3194
3275
|
if (item.id === rootResource2.id) return false;
|
|
3195
3276
|
return true;
|
|
@@ -3228,7 +3309,7 @@ var ResourceExplorer = memo2(
|
|
|
3228
3309
|
return /* @__PURE__ */ React2.createElement(
|
|
3229
3310
|
"div",
|
|
3230
3311
|
{
|
|
3231
|
-
style: { display: "flex", alignItems: "center", gap: "
|
|
3312
|
+
style: { display: "flex", alignItems: "center", gap: "6px" }
|
|
3232
3313
|
},
|
|
3233
3314
|
publishStatus && /* @__PURE__ */ React2.createElement(
|
|
3234
3315
|
Chip,
|
|
@@ -3241,8 +3322,9 @@ var ResourceExplorer = memo2(
|
|
|
3241
3322
|
);
|
|
3242
3323
|
},
|
|
3243
3324
|
renderDetail: (file, selected) => {
|
|
3325
|
+
if (!showFileSizes) return null;
|
|
3244
3326
|
if (file.type !== "asset") return null;
|
|
3245
|
-
const asset = assets.find((a) => a.id === file.assetId);
|
|
3327
|
+
const asset = assets.find((a) => a.stableId === file.assetId) ?? assets.find((a) => a.id === file.assetId);
|
|
3246
3328
|
if (!asset) return null;
|
|
3247
3329
|
return /* @__PURE__ */ React2.createElement(
|
|
3248
3330
|
FileExplorerDetail2,
|
|
@@ -3388,6 +3470,8 @@ export {
|
|
|
3388
3470
|
createMediaItem,
|
|
3389
3471
|
createMediaItemTree,
|
|
3390
3472
|
deleteResources,
|
|
3473
|
+
getContentTypeFromExtension,
|
|
3474
|
+
getContentTypeFromFile,
|
|
3391
3475
|
getDepthMap,
|
|
3392
3476
|
getParentDirectories,
|
|
3393
3477
|
getVisibleItems,
|