diff --git a/packages/repl/src/lib/Output/Viewer.svelte b/packages/repl/src/lib/Output/Viewer.svelte index 3931e79a1f..ba4b03f05a 100644 --- a/packages/repl/src/lib/Output/Viewer.svelte +++ b/packages/repl/src/lib/Output/Viewer.svelte @@ -5,13 +5,14 @@ import Message from '../Message.svelte'; import PaneWithPanel from './PaneWithPanel.svelte'; import ReplProxy from './ReplProxy.js'; - import Console, { type Log } from './console/Console.svelte'; + import { type Log } from './console/Console.svelte'; import getLocationFromStack from './get-location-from-stack'; import srcdoc from './srcdoc/index.html?raw'; import ErrorOverlay from './ErrorOverlay.svelte'; import type { CompileError } from 'svelte/compiler'; import type { Bundle } from '../types'; import type { Writable } from 'svelte/store'; + import DevTools from './devtools/DevTools.svelte'; export let error: Error | null; /** status by Bundler class instance */ @@ -157,30 +158,34 @@ const __repl_exports = ${$bundle.client?.code}; { - const { mount, unmount, App, untrack } = __repl_exports; + const { mount, unmount, App } = __repl_exports; - const console_methods = ['log', 'error', 'trace', 'assert', 'warn', 'table', 'group']; + const render_app = () => { + const component = mount(App, { target: document.body }); - // The REPL hooks up to the console to provide a virtual console. However, the implementation - // needs to stringify the console to pass over a MessageChannel, which means that the object - // can get deeply read and tracked by accident when using the console. We can avoid this by - // ensuring we untrack the main console methods. - - const original = {}; - - for (const method of console_methods) { - original[method] = console[method]; - console[method] = function (...v) { - return untrack(() => original[method].apply(this, v)); - } - } - const component = mount(App, { target: document.body }); - window.__unmount_previous = () => { - for (const method of console_methods) { - console[method] = original[method]; + window.__unmount_previous = () => { + unmount(component); } - unmount(component); + }; + + if (!window.initialize_devtools) { + window.initialize_devtools = () => { + var script = document.createElement('script'); + script.src = 'https://cdn.jsdelivr.net/npm/chii@1.12.3/public/target.js'; + script.setAttribute('embedded', 'true'); + script.setAttribute('cdn', 'https://cdn.jsdelivr.net/npm/chii/public'); + document.head.appendChild(script); + + script.onload = render_app; + }; + + setTimeout(() => { + window.dispatchEvent(new Event('preview_ready')); + }, 0); + } else { + render_app(); } + } //# sourceURL=playground:output `); @@ -282,7 +287,7 @@ 'allow-pointer-lock', 'allow-modals', can_escape ? 'allow-popups-to-escape-sandbox' : '', - relaxed ? 'allow-same-origin' : '' + 'allow-same-origin' ].join(' ')} class={error || pending || pending_imports ? 'greyed-out' : ''} srcdoc={BROWSER ? srcdoc : ''} @@ -295,18 +300,9 @@
{#if !onLog} - - {#snippet header()} - - {/snippet} - + {#snippet body()} - + {/snippet} {:else} diff --git a/packages/repl/src/lib/Output/devtools/DevTools.svelte b/packages/repl/src/lib/Output/devtools/DevTools.svelte new file mode 100644 index 0000000000..92f7062b42 --- /dev/null +++ b/packages/repl/src/lib/Output/devtools/DevTools.svelte @@ -0,0 +1,31 @@ + + + + + diff --git a/packages/repl/src/lib/Output/srcdoc/index.html b/packages/repl/src/lib/Output/srcdoc/index.html index 9e56bf30db..7aa1e54a8b 100644 --- a/packages/repl/src/lib/Output/srcdoc/index.html +++ b/packages/repl/src/lib/Output/srcdoc/index.html @@ -68,21 +68,6 @@