File tree Expand file tree Collapse file tree 3 files changed +67
-21
lines changed
apps/svelte.dev/src/routes/(authed)/playground/[id]/embed Expand file tree Collapse file tree 3 files changed +67
-21
lines changed Original file line number Diff line number Diff line change 5
5
import { Repl } from ' @sveltejs/repl' ;
6
6
import { mapbox_setup } from ' ../../../../../config.js' ;
7
7
import { page } from ' $app/state' ;
8
+ import { decode_and_decompress_text } from ' ../gzip.js' ;
9
+ import type { File } from ' editor' ;
8
10
9
11
let { data } = $props ();
10
12
25
27
});
26
28
}
27
29
30
+ // TODO make this munging unnecessary
31
+ function munge(data : any ): File {
32
+ const basename = ` ${data .name }.${data .type } ` ;
33
+
34
+ return {
35
+ type: ' file' ,
36
+ name: basename ,
37
+ basename ,
38
+ contents: data .source ,
39
+ text: true
40
+ };
41
+ }
42
+
43
+ async function set_files() {
44
+ const hash = location .hash .slice (1 );
45
+
46
+ if (! hash ) {
47
+ repl ?.set ({
48
+ files: data .gist .components .map (munge )
49
+ });
50
+
51
+ return ;
52
+ }
53
+
54
+ try {
55
+ const recovered = JSON .parse (await decode_and_decompress_text (hash ));
56
+ repl .set ({ files: recovered .files });
57
+ } catch {
58
+ alert (` Couldn't load the code from the URL. Make sure you copied the link correctly. ` );
59
+ }
60
+ }
61
+
28
62
afterNavigate (() => {
29
- repl ?.set ({
30
- files: data .gist .components
31
- });
63
+ set_files ();
32
64
});
33
65
34
66
const relaxed = $derived (data .gist .relaxed || (data .user && data .user .id === data .gist .owner ));
51
83
can _escape
52
84
injectedJS ={mapbox_setup }
53
85
previewTheme ={theme .current }
54
- embedded
86
+ embedded ={ page . url . searchParams . has ( ' output-only ' ) ? ' output-only ' : true }
55
87
/>
56
88
{/if }
57
89
</div >
Original file line number Diff line number Diff line change 12
12
interface Props {
13
13
status: string | null ;
14
14
runtimeError? : Error | null ;
15
- embedded? : boolean ;
15
+ embedded? : boolean | ' output-only ' ;
16
16
relaxed? : boolean ;
17
17
can_escape? : boolean ;
18
18
injectedJS: string ;
182
182
});
183
183
</script >
184
184
185
- <div class =" view-toggle" >
186
- {#if workspace .current .name .endsWith (' .md' )}
187
- <button class =" active" >Markdown</button >
188
- {:else }
189
- <button aria-current ={view === ' result' } onclick ={() => (view = ' result' )}>Result</button >
190
- <button aria-current ={view === ' js' } onclick ={() => (view = ' js' )}>JS output</button >
191
- <button aria-current ={view === ' css' } onclick ={() => (view = ' css' )}>CSS output</button >
192
- <button aria-current ={view === ' ast' } onclick ={() => (view = ' ast' )}>AST output</button >
193
- {/if }
194
- </div >
185
+ {#if embedded !== ' output-only' }
186
+ <div class =" view-toggle" >
187
+ {#if workspace .current .name .endsWith (' .md' )}
188
+ <button class =" active" >Markdown</button >
189
+ {:else }
190
+ <button aria-current ={view === ' result' } onclick ={() => (view = ' result' )}>Result</button >
191
+ <button aria-current ={view === ' js' } onclick ={() => (view = ' js' )}>JS output</button >
192
+ <button aria-current ={view === ' css' } onclick ={() => (view = ' css' )}>CSS output</button >
193
+ <button aria-current ={view === ' ast' } onclick ={() => (view = ' ast' )}>AST output</button >
194
+ {/if }
195
+ </div >
196
+ {/if }
195
197
196
198
<!-- component viewer -->
197
199
<div class ="tab-content" class:visible ={! is_markdown && view === ' result' }>
202
204
{can_escape }
203
205
{injectedJS }
204
206
{injectedCSS }
207
+ onLog ={embedded === ' output-only' ? () => {} : undefined }
205
208
theme ={previewTheme }
206
209
/>
207
210
</div >
Original file line number Diff line number Diff line change 13
13
interface Props {
14
14
packagesUrl? : string ;
15
15
svelteVersion? : string ;
16
- embedded? : boolean ;
16
+ embedded? : boolean | ' output-only ' ;
17
17
orientation? : ' columns' | ' rows' ;
18
18
relaxed? : boolean ;
19
19
can_escape? : boolean ;
152
152
let mobile = $derived (width < 540 );
153
153
154
154
$effect (() => {
155
- $toggleable = mobile && orientation === ' columns' ;
155
+ $toggleable = mobile && orientation === ' columns' && embedded !== ' output-only ' ;
156
156
});
157
157
158
158
let runes = $derived (
166
166
167
167
<svelte:window onbeforeunload ={before_unload } />
168
168
169
- <div class ="container" class:embedded class:toggleable ={$toggleable } bind:clientWidth ={width }>
169
+ <div
170
+ class ="container {embedded === ' output-only' ? ' ' : ' container-normal' }"
171
+ class:embedded
172
+ class:toggleable ={$toggleable }
173
+ bind:clientWidth ={width }
174
+ >
170
175
<div class ="viewport" class:output ={show_output }>
171
176
<SplitPane
172
177
id =" main"
173
178
type ={orientation === ' rows' ? ' vertical' : ' horizontal' }
174
- pos =" {mobile || fixed ? fixedPos : orientation === ' rows' ? 60 : 50 }%"
175
- min =" 100px"
179
+ pos =" {embedded === ' output-only'
180
+ ? 0
181
+ : mobile || fixed
182
+ ? fixedPos
183
+ : orientation === ' rows'
184
+ ? 60
185
+ : 50 }%"
186
+ min ={embedded === ' output-only' ? ' 0px' : ' 100px' }
176
187
max =" -4.1rem"
177
188
>
178
189
{#snippet a ()}
264
275
265
276
/* on mobile, override the <SplitPane> controls */
266
277
@media (max-width : 799px ) {
267
- :global {
278
+ .container-normal :global {
268
279
[data-pane ='main '] {
269
280
--pos : 50% !important ;
270
281
}
You can’t perform that action at this time.
0 commit comments