Skip to content

Commit

Permalink
setup iframe boilerplate and messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn committed Oct 18, 2020
1 parent 28f54db commit e0362b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions public/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,9 @@ textarea {
height: 100%;
resize: none;
}

iframe {
width: 100%;
height: 100%;
border: none;
}
6 changes: 4 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
const worker = new Worker("./worker.js");
let compiled;
worker.addEventListener("message", (event) => {
console.log(event.data);
compiled = event.data;
});
function compile(_components: Component[]): void {
Expand All @@ -40,5 +42,5 @@

<main>
<Input bind:components bind:current />
<Output />
<Output {compiled} />
</main>
26 changes: 26 additions & 0 deletions src/Output.svelte
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
<script lang="ts">
export let compiled: string;
let iframe: HTMLIFrameElement;
function update(code: string) {
iframe.contentWindow.postMessage(code, "*");
}
$: iframe && compiled && update(compiled);
const srcdoc = `
<!doctype html>
<html>
<head>
<script type="module">
window.addEventListener('message', event => {
console.log(event.data)
}, false)
<\/script>
</head>
<body></body>
</html>
`;
</script>

<section><iframe title="Rendered REPL" bind:this={iframe} {srcdoc} /></section>

0 comments on commit e0362b5

Please sign in to comment.