✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.
refactor: remove unused files
AykutSarac3308b22e8bee
diff --git a/apps/www/src/features/editor/views/GraphView/CustomNode/ObjectNode.tsx b/apps/www/src/features/editor/views/GraphView/CustomNode/ObjectNode.tsxdeleted file mode 100644index b6fb7704..00000000--- a/apps/www/src/features/editor/views/GraphView/CustomNode/ObjectNode.tsx+++ /dev/null@@ -1,59 +0,0 @@-import React from "react";-import type { NodeData } from "jsoncrack-react";-import type { CustomNodeProps } from ".";-import { NODE_DIMENSIONS } from "../../../../../constants/graph";-import { TextRenderer } from "./TextRenderer";-import * as Styled from "./styles";--type RowProps = {- row: NodeData["text"][number];- x: number;- y: number;- index: number;-};--const Row = ({ row, x, y, index }: RowProps) => {- const rowPosition = index * NODE_DIMENSIONS.ROW_HEIGHT;-- const getRowText = () => {- if (row.type === "object") return `{${row.childrenCount ?? 0} keys}`;- if (row.type === "array") return `[${row.childrenCount ?? 0} items]`;- return row.value;- };-- return (- <Styled.StyledRow- $value={row.value}- data-key={`${row.key}: ${row.value}`}- data-x={x}- data-y={y + rowPosition}- >- <Styled.StyledKey $type="object">{row.key}: </Styled.StyledKey>- <TextRenderer>{getRowText()}</TextRenderer>- </Styled.StyledRow>- );-};--const Node = ({ node, x, y }: CustomNodeProps) => (- <Styled.StyledForeignObject- data-id={`node-${node.id}`}- width={node.width}- height={node.height}- x={0}- y={0}- $isObject- >- {node.text.map((row, index) => (- <Row key={`${node.id}-${index}`} row={row} x={x} y={y} index={index} />- ))}- </Styled.StyledForeignObject>-);--function propsAreEqual(prev: CustomNodeProps, next: CustomNodeProps) {- return (- JSON.stringify(prev.node.text) === JSON.stringify(next.node.text) &&- prev.node.width === next.node.width- );-}--export const ObjectNode = React.memo(Node, propsAreEqual);diff --git a/apps/www/src/features/editor/views/GraphView/CustomNode/TextNode.tsx b/apps/www/src/features/editor/views/GraphView/CustomNode/TextNode.tsxdeleted file mode 100644index d5afeb78..00000000--- a/apps/www/src/features/editor/views/GraphView/CustomNode/TextNode.tsx+++ /dev/null@@ -1,47 +0,0 @@-import React from "react";-import styled from "styled-components";-import type { CustomNodeProps } from ".";-import { TextRenderer } from "./TextRenderer";-import * as Styled from "./styles";--const StyledTextNodeWrapper = styled.span<{ $isParent: boolean }>`- display: flex;- justify-content: ${({ $isParent }) => ($isParent ? "center" : "flex-start")};- align-items: center;- height: 100%;- width: 100%;- overflow: hidden;- padding: 0 10px;-`;--const Node = ({ node, x, y }: CustomNodeProps) => {- const { text, width, height } = node;- const value = text[0].value;-- return (- <Styled.StyledForeignObject- data-id={`node-${node.id}`}- width={width}- height={height}- x={0}- y={0}- >- <StyledTextNodeWrapper- data-x={x}- data-y={y}- data-key={JSON.stringify(text)}- $isParent={false}- >- <Styled.StyledKey $value={value} $type={typeof text[0].value}>- <TextRenderer>{value}</TextRenderer>- </Styled.StyledKey>- </StyledTextNodeWrapper>- </Styled.StyledForeignObject>- );-};--function propsAreEqual(prev: CustomNodeProps, next: CustomNodeProps) {- return prev.node.text === next.node.text && prev.node.width === next.node.width;-}--export const TextNode = React.memo(Node, propsAreEqual);diff --git a/apps/www/src/features/editor/views/GraphView/CustomNode/index.tsx b/apps/www/src/features/editor/views/GraphView/CustomNode/index.tsxdeleted file mode 100644index ed015b20..00000000--- a/apps/www/src/features/editor/views/GraphView/CustomNode/index.tsx+++ /dev/null@@ -1,59 +0,0 @@-import React from "react";-import { useComputedColorScheme } from "@mantine/core";-import type { NodeData } from "jsoncrack-react";-import type { NodeProps } from "reaflow";-import { Node } from "reaflow";-import { useModal } from "../../../../../store/useModal";-import useGraph from "../stores/useGraph";-import { ObjectNode } from "./ObjectNode";-import { TextNode } from "./TextNode";--export interface CustomNodeProps {- node: NodeData;- x: number;- y: number;- hasCollapse?: boolean;-}--const CustomNodeWrapper = (nodeProps: NodeProps<NodeData>) => {- const setSelectedNode = useGraph(state => state.setSelectedNode);- const setVisible = useModal(state => state.setVisible);- const colorScheme = useComputedColorScheme();-- const handleNodeClick = React.useCallback(- (_: React.MouseEvent<SVGGElement, MouseEvent>, data: NodeData) => {- if (setSelectedNode) setSelectedNode(data);- setVisible("NodeModal", true);- },- [setSelectedNode, setVisible]- );-- return (- <Node- {...nodeProps}- onClick={handleNodeClick as any}- animated={false}- label={null as any}- onEnter={ev => {- ev.currentTarget.style.stroke = "#3B82F6";- }}- onLeave={ev => {- ev.currentTarget.style.stroke = colorScheme === "dark" ? "#424242" : "#BCBEC0";- }}- style={{- fill: colorScheme === "dark" ? "#292929" : "#ffffff",- stroke: colorScheme === "dark" ? "#424242" : "#BCBEC0",- strokeWidth: 1,- }}- >- {({ node, x, y }) => {- if (nodeProps.properties.text[0].key == null)- return <TextNode node={nodeProps.properties as NodeData} x={x} y={y} />;-- return <ObjectNode node={node as NodeData} x={x} y={y} />;- }}- </Node>- );-};--export const CustomNode = React.memo(CustomNodeWrapper);diff --git a/apps/www/src/features/editor/views/GraphView/CustomNode/styles.tsx b/apps/www/src/features/editor/views/GraphView/CustomNode/styles.tsxdeleted file mode 100644index 29b1f4d7..00000000--- a/apps/www/src/features/editor/views/GraphView/CustomNode/styles.tsx+++ /dev/null@@ -1,104 +0,0 @@-import type { DefaultTheme } from "styled-components";-import styled from "styled-components";-import { LinkItUrl } from "react-linkify-it";-import { NODE_DIMENSIONS } from "../../../../../constants/graph";--type TextColorFn = {- theme: DefaultTheme;- $type?: string;- $value?: string | number | null | boolean;-};--function getTextColor({ $value, $type, theme }: TextColorFn) {- if ($value === null) return theme.NODE_COLORS.NULL;- if ($type === "object") return theme.NODE_COLORS.NODE_KEY;- if ($type === "number") return theme.NODE_COLORS.INTEGER;- if ($value === true) return theme.NODE_COLORS.BOOL.TRUE;- if ($value === false) return theme.NODE_COLORS.BOOL.FALSE;- return theme.NODE_COLORS.NODE_VALUE;-}--export const StyledLinkItUrl = styled(LinkItUrl)`- text-decoration: underline;- pointer-events: all;-`;--export const StyledForeignObject = styled.foreignObject<{ $isObject?: boolean }>`- text-align: ${({ $isObject }) => !$isObject && "center"};- color: ${({ theme }) => theme.NODE_COLORS.TEXT};- font-family: monospace;- font-size: 12px;- font-weight: 500;- overflow: hidden;- pointer-events: none;-- &.searched {- background: rgba(27, 255, 0, 0.08);- border: 1px solid ${({ theme }) => theme.TEXT_POSITIVE};- border-radius: 4px;- box-sizing: border-box;- box-shadow: 0 0 0 3px rgba(0, 220, 125, 0.12);- }-- .highlight {- background: rgba(255, 214, 0, 0.2);- border-radius: 2px;- padding: 0 1px;- }-- .renderVisible {- display: flex;- justify-content: center;- align-items: center;- font-size: 12px;- width: 100%;- height: 100%;- overflow: hidden;- cursor: pointer;- }-`;--export const StyledKey = styled.span<{- $type: TextColorFn["$type"];- $value?: TextColorFn["$value"];-}>`- display: inline;- align-items: center;- justify-content: center;- flex: 1;- min-width: 0;- height: auto;- line-height: inherit;- padding: 0; // Remove padding- color: ${({ theme, $type, $value = "" }) => getTextColor({ $value, $type, theme })};- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;-`;--export const StyledRow = styled.span<{ $value: TextColorFn["$value"] }>`- padding: 3px 10px;- height: ${NODE_DIMENSIONS.ROW_HEIGHT}px;- line-height: 24px;- color: ${({ theme, $value }) => getTextColor({ $value, theme, $type: typeof $value })};- display: block;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;- border-bottom: 1px solid ${({ theme }) => theme.NODE_COLORS.DIVIDER};- box-sizing: border-box;-- &:last-of-type {- border-bottom: none;- }-- .searched & {- border-bottom: 1px solid ${({ theme }) => theme.TEXT_POSITIVE};- }-`;--export const StyledChildrenCount = styled.span`- color: ${({ theme }) => theme.NODE_COLORS.CHILD_COUNT};- padding: 10px;- margin-left: -15px;-`;diff --git a/apps/www/src/features/editor/views/GraphView/lib/jsonParser.ts b/apps/www/src/features/editor/views/GraphView/lib/jsonParser.tsdeleted file mode 100644index 4b019839..00000000--- a/apps/www/src/features/editor/views/GraphView/lib/jsonParser.ts+++ /dev/null@@ -1,207 +0,0 @@-/**- * Copyright (c) JSON Crack- * This source code is licensed under the Apache 2.0 license found in the- * LICENSE file in the root directory of this source tree.- */-import { parseTree, getNodePath, type Node } from "jsonc-parser";-import type { EdgeData, NodeData, NodeRow } from "jsoncrack-react";-import { calculateNodeSize } from "./utils/calculateNodeSize";--export type Graph = {- nodes: NodeData[];- edges: EdgeData[];-};--export const parser = (json: string): Graph => {- const jsonTree = parseTree(json);- if (!jsonTree) return { nodes: [], edges: [] };-- const nodes: NodeData[] = [];- const edges: EdgeData[] = [];- let nodeId = 1;- let edgeId = 1;-- function traverse(node: Node, parentId?: string) {- const id = String(nodeId++);- const text: NodeRow[] = [];-- // If parentId is provided, create an edge from parentId to the current node id- if (parentId !== undefined && node.parent?.type === "array") {- edges.push({- id: String(edgeId++),- from: parentId,- to: id,- text: "",- });- }-- const isArray = node.type === "array";- const isRootArray = !node.parent || node.parent.type === "array";- if (isArray && isRootArray) {- const { width, height } = calculateNodeSize(`[${node.children?.length ?? "0"} items]`);- nodes.push({- id,- text: [- {- key: null,- value: `[${node.children?.length ?? 0} items]`,- type: "array",- childrenCount: node.children?.length,- },- ],- width,- height,- path: [],- });-- node.children?.forEach(child => {- traverse(child, id);- });-- return id;- }-- node.children?.forEach(child => {- if (!child.children || !child.children[1]) return traverse(child, id);-- const key = child.children[0].value ?? null;- const valueNode = child.children[1];- const type = valueNode.type;-- if (type === "array") {- const targetIds: string[] = [];-- valueNode.children?.forEach(arrayChild => {- const arrayChildId = traverse(arrayChild, undefined);- if (arrayChildId) targetIds.push(arrayChildId);- });-- text.push({- key,- value: valueNode.value,- type,- to: targetIds.length > 0 ? targetIds : undefined,- childrenCount: valueNode.children?.length,- });-- targetIds.forEach(targetId => {- edges.push({- id: String(edgeId++),- from: id,- to: targetId,- text: key ?? null,- });- });- } else if (type === "object") {- const objectNodeId = traverse(valueNode, id);- text.push({- key,- value: valueNode.value,- type,- childrenCount: Object.keys(valueNode.children ?? {}).length,- ...(objectNodeId && { to: [objectNodeId] }),- });-- if (objectNodeId) {- edges.push({- id: String(edgeId++),- from: id,- to: objectNodeId,- text: key ?? null,- });- }- } else {- text.push({- key,- value: valueNode.value,- type,- });- }- });-- // to handle case where empty object inside array [{}]- if (node.parent?.type === "array" && node.type === "object" && node.children?.length === 0) {- text.push({- key: null,- value: "{0 keys}",- type: "object",- childrenCount: 0,- });- }-- const appendParentKey = () => {- const getParentKey = (targetNode: any) => {- const path = getNodePath(targetNode);- return path?.pop()?.toString();- };-- if (!node.parent) {- return { parentKey: getParentKey(node), parentType: node.type };- }-- if (node.parent.type === "array") {- return { parentKey: getParentKey(node.parent), parentType: "array" };- }-- if (node.parent.type === "property") {- return { parentKey: getParentKey(node), parentType: "object" };- }-- return {- parentKey: getParentKey(node),- parentType: node.parent.type.replace("property", "object"),- };- };-- // its for singular text like string, number, boolean, null- if (text.length === 0) {- if (typeof node.value === "undefined") return;- const { width, height } = calculateNodeSize(node.value);-- nodes.push({- id,- text: [- {- key: null,- value: node.value,- type: node.type,- },- ],- width,- height,- path: getNodePath(node),- ...appendParentKey(),- });- } else {- let t: string | [string, string][];-- if (text.some(t => t.key !== null)) {- t = text.map(t => {- const keyStr = t.key === null ? "" : t.key;- if (t.type === "object") return [keyStr, `{${t.childrenCount ?? 0} keys}`];- if (t.type === "array") return [keyStr, `[${t.childrenCount ?? 0} items]`];- if (t.value === null) return [keyStr, "null"];-- return [keyStr, `${t.value}`];- });- } else {- t = `${text[0].value}`;- }-- const { width, height } = calculateNodeSize(t);- nodes.push({- id,- text,- width,- height,- path: getNodePath(node),- ...appendParentKey(),- });- }-- return id; // Return the current id for referencing in the parent node- }-- traverse(jsonTree);- return { nodes, edges };-};diff --git a/apps/www/src/features/editor/views/GraphView/lib/utils/calculateNodeSize.ts b/apps/www/src/features/editor/views/GraphView/lib/utils/calculateNodeSize.tsdeleted file mode 100644index 14f1efa9..00000000--- a/apps/www/src/features/editor/views/GraphView/lib/utils/calculateNodeSize.ts+++ /dev/null@@ -1,60 +0,0 @@-import { NODE_DIMENSIONS } from "../../../../../../constants/graph";--type Text = number | string | [string, string][];-type Size = { width: number; height: number };--const calculateLines = (text: Text): string => {- if (Array.isArray(text)) {- return text.map(([k, v]) => `${k}: ${JSON.stringify(v).slice(0, 80)}`).join("\n");- }-- return `${text}`;-};--const calculateWidthAndHeight = (str: string, single = false) => {- if (!str) return { width: 45, height: 45 };-- const dummyElement = document.createElement("div");- dummyElement.style.whiteSpace = single ? "nowrap" : "pre-wrap";- dummyElement.innerText = str;- dummyElement.style.fontSize = "12px";- dummyElement.style.width = "fit-content";- dummyElement.style.padding = "0 10px";- dummyElement.style.fontWeight = "500";- dummyElement.style.fontFamily = "monospace";- document.body.appendChild(dummyElement);-- const clientRect = dummyElement.getBoundingClientRect();- const lines = str.split("\n").length;-- const width = clientRect.width + 4;- // Use parent height for single line nodes that are parents- const height = single ? NODE_DIMENSIONS.PARENT_HEIGHT : lines * NODE_DIMENSIONS.ROW_HEIGHT;-- document.body.removeChild(dummyElement);- return { width, height };-};--const sizeCache = new Map<Text, Size>();--// clear cache every 2 mins-setInterval(() => sizeCache.clear(), 120_000);--export const calculateNodeSize = (text: Text, isParent = false) => {- const cacheKey = [text, isParent].toString();-- // check cache if data already exists- if (sizeCache.has(cacheKey)) {- const size = sizeCache.get(cacheKey);- if (size) return size;- }-- const lines = calculateLines(text);- const sizes = calculateWidthAndHeight(lines, typeof text === "string");-- if (isParent) sizes.width += 80;- if (sizes.width > 700) sizes.width = 700;-- sizeCache.set(cacheKey, sizes);- return sizes;-};diff --git a/apps/www/src/features/editor/views/GraphView/lib/utils/getChildrenEdges.ts b/apps/www/src/features/editor/views/GraphView/lib/utils/getChildrenEdges.tsdeleted file mode 100644index b0e18c52..00000000--- a/apps/www/src/features/editor/views/GraphView/lib/utils/getChildrenEdges.ts+++ /dev/null@@ -1,9 +0,0 @@-import type { EdgeData, NodeData } from "jsoncrack-react";--export const getChildrenEdges = (nodes: NodeData[], edges: EdgeData[]): EdgeData[] => {- const nodeIds = nodes.map(node => node.id);-- return edges.filter(- edge => nodeIds.includes(edge.from as string) || nodeIds.includes(edge.to as string)- );-};diff --git a/apps/www/src/features/editor/views/GraphView/lib/utils/getOutgoers.ts b/apps/www/src/features/editor/views/GraphView/lib/utils/getOutgoers.tsdeleted file mode 100644index d14e530e..00000000--- a/apps/www/src/features/editor/views/GraphView/lib/utils/getOutgoers.ts+++ /dev/null@@ -1,33 +0,0 @@-import type { EdgeData, NodeData } from "jsoncrack-react";--type Outgoers = [NodeData[], string[]];--export const getOutgoers = (- nodeId: string,- nodes: NodeData[],- edges: EdgeData[],- parent: string[] = []-): Outgoers => {- const outgoerNodes: NodeData[] = [];- const matchingNodes: string[] = [];-- if (parent.includes(nodeId)) {- const initialParentNode = nodes.find(n => n.id === nodeId);-- if (initialParentNode) outgoerNodes.push(initialParentNode);- }-- const findOutgoers = (currentNodeId: string) => {- const outgoerIds = edges.filter(e => e.from === currentNodeId).map(e => e.to);- const nodeList = nodes.filter(n => {- if (parent.includes(n.id) && !matchingNodes.includes(n.id)) matchingNodes.push(n.id);- return outgoerIds.includes(n.id) && !parent.includes(n.id);- });-- outgoerNodes.push(...nodeList);- nodeList.forEach(node => findOutgoers(node.id));- };-- findOutgoers(nodeId);- return [outgoerNodes, matchingNodes];-};diff --git a/apps/www/src/features/editor/views/GraphView/CustomNode/TextRenderer.tsx b/apps/www/src/features/editor/views/TreeView/TextRenderer.tsxsimilarity index 100%rename from apps/www/src/features/editor/views/GraphView/CustomNode/TextRenderer.tsxrename to apps/www/src/features/editor/views/TreeView/TextRenderer.tsxdiff --git a/apps/www/src/features/editor/views/TreeView/Value.tsx b/apps/www/src/features/editor/views/TreeView/Value.tsxindex 0046a9b8..2e88fa98 100644--- a/apps/www/src/features/editor/views/TreeView/Value.tsx+++ b/apps/www/src/features/editor/views/TreeView/Value.tsx@@ -1,7 +1,7 @@import React from "react";import type { DefaultTheme } from "styled-components";import { useTheme } from "styled-components";-import { TextRenderer } from "../GraphView/CustomNode/TextRenderer";+import { TextRenderer } from "./TextRenderer";type TextColorFn = {theme: DefaultTheme;diff --git a/apps/www/src/lib/utils/generateType.ts b/apps/www/src/lib/utils/generateType.tsdeleted file mode 100644index 255a4a6b..00000000--- a/apps/www/src/lib/utils/generateType.ts+++ /dev/null@@ -1,23 +0,0 @@-import { type FileFormat, TypeLanguage } from "../../enums/file.enum";-import { contentToJson } from "./jsonAdapter";--export const generateType = async (input: string, format: FileFormat, output: TypeLanguage) => {- try {- const inputToJson = await contentToJson(input, format);- const jsonString = JSON.stringify(inputToJson);-- if (output === TypeLanguage.Go) {- const json2go = await import("./json2go.js");- const gofmt = await import("gofmt.js");- const types = json2go.default(jsonString);-- return gofmt.default(types.go);- } else {- const { run } = await import("json_typegen_wasm");- return run("Root", jsonString, JSON.stringify({ output_mode: output }));- }- } catch (error) {- console.error(error);- return "";- }-};