UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

95 lines (94 loc) 2.63 kB
import { jsxs as c, jsx as a } from "react/jsx-runtime"; import { useFileContent as p } from "../../synapse-queries/file/useFiles.js"; import { useLatestTag as h } from "../../synapse-queries/github/useGithub.js"; import { Container as f, Box as s, Button as u } from "@mui/material"; import "@mui/material/Skeleton"; import { useState as x, useMemo as w } from "react"; import "lodash-es"; import { SkeletonParagraph as g } from "../Skeleton/SkeletonParagraph.js"; import { Markdown as b } from "./MarkdownSynapse.js"; import { replaceFileExtension as k } from "../../utils/functions/StringUtils.js"; function E(t) { const { repoOwner: e, repoName: o } = t, { data: n } = h(e, o); return /* @__PURE__ */ a(U, { ...t, tagName: n }); } const y = (t, e) => { if (!t) return; const o = ` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>${e}</title> </head> <body style="margin: 0; padding: 20px; font-family: Arial, sans-serif; line-height: 24px;"> ${t} </body> </html> `, n = new Blob([o], { type: "text/html" }), l = URL.createObjectURL(n), r = document.createElement("a"); r.href = l, r.download = e, r.click(), URL.revokeObjectURL(l); }; function U({ repoOwner: t, repoName: e, filePath: o, tagName: n, showDownloadButton: l = !1 }) { const [r, m] = x( null ), d = w( () => k(o, "html"), [o] ), { data: i } = p( `https://cdn.jsdelivr.net/gh/${t}/${e}@${n}/${o}`, { enabled: !!n } ); return /* @__PURE__ */ c( f, { sx: { "> .markdown": { px: "10px" //without this, numbered lists in the md overflow left (and are cut off) } }, children: [ l && r && /* @__PURE__ */ a( s, { sx: { display: "flex", float: "right", mt: "15px" }, children: /* @__PURE__ */ a( u, { variant: "outlined", color: "primary", sx: { mb: 1 }, onClick: () => y(r, d), children: "Download" } ) } ), i ? /* @__PURE__ */ a( b, { markdown: i, onMarkdownProcessingDone: m } ) : /* @__PURE__ */ a(s, { sx: { width: "100%" }, children: /* @__PURE__ */ a(g, { rowHeight: "30px", numRows: 70 }) }) ] } ); } export { E as MarkdownGithubLatestTag, U as default }; //# sourceMappingURL=MarkdownGithub.js.map