-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: work on the node param components
- Loading branch information
1 parent
da326f6
commit 04d4eba
Showing
7 changed files
with
243 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Switch } from "@mui/material"; | ||
import { NodeParamProps } from "./NodeParam"; | ||
|
||
interface Props extends NodeParamProps { | ||
value: boolean; | ||
|
||
onChange: (value: boolean) => void; | ||
} | ||
|
||
export default function NodeBooleanParam({ | ||
htmlFor, | ||
paramKey, | ||
paramConfig, | ||
value, | ||
onChange, | ||
}: Props) { | ||
return ( | ||
<Switch | ||
id={htmlFor} | ||
checked={value} | ||
onChange={(e) => onChange(e.target.checked)} | ||
/> | ||
); | ||
} |
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,111 @@ | ||
import { useAtom } from "jotai"; | ||
import stringify from "json-stable-stringify-without-jsonify"; | ||
import { useState } from "react"; | ||
|
||
import { Typography } from "@mui/material"; | ||
import CodeEditor from "@src/components/CodeEditor"; | ||
import ReactJson, { InteractionProps } from "react-json-view"; | ||
|
||
import TabContext from "@mui/lab/TabContext"; | ||
import TabList from "@mui/lab/TabList"; | ||
import TabPanel from "@mui/lab/TabPanel"; | ||
import { Box, FormHelperText, Tab, useTheme } from "@mui/material"; | ||
|
||
import { jsonEditorAtom, projectScope } from "@src/atoms/projectScope"; | ||
import { fieldSx } from "@src/components/SideDrawer/utils"; | ||
|
||
const isValidJson = (val: any) => { | ||
try { | ||
if (typeof val === "string") JSON.parse(val); | ||
else JSON.stringify(val); | ||
} catch (error) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
export default function Json() { | ||
const theme = useTheme(); | ||
|
||
const [editor, setEditor] = useAtom(jsonEditorAtom, projectScope); | ||
const [codeValid, setCodeValid] = useState(true); | ||
|
||
let isArray = true; | ||
|
||
const baseValue = isArray ? [] : {}; | ||
const formattedJson = stringify(baseValue, { space: 2 }); | ||
const sanitizedValue = JSON.parse(formattedJson); | ||
|
||
const handleEdit = (edit: InteractionProps) => {}; | ||
|
||
return ( | ||
<TabContext value={editor}> | ||
<TabList | ||
onChange={(_, newValue) => { | ||
setEditor(newValue); | ||
setCodeValid(true); | ||
}} | ||
aria-label="JSON editor" | ||
variant="standard" | ||
sx={{ | ||
minHeight: 32, | ||
// mt: -32 / 8, | ||
".MuiPopover-root &": { mt: 0 }, // Don’t have margins in popover cell | ||
|
||
"& .MuiTabs-flexContainer": { | ||
justifyContent: "flex-end", | ||
".MuiPopover-root &": { | ||
justifyContent: "center", | ||
}, | ||
}, | ||
"& .MuiTab-root": { minHeight: 32, py: 0 }, | ||
}} | ||
> | ||
<Tab label="Tree" value="tree" /> | ||
<Tab label="Code" value="code" /> | ||
</TabList> | ||
|
||
<TabPanel value="tree" sx={{ p: 0 }}> | ||
<Box sx={[fieldSx, { overflowX: "auto", typography: "caption" }]}> | ||
<ReactJson | ||
src={sanitizedValue} | ||
onEdit={handleEdit} | ||
onAdd={handleEdit} | ||
onDelete={handleEdit} | ||
theme={theme.palette.mode === "dark" ? "monokai" : "rjv-default"} | ||
iconStyle="triangle" | ||
style={{ | ||
fontFamily: theme.typography.fontFamilyMono, | ||
backgroundColor: "transparent", | ||
minHeight: 100 - 4 - 4, | ||
}} | ||
quotesOnKeys={false} | ||
sortKeys | ||
/> | ||
</Box> | ||
</TabPanel> | ||
|
||
<TabPanel value="code" sx={{ p: 0 }}> | ||
<CodeEditor | ||
defaultLanguage="json" | ||
value={formattedJson || "{\n \n}"} | ||
onValidStatusUpdate={({ isValid }) => setCodeValid(isValid)} | ||
error={!codeValid} | ||
width={undefined} | ||
fullScreenTitle={ | ||
<> | ||
<Typography variant="h6" component="div" style={{ flexGrow: 1 }}> | ||
JSON editor | ||
</Typography> | ||
</> | ||
} | ||
/> | ||
{!codeValid && ( | ||
<FormHelperText error variant="filled"> | ||
Invalid JSON | ||
</FormHelperText> | ||
)} | ||
</TabPanel> | ||
</TabContext> | ||
); | ||
} |
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,22 @@ | ||
import { Typography } from "@mui/material"; | ||
import { NodeParamProps } from "./NodeParam"; | ||
|
||
interface Props extends NodeParamProps { | ||
value: string; | ||
|
||
onChange: (value: string) => void; | ||
} | ||
|
||
export default function NodeNullParam({ | ||
htmlFor, | ||
paramKey, | ||
paramConfig, | ||
value, | ||
onChange, | ||
}: Props) { | ||
return ( | ||
<Typography component="code" variant="body2"> | ||
null | ||
</Typography> | ||
); | ||
} |
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,33 @@ | ||
import { Box } from "@mui/material"; | ||
import { NodeParamProps } from "./NodeParam"; | ||
|
||
interface Props extends NodeParamProps { | ||
value: string; | ||
|
||
onChange: (value: number) => void; | ||
} | ||
|
||
export default function NodeNumberParam({ | ||
htmlFor, | ||
paramKey, | ||
paramConfig, | ||
value, | ||
onChange, | ||
}: Props) { | ||
return ( | ||
<Box | ||
component="input" | ||
id={htmlFor} | ||
type="number" | ||
value={value} | ||
onChange={(e) => onChange(Number(e.target.value))} | ||
height={24} | ||
width={140} | ||
px={1} | ||
border={0} | ||
borderRadius={1} | ||
bgcolor="background.default" | ||
sx={(theme) => ({ outlineColor: theme.palette.primary.main })} | ||
/> | ||
); | ||
} |
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