feat: hide edit on embed

This commit is contained in:
AykutSarac 2023-05-21 13:01:13 +03:00
parent 98c37cc322
commit 9423d6e14f
No known key found for this signature in database
3 changed files with 15 additions and 11 deletions

View File

@ -24,14 +24,7 @@ import useModal from "src/store/useModal";
import useStored from "src/store/useStored";
import useUser from "src/store/useUser";
import { getNextDirection } from "src/utils/graph/getNextDirection";
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
import { isIframe } from "src/utils/widget";
export const StyledTools = styled.div`
position: relative;
@ -157,7 +150,7 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
]);
const logoURL = React.useMemo(() => {
if (!inIframe()) return "https://jsoncrack.com";
if (!isIframe()) return "https://jsoncrack.com";
return window.location.href.replace("widget", "editor");
}, []);
@ -168,7 +161,7 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
as="a"
title="JSON Crack"
href={logoURL}
target={inIframe() ? "_blank" : "_parent"}
target={isIframe() ? "_blank" : "_parent"}
>
<Flex gap="xs" align="center" justify="center">
<StyledLogo

View File

@ -11,6 +11,7 @@ import useGraph from "src/store/useGraph";
import useModal from "src/store/useModal";
import useStored from "src/store/useStored";
import useUser from "src/store/useUser";
import { isIframe } from "src/utils/widget";
const dataToString = (data: any) => {
const text = Array.isArray(data) ? Object.fromEntries(data) : data;
@ -82,7 +83,10 @@ export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
onModalClose();
};
const isEditVisible = path !== "{Root}" && !isParent;
const isEditVisible = React.useMemo(
() => path !== "{Root}" && !isParent && !isIframe(),
[isParent, path]
);
return (
<Modal title="Node Content" size="auto" opened={opened} onClose={onModalClose} centered>

7
src/utils/widget.ts Normal file
View File

@ -0,0 +1,7 @@
export function isIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}