diff --git a/docs/src/components/JSONPathPlayground/index.js b/docs/src/components/JSONPathPlayground/index.js index 92040ce..c75f23f 100644 --- a/docs/src/components/JSONPathPlayground/index.js +++ b/docs/src/components/JSONPathPlayground/index.js @@ -1,5 +1,6 @@ -import React from "react"; -import { useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; + +import { useColorMode } from "@docusaurus/theme-common"; import { Container } from "@mui/material"; import Grid from "@mui/material/Unstable_Grid2"; @@ -23,17 +24,7 @@ const commonEditorOptions = { padding: { bottom: 10, top: 10 }, }; -const theme = "vs-dark"; - -// function handleEditorDidMount(editor, monaco) { -// import("monaco-themes/themes/Tomorrow-Night-Eighties.json") -// .then((themeData) => { -// monaco.editor.defineTheme("Tomorrow-Night-Eighties", themeData); -// }) -// .then((_) => monaco.editor.setTheme("Tomorrow-Night-Eighties")); -// } - -function QueryEditor({ defaultQuery, onChange }) { +function QueryEditor({ defaultQuery, theme, onChange }) { return ( ); } -function JSONEditor({ onChange }) { +function JSONEditor({ onChange, theme }) { const defaultValue = JSON.stringify( { users: [ @@ -73,13 +64,14 @@ function JSONEditor({ onChange }) { ); } -function ResultsEditor({ result }) { +function ResultsEditor({ result, theme, beforeMount }) { return ( { + if (colorMode && monacoRef.current !== null) { + monacoRef.current.editor.setTheme( + colorMode === "light" ? "light" : "vs-dark", + ); + } + }, [colorMode]); + + /** + * Compile the query and update the results. + */ function _onQueryChange(value) { try { const path = jsonpath.compile(value.trim()); @@ -138,6 +152,9 @@ export default function Playground() { } } + /** + * Compile the query and update the results after a timeout. + */ function onQueryChange(value) { clearTimeout(timer); timer = setTimeout(() => _onQueryChange(value), timerInterval); @@ -163,29 +180,31 @@ export default function Playground() { return ( - +

JSONPath Playground

-
+
- + - + - + - + @@ -204,7 +223,7 @@ export default function Playground() {

JSON data is on the left and results are on the right.
- Drag out the third pane on the right to see a normalized path for{" "} + Drag out the extra pane on the right to see a normalized path for each result.
Results are updated automatically after one second of inactivity. diff --git a/docs/src/components/JSONPathPlayground/styles.module.css b/docs/src/components/JSONPathPlayground/styles.module.css index 9894540..435c658 100644 --- a/docs/src/components/JSONPathPlayground/styles.module.css +++ b/docs/src/components/JSONPathPlayground/styles.module.css @@ -9,3 +9,8 @@ font-weight: bold; } + +.headingRule { + margin-top: 1em; + margin-bottom: 2em; +} \ No newline at end of file