From 47ee896b57a03f7dc22ddbaf843b3058d86cccd1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 7 Oct 2020 15:33:04 +0200 Subject: [PATCH] Online editor: Ability to open any snippet passed in the query --- tools/online_editor/index.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/online_editor/index.ts b/tools/online_editor/index.ts index 059be407c..aac1ea54e 100644 --- a/tools/online_editor/index.ts +++ b/tools/online_editor/index.ts @@ -10,12 +10,6 @@ LICENSE END */ import * as monaco from 'monaco-editor'; var sixtyfps; - -async function run() { - sixtyfps = await import("../../api/sixtyfps-wasm-interpreter/pkg/index.js"); - update(); -} - var editor = monaco.editor.create(document.getElementById("editor")); function load_from_url(url) { @@ -25,12 +19,11 @@ function load_from_url(url) { } -load_from_url("https://raw.githubusercontent.com/sixtyfpsui/sixtyfps/master/examples/gallery/gallery.60"); - let select = (document.getElementById("select_combo")); -select.onchange = function () { +function select_combo_changed() { load_from_url("https://raw.githubusercontent.com/sixtyfpsui/sixtyfps/master/" + select.value); -}; +} +select.onchange = select_combo_changed; let compile_button = (document.getElementById("compile_button")); compile_button.onclick = function () { @@ -43,11 +36,6 @@ auto_compile.onchange = function () { update(); }; -editor.getModel().onDidChangeContent(function () { - if (auto_compile.checked) - update(); -}); - function update() { let source = editor.getModel().getValue(); let div = document.getElementById("preview"); @@ -94,4 +82,20 @@ function render_or_error(source, div) { } } +async function run() { + const params = new URLSearchParams(window.location.search); + const code = params.get("snippet"); + if (code) { + editor.getModel().setValue(code); + } else { + select_combo_changed(); + } + sixtyfps = await import("../../api/sixtyfps-wasm-interpreter/pkg/index.js"); + update(); + editor.getModel().onDidChangeContent(function () { + if (auto_compile.checked) + update(); + }); +} + run(); \ No newline at end of file