({ manualLink, examples, defaultProgram })
| 36 | * @param {string} config.defaultProgram - Initial program to load |
| 37 | */ |
| 38 | export function initializeApp({ manualLink, examples, defaultProgram }) { |
| 39 | // Create and insert app template |
| 40 | const app = document.getElementById('app'); |
| 41 | const appTemplate = createAppTemplate({ examples }); |
| 42 | app.appendChild(appTemplate); |
| 43 | |
| 44 | // Get DOM elements |
| 45 | const logEl = document.getElementById('log'); |
| 46 | const exampleSelect = document.getElementById('example-select'); |
| 47 | const editorHost = document.getElementById('code-editor'); |
| 48 | const validationContainer = document.getElementById('validation-container'); |
| 49 | const replContainer = document.getElementById('repl-container'); |
| 50 | const aiChatContainer = document.getElementById('ai-chat-container'); |
| 51 | |
| 52 | // Initialize core components |
| 53 | const builtins = createBuiltins(); |
| 54 | const audio = new AudioEngine(); |
| 55 | const stateManager = new StateManager(); |
| 56 | const scheduler = new Scheduler({ audio, builtins, stateManager }); |
| 57 | |
| 58 | // Create validation indicator |
| 59 | const validationIndicator = new ValidationIndicator(); |
| 60 | validationContainer.appendChild(validationIndicator.getElement()); |
| 61 | |
| 62 | // Create live evaluator |
| 63 | const liveEvaluator = new LiveEvaluator({ scheduler, debounceMs: defaults.debounceMs }); |
| 64 | |
| 65 | // Create REPL |
| 66 | const repl = new REPL({ |
| 67 | getProgram: () => liveEvaluator.currentProgram || [], |
| 68 | builtins, |
| 69 | stateManager |
| 70 | }); |
| 71 | replContainer.appendChild(repl.getElement()); |
| 72 | |
| 73 | // Logging utility |
| 74 | function log(msg) { |
| 75 | logEl.textContent = (msg + "\n" + logEl.textContent).slice(0, defaults.logMaxChars); |
| 76 | } |
| 77 | |
| 78 | // Editor management |
| 79 | let editorView; |
| 80 | |
| 81 | function getCode() { |
| 82 | return editorView ? editorView.state.doc.toString() : ''; |
| 83 | } |
| 84 | |
| 85 | function setCode(text) { |
| 86 | if (!editorView) return; |
| 87 | editorView.dispatch({ changes: { from: 0, to: editorView.state.doc.length, insert: text } }); |
| 88 | } |
| 89 | |
| 90 | // Allow optional external drivers (e.g., AI bridge) to read/write code or run queries. |
| 91 | const runQuery = (queryText) => { |
| 92 | if (repl && typeof repl.executeQueryFromText === 'function') { |
| 93 | repl.executeQueryFromText(queryText); |
| 94 | } |
| 95 | }; |
no test coverage detected