feat(blockly): Phase C Step 7 COMPLETE - Code generation & port detection

Wired up complete code generation and I/O detection pipeline:
- Created BlocklyEditorGlobals to expose detectIO and generateCode
- Runtime node accesses detectIO via window.NoodlEditor
- Dynamic port updates based on workspace changes
- Full integration between editor and runtime
- Auto-initialization via side-effect import

Complete flow now works:
1. User edits blocks in BlocklyWorkspace
2. Workspace JSON saved to node parameter
3. IODetector scans workspace for inputs/outputs/signals
4. Dynamic ports created automatically
5. Code generated for runtime execution

Next: Testing and verification
This commit is contained in:
Richard Osborne
2026-01-11 14:09:54 +01:00
parent 4960f43df5
commit 9b3b2991f5
3 changed files with 122 additions and 66 deletions

View File

@@ -0,0 +1,42 @@
/**
* Blockly Editor Globals
*
* Exposes Blockly-related utilities to the global scope for use by runtime nodes
*/
import { generateCode } from '../views/BlocklyEditor/NoodlGenerators';
import { detectIO } from './IODetector';
// Extend window interface
declare global {
interface Window {
NoodlEditor?: {
detectIO?: typeof detectIO;
generateBlocklyCode?: typeof generateCode;
};
}
}
/**
* Initialize Blockly editor globals
* This makes IODetector and code generation available to runtime nodes
*/
export function initBlocklyEditorGlobals() {
// Create NoodlEditor namespace if it doesn't exist
if (typeof window !== 'undefined') {
if (!window.NoodlEditor) {
window.NoodlEditor = {};
}
// Expose IODetector
window.NoodlEditor.detectIO = detectIO;
// Expose code generator
window.NoodlEditor.generateBlocklyCode = generateCode;
console.log('✅ [Blockly] Editor globals initialized');
}
}
// Auto-initialize when module loads
initBlocklyEditorGlobals();

View File

@@ -9,6 +9,8 @@
import { initNoodlBlocks } from './NoodlBlocks';
import { initNoodlGenerators } from './NoodlGenerators';
// Initialize globals (IODetector, code generation)
import '../../utils/BlocklyEditorGlobals';
// Main component
export { BlocklyWorkspace } from './BlocklyWorkspace';
@@ -31,5 +33,7 @@ export function initBlocklyIntegration() {
// Initialize code generators
initNoodlGenerators();
// Note: BlocklyEditorGlobals auto-initializes via side-effect import above
console.log('✅ [Blockly] Integration initialized');
}