@noya-app/noya-file-explorer 0.0.18 → 0.0.20
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 +17 -0
- package/dist/index.css +850 -8
- 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.js
CHANGED
|
@@ -1122,6 +1122,8 @@ __export(src_exports, {
|
|
|
1122
1122
|
createMediaItem: () => createMediaItem,
|
|
1123
1123
|
createMediaItemTree: () => createMediaItemTree,
|
|
1124
1124
|
deleteResources: () => deleteResources,
|
|
1125
|
+
getContentTypeFromExtension: () => getContentTypeFromExtension,
|
|
1126
|
+
getContentTypeFromFile: () => getContentTypeFromFile,
|
|
1125
1127
|
getDepthMap: () => getDepthMap,
|
|
1126
1128
|
getParentDirectories: () => getParentDirectories,
|
|
1127
1129
|
getVisibleItems: () => getVisibleItems,
|
|
@@ -1988,11 +1990,12 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1988
1990
|
const parentPath = tree.idToPathMap.get(selectedId);
|
|
1989
1991
|
if (!parentPath) return;
|
|
1990
1992
|
const uploadPromises = files.map(async (file) => {
|
|
1991
|
-
const
|
|
1993
|
+
const created = await assetManager.create(file);
|
|
1994
|
+
const assetStableId = created.id;
|
|
1992
1995
|
const assetPath = import_imfs4.path.join(parentPath, import_imfs4.path.basename(file.name));
|
|
1993
1996
|
return {
|
|
1994
1997
|
assetPath,
|
|
1995
|
-
asset: createMediaAsset({ assetId:
|
|
1998
|
+
asset: createMediaAsset({ assetId: assetStableId })
|
|
1996
1999
|
};
|
|
1997
2000
|
});
|
|
1998
2001
|
setIsUploading(true);
|
|
@@ -2022,7 +2025,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
2022
2025
|
const handleDownload = (0, import_react.useCallback)(
|
|
2023
2026
|
async (selectedItems) => {
|
|
2024
2027
|
const downloadPromises = selectedItems.filter((item) => item.kind === "asset").map(async (item) => {
|
|
2025
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2028
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2026
2029
|
if (!asset?.url) return;
|
|
2027
2030
|
return (0, import_react_utils.downloadUrl)(asset.url, tree.getNameForId(item.id));
|
|
2028
2031
|
});
|
|
@@ -2033,7 +2036,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
2033
2036
|
const handlePreview = (0, import_react.useCallback)(
|
|
2034
2037
|
async (selectedItems) => {
|
|
2035
2038
|
const previewPromises = selectedItems.filter((item) => item.kind === "asset").map(async (item) => {
|
|
2036
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2039
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2037
2040
|
if (!asset?.url) return;
|
|
2038
2041
|
return window?.open(asset.url, "_blank");
|
|
2039
2042
|
});
|
|
@@ -2046,7 +2049,8 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
2046
2049
|
try {
|
|
2047
2050
|
const file = await (0, import_browser_fs_access.fileOpen)();
|
|
2048
2051
|
if (!file) return;
|
|
2049
|
-
const
|
|
2052
|
+
const created = await assetManager.create(file);
|
|
2053
|
+
const assetStableId = created.id;
|
|
2050
2054
|
const oldFile = selectedItem;
|
|
2051
2055
|
const oldFilePath = tree.idToPathMap.get(oldFile.id);
|
|
2052
2056
|
if (!oldFilePath || oldFile.kind !== "asset") return;
|
|
@@ -2056,7 +2060,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
2056
2060
|
...media,
|
|
2057
2061
|
[oldFilePath]: createMediaAsset({
|
|
2058
2062
|
...oldFile,
|
|
2059
|
-
assetId:
|
|
2063
|
+
assetId: assetStableId
|
|
2060
2064
|
})
|
|
2061
2065
|
}
|
|
2062
2066
|
);
|
|
@@ -2316,7 +2320,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
2316
2320
|
renderAction,
|
|
2317
2321
|
renderDetail: (file, selected) => {
|
|
2318
2322
|
if (file.kind !== "asset") return null;
|
|
2319
|
-
const asset = assets.find((a) => a.id === file.assetId);
|
|
2323
|
+
const asset = assets.find((a) => a.stableId === file.assetId) ?? assets.find((a) => a.id === file.assetId);
|
|
2320
2324
|
if (!asset) return null;
|
|
2321
2325
|
return /* @__PURE__ */ import_react2.default.createElement(import_noya_designsystem.FileExplorerDetail, { selected, size }, (0, import_noya_designsystem.formatByteSize)(asset.size));
|
|
2322
2326
|
},
|
|
@@ -2404,6 +2408,82 @@ var import_react3 = require("react");
|
|
|
2404
2408
|
var import_imfs6 = require("imfs");
|
|
2405
2409
|
var import_react4 = __toESM(require("react"));
|
|
2406
2410
|
|
|
2411
|
+
// src/utils/contentType.ts
|
|
2412
|
+
function getContentTypeFromFile(file) {
|
|
2413
|
+
if (file.type) {
|
|
2414
|
+
return file.type;
|
|
2415
|
+
}
|
|
2416
|
+
const extension = file.name.split(".").pop()?.toLowerCase();
|
|
2417
|
+
return getContentTypeFromExtension(extension);
|
|
2418
|
+
}
|
|
2419
|
+
function getContentTypeFromExtension(extension) {
|
|
2420
|
+
if (!extension) {
|
|
2421
|
+
return "application/octet-stream";
|
|
2422
|
+
}
|
|
2423
|
+
const extensionToMimeType = {
|
|
2424
|
+
// Text files
|
|
2425
|
+
md: "text/markdown",
|
|
2426
|
+
markdown: "text/markdown",
|
|
2427
|
+
txt: "text/plain",
|
|
2428
|
+
json: "application/json",
|
|
2429
|
+
xml: "application/xml",
|
|
2430
|
+
csv: "text/csv",
|
|
2431
|
+
html: "text/html",
|
|
2432
|
+
htm: "text/html",
|
|
2433
|
+
css: "text/css",
|
|
2434
|
+
js: "text/javascript",
|
|
2435
|
+
mjs: "text/javascript",
|
|
2436
|
+
ts: "text/typescript",
|
|
2437
|
+
tsx: "text/typescript",
|
|
2438
|
+
jsx: "text/javascript",
|
|
2439
|
+
// Images
|
|
2440
|
+
svg: "image/svg+xml",
|
|
2441
|
+
png: "image/png",
|
|
2442
|
+
jpg: "image/jpeg",
|
|
2443
|
+
jpeg: "image/jpeg",
|
|
2444
|
+
gif: "image/gif",
|
|
2445
|
+
webp: "image/webp",
|
|
2446
|
+
bmp: "image/bmp",
|
|
2447
|
+
ico: "image/x-icon",
|
|
2448
|
+
tiff: "image/tiff",
|
|
2449
|
+
tif: "image/tiff",
|
|
2450
|
+
// Documents
|
|
2451
|
+
pdf: "application/pdf",
|
|
2452
|
+
doc: "application/msword",
|
|
2453
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
2454
|
+
xls: "application/vnd.ms-excel",
|
|
2455
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
2456
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
2457
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
2458
|
+
// Audio
|
|
2459
|
+
mp3: "audio/mpeg",
|
|
2460
|
+
wav: "audio/wav",
|
|
2461
|
+
ogg: "audio/ogg",
|
|
2462
|
+
m4a: "audio/mp4",
|
|
2463
|
+
flac: "audio/flac",
|
|
2464
|
+
// Video
|
|
2465
|
+
mp4: "video/mp4",
|
|
2466
|
+
webm: "video/webm",
|
|
2467
|
+
mov: "video/quicktime",
|
|
2468
|
+
avi: "video/x-msvideo",
|
|
2469
|
+
mkv: "video/x-matroska",
|
|
2470
|
+
// Archives
|
|
2471
|
+
zip: "application/zip",
|
|
2472
|
+
tar: "application/x-tar",
|
|
2473
|
+
gz: "application/gzip",
|
|
2474
|
+
"7z": "application/x-7z-compressed",
|
|
2475
|
+
rar: "application/vnd.rar",
|
|
2476
|
+
// Fonts
|
|
2477
|
+
woff: "font/woff",
|
|
2478
|
+
woff2: "font/woff2",
|
|
2479
|
+
ttf: "font/ttf",
|
|
2480
|
+
otf: "font/otf",
|
|
2481
|
+
// Other
|
|
2482
|
+
sketch: "application/x-sketch"
|
|
2483
|
+
};
|
|
2484
|
+
return extensionToMimeType[extension] || "application/octet-stream";
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2407
2487
|
// src/utils/handleFileDrop.ts
|
|
2408
2488
|
var import_noya_schemas2 = require("@noya-app/noya-schemas");
|
|
2409
2489
|
var import_noya_utils3 = require("@noya-app/noya-utils");
|
|
@@ -2512,7 +2592,7 @@ async function handleDataTransfer({
|
|
|
2512
2592
|
id: (0, import_noya_utils3.uuid)(),
|
|
2513
2593
|
asset: {
|
|
2514
2594
|
content: import_noya_utils3.Base64.encode(await file.arrayBuffer()),
|
|
2515
|
-
contentType: file
|
|
2595
|
+
contentType: getContentTypeFromFile(file),
|
|
2516
2596
|
encoding: "base64"
|
|
2517
2597
|
},
|
|
2518
2598
|
path: import_imfs5.path.join(rootItemPath, relativePath),
|
|
@@ -2615,7 +2695,8 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2615
2695
|
itemStyle,
|
|
2616
2696
|
publishedResources,
|
|
2617
2697
|
virtualized = false,
|
|
2618
|
-
renderUser
|
|
2698
|
+
renderUser,
|
|
2699
|
+
showFileSizes = true
|
|
2619
2700
|
}, ref) {
|
|
2620
2701
|
const setMedia = (0, import_react3.useCallback)(
|
|
2621
2702
|
(...args) => {
|
|
@@ -2830,7 +2911,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2830
2911
|
id: (0, import_noya_utils4.uuid)(),
|
|
2831
2912
|
asset: {
|
|
2832
2913
|
content: import_noya_utils4.Base64.encode(await file.arrayBuffer()),
|
|
2833
|
-
contentType: file
|
|
2914
|
+
contentType: getContentTypeFromFile(file),
|
|
2834
2915
|
encoding: "base64"
|
|
2835
2916
|
},
|
|
2836
2917
|
path: assetPath,
|
|
@@ -2866,7 +2947,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2866
2947
|
const handleDownload = (0, import_react3.useCallback)(
|
|
2867
2948
|
async (selectedItems) => {
|
|
2868
2949
|
const downloadPromises = selectedItems.filter((item) => item.type === "asset").map(async (item) => {
|
|
2869
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2950
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2870
2951
|
if (!asset?.url) return;
|
|
2871
2952
|
return (0, import_react_utils2.downloadUrl)(asset.url, tree.getNameForId(item.id));
|
|
2872
2953
|
});
|
|
@@ -2877,7 +2958,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2877
2958
|
const handlePreview = (0, import_react3.useCallback)(
|
|
2878
2959
|
async (selectedItems) => {
|
|
2879
2960
|
const previewPromises = selectedItems.filter((item) => item.type === "asset").map(async (item) => {
|
|
2880
|
-
const asset = assets.find((a) => a.id === item.assetId);
|
|
2961
|
+
const asset = assets.find((a) => a.stableId === item.assetId) ?? assets.find((a) => a.id === item.assetId);
|
|
2881
2962
|
if (!asset?.url) return;
|
|
2882
2963
|
return window?.open(asset.url, "_blank");
|
|
2883
2964
|
});
|
|
@@ -2890,7 +2971,8 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2890
2971
|
try {
|
|
2891
2972
|
const file = await (0, import_browser_fs_access2.fileOpen)();
|
|
2892
2973
|
if (!file) return;
|
|
2893
|
-
const
|
|
2974
|
+
const created = await assetManager.create(file);
|
|
2975
|
+
const assetStableId = created.id;
|
|
2894
2976
|
const oldFile = selectedItem;
|
|
2895
2977
|
const oldFilePath = tree.idToPathMap.get(oldFile.id);
|
|
2896
2978
|
if (!oldFilePath || oldFile.type !== "asset") return;
|
|
@@ -2900,7 +2982,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
2900
2982
|
...media,
|
|
2901
2983
|
[oldFilePath]: (0, import_noya_schemas3.createAssetResource)({
|
|
2902
2984
|
...oldFile,
|
|
2903
|
-
assetId:
|
|
2985
|
+
assetId: assetStableId
|
|
2904
2986
|
})
|
|
2905
2987
|
}
|
|
2906
2988
|
);
|
|
@@ -3146,6 +3228,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
3146
3228
|
},
|
|
3147
3229
|
getExpanded,
|
|
3148
3230
|
setExpanded: handleSetExpanded,
|
|
3231
|
+
renameSelectsBeforeDot: true,
|
|
3149
3232
|
getRenamable: (item) => {
|
|
3150
3233
|
if (item.id === import_noya_schemas3.rootResource.id) return false;
|
|
3151
3234
|
return true;
|
|
@@ -3184,7 +3267,7 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
3184
3267
|
return /* @__PURE__ */ import_react4.default.createElement(
|
|
3185
3268
|
"div",
|
|
3186
3269
|
{
|
|
3187
|
-
style: { display: "flex", alignItems: "center", gap: "
|
|
3270
|
+
style: { display: "flex", alignItems: "center", gap: "6px" }
|
|
3188
3271
|
},
|
|
3189
3272
|
publishStatus && /* @__PURE__ */ import_react4.default.createElement(
|
|
3190
3273
|
import_noya_designsystem2.Chip,
|
|
@@ -3197,8 +3280,9 @@ var ResourceExplorer = (0, import_react3.memo)(
|
|
|
3197
3280
|
);
|
|
3198
3281
|
},
|
|
3199
3282
|
renderDetail: (file, selected) => {
|
|
3283
|
+
if (!showFileSizes) return null;
|
|
3200
3284
|
if (file.type !== "asset") return null;
|
|
3201
|
-
const asset = assets.find((a) => a.id === file.assetId);
|
|
3285
|
+
const asset = assets.find((a) => a.stableId === file.assetId) ?? assets.find((a) => a.id === file.assetId);
|
|
3202
3286
|
if (!asset) return null;
|
|
3203
3287
|
return /* @__PURE__ */ import_react4.default.createElement(
|
|
3204
3288
|
import_noya_designsystem2.FileExplorerDetail,
|
|
@@ -3345,6 +3429,8 @@ function getPublishStatus({
|
|
|
3345
3429
|
createMediaItem,
|
|
3346
3430
|
createMediaItemTree,
|
|
3347
3431
|
deleteResources,
|
|
3432
|
+
getContentTypeFromExtension,
|
|
3433
|
+
getContentTypeFromFile,
|
|
3348
3434
|
getDepthMap,
|
|
3349
3435
|
getParentDirectories,
|
|
3350
3436
|
getVisibleItems,
|