From 9423d6e14f30e083725e2f7ed626a649ad06755e Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Sun, 21 May 2023 13:01:13 +0300 Subject: [PATCH] feat: hide edit on embed --- src/containers/Editor/LiveEditor/Tools.tsx | 13 +++---------- src/containers/Modals/NodeModal/index.tsx | 6 +++++- src/utils/widget.ts | 7 +++++++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 src/utils/widget.ts diff --git a/src/containers/Editor/LiveEditor/Tools.tsx b/src/containers/Editor/LiveEditor/Tools.tsx index a8ebc5d..ac26fb1 100644 --- a/src/containers/Editor/LiveEditor/Tools.tsx +++ b/src/containers/Editor/LiveEditor/Tools.tsx @@ -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"} > { const text = Array.isArray(data) ? Object.fromEntries(data) : data; @@ -82,7 +83,10 @@ export const NodeModal: React.FC = ({ opened, onClose }) => { onModalClose(); }; - const isEditVisible = path !== "{Root}" && !isParent; + const isEditVisible = React.useMemo( + () => path !== "{Root}" && !isParent && !isIframe(), + [isParent, path] + ); return ( diff --git a/src/utils/widget.ts b/src/utils/widget.ts new file mode 100644 index 0000000..3e336b6 --- /dev/null +++ b/src/utils/widget.ts @@ -0,0 +1,7 @@ +export function isIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } +}