mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
improve array text detection
This commit is contained in:
parent
82320ad5d7
commit
0f94dc9046
@ -5,7 +5,7 @@ enum ButtonType {
|
|||||||
PRIMARY = "SILVER_DARK",
|
PRIMARY = "SILVER_DARK",
|
||||||
SECONDARY = "BLURPLE",
|
SECONDARY = "BLURPLE",
|
||||||
DANGER = "DANGER",
|
DANGER = "DANGER",
|
||||||
SUCCESS = "SEAGREEN",
|
SUCCESS = "LIGHTGREEN",
|
||||||
WARNING = "ORANGE",
|
WARNING = "ORANGE",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ const ObjectNode: React.FC<CustomNodeProps<[string, unknown][]>> = ({
|
|||||||
(val, idx) =>
|
(val, idx) =>
|
||||||
val[1] && (
|
val[1] && (
|
||||||
<Styled.StyledRow key={idx} width={width}>
|
<Styled.StyledRow key={idx} width={width}>
|
||||||
<Styled.StyledKey>{val[0]}: </Styled.StyledKey>
|
<Styled.StyledKey objectKey>{val[0]}: </Styled.StyledKey>
|
||||||
{val[1]}
|
{val[1]}
|
||||||
</Styled.StyledRow>
|
</Styled.StyledRow>
|
||||||
)
|
)
|
||||||
|
@ -2,12 +2,17 @@ import React from "react";
|
|||||||
import { CustomNodeProps } from ".";
|
import { CustomNodeProps } from ".";
|
||||||
import * as Styled from "./styles";
|
import * as Styled from "./styles";
|
||||||
|
|
||||||
const BondNode: React.FC<CustomNodeProps<string>> = ({ width, height, value }) => {
|
const BondNode: React.FC<CustomNodeProps<string>> = ({
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
value,
|
||||||
|
isParent = false,
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
|
<Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
|
||||||
<Styled.StyledTextWrapper>
|
<Styled.StyledTextWrapper>
|
||||||
<Styled.StyledText width={width} height={height}>
|
<Styled.StyledText width={width} height={height}>
|
||||||
<Styled.StyledKey bond>{value}</Styled.StyledKey>
|
<Styled.StyledKey parent={isParent}>{value}</Styled.StyledKey>
|
||||||
</Styled.StyledText>
|
</Styled.StyledText>
|
||||||
</Styled.StyledTextWrapper>
|
</Styled.StyledTextWrapper>
|
||||||
</Styled.StyledForeignObject>
|
</Styled.StyledForeignObject>
|
@ -1,13 +1,13 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Label, Node, Port, NodeProps } from "reaflow";
|
import { Label, Node, Port, NodeProps } from "reaflow";
|
||||||
import ArrayNode from "./ArrayNode";
|
|
||||||
import BondNode from "./BondNode";
|
|
||||||
import ObjectNode from "./ObjectNode";
|
import ObjectNode from "./ObjectNode";
|
||||||
|
import TextNode from "./TextNode";
|
||||||
|
|
||||||
export interface CustomNodeProps<T> {
|
export interface CustomNodeProps<T> {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
value: T;
|
value: T;
|
||||||
|
isParent?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseLabelStyle = {
|
const baseLabelStyle = {
|
||||||
@ -33,16 +33,18 @@ export const CustomNode = (nodeProps: NodeProps) => {
|
|||||||
const { width, height } = nodeProps;
|
const { width, height } = nodeProps;
|
||||||
|
|
||||||
if (data.text instanceof Object) {
|
if (data.text instanceof Object) {
|
||||||
if (Object.keys(data.text).every((val) => !isNaN(+val))) {
|
|
||||||
const text = Object.values(data.text).join("");
|
|
||||||
return <ArrayNode width={width} height={height} value={text} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const entries = Object.entries(data.text);
|
const entries = Object.entries(data.text);
|
||||||
return <ObjectNode width={width} height={height} value={entries} />;
|
return <ObjectNode width={width} height={height} value={entries} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <BondNode width={width} height={height} value={data.text} />;
|
return (
|
||||||
|
<TextNode
|
||||||
|
isParent={data.data.isParent}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
value={data.text}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
</Node>
|
</Node>
|
||||||
);
|
);
|
||||||
|
@ -22,6 +22,9 @@ export function getEdgeNodes(graph: any, isExpanded: boolean = true): any {
|
|||||||
nodes.push({
|
nodes.push({
|
||||||
id: el.id,
|
id: el.id,
|
||||||
text: el.text,
|
text: el.text,
|
||||||
|
data: {
|
||||||
|
isParent: el.parent,
|
||||||
|
},
|
||||||
width: isExpanded ? 35 + longestLine * 8 : 180,
|
width: isExpanded ? 35 + longestLine * 8 : 180,
|
||||||
height: isExpanded ? 30 + lines.length * 10 : 50,
|
height: isExpanded ? 30 + lines.length * 10 : 50,
|
||||||
});
|
});
|
||||||
|
2
src/typings/styled.d.ts
vendored
2
src/typings/styled.d.ts
vendored
@ -19,7 +19,7 @@ declare module "styled-components" {
|
|||||||
CRIMSON: string;
|
CRIMSON: string;
|
||||||
DARK_SALMON: string;
|
DARK_SALMON: string;
|
||||||
DANGER: string;
|
DANGER: string;
|
||||||
SEAGREEN: string;
|
LIGHTGREEN: string;
|
||||||
ORANGE: string;
|
ORANGE: string;
|
||||||
SILVER: string;
|
SILVER: string;
|
||||||
SILVER_DARK: string;
|
SILVER_DARK: string;
|
||||||
|
@ -14,23 +14,31 @@ export const parser = (input: string | string[]) => {
|
|||||||
) => {
|
) => {
|
||||||
if (!os) return [];
|
if (!os) return [];
|
||||||
|
|
||||||
return [os].flat().map((o) => ({
|
return [os].flat().map((o) => {
|
||||||
id: nextId(),
|
const isObject = o instanceof Object;
|
||||||
text: Object.fromEntries(
|
|
||||||
Object.entries(o).filter(
|
return {
|
||||||
([k, v]) => !Array.isArray(v) && !(v instanceof Object)
|
id: nextId(),
|
||||||
)
|
text: !isObject
|
||||||
),
|
? o.toString()
|
||||||
children: Object.entries(o)
|
: Object.fromEntries(
|
||||||
.filter(([k, v]) => Array.isArray(v) || typeof v === "object")
|
Object.entries(o).filter(
|
||||||
.flatMap(([k, v]) => [
|
([k, v]) => !Array.isArray(v) && !(v instanceof Object)
|
||||||
{
|
)
|
||||||
id: nextId(),
|
),
|
||||||
text: k,
|
parent: false,
|
||||||
children: extract(v, nextId),
|
children: Object.entries(o)
|
||||||
},
|
.filter(([k, v]) => Array.isArray(v) || typeof v === "object")
|
||||||
]),
|
.flatMap(([k, v]) => [
|
||||||
}));
|
{
|
||||||
|
id: nextId(),
|
||||||
|
text: k,
|
||||||
|
parent: true,
|
||||||
|
children: extract(v, nextId),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const relationships = (xs: { id: string; children: never[] }[]) => {
|
const relationships = (xs: { id: string; children: never[] }[]) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user