ssovee-os-web-ui 0.1.102 → 0.1.103
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/README.md +2 -2
- package/dist/index.cjs +89 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +3 -0
- package/dist/index.js +89 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ export function NoteEditor() {
|
|
|
107
107
|
|
|
108
108
|
### PreviewComponent
|
|
109
109
|
|
|
110
|
-
`PreviewComponent` previews a file from base64 data supplied by the host application. Pass either raw base64 or a complete data URL along with the original file name.
|
|
110
|
+
`PreviewComponent` previews a file from base64 data supplied by the host application. Pass either raw base64 or a complete data URL along with the original file name. Images, PDFs, text files, JSON, audio, and video use browser-native previews. Office and binary formats receive a download action because browsers cannot render them directly from base64 without a document parser.
|
|
111
111
|
|
|
112
112
|
```tsx
|
|
113
113
|
import { PreviewComponent } from "ssovee-os-web-ui";
|
|
@@ -123,7 +123,7 @@ export function FilePreview({ fileName, base64 }: { fileName: string; base64: st
|
|
|
123
123
|
}
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
Supported image extensions include `avif`, `bmp`, `gif`, `jpg`, `jpeg`, `png`, `svg`, and `webp`. Supported text extensions include `css`, `csv`, `html`, `js`, `jsx`, `md`, `ts`, `tsx`, `txt`, `xml`, `yaml`, and `yml
|
|
126
|
+
Supported image extensions include `avif`, `bmp`, `gif`, `heic`, `jpg`, `jpeg`, `png`, `svg`, `tif`, `tiff`, and `webp`. Supported text extensions include common `c`, `cpp`, `css`, `csv`, `env`, `html`, `java`, `js`, `jsx`, `md`, `php`, `py`, `rb`, `rs`, `sh`, `sql`, `ts`, `tsx`, `txt`, `xml`, `yaml`, and `yml` files. Audio and video include common `aac`, `flac`, `m4a`, `mp3`, `ogg`, `wav`, `avi`, `m4v`, `mkv`, `mov`, `mp4`, `mpeg`, `ogv`, `webm`, and `wmv` files. Office formats such as `doc`, `docx`, `xls`, `xlsx`, `ppt`, and `pptx`, plus archives such as `zip`, `7z`, and `rar`, are available to download.
|
|
127
127
|
|
|
128
128
|
## Window components
|
|
129
129
|
|
package/dist/index.cjs
CHANGED
|
@@ -2318,12 +2318,16 @@ var Tabs = ({
|
|
|
2318
2318
|
] });
|
|
2319
2319
|
};
|
|
2320
2320
|
var Tabs_default = Tabs;
|
|
2321
|
-
var imageExtensions = /\.(avif|bmp|gif|jpe?g|png|svg|webp)$/i;
|
|
2322
|
-
var textExtensions = /\.(css|csv|html?|js|jsx|md|mjs|ts|tsx|txt|xml|yaml|yml)$/i;
|
|
2321
|
+
var imageExtensions = /\.(avif|bmp|gif|heic|jpe?g|png|svg|tiff?|webp)$/i;
|
|
2322
|
+
var textExtensions = /\.(c|cc|conf|cpp|css|csv|env|h|hpp|html?|ini|java|js|jsx|log|md|mjs|php|py|rb|rs|sh|sql|swift|ts|tsx|txt|xml|yaml|yml)$/i;
|
|
2323
|
+
var audioExtensions = /\.(aac|flac|m4a|mp3|ogg|wav|weba)$/i;
|
|
2324
|
+
var videoExtensions = /\.(avi|m4v|mkv|mov|mp4|mpeg|ogv|webm|wmv)$/i;
|
|
2323
2325
|
var getPreviewType = (fileName) => {
|
|
2324
2326
|
if (/\.pdf$/i.test(fileName)) return "pdf";
|
|
2325
2327
|
if (/\.json$/i.test(fileName)) return "json";
|
|
2326
2328
|
if (imageExtensions.test(fileName)) return "image";
|
|
2329
|
+
if (audioExtensions.test(fileName)) return "audio";
|
|
2330
|
+
if (videoExtensions.test(fileName)) return "video";
|
|
2327
2331
|
if (textExtensions.test(fileName) || !fileName.includes(".")) return "text";
|
|
2328
2332
|
return "unsupported";
|
|
2329
2333
|
};
|
|
@@ -2333,12 +2337,40 @@ var getMimeType = (fileName) => {
|
|
|
2333
2337
|
avif: "image/avif",
|
|
2334
2338
|
bmp: "image/bmp",
|
|
2335
2339
|
gif: "image/gif",
|
|
2340
|
+
heic: "image/heic",
|
|
2336
2341
|
jpeg: "image/jpeg",
|
|
2337
2342
|
jpg: "image/jpeg",
|
|
2338
2343
|
png: "image/png",
|
|
2339
2344
|
svg: "image/svg+xml",
|
|
2345
|
+
tif: "image/tiff",
|
|
2346
|
+
tiff: "image/tiff",
|
|
2340
2347
|
webp: "image/webp",
|
|
2341
|
-
pdf: "application/pdf"
|
|
2348
|
+
pdf: "application/pdf",
|
|
2349
|
+
aac: "audio/aac",
|
|
2350
|
+
flac: "audio/flac",
|
|
2351
|
+
m4a: "audio/mp4",
|
|
2352
|
+
mp3: "audio/mpeg",
|
|
2353
|
+
ogg: "audio/ogg",
|
|
2354
|
+
wav: "audio/wav",
|
|
2355
|
+
weba: "audio/webm",
|
|
2356
|
+
avi: "video/x-msvideo",
|
|
2357
|
+
m4v: "video/mp4",
|
|
2358
|
+
mkv: "video/x-matroska",
|
|
2359
|
+
mov: "video/quicktime",
|
|
2360
|
+
mp4: "video/mp4",
|
|
2361
|
+
mpeg: "video/mpeg",
|
|
2362
|
+
ogv: "video/ogg",
|
|
2363
|
+
webm: "video/webm",
|
|
2364
|
+
wmv: "video/x-ms-wmv",
|
|
2365
|
+
doc: "application/msword",
|
|
2366
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
2367
|
+
xls: "application/vnd.ms-excel",
|
|
2368
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
2369
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
2370
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
2371
|
+
zip: "application/zip",
|
|
2372
|
+
"7z": "application/x-7z-compressed",
|
|
2373
|
+
rar: "application/vnd.rar"
|
|
2342
2374
|
};
|
|
2343
2375
|
return mimeTypes[extension ?? ""] ?? "application/octet-stream";
|
|
2344
2376
|
};
|
|
@@ -2351,33 +2383,69 @@ var decodeBase64 = (base64) => {
|
|
|
2351
2383
|
const bytes = Uint8Array.from(atob(value), (character) => character.charCodeAt(0));
|
|
2352
2384
|
return new TextDecoder().decode(bytes);
|
|
2353
2385
|
};
|
|
2354
|
-
var
|
|
2386
|
+
var toPdfBytes = (base64) => {
|
|
2355
2387
|
const value = base64.includes(",") ? base64.slice(base64.indexOf(",") + 1) : base64;
|
|
2356
|
-
|
|
2357
|
-
return new Blob([bytes], { type: "application/pdf" });
|
|
2388
|
+
return Uint8Array.from(atob(value), (character) => character.charCodeAt(0));
|
|
2358
2389
|
};
|
|
2359
2390
|
var PreviewComponent = ({ fileName, base64, className }) => {
|
|
2360
2391
|
const previewType = getPreviewType(fileName);
|
|
2361
2392
|
const dataUrl = toDataUrl(base64, fileName);
|
|
2362
|
-
const
|
|
2393
|
+
const pdfContainerRef = React24.useRef(null);
|
|
2394
|
+
const [pdfState, setPdfState] = React24.useState("loading");
|
|
2363
2395
|
React24.useEffect(() => {
|
|
2364
|
-
if (previewType !== "pdf" ||
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2396
|
+
if (previewType !== "pdf" || !pdfContainerRef.current) return;
|
|
2397
|
+
let cancelled = false;
|
|
2398
|
+
const container = pdfContainerRef.current;
|
|
2399
|
+
setPdfState("loading");
|
|
2400
|
+
container.replaceChildren();
|
|
2401
|
+
import('pdfjs-dist/legacy/build/pdf.mjs').then(async ({ getDocument }) => {
|
|
2402
|
+
const pdf = await getDocument({ data: toPdfBytes(base64) }).promise;
|
|
2403
|
+
for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber += 1) {
|
|
2404
|
+
if (cancelled) return;
|
|
2405
|
+
const page = await pdf.getPage(pageNumber);
|
|
2406
|
+
const viewport = page.getViewport({ scale: 1.35 });
|
|
2407
|
+
const canvas = document.createElement("canvas");
|
|
2408
|
+
const context = canvas.getContext("2d");
|
|
2409
|
+
if (!context) throw new Error("Canvas is not supported");
|
|
2410
|
+
canvas.width = viewport.width;
|
|
2411
|
+
canvas.height = viewport.height;
|
|
2412
|
+
canvas.setAttribute("aria-label", `${fileName}, page ${pageNumber}`);
|
|
2413
|
+
canvas.className = "mb-3 max-w-full shadow-sm";
|
|
2414
|
+
container.appendChild(canvas);
|
|
2415
|
+
await page.render({ canvas, canvasContext: context, viewport }).promise;
|
|
2416
|
+
}
|
|
2417
|
+
if (!cancelled) setPdfState("ready");
|
|
2418
|
+
}).catch(() => {
|
|
2419
|
+
if (!cancelled) setPdfState("error");
|
|
2420
|
+
});
|
|
2421
|
+
return () => {
|
|
2422
|
+
cancelled = true;
|
|
2423
|
+
container.replaceChildren();
|
|
2424
|
+
};
|
|
2425
|
+
}, [base64, fileName, previewType]);
|
|
2373
2426
|
if (previewType === "image") {
|
|
2374
2427
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex h-full min-h-48 w-full items-center justify-center overflow-auto", className), children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: dataUrl, alt: fileName, className: "max-h-full max-w-full object-contain" }) });
|
|
2375
2428
|
}
|
|
2376
2429
|
if (previewType === "pdf") {
|
|
2377
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
2378
|
-
"
|
|
2379
|
-
|
|
2380
|
-
|
|
2430
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex min-h-96 flex-col items-center overflow-auto p-3", className), children: [
|
|
2431
|
+
pdfState === "loading" && /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
2432
|
+
"Loading ",
|
|
2433
|
+
fileName,
|
|
2434
|
+
"..."
|
|
2435
|
+
] }),
|
|
2436
|
+
pdfState === "error" && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-3", children: "Unable to render this PDF." }),
|
|
2437
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: pdfContainerRef, className: "flex w-full flex-col items-center" }),
|
|
2438
|
+
/* @__PURE__ */ jsxRuntime.jsxs("a", { href: dataUrl, download: fileName, className: "mt-3", children: [
|
|
2439
|
+
"Download ",
|
|
2440
|
+
fileName
|
|
2441
|
+
] })
|
|
2442
|
+
] });
|
|
2443
|
+
}
|
|
2444
|
+
if (previewType === "audio") {
|
|
2445
|
+
return /* @__PURE__ */ jsxRuntime.jsx("audio", { controls: true, src: dataUrl, className: cn("w-full", className) });
|
|
2446
|
+
}
|
|
2447
|
+
if (previewType === "video") {
|
|
2448
|
+
return /* @__PURE__ */ jsxRuntime.jsx("video", { controls: true, src: dataUrl, className: cn("max-h-full max-w-full", className) });
|
|
2381
2449
|
}
|
|
2382
2450
|
if (previewType === "text" || previewType === "json") {
|
|
2383
2451
|
let content;
|
|
@@ -2394,7 +2462,7 @@ var PreviewComponent = ({ fileName, base64, className }) => {
|
|
|
2394
2462
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex min-h-48 items-center justify-center p-4 text-center", className), children: /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
2395
2463
|
"Preview is not available for ",
|
|
2396
2464
|
fileName,
|
|
2397
|
-
"."
|
|
2465
|
+
". This file format is not supported."
|
|
2398
2466
|
] }) });
|
|
2399
2467
|
};
|
|
2400
2468
|
var PreviewComponent_default = PreviewComponent;
|