Skip to content

Commit

Permalink
feat: Added monaco editor and simple schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon S. Pedersen committed Jun 28, 2024
1 parent 4190fb5 commit a39ae61
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 26 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions packages/designer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
"version": "1.0.0-vnext.13",
"name": "@eavfw/quickform-designer",
"dependencies": {
"monaco-editor": "^0.50.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"peerDependencies": {
"@craftjs/core": "^0.2.4",
"@eavfw/apps": "^1.4.0-vnext.33",
"@eavfw/designer": "^1.1.1",
"@eavfw/designer-core": "^1.1.1",
"@eavfw/designer-nodes": "^1.1.2",

"@eavfw/apps": "^1.4.0-vnext.33",
"@eavfw/manifest": "^1.5.0-vnext.15",
"@eavfw/forms": "^1.2.0-vnext.8",
"@eavfw/manifest": "^1.5.0-vnext.15",
"@eavfw/utils": "^1.1.0-vnext.2",

"pako": "^2.0.4",
"@fluentui/react-components": "=>9.46.0 <9.49.2",
"@craftjs/core": "^0.2.4",
"@rjsf/core": "5.18.4",
"@rjsf/fluentui-rc": "5.18.4",
"@rjsf/utils": "5.18.4",
"@rjsf/validator-ajv8": "5.18.4",
"@rjsf/utils": "5.18.4"
"pako": "^2.0.4"
},
"devDependencies": {
"@types/pako": "2.0.3"
Expand All @@ -40,4 +39,4 @@
"scripts": {
"release": "semantic-release -e semantic-release-monorepo"
}
}
}
56 changes: 47 additions & 9 deletions packages/designer/src/Components/Views/QuickFormSourceView.tsx
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;
49 changes: 49 additions & 0 deletions packages/designer/src/Utils/SourceViewSchema.ts
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"] },
}
}
}
]

0 comments on commit a39ae61

Please sign in to comment.