File tree Expand file tree Collapse file tree 5 files changed +66
-17
lines changed Expand file tree Collapse file tree 5 files changed +66
-17
lines changed Original file line number Diff line number Diff line change 1919 "dependencies" : {
2020 "@jridgewell/sourcemap-codec" : " ^1.4.15" ,
2121 "@supabase/supabase-js" : " ^2.31.0" ,
22- "@sveltejs/repl" : " 0.5 .0" ,
22+ "@sveltejs/repl" : " 0.6 .0" ,
2323 "cookie" : " ^0.5.0" ,
2424 "devalue" : " ^4.3.2" ,
2525 "do-not-zip" : " ^1.0.0" ,
Original file line number Diff line number Diff line change 11import { redirect } from '@sveltejs/kit' ;
22
3+ /**
4+ * create a query params string from an object of query parameters
5+ * @param {Record<string, string> } queries
6+ * @returns {string }
7+ */
8+ function add_query_params ( queries ) {
9+ const query_array = [ ] ;
10+ for ( let query in queries ) {
11+ if ( queries [ query ] !== null ) {
12+ query_array . push ( `${ query } =${ queries [ query ] } ` ) ;
13+ }
14+ }
15+ return query_array . length > 0 ? `?${ query_array . join ( '&' ) } ` : `` ;
16+ }
17+
318export function load ( { url } ) {
419 const query = url . searchParams ;
520 const gist = query . get ( 'gist' ) ;
621 const example = query . get ( 'example' ) ;
722 const version = query . get ( 'version' ) ;
23+ const vim = query . get ( 'vim' ) ;
824
925 // redirect to v2 REPL if appropriate
1026 if ( / ^ [ ^ > ] ? [ 1 2 ] / . test ( version ) ) {
1127 throw redirect ( 302 , `https://v2.svelte.dev/repl?${ query } ` ) ;
1228 }
1329
1430 const id = gist || example || 'hello-world' ;
15- const q = version ? `?version=${ version } ` : `` ;
16-
31+ const q = add_query_params ( {
32+ version,
33+ vim
34+ } ) ;
1735 throw redirect ( 301 , `/repl/${ id } ${ q } ` ) ;
1836}
Original file line number Diff line number Diff line change 1+ import { browser } from '$app/environment' ;
2+
3+ export function load ( { data, url } ) {
4+ // initialize vim with the search param
5+ const vim_search_params = url . searchParams . get ( 'vim' ) ;
6+ let vim = vim_search_params !== null && vim_search_params !== 'false' ;
7+ // when in the browser check if there's a local storage entry and eventually override
8+ // vim if there's not a search params otherwise update the local storage
9+ if ( browser ) {
10+ const vim_local_storage = window . localStorage . getItem ( 'svelte:vim-enabled' ) ;
11+ if ( vim_search_params !== null ) {
12+ window . localStorage . setItem ( 'svelte:vim-enabled' , vim . toString ( ) ) ;
13+ } else if ( vim_local_storage ) {
14+ vim = vim_local_storage !== 'false' ;
15+ }
16+ }
17+ return { ...data , vim } ;
18+ }
Original file line number Diff line number Diff line change 6161 : ` https://unpkg.com/svelte@${ version} ` ;
6262
6363 $: relaxed = data .gist .relaxed || (data .user && data .user .id === data .gist .owner );
64+
65+ $: vim = data .vim ;
6466< / script>
6567
6668< svelte: head>
8789 bind: this = {repl}
8890 {svelteUrl}
8991 {relaxed}
92+ {vim}
9093 injectedJS= {mapbox_setup}
9194 showModified
9295 showAst
You can’t perform that action at this time.
0 commit comments