Skip to content

Commit 09b7d05

Browse files
committed
use jsoneditor instead of react-json-tree
1 parent eba12e7 commit 09b7d05

File tree

6 files changed

+359
-26
lines changed

6 files changed

+359
-26
lines changed

packages/redux-devtools-inspector-monitor/demo/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"typescript": "~5.3.3",
5252
"webpack": "^5.89.0",
5353
"webpack-cli": "^5.1.4",
54-
"webpack-dev-server": "^4.15.1"
54+
"webpack-dev-server": "^4.15.1",
55+
"css-loader": "^6.8.1",
56+
"style-loader": "^3.3.3"
5557
}
5658
}

packages/redux-devtools-inspector-monitor/demo/webpack.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const config: webpack.Configuration = {
3939
},
4040
},
4141
},
42+
{
43+
test: /\.css$/i,
44+
use: ['style-loader', 'css-loader'],
45+
},
4246
],
4347
},
4448
resolve: {

packages/redux-devtools-inspector-monitor/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"lodash.debounce": "^4.0.8",
5151
"react-base16-styling": "^0.9.1",
5252
"react-json-tree": "^0.18.0",
53-
"redux-devtools-themes": "^1.0.0"
53+
"redux-devtools-themes": "^1.0.0",
54+
"vanilla-jsoneditor": "^0.21.4"
5455
},
5556
"devDependencies": {
5657
"@babel/cli": "^7.23.4",

packages/redux-devtools-inspector-monitor/src/tabs/StateTab.tsx

+11-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Action } from 'redux';
44
import getItemString from './getItemString';
55
import getJsonTreeTheme from './getJsonTreeTheme';
66
import { TabComponentProps } from '../ActionPreview';
7+
import { VanillaJSONEditor } from './VanillaJSONEditor';
78

89
const StateTab: React.FunctionComponent<
910
TabComponentProps<any, Action<string>>
@@ -16,19 +17,15 @@ const StateTab: React.FunctionComponent<
1617
isWideLayout,
1718
sortStateTreeAlphabetically,
1819
disableStateTreeCollection,
19-
}) => (
20-
<JSONTree
21-
labelRenderer={labelRenderer}
22-
theme={getJsonTreeTheme(base16Theme)}
23-
data={nextState}
24-
getItemString={(type, data) =>
25-
getItemString(type, data, dataTypeKey, isWideLayout)
26-
}
27-
invertTheme={invertTheme}
28-
hideRoot
29-
sortObjectKeys={sortStateTreeAlphabetically}
30-
{...(disableStateTreeCollection ? { collectionLimit: 0 } : {})}
31-
/>
32-
);
20+
}) => {
21+
return (
22+
<VanillaJSONEditor
23+
content={{
24+
json: nextState
25+
}}
26+
readOnly={true}
27+
/>
28+
);
29+
}
3330

3431
export default StateTab;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useEffect, useRef } from "react";
2+
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'
3+
4+
import { JSONEditor } from "vanilla-jsoneditor";
5+
6+
export const VanillaJSONEditor = (props: any) => {
7+
const refContainer = useRef(null);
8+
const refEditor = useRef(null);
9+
10+
useEffect(() => {
11+
// create editor
12+
console.log("create editor", refContainer.current);
13+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
14+
// @ts-expect-error
15+
refEditor.current = new JSONEditor({
16+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
17+
// @ts-expect-error
18+
target: refContainer.current,
19+
props: {}
20+
});
21+
22+
return () => {
23+
// destroy editor
24+
if (refEditor.current) {
25+
console.log("destroy editor");
26+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
27+
// @ts-expect-error
28+
refEditor.current.destroy();
29+
refEditor.current = null;
30+
}
31+
};
32+
}, []);
33+
34+
// update props
35+
useEffect(() => {
36+
if (refEditor.current) {
37+
console.log("update props", props);
38+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
39+
// @ts-expect-error
40+
refEditor.current.updateProps(props);
41+
}
42+
}, [props]);
43+
44+
return <div style={{height: '100%'}} className="jse-theme-dark" ref={refContainer}></div>;
45+
}

0 commit comments

Comments
 (0)