-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourcesView.svelte
More file actions
42 lines (38 loc) · 1.25 KB
/
SourcesView.svelte
File metadata and controls
42 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script lang="ts">
const SourceViewPromise = Promise.all([
import("svelte/compiler"),
fetch("./SourceView.svelte").then((res) => res.text()),
]).then(async ([compiler, code]) => {
const { js } = compiler.compile(code, { generate: "client" });
const { default: SourceView } = (await import(
URL.createObjectURL(new Blob([js.code], { type: "text/javascript" }))
)) as typeof import("./SourceView.svelte");
return SourceView;
});
const sources = {
"./index.html": { lang: "html" },
"./App.svelte": { lang: "svelte" },
"./ReadmeView.svelte": { lang: "svelte" },
"./SourceView.svelte": { lang: "svelte" },
"./SourcesView.svelte": { lang: "svelte" },
} as const satisfies { [url: string]: { lang: string } };
let selectedSourceUrl = $state<keyof typeof sources>("./index.html");
let sourceLoading = $state(false);
</script>
<label>
Source:
<select bind:value={selectedSourceUrl}>
{#each Object.keys(sources) as url}
<option value={url}>{url}</option>
{/each}
</select>
</label>
{#await SourceViewPromise then SourceView}
{#if sourceLoading}
<progress></progress>
{/if}
<SourceView
url={selectedSourceUrl}
onLoadingChange={(loading) => (sourceLoading = loading)}
/>
{/await}