-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(repl): update broken embed repl to work like regular one, remove …
…obsolete ReplWidget.svelte (#10180)
- Loading branch information
Showing
8 changed files
with
152 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js
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,16 @@ | ||
import { error } from '@sveltejs/kit'; | ||
|
||
export async function load({ fetch, params, url }) { | ||
const res = await fetch(`/repl/api/${params.id}.json`); | ||
|
||
if (!res.ok) { | ||
throw error(res.status); | ||
} | ||
|
||
const gist = await res.json(); | ||
|
||
return { | ||
gist, | ||
version: url.searchParams.get('version') || '4' | ||
}; | ||
} |
92 changes: 92 additions & 0 deletions
92
sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte
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,92 @@ | ||
<script> | ||
import { browser } from '$app/environment'; | ||
import { afterNavigate } from '$app/navigation'; | ||
import { theme } from '@sveltejs/site-kit/stores'; | ||
import Repl from '@sveltejs/repl'; | ||
import { mapbox_setup } from '../../../../../config.js'; | ||
import { onMount } from 'svelte'; | ||
export let data; | ||
let version = data.version; | ||
/** @type {import('@sveltejs/repl').default} */ | ||
let repl; | ||
function update_query_string(version) { | ||
const params = []; | ||
if (version !== 'latest') params.push(`version=${version}`); | ||
const url = | ||
params.length > 0 | ||
? `/repl/${data.gist.id}/embed?${params.join('&')}` | ||
: `/repl/${data.gist.id}/embed`; | ||
history.replaceState({}, 'x', url); | ||
} | ||
$: if (typeof history !== 'undefined') update_query_string(version); | ||
onMount(() => { | ||
if (data.version !== 'local') { | ||
fetch(`https://unpkg.com/svelte@${data.version || '4'}/package.json`) | ||
.then((r) => r.json()) | ||
.then((pkg) => { | ||
version = pkg.version; | ||
}); | ||
} | ||
}); | ||
afterNavigate(() => { | ||
repl?.set({ | ||
files: data.gist.components | ||
}); | ||
}); | ||
$: svelteUrl = | ||
browser && version === 'local' | ||
? `${location.origin}/repl/local` | ||
: `https://unpkg.com/svelte@${version}`; | ||
$: relaxed = data.gist.relaxed || (data.user && data.user.id === data.gist.owner); | ||
</script> | ||
<svelte:head> | ||
<title>{data.gist.name} • REPL • Svelte</title> | ||
<meta name="twitter:title" content="{data.gist.name} • REPL • Svelte" /> | ||
<meta name="twitter:description" content="Cybernetically enhanced web apps" /> | ||
<meta name="Description" content="Interactive Svelte playground" /> | ||
</svelte:head> | ||
<div class="repl-outer"> | ||
{#if browser} | ||
<Repl | ||
bind:this={repl} | ||
{svelteUrl} | ||
{relaxed} | ||
injectedJS={mapbox_setup} | ||
showModified | ||
showAst | ||
previewTheme={$theme.current} | ||
embedded | ||
/> | ||
{/if} | ||
</div> | ||
<style> | ||
.repl-outer { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: var(--sk-back-1); | ||
overflow: hidden; | ||
box-sizing: border-box; | ||
--pane-controls-h: 4.2rem; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
</style> |
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js
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,14 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
|
||
export function load({ url }) { | ||
if (!url.searchParams.has('gist')) { | ||
throw redirect(301, '/repl/hello-world/embed'); | ||
} else { | ||
const searchParamsWithoutGist = new URLSearchParams(url.searchParams); | ||
searchParamsWithoutGist.delete('gist'); | ||
throw redirect( | ||
301, | ||
`/repl/${url.searchParams.get('gist')}/embed?${searchParamsWithoutGist.toString()}` | ||
); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
sites/svelte.dev/src/routes/(authed)/repl/embed/+page.svelte
This file was deleted.
Oops, something went wrong.
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