reifyui 0.13.4 → 0.13.5

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 CHANGED
@@ -4428,6 +4428,7 @@ function kindOf(name, mime = "") {
4428
4428
  if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
4429
4429
  if (e === "csv" || e === "tsv") return "csv";
4430
4430
  if (e === "md" || e === "markdown") return "markdown";
4431
+ if (e === "html" || e === "htm") return "html";
4431
4432
  if (SHEET.has(e)) return "sheet";
4432
4433
  if (OFFICE.has(e)) return "office";
4433
4434
  if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
@@ -4479,12 +4480,14 @@ function FilePreview({
4479
4480
  const { url, name } = file || {};
4480
4481
  const [st, setSt] = (0, import_react19.useState)({ kind: "loading" });
4481
4482
  const [tab, setTab] = (0, import_react19.useState)(0);
4483
+ const [view, setView] = (0, import_react19.useState)("preview");
4482
4484
  (0, import_react19.useEffect)(() => {
4483
4485
  if (!url) return void 0;
4484
4486
  let alive = true;
4485
4487
  let obj;
4486
4488
  setSt({ kind: "loading" });
4487
4489
  setTab(0);
4490
+ setView("preview");
4488
4491
  const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
4489
4492
  (async () => {
4490
4493
  const res = await get(url);
@@ -4519,7 +4522,7 @@ function FilePreview({
4519
4522
  }
4520
4523
  return;
4521
4524
  }
4522
- if (kind === "csv" || kind === "markdown" || kind === "code") {
4525
+ if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
4523
4526
  const text = await res.text();
4524
4527
  if (!alive) return;
4525
4528
  if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
@@ -4545,6 +4548,18 @@ function FilePreview({
4545
4548
  /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("header", { className: "uic-fp-head", children: [
4546
4549
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-ic", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(FileTypeIcon, { name, size: 20 }) }),
4547
4550
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
4551
+ 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)(
4552
+ "button",
4553
+ {
4554
+ type: "button",
4555
+ role: "tab",
4556
+ "aria-selected": view === id,
4557
+ className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
4558
+ onClick: () => setView(id),
4559
+ children: label
4560
+ },
4561
+ id
4562
+ )) }),
4548
4563
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
4549
4564
  "button",
4550
4565
  {
@@ -4576,6 +4591,10 @@ function FilePreview({
4576
4591
  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
4592
  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
4593
  st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "", lang: LANG[extOf(name)] || "plaintext" }),
4594
+ st.kind === "html" && view === "source" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "", lang: "xml" }),
4595
+ st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
4596
+ // work, and nothing in it can read the host page, its cookies or its storage.
4597
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
4579
4598
  st.kind === "csv" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Grid, { rows: st.rows }),
4580
4599
  st.kind === "sheet" && st.sheets && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "uic-fp-xlsx", children: [
4581
4600
  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." }),