-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* context menu, json5 toggle * cleanup file import UX * more import cases supported, fix toggle for value pane * cleanup menus and state * cleanup log * json4 to 5 and vv for schema as well * persist schema, show to users * handle query params, fix serialization bugs
- Loading branch information
Showing
23 changed files
with
972 additions
and
219 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
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,51 @@ | ||
import dynamic from "next/dynamic" | ||
import { SchemaState } from "@/store/main" | ||
|
||
import { EditorMenu } from "./menu" | ||
|
||
export interface EditorPane { | ||
heading: string | ||
editorKey: keyof SchemaState["editors"] | ||
schema?: Record<string, unknown> | ||
value?: string | ||
setValueString: (val: string) => void | ||
} | ||
|
||
const JSONEditor = dynamic( | ||
async () => (await import("./json-editor")).JSONEditor, | ||
{ ssr: false } | ||
) | ||
|
||
export const EditorPane = ({ | ||
schema, | ||
editorKey, | ||
heading, | ||
value, | ||
setValueString, | ||
...props | ||
}: EditorPane) => { | ||
return ( | ||
<> | ||
<div className="flex items-center justify-between rounded-lg"> | ||
<h3 className="text-md pl-2 font-medium w-full">{heading}</h3> | ||
<EditorMenu | ||
heading={heading} | ||
editorKey={editorKey} | ||
value={value} | ||
setValueString={setValueString} | ||
/> | ||
</div> | ||
<JSONEditor | ||
onValueChange={setValueString} | ||
// value={editorValue} | ||
// json schema spec v? allow spec selection | ||
schema={schema} | ||
editorKey={editorKey} | ||
className="flex-1 overflow-auto" | ||
height="100%" | ||
value={value} | ||
{...props} | ||
/> | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,38 @@ | ||
"use client" | ||
|
||
import { useEffect } from "react" | ||
import dynamic from "next/dynamic" | ||
import { useMainStore } from "@/store/main" | ||
|
||
import { Icons } from "../icons" | ||
import { Button } from "../ui/button" | ||
import { EditorPane } from "./editor-pane" | ||
|
||
const JSONEditor = dynamic( | ||
async () => (await import("./json-editor")).JSONEditor, | ||
{ ssr: false } | ||
) | ||
|
||
export const JSONSchemaEditor = () => { | ||
export const JSONSchemaEditor = ({ url }: { url: string | null }) => { | ||
const schemaSpec = useMainStore((state) => state.schemaSpec) | ||
const pristineSchema = useMainStore((state) => state.pristineSchema) | ||
const [loadIndex, setSchema] = useMainStore((state) => [ | ||
state.loadIndex, | ||
state.setSchema, | ||
]) | ||
const loadIndex = useMainStore((state) => state.loadIndex) | ||
|
||
const setValueString = useMainStore((state) => state.setSchemaString) | ||
const value = useMainStore((state) => state.schemaString) | ||
const setSelectedSchema = useMainStore( | ||
(state) => state.setSelectedSchemaFromUrl | ||
) | ||
|
||
useEffect(() => { | ||
loadIndex() | ||
}, [loadIndex]) | ||
|
||
useEffect(() => { | ||
if (url && url?.length && url.startsWith("http")) { | ||
setSelectedSchema(url) | ||
} | ||
}, [url]) | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center justify-between"> | ||
<h3 className="text-lg font-semibold">Schema</h3> | ||
<div> | ||
<Button variant="ghost"> | ||
<Icons.Hamburger className="h-5 w-5" /> | ||
</Button> | ||
</div> | ||
</div> | ||
<JSONEditor | ||
onValueChange={(val) => setSchema(JSON.parse(val))} | ||
value={JSON.stringify(pristineSchema, null, 2)} | ||
// json schema spec v? allow spec selection | ||
schema={schemaSpec} | ||
className="flex-1 overflow-auto" | ||
height="100%" | ||
/> | ||
</> | ||
<EditorPane | ||
editorKey="schema" | ||
heading="Schema" | ||
// json schema spec v? allow spec selection | ||
schema={schemaSpec} | ||
setValueString={setValueString} | ||
value={value} | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,35 +1,21 @@ | ||
"use client" | ||
|
||
import dynamic from "next/dynamic" | ||
import { useMainStore } from "@/store/main" | ||
|
||
import { Icons } from "../icons" | ||
import { Button } from "../ui/button" | ||
|
||
const JSONEditor = dynamic( | ||
async () => (await import("./json-editor")).JSONEditor, | ||
{ ssr: false } | ||
) | ||
import { EditorPane } from "./editor-pane" | ||
|
||
export const JSONValueEditor = () => { | ||
const schema = useMainStore((state) => state.schema) | ||
return ( | ||
<> | ||
<div className="flex items-center justify-between"> | ||
<h3 className="text-lg font-semibold">Value</h3> | ||
<div> | ||
<Button variant="ghost"> | ||
<Icons.Hamburger className="h-5 w-5" /> | ||
</Button> | ||
</div> | ||
</div> | ||
const setValueString = useMainStore((state) => state.setTestValueString) | ||
const value = useMainStore((state) => state.testValueString) | ||
|
||
<JSONEditor | ||
value={"{ }"} | ||
schema={schema} | ||
className="flex-1 overflow-auto" | ||
height="100%" | ||
/> | ||
</> | ||
return ( | ||
<EditorPane | ||
editorKey="testValue" | ||
heading={"Test Value"} | ||
schema={schema} | ||
setValueString={setValueString} | ||
value={value} | ||
/> | ||
) | ||
} |
Oops, something went wrong.