forked from iway1/trpc-panel
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
13,707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/trpc-panel/src/react-app/components/form/JSONEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import type JSONEditor from 'jsoneditor'; | ||
|
||
const jsonEditorImport = import('jsoneditor').then(({ default: JSONEditor }) => JSONEditor); | ||
|
||
export default function JSONEditorDemo ({ | ||
value, | ||
onChange, | ||
}: { | ||
value: any; | ||
onChange: (value: any) => void; | ||
}) { | ||
const editorRef = useRef(null); | ||
|
||
useEffect(() => { | ||
let abort = false; | ||
let newEditor: JSONEditor; | ||
jsonEditorImport.then(JSONEditor => { | ||
if (!abort && editorRef.current) { | ||
newEditor = new JSONEditor(editorRef.current, { | ||
mode: 'code', | ||
history: false, | ||
onChange: () => { | ||
try { | ||
onChange(newEditor.get()); | ||
} catch (err) {} | ||
}, | ||
}); | ||
newEditor.set(value); | ||
} | ||
}); | ||
|
||
return () => { | ||
abort = true; | ||
if (newEditor) { | ||
newEditor.destroy(); | ||
} | ||
}; | ||
}, [ editorRef.current, value ]); | ||
|
||
return ( | ||
<div className="jsoneditor-react-container" ref={editorRef} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/trpc-panel/src/react-app/components/icons/ToggleJsonIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
|
||
export function ToggleJsonIcon({ className }: { className?: string }) { | ||
return ( | ||
<svg | ||
id="Layer_1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
className={className} | ||
> | ||
<defs> | ||
<style>{`.cls-1{fill:#444;fill-rule:evenodd;}`}</style> | ||
</defs> | ||
<title>toggle raw JSON input</title> | ||
<path | ||
className="cls-1" | ||
d="M8 3a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2H3v2h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h2v-2H8v-5a2 2 0 0 0-2-2a2 2 0 0 0 2-2V5h2V3m6 0a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1v2h-1a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-2v-2h2v-5a2 2 0 0 1 2-2a2 2 0 0 1-2-2V5h-2V3h2Z" | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.