mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
WIP
This commit is contained in:
@@ -380,6 +380,8 @@
|
|||||||
window.log = console.log
|
window.log = console.log
|
||||||
|
|
||||||
if(new URLSearchParams(window.location.search).get('leporello') == null) {
|
if(new URLSearchParams(window.location.search).get('leporello') == null) {
|
||||||
|
await import('./src/launch.js');
|
||||||
|
/*
|
||||||
const {init} = await import('./src/index.js');
|
const {init} = await import('./src/index.js');
|
||||||
(
|
(
|
||||||
document.readyState == 'complete'
|
document.readyState == 'complete'
|
||||||
@@ -390,6 +392,7 @@
|
|||||||
).then(() => {
|
).then(() => {
|
||||||
init(document.getElementById('app'))
|
init(document.getElementById('app'))
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
12
src/cmd.js
12
src/cmd.js
@@ -759,6 +759,7 @@ const load_dir = (state, dir) => {
|
|||||||
collect_files(dir).map(f => [f.path, f.contents])
|
collect_files(dir).map(f => [f.path, f.contents])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Clear parse cache and rerun code
|
||||||
return rerun_code({
|
return rerun_code({
|
||||||
...state,
|
...state,
|
||||||
// remove cache
|
// remove cache
|
||||||
@@ -773,6 +774,15 @@ const create_file = (state, dir, current_module) => {
|
|||||||
return {...load_dir(state, dir), current_module}
|
return {...load_dir(state, dir), current_module}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const open_run_window = state => {
|
||||||
|
// After we reopen run window, we should reload external modules in the
|
||||||
|
// context of new window. Clear external_imports_cache
|
||||||
|
return rerun_code({
|
||||||
|
...state,
|
||||||
|
external_imports_cache: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const get_initial_state = state => {
|
export const get_initial_state = state => {
|
||||||
const with_files = state.project_dir == null
|
const with_files = state.project_dir == null
|
||||||
? state
|
? state
|
||||||
@@ -798,7 +808,7 @@ export const get_initial_state = state => {
|
|||||||
|
|
||||||
export const COMMANDS = {
|
export const COMMANDS = {
|
||||||
input,
|
input,
|
||||||
rerun_code,
|
open_run_window,
|
||||||
load_dir,
|
load_dir,
|
||||||
create_file,
|
create_file,
|
||||||
step_into,
|
step_into,
|
||||||
|
|||||||
10
src/effects.js
vendored
10
src/effects.js
vendored
@@ -8,13 +8,21 @@ import {
|
|||||||
import {FLAGS} from './feature_flags.js'
|
import {FLAGS} from './feature_flags.js'
|
||||||
import {exec} from './index.js'
|
import {exec} from './index.js'
|
||||||
|
|
||||||
|
// Imports in the context of `run_window`, so global variables in loaded
|
||||||
|
// modules refer to that window's context
|
||||||
|
const import_in_run_window = url => {
|
||||||
|
return new globalThis.run_window.Function('url', `
|
||||||
|
return import(url)
|
||||||
|
`)(url)
|
||||||
|
}
|
||||||
|
|
||||||
const load_external_imports = async state => {
|
const load_external_imports = async state => {
|
||||||
if(state.loading_external_imports_state == null) {
|
if(state.loading_external_imports_state == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const urls = state.loading_external_imports_state.external_imports
|
const urls = state.loading_external_imports_state.external_imports
|
||||||
const results = await Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
urls.map(u => import(
|
urls.map(u => import_in_run_window(
|
||||||
/^\w+:\/\//.test(u)
|
/^\w+:\/\//.test(u)
|
||||||
? // starts with protocol, import as is
|
? // starts with protocol, import as is
|
||||||
u
|
u
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {COMMANDS, get_initial_state} from './cmd.js'
|
import {get_initial_state} from './cmd.js'
|
||||||
import {active_frame} from './calltree.js'
|
|
||||||
import {UI} from './editor/ui.js'
|
import {UI} from './editor/ui.js'
|
||||||
import {EFFECTS, render_initial_state, render_common_side_effects} from './effects.js'
|
import {EFFECTS, render_initial_state, render_common_side_effects} from './effects.js'
|
||||||
import {load_dir} from './filesystem.js'
|
import {load_dir} from './filesystem.js'
|
||||||
@@ -62,10 +61,13 @@ const read_modules = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let COMMANDS
|
||||||
let ui
|
let ui
|
||||||
let state
|
let state
|
||||||
|
|
||||||
export const init = (container) => {
|
export const init = (container, _COMMANDS) => {
|
||||||
|
COMMANDS = _COMMANDS
|
||||||
|
|
||||||
set_error_handler(window)
|
set_error_handler(window)
|
||||||
|
|
||||||
read_modules().then(initial_state => {
|
read_modules().then(initial_state => {
|
||||||
|
|||||||
6
src/launch.js
Normal file
6
src/launch.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// external
|
||||||
|
import {init} from './index.js'
|
||||||
|
|
||||||
|
import {COMMANDS} from './cmd.js'
|
||||||
|
|
||||||
|
init(globalThis.document.getElementById('app'), COMMANDS)
|
||||||
Reference in New Issue
Block a user