Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/EditorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function EditorPanel({
acceptFiles,
hasClear,
hasCopy = true,
hasPrettier = true,
topNotifications,
language,
defaultValue,
Expand All @@ -63,6 +64,7 @@ export default function EditorPanel({
const [showSettingsDialogue, setSettingsDialog] = useState(false);
const [value, setValue] = useState(defaultValue);
const [fetchingUrl, setFetchingUrl] = useState("");
const editorRef = useRef<any>(null);

const options = {
fontSize: 14,
Expand Down Expand Up @@ -137,6 +139,17 @@ export default function EditorPanel({
});
}, [value]);

const prettifyValue = useCallback(async () => {
if (!editorRef.current) return;
const action = editorRef.current.getAction("editor.action.formatDocument");
if (!action) {
toaster.warning("Formatter not available for this input.", { id });
return;
}

await action.run();
}, [id]);

const fetchFile = useCallback(
close => {
(async () => {
Expand Down Expand Up @@ -255,6 +268,17 @@ export default function EditorPanel({
</a>
)}

{hasPrettier && editable && (
<Button
marginRight={10}
iconBefore="clean"
onClick={prettifyValue}
height={28}
>
Prettify
</Button>
)}

{hasCopy && (
<Button
appearance="primary"
Expand Down Expand Up @@ -287,6 +311,9 @@ export default function EditorPanel({
language={language}
value={value}
options={options}
onMount={editor => {
editorRef.current = editor;
}}
onChange={value => {
setValue(value);
onChange(value);
Expand Down
5 changes: 4 additions & 1 deletion components/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface MonacoProps {
options?: any;
defaultValue?: string;
onChange: (value: string) => void;
onMount?: (editor: any) => void;
}

export const Monaco: React.FC<MonacoProps> = ({
Expand All @@ -24,7 +25,8 @@ export const Monaco: React.FC<MonacoProps> = ({
height,
width,
options,
onChange
onChange,
onMount
}) => {
return (
<Editor
Expand All @@ -35,6 +37,7 @@ export const Monaco: React.FC<MonacoProps> = ({
width={width}
options={options}
onChange={onChange}
onMount={onMount}
loading={
<Pane
display="flex"
Expand Down