···11import * as CID from "@atcute/cid";
22import { html, render } from "lit-html";
3344+import { basicSetup, EditorView } from "codemirror";
55+import { css as langCss } from "@codemirror/lang-css";
66+import { html as langHtml } from "@codemirror/lang-html";
77+import { javascript as langJs } from "@codemirror/lang-javascript";
88+import { autocompletion } from "@codemirror/autocomplete";
99+410import foundation from "@common/constituents/foundation.js";
511import { effect } from "@common/signal.js";
612···5561// BUILD
5662////////////////////////////////////////////
57636464+// Code editor
6565+const editorContainer = document.body.querySelector("#html-input-container");
6666+if (!editorContainer) throw new Error("Editor container not found");
6767+6868+const editor = new EditorView({
6969+ parent: editorContainer,
7070+ doc: `
7171+<script type="module">
7272+ import foundation from "./common/constituents/foundation.js";
7373+ import { effect } from "./common/signal.js";
7474+7575+ const components = foundation.assemblage.queueManagement();
7676+7777+ effect(() => {
7878+ const currentlyPlaying = components.engine.queue.now();
7979+ })
8080+</script>
8181+ `.trim(),
8282+ extensions: [
8383+ basicSetup,
8484+ langHtml(),
8585+ langCss(),
8686+ langJs(),
8787+ autocompletion(),
8888+ ],
8989+});
9090+9191+// Form submit
5892document.querySelector("#build-form")?.addEventListener(
5993 "submit",
6094 onBuildSubmit,
···66100async function onBuildSubmit(event) {
67101 event.preventDefault();
681026969- const htmlEl =
7070- /** @type {HTMLTextAreaElement | null} */ (document.querySelector(
7171- "#html-input",
7272- ));
73103 const nameEl = /** @type {HTMLInputElement | null} */ (document.querySelector(
74104 "#name-input",
75105 ));
761067777- const html = htmlEl?.value ?? "";
107107+ const html = editor.state.doc.toString();
78108 const cid = await CID.create(0x55, new TextEncoder().encode(html));
79109 const name = nameEl?.value ?? "nameless";
80110···91121 /** @type {HTMLSelectElement | null} */
92122 const selected = document.body.querySelector("#example-select");
931239494- if (htmlEl && selected?.value) {
9595- htmlEl.value = await fetch(
124124+ if (selected?.value) {
125125+ const text = await fetch(
96126 `themes/loader/constituent/examples/${selected.value}`,
97127 ).then((r) => r.text());
128128+129129+ editor.dispatch({
130130+ changes: { from: 0, to: editor.state.doc.length, insert: text },
131131+ });
98132 }
99133 break;
100134 }
+5-2
src/themes/loader/constituent/index.vto
···6969 If you know a bit of HTML & Javascript, you can write your own or plug in some code you found elsewhere:
7070 </p>
71717272- <div>
7373- <textarea id="html-input" class="monospace-font" placeholder="<div>goes here</div>"></textarea>
7272+ <div id="html-input-container" class="code-editor monospace-font">
7473 </div>
7574 </div>
7675···9089 </p>
9190 <div>
9291 <select id="example-select">
9292+ <button>
9393+ <selectedcontent></selectedcontent>
9494+ </button>
9595+9396 <option value="now-playing.txt" selected>Now playing + Next Queue Item</option>
9497 </select>
9598 </div>