Skip to content

Commit a000bb6

Browse files
committed
integrate into menu
1 parent a9b6006 commit a000bb6

File tree

6 files changed

+53
-54
lines changed

6 files changed

+53
-54
lines changed

apps/svelte.dev/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"cookie": "^0.7.0",
3838
"d3-geo": "^3.1.0",
3939
"d3-geo-projection": "^4.0.0",
40-
"do-not-zip": "^1.0.0",
4140
"editor": "workspace:*",
4241
"flexsearch": "^0.7.43",
4342
"flru": "^1.0.2",

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js';
1010
import { page } from '$app/state';
1111
import type { File } from 'editor';
12-
// @ts-expect-error this library was created way before TS conquered the world
13-
import * as doNotZip from 'do-not-zip';
1412
1513
let { data } = $props();
1614
@@ -115,46 +113,6 @@
115113
}
116114
}
117115
118-
async function download() {
119-
const { files: components, imports } = repl.toJSON();
120-
121-
const files: Array<{ path: string; data: string }> = await (
122-
await fetch('/svelte-template.json')
123-
).json();
124-
125-
if (imports.length > 0) {
126-
const idx = files.findIndex(({ path }) => path === 'package.json');
127-
const pkg = JSON.parse(files[idx].data);
128-
const { devDependencies } = pkg;
129-
imports.forEach((mod) => {
130-
const match = /^(@[^/]+\/)?[^@/]+/.exec(mod)!;
131-
devDependencies[match[0]] = 'latest';
132-
});
133-
pkg.devDependencies = devDependencies;
134-
files[idx].data = JSON.stringify(pkg, null, ' ');
135-
}
136-
137-
files.push(
138-
...components.map((component) => ({
139-
path: `src/routes/${component.name}`,
140-
data: (component as File).contents
141-
}))
142-
);
143-
144-
const downloadBlob = (blob: any, filename: string) => {
145-
const url = URL.createObjectURL(blob);
146-
const link = document.createElement('a');
147-
link.href = url;
148-
link.download = filename;
149-
link.style.display = 'none';
150-
document.body.appendChild(link);
151-
link.click();
152-
URL.revokeObjectURL(url);
153-
link.remove();
154-
};
155-
downloadBlob(doNotZip.toBlob(files), 'svelte-app.zip');
156-
}
157-
158116
async function update_hash() {
159117
// Only change hash when necessary to avoid polluting everyone's browser history
160118
if (modified) {
@@ -217,12 +175,6 @@
217175
sessionStorage.setItem(STORAGE_KEY, json);
218176
}
219177
}}
220-
onkeydown={(e) => {
221-
// TODO remove once dropdown from VIM UI PR is merged
222-
if (e.ctrlKey && e.key === 'd') {
223-
download();
224-
}
225-
}}
226178
/>
227179

228180
<svelte:body onmouseleave={update_hash} />

packages/repl/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@sveltejs/site-kit": "workspace:*",
8181
"@sveltejs/svelte-json-tree": "^2.2.1",
8282
"acorn": "^8.11.3",
83+
"do-not-zip": "^1.0.0",
8384
"editor": "workspace:*",
8485
"esm-env": "^1.0.0",
8586
"esrap": "^1.2.2",

packages/repl/src/lib/Input/ComponentSelector.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
workspace: Workspace;
1111
can_migrate: boolean;
1212
migrate: () => void;
13+
download: () => void;
1314
}
1415
15-
let { runes, onchange, workspace, can_migrate, migrate }: Props = $props();
16+
let { runes, onchange, workspace, can_migrate, migrate, download }: Props = $props();
1617
1718
let input = $state() as HTMLInputElement;
1819
let input_value = $state(workspace.current.name);
@@ -170,6 +171,7 @@
170171
</label>
171172

172173
<button disabled={!can_migrate} onclick={migrate}>Migrate to Svelte 5, if possible</button>
174+
<button onclick={download}>Download app</button>
173175
</Toolbox>
174176
</div>
175177
</div>

packages/repl/src/lib/Repl.svelte

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import * as doNotZip from 'do-not-zip';
23
import { SplitPane } from '@rich_harris/svelte-split-pane';
34
import { ScreenToggle } from '@sveltejs/site-kit/components';
45
import { BROWSER } from 'esm-env';
@@ -107,6 +108,50 @@
107108
rebundle();
108109
}
109110
111+
async function download() {
112+
const { files: components, imports } = toJSON();
113+
114+
const files: Array<{ path: string; data: string }> =
115+
await // TODO this is a bit of a cyclic dependency: we assume that the site
116+
// does provide a template at this position which matches our expectations
117+
(
118+
await fetch('/svelte-template.json')
119+
).json();
120+
121+
if (imports.length > 0) {
122+
const idx = files.findIndex(({ path }) => path === 'package.json');
123+
const pkg = JSON.parse(files[idx].data);
124+
const { devDependencies } = pkg;
125+
imports.forEach((mod) => {
126+
const match = /^(@[^/]+\/)?[^@/]+/.exec(mod)!;
127+
devDependencies[match[0]] = 'latest';
128+
});
129+
pkg.devDependencies = devDependencies;
130+
files[idx].data = JSON.stringify(pkg, null, ' ');
131+
}
132+
133+
files.push(
134+
...components.map((component) => ({
135+
path: `src/routes/${component.name}`,
136+
data: (component as File).contents
137+
}))
138+
);
139+
140+
const downloadBlob = (blob: any, filename: string) => {
141+
const url = URL.createObjectURL(blob);
142+
const link = document.createElement('a');
143+
link.href = url;
144+
link.download = filename;
145+
link.style.display = 'none';
146+
document.body.appendChild(link);
147+
link.click();
148+
URL.revokeObjectURL(url);
149+
link.remove();
150+
};
151+
152+
downloadBlob(doNotZip.toBlob(files), 'svelte-app.zip');
153+
}
154+
110155
let width = $state(0);
111156
let show_output = $state(false);
112157
let status: string | null = $state(null);
@@ -174,7 +219,7 @@
174219
>
175220
{#snippet a()}
176221
<section>
177-
<ComponentSelector {runes} {onchange} {workspace} {can_migrate} {migrate} />
222+
<ComponentSelector {runes} {onchange} {workspace} {can_migrate} {migrate} {download} />
178223

179224
<Editor {workspace} />
180225
</section>

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)