Merge pull request #2383 from sveltejs/update-repl

Update REPL
pull/2397/head
Rich Harris 6 years ago committed by GitHub
commit b04cada2dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1140,12 +1140,13 @@
"integrity": "sha512-oZLYFEAzUKyi3SKnXvj32ZCEGH6RDnao7COuCVhDydMS9NrCSVXhM79VaKyP5+Zc33m0QXEd2DN3UkU7OsHcfw=="
},
"@sveltejs/svelte-repl": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/@sveltejs/svelte-repl/-/svelte-repl-0.0.7.tgz",
"integrity": "sha512-gA1UD7ZKbvdLoKsRUPg+yceHmn0vOB4HUBmhV8H0wWr8VyU0nqxM0dlBPvqZUMVVjC9cNyGF3bqHKtBiJHRyhA==",
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/@sveltejs/svelte-repl/-/svelte-repl-0.0.9.tgz",
"integrity": "sha512-n0cYMyzxCU/oEwibliNRcIMiRcOpt7oA4l9u/C2WFWzb4ygWhZ9gpYEI4IYvdUI/RJfe5KSR7TdAZI/dUk3mqg==",
"dev": true,
"requires": {
"codemirror": "^5.45.0",
"sourcemap-codec": "^1.4.4",
"yootils": "0.0.15"
},
"dependencies": {

@ -39,7 +39,7 @@
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/runtime": "^7.3.1",
"@sveltejs/svelte-repl": "0.0.7",
"@sveltejs/svelte-repl": "0.0.9",
"chokidar": "^2.1.2",
"degit": "^2.1.3",
"eslint-plugin-svelte3": "^0.4.4",

@ -0,0 +1,35 @@
<script>
export let checked;
</script>
<style>
.input-output-toggle {
display: grid;
position: absolute;
user-select: none;
grid-template-columns: 1fr 40px 1fr;
grid-gap: 0.5em;
align-items: center;
width: 100%;
height: 42px;
border-top: 1px solid var(--second);
}
input {
display: block;
}
span {
color: #ccc;
}
.active {
color: #555;
}
</style>
<label class="input-output-toggle">
<span class:active={!checked} style="text-align: right">input</span>
<input type="checkbox" bind:checked>
<span class:active={checked}>output</span>
</label>

@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import { process_example } from './process_example.js';
import Repl from '@sveltejs/svelte-repl';
import InputOutputToggle from './InputOutputToggle.svelte';
export let version = 'beta';
export let gist = null;
@ -10,6 +11,11 @@
let repl;
let name = 'loading...';
let width = process.browser
? window.innerWidth - 32
: 1000;
let checked = false;
onMount(() => {
if (version !== 'local') {
@ -71,6 +77,8 @@
`https://unpkg.com/svelte@${version}`;
const rollupUrl = `https://unpkg.com/rollup@1/dist/rollup.browser.js`;
$: mobile = width < 560;
</script>
<style>
@ -85,10 +93,38 @@
box-sizing: border-box;
--pane-controls-h: 4.2rem;
}
.viewport {
width: 100%;
height: 100%;
}
.mobile .viewport {
width: 200%;
height: calc(100% - 42px);
transition: transform 0.3s;
}
.mobile .offset {
transform: translate(-50%, 0);
}
</style>
<div class="repl-outer">
{#if process.browser}
<Repl bind:this={repl} {svelteUrl} {rollupUrl} embedded={true} relaxed/>
<div class="repl-outer" bind:clientWidth={width} class:mobile>
<div class="viewport" class:offset={checked}>
{#if process.browser}
<Repl
bind:this={repl}
fixed={mobile}
{svelteUrl}
{rollupUrl}
embedded
relaxed
/>
{/if}
</div>
{#if mobile}
<InputOutputToggle bind:checked/>
{/if}
</div>
</div>

@ -11,6 +11,7 @@
<script>
import { onMount } from 'svelte';
import { process_example } from '../../components/Repl/process_example.js';
import InputOutputToggle from '../../components/Repl/InputOutputToggle.svelte';
import AppControls from './_components/AppControls/index.svelte';
import Repl from '@sveltejs/svelte-repl';
@ -23,6 +24,8 @@
let name = 'loading...';
let zen_mode = false;
let relaxed = false;
let width = process.browser ? window.innerWidth : 1000;
let checked = false;
$: if (typeof history !== 'undefined') {
const params = [];
@ -114,6 +117,8 @@
// needed for context API example
const mapbox_setup = `window.MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN;`;
$: mobile = width < 540;
</script>
<style>
@ -129,6 +134,21 @@
box-sizing: border-box;
}
.viewport {
width: 100%;
height: 100%;
}
.mobile .viewport {
width: 200%;
height: calc(100% - 42px);
transition: transform 0.3s;
}
.mobile .offset {
transform: translate(-50%, 0);
}
.zen-mode {
position: fixed;
width: 100%;
@ -164,7 +184,9 @@
<title>Svelte REPL</title>
</svelte:head>
<div class="repl-outer {zen_mode ? 'zen-mode' : ''}">
<svelte:window bind:innerWidth={width}/>
<div class="repl-outer {zen_mode ? 'zen-mode' : ''}" class:mobile>
<AppControls
{name}
{gist}
@ -174,12 +196,19 @@
/>
{#if process.browser}
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
{relaxed}
setup={mapbox_setup}
/>
<div class="viewport" class:offset={checked}>
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
{relaxed}
fixed={mobile}
setup={mapbox_setup}
/>
</div>
{#if mobile}
<InputOutputToggle bind:checked/>
{/if}
{/if}
</div>

@ -0,0 +1,40 @@
<script>
export let offset = 0;
</script>
<style>
.toggle {
position: fixed;
bottom: 0;
width: 100%;
height: 42px;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid var(--second);
background-color: white;
}
button {
padding: 0.3em 0.6em;
border-radius: 1em;
line-height: 1;
height: 1em;
box-sizing: content-box;
color: #999;
border: 1px solid #f4f4f4;
width: 4em;
margin: 0 0.15em;
}
.selected {
background-color: var(--prime);
color: white;
}
</style>
<div class="toggle">
<button class:selected={offset === 0} on:click={() => offset = 0}>tutorial</button>
<button class:selected={offset === 1} on:click={() => offset = 1}>input</button>
<button class:selected={offset === 2} on:click={() => offset = 2}>output</button>
</div>

@ -15,6 +15,7 @@
<script>
import TableOfContents from './_components/TableOfContents.svelte';
import ScreenToggle from './_components/ScreenToggle.svelte';
import Icon from '../../../components/Icon.svelte';
import Repl from '@sveltejs/svelte-repl';
import { getContext } from 'svelte';
@ -29,6 +30,9 @@
let scrollable;
const lookup = new Map();
let width = process.browser ? window.innerWidth : 1000;
let offset = 0;
sections.forEach(section => {
section.chapters.forEach(chapter => {
const obj = {
@ -70,6 +74,8 @@
});
}
$: mobile = width < 768;
function reset() {
repl.update({
components: chapter.app_a.map(clone)
@ -107,14 +113,40 @@
position: relative;
height: calc(100vh - var(--nav-h));
overflow: hidden;
padding: 0;
padding: 0 0 42px 0;
/* margin: 0 calc(var(--side-nav) * -1); */
box-sizing: border-box;
}
.viewport {
display: grid;
grid-template-columns: minmax(33.333%, 480px) auto;
width: 300%;
height: 100%;
grid-template-columns: 33.333% 66.666%;
transition: transform 0.3s;
grid-auto-rows: 100%;
}
.offset-1 { transform: translate(-33.333%, 0); }
.offset-2 { transform: translate(-66.666%, 0); }
@media (min-width: 768px) {
.tutorial-outer {
padding: 0;
}
.viewport {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: minmax(33.333%, 480px) auto;
grid-auto-rows: 100%;
transition: none;
}
.offset-1, .offset-2 { transform: none; }
}
.tutorial-text {
display: flex;
flex-direction: column;
@ -215,44 +247,53 @@
<title>{selected.section.title} / {selected.chapter.title} • Svelte Tutorial</title>
</svelte:head>
<div class="tutorial-outer">
<div class="tutorial-text">
<div class="table-of-contents">
<TableOfContents {sections} {slug} {selected}/>
</div>
<svelte:window bind:innerWidth={width}/>
<div class="chapter-markup" bind:this={scrollable}>
{@html chapter.html}
<div class="controls">
{#if chapter.app_b}
<!-- TODO disable this button when the contents of the REPL
matches the expected end result -->
<button class="show" on:click="{() => completed ? reset() : complete()}">
{completed ? 'Reset' : 'Show me'}
</button>
{/if}
{#if selected.next}
<a class="next" href="tutorial/{selected.next.slug}">Next <Icon name="arrow-right" /></a>
{/if}
<div class="tutorial-outer">
<div class="viewport offset-{offset}">
<div class="tutorial-text">
<div class="table-of-contents">
<TableOfContents {sections} {slug} {selected}/>
</div>
<div class="improve-chapter">
<a href={improve_link}><Icon name="edit" size={14}/> Edit this chapter</a>
<div class="chapter-markup" bind:this={scrollable}>
{@html chapter.html}
<div class="controls">
{#if chapter.app_b}
<!-- TODO disable this button when the contents of the REPL
matches the expected end result -->
<button class="show" on:click="{() => completed ? reset() : complete()}">
{completed ? 'Reset' : 'Show me'}
</button>
{/if}
{#if selected.next}
<a class="next" href="tutorial/{selected.next.slug}">Next <Icon name="arrow-right" /></a>
{/if}
</div>
<div class="improve-chapter">
<a href={improve_link}><Icon name="edit" size={14}/> Edit this chapter</a>
</div>
</div>
</div>
</div>
<div class="tutorial-repl">
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
orientation="rows"
on:change={handle_change}
setup={mapbox_setup}
relaxed
/>
<div class="tutorial-repl">
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
orientation={mobile ? 'columns' : 'rows'}
fixed={mobile}
on:change={handle_change}
setup={mapbox_setup}
relaxed
/>
</div>
</div>
{#if mobile}
<ScreenToggle bind:offset/>
{/if}
</div>

Loading…
Cancel
Save