Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
if (!hash && !saved) {
repl?.set({
// TODO make this munging unnecessary (using JSON instead of structuredClone for better browser compat)
files: JSON.parse(JSON.stringify(data.gist.components)).map(munge)
files: JSON.parse(JSON.stringify(data.gist.components)).map(munge),
tailwind: false // TODO
});

modified = false;
Expand All @@ -92,7 +93,7 @@
name = recovered.name;
}

repl.set({ files });
repl.set({ files, tailwind: recovered.tailwind ?? false });
} catch {
alert(`Couldn't load the code from the URL. Make sure you copied the link correctly.`);
}
Expand Down Expand Up @@ -155,7 +156,8 @@
async function update_hash() {
// Only change hash when necessary to avoid polluting everyone's browser history
if (modified) {
const json = JSON.stringify({ name, files: repl.toJSON().files });
const { files, tailwind } = repl.toJSON();
const json = JSON.stringify({ name, files, tailwind });
await set_hash(json);
}
}
Expand Down Expand Up @@ -210,7 +212,8 @@
if (modified) {
// we can't save to the hash because it's an async operation, so we use
// a short-lived sessionStorage value instead
const json = JSON.stringify({ name, files: repl.toJSON().files });
const { files, tailwind } = repl.toJSON();
const json = JSON.stringify({ name, files, tailwind });
sessionStorage.setItem(STORAGE_KEY, json);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@

if (!hash) {
repl?.set({
files: data.gist.components.map(munge)
files: data.gist.components.map(munge),
tailwind: false // TODO
});

return;
}

try {
const recovered = JSON.parse(await decode_and_decompress_text(hash));
repl.set({ files: recovered.files });
repl.set({ files: recovered.files, tailwind: recovered.tailwind ?? false });
} catch {
alert(`Couldn't load the code from the URL. Make sure you copied the link correctly.`);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/editor/src/lib/Workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,14 @@ export class Workspace {
this.#onreset?.(this.#files);
}

reset(new_files: Item[], selected?: string) {
reset(new_files: Item[], options: { tailwind: boolean }, selected?: string) {
this.states.clear();
this.set(new_files, selected);

this.mark_saved();

this.#tailwind = options.tailwind;

this.#onreset(new_files);
this.#reset_diagnostics();
}
Expand Down Expand Up @@ -471,7 +473,7 @@ export class Workspace {

set tailwind(value) {
this.#tailwind = value;
this.#onreset(this.#files);
this.#onupdate(this.#current);
}

get vim() {
Expand Down
7 changes: 4 additions & 3 deletions packages/repl/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@
export function toJSON() {
return {
imports: $bundle?.imports ?? [],
files: workspace.files
files: workspace.files,
tailwind: workspace.tailwind
};
}

// TODO get rid
export async function set(data: { files: File[]; css?: string }) {
workspace.reset(data.files, 'App.svelte');
export async function set(data: { files: File[]; tailwind?: boolean }) {
workspace.reset(data.files, { tailwind: data.tailwind ?? false }, 'App.svelte');
}

// TODO get rid
Expand Down