✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.
chore: refactor
AykutSaraca998d849f726
diff --git a/src/components/AdTest/index.tsx b/src/components/AdTest/index.tsxdeleted file mode 100644index 3850a882..00000000--- a/src/components/AdTest/index.tsx+++ /dev/null@@ -1,140 +0,0 @@-import React from "react";-import styled from "styled-components";--const AdWrapper = styled.div`- & {- position: fixed;- z-index: 1000;- bottom: 40px;- right: 10px;- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,- Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;- }-- & .native-button {- z-index: 100;- display: flex;- padding: 8px 20px;- border-radius: 4px;- box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, 0.15);- color: #fff;- text-transform: uppercase;- letter-spacing: 1px;- font-weight: 600;- font-size: 12px;- cursor: pointer;-- user-select: none;- justify-content: center;- align-items: center;- }-- & .native-img {- margin-right: 10px;- width: 20px;- height: 20px;- }-- & .native-overlay {- position: fixed;- bottom: 80px;- display: none;- padding: 20px;- max-width: 330px;- border-radius: 4px;- background: #fff;- box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, 0.15);- opacity: 0;- transition:- transform 0.2s ease-in-out,- opacity 0.1s ease-in-out;- transform: scale(1) translateY(-50px);- }-- & #native-button:checked + .native-overlay {- opacity: 1;- transition:- transform 0.2s ease-in-out,- opacity 0.4s ease-in-out;- transform: scale(1) translateY(0);- }-- #native-button {- display: none;- }-- & .native-banner {- line-height: 1.35;- }-- & .native-tagline {- letter-spacing: 0.5px;- font-weight: 600;- font-size: 16px;- }-- & .native-description {- margin-bottom: 10px;- font-size: 16px;- }-- & .native-footer {- display: flex;-- justify-content: space-between;- align-items: center;- }-- & .native-logo {- width: 120px;- height: auto;- }-- & .native-cta {- padding: 6px 8px;- border-radius: 3px;- text-decoration: none;- text-transform: uppercase;- letter-spacing: 0.5px;- font-weight: 600;- font-size: 12px;- }-`;--const template = `${"`"}-<label class="native-button" for="native-button" style="background-color: ##backgroundColor##; color: ##textColor##;"><img src="##image##" class="native-img">Sponsored by ##company##</label>-<input type="checkbox" id="native-button">-<div class="native-overlay" style="background-color: ##backgroundColor##; color: ##textColor##">- <div class="native-banner">- <div class="native-tagline">##tagline##</div>- <div class="native-description">##description##</div>- <div class="native-footer">- <a href="##statlink##" class="native-cta" style="background-color: ##ctaBackgroundColor##; color: ##ctaTextColor##">##callToAction##</a>- <img class="native-logo" src="##logo##">- </div>- </div>-</div>-${"`"}`;--export const AdTest = () => {- const ref = React.useRef<HTMLDivElement>(null!);-- React.useEffect(() => {- if (window.innerWidth < 660) return;- ref.current.innerHTML = "";- const s = document.createElement("script");-- s.id = "_carbonads_js";- s.innerHTML = `(function() {- if (typeof _bsa !== 'undefined' && _bsa) {- _bsa.init('custom', 'CWYD42JI', 'placement:jsoncrackcom', {- target: '#cutton-js',- template: ${template}- });- }- })();`;- ref.current.appendChild(s);- }, []);-- return <AdWrapper ref={ref} id="cutton-js"></AdWrapper>;-};diff --git a/src/components/CarbonAds/index.tsx b/src/components/CarbonAds/index.tsxdeleted file mode 100644index beb4e968..00000000--- a/src/components/CarbonAds/index.tsx+++ /dev/null@@ -1,22 +0,0 @@-import React from "react";-import useUser from "src/store/useUser";--export const CarbonAds = () => {- const ref = React.useRef<HTMLDivElement>(null!);- const premium = useUser(state => state.premium);-- React.useEffect(() => {- if (!premium) {- ref.current.innerHTML = "";- const s = document.createElement("script");-- s.id = "_carbonads_js";- s.src = "//cdn.carbonads.com/carbon.js?serve=CE7IPKQL&placement=jsoncrackcom";- ref.current.appendChild(s);- }- }, [premium]);-- if (premium) return null;-- return <div ref={ref} className="carbon-outer" />;-};diff --git a/src/containers/Editor/JsonEditor/index.tsx b/src/containers/Editor/JsonEditor.tsxsimilarity index 100%rename from src/containers/Editor/JsonEditor/index.tsxrename to src/containers/Editor/JsonEditor.tsxdiff --git a/src/containers/Editor/LiveEditor.tsx b/src/containers/Editor/LiveEditor.tsxnew file mode 100644index 00000000..0ae94d25--- /dev/null+++ b/src/containers/Editor/LiveEditor.tsx@@ -0,0 +1,77 @@+import React from "react";+import styled from "styled-components";+import { Menu, Text } from "@mantine/core";+import { firaMono } from "src/constants/fonts";+import { Graph } from "src/containers/Views/GraphView";+import { TreeView } from "src/containers/Views/TreeView";+import { ViewMode } from "src/enums/viewMode.enum";+import useConfig from "src/store/useConfig";++const StyledLiveEditor = styled.div`+ position: relative;+ height: 100%;+ background: ${({ theme }) => theme.GRID_BG_COLOR};+ overflow: auto;++ & > ul {+ margin-top: 0 !important;+ padding: 12px !important;+ font-family: ${firaMono.style.fontFamily};+ font-size: 14px;+ font-weight: 500;+ }+`;++const View = () => {+ const viewMode = useConfig(state => state.viewMode);++ if (viewMode === ViewMode.Graph) return <Graph />;+ if (viewMode === ViewMode.Tree) return <TreeView />;+ return null;+};++const LiveEditor: React.FC = () => {+ const [contextOpened, setContextOpened] = React.useState(false);+ const [contextPosition, setContextPosition] = React.useState({+ x: 0,+ y: 0,+ });++ return (+ <StyledLiveEditor+ onContextMenuCapture={e => {+ e.preventDefault();+ setContextOpened(true);+ setContextPosition({ x: e.pageX, y: e.pageY });+ }}+ onClick={() => setContextOpened(false)}+ >+ <div+ style={{+ position: "fixed",+ top: contextPosition.y,+ left: contextPosition.x,+ zIndex: 100,+ }}+ >+ <Menu opened={false} shadow="sm">+ <Menu.Dropdown>+ <Menu.Item>+ <Text size="xs">Download as Image</Text>+ </Menu.Item>+ <Menu.Item>+ <Text size="xs">Zoom to Fit</Text>+ </Menu.Item>+ <Menu.Item>+ <Text size="xs">Rotate</Text>+ </Menu.Item>+ </Menu.Dropdown>+ </Menu>+ </div>++ <View />+ </StyledLiveEditor>+ );+};++export default LiveEditor;diff --git a/src/containers/Editor/LiveEditor/Tools.tsx b/src/containers/Editor/LiveEditor/Tools.tsxdeleted file mode 100644index d3b927ae..00000000--- a/src/containers/Editor/LiveEditor/Tools.tsx+++ /dev/null@@ -1,563 +0,0 @@-import React from "react";-import Link from "next/link";-import { useRouter } from "next/router";-import styled from "styled-components";-import {- Avatar,- Flex,- Group,- Input,- MediaQuery,- Menu,- SegmentedControl,- Select,- Text,-} from "@mantine/core";-import { getHotkeyHandler, useHotkeys } from "@mantine/hooks";-import ReactGA from "react-ga4";-import toast from "react-hot-toast";-import { AiOutlineFullscreen } from "react-icons/ai";-import { BsCheck2 } from "react-icons/bs";-import { CgArrowsMergeAltH, CgArrowsShrinkH, CgChevronDown } from "react-icons/cg";-import { FiDownload } from "react-icons/fi";-import { MdOutlineWorkspacePremium } from "react-icons/md";-import { SiJsonwebtokens } from "react-icons/si";-import { TiFlowMerge } from "react-icons/ti";-import {- VscCollapseAll,- VscExpandAll,- VscJson,- VscTarget,- VscSearchFuzzy,- VscGroupByRefType,- VscSignOut,- VscFeedback,- VscSignIn,-} from "react-icons/vsc";-import { SearchInput } from "src/components/SearchInput";-import { FileFormat } from "src/enums/file.enum";-import { ViewMode } from "src/enums/viewMode.enum";-import useToggleHide from "src/hooks/useToggleHide";-import { JSONCrackLogo } from "src/layout/JsonCrackLogo";-import { getNextDirection } from "src/lib/utils/graph/getNextDirection";-import { isIframe } from "src/lib/utils/widget";-import useConfig from "src/store/useConfig";-import useFile from "src/store/useFile";-import useGraph from "src/store/useGraph";-import useJson from "src/store/useJson";-import useModal from "src/store/useModal";-import useUser from "src/store/useUser";--export const StyledTools = styled.div`- position: relative;- display: flex;- align-items: center;- gap: 4px;- justify-content: space-between;- height: 36px;- padding: 4px 8px;- background: ${({ theme }) => theme.TOOLBAR_BG};- color: ${({ theme }) => theme.SILVER};- box-shadow: 0 1px 0px ${({ theme }) => theme.BACKGROUND_TERTIARY};- z-index: 36;-- @media only screen and (max-width: 320px) {- display: none;- }-`;--const StyledToolElement = styled.button<{ $hide?: boolean }>`- display: ${({ $hide }) => ($hide ? "none" : "grid")};- place-content: center;- font-size: 12px;- background: none;- color: ${({ theme }) => theme.INTERACTIVE_NORMAL};- padding: 6px;- border-radius: 3px;-- &:hover {- background-image: linear-gradient(rgba(0, 0, 0, 0.1) 0 0);- }-- &:hover {- color: ${({ theme }) => theme.INTERACTIVE_HOVER};- opacity: 1;- box-shadow: none;- }-`;--const StyledFlowIcon = styled(TiFlowMerge)<{ rotate: number }>`- transform: rotate(${({ rotate }) => `${rotate}deg`});-`;--function rotateLayout(direction: "LEFT" | "RIGHT" | "DOWN" | "UP") {- if (direction === "LEFT") return 90;- if (direction === "UP") return 180;- if (direction === "RIGHT") return 270;- return 360;-}--function fullscreenBrowser() {- if (!document.fullscreenElement) {- document.documentElement.requestFullscreen().catch(() => {- toast.error("Unable to enter fullscreen mode.");- });- } else if (document.exitFullscreen) {- document.exitFullscreen();- }-}--const ViewMenu = () => {- const { validateHiddenNodes } = useToggleHide();- const [coreKey, setCoreKey] = React.useState("CTRL");- const toggleFold = useGraph(state => state.toggleFold);- const setDirection = useGraph(state => state.setDirection);- const direction = useGraph(state => state.direction);- const expandGraph = useGraph(state => state.expandGraph);- const collapseGraph = useGraph(state => state.collapseGraph);- const focusFirstNode = useGraph(state => state.focusFirstNode);- const foldNodes = useGraph(state => state.foldNodes);- const graphCollapsed = useGraph(state => state.graphCollapsed);-- const toggleFoldNodes = () => {- toggleFold(!foldNodes);- toast(`${foldNodes ? "Unfolded" : "Folded"} nodes`);- };-- const toggleDirection = () => {- const nextDirection = getNextDirection(direction || "RIGHT");- if (setDirection) setDirection(nextDirection);- };-- const toggleExpandCollapseGraph = () => {- if (graphCollapsed) expandGraph();- else collapseGraph();-- validateHiddenNodes();- toast(`${graphCollapsed ? "Expanded" : "Collapsed"} graph.`);- };-- useHotkeys([- ["mod+shift+d", toggleDirection],- ["mod+shift+f", toggleFoldNodes],- ["mod+shift+c", toggleExpandCollapseGraph],- [- "mod+f",- () => {- const input = document.querySelector("#search-node") as HTMLInputElement;- input.focus();- },- ],- ]);-- React.useEffect(() => {- if (typeof window !== "undefined") {- setCoreKey(navigator.userAgent.indexOf("Mac OS X") ? "⌘" : "CTRL");- }- }, []);-- return (- <Menu shadow="md" closeOnItemClick={false} withArrow>- <Menu.Target>- <StyledToolElement>- <Flex align="center" gap={3}>- View <CgChevronDown />- </Flex>- </StyledToolElement>- </Menu.Target>- <Menu.Dropdown>- <Menu.Item- fz={12}- onClick={() => {- toggleDirection();- ReactGA.event({- action: "toggle_layout_direction",- category: "User",- label: "Tools",- });- }}- icon={<StyledFlowIcon rotate={rotateLayout(direction || "RIGHT")} />}- rightSection={- <Text ml="md" fz={10} color="dimmed">- {coreKey} Shift D- </Text>- }- >- Rotate Layout- </Menu.Item>- <Menu.Item- fz={12}- onClick={() => {- toggleFoldNodes();- ReactGA.event({- action: "toggle_fold_nodes",- category: "User",- label: "Tools",- });- }}- icon={foldNodes ? <CgArrowsShrinkH /> : <CgArrowsMergeAltH />}- rightSection={- <Text ml="md" fz={10} color="dimmed">- {coreKey} Shift F- </Text>- }- >- {foldNodes ? "Unfold" : "Fold"} Nodes- </Menu.Item>- <Menu.Item- fz={12}- onClick={() => {- toggleExpandCollapseGraph();- ReactGA.event({- action: "toggle_collapse_nodes",- category: "User",- label: "Tools",- });- }}- icon={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}- rightSection={- <Text ml="md" fz={10} color="dimmed">- {coreKey} Shift C- </Text>- }- >- {graphCollapsed ? "Expand" : "Collapse"} Nodes- </Menu.Item>- <Menu.Item fz={12} onClick={focusFirstNode} icon={<VscTarget />}>- Focus to First Node- </Menu.Item>- </Menu.Dropdown>- </Menu>- );-};--export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) => {- const { push } = useRouter();-- const getJson = useJson(state => state.getJson);- const setVisible = useModal(state => state.setVisible);- const centerView = useGraph(state => state.centerView);- const zoomIn = useGraph(state => state.zoomIn);- const zoomOut = useGraph(state => state.zoomOut);- const toggleGestures = useConfig(state => state.toggleGestures);- const toggleChildrenCount = useConfig(state => state.toggleChildrenCount);- const toggleDarkMode = useConfig(state => state.toggleDarkMode);- const toggleRulers = useConfig(state => state.toggleRulers);- const toggleCollapseButton = useConfig(state => state.toggleCollapseButton);- const setViewMode = useConfig(state => state.setViewMode);- const setZoomFactor = useGraph(state => state.setZoomFactor);- const toggleImagePreview = useConfig(state => state.toggleImagePreview);- const logout = useUser(state => state.logout);-- const user = useUser(state => state.user);- const premium = useUser(state => state.premium);-- const zoomFactor = useGraph(state => state.viewPort?.zoomFactor || 1);- const gesturesEnabled = useConfig(state => state.gesturesEnabled);- const childrenCountVisible = useConfig(state => state.childrenCountVisible);- const darkmodeEnabled = useConfig(state => state.darkmodeEnabled);- const viewMode = useConfig(state => state.viewMode);- const rulersEnabled = useConfig(state => state.rulersEnabled);- const collapseButtonVisible = useConfig(state => state.collapseButtonVisible);- const imagePreviewEnabled = useConfig(state => state.imagePreviewEnabled);-- const setFormat = useFile(state => state.setFormat);- const format = useFile(state => state.format);-- const [tempZoomValue, setTempZoomValue] = React.useState(zoomFactor);- const [logoURL, setLogoURL] = React.useState("CTRL");-- React.useEffect(() => {- if (!Number.isNaN(zoomFactor)) setTempZoomValue(zoomFactor);- }, [zoomFactor]);-- useHotkeys([- ["shift+Digit0", () => setZoomFactor(100 / 100)],- ["shift+Digit1", centerView],- ]);-- React.useEffect(() => {- if (typeof window !== "undefined") {- const url = !isIframe()- ? "https://jsoncrack.com"- : window.location.href.replace("widget", "editor");-- setLogoURL(url);- }- }, []);-- const handleSave = () => {- const a = document.createElement("a");- const file = new Blob([getJson()], { type: "text/plain" });-- a.href = window.URL.createObjectURL(file);- a.download = "jsoncrack.json";- a.click();- };-- return (- <StyledTools>- {isWidget && (- <StyledToolElement title="JSON Crack">- <Flex gap="xs" align="center" justify="center">- <JSONCrackLogo- fontSize="1.2em"- href={logoURL}- target={isIframe() ? "_blank" : "_parent"}- />- </Flex>- </StyledToolElement>- )}- {!isWidget && (- <MediaQuery smallerThan="xs" styles={{ display: "none" }}>- <Group spacing="xs" position="left" w="100%" noWrap>- <StyledToolElement title="JSON Crack">- <Flex gap="xs" align="center" justify="center">- <JSONCrackLogo fontSize="1.2em" />- </Flex>- </StyledToolElement>- <Select- defaultValue="json"- size="xs"- value={format}- onChange={setFormat}- miw={80}- w={120}- data={[- { value: FileFormat.JSON, label: "JSON" },- { value: FileFormat.YAML, label: "YAML" },- { value: FileFormat.XML, label: "XML" },- { value: FileFormat.TOML, label: "TOML" },- { value: FileFormat.CSV, label: "CSV" },- ]}- />- <Menu trigger="click" shadow="md" withArrow>- <Menu.Target>- <StyledToolElement title="View Mode">- <Flex align="center" gap={3}>- View Mode <CgChevronDown />- </Flex>- </StyledToolElement>- </Menu.Target>- <Menu.Dropdown>- <SegmentedControl- value={viewMode}- onChange={setViewMode}- data={[- { value: ViewMode.Graph, label: "Graph" },- { value: ViewMode.Tree, label: "Tree" },- ]}- />- </Menu.Dropdown>- </Menu>- <StyledToolElement title="Import File" onClick={() => setVisible("import")(true)}>- Import- </StyledToolElement>- <ViewMenu />- <Menu shadow="md" withArrow>- <Menu.Target>- <StyledToolElement>- <Flex align="center" gap={3}>- Tools <CgChevronDown />- </Flex>- </StyledToolElement>- </Menu.Target>- <Menu.Dropdown>- <Menu.Item fz={12} icon={<VscSearchFuzzy />} onClick={() => setVisible("jq")(true)}>- JSON Query (jq)- </Menu.Item>- <Menu.Item fz={12} icon={<VscJson />} onClick={() => setVisible("schema")(true)}>- JSON Schema- </Menu.Item>- <Menu.Item- fz={12}- icon={<SiJsonwebtokens />}- onClick={() => setVisible("jwt")(true)}- >- Decode JWT- </Menu.Item>- <Menu.Item- fz={12}- icon={<VscGroupByRefType />}- onClick={() => setVisible("type")(true)}- >- Generate Type- </Menu.Item>- </Menu.Dropdown>- </Menu>- <StyledToolElement title="Cloud" onClick={() => setVisible("cloud")(true)}>- Cloud- </StyledToolElement>- <StyledToolElement title="Download as File" onClick={handleSave}>- Download- </StyledToolElement>- </Group>- </MediaQuery>- )}- <Group spacing="xs" position="right" w="100%" noWrap>- <SearchInput />-- {!isWidget && (- <StyledToolElement title="Save as Image" onClick={() => setVisible("download")(true)}>- <FiDownload size="18" />- </StyledToolElement>- )}-- {!isWidget && (- <Menu shadow="md" trigger="click" closeOnItemClick={false} withArrow>- <Menu.Target>- <StyledToolElement>- <Flex gap={4}>- {Math.round(zoomFactor * 100)}%- <CgChevronDown />- </Flex>- </StyledToolElement>- </Menu.Target>- <Menu.Dropdown>- <Menu.Item>- <Input- type="number"- value={Math.round(tempZoomValue * 100)}- onChange={e => setTempZoomValue(e.currentTarget.valueAsNumber / 100)}- onKeyDown={getHotkeyHandler([["Enter", () => setZoomFactor(tempZoomValue)]])}- size="xs"- rightSection="%"- />- </Menu.Item>- <Menu.Item rightSection="+" onClick={zoomIn}>- <Text size="xs">Zoom in</Text>- </Menu.Item>- <Menu.Item rightSection="-" onClick={zoomOut}>- <Text size="xs">Zoom out</Text>- </Menu.Item>- <Menu.Item rightSection="⇧ 1" onClick={centerView}>- <Text size="xs">Zoom to fit</Text>- </Menu.Item>- <Menu.Item onClick={() => setZoomFactor(50 / 100)}>- <Text size="xs">Zoom to %50</Text>- </Menu.Item>- <Menu.Item rightSection="⇧ 0" onClick={() => setZoomFactor(100 / 100)}>- <Text size="xs">Zoom to %100</Text>- </Menu.Item>- <Menu.Item onClick={() => setZoomFactor(200 / 100)}>- <Text size="xs">Zoom to %200</Text>- </Menu.Item>- <Menu.Divider />- <Menu.Item- icon={<BsCheck2 opacity={rulersEnabled ? 100 : 0} />}- onClick={() => toggleRulers(!rulersEnabled)}- >- <Text size="xs">Rulers</Text>- </Menu.Item>- <Menu.Item- icon={<BsCheck2 opacity={gesturesEnabled ? 100 : 0} />}- onClick={() => toggleGestures(!gesturesEnabled)}- >- <Text size="xs">Trackpad Gestures</Text>- </Menu.Item>- <Menu.Item- icon={<BsCheck2 opacity={childrenCountVisible ? 100 : 0} />}- onClick={() => toggleChildrenCount(!childrenCountVisible)}- >- <Text size="xs">Item Count</Text>- </Menu.Item>- <Menu.Item- icon={<BsCheck2 opacity={imagePreviewEnabled ? 100 : 0} />}- onClick={() => toggleImagePreview(!imagePreviewEnabled)}- >- <Text size="xs">Image Link Preview</Text>- </Menu.Item>- <Menu.Item- icon={<BsCheck2 opacity={collapseButtonVisible ? 100 : 0} />}- onClick={() => toggleCollapseButton(!collapseButtonVisible)}- >- <Text size="xs">Show Expand/Collapse</Text>- </Menu.Item>- <Menu.Item- icon={<BsCheck2 opacity={darkmodeEnabled ? 100 : 0} />}- onClick={() => toggleDarkMode(!darkmodeEnabled)}- >- <Text size="xs">Dark Mode</Text>- </Menu.Item>- </Menu.Dropdown>- </Menu>- )}-- {!isWidget && (- <Menu shadow="md" trigger="click" closeOnItemClick={false} withArrow>- <Menu.Target>- <StyledToolElement>- <Avatar- color="grape"- variant="filled"- size={20}- radius="xl"- src={user?.user_metadata.avatar_url}- alt={user?.user_metadata.name}- >- {user?.user_metadata.name[0]}- </Avatar>- </StyledToolElement>- </Menu.Target>- <Menu.Dropdown>- {user ? (- <Menu.Item- icon={- <Avatar color="grape" alt={user.user_metadata.name} size={20} radius="xl" />- }- onClick={() => setVisible("account")(true)}- closeMenuOnClick- >- <Text size="xs">Account</Text>- </Menu.Item>- ) : (- <Link href="/sign-in">- <Menu.Item icon={<VscSignIn />}>- <Text size="xs">Sign in</Text>- </Menu.Item>- </Link>- )}- {!premium && (- <Menu.Item- icon={<MdOutlineWorkspacePremium color="red" />}- onClick={() => setVisible("premium")(true)}- closeMenuOnClick- >- <Text- variant="gradient"- fw="bold"- gradient={{ from: "orange", to: "red" }}- size="xs"- >- Get Premium- </Text>- </Menu.Item>- )}- {user && (- <>- <Menu.Divider />- <Menu.Item- icon={<VscFeedback />}- onClick={() => setVisible("review")(true)}- closeMenuOnClick- >- <Text size="xs">Feedback</Text>- </Menu.Item>- <Menu.Item icon={<VscSignOut />} onClick={() => logout()} closeMenuOnClick>- <Text size="xs">Log out</Text>- </Menu.Item>- </>- )}- </Menu.Dropdown>- </Menu>- )}-- {!isWidget && (- <StyledToolElement title="Fullscreen" $hide={isWidget} onClick={fullscreenBrowser}>- <AiOutlineFullscreen size="18" />- </StyledToolElement>- )}- </Group>- </StyledTools>- );-};diff --git a/src/containers/Editor/LiveEditor/index.tsx b/src/containers/Editor/LiveEditor/index.tsxdeleted file mode 100644index 922ae320..00000000--- a/src/containers/Editor/LiveEditor/index.tsx+++ /dev/null@@ -1,145 +0,0 @@-import React from "react";-import styled, { DefaultTheme, useTheme } from "styled-components";-import { Menu, Text } from "@mantine/core";-import { JSONTree } from "react-json-tree";-import { Graph } from "src/components/Graph";-import { TextRenderer } from "src/components/Graph/CustomNode/TextRenderer";-import { firaMono } from "src/constants/fonts";-import { ViewMode } from "src/enums/viewMode.enum";-import useConfig from "src/store/useConfig";-import useJson from "src/store/useJson";--const StyledLiveEditor = styled.div`- position: relative;- height: 100%;- background: ${({ theme }) => theme.GRID_BG_COLOR};- overflow: auto;-- & > ul {- margin-top: 0 !important;- padding: 12px !important;- font-family: ${firaMono.style.fontFamily};- font-size: 14px;- font-weight: 500;- }-`;--type TextColorFn = {- theme: DefaultTheme;- $value?: string | unknown;-};--function getValueColor({ $value, theme }: TextColorFn) {- if ($value && !Number.isNaN(+$value)) return theme.NODE_COLORS.INTEGER;- if ($value === "true") return theme.NODE_COLORS.BOOL.TRUE;- if ($value === "false") return theme.NODE_COLORS.BOOL.FALSE;- if ($value === "null") return theme.NODE_COLORS.NULL;-- // default- return theme.NODE_COLORS.NODE_VALUE;-}--function getLabelColor({ $type, theme }: { $type?: string; theme: DefaultTheme }) {- if ($type === "Object") return theme.NODE_COLORS.PARENT_OBJ;- if ($type === "Array") return theme.NODE_COLORS.PARENT_ARR;- return theme.NODE_COLORS.PARENT_OBJ;-}--const View = () => {- const theme = useTheme();- const json = useJson(state => state.json);- const viewMode = useConfig(state => state.viewMode);-- if (viewMode === ViewMode.Graph) return <Graph />;-- if (viewMode === ViewMode.Tree)- return (- <JSONTree- data={JSON.parse(json)}- labelRenderer={(keyPath, nodeType, expanded, expandable) => {- return (- <span- style={{- color: getLabelColor({- theme,- $type: nodeType,- }),- }}- >- {keyPath[0]}:- </span>- );- }}- valueRenderer={(valueAsString, value) => {- return (- <span- style={{- color: getValueColor({- theme,- $value: valueAsString,- }),- }}- >- <TextRenderer>{JSON.stringify(value)}</TextRenderer>- </span>- );- }}- theme={{- extend: {- overflow: "scroll",- height: "100%",- scheme: "monokai",- author: "wimer hazenberg (http://www.monokai.nl)",- base00: theme.GRID_BG_COLOR,- },- }}- />- );-};--const LiveEditor: React.FC = () => {- const viewMode = useConfig(state => state.viewMode);- const [contextOpened, setContextOpened] = React.useState(false);- const [contextPosition, setContextPosition] = React.useState({- x: 0,- y: 0,- });-- return (- <StyledLiveEditor- onContextMenuCapture={e => {- e.preventDefault();- setContextOpened(true);- setContextPosition({ x: e.pageX, y: e.pageY });- }}- onClick={() => setContextOpened(false)}- >- <div- style={{- position: "fixed",- top: contextPosition.y,- left: contextPosition.x,- zIndex: 100,- }}- >- <Menu opened={false} shadow="sm">- <Menu.Dropdown>- <Menu.Item>- <Text size="xs">Download as Image</Text>- </Menu.Item>- <Menu.Item>- <Text size="xs">Zoom to Fit</Text>- </Menu.Item>- <Menu.Item>- <Text size="xs">Rotate</Text>- </Menu.Item>- </Menu.Dropdown>- </Menu>- </div>-- <View />- </StyledLiveEditor>- );-};--export default LiveEditor;diff --git a/src/containers/Toolbar/AccountMenu.tsx b/src/containers/Toolbar/AccountMenu.tsxnew file mode 100644index 00000000..540580e2--- /dev/null+++ b/src/containers/Toolbar/AccountMenu.tsx@@ -0,0 +1,77 @@+import React from "react";+import Link from "next/link";+import { Menu, Avatar, Text } from "@mantine/core";+import { MdOutlineWorkspacePremium } from "react-icons/md";+import { VscSignIn, VscFeedback, VscSignOut } from "react-icons/vsc";+import useModal from "src/store/useModal";+import useUser from "src/store/useUser";+import * as Styles from "./styles";++export const AccountMenu = () => {+ const user = useUser(state => state.user);+ const premium = useUser(state => state.premium);+ const logout = useUser(state => state.logout);+ const setVisible = useModal(state => state.setVisible);++ return (+ <Menu shadow="md" trigger="click" closeOnItemClick={false} withArrow>+ <Menu.Target>+ <Styles.StyledToolElement>+ <Avatar+ color="grape"+ variant="filled"+ size={20}+ radius="xl"+ src={user?.user_metadata.avatar_url}+ alt={user?.user_metadata.name}+ >+ {user?.user_metadata.name[0]}+ </Avatar>+ </Styles.StyledToolElement>+ </Menu.Target>+ <Menu.Dropdown>+ {user ? (+ <Menu.Item+ icon={<Avatar color="grape" alt={user.user_metadata.name} size={20} radius="xl" />}+ onClick={() => setVisible("account")(true)}+ closeMenuOnClick+ >+ <Text size="xs">Account</Text>+ </Menu.Item>+ ) : (+ <Link href="/sign-in">+ <Menu.Item icon={<VscSignIn />}>+ <Text size="xs">Sign in</Text>+ </Menu.Item>+ </Link>+ )}+ {!premium && (+ <Menu.Item+ icon={<MdOutlineWorkspacePremium color="red" />}+ onClick={() => setVisible("premium")(true)}+ closeMenuOnClick+ >+ <Text variant="gradient" fw="bold" gradient={{ from: "orange", to: "red" }} size="xs">+ Get Premium+ </Text>+ </Menu.Item>+ )}+ {user && (+ <>+ <Menu.Divider />+ <Menu.Item+ icon={<VscFeedback />}+ onClick={() => setVisible("review")(true)}+ closeMenuOnClick+ >+ <Text size="xs">Feedback</Text>+ </Menu.Item>+ <Menu.Item icon={<VscSignOut />} onClick={() => logout()} closeMenuOnClick>+ <Text size="xs">Log out</Text>+ </Menu.Item>+ </>+ )}+ </Menu.Dropdown>+ </Menu>+ );+};diff --git a/src/containers/Toolbar/Logo.tsx b/src/containers/Toolbar/Logo.tsxnew file mode 100644index 00000000..1744cbf5--- /dev/null+++ b/src/containers/Toolbar/Logo.tsx@@ -0,0 +1,27 @@+import React from "react";+import { Flex } from "@mantine/core";+import { JSONCrackLogo } from "src/layout/JsonCrackLogo";+import { isIframe } from "src/lib/utils/widget";+import * as Styles from "./styles";++export const Logo = () => {+ const [logoURL, setLogoURL] = React.useState("CTRL");++ React.useEffect(() => {+ if (typeof window !== "undefined") {+ const url = !isIframe()+ ? "https://jsoncrack.com"+ : window.location.href.replace("widget", "editor");++ setLogoURL(url);+ }+ }, []);++ return (+ <Styles.StyledToolElement title="JSON Crack">+ <Flex gap="xs" align="center" justify="center">+ <JSONCrackLogo fontSize="1.2em" href={logoURL} target={isIframe() ? "_blank" : "_parent"} />+ </Flex>+ </Styles.StyledToolElement>+ );+};diff --git a/src/containers/Toolbar/ToolsMenu.tsx b/src/containers/Toolbar/ToolsMenu.tsxnew file mode 100644index 00000000..ca554926--- /dev/null+++ b/src/containers/Toolbar/ToolsMenu.tsx@@ -0,0 +1,37 @@+import React from "react";+import { Menu, Flex } from "@mantine/core";+import { CgChevronDown } from "react-icons/cg";+import { SiJsonwebtokens } from "react-icons/si";+import { VscSearchFuzzy, VscJson, VscGroupByRefType } from "react-icons/vsc";+import useModal from "src/store/useModal";+import * as Styles from "./styles";++export const ToolsMenu = () => {+ const setVisible = useModal(state => state.setVisible);++ return (+ <Menu shadow="md" withArrow>+ <Menu.Target>+ <Styles.StyledToolElement>+ <Flex align="center" gap={3}>+ Tools <CgChevronDown />+ </Flex>+ </Styles.StyledToolElement>+ </Menu.Target>+ <Menu.Dropdown>+ <Menu.Item fz={12} icon={<VscSearchFuzzy />} onClick={() => setVisible("jq")(true)}>+ JSON Query (jq)+ </Menu.Item>+ <Menu.Item fz={12} icon={<VscJson />} onClick={() => setVisible("schema")(true)}>+ JSON Schema+ </Menu.Item>+ <Menu.Item fz={12} icon={<SiJsonwebtokens />} onClick={() => setVisible("jwt")(true)}>+ Decode JWT+ </Menu.Item>+ <Menu.Item fz={12} icon={<VscGroupByRefType />} onClick={() => setVisible("type")(true)}>+ Generate Type+ </Menu.Item>+ </Menu.Dropdown>+ </Menu>+ );+};diff --git a/src/containers/Toolbar/ViewMenu.tsx b/src/containers/Toolbar/ViewMenu.tsxnew file mode 100644index 00000000..a7178836--- /dev/null+++ b/src/containers/Toolbar/ViewMenu.tsx@@ -0,0 +1,142 @@+import React from "react";+import { Menu, Flex, Text } from "@mantine/core";+import { useHotkeys } from "@mantine/hooks";+import ReactGA from "react-ga4";+import toast from "react-hot-toast";+import { CgChevronDown, CgArrowsShrinkH, CgArrowsMergeAltH } from "react-icons/cg";+import { VscExpandAll, VscCollapseAll, VscTarget } from "react-icons/vsc";+import useToggleHide from "src/hooks/useToggleHide";+import { getNextDirection } from "src/lib/utils/graph/getNextDirection";+import useGraph from "src/store/useGraph";+import * as Styles from "./styles";++function rotateLayout(direction: "LEFT" | "RIGHT" | "DOWN" | "UP") {+ if (direction === "LEFT") return 90;+ if (direction === "UP") return 180;+ if (direction === "RIGHT") return 270;+ return 360;+}++export const ViewMenu = () => {+ const { validateHiddenNodes } = useToggleHide();+ const [coreKey, setCoreKey] = React.useState("CTRL");+ const toggleFold = useGraph(state => state.toggleFold);+ const setDirection = useGraph(state => state.setDirection);+ const direction = useGraph(state => state.direction);+ const expandGraph = useGraph(state => state.expandGraph);+ const collapseGraph = useGraph(state => state.collapseGraph);+ const focusFirstNode = useGraph(state => state.focusFirstNode);+ const foldNodes = useGraph(state => state.foldNodes);+ const graphCollapsed = useGraph(state => state.graphCollapsed);++ const toggleFoldNodes = () => {+ toggleFold(!foldNodes);+ toast(`${foldNodes ? "Unfolded" : "Folded"} nodes`);+ };++ const toggleDirection = () => {+ const nextDirection = getNextDirection(direction || "RIGHT");+ if (setDirection) setDirection(nextDirection);+ };++ const toggleExpandCollapseGraph = () => {+ if (graphCollapsed) expandGraph();+ else collapseGraph();++ validateHiddenNodes();+ toast(`${graphCollapsed ? "Expanded" : "Collapsed"} graph.`);+ };++ useHotkeys([+ ["mod+shift+d", toggleDirection],+ ["mod+shift+f", toggleFoldNodes],+ ["mod+shift+c", toggleExpandCollapseGraph],+ [+ "mod+f",+ () => {+ const input = document.querySelector("#search-node") as HTMLInputElement;+ input.focus();+ },+ ],+ ]);++ React.useEffect(() => {+ if (typeof window !== "undefined") {+ setCoreKey(navigator.userAgent.indexOf("Mac OS X") ? "⌘" : "CTRL");+ }+ }, []);++ return (+ <Menu shadow="md" closeOnItemClick={false} withArrow>+ <Menu.Target>+ <Styles.StyledToolElement>+ <Flex align="center" gap={3}>+ View <CgChevronDown />+ </Flex>+ </Styles.StyledToolElement>+ </Menu.Target>+ <Menu.Dropdown>+ <Menu.Item+ fz={12}+ onClick={() => {+ toggleDirection();+ ReactGA.event({+ action: "toggle_layout_direction",+ category: "User",+ label: "Tools",+ });+ }}+ icon={<Styles.StyledFlowIcon rotate={rotateLayout(direction || "RIGHT")} />}+ rightSection={+ <Text ml="md" fz={10} color="dimmed">+ {coreKey} Shift D+ </Text>+ }+ >+ Rotate Layout+ </Menu.Item>+ <Menu.Item+ fz={12}+ onClick={() => {+ toggleFoldNodes();+ ReactGA.event({+ action: "toggle_fold_nodes",+ category: "User",+ label: "Tools",+ });+ }}+ icon={foldNodes ? <CgArrowsShrinkH /> : <CgArrowsMergeAltH />}+ rightSection={+ <Text ml="md" fz={10} color="dimmed">+ {coreKey} Shift F+ </Text>+ }+ >+ {foldNodes ? "Unfold" : "Fold"} Nodes+ </Menu.Item>+ <Menu.Item+ fz={12}+ onClick={() => {+ toggleExpandCollapseGraph();+ ReactGA.event({+ action: "toggle_collapse_nodes",+ category: "User",+ label: "Tools",+ });+ }}+ icon={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}+ rightSection={+ <Text ml="md" fz={10} color="dimmed">+ {coreKey} Shift C+ </Text>+ }+ >+ {graphCollapsed ? "Expand" : "Collapse"} Nodes+ </Menu.Item>+ <Menu.Item fz={12} onClick={focusFirstNode} icon={<VscTarget />}>+ Focus to First Node+ </Menu.Item>+ </Menu.Dropdown>+ </Menu>+ );+};diff --git a/src/containers/Toolbar/ViewModeMenu.tsx b/src/containers/Toolbar/ViewModeMenu.tsxnew file mode 100644index 00000000..dab1a0b5--- /dev/null+++ b/src/containers/Toolbar/ViewModeMenu.tsx@@ -0,0 +1,33 @@+import React from "react";+import { Menu, Flex, SegmentedControl } from "@mantine/core";+import { CgChevronDown } from "react-icons/cg";+import { ViewMode } from "src/enums/viewMode.enum";+import useConfig from "src/store/useConfig";+import * as Styles from "./styles";++export const ViewModeMenu = () => {+ const viewMode = useConfig(state => state.viewMode);+ const setViewMode = useConfig(state => state.setViewMode);++ return (+ <Menu trigger="click" shadow="md" withArrow>+ <Menu.Target>+ <Styles.StyledToolElement title="View Mode">+ <Flex align="center" gap={3}>+ View Mode <CgChevronDown />+ </Flex>+ </Styles.StyledToolElement>+ </Menu.Target>+ <Menu.Dropdown>+ <SegmentedControl+ value={viewMode}+ onChange={setViewMode}+ data={[+ { value: ViewMode.Graph, label: "Graph" },+ { value: ViewMode.Tree, label: "Tree" },+ ]}+ />+ </Menu.Dropdown>+ </Menu>+ );+};diff --git a/src/containers/Toolbar/ZoomMenu.tsx b/src/containers/Toolbar/ZoomMenu.tsxnew file mode 100644index 00000000..161966ce--- /dev/null+++ b/src/containers/Toolbar/ZoomMenu.tsx@@ -0,0 +1,121 @@+import React from "react";+import { Menu, Flex, Input, Text } from "@mantine/core";+import { getHotkeyHandler, useHotkeys } from "@mantine/hooks";+import { BsCheck2 } from "react-icons/bs";+import { CgChevronDown } from "react-icons/cg";+import useConfig from "src/store/useConfig";+import useGraph from "src/store/useGraph";+import * as Styles from "./styles";++export const ZoomMenu = () => {+ const zoomIn = useGraph(state => state.zoomIn);+ const zoomOut = useGraph(state => state.zoomOut);+ const toggleGestures = useConfig(state => state.toggleGestures);+ const toggleChildrenCount = useConfig(state => state.toggleChildrenCount);+ const toggleDarkMode = useConfig(state => state.toggleDarkMode);+ const toggleRulers = useConfig(state => state.toggleRulers);+ const toggleCollapseButton = useConfig(state => state.toggleCollapseButton);+ const toggleImagePreview = useConfig(state => state.toggleImagePreview);++ const centerView = useGraph(state => state.centerView);+ const setZoomFactor = useGraph(state => state.setZoomFactor);++ const gesturesEnabled = useConfig(state => state.gesturesEnabled);+ const childrenCountVisible = useConfig(state => state.childrenCountVisible);+ const darkmodeEnabled = useConfig(state => state.darkmodeEnabled);+ const rulersEnabled = useConfig(state => state.rulersEnabled);+ const collapseButtonVisible = useConfig(state => state.collapseButtonVisible);+ const imagePreviewEnabled = useConfig(state => state.imagePreviewEnabled);++ const zoomFactor = useGraph(state => state.viewPort?.zoomFactor || 1);+ const [tempZoomValue, setTempZoomValue] = React.useState(zoomFactor);++ React.useEffect(() => {+ if (!Number.isNaN(zoomFactor)) setTempZoomValue(zoomFactor);+ }, [zoomFactor]);++ useHotkeys([+ ["shift+Digit0", () => setZoomFactor(100 / 100)],+ ["shift+Digit1", centerView],+ ]);++ return (+ <Menu shadow="md" trigger="click" closeOnItemClick={false} withArrow>+ <Menu.Target>+ <Styles.StyledToolElement>+ <Flex gap={4}>+ {Math.round(zoomFactor * 100)}%+ <CgChevronDown />+ </Flex>+ </Styles.StyledToolElement>+ </Menu.Target>+ <Menu.Dropdown>+ <Menu.Item>+ <Input+ type="number"+ value={Math.round(tempZoomValue * 100)}+ onChange={e => setTempZoomValue(e.currentTarget.valueAsNumber / 100)}+ onKeyDown={getHotkeyHandler([["Enter", () => setZoomFactor(tempZoomValue)]])}+ size="xs"+ rightSection="%"+ />+ </Menu.Item>+ <Menu.Item rightSection="+" onClick={zoomIn}>+ <Text size="xs">Zoom in</Text>+ </Menu.Item>+ <Menu.Item rightSection="-" onClick={zoomOut}>+ <Text size="xs">Zoom out</Text>+ </Menu.Item>+ <Menu.Item rightSection="⇧ 1" onClick={centerView}>+ <Text size="xs">Zoom to fit</Text>+ </Menu.Item>+ <Menu.Item onClick={() => setZoomFactor(50 / 100)}>+ <Text size="xs">Zoom to %50</Text>+ </Menu.Item>+ <Menu.Item rightSection="⇧ 0" onClick={() => setZoomFactor(100 / 100)}>+ <Text size="xs">Zoom to %100</Text>+ </Menu.Item>+ <Menu.Item onClick={() => setZoomFactor(200 / 100)}>+ <Text size="xs">Zoom to %200</Text>+ </Menu.Item>+ <Menu.Divider />+ <Menu.Item+ icon={<BsCheck2 opacity={rulersEnabled ? 100 : 0} />}+ onClick={() => toggleRulers(!rulersEnabled)}+ >+ <Text size="xs">Rulers</Text>+ </Menu.Item>+ <Menu.Item+ icon={<BsCheck2 opacity={gesturesEnabled ? 100 : 0} />}+ onClick={() => toggleGestures(!gesturesEnabled)}+ >+ <Text size="xs">Trackpad Gestures</Text>+ </Menu.Item>+ <Menu.Item+ icon={<BsCheck2 opacity={childrenCountVisible ? 100 : 0} />}+ onClick={() => toggleChildrenCount(!childrenCountVisible)}+ >+ <Text size="xs">Item Count</Text>+ </Menu.Item>+ <Menu.Item+ icon={<BsCheck2 opacity={imagePreviewEnabled ? 100 : 0} />}+ onClick={() => toggleImagePreview(!imagePreviewEnabled)}+ >+ <Text size="xs">Image Link Preview</Text>+ </Menu.Item>+ <Menu.Item+ icon={<BsCheck2 opacity={collapseButtonVisible ? 100 : 0} />}+ onClick={() => toggleCollapseButton(!collapseButtonVisible)}+ >+ <Text size="xs">Show Expand/Collapse</Text>+ </Menu.Item>+ <Menu.Item+ icon={<BsCheck2 opacity={darkmodeEnabled ? 100 : 0} />}+ onClick={() => toggleDarkMode(!darkmodeEnabled)}+ >+ <Text size="xs">Dark Mode</Text>+ </Menu.Item>+ </Menu.Dropdown>+ </Menu>+ );+};diff --git a/src/containers/Toolbar/index.tsx b/src/containers/Toolbar/index.tsxnew file mode 100644index 00000000..df1ba588--- /dev/null+++ b/src/containers/Toolbar/index.tsx@@ -0,0 +1,116 @@+import React from "react";+import { Flex, Group, MediaQuery, Select } from "@mantine/core";+import toast from "react-hot-toast";+import { AiOutlineFullscreen } from "react-icons/ai";+import { FiDownload } from "react-icons/fi";+import { SearchInput } from "src/components/SearchInput";+import { FileFormat } from "src/enums/file.enum";+import { JSONCrackLogo } from "src/layout/JsonCrackLogo";+import useFile from "src/store/useFile";+import useJson from "src/store/useJson";+import useModal from "src/store/useModal";+import { AccountMenu } from "./AccountMenu";+import { Logo } from "./Logo";+import { ToolsMenu } from "./ToolsMenu";+import { ViewMenu } from "./ViewMenu";+import { ViewModeMenu } from "./ViewModeMenu";+import { ZoomMenu } from "./ZoomMenu";+import * as Styles from "./styles";++function fullscreenBrowser() {+ if (!document.fullscreenElement) {+ document.documentElement.requestFullscreen().catch(() => {+ toast.error("Unable to enter fullscreen mode.");+ });+ } else if (document.exitFullscreen) {+ document.exitFullscreen();+ }+}++export const Toolbar: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) => {+ const getJson = useJson(state => state.getJson);+ const setVisible = useModal(state => state.setVisible);++ const setFormat = useFile(state => state.setFormat);+ const format = useFile(state => state.format);++ const handleSave = () => {+ const a = document.createElement("a");+ const file = new Blob([getJson()], { type: "text/plain" });++ a.href = window.URL.createObjectURL(file);+ a.download = "jsoncrack.json";+ a.click();+ };++ return (+ <Styles.StyledTools>+ {isWidget && <Logo />}+ {!isWidget && (+ <MediaQuery smallerThan="xs" styles={{ display: "none" }}>+ <Group spacing="xs" position="left" w="100%" noWrap>+ <Styles.StyledToolElement title="JSON Crack">+ <Flex gap="xs" align="center" justify="center">+ <JSONCrackLogo fontSize="1.2em" />+ </Flex>+ </Styles.StyledToolElement>++ <Select+ defaultValue="json"+ size="xs"+ value={format}+ onChange={setFormat}+ miw={80}+ w={120}+ data={[+ { value: FileFormat.JSON, label: "JSON" },+ { value: FileFormat.YAML, label: "YAML" },+ { value: FileFormat.XML, label: "XML" },+ { value: FileFormat.TOML, label: "TOML" },+ { value: FileFormat.CSV, label: "CSV" },+ ]}+ />++ <ViewModeMenu />+ <Styles.StyledToolElement+ title="Import File"+ onClick={() => setVisible("import")(true)}+ >+ Import+ </Styles.StyledToolElement>+ <ViewMenu />+ <ToolsMenu />+ <Styles.StyledToolElement title="Cloud" onClick={() => setVisible("cloud")(true)}>+ Cloud+ </Styles.StyledToolElement>+ <Styles.StyledToolElement title="Download as File" onClick={handleSave}>+ Download+ </Styles.StyledToolElement>+ </Group>+ </MediaQuery>+ )}+ <Group spacing="xs" position="right" w="100%" noWrap>+ <SearchInput />+ {!isWidget && (+ <>+ <Styles.StyledToolElement+ title="Save as Image"+ onClick={() => setVisible("download")(true)}+ >+ <FiDownload size="18" />+ </Styles.StyledToolElement>+ <ZoomMenu />+ <AccountMenu />+ <Styles.StyledToolElement+ title="Fullscreen"+ $hide={isWidget}+ onClick={fullscreenBrowser}+ >+ <AiOutlineFullscreen size="18" />+ </Styles.StyledToolElement>+ </>+ )}+ </Group>+ </Styles.StyledTools>+ );+};diff --git a/src/containers/Toolbar/styles.ts b/src/containers/Toolbar/styles.tsnew file mode 100644index 00000000..bc1a1934--- /dev/null+++ b/src/containers/Toolbar/styles.ts@@ -0,0 +1,44 @@+import styled from "styled-components";+import { TiFlowMerge } from "react-icons/ti";++export const StyledTools = styled.div`+ position: relative;+ display: flex;+ align-items: center;+ gap: 4px;+ justify-content: space-between;+ height: 36px;+ padding: 4px 8px;+ background: ${({ theme }) => theme.TOOLBAR_BG};+ color: ${({ theme }) => theme.SILVER};+ box-shadow: 0 1px 0px ${({ theme }) => theme.BACKGROUND_TERTIARY};+ z-index: 36;++ @media only screen and (max-width: 320px) {+ display: none;+ }+`;++export const StyledToolElement = styled.button<{ $hide?: boolean }>`+ display: ${({ $hide }) => ($hide ? "none" : "grid")};+ place-content: center;+ font-size: 12px;+ background: none;+ color: ${({ theme }) => theme.INTERACTIVE_NORMAL};+ padding: 6px;+ border-radius: 3px;++ &:hover {+ background-image: linear-gradient(rgba(0, 0, 0, 0.1) 0 0);+ }++ &:hover {+ color: ${({ theme }) => theme.INTERACTIVE_HOVER};+ opacity: 1;+ box-shadow: none;+ }+`;++export const StyledFlowIcon = styled(TiFlowMerge)<{ rotate: number }>`+ transform: rotate(${({ rotate }) => `${rotate}deg`});+`;diff --git a/src/components/Graph/CustomEdge/index.tsx b/src/containers/Views/GraphView/CustomEdge/index.tsxsimilarity index 100%rename from src/components/Graph/CustomEdge/index.tsxrename to src/containers/Views/GraphView/CustomEdge/index.tsxdiff --git a/src/components/Graph/CustomNode/ObjectNode.tsx b/src/containers/Views/GraphView/CustomNode/ObjectNode.tsxsimilarity index 93%rename from src/components/Graph/CustomNode/ObjectNode.tsxrename to src/containers/Views/GraphView/CustomNode/ObjectNode.tsxindex cb36bee6..7cd8f9dc 100644--- a/src/components/Graph/CustomNode/ObjectNode.tsx+++ b/src/containers/Views/GraphView/CustomNode/ObjectNode.tsx@@ -1,5 +1,5 @@import React from "react";-import { CustomNodeProps } from "src/components/Graph/CustomNode";+import { CustomNodeProps } from "src/containers/Views/GraphView/CustomNode";import { TextRenderer } from "./TextRenderer";import * as Styled from "./styles";diff --git a/src/components/Graph/CustomNode/TextNode.tsx b/src/containers/Views/GraphView/CustomNode/TextNode.tsxsimilarity index 97%rename from src/components/Graph/CustomNode/TextNode.tsxrename to src/containers/Views/GraphView/CustomNode/TextNode.tsxindex f18160ad..9d90ad35 100644--- a/src/components/Graph/CustomNode/TextNode.tsx+++ b/src/containers/Views/GraphView/CustomNode/TextNode.tsx@@ -1,7 +1,7 @@import React from "react";import styled from "styled-components";import { MdLink, MdLinkOff } from "react-icons/md";-import { CustomNodeProps } from "src/components/Graph/CustomNode";+import { CustomNodeProps } from "src/containers/Views/GraphView/CustomNode";import useToggleHide from "src/hooks/useToggleHide";import { isContentImage } from "src/lib/utils/graph/calculateNodeSize";import useConfig from "src/store/useConfig";diff --git a/src/components/Graph/CustomNode/TextRenderer.tsx b/src/containers/Views/GraphView/CustomNode/TextRenderer.tsxsimilarity index 100%rename from src/components/Graph/CustomNode/TextRenderer.tsxrename to src/containers/Views/GraphView/CustomNode/TextRenderer.tsxdiff --git a/src/components/Graph/CustomNode/index.tsx b/src/containers/Views/GraphView/CustomNode/index.tsxsimilarity index 100%rename from src/components/Graph/CustomNode/index.tsxrename to src/containers/Views/GraphView/CustomNode/index.tsxdiff --git a/src/components/Graph/CustomNode/styles.tsx b/src/containers/Views/GraphView/CustomNode/styles.tsxsimilarity index 100%rename from src/components/Graph/CustomNode/styles.tsxrename to src/containers/Views/GraphView/CustomNode/styles.tsxdiff --git a/src/components/Graph/ErrorView.tsx b/src/containers/Views/GraphView/ErrorView.tsxsimilarity index 100%rename from src/components/Graph/ErrorView.tsxrename to src/containers/Views/GraphView/ErrorView.tsxdiff --git a/src/components/Graph/PremiumView.tsx b/src/containers/Views/GraphView/PremiumView.tsxsimilarity index 100%rename from src/components/Graph/PremiumView.tsxrename to src/containers/Views/GraphView/PremiumView.tsxdiff --git a/src/components/Graph/index.tsx b/src/containers/Views/GraphView/index.tsxsimilarity index 98%rename from src/components/Graph/index.tsxrename to src/containers/Views/GraphView/index.tsxindex 4d5f3133..1fb181fe 100644--- a/src/components/Graph/index.tsx+++ b/src/containers/Views/GraphView/index.tsx@@ -5,7 +5,7 @@ import { toast } from "react-hot-toast";import { Space } from "react-zoomable-ui";import { ElkRoot } from "reaflow/dist/layout/useLayout";import { useLongPress } from "use-long-press";-import { CustomNode } from "src/components/Graph/CustomNode";+import { CustomNode } from "src/containers/Views/GraphView/CustomNode";import { ViewMode } from "src/enums/viewMode.enum";import useToggleHide from "src/hooks/useToggleHide";import { Loading } from "src/layout/Loading";diff --git a/src/containers/Views/TreeView.tsx b/src/containers/Views/TreeView.tsxnew file mode 100644index 00000000..0a371ffa--- /dev/null+++ b/src/containers/Views/TreeView.tsx@@ -0,0 +1,74 @@+import React from "react";+import { DefaultTheme, useTheme } from "styled-components";+import { JSONTree } from "react-json-tree";+import { TextRenderer } from "src/containers/Views/GraphView/CustomNode/TextRenderer";+import useJson from "src/store/useJson";++type TextColorFn = {+ theme: DefaultTheme;+ $value?: string | unknown;+};++function getValueColor({ $value, theme }: TextColorFn) {+ if ($value && !Number.isNaN(+$value)) return theme.NODE_COLORS.INTEGER;+ if ($value === "true") return theme.NODE_COLORS.BOOL.TRUE;+ if ($value === "false") return theme.NODE_COLORS.BOOL.FALSE;+ if ($value === "null") return theme.NODE_COLORS.NULL;++ // default+ return theme.NODE_COLORS.NODE_VALUE;+}++function getLabelColor({ $type, theme }: { $type?: string; theme: DefaultTheme }) {+ if ($type === "Object") return theme.NODE_COLORS.PARENT_OBJ;+ if ($type === "Array") return theme.NODE_COLORS.PARENT_ARR;+ return theme.NODE_COLORS.PARENT_OBJ;+}++export const TreeView = () => {+ const theme = useTheme();+ const json = useJson(state => state.json);++ return (+ <JSONTree+ data={JSON.parse(json)}+ labelRenderer={(keyPath, nodeType, expanded, expandable) => {+ return (+ <span+ style={{+ color: getLabelColor({+ theme,+ $type: nodeType,+ }),+ }}+ >+ {keyPath[0]}:+ </span>+ );+ }}+ valueRenderer={(valueAsString, value) => {+ return (+ <span+ style={{+ color: getValueColor({+ theme,+ $value: valueAsString,+ }),+ }}+ >+ <TextRenderer>{JSON.stringify(value)}</TextRenderer>+ </span>+ );+ }}+ theme={{+ extend: {+ overflow: "scroll",+ height: "100%",+ scheme: "monokai",+ author: "wimer hazenberg (http://www.monokai.nl)",+ base00: theme.GRID_BG_COLOR,+ },+ }}+ />+ );+};diff --git a/src/pages/editor.tsx b/src/pages/editor.tsxindex d8117799..010f8920 100644--- a/src/pages/editor.tsx+++ b/src/pages/editor.tsx@@ -4,7 +4,7 @@ import Head from "next/head";import { useRouter } from "next/router";import styled from "styled-components";import { BottomBar } from "src/containers/Editor/BottomBar";-import { Tools } from "src/containers/Editor/LiveEditor/Tools";+import { Toolbar } from "src/containers/Toolbar";import { EditorWrapper } from "src/layout/EditorWrapper";import { Loading } from "src/layout/Loading";import useFile from "src/store/useFile";@@ -47,7 +47,7 @@ const EditorPage: React.FC = () => {{hasQuery && <meta name="robots" content="noindex,nofollow" />}</Head><StyledPageWrapper>- <Tools />+ <Toolbar /><StyledEditorWrapper><Panes /></StyledEditorWrapper>diff --git a/src/pages/widget.tsx b/src/pages/widget.tsxindex fbcacfee..50f7a1f6 100644--- a/src/pages/widget.tsx+++ b/src/pages/widget.tsx@@ -5,7 +5,7 @@ import { useRouter } from "next/router";import { ThemeProvider } from "styled-components";import toast from "react-hot-toast";import { darkTheme, lightTheme } from "src/constants/theme";-import { Tools } from "src/containers/Editor/LiveEditor/Tools";+import { Toolbar } from "src/containers/Toolbar";import { EditorWrapper } from "src/layout/EditorWrapper";import useFile from "src/store/useFile";import useGraph from "src/store/useGraph";@@ -17,7 +17,7 @@ interface EmbedMessage {};}-const Graph = dynamic(() => import("src/components/Graph").then(c => c.Graph), {+const Graph = dynamic(() => import("src/containers/Views/GraphView").then(c => c.Graph), {ssr: false,});@@ -63,7 +63,7 @@ const WidgetPage = () => {<meta name="robots" content="noindex,nofollow" /></Head><ThemeProvider theme={theme === "dark" ? darkTheme : lightTheme}>- <Tools isWidget />+ <Toolbar isWidget /><Graph isWidget /></ThemeProvider></EditorWrapper>