From e113e81b91a9724bca3b9b683c4b68b0431f0ca3 Mon Sep 17 00:00:00 2001 From: Sam Lavigne Date: Thu, 31 Aug 2023 00:36:44 -0400 Subject: [PATCH] add secret save functionality (cmd-s) to output json of graph --- src/Graph.svelte | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Graph.svelte b/src/Graph.svelte index cbca98e..d780ef1 100644 --- a/src/Graph.svelte +++ b/src/Graph.svelte @@ -20,6 +20,9 @@ default: ButtonEdge, }; + let downloadLink; + let savedData; + function onClick(e) { if (e.detail.nodeType === "filter") { const newSelected = $nodes.findIndex((n) => n.id === e.detail.id); @@ -28,8 +31,24 @@ } } } + + function onKey(e) { + if ((e.ctrlKey || e.metaKey) && e.key === "s") { + e.preventDefault(); + const out = JSON.stringify({ nodes: $nodes, edges: $edges }, null, 2); + savedData = "data:text/json;charset=utf-8," + encodeURIComponent(out); + setTimeout(() => { + downloadLink.click(); + }, 600); + } + } + + +Download +