"use client"; import { useCallback, useMemo, useState } from "react"; import YAML from "yaml"; import { toolGroups } from "@/config/tools"; import { Editor, EditorProps } from "@/components/ui/editor"; import { Select, SelectContent, SelectItem, SelectProps, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { ClearButton } from "@/components/buttons/clear"; import { CopyButton } from "@/components/buttons/copy"; import { FileButton } from "@/components/buttons/file"; import { PasteButton } from "@/components/buttons/paste"; import { Configuration } from "@/components/configuration"; import { Configurations } from "@/components/configurations"; import { ControlMenu } from "@/components/control-menu"; import { icons } from "@/components/icons"; import { PageRootSection } from "@/components/page-root-section"; import { PageSection } from "@/components/page-section"; const two = " "; const four = " "; export default function Page() { const [indentation, setIndentation] = useState(two); const [json, setJson] = useState('{\n "foo": "bar"\n}'); const [yaml, setYaml] = useState("foo: bar"); const setJsonReactively = useCallback( (text: string) => { setJson(text); try { const parsed = JSON.parse(text) as unknown; setYaml(YAML.stringify(parsed, { indent: indentation.length, simpleKeys: true })); } catch { setYaml(""); } }, [indentation.length] ); const setYamlReactively = useCallback( (text: string) => { setYaml(text); try { const parsed = YAML.parse(text, { merge: true }) as unknown; setJson(JSON.stringify(parsed, null, indentation)); } catch { setJson(""); } }, [indentation] ); const clearBoth = useCallback(() => { setJson(""); setYaml(""); }, []); const onIndentationChange: SelectProps["onValueChange"] = value => { setIndentation(value); try { const parsed = JSON.parse(json) as unknown; setJson(JSON.stringify(parsed, null, value)); setYaml(YAML.stringify(parsed, { indent: value.length, simpleKeys: true })); } catch { clearBoth(); } }; const onJsonChange: EditorProps["onChange"] = value => setJsonReactively(value ?? ""); const onYamlChange: EditorProps["onChange"] = value => setYamlReactively(value ?? ""); const indentationIcon = useMemo(() => , []); const indentationConfig = ( 2 spaces 4 spaces } /> ); const jsonPasteButton = useMemo( () => , [setJsonReactively] ); const yamlPasteButton = useMemo( () => , [setYamlReactively] ); const jsonFileButton = useMemo( () => ( ), [setJsonReactively] ); const yamlFileButton = useMemo( () => ( ), [setYamlReactively] ); const jsonCopyButton = ; const yamlCopyButton = ; const clearButton = useMemo( () => , [clearBoth] ); const jsonControl = ( ); const yamlControl = ( ); return (
); }