-
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.
feat: Added monaco editor and simple schema
- Loading branch information
Simon S. Pedersen
committed
Jun 28, 2024
1 parent
4190fb5
commit a39ae61
Showing
4 changed files
with
112 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
56 changes: 47 additions & 9 deletions
56
packages/designer/src/Components/Views/QuickFormSourceView.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 |
---|---|---|
@@ -1,14 +1,52 @@ | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
import { useQuickFormDefinition } from "../../Contexts/QuickFormDefContext"; | ||
import Editor, { OnMount, useMonaco } from "@monaco-editor/react"; | ||
import type { editor } from 'monaco-editor/esm/vs/editor/editor.api'; | ||
import { sourceViewSchema } from "../../Utils/SourceViewSchema"; | ||
|
||
export const QuickFormSourceView = () => { | ||
try { | ||
const { quickformpayload: updateQuickFormPayload } = useQuickFormDefinition(); | ||
const [height, setHeight] = useState<number>(0); | ||
|
||
const { quickformpayload: updateQuickFormPayload } = useQuickFormDefinition(); | ||
return ( | ||
<div style={{ margin: "15px", backgroundColor: "white", padding: "15px", borderRadius: "5px" }}> | ||
<pre> | ||
{JSON.stringify(updateQuickFormPayload, null, 4)} | ||
</pre> | ||
</div> | ||
) | ||
const data = JSON.stringify(updateQuickFormPayload, null, 4); | ||
const editorRef = useRef<editor.IStandaloneCodeEditor>(); | ||
const div = useCallback((node: HTMLDivElement) => { }, []); | ||
const handleEditorDidMount: OnMount = (editor, monaco) => { | ||
editorRef.current = editor; | ||
editor.onDidContentSizeChange(() => { | ||
setHeight(Math.max(100, editor.getContentHeight())); | ||
editor.layout(); | ||
}); | ||
}; | ||
const monaco = useMonaco(); | ||
useEffect(() => { | ||
if (monaco) { | ||
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ | ||
validate: true, allowComments: true, | ||
//schemas: sourceViewSchema, | ||
schemaValidation: "error", | ||
}); | ||
} | ||
}, [monaco]); | ||
|
||
} | ||
return ( | ||
<div style={{ height: height, width: "100%" }} ref={div}> | ||
{data && | ||
<Editor | ||
options={{ | ||
automaticLayout: true, | ||
scrollBeyondLastLine: false | ||
}} | ||
onMount={handleEditorDidMount} | ||
defaultLanguage="json" | ||
value={data} | ||
/> | ||
} | ||
</div> | ||
); | ||
} finally { | ||
console.groupEnd(); | ||
} | ||
}; | ||
export default QuickFormSourceView; |
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,49 @@ | ||
import { languages } from "monaco-editor"; | ||
|
||
export const sourceViewSchema = | ||
[ | ||
{ | ||
uri: "http://myserver/submitfields.json", // id of the first schema | ||
fileMatch: ["*"], // associate with our model | ||
schema: { | ||
type: "object", | ||
properties: { | ||
uiSchema: { | ||
$ref: "http://myserver/uiSchema.json" // reference the second schema | ||
} | ||
} | ||
} | ||
}, | ||
|
||
{ | ||
uri: "http://myserver/uiSchema.json", // id of the first schema | ||
schema: { | ||
type: "object", | ||
properties: { | ||
"ui:label": { | ||
type: "string" | ||
}, | ||
}, | ||
"patternProperties": { | ||
"^\\w+$": { | ||
"type": "object", | ||
"properties": { | ||
"ui:label": { "type": "string" }, | ||
"ui:placeholder": { "type": "string" }, | ||
"ui:inputProps": { $ref: "http://myserver/inputProps.json" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
uri: "http://myserver/inputProps.json", // id of the first schema | ||
schema: { | ||
type: "object", | ||
properties: { | ||
"beforeIcon": { enum: ["Email", "User"] }, | ||
"afterIcon": { enum: ["Email", "User"] }, | ||
} | ||
} | ||
} | ||
] |