File size: 1,437 Bytes
1c844de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Blockly Interface</title>
    <script src="https://unpkg.com/blockly/blockly.min.js"></script>
    <style>
        #blocklyDiv {
            height: 480px;
            width: 600px;
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <h1>Blockly Coding Interface</h1>
    <div id="blocklyDiv"></div>
    <button id="generate">Generate Code</button>
    <pre id="code"></pre>
    <script>
        var workspace = Blockly.inject('blocklyDiv', {
            toolbox: `
                <xml>
                    <block type="controls_if"></block>
                    <block type="logic_compare"></block>
                    <block type="math_number"></block>
                    <block type="math_arithmetic">
                        <field name="OP">ADD</field>
                    </block>
                    <block type="text"></block>
                    <block type="text_print"></block>
                </xml>
            `
        });

        document.getElementById('generate').onclick = function() {
            var code = Blockly.JavaScript.workspaceToCode(workspace);
            document.getElementById('code').innerText = code;
            // You could send the code back to the Gradio app here if needed
        };
    </script>
</body>
</html>