diff --git a/app/Header.tsx b/app/Header.tsx
index 339753f..3eddf0d 100644
--- a/app/Header.tsx
+++ b/app/Header.tsx
@@ -1,7 +1,6 @@
-'use client';
-
import React from 'react';
import ThemeSwitcher from '@/Components/ThemeSwitcher';
+import Link from 'next/link';
const Header = () => {
@@ -13,9 +12,12 @@ const Header = () => {
diff --git a/app/jsonparser/ExportModal.tsx b/app/jsonparser/ExportModal.tsx
new file mode 100644
index 0000000..63fbd18
--- /dev/null
+++ b/app/jsonparser/ExportModal.tsx
@@ -0,0 +1,127 @@
+'use client';
+
+import React, { useEffect, useState } from 'react';
+import {
+ Button,
+ Checkbox,
+ CheckboxGroup,
+ Modal,
+ ModalBody,
+ ModalContent,
+ ModalFooter,
+ ModalHeader,
+ Textarea
+} from '@nextui-org/react';
+import { toast } from 'react-toastify';
+import { HiOutlineDownload, HiOutlineDuplicate } from 'react-icons/hi';
+
+const workflows = new Map string>([
+ [ 'minify', (json) => {
+ try {
+ const value = JSON.parse(json);
+ return JSON.stringify(value);
+ } catch (e) {
+ toast.error(`Operation Failed: ${ e }`, { autoClose: 5000 });
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-expect-error
+ return e.toString();
+ }
+ } ]
+]);
+
+type Props = { isOpen: boolean, onOpenChange: () => void, value: string };
+
+const ExportModal = ({ isOpen, onOpenChange, value }: Props) => {
+ const [ workflow, setWorkflow ] = useState([]);
+ const [ editorValue, setEditorValue ] = useState(value);
+ useEffect(() => {
+ setEditorValue(value);
+ }, [ value ]);
+
+ const [ exportValue, setExportValue ] = useState(editorValue);
+ useEffect(() => {
+ let value = editorValue;
+ for (const fn of workflow) {
+ const func = workflows.get(fn);
+ value = func ? func(value) : value;
+ }
+ setExportValue(value);
+ }, [ workflow, editorValue ]);
+
+ return (
+
+
+ { (onClose) => (
+ <>
+ Export
+
+
+ Minify
+
+
+
+
+
+ }
+ onClick={ () => {
+ const blob = new Blob([ exportValue ], { type: 'application/json' });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = 'value.json';
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ toast.success('File Downloaded');
+ } }
+ >
+ Download
+
+ }
+ onClick={ () => {
+ navigator.clipboard.writeText(exportValue);
+ toast.success('Copied to Clipboard');
+ } }
+ >
+ Copy
+
+
+
+
+
+
+ >
+ ) }
+
+
+ );
+};
+
+export default ExportModal;
+
diff --git a/app/jsonparser/JsonEditor.tsx b/app/jsonparser/JsonEditor.tsx
new file mode 100644
index 0000000..caad30a
--- /dev/null
+++ b/app/jsonparser/JsonEditor.tsx
@@ -0,0 +1,34 @@
+'use client';
+
+import React, { useState } from 'react';
+import MonacoEditor from '@/app/public/MonacoEditor';
+import { Button, useDisclosure } from '@nextui-org/react';
+import ExportModal from '@/app/jsonparser/ExportModal';
+import { HiOutlineExternalLink } from 'react-icons/hi';
+
+const DEFAULT_EDITOR_VALUE = '{}';
+
+const JsonEditor = () => {
+ const [ editorValue, setEditorValue ] = useState(DEFAULT_EDITOR_VALUE);
+ const { isOpen, onOpen, onOpenChange } = useDisclosure();
+
+ return (
+ <>
+
+ >
+ );
+};
+export default JsonEditor;
diff --git a/app/jsonparser/page.tsx b/app/jsonparser/page.tsx
index 150cb20..9c196b4 100644
--- a/app/jsonparser/page.tsx
+++ b/app/jsonparser/page.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import MonacoEditor from '@/app/public/MonacoEditor';
+import JsonEditor from '@/app/jsonparser/JsonEditor';
const Page = () => {
return (
@@ -7,7 +7,7 @@ const Page = () => {
-
+
>
);
diff --git a/app/public/MonacoEditor.tsx b/app/public/MonacoEditor.tsx
index 07eefab..0c85c2b 100644
--- a/app/public/MonacoEditor.tsx
+++ b/app/public/MonacoEditor.tsx
@@ -1,41 +1,77 @@
'use client';
-import React, { useState } from 'react';
+import React, { useRef, useState } from 'react';
import { Editor as Monaco } from '@monaco-editor/react';
import { useTheme } from 'next-themes';
-import { Button } from '@nextui-org/react';
-import { HiOutlineClipboardDocumentList } from 'react-icons/hi2';
+import { Button, Spinner } from '@nextui-org/react';
import { toast } from 'react-toastify';
+import { HiOutlineDuplicate } from 'react-icons/hi';
+import { MdFormatShapes } from 'react-icons/md';
type Props = {
language: string,
defaultValue: string
+ height?: string
+ setValue?: (value: string) => void
}
-const MonacoEditor = (props: Props) => {
+const MonacoEditor = ({ language, defaultValue, height = '75vh', setValue }: Props) => {
const { theme } = useTheme();
- const [ editorValue, setEditorValue ] = useState(props.defaultValue);
- console.log(editorValue);
+ const [ editorValue, setEditorValue ] = useState(defaultValue);
+
+ const editorRef = useRef(null);
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-expect-error
+ const handleEditorDidMount = (editor) => {
+ editorRef.current = editor;
+ };
+ const formatCode = () => {
+ if (editorRef.current) {
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-expect-error
+ editorRef.current.getAction('editor.action.formatDocument').run();
+ }
+ };
+
return (
-
+
setEditorValue(val as string) }
+ defaultValue={ defaultValue }
+ loading={ }
+ onMount={ handleEditorDidMount }
+ onChange={ (val) => {
+ setEditorValue(val as string);
+ if (setValue) {
+ setValue(val as string);
+ }
+ } }
/>
-
+
+