mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-20 05:12:54 +08:00
feat: hide edit on embed
This commit is contained in:
parent
98c37cc322
commit
9423d6e14f
@ -24,14 +24,7 @@ import useModal from "src/store/useModal";
|
|||||||
import useStored from "src/store/useStored";
|
import useStored from "src/store/useStored";
|
||||||
import useUser from "src/store/useUser";
|
import useUser from "src/store/useUser";
|
||||||
import { getNextDirection } from "src/utils/graph/getNextDirection";
|
import { getNextDirection } from "src/utils/graph/getNextDirection";
|
||||||
|
import { isIframe } from "src/utils/widget";
|
||||||
function inIframe() {
|
|
||||||
try {
|
|
||||||
return window.self !== window.top;
|
|
||||||
} catch (e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const StyledTools = styled.div`
|
export const StyledTools = styled.div`
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -157,7 +150,7 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const logoURL = React.useMemo(() => {
|
const logoURL = React.useMemo(() => {
|
||||||
if (!inIframe()) return "https://jsoncrack.com";
|
if (!isIframe()) return "https://jsoncrack.com";
|
||||||
return window.location.href.replace("widget", "editor");
|
return window.location.href.replace("widget", "editor");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -168,7 +161,7 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
|
|||||||
as="a"
|
as="a"
|
||||||
title="JSON Crack"
|
title="JSON Crack"
|
||||||
href={logoURL}
|
href={logoURL}
|
||||||
target={inIframe() ? "_blank" : "_parent"}
|
target={isIframe() ? "_blank" : "_parent"}
|
||||||
>
|
>
|
||||||
<Flex gap="xs" align="center" justify="center">
|
<Flex gap="xs" align="center" justify="center">
|
||||||
<StyledLogo
|
<StyledLogo
|
||||||
|
@ -11,6 +11,7 @@ import useGraph from "src/store/useGraph";
|
|||||||
import useModal from "src/store/useModal";
|
import useModal from "src/store/useModal";
|
||||||
import useStored from "src/store/useStored";
|
import useStored from "src/store/useStored";
|
||||||
import useUser from "src/store/useUser";
|
import useUser from "src/store/useUser";
|
||||||
|
import { isIframe } from "src/utils/widget";
|
||||||
|
|
||||||
const dataToString = (data: any) => {
|
const dataToString = (data: any) => {
|
||||||
const text = Array.isArray(data) ? Object.fromEntries(data) : data;
|
const text = Array.isArray(data) ? Object.fromEntries(data) : data;
|
||||||
@ -82,7 +83,10 @@ export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
|||||||
onModalClose();
|
onModalClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const isEditVisible = path !== "{Root}" && !isParent;
|
const isEditVisible = React.useMemo(
|
||||||
|
() => path !== "{Root}" && !isParent && !isIframe(),
|
||||||
|
[isParent, path]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal title="Node Content" size="auto" opened={opened} onClose={onModalClose} centered>
|
<Modal title="Node Content" size="auto" opened={opened} onClose={onModalClose} centered>
|
||||||
|
7
src/utils/widget.ts
Normal file
7
src/utils/widget.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export function isIframe() {
|
||||||
|
try {
|
||||||
|
return window.self !== window.top;
|
||||||
|
} catch (e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user