2022-06-16 21:37:20 +00:00
|
|
|
(function () {
|
|
|
|
const vscode = acquireVsCodeApi();
|
|
|
|
|
|
|
|
const container = document.getElementById("root");
|
|
|
|
|
|
|
|
const root = ReactDOM.createRoot(container);
|
2022-06-20 15:06:30 +00:00
|
|
|
function updateContent(text, showSettings) {
|
2022-06-16 21:37:20 +00:00
|
|
|
root.render(
|
|
|
|
React.createElement(squiggle_components.SquigglePlayground, {
|
|
|
|
code: text,
|
2022-06-20 14:38:45 +00:00
|
|
|
showEditor: false,
|
2022-06-20 15:06:30 +00:00
|
|
|
showSummary: Boolean(showSettings.showSummary),
|
2022-06-16 21:37:20 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle messages sent from the extension to the webview
|
|
|
|
window.addEventListener("message", (event) => {
|
|
|
|
const message = event.data; // The json data that the extension sent
|
|
|
|
switch (message.type) {
|
|
|
|
case "update":
|
2022-06-20 15:06:30 +00:00
|
|
|
const { text, showSettings } = message;
|
2022-06-16 21:37:20 +00:00
|
|
|
|
|
|
|
// Update our webview's content
|
2022-06-20 15:06:30 +00:00
|
|
|
updateContent(text, showSettings);
|
2022-06-16 21:37:20 +00:00
|
|
|
|
|
|
|
// Then persist state information.
|
|
|
|
// This state is returned in the call to `vscode.getState` below when a webview is reloaded.
|
2022-06-20 15:06:30 +00:00
|
|
|
vscode.setState({ text, showSettings });
|
2022-06-16 21:37:20 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const state = vscode.getState();
|
|
|
|
if (state) {
|
2022-06-20 15:06:30 +00:00
|
|
|
updateContent(state.text, state.showSettings);
|
2022-06-16 21:37:20 +00:00
|
|
|
}
|
|
|
|
})();
|