Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

feat: remove limitations for free plan

AykutSarac8044fadc35ad
diff --git a/src/containers/Modals/ImportModal/index.tsx b/src/containers/Modals/ImportModal/index.tsx
index 7847adb0..8dc8764d 100644
--- a/src/containers/Modals/ImportModal/index.tsx
+++ b/src/containers/Modals/ImportModal/index.tsx
@@ -11,17 +11,11 @@ import {
Text,
} from "@mantine/core";
import { Dropzone } from "@mantine/dropzone";
-import styled from "styled-components";
import toast from "react-hot-toast";
import { AiOutlineUpload } from "react-icons/ai";
import { FileFormat } from "src/enums/file.enum";
import useFile from "src/store/useFile";
-const StyledFileName = styled.span`
- padding-top: 14px;
- color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
-`;
-
export const ImportModal: React.FC<ModalProps> = ({ opened, onClose }) => {
const [url, setURL] = React.useState("");
const [file, setFile] = React.useState<File | null>(null);
@@ -75,7 +69,7 @@ export const ImportModal: React.FC<ModalProps> = ({ opened, onClose }) => {
placeholder="URL of JSON to fetch"
data-autofocus
/>
- <Paper bg="dark" radius="md" style={{ cursor: "pointer" }}>
+ <Paper radius="md" style={{ cursor: "pointer" }} withBorder>
<Dropzone
onDrop={files => setFile(files[0])}
onReject={files => toast.error(`Unable to load file ${files[0].file.name}`)}
diff --git a/src/containers/Modals/NodeModal/index.tsx b/src/containers/Modals/NodeModal/index.tsx
index c1cba767..6a9263a2 100644
--- a/src/containers/Modals/NodeModal/index.tsx
+++ b/src/containers/Modals/NodeModal/index.tsx
@@ -1,15 +1,7 @@
import React from "react";
-import { Modal, Stack, Text, ScrollArea, ModalProps, Button } from "@mantine/core";
+import { Modal, Stack, Text, ScrollArea, ModalProps } from "@mantine/core";
import { CodeHighlight } from "@mantine/code-highlight";
-import Editor from "@monaco-editor/react";
-import { VscLock } from "react-icons/vsc";
-import { gaEvent } from "src/lib/utils/gaEvent";
-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 useModal from "src/store/useModal";
-import useUser from "src/store/useUser";
const dataToString = (data: any) => {
const text = Array.isArray(data) ? Object.fromEntries(data) : data;
@@ -22,101 +14,24 @@ const dataToString = (data: any) => {
};
export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
- const isPremium = useUser(state => state.premium);
- const editContents = useFile(state => state.editContents);
- const setVisible = useModal(state => state.setVisible);
- const darkmodeEnabled = useConfig(state => (state.darkmodeEnabled ? "vs-dark" : "light"));
const nodeData = useGraph(state => dataToString(state.selectedNode?.text));
const path = useGraph(state => state.selectedNode?.path || "");
- const isParent = useGraph(state => state.selectedNode?.data?.isParent);
- const [editMode, setEditMode] = React.useState(false);
- const [value, setValue] = React.useState(nodeData || "");
-
- const onUpdate = () => {
- if (!value) return setEditMode(false);
- if (!isPremium) return;
- editContents(path!, value, () => {
- setEditMode(false);
- gaEvent("input", "node contents update");
- onModalClose();
- });
- };
-
- const onModalClose = () => {
- setEditMode(false);
- setValue("");
- onClose();
- };
-
- const onEditClick = () => {
- if (isPremium) return setEditMode(true);
- setVisible("premium")(true);
- };
-
- const isEditVisible = React.useMemo(
- () => path !== "{Root}" && !isParent && !isIframe(),
- [isParent, path]
- );
return (
- <Modal title="Node Content" size="auto" opened={opened} onClose={onModalClose} centered>
+ <Modal title="Node Content" size="auto" opened={opened} onClose={onClose} centered>
<Stack py="sm" gap="sm">
<Stack gap="xs">
<Text fz="sm" fw={700}>
Content
</Text>
- {editMode ? (
- <Editor
- theme={darkmodeEnabled}
- defaultValue={nodeData}
- onChange={e => setValue(e!)}
- height={200}
- language="json"
- options={{
- readOnly: !editMode,
- minimap: {
- enabled: false,
- },
- }}
- />
- ) : (
- <ScrollArea>
- <CodeHighlight
- code={nodeData}
- miw={350}
- mah={250}
- maw={600}
- language="json"
- withCopyButton
- />
- </ScrollArea>
- )}
+ <ScrollArea.Autosize mah={250} maw={600}>
+ <CodeHighlight code={nodeData} miw={350} maw={600} language="json" withCopyButton />
+ </ScrollArea.Autosize>
</Stack>
- {isEditVisible && (
- <Stack gap="xs">
- {editMode ? (
- <Button
- variant={value ? "filled" : "light"}
- color={value ? "green" : "blue"}
- onClick={onUpdate}
- >
- {value.length ? "Update Document" : "Cancel"}
- </Button>
- ) : (
- <Button
- onClick={onEditClick}
- leftSection={!isPremium && <VscLock />}
- variant="filled"
- >
- Edit
- </Button>
- )}
- </Stack>
- )}
<Text fz="sm" fw={700}>
Node Path
</Text>
- <ScrollArea>
+ <ScrollArea.Autosize maw={600}>
<CodeHighlight
code={path}
miw={350}
@@ -126,7 +41,7 @@ export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
copiedLabel="Copied to clipboard"
withCopyButton
/>
- </ScrollArea>
+ </ScrollArea.Autosize>
</Stack>
</Modal>
);
diff --git a/src/containers/Toolbar/index.tsx b/src/containers/Toolbar/index.tsx
index 191cb411..684037d8 100644
--- a/src/containers/Toolbar/index.tsx
+++ b/src/containers/Toolbar/index.tsx
@@ -62,6 +62,7 @@ export const Toolbar: React.FC<{ isWidget?: boolean }> = ({ isWidget = false })
{ value: FileFormat.TOML, label: "TOML" },
{ value: FileFormat.CSV, label: "CSV" },
]}
+ allowDeselect={false}
/>
<FileMenu />
@@ -93,7 +94,7 @@ export const Toolbar: React.FC<{ isWidget?: boolean }> = ({ isWidget = false })
style={{ textAlign: "center", gap: 8, alignItems: "center" }}
>
<BsBoxArrowUpLeft />
- You&apos;re invited to try the new editor!
+ Premium editor has moved!
<Badge size="xs" variant="light" color="teal">
New
</Badge>
diff --git a/src/containers/Views/GraphView/ErrorView.tsx b/src/containers/Views/GraphView/ErrorView.tsx
deleted file mode 100644
index db11a716..00000000
--- a/src/containers/Views/GraphView/ErrorView.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import React from "react";
-import styled from "styled-components";
-
-const StyledErrorView = styled.div`
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
-`;
-
-const StyledTitle = styled.h2`
- color: ${({ theme }) => theme.TEXT_DANGER};
-`;
-
-const StyledInfo = styled.p`
- width: 60%;
- text-align: center;
- color: ${({ theme }) => theme.TEXT_NORMAL};
-`;
-
-export const ErrorView = () => (
- <StyledErrorView>
- <StyledTitle>JSON Crack is unable to handle this file!</StyledTitle>
- <StyledInfo>
- We apologize for the problem you encountered. We are doing our best as an Open Source
- community to improve our service. Unfortunately, JSON Crack is currently unable to handle such
- a large file. Please try the tree view from View Modes to see if it works.
- </StyledInfo>
- </StyledErrorView>
-);
diff --git a/src/containers/Views/GraphView/PremiumView.tsx b/src/containers/Views/GraphView/PremiumView.tsx
index 7b528da0..6aeafe55 100644
--- a/src/containers/Views/GraphView/PremiumView.tsx
+++ b/src/containers/Views/GraphView/PremiumView.tsx
@@ -1,7 +1,7 @@
import React from "react";
-import { Button, List, ThemeIcon, Title } from "@mantine/core";
+import { Button, Title } from "@mantine/core";
import styled from "styled-components";
-import { BsCheck } from "react-icons/bs";
+import { MdChevronRight } from "react-icons/md";
import { JSONCrackLogo } from "src/layout/JsonCrackLogo";
const StyledPremiumView = styled.div`
@@ -13,6 +13,7 @@ const StyledPremiumView = styled.div`
width: 100%;
height: 100%;
background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
+ overflow: hidden;
img {
filter: drop-shadow(2px 2px 1px black);
@@ -136,7 +137,7 @@ const StyledInfo = styled.p`
font-weight: 600;
font-size: 20px;
text-align: center;
- color: ${({ theme }) => theme.TEXT_NORMAL};
+ color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
`;
const StyledContent = styled.div`
@@ -159,38 +160,22 @@ export const PremiumView = () => (
<JSONCrackLogo fontSize="4rem" />
</Title>
<StyledInfo>
- Upgrade JSON Crack to premium and explore the full potential of your data!
+ Free version is not optimized to handle data of this size. Check out the premium version for
+ more features and capabilities.
</StyledInfo>
- <List
- c="dimmed"
- mt="lg"
- spacing="xs"
- size="md"
- center
- icon={
- <ThemeIcon color="teal" size={20} radius="xl">
- <BsCheck size="1rem" />
- </ThemeIcon>
- }
- >
- <List.Item>Edit directly on graph</List.Item>
- <List.Item>JSON Schema support</List.Item>
- <List.Item>Visualize data at full capability</List.Item>
- <List.Item>Save & share up to 200 files</List.Item>
- </List>
-
<Button
mt="lg"
size="lg"
component="a"
fw="bolder"
- variant="gradient"
- gradient={{ from: "blue", to: "teal" }}
- href="https://pro.jsoncrack.com/pricing"
+ color="indigo"
+ radius="sm"
+ href="https://pro.jsoncrack.com"
target="_blank"
+ rightSection={<MdChevronRight size="24" />}
>
- UPGRADE TO PREMIUM
+ Take me there
</Button>
</StyledContent>
diff --git a/src/containers/Views/GraphView/index.tsx b/src/containers/Views/GraphView/index.tsx
index d8771d39..07b4e10a 100644
--- a/src/containers/Views/GraphView/index.tsx
+++ b/src/containers/Views/GraphView/index.tsx
@@ -2,20 +2,15 @@ import React from "react";
import dynamic from "next/dynamic";
import styled from "styled-components";
import debounce from "lodash.debounce";
-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/containers/Views/GraphView/CustomNode";
-import { ViewMode } from "src/enums/viewMode.enum";
import useToggleHide from "src/hooks/useToggleHide";
import { Loading } from "src/layout/Loading";
import useConfig from "src/store/useConfig";
import useGraph from "src/store/useGraph";
-import useUser from "src/store/useUser";
-import { NodeData } from "src/types/graph";
import { CustomEdge } from "./CustomEdge";
-import { ErrorView } from "./ErrorView";
import { PremiumView } from "./PremiumView";
const Canvas = dynamic(() => import("reaflow").then(r => r.Canvas), {
@@ -86,10 +81,6 @@ const layoutOptions = {
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
};
-const PREMIUM_LIMIT = 200;
-const ERROR_LIMIT_TREE = 5_000;
-const ERROR_LIMIT = 10_000;
-
const GraphCanvas = ({ isWidget }: GraphProps) => {
const { validateHiddenNodes } = useToggleHide();
const setLoading = useGraph(state => state.setLoading);
@@ -147,22 +138,13 @@ const GraphCanvas = ({ isWidget }: GraphProps) => {
);
};
-function getViewType(nodes: NodeData[]) {
- if (nodes.length > ERROR_LIMIT) return "error";
- if (nodes.length > ERROR_LIMIT_TREE) return "tree";
- if (nodes.length > PREMIUM_LIMIT) return "premium";
- return "graph";
-}
-
export const Graph = ({ isWidget = false }: GraphProps) => {
const setViewPort = useGraph(state => state.setViewPort);
const viewPort = useGraph(state => state.viewPort);
+ const aboveSupportedLimit = useGraph(state => state.nodes.length > 1_000);
const loading = useGraph(state => state.loading);
- const isPremium = useUser(state => state.premium);
- const viewType = useGraph(state => getViewType(state.nodes));
const gesturesEnabled = useConfig(state => state.gesturesEnabled);
const rulersEnabled = useConfig(state => state.rulersEnabled);
- const setViewMode = useConfig(state => state.setViewMode);
const callback = React.useCallback(() => {
const canvas = document.querySelector(".jsoncrack-canvas") as HTMLDivElement | null;
@@ -181,22 +163,14 @@ export const Graph = ({ isWidget = false }: GraphProps) => {
if ("activeElement" in document) (document.activeElement as HTMLElement)?.blur();
}, []);
- if (viewType === "error") {
- return <ErrorView />;
- }
-
- if (viewType === "tree") {
- setViewMode(ViewMode.Tree);
- toast("This document is too large to display as a graph. Switching to tree view.");
- }
-
- if (viewType === "premium" && !isWidget) {
- if (!isPremium) return <PremiumView />;
- }
const debouncedOnZoomChangeHandler = debounce(() => {
setViewPort(viewPort!);
}, 300);
+ if (aboveSupportedLimit) {
+ return <PremiumView />;
+ }
+
return (
<>
<Loading loading={loading} message="Painting graph..." />
diff --git a/src/containers/Views/TreeView/EditModal.tsx b/src/containers/Views/TreeView/EditModal.tsx
deleted file mode 100644
index 878e30d1..00000000
--- a/src/containers/Views/TreeView/EditModal.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import React from "react";
-import { Button, Divider, Group, Modal, TextInput } from "@mantine/core";
-import _unset from "lodash.unset";
-import _update from "lodash.update";
-import { VscLock } from "react-icons/vsc";
-import useFile from "src/store/useFile";
-import useJson from "src/store/useJson";
-import useModal from "src/store/useModal";
-import useUser from "src/store/useUser";
-
-interface EditModalProps {
- opened: boolean;
- setOpened: React.Dispatch<React.SetStateAction<boolean>>;
- selectedValue: string | number | null;
- path: (string | number)[];
- value: string;
- setValue: React.Dispatch<React.SetStateAction<string>>;
- errorMessage: string | null;
- setErrorMessage: React.Dispatch<React.SetStateAction<string | null>>;
-}
-
-export const EditModal = ({
- opened,
- setOpened,
- selectedValue,
- path,
- value,
- setValue,
- errorMessage,
- setErrorMessage,
-}: EditModalProps) => {
- const setContents = useFile(state => state.setContents);
- const getJson = useJson(state => state.getJson);
- const showPremiumModal = useModal(state => state.setVisible("premium"));
- const premium = useUser(state => state.premium);
-
- return (
- <Modal centered title={selectedValue} opened={opened} onClose={() => setOpened(false)}>
- <TextInput
- value={value}
- onChange={e => {
- setValue(e.currentTarget.value);
- }}
- error={errorMessage}
- />
- <Divider my="md" />
- <Group justify="right">
- <Button
- color="red"
- onClick={() => {
- try {
- if (!premium) return showPremiumModal(true);
- const updatedJson = JSON.parse(getJson());
- _unset(updatedJson, path);
-
- setContents({ contents: JSON.stringify(updatedJson, null, 2) });
- setErrorMessage(null);
- setOpened(false);
- } catch (error: any) {
- setErrorMessage(error.message);
- }
- }}
- rightSection={!premium && <VscLock />}
- >
- Delete
- </Button>
- <Button
- onClick={() => {
- try {
- if (!premium) return showPremiumModal(true);
- const updatedJson = _update(JSON.parse(getJson()), path, () => JSON.parse(value));
- setContents({ contents: JSON.stringify(updatedJson, null, 2) });
-
- setErrorMessage(null);
- setOpened(false);
- } catch (error: any) {
- setErrorMessage(error.message);
- }
- }}
- rightSection={!premium && <VscLock />}
- >
- Apply
- </Button>
- </Group>
- </Modal>
- );
-};
diff --git a/src/containers/Views/TreeView/Label.tsx b/src/containers/Views/TreeView/Label.tsx
index f9cecace..1fbb243f 100644
--- a/src/containers/Views/TreeView/Label.tsx
+++ b/src/containers/Views/TreeView/Label.tsx
@@ -1,18 +1,10 @@
import React from "react";
-import { Button, HoverCard } from "@mantine/core";
import { styled, DefaultTheme } from "styled-components";
-import _get from "lodash.get";
-import { VscEdit } from "react-icons/vsc";
import { KeyPath } from "react-json-tree";
-import useJson from "src/store/useJson";
interface LabelProps {
keyPath: KeyPath;
nodeType: string;
- setOpened: React.Dispatch<React.SetStateAction<boolean>>;
- setSelectedValue: React.Dispatch<React.SetStateAction<string | number | null>>;
- setPath: React.Dispatch<React.SetStateAction<(string | number)[]>>;
- setValue: React.Dispatch<React.SetStateAction<string>>;
}
function getLabelColor({ $type, theme }: { $type?: string; theme: DefaultTheme }) {
@@ -30,40 +22,6 @@ const StyledLabel = styled.span<{ $nodeType?: string }>`
}
`;
-export const Label = ({
- keyPath,
- nodeType,
- setOpened,
- setSelectedValue,
- setPath,
- setValue,
-}: LabelProps) => {
- const getJson = useJson(state => state.getJson);
-
- return (
- <HoverCard shadow="sm" openDelay={50} closeDelay={250} withArrow position="left">
- <HoverCard.Target>
- <StyledLabel $nodeType={nodeType}>{keyPath[0]}:</StyledLabel>
- </HoverCard.Target>
- <HoverCard.Dropdown py={4}>
- <Button
- variant="transparent"
- size="xs"
- onClick={() => {
- setOpened(true);
- setSelectedValue(keyPath[0]);
-
- const path = keyPath.toReversed();
- const value = _get(JSON.parse(getJson()), path);
-
- setPath(path);
- setValue(JSON.stringify(value));
- }}
- leftSection={<VscEdit size="12" />}
- >
- Edit
- </Button>
- </HoverCard.Dropdown>
- </HoverCard>
- );
+export const Label = ({ keyPath, nodeType }: LabelProps) => {
+ return <StyledLabel $nodeType={nodeType}>{keyPath[0]}:</StyledLabel>;
};
diff --git a/src/containers/Views/TreeView/index.tsx b/src/containers/Views/TreeView/index.tsx
index 59993a96..486d7f78 100644
--- a/src/containers/Views/TreeView/index.tsx
+++ b/src/containers/Views/TreeView/index.tsx
@@ -2,18 +2,12 @@ import React from "react";
import { useTheme } from "styled-components";
import { JSONTree } from "react-json-tree";
import useJson from "src/store/useJson";
-import { EditModal } from "./EditModal";
import { Label } from "./Label";
import { Value } from "./Value";
export const TreeView = () => {
const theme = useTheme();
const json = useJson(state => state.json);
- const [opened, setOpened] = React.useState(false);
- const [selectedValue, setSelectedValue] = React.useState<string | number | null>(null);
- const [path, setPath] = React.useState<(string | number)[]>([]);
- const [value, setValue] = React.useState("");
- const [errorMessage, setErrorMessage] = React.useState<string | null>(null);
return (
<>
@@ -21,18 +15,7 @@ export const TreeView = () => {
hideRoot
data={JSON.parse(json)}
valueRenderer={(valueAsString, value) => <Value {...{ valueAsString, value }} />}
- labelRenderer={(keyPath, nodeType) => (
- <Label
- {...{
- keyPath,
- nodeType,
- setOpened,
- setSelectedValue,
- setPath,
- setValue,
- }}
- />
- )}
+ labelRenderer={(keyPath, nodeType) => <Label {...{ keyPath, nodeType }} />}
theme={{
extend: {
overflow: "scroll",
@@ -43,18 +26,6 @@ export const TreeView = () => {
},
}}
/>
- <EditModal
- {...{
- opened,
- setOpened,
- selectedValue,
- path,
- value,
- setValue,
- errorMessage,
- setErrorMessage,
- }}
- />
</>
);
};
diff --git a/src/store/useFile.ts b/src/store/useFile.ts
index 602d422b..44dd8182 100644
--- a/src/store/useFile.ts
+++ b/src/store/useFile.ts
@@ -1,6 +1,4 @@
import debounce from "lodash.debounce";
-import _get from "lodash.get";
-import _set from "lodash.set";
import { toast } from "react-hot-toast";
import { create } from "zustand";
import { defaultJson } from "src/constants/data";
@@ -12,7 +10,6 @@ import { documentSvc } from "src/services/document.service";
import useConfig from "./useConfig";
import useGraph from "./useGraph";
import useJson from "./useJson";
-import useUser from "./useUser";
type SetContents = {
contents?: string;
@@ -31,7 +28,6 @@ interface JsonActions {
setContents: (data: SetContents) => void;
fetchFile: (fileId: string) => void;
fetchUrl: (url: string) => void;
- editContents: (path: string, value: string, callback?: () => void) => void;
setFormat: (format: FileFormat) => void;
clear: () => void;
setFile: (fileData: File) => void;
@@ -92,9 +88,7 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
set({ contents: "" });
useJson.getState().clear();
},
- setJsonSchema: jsonSchema => {
- if (useUser.getState().premium) set({ jsonSchema });
- },
+ setJsonSchema: jsonSchema => set({ jsonSchema }),
setFile: fileData => {
set({ fileData, format: fileData.format || FileFormat.JSON });
get().setContents({ contents: fileData.content, hasChanges: false });
@@ -181,37 +175,6 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
get().setContents({ contents: defaultJson, hasChanges: false });
}
},
- editContents: async (path, value, callback) => {
- try {
- if (!value) return;
-
- let tempValue = value;
- const pathJson = _get(JSON.parse(useJson.getState().json), path.replace("{Root}.", ""));
- const changedValue = JSON.parse(value);
-
- if (typeof changedValue !== "string") {
- tempValue = {
- ...filterArrayAndObjectFields(pathJson),
- ...changedValue,
- };
- } else {
- tempValue = tempValue.replaceAll('"', "");
- }
-
- const newJson = _set(
- JSON.parse(useJson.getState().json),
- path.replace("{Root}.", ""),
- tempValue
- );
-
- const contents = await jsonToContent(JSON.stringify(newJson, null, 2), get().format);
-
- get().setContents({ contents });
- if (callback) callback();
- } catch (error) {
- toast.error("Invalid Property!");
- }
- },
}));
export default useFile;