Skip to content

Commit 1940987

Browse files
authored
Merge pull request #280 from AykutSarac/mona-sans
Cloud updates
2 parents da620a1 + db0536a commit 1940987

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2608
-1139
lines changed

.env.development

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
NEXT_PUBLIC_BASE_URL=http://localhost:3000
1+
NEXT_PUBLIC_BASE_URL=http://localhost:3000
2+
NEXT_PUBLIC_ALTOGIC_ENV_URL=https://jsoncrack.c5-na.altogic.com
3+
NEXT_PUBLIC_ALTOGIC_CLIENT_KEY=f1e92022789f4ccf91273a345ab2bdf8

.env.production

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
NEXT_PUBLIC_BASE_URL=https://jsoncrack.com
1+
NEXT_PUBLIC_BASE_URL=https://jsoncrack.com
2+
NEXT_PUBLIC_ALTOGIC_ENV_URL=https://jsoncrack.c5-na.altogic.com
3+
NEXT_PUBLIC_ALTOGIC_CLIENT_KEY=f1e92022789f4ccf91273a345ab2bdf8

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"trailingComma": "es5",
33
"singleQuote": false,
44
"semi": true,
5-
"printWidth": 85,
5+
"printWidth": 100,
66
"arrowParens": "avoid",
77
"importOrder": [
88
"^(react/(.*)$)|^(react$)",

next.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const withPWA = require("next-pwa")({
99
* @type {import('next').NextConfig}
1010
*/
1111
const nextConfig = {
12-
reactStrictMode: true,
12+
reactStrictMode: false,
1313
};
1414

1515
module.exports = withPWA(nextConfig);

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-crack",
33
"private": true,
4-
"version": "v2.2.0",
4+
"version": "v2.5.0",
55
"author": "https://github.com/AykutSarac",
66
"homepage": "https://jsoncrack.com",
77
"scripts": {
@@ -14,11 +14,17 @@
1414
},
1515
"dependencies": {
1616
"@monaco-editor/react": "^4.4.6",
17+
"@react-oauth/google": "^0.4.0",
1718
"@sentry/nextjs": "^7.16.0",
19+
"@tanstack/react-query": "^4.19.1",
1820
"allotment": "^1.17.0",
19-
"compress-json": "^2.1.2",
21+
"altogic": "^2.3.8",
22+
"axios": "^1.1.3",
23+
"dayjs": "^1.11.6",
2024
"html-to-image": "^1.10.8",
2125
"jsonc-parser": "^3.2.0",
26+
"lodash.debounce": "^4.0.8",
27+
"lz-string": "^1.4.4",
2228
"next": "^12.3.1",
2329
"next-transpile-modules": "^9.1.0",
2430
"react": "^18.2.0",
@@ -28,6 +34,7 @@
2834
"react-icons": "^4.6.0",
2935
"react-in-viewport": "^1.0.0-alpha.28",
3036
"react-linkify-it": "^1.0.7",
37+
"react-syntax-highlighter": "^15.5.0",
3138
"react-zoom-pan-pinch": "^2.1.3",
3239
"reaflow": "^5.0.7",
3340
"styled-components": "^5.3.6",
@@ -36,9 +43,12 @@
3643
"devDependencies": {
3744
"@testing-library/react": "^13.3.0",
3845
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
46+
"@types/lodash.debounce": "^4.0.7",
47+
"@types/lz-string": "^1.3.34",
3948
"@types/node": "^18.7.21",
4049
"@types/react": "18.0.21",
4150
"@types/react-color": "^3.0.6",
51+
"@types/react-syntax-highlighter": "^15.5.5",
4252
"@types/styled-components": "^5.1.26",
4353
"eslint": "8.24.0",
4454
"eslint-config-next": "12.3.1",

public/assets/404.svg

+1-1
Loading

public/assets/Mona-Sans.woff2

131 KB
Binary file not shown.

public/assets/icon.png

44.3 KB
Loading

src/api/altogic.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { APIError, createClient } from "altogic";
2+
3+
let envUrl = process.env.NEXT_PUBLIC_ALTOGIC_ENV_URL as string;
4+
let clientKey = process.env.NEXT_PUBLIC_ALTOGIC_CLIENT_KEY as string;
5+
6+
const altogic = createClient(envUrl, clientKey);
7+
8+
export interface AltogicResponse<T> {
9+
data: T;
10+
errors: APIError | null;
11+
}
12+
13+
export { altogic };

src/components/Button/index.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled, { DefaultTheme } from "styled-components";
44
enum ButtonType {
55
PRIMARY = "PRIMARY",
66
SECONDARY = "BLURPLE",
7+
TERTIARY = "PURPLE",
78
DANGER = "DANGER",
89
SUCCESS = "SEAGREEN",
910
WARNING = "ORANGE",
@@ -16,7 +17,7 @@ interface ButtonProps {
1617

1718
type ConditionalProps =
1819
| ({
19-
link?: boolean;
20+
link: boolean;
2021
} & React.ComponentPropsWithoutRef<"a">)
2122
| ({
2223
link?: never;
@@ -29,19 +30,20 @@ function getButtonStatus(status: keyof typeof ButtonType, theme: DefaultTheme) {
2930
const StyledButton = styled.button<{
3031
status: keyof typeof ButtonType;
3132
block: boolean;
33+
link: boolean;
3234
}>`
33-
display: flex;
35+
display: inline-flex;
3436
align-items: center;
3537
background: ${({ status, theme }) => getButtonStatus(status, theme)};
3638
color: #ffffff;
37-
padding: 8px 16px;
38-
min-width: 60px;
39+
padding: ${({ link }) => (link ? "2px 16px" : "8px 16px")};
40+
min-width: 70px;
3941
min-height: 32px;
4042
border-radius: 3px;
43+
font-family: "Mona Sans";
4144
font-size: 14px;
4245
font-weight: 500;
43-
font-family: "Catamaran", sans-serif;
44-
width: ${({ block }) => (block ? "100%" : "fit-content")};
46+
width: ${({ block }) => (block ? "-webkit-fill-available" : "fit-content")};
4547
height: 40px;
4648
background-image: none;
4749
@@ -73,6 +75,7 @@ const StyledButtonContent = styled.div`
7375
gap: 8px;
7476
white-space: nowrap;
7577
text-overflow: ellipsis;
78+
font-weight: 600;
7679
`;
7780

7881
export const Button: React.FC<ButtonProps & ConditionalProps> = ({
@@ -84,10 +87,11 @@ export const Button: React.FC<ButtonProps & ConditionalProps> = ({
8487
}) => {
8588
return (
8689
<StyledButton
87-
as={link ? "a" : "button"}
8890
type="button"
91+
as={link ? "a" : "button"}
8992
status={status ?? "PRIMARY"}
9093
block={block}
94+
link={link}
9195
{...props}
9296
>
9397
<StyledButtonContent>{children}</StyledButtonContent>
+5-20
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
11
import React from "react";
22
// import { useInViewport } from "react-in-viewport";
33
import { CustomNodeProps } from "src/components/CustomNode";
4-
import useConfig from "src/store/useConfig";
4+
import useGraph from "src/store/useGraph";
55
import * as Styled from "./styles";
66

77
const inViewport = true;
88

99
const ObjectNode: React.FC<CustomNodeProps> = ({ node, x, y }) => {
1010
const { text, width, height, data } = node;
1111
const ref = React.useRef(null);
12-
const performanceMode = useConfig(state => state.performanceMode);
12+
const performanceMode = useGraph(state => state.performanceMode);
1313
// const { inViewport } = useInViewport(ref);
1414

1515
if (data.isEmpty) return null;
1616

1717
return (
18-
<Styled.StyledForeignObject
19-
width={width}
20-
height={height}
21-
x={0}
22-
y={0}
23-
ref={ref}
24-
isObject
25-
>
18+
<Styled.StyledForeignObject width={width} height={height} x={0} y={0} ref={ref} isObject>
2619
{(!performanceMode || inViewport) &&
2720
text.map((val, idx) => (
28-
<Styled.StyledRow
29-
data-key={JSON.stringify(val[1])}
30-
data-x={x}
31-
data-y={y}
32-
key={idx}
33-
>
21+
<Styled.StyledRow data-key={JSON.stringify(val[1])} data-x={x} data-y={y} key={idx}>
3422
<Styled.StyledKey objectKey>
3523
{JSON.stringify(val[0]).replaceAll('"', "")}:{" "}
3624
</Styled.StyledKey>
@@ -42,10 +30,7 @@ const ObjectNode: React.FC<CustomNodeProps> = ({ node, x, y }) => {
4230
};
4331

4432
function propsAreEqual(prev: CustomNodeProps, next: CustomNodeProps) {
45-
return (
46-
String(prev.node.text) === String(next.node.text) &&
47-
prev.node.width === next.node.width
48-
);
33+
return String(prev.node.text) === String(next.node.text) && prev.node.width === next.node.width;
4934
}
5035

5136
export default React.memo(ObjectNode, propsAreEqual);

src/components/CustomNode/TextNode.tsx

+45-37
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from "react";
22
import { MdLink, MdLinkOff } from "react-icons/md";
33
// import { useInViewport } from "react-in-viewport";
44
import { CustomNodeProps } from "src/components/CustomNode";
5-
import useConfig from "src/store/useConfig";
65
import useGraph from "src/store/useGraph";
76
import useStored from "src/store/useStored";
87
import styled from "styled-components";
@@ -28,27 +27,34 @@ const StyledExpand = styled.button`
2827

2928
const StyledTextNodeWrapper = styled.div<{ hasCollapse: boolean }>`
3029
display: flex;
31-
justify-content: ${({ hasCollapse }) =>
32-
hasCollapse ? "space-between" : "center"};
30+
justify-content: ${({ hasCollapse }) => (hasCollapse ? "space-between" : "center")};
3331
align-items: center;
3432
height: 100%;
3533
width: 100%;
3634
`;
3735

38-
const TextNode: React.FC<CustomNodeProps> = ({
39-
node,
40-
x,
41-
y,
42-
hasCollapse = false,
43-
}) => {
36+
const StyledImageWrapper = styled.div`
37+
padding: 5px;
38+
`;
39+
40+
const StyledImage = styled.img`
41+
border-radius: 2px;
42+
object-fit: contain;
43+
background: ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT};
44+
`;
45+
46+
const TextNode: React.FC<CustomNodeProps> = ({ node, x, y, hasCollapse = false }) => {
4447
const { id, text, width, height, data } = node;
4548
const ref = React.useRef(null);
4649
const hideCollapse = useStored(state => state.hideCollapse);
47-
const hideChildrenCount = useStored(state => state.hideChildrenCount);
50+
const childrenCount = useStored(state => state.childrenCount);
51+
const imagePreview = useStored(state => state.imagePreview);
4852
const expandNodes = useGraph(state => state.expandNodes);
4953
const collapseNodes = useGraph(state => state.collapseNodes);
5054
const isExpanded = useGraph(state => state.collapsedParents.includes(id));
51-
const performanceMode = useConfig(state => state.performanceMode);
55+
const performanceMode = useGraph(state => state.performanceMode);
56+
const isImage =
57+
!Array.isArray(text) && /(https?:\/\/.*\.(?:png|jpg|gif))/i.test(text) && imagePreview;
5258
// const { inViewport } = useInViewport(ref);
5359

5460
const handleExpand = (e: React.MouseEvent<HTMLButtonElement>) => {
@@ -64,36 +70,38 @@ const TextNode: React.FC<CustomNodeProps> = ({
6470
height={height}
6571
x={0}
6672
y={0}
67-
hideCollapse={hideCollapse}
6873
hasCollapse={data.parent && hasCollapse}
6974
ref={ref}
7075
>
71-
<StyledTextNodeWrapper hasCollapse={data.parent && !hideCollapse}>
72-
{(!performanceMode || inViewport) && (
73-
<Styled.StyledKey
74-
data-x={x}
75-
data-y={y}
76-
data-key={JSON.stringify(text)}
77-
parent={data.parent}
78-
>
79-
<Styled.StyledLinkItUrl>
80-
{JSON.stringify(text).replaceAll('"', "")}
81-
</Styled.StyledLinkItUrl>
82-
</Styled.StyledKey>
83-
)}
84-
85-
{data.parent && data.childrenCount > 0 && !hideChildrenCount && (
86-
<Styled.StyledChildrenCount>
87-
({data.childrenCount})
88-
</Styled.StyledChildrenCount>
89-
)}
76+
{isImage ? (
77+
<StyledImageWrapper>
78+
<StyledImage src={text} width="70" height="70" />
79+
</StyledImageWrapper>
80+
) : (
81+
<StyledTextNodeWrapper hasCollapse={data.parent && hideCollapse}>
82+
{(!performanceMode || inViewport) && (
83+
<Styled.StyledKey
84+
data-x={x}
85+
data-y={y}
86+
data-key={JSON.stringify(text)}
87+
parent={data.parent}
88+
>
89+
<Styled.StyledLinkItUrl>
90+
{JSON.stringify(text).replaceAll('"', "")}
91+
</Styled.StyledLinkItUrl>
92+
</Styled.StyledKey>
93+
)}
94+
{data.parent && data.childrenCount > 0 && childrenCount && (
95+
<Styled.StyledChildrenCount>({data.childrenCount})</Styled.StyledChildrenCount>
96+
)}
9097

91-
{inViewport && data.parent && hasCollapse && !hideCollapse && (
92-
<StyledExpand onClick={handleExpand}>
93-
{isExpanded ? <MdLinkOff size={18} /> : <MdLink size={18} />}
94-
</StyledExpand>
95-
)}
96-
</StyledTextNodeWrapper>
98+
{inViewport && data.parent && hasCollapse && hideCollapse && (
99+
<StyledExpand onClick={handleExpand}>
100+
{isExpanded ? <MdLinkOff size={18} /> : <MdLink size={18} />}
101+
</StyledExpand>
102+
)}
103+
</StyledTextNodeWrapper>
104+
)}
97105
</Styled.StyledForeignObject>
98106
);
99107
};

src/components/CustomNode/index.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ export const CustomNode = (nodeProps: NodeProps) => {
2828
}
2929

3030
return (
31-
<TextNode
32-
node={node as NodeData}
33-
hasCollapse={data.childrenCount > 0}
34-
x={x}
35-
y={y}
36-
/>
31+
<TextNode node={node as NodeData} hasCollapse={data.childrenCount > 0} x={x} y={y} />
3732
);
3833
}}
3934
</Node>

src/components/CustomNode/styles.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const StyledLinkItUrl = styled(LinkItUrl)`
1616

1717
export const StyledForeignObject = styled.foreignObject<{
1818
hasCollapse?: boolean;
19-
hideCollapse?: boolean;
2019
isObject?: boolean;
2120
}>`
2221
text-align: ${({ isObject }) => !isObject && "center"};
@@ -53,11 +52,7 @@ export const StyledForeignObject = styled.foreignObject<{
5352
}
5453
`;
5554

56-
function getKeyColor(
57-
theme: DefaultTheme,
58-
parent: "array" | "object" | false,
59-
objectKey: boolean
60-
) {
55+
function getKeyColor(theme: DefaultTheme, parent: "array" | "object" | false, objectKey: boolean) {
6156
if (parent) {
6257
if (parent === "array") return theme.NODE_COLORS.PARENT_ARR;
6358
return theme.NODE_COLORS.PARENT_OBJ;
@@ -74,8 +69,7 @@ export const StyledKey = styled.span<{
7469
display: inline;
7570
flex: 1;
7671
font-weight: 500;
77-
color: ${({ theme, objectKey = false, parent = false }) =>
78-
getKeyColor(theme, parent, objectKey)};
72+
color: ${({ theme, objectKey = false, parent = false }) => getKeyColor(theme, parent, objectKey)};
7973
font-size: ${({ parent }) => parent && "14px"};
8074
overflow: hidden;
8175
text-overflow: ellipsis;

src/components/ErrorContainer/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import { MdReportGmailerrorred, MdOutlineCheckCircleOutline } from "react-icons/md";
3+
import useJson from "src/store/useJson";
34
import styled from "styled-components";
45

56
const StyledErrorWrapper = styled.div`
@@ -40,7 +41,9 @@ const StyledError = styled.pre`
4041
white-space: pre-line;
4142
`;
4243

43-
export const ErrorContainer = ({ hasError }: { hasError: boolean }) => {
44+
export const ErrorContainer = () => {
45+
const hasError = useJson(state => state.hasError);
46+
4447
return (
4548
<StyledErrorWrapper>
4649
<StyledErrorExpand error={hasError}>

0 commit comments

Comments
 (0)