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
39 changes: 0 additions & 39 deletions package-lock.json

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

54 changes: 53 additions & 1 deletion src/components/JsonEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";

export const JsonEditor: React.FC<{
value: string;
Expand Down Expand Up @@ -28,5 +28,57 @@ export const JsonEditor: React.FC<{
))}
</ul>
)}
<div className="export-buttons">
<button
id="import-json-button"
onClick={() => {
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "application/json";

fileInput.onchange = (event) => {
const file = (event.target as HTMLInputElement).files?.[0];
if (!file) return;

console.info("Importing JSON from file:", file.name);

const reader = new FileReader();
reader.onload = (e) => {
const text = e.target?.result;
if (typeof text === "string") {
onChange(text);
} else {
console.error("Failed to read file as text:", file.name);
}
};
reader.onerror = (e) => {
console.error("Error reading file:", e);
};
};
fileInput.click();
}}
>
Import JSON
</button>
<button
id="export-json-button"
onClick={() => {
const blob = new Blob([value], {
type: "application/json",
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");

link.href = url;
link.download = "graph.json";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}}
>
Export JSON
</button>
</div>
</div>
);