repl now accepts code in innerHTML + bump

This commit is contained in:
Felix Roos 2023-12-15 11:50:49 +01:00
parent 9b58cf9890
commit 372e93e8f8
4 changed files with 36 additions and 12 deletions

View file

@ -0,0 +1,2 @@
<script src="https://unpkg.com/@strudel/repl@0.9.3"></script>
<strudel-editor code='s("bd")'></strudel-editor>

View file

@ -1,6 +1,6 @@
{
"name": "@strudel/repl",
"version": "0.9.3",
"version": "0.9.4",
"description": "Strudel REPL as a Web Component",
"main": "index.mjs",
"publishConfig": {

View file

@ -59,13 +59,24 @@ class StrudelRepl extends HTMLElement {
}
}
connectedCallback() {
// setTimeout makes sure the dom is ready
setTimeout(() => {
const code = (this.innerHTML + '').replace('<!--', '').replace('-->', '').trim();
if (code) {
// use comment code in element body if present
this.setAttribute('code', code);
}
});
// use a separate container for the editor, to make sure the innerHTML stays as is
const container = document.createElement('div');
this.parentElement.insertBefore(container, this.nextSibling);
const drawContext = getDrawContext();
const drawTime = [-2, 2];
this.editor = new StrudelMirror({
defaultOutput: webaudioOutput,
getTime: () => getAudioContext().currentTime,
transpiler,
root: this,
root: container,
initialCode: '// LOADING',
pattern: silence,
settings: this.settings,