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.cjs
CHANGED
|
@@ -4416,7 +4416,11 @@ var LANG = {
|
|
|
4416
4416
|
lua: "lua",
|
|
4417
4417
|
pl: "perl",
|
|
4418
4418
|
dockerfile: "dockerfile",
|
|
4419
|
-
diff: "diff"
|
|
4419
|
+
diff: "diff",
|
|
4420
|
+
md: "markdown",
|
|
4421
|
+
txt: "plaintext",
|
|
4422
|
+
log: "plaintext",
|
|
4423
|
+
csv: "plaintext"
|
|
4420
4424
|
};
|
|
4421
4425
|
var OFFICE = /* @__PURE__ */ new Set(["pptx", "ppt", "pptm", "odp", "doc", "docx", "odt", "rtf"]);
|
|
4422
4426
|
var SHEET = /* @__PURE__ */ new Set(["xls", "xlsx", "xlsm", "xlsb", "ods"]);
|
|
@@ -4428,6 +4432,7 @@ function kindOf(name, mime = "") {
|
|
|
4428
4432
|
if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
|
|
4429
4433
|
if (e === "csv" || e === "tsv") return "csv";
|
|
4430
4434
|
if (e === "md" || e === "markdown") return "markdown";
|
|
4435
|
+
if (e === "html" || e === "htm") return "html";
|
|
4431
4436
|
if (SHEET.has(e)) return "sheet";
|
|
4432
4437
|
if (OFFICE.has(e)) return "office";
|
|
4433
4438
|
if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
|
|
@@ -4479,12 +4484,14 @@ function FilePreview({
|
|
|
4479
4484
|
const { url, name } = file || {};
|
|
4480
4485
|
const [st, setSt] = (0, import_react19.useState)({ kind: "loading" });
|
|
4481
4486
|
const [tab, setTab] = (0, import_react19.useState)(0);
|
|
4487
|
+
const [view, setView] = (0, import_react19.useState)("preview");
|
|
4482
4488
|
(0, import_react19.useEffect)(() => {
|
|
4483
4489
|
if (!url) return void 0;
|
|
4484
4490
|
let alive = true;
|
|
4485
4491
|
let obj;
|
|
4486
4492
|
setSt({ kind: "loading" });
|
|
4487
4493
|
setTab(0);
|
|
4494
|
+
setView("preview");
|
|
4488
4495
|
const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
|
|
4489
4496
|
(async () => {
|
|
4490
4497
|
const res = await get(url);
|
|
@@ -4519,7 +4526,7 @@ function FilePreview({
|
|
|
4519
4526
|
}
|
|
4520
4527
|
return;
|
|
4521
4528
|
}
|
|
4522
|
-
if (kind === "csv" || kind === "markdown" || kind === "code") {
|
|
4529
|
+
if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
|
|
4523
4530
|
const text = await res.text();
|
|
4524
4531
|
if (!alive) return;
|
|
4525
4532
|
if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
|
|
@@ -4545,6 +4552,18 @@ function FilePreview({
|
|
|
4545
4552
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("header", { className: "uic-fp-head", children: [
|
|
4546
4553
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-ic", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(FileTypeIcon, { name, size: 20 }) }),
|
|
4547
4554
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
|
|
4555
|
+
st.kind === "html" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-seg", role: "tablist", "aria-label": "Show the page or its source", children: [["preview", "Preview"], ["source", "Source"]].map(([id, label]) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
4556
|
+
"button",
|
|
4557
|
+
{
|
|
4558
|
+
type: "button",
|
|
4559
|
+
role: "tab",
|
|
4560
|
+
"aria-selected": view === id,
|
|
4561
|
+
className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
|
|
4562
|
+
onClick: () => setView(id),
|
|
4563
|
+
children: label
|
|
4564
|
+
},
|
|
4565
|
+
id
|
|
4566
|
+
)) }),
|
|
4548
4567
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
4549
4568
|
"button",
|
|
4550
4569
|
{
|
|
@@ -4575,7 +4594,11 @@ function FilePreview({
|
|
|
4575
4594
|
st.kind === "video" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
|
|
4576
4595
|
st.kind === "audio" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("audio", { src: st.objUrl, controls: true }) }),
|
|
4577
4596
|
st.kind === "markdown" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("pre", { className: "uic-fp-pre", children: st.text }) }),
|
|
4578
|
-
st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "",
|
|
4597
|
+
st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "", language: LANG[extOf(name)] || "plaintext" }),
|
|
4598
|
+
st.kind === "html" && view === "source" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "", language: "xml" }),
|
|
4599
|
+
st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
|
|
4600
|
+
// work, and nothing in it can read the host page, its cookies or its storage.
|
|
4601
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
|
|
4579
4602
|
st.kind === "csv" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Grid, { rows: st.rows }),
|
|
4580
4603
|
st.kind === "sheet" && st.sheets && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "uic-fp-xlsx", children: [
|
|
4581
4604
|
st.sheets[tab]?.filled ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
|