thurtle: Document query parameters

This commit is contained in:
Remko Tronçon 2022-05-21 11:07:30 +02:00
parent f4484be2ef
commit f2e37ba093
3 changed files with 54 additions and 32 deletions

View file

@ -67,7 +67,10 @@ export const createElement = (
return element; return element;
}; };
const appendChild = (parent: HTMLElement, child: Child | Child[]) => { const appendChild = (parent: HTMLElement, child: Child | Child[] | null) => {
if (child == null) {
return;
}
if (Array.isArray(child)) if (Array.isArray(child))
child.forEach((nestedChild) => appendChild(parent, nestedChild)); child.forEach((nestedChild) => appendChild(parent, nestedChild));
else else

View file

@ -6,6 +6,10 @@
height: calc(100% - 40px); height: calc(100% - 40px);
} }
.no-nav .main {
height: 100%;
}
.editor { .editor {
flex: 1; flex: 1;
} }
@ -15,6 +19,10 @@
padding-bottom: 0 !important; padding-bottom: 0 !important;
} }
.no-nav nav {
display: none;
}
.world { .world {
border: thin solid rgb(171, 208, 166); border: thin solid rgb(171, 208, 166);
border-radius: 0.5em; border-radius: 0.5em;
@ -32,17 +40,17 @@
.output { .output {
font-size: 0.75em; font-size: 0.75em;
overflow: auto; overflow: auto;
min-height: calc(
100vh - 438px
); /* hack because i can't figure out how to auto scale this */
max-height: calc(
100vh - 438px
); /* hack because i can't figure out how to auto scale this */
height: calc( height: calc(
100vh - 438px 100vh - 438px
); /* hack because i can't figure out how to auto scale this */ ); /* hack because i can't figure out how to auto scale this */
} }
.no-nav .output {
height: calc(
100vh - 398px
); /* hack because i can't figure out how to auto scale this */
}
label { label {
font-weight: 500; font-weight: 500;
} }

View file

@ -1,3 +1,11 @@
/////////////////////////////////////////////////////////////////////////
// Query parameters:
// `p`: Base64-encoded program
// `pn`: Program name. If `p` is not provided, looks up builtin example
// `ar`: Auto-run program
// `sn`: Show navbar (default: 1)
/////////////////////////////////////////////////////////////////////////
import * as jsx from "./jsx"; import * as jsx from "./jsx";
import WAForth from "waforth"; import WAForth from "waforth";
import "./thurtle.css"; import "./thurtle.css";
@ -15,6 +23,25 @@ import { saveAs } from "file-saver";
declare let bootstrap: any; declare let bootstrap: any;
function parseQS(sqs = window.location.search) {
const qs: Record<string, string> = {};
const sqss = sqs
.substring(sqs.indexOf("?") + 1)
.replace(/\+/, " ")
.split("&");
for (const p of sqss) {
const j = p.indexOf("=");
if (j > 0) {
qs[decodeURIComponent(p.substring(0, j))] = decodeURIComponent(
p.substring(j + 1)
);
}
}
return qs;
}
const qs = parseQS();
function About() { function About() {
return ( return (
<> <>
@ -27,7 +54,7 @@ function About() {
const editor = new Editor(); const editor = new Editor();
const rootEl = ( const rootEl = (
<div class="root"> <div class={"root" + (qs.sn === "0" ? " no-nav" : "")}>
<nav class="navbar navbar-light bg-light"> <nav class="navbar navbar-light bg-light">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="/thurtle"> <a class="navbar-brand" href="/thurtle">
@ -217,11 +244,13 @@ const rootEl = (
</form> </form>
</div> </div>
</div> </div>
{qs.sn !== "0" ? (
<div class="container mt-2 text-muted d-sm-none"> <div class="container mt-2 text-muted d-sm-none">
<p> <p>
<About /> <About />
</p> </p>
</div> </div>
) : null}
</div> </div>
<div <div
class="modal fade" class="modal fade"
@ -705,26 +734,8 @@ document.addEventListener("keydown", (ev) => {
} }
}); });
//////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
function parseQS(sqs = window.location.search) {
const qs: Record<string, string> = {};
const sqss = sqs
.substring(sqs.indexOf("?") + 1)
.replace(/\+/, " ")
.split("&");
for (const p of sqss) {
const j = p.indexOf("=");
if (j > 0) {
qs[decodeURIComponent(p.substring(0, j))] = decodeURIComponent(
p.substring(j + 1)
);
}
}
return qs;
}
const qs = parseQS();
if (qs.p) { if (qs.p) {
saveProgram(qs.pn ?? "", atob(qs.p), true); saveProgram(qs.pn ?? "", atob(qs.p), true);
loadPrograms(); loadPrograms();