var workspace = Blockly.inject('blocklyDiv', {
/*plugins: {
toolbox: ContinuousToolbox,
flyoutsVerticalToolbox: ContinuousFlyout,
metricsManager: ContinuousMetrics,
},*/
toolbox: document.getElementById('toolbox'),
grid: {
spacing: 20,
length: 3,
colour: '#ccc',
snap: false,
},
trashcan: true,
renderer: 'Zelos',
theme: 'darkTheme',
sounds: true,
zoom: {
controls: true,
wheel: true,
startScale: 0.8,
maxScale: 15,
minScale: 0.5,
scaleSpeed: 1.2,
pinch: true
},
});
const backpack = new Backpack(workspace);
backpack.init();
const options = {
contextMenu: true,
shortcut: true,
};
// Initialize plugin.
const plugin = new CrossTabCopyPaste();
plugin.init(options, () => {
console.log('Use this error callback to handle TypeError while pasting');
});
// optional: Remove the duplication command from Blockly's context menu.
Blockly.ContextMenuRegistry.registry.unregister('blockDuplicate');
// optional: You can change the position of the menu added to the context menu.
Blockly.ContextMenuRegistry.registry.getItem('blockCopyToStorage').weight = 2;
Blockly.ContextMenuRegistry.registry.getItem(
'blockPasteFromStorage',
).weight = 3;
workspace.addChangeListener(updateCode);
// Function to update the code
function updateCode() {
var code = Blockly.JavaScript.workspaceToCode(workspace);
Blockly.JavaScript.addReservedWords('code');
document.getElementById('generatedCodeBlockly').textContent = code;
updateHTML(code); // Update HTML in iframe
}
// Function to update HTML content in iframe
function updateHTML(html) {
var iframe = document.getElementById('generatedHTMLFrame');
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(html);
iframeDocument.close();
}
// Initial code update
updateCode();