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.js CHANGED
@@ -2267,6 +2267,7 @@ function kindOf(name, mime = "") {
2267
2267
  if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
2268
2268
  if (e === "csv" || e === "tsv") return "csv";
2269
2269
  if (e === "md" || e === "markdown") return "markdown";
2270
+ if (e === "html" || e === "htm") return "html";
2270
2271
  if (SHEET.has(e)) return "sheet";
2271
2272
  if (OFFICE.has(e)) return "office";
2272
2273
  if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
@@ -2318,12 +2319,14 @@ function FilePreview({
2318
2319
  const { url, name } = file || {};
2319
2320
  const [st, setSt] = useState10({ kind: "loading" });
2320
2321
  const [tab, setTab] = useState10(0);
2322
+ const [view, setView] = useState10("preview");
2321
2323
  useEffect8(() => {
2322
2324
  if (!url) return void 0;
2323
2325
  let alive = true;
2324
2326
  let obj;
2325
2327
  setSt({ kind: "loading" });
2326
2328
  setTab(0);
2329
+ setView("preview");
2327
2330
  const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
2328
2331
  (async () => {
2329
2332
  const res = await get(url);
@@ -2358,7 +2361,7 @@ function FilePreview({
2358
2361
  }
2359
2362
  return;
2360
2363
  }
2361
- if (kind === "csv" || kind === "markdown" || kind === "code") {
2364
+ if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
2362
2365
  const text = await res.text();
2363
2366
  if (!alive) return;
2364
2367
  if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
@@ -2384,6 +2387,18 @@ function FilePreview({
2384
2387
  /* @__PURE__ */ jsxs11("header", { className: "uic-fp-head", children: [
2385
2388
  /* @__PURE__ */ jsx13("span", { className: "uic-fp-ic", children: /* @__PURE__ */ jsx13(FileTypeIcon, { name, size: 20 }) }),
2386
2389
  /* @__PURE__ */ jsx13("span", { className: "uic-fp-name", title: name, children: name }),
2390
+ 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(
2391
+ "button",
2392
+ {
2393
+ type: "button",
2394
+ role: "tab",
2395
+ "aria-selected": view === id,
2396
+ className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
2397
+ onClick: () => setView(id),
2398
+ children: label
2399
+ },
2400
+ id
2401
+ )) }),
2387
2402
  /* @__PURE__ */ jsx13(
2388
2403
  "button",
2389
2404
  {
@@ -2415,6 +2430,10 @@ function FilePreview({
2415
2430
  st.kind === "audio" && st.objUrl && /* @__PURE__ */ jsx13("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx13("audio", { src: st.objUrl, controls: true }) }),
2416
2431
  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
2432
  st.kind === "code" && /* @__PURE__ */ jsx13(CodeBlock, { code: st.text || "", lang: LANG[extOf(name)] || "plaintext" }),
2433
+ st.kind === "html" && view === "source" && /* @__PURE__ */ jsx13(CodeBlock, { code: st.text || "", lang: "xml" }),
2434
+ st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
2435
+ // work, and nothing in it can read the host page, its cookies or its storage.
2436
+ /* @__PURE__ */ jsx13("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
2418
2437
  st.kind === "csv" && /* @__PURE__ */ jsx13(Grid, { rows: st.rows }),
2419
2438
  st.kind === "sheet" && st.sheets && /* @__PURE__ */ jsxs11("div", { className: "uic-fp-xlsx", children: [
2420
2439
  st.sheets[tab]?.filled ? /* @__PURE__ */ jsx13(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ jsx13("div", { className: "uic-fp-empty", children: "This sheet is empty." }),