"use client";
import { useState } from "react";
import yaml from "js-yaml";
import { toolGroups } from "@/config/tools";
import { safeJsonParse } from "@/lib/json";
import { safeYamlParse } from "@/lib/yaml";
import { Editor, EditorProps } from "@/components/ui/editor";
import * as Select from "@/components/ui/select";
import * as Button from "@/components/buttons";
import { Configuration } from "@/components/configuration";
import { Configurations } from "@/components/configurations";
import { ControlMenu } from "@/components/control-menu";
import * as icons from "@/components/icons";
import { PageRootSection } from "@/components/page-root-section";
import { PageSection } from "@/components/page-section";
const indentations = {
two: " ",
four: " ",
};
export default function Page() {
const [form, setForm] = useState({
indentation: indentations.two,
json: '{\n "foo": "bar"\n}',
yaml: "foo: bar",
});
const setFormByJson = (text: string) => {
setForm(prev => ({
...prev,
json: text,
yaml: safeJsonParse(text)
.map(x => yaml.dump(x, { indent: prev.indentation.length, quotingType: '"' }))
.unwrapOr(""),
}));
};
const setFormByYaml = (text: string) => {
setForm(prev => ({
...prev,
json: safeYamlParse(text)
.map(x => JSON.stringify(x, null, prev.indentation))
.unwrapOr(""),
yaml: text,
}));
};
const clearBoth = () => {
setForm(prev => ({
...prev,
json: "",
yaml: "",
}));
};
const onIndentationChange: Select.Props["onValueChange"] = value => {
const jsonYaml = safeJsonParse(form.json)
.map(x => ({
json: JSON.stringify(x, null, value),
yaml: yaml.dump(x, { indent: value.length, quotingType: '"' }),
}))
.unwrapOr({
json: "",
yaml: "",
});
setForm({
indentation: value,
...jsonYaml,
});
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const onJsonChange: EditorProps["onChange"] = value => setFormByJson(value ?? "");
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const onYamlChange: EditorProps["onChange"] = value => setFormByYaml(value ?? "");
const indentationConfig = (
}
title="Indentation"
control={
2 spaces
4 spaces
}
/>
);
const jsonPasteButton = ;
const yamlPasteButton = ;
const jsonFileButton = (
);
const yamlFileButton = (
);
const jsonCopyButton = ;
const yamlCopyButton = ;
const clearButton = (
);
const jsonControl = (
);
const yamlControl = (
);
return (
);
}