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
5 changes: 5 additions & 0 deletions .changeset/great-singers-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/repl': patch
---

Themeable previews
14 changes: 7 additions & 7 deletions packages/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"@fontsource/fira-mono": "^4.5.10",
"@playwright/test": "^1.33.0",
"@sveltejs/adapter-auto": "^2.0.1",
"@sveltejs/kit": "^1.15.9",
"@sveltejs/kit": "^1.15.10",
"@sveltejs/package": "^2.0.2",
"@types/marked": "^4.0.8",
"@types/marked": "^4.3.0",
"publint": "^0.1.11",
"svelte": "^3.58.0",
"svelte-check": "^3.2.0",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"vite": "^4.3.3"
"vite": "^4.3.4"
},
"dependencies": {
"@codemirror/autocomplete": "^6.6.0",
Expand All @@ -56,19 +56,19 @@
"@codemirror/language": "^6.6.0",
"@codemirror/lint": "^6.2.1",
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.10.0",
"@codemirror/view": "^6.10.1",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@lezer/highlight": "^1.1.4",
"@neocodemirror/svelte": "0.0.5",
"@neocodemirror/svelte": "0.0.8",
"@replit/codemirror-lang-svelte": "^6.0.0",
"@rich_harris/svelte-split-pane": "^1.1.0",
"@rollup/browser": "^3.21.1",
"@rollup/browser": "^3.21.3",
"@sveltejs/site-kit": "5.0.4",
"acorn": "^8.8.2",
"codemirror": "^6.0.1",
"esm-env": "^1.0.0",
"estree-walker": "^3.0.3",
"marked": "^4.3.0",
"marked": "^5.0.0",
"resolve.exports": "^2.0.2",
"svelte-json-tree": "^1.0.0"
},
Expand Down
7 changes: 4 additions & 3 deletions packages/repl/src/lib/CodeMirror.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@
* @param {number} pos
*/
export function setCursor(pos) {
$cmInstance.view?.dispatch({
selection: { anchor: pos, head: pos }
});
cursor_pos = pos;
}

/** @type {(...val: any) => void} */
Expand Down Expand Up @@ -180,6 +178,8 @@
/** @type {import('@codemirror/state').Extension[]} */
let extensions = [];

let cursor_pos = 0;

$: {
if ($cmInstance.view) {
fulfil_module_editor_ready();
Expand Down Expand Up @@ -232,6 +232,7 @@
tabSize: 2,
theme: svelteTheme,
readonly,
cursorPos: cursor_pos,
lang,
langMap: {
js: () => import('@codemirror/lang-javascript').then((m) => m.javascript()),
Expand Down
12 changes: 11 additions & 1 deletion packages/repl/src/lib/Output/Output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
// export let theme;
export let showAst = false;

/** @type {'light' | 'dark'} */
export let previewTheme;

/**
* @param {import('$lib/types').File} file
* @param {import('svelte/types/compiler').CompileOptions} options
Expand Down Expand Up @@ -113,7 +116,14 @@

<!-- component viewer -->
<div class="tab-content" class:visible={selected_type !== 'md' && view === 'result'}>
<Viewer bind:error={runtimeError} {status} {relaxed} {injectedJS} {injectedCSS} />
<Viewer
bind:error={runtimeError}
{status}
{relaxed}
{injectedJS}
{injectedCSS}
theme={previewTheme}
/>
</div>

<!-- js output -->
Expand Down
2 changes: 1 addition & 1 deletion packages/repl/src/lib/Output/ReplProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class ReplProxy {
on_console_group: noop,
on_console_group_collapsed: noop,
on_console_group_end: noop,
on_unhandled_rejection: noop,
on_unhandled_rejection: noop
};

/** @type {Map<number, { resolve: (value: any) => void, reject: (value: any) => void }>} */
Expand Down
9 changes: 7 additions & 2 deletions packages/repl/src/lib/Output/Viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
export let injectedJS = '';
export let injectedCSS = '';

/** @type {'light' | 'dark'} */
export let theme;

/** @type {HTMLIFrameElement} */
let iframe;
let pending_imports = 0;
Expand Down Expand Up @@ -75,7 +78,7 @@
},
on_console_group_collapsed: (action) => {
group_logs(action.label, true);
},
}
});

iframe.addEventListener('load', () => {
Expand All @@ -88,6 +91,8 @@
};
});

$: if (ready) proxy?.iframe_command('set_theme', { theme });

/**
* @param {import('$lib/types').Bundle | null} $bundle
*/
Expand Down Expand Up @@ -231,7 +236,7 @@
'allow-pointer-lock',
'allow-top-navigation',
'allow-modals',
relaxed ? 'allow-same-origin' : '',
relaxed ? 'allow-same-origin' : ''
].join(' ')}
class={error || pending || pending_imports ? 'greyed-out' : ''}
srcdoc={BROWSER ? srcdoc : ''}
Expand Down
115 changes: 52 additions & 63 deletions packages/repl/src/lib/Output/srcdoc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,66 @@
<html>
<head>
<style>
html,
body {
position: relative;
width: 100%;
height: 100%;
}

body {
color: #333;
margin: 0;
padding: 8px;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
Cantarell, 'Helvetica Neue', sans-serif;
--bg-1: hsl(0, 0%, 100%);
--bg-2: hsl(206, 20%, 90%);
--bg-3: hsl(206, 20%, 80%);
--fg-1: hsl(0, 0%, 13%);
--fg-2: hsl(0, 0%, 20%);
--fg-2: hsl(0, 0%, 30%);
--link: hsl(208, 77%, 47%);
--link-hover: hsl(208, 77%, 55%);
--link-active: hsl(208, 77%, 40%);
--border-radius: 4px;
--font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
--font-mono: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas,
'DejaVu Sans Mono', monospace;
color-scheme: light;
background: var(--bg-1);
color: var(--fg-1);
font-family: var(--font);
line-height: 1.5;
margin: 1rem;
height: calc(100vh - 2rem);
accent-color: var(--hover) !important;
}

a {
color: rgb(0, 100, 200);
text-decoration: none;
color: var(--link);
}

a:hover {
text-decoration: underline;
}

a:visited {
color: rgb(0, 80, 160);
color: var(--link-hover);
}

label {
display: block;
a:active {
color: var(--link-active);
}

input,
button,
select,
textarea {
font-family: inherit;
font-size: inherit;
-webkit-padding: 0.4em 0;
padding: 0.4em;
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 2px;
code {
background: var(--bg-2);
font-family: var(--font-mono);
font-size: 0.9em;
padding: 0.15rem 0.3rem;
border-radius: var(--border-radius);
}

input[type='range'] {
padding: 0.4em 0;
ul.todos {
padding: 0;
}

input:disabled {
color: #ccc;
}

button {
color: #333;
background-color: #f4f4f4;
outline: none;
}

button:disabled {
color: #999;
}

button:not(:disabled):active {
background-color: #ddd;
}

button:focus {
border-color: #666;
}

@media (prefers-color-scheme: dark) {
body {
background: hsl(0, 0%, 18%);
color: hsl(0, 0%, 90%);
}
body.dark {
color-scheme: dark;
--bg-1: hsl(0, 0%, 18%);
--bg-2: hsl(0, 0%, 30%);
--bg-3: hsl(0, 0%, 40%);
--fg-1: hsl(0, 0%, 90%);
--fg-2: hsl(0, 0%, 70%);
--fg-3: hsl(0, 0%, 60%);
--link: hsl(206, 96%, 72%);
--link-hover: hsl(206, 96%, 78%);
--link-active: hsl(206, 96%, 64%);
}
</style>

Expand All @@ -93,6 +75,13 @@
const send_error = (message, stack) =>
send_reply({ action: 'cmd_error', message, stack });

if (action === 'set_theme') {
const { theme } = ev.data.args;

document.body.classList.toggle('dark', theme === 'dark');
send_ok();
}

if (action === 'eval') {
try {
const { script } = ev.data.args;
Expand Down
4 changes: 3 additions & 1 deletion packages/repl/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
export let fixedPos = 50;
export let injectedJS = '';
export let injectedCSS = '';
// export let theme = 'svelte';
/** @type {'light' | 'dark'} */
export let previewTheme = 'light';
export let showModified = false;
export let showAst = false;

Expand Down Expand Up @@ -196,6 +197,7 @@
{injectedJS}
{injectedCSS}
{showAst}
{previewTheme}
/>
</section>
</SplitPane>
Expand Down
2 changes: 1 addition & 1 deletion packages/repl/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</script>

<main>
<Repl bind:this={repl} showAst />
<Repl bind:this={repl} previewTheme="dark" />
</main>

<style>
Expand Down
Loading