-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from milafrerichs/feat/use-slots
Feat: Use Layouts and Slots & Use stores
- Loading branch information
Showing
11 changed files
with
236 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,5 +87,5 @@ | |
</script> | ||
|
||
<Repl {files} /> | ||
<Repl layout={'default'} {files} /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "javascript-repl", | ||
"svelte": "src/Repl.svelte", | ||
"module": "index.mjs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
"main": "index.js", | ||
"author": "Mila Frerichs <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script> | ||
import srcdoc from './srcdoc/index.js'; | ||
import { onMount } from 'svelte'; | ||
import { | ||
ready, | ||
injectedJS, | ||
injectedLibraries | ||
} from './stores.js' | ||
let iframe; | ||
export let injectedCSS = ''; | ||
export let code; | ||
export let html; | ||
let message = ''; | ||
onMount(() => { | ||
iframe.addEventListener('load', () => { | ||
ready.set(true); | ||
}); | ||
}); | ||
$: if($ready && (code || html)) { | ||
message = ` | ||
${$injectedJS} | ||
${styles} | ||
document.body.innerHTML = ''; | ||
document.body.innerHTML = '${html}'; | ||
${code} | ||
` | ||
iframe.contentWindow.postMessage({ script: message }, '*'); | ||
} | ||
$: styles = injectedCSS && `{ | ||
const style = document.createElement('style'); | ||
style.textContent = ${JSON.stringify(injectedCSS)}; | ||
document.head.appendChild(style); | ||
}`; | ||
$: if($injectedLibraries.length > 0) { | ||
libraries = $injectedLibraries.map((lib) => { | ||
return `{ | ||
const script = document.createElement('script'); | ||
script.type= 'text/javascript'; | ||
script.src = '${lib}'; | ||
document.head.appendChild(script); | ||
}` | ||
}) | ||
} | ||
</script> | ||
<iframe | ||
title="Result" | ||
sandbox="allow-scripts allow-same-origin" | ||
bind:this={iframe} | ||
{srcdoc} | ||
></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,8 @@ | ||
<script> | ||
import srcdoc from './srcdoc/index.js'; | ||
import { onMount } from 'svelte'; | ||
let iframe; | ||
export let injectedJS = ''; | ||
export let injectedCSS = ''; | ||
export let injectedLibraries = []; | ||
export let html = ''; | ||
export let code = ''; | ||
export let ready = false; | ||
let message = ''; | ||
onMount(() => { | ||
iframe.addEventListener('load', () => { | ||
ready = true; | ||
}); | ||
}); | ||
$: if(ready && (code || html)) { | ||
message = ` | ||
${injectedJS} | ||
${styles} | ||
document.body.innerHTML = ''; | ||
document.body.innerHTML = '${html}'; | ||
${code} | ||
` | ||
iframe.contentWindow.postMessage({ script: message }, '*'); | ||
} | ||
$: styles = injectedCSS && `{ | ||
const style = document.createElement('style'); | ||
style.textContent = ${JSON.stringify(injectedCSS)}; | ||
document.head.appendChild(style); | ||
}`; | ||
$: if(injectedLibraries.length > 0) { | ||
libraries = injectedLibraries.map((lib) => { | ||
return `{ | ||
const script = document.createElement('script'); | ||
script.type= 'text/javascript'; | ||
script.src = '${lib}'; | ||
document.head.appendChild(script); | ||
}` | ||
}) | ||
} | ||
import Result from './Result.svelte'; | ||
import { code, html } from './stores.js' | ||
</script> | ||
<iframe | ||
title="Result" | ||
sandbox="allow-scripts allow-same-origin" | ||
bind:this={iframe} | ||
{srcdoc} | ||
></iframe> | ||
|
||
<Result code={$code} html={$html} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script> | ||
import Viewer from './Viewer.svelte'; | ||
import Console from './Console.svelte'; | ||
import { code } from './stores.js' | ||
export let cssStyles; | ||
let tab = 'viewer'; | ||
function showConsole() { | ||
tab = 'console'; | ||
} | ||
function showResult() { | ||
tab = 'viewer'; | ||
} | ||
</script> | ||
|
||
<div class="{cssStyles.viewerContainer}"> | ||
<div class="{cssStyles.viewerActions.container}"> | ||
<div class="{cssStyles.viewerActions.tabItem}"> | ||
<a class:active="{tab == 'viewer'}" class="{cssStyles.viewerActions.link}" on:click="{() => showResult()}">Result</a> | ||
</div> | ||
<div class="{cssStyles.viewerActions.tabItem}"> | ||
<a class:active="{tab == 'console'}" class="{cssStyles.viewerActions.link}" on:click="{() => showConsole()}">Console</a> | ||
</div> | ||
</div> | ||
<div class="{cssStyles.viewerConsoleContainer}"> | ||
<div class:hidden="{tab != 'viewer'}" class="{cssStyles.viewer}"> | ||
<Viewer /> | ||
</div> | ||
<div class:hidden="{tab != 'console'}" class="{cssStyles.console}"> | ||
<Console /> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script> | ||
import { | ||
files, | ||
currentFileIndex | ||
} from './../stores.js' | ||
export let cssStyles; | ||
function showFile(fileIndex) { | ||
currentFileIndex.set(fileIndex); | ||
} | ||
</script> | ||
|
||
<div class="{cssStyles.container}" > | ||
<div class="result-container {cssStyles.resultContainer}"> | ||
<div class="{cssStyles.editor}"> | ||
<div class="{cssStyles.editorActions.container}"> | ||
{#each $files as { name }, i} | ||
<div class="{cssStyles.editorActions.tabItem}"> | ||
<a class:active="{$currentFileIndex == i}" class="{cssStyles.editorActions.link}" on:click="{() => showFile(i)}">{name}</a> | ||
</div> | ||
{/each} | ||
</div> | ||
<slot name="editor"></slot> | ||
</div> | ||
<slot name="viewer-console"></slot> | ||
</div> | ||
</div> |
Oops, something went wrong.