mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Online editor: Ability to open any snippet passed in the query
This commit is contained in:
parent
117e1d3389
commit
47ee896b57
1 changed files with 19 additions and 15 deletions
|
@ -10,12 +10,6 @@ LICENSE END */
|
||||||
import * as monaco from 'monaco-editor';
|
import * as monaco from 'monaco-editor';
|
||||||
|
|
||||||
var sixtyfps;
|
var sixtyfps;
|
||||||
|
|
||||||
async function run() {
|
|
||||||
sixtyfps = await import("../../api/sixtyfps-wasm-interpreter/pkg/index.js");
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
var editor = monaco.editor.create(document.getElementById("editor"));
|
var editor = monaco.editor.create(document.getElementById("editor"));
|
||||||
|
|
||||||
function load_from_url(url) {
|
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 = (<HTMLInputElement>document.getElementById("select_combo"));
|
let select = (<HTMLInputElement>document.getElementById("select_combo"));
|
||||||
select.onchange = function () {
|
function select_combo_changed() {
|
||||||
load_from_url("https://raw.githubusercontent.com/sixtyfpsui/sixtyfps/master/" + select.value);
|
load_from_url("https://raw.githubusercontent.com/sixtyfpsui/sixtyfps/master/" + select.value);
|
||||||
};
|
}
|
||||||
|
select.onchange = select_combo_changed;
|
||||||
|
|
||||||
let compile_button = (<HTMLButtonElement>document.getElementById("compile_button"));
|
let compile_button = (<HTMLButtonElement>document.getElementById("compile_button"));
|
||||||
compile_button.onclick = function () {
|
compile_button.onclick = function () {
|
||||||
|
@ -43,11 +36,6 @@ auto_compile.onchange = function () {
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.getModel().onDidChangeContent(function () {
|
|
||||||
if (auto_compile.checked)
|
|
||||||
update();
|
|
||||||
});
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
let source = editor.getModel().getValue();
|
let source = editor.getModel().getValue();
|
||||||
let div = document.getElementById("preview");
|
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();
|
run();
|
Loading…
Add table
Add a link
Reference in a new issue