reifyui 0.13.4 → 0.13.6
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/index.cjs +26 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilePreview.jsx +22 -2
- package/styles/file.css +4 -0
package/dist/index.js
CHANGED
|
@@ -2255,7 +2255,11 @@ var LANG = {
|
|
|
2255
2255
|
lua: "lua",
|
|
2256
2256
|
pl: "perl",
|
|
2257
2257
|
dockerfile: "dockerfile",
|
|
2258
|
-
diff: "diff"
|
|
2258
|
+
diff: "diff",
|
|
2259
|
+
md: "markdown",
|
|
2260
|
+
txt: "plaintext",
|
|
2261
|
+
log: "plaintext",
|
|
2262
|
+
csv: "plaintext"
|
|
2259
2263
|
};
|
|
2260
2264
|
var OFFICE = /* @__PURE__ */ new Set(["pptx", "ppt", "pptm", "odp", "doc", "docx", "odt", "rtf"]);
|
|
2261
2265
|
var SHEET = /* @__PURE__ */ new Set(["xls", "xlsx", "xlsm", "xlsb", "ods"]);
|
|
@@ -2267,6 +2271,7 @@ function kindOf(name, mime = "") {
|
|
|
2267
2271
|
if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
|
|
2268
2272
|
if (e === "csv" || e === "tsv") return "csv";
|
|
2269
2273
|
if (e === "md" || e === "markdown") return "markdown";
|
|
2274
|
+
if (e === "html" || e === "htm") return "html";
|
|
2270
2275
|
if (SHEET.has(e)) return "sheet";
|
|
2271
2276
|
if (OFFICE.has(e)) return "office";
|
|
2272
2277
|
if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
|
|
@@ -2318,12 +2323,14 @@ function FilePreview({
|
|
|
2318
2323
|
const { url, name } = file || {};
|
|
2319
2324
|
const [st, setSt] = useState10({ kind: "loading" });
|
|
2320
2325
|
const [tab, setTab] = useState10(0);
|
|
2326
|
+
const [view, setView] = useState10("preview");
|
|
2321
2327
|
useEffect8(() => {
|
|
2322
2328
|
if (!url) return void 0;
|
|
2323
2329
|
let alive = true;
|
|
2324
2330
|
let obj;
|
|
2325
2331
|
setSt({ kind: "loading" });
|
|
2326
2332
|
setTab(0);
|
|
2333
|
+
setView("preview");
|
|
2327
2334
|
const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
|
|
2328
2335
|
(async () => {
|
|
2329
2336
|
const res = await get(url);
|
|
@@ -2358,7 +2365,7 @@ function FilePreview({
|
|
|
2358
2365
|
}
|
|
2359
2366
|
return;
|
|
2360
2367
|
}
|
|
2361
|
-
if (kind === "csv" || kind === "markdown" || kind === "code") {
|
|
2368
|
+
if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
|
|
2362
2369
|
const text = await res.text();
|
|
2363
2370
|
if (!alive) return;
|
|
2364
2371
|
if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
|
|
@@ -2384,6 +2391,18 @@ function FilePreview({
|
|
|
2384
2391
|
/* @__PURE__ */ jsxs11("header", { className: "uic-fp-head", children: [
|
|
2385
2392
|
/* @__PURE__ */ jsx13("span", { className: "uic-fp-ic", children: /* @__PURE__ */ jsx13(FileTypeIcon, { name, size: 20 }) }),
|
|
2386
2393
|
/* @__PURE__ */ jsx13("span", { className: "uic-fp-name", title: name, children: name }),
|
|
2394
|
+
st.kind === "html" && /* @__PURE__ */ jsx13("div", { className: "uic-fp-seg", role: "tablist", "aria-label": "Show the page or its source", children: [["preview", "Preview"], ["source", "Source"]].map(([id, label]) => /* @__PURE__ */ jsx13(
|
|
2395
|
+
"button",
|
|
2396
|
+
{
|
|
2397
|
+
type: "button",
|
|
2398
|
+
role: "tab",
|
|
2399
|
+
"aria-selected": view === id,
|
|
2400
|
+
className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
|
|
2401
|
+
onClick: () => setView(id),
|
|
2402
|
+
children: label
|
|
2403
|
+
},
|
|
2404
|
+
id
|
|
2405
|
+
)) }),
|
|
2387
2406
|
/* @__PURE__ */ jsx13(
|
|
2388
2407
|
"button",
|
|
2389
2408
|
{
|
|
@@ -2414,7 +2433,11 @@ function FilePreview({
|
|
|
2414
2433
|
st.kind === "video" && st.objUrl && /* @__PURE__ */ jsx13("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx13("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
|
|
2415
2434
|
st.kind === "audio" && st.objUrl && /* @__PURE__ */ jsx13("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx13("audio", { src: st.objUrl, controls: true }) }),
|
|
2416
2435
|
st.kind === "markdown" && /* @__PURE__ */ jsx13("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ jsx13("pre", { className: "uic-fp-pre", children: st.text }) }),
|
|
2417
|
-
st.kind === "code" && /* @__PURE__ */ jsx13(CodeBlock, { code: st.text || "",
|
|
2436
|
+
st.kind === "code" && /* @__PURE__ */ jsx13(CodeBlock, { code: st.text || "", language: LANG[extOf(name)] || "plaintext" }),
|
|
2437
|
+
st.kind === "html" && view === "source" && /* @__PURE__ */ jsx13(CodeBlock, { code: st.text || "", language: "xml" }),
|
|
2438
|
+
st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
|
|
2439
|
+
// work, and nothing in it can read the host page, its cookies or its storage.
|
|
2440
|
+
/* @__PURE__ */ jsx13("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
|
|
2418
2441
|
st.kind === "csv" && /* @__PURE__ */ jsx13(Grid, { rows: st.rows }),
|
|
2419
2442
|
st.kind === "sheet" && st.sheets && /* @__PURE__ */ jsxs11("div", { className: "uic-fp-xlsx", children: [
|
|
2420
2443
|
st.sheets[tab]?.filled ? /* @__PURE__ */ jsx13(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ jsx13("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
|