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