2022-04-11 01:48:17 +00:00
|
|
|
import React from "react";
|
|
|
|
import Layout from "@theme/Layout";
|
|
|
|
import { SquigglePlayground } from "../components/SquigglePlayground";
|
|
|
|
|
2022-06-21 21:09:42 +00:00
|
|
|
function getHashData() {
|
|
|
|
if (typeof window === "undefined") {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return JSON.parse(window.decodeURIComponent(window.location.hash.slice(1)));
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setHashData(Data) {
|
|
|
|
window.location.hash = window.encodeURIComponent(
|
|
|
|
JSON.stringify({ ...getHashData(), ...Data })
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-11 01:48:17 +00:00
|
|
|
export default function PlaygroundPage() {
|
2022-06-21 21:09:42 +00:00
|
|
|
const playgroundProps = {
|
|
|
|
initialSquiggleString: "normal(0,1)",
|
|
|
|
height: 700,
|
|
|
|
showTypes: true,
|
|
|
|
...getHashData(),
|
|
|
|
onCodeChange: (code) => setHashData({ initialSquiggleString: code }),
|
|
|
|
onSettingsChange: (settings) => {
|
|
|
|
const { showTypes, showControls, showSummary, showEditor } = settings;
|
|
|
|
setHashData({ showTypes, showControls, showSummary, showEditor });
|
|
|
|
},
|
|
|
|
};
|
2022-04-11 01:48:17 +00:00
|
|
|
return (
|
|
|
|
<Layout title="Playground" description="Squiggle Playground">
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
maxWidth: 2000,
|
|
|
|
}}
|
|
|
|
>
|
2022-06-21 21:09:42 +00:00
|
|
|
<SquigglePlayground {...playgroundProps} />
|
2022-04-11 01:48:17 +00:00
|
|
|
</div>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|