synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
224 lines (223 loc) • 6.78 kB
JavaScript
import { jsx as e, jsxs as t, Fragment as k } from "react/jsx-runtime";
import { Popover as O, Stack as S, Box as n, Typography as p, Alert as B, FormControl as D, Select as H, MenuItem as i, Button as L } from "@mui/material";
import { useCitation as F } from "./useCitation.js";
import { createLinkAndDownload as R } from "./CitationPopoverUtils.js";
import { KeyboardArrowDown as A } from "@mui/icons-material";
import E from "@mui/icons-material/Close";
import { useState as T } from "react";
import { CopyToClipboardIcon as W } from "../CopyToClipboardIcon.js";
import { Markdown as j } from "../Markdown/MarkdownSynapse.js";
const z = {
width: "100%",
".MuiInputBase-root": {
minHeight: "38px",
borderRadius: 0,
"&:before, &:after": {
borderBottom: "none !important"
}
},
"& .MuiOutlinedInput-notchedOutline": {
border: 0
},
"&.MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline": {
border: "none"
},
".MuiSelect-select": {
display: "flex",
alignItems: "center"
},
".MuiInputBase-input": {
padding: "7px 10px"
}
}, X = (c) => {
const {
doi: x,
title: m,
boilerplateText: l,
defaultCitationFormat: u,
onClose: s,
anchorEl: h,
open: b,
id: f
} = c, [r, g] = T(
u || "bibtex"
), {
data: a,
isLoading: v,
error: d
} = F(x || "", r, !0), w = (o) => {
if (!o)
return;
const y = {
apa: "ris",
bibtex: "bib",
ieee: "ris",
nature: "ris",
science: "ris"
}[r] || "txt", M = new Blob([o], { type: "text/plain" }), I = URL.createObjectURL(M);
R(m || "citation", y, I);
}, C = (o) => {
g(o.target.value);
};
return /* @__PURE__ */ e(
O,
{
"aria-label": "Citation options",
role: "dialog",
id: f,
elevation: 9,
open: b,
anchorEl: h,
onClose: s,
anchorOrigin: {
vertical: "bottom",
horizontal: "left"
},
transformOrigin: {
vertical: "top",
horizontal: "left"
},
slotProps: {
paper: {
square: !0,
sx: (o) => ({
width: "500px",
position: "relative",
[o.breakpoints.down("sm")]: {
maxWidth: "100%",
maxHeight: "100%",
top: "0 !important",
left: "0 !important",
bottom: "0 !important"
}
})
}
},
children: /* @__PURE__ */ t(
S,
{
sx: {
gap: "20px",
padding: "20px"
},
children: [
/* @__PURE__ */ t(n, { sx: { display: "flex", alignItems: "center" }, children: [
/* @__PURE__ */ e(
p,
{
sx: { fontSize: "20px", fontWeight: 700, lineHeight: "normal" },
children: "Cite As:"
}
),
/* @__PURE__ */ e(
E,
{
sx: {
cursor: "pointer",
display: { xs: "block", sm: "none" },
marginLeft: "auto",
color: "#878E95"
},
onClick: () => {
s?.({}, "escapeKeyDown");
}
}
)
] }),
d && /* @__PURE__ */ e(B, { severity: "error", sx: { my: 2 }, icon: !1, children: d.message }),
/* @__PURE__ */ t(
p,
{
variant: "smallText1",
component: "div",
sx: {
lineHeight: "normal",
maxHeight: "300px",
overflowY: "scroll",
wordWrap: "break-word"
},
children: [
l && /* @__PURE__ */ t(k, { children: [
/* @__PURE__ */ e(j, { markdown: l }),
/* @__PURE__ */ e("br", {})
] }),
v ? /* @__PURE__ */ t(n, { sx: { fontWeight: 700 }, children: [
/* @__PURE__ */ e("br", {}),
"Loading citation..."
] }) : a
]
}
),
/* @__PURE__ */ t(
n,
{
sx: {
display: "flex",
flexDirection: { xs: "column", sm: "row" },
gap: { xs: "10px", sm: "8px" },
width: "100%",
maxHeight: "38px"
},
children: [
/* @__PURE__ */ e(n, { sx: { flex: 1 }, children: /* @__PURE__ */ e(D, { sx: z, children: /* @__PURE__ */ t(
H,
{
variant: "standard",
sx: {
svg: {
color: "#878E95",
width: "24px",
height: "24px",
right: "10px"
}
},
value: r,
onChange: C,
IconComponent: A,
children: [
/* @__PURE__ */ e(i, { value: "bibtex", children: "bibtex" }),
/* @__PURE__ */ e(i, { value: "apa", children: "apa" }),
/* @__PURE__ */ e(i, { value: "ieee", children: "ieee" }),
/* @__PURE__ */ e(i, { value: "nature", children: "nature" }),
/* @__PURE__ */ e(i, { value: "science", children: "science" })
]
}
) }) }),
/* @__PURE__ */ e(
L,
{
onClick: () => w(a || ""),
variant: "contained",
sx: {
padding: "6px 16px",
borderRadius: 0
},
children: "Download Citation"
}
),
/* @__PURE__ */ e(
W,
{
value: a || "",
sx: {
borderRadius: 0,
padding: "6px 16px",
border: "1px solid",
borderColor: "primary.main"
}
}
)
]
}
)
]
}
)
}
);
};
export {
X as CitationPopoverContent,
X as default
};
//# sourceMappingURL=CitationPopoverContent.js.map