Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"@openzeppelin/contracts-upgradeable@npm:4.8.3": "npm:4.9.6",
"@openzeppelin/contracts-upgradeable@npm:4.9.3": "npm:4.9.6",
"elliptic@npm:6.5.4": "npm:6.6.1",
"word-wrap@npm:~1.2.3": "npm:1.2.5"
"word-wrap@npm:~1.2.3": "npm:1.2.5",
"@codemirror/state": "npm:6.5.2"
},
"scripts": {
"check-prerequisites": "scripts/check-prerequisites.sh",
Expand Down
3 changes: 2 additions & 1 deletion web-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"typescript": "^5.6.3"
},
"dependencies": {
"@codemirror/state": "^6.5.2",
"@coinbase/wallet-sdk": "^4.3.2",
"@kleros/kleros-sdk": "workspace:^",
"@kleros/kleros-v2-contracts": "workspace:^",
Expand All @@ -69,7 +70,7 @@
"react-use": "^17.5.1",
"styled-components": "^5.3.3",
"typewriter-effect": "^2.21.0",
"vanilla-jsoneditor": "^0.23.0",
"vanilla-jsoneditor": "^3.3.1",
"viem": "^2.24.1",
"wagmi": "^2.14.15"
}
Expand Down
32 changes: 24 additions & 8 deletions web-devtools/src/components/JSONEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { useEffect, useRef } from "react";
import styled, { css } from "styled-components";

import { JSONEditor as Editor } from "vanilla-jsoneditor";
import {
createJSONEditor,
type JSONEditorPropsOptional,
type JsonEditor as VanillaJsonEditor,
} from "vanilla-jsoneditor";

import { landscapeStyle } from "styles/landscapeStyle";

Expand Down Expand Up @@ -35,14 +39,13 @@ const Container = styled.div`

const JSONEditor = (props: any) => {
const refContainer = useRef<HTMLDivElement | null>(null);
const refEditor = useRef<Editor | null>(null);
const refEditor = useRef<VanillaJsonEditor | null>(null);
const refPrevProps = useRef<JSONEditorPropsOptional>(props);

useEffect(() => {
refEditor.current = new Editor({
target: refContainer.current!,
props: {
...props,
},
refEditor.current = createJSONEditor({
target: refContainer.current as HTMLDivElement,
props,
});

return () => {
Expand All @@ -53,12 +56,25 @@ const JSONEditor = (props: any) => {
};
}, []);

// update props
useEffect(() => {
if (refEditor.current) {
refEditor.current.updateProps(props);
const changedProps = filterUnchangedProps(props, refPrevProps.current);
refEditor.current.updateProps(changedProps);
refPrevProps.current = props;
}
}, [props]);

return <Container ref={refContainer} className={props.className}></Container>;
};

function filterUnchangedProps(
props: JSONEditorPropsOptional,
prevProps: JSONEditorPropsOptional
): JSONEditorPropsOptional {
return Object.fromEntries(
Object.entries(props).filter(([key, value]) => value !== prevProps[key as keyof JSONEditorPropsOptional])
);
}

export default JSONEditor;
Loading
Loading