mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
open window to run code
This commit is contained in:
@@ -322,8 +322,12 @@
|
||||
.status {
|
||||
color: red;
|
||||
}
|
||||
.options {
|
||||
|
||||
.open_run_window {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.options {
|
||||
padding: 5px;
|
||||
}
|
||||
.options > * {
|
||||
@@ -384,8 +388,6 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<iframe id='run_code' src='iframe.html' hidden>
|
||||
</iframe>
|
||||
<div id='app' class='app'>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {exec, get_state} from '../index.js'
|
||||
import {exec, get_state, open_run_window} from '../index.js'
|
||||
import {Editor} from './editor.js'
|
||||
import {Files} from './files.js'
|
||||
import {CallTree} from './calltree.js'
|
||||
@@ -67,6 +67,15 @@ export class UI {
|
||||
'Fullscreen'
|
||||
),
|
||||
*/
|
||||
|
||||
el('a', {
|
||||
'class': 'open_run_window',
|
||||
href: 'javascript: void(0)',
|
||||
click: open_run_window,
|
||||
},
|
||||
'(Re)open run window (F6)'
|
||||
),
|
||||
|
||||
this.options = el('div', 'options',
|
||||
el('label', {'for': 'standard'},
|
||||
el('input', {
|
||||
@@ -126,6 +135,10 @@ export class UI {
|
||||
if(e.key == 'F5'){
|
||||
this.fullscreen_editor()
|
||||
}
|
||||
|
||||
if(e.key == 'F6'){
|
||||
open_run_window()
|
||||
}
|
||||
})
|
||||
|
||||
if(!FLAGS.embed_value_explorer) {
|
||||
|
||||
19
src/eval.js
19
src/eval.js
@@ -57,15 +57,16 @@ type Node = ToplevelCall | Call
|
||||
*/
|
||||
|
||||
// TODO just export const Iframe_Function?
|
||||
const make_function = globalThis.process != null
|
||||
// Tests are run in Node.js, no iframe
|
||||
? (...args) => new Function(...args)
|
||||
// Browser context, run code in iframe
|
||||
: (...args) => {
|
||||
/* access window object for iframe */
|
||||
const fn_constructor = globalThis.run_code.contentWindow.Function
|
||||
return new fn_constructor(...args)
|
||||
}
|
||||
const make_function = (...args) => {
|
||||
if(globalThis.run_window == null) {
|
||||
// Tests are run in Node.js or user have not opened run_window
|
||||
return new Function(...args)
|
||||
} else {
|
||||
// Code run in browser and user opened run_window
|
||||
const fn_constructor = globalThis.run_window.Function
|
||||
return new fn_constructor(...args)
|
||||
}
|
||||
}
|
||||
|
||||
const codegen_function_expr = (node, cxt, name) => {
|
||||
const do_codegen = n => codegen(n, cxt)
|
||||
|
||||
@@ -10,6 +10,13 @@ const EXAMPLE = `const fib = n =>
|
||||
: fib(n - 1) + fib(n - 2)
|
||||
fib(6)`
|
||||
|
||||
export const open_run_window = () => {
|
||||
if(globalThis.run_window != null) {
|
||||
globalThis.run_window.close()
|
||||
}
|
||||
globalThis.run_window = open('about:blank')
|
||||
}
|
||||
|
||||
const read_modules = async () => {
|
||||
const default_module = {'': localStorage.code || EXAMPLE}
|
||||
const current = {
|
||||
|
||||
Reference in New Issue
Block a user