Spaces:
Running
Running
owenkaplinsky
commited on
Commit
·
91f956e
1
Parent(s):
72263a9
Add dropdown functionality
Browse files- project/src/index.html +6 -7
- project/src/index.js +60 -0
project/src/index.html
CHANGED
|
@@ -16,19 +16,18 @@
|
|
| 16 |
<div class="menuGroup">
|
| 17 |
<button class="menuButton">File</button>
|
| 18 |
<div class="dropdown">
|
| 19 |
-
<a href="#" class="dropdownItem" data-action="new">New</a>
|
| 20 |
-
<a href="#" class="dropdownItem" data-action="open">Open</a>
|
| 21 |
-
<a href="#" class="dropdownItem" data-action="download">Download</a>
|
| 22 |
</div>
|
| 23 |
</div>
|
| 24 |
|
| 25 |
<div class="menuGroup">
|
| 26 |
<button class="menuButton">Edit</button>
|
| 27 |
<div class="dropdown">
|
| 28 |
-
<a href="#" class="dropdownItem" data-action="undo">Undo</a>
|
| 29 |
-
<a href="#" class="dropdownItem" data-action="redo">Redo</a>
|
| 30 |
-
<a href="#" class="dropdownItem" data-action="cleanup">Clean up</a>
|
| 31 |
-
<a href="#" class="dropdownItem" data-action="clear">Clear</a>
|
| 32 |
</div>
|
| 33 |
</div>
|
| 34 |
|
|
|
|
| 16 |
<div class="menuGroup">
|
| 17 |
<button class="menuButton">File</button>
|
| 18 |
<div class="dropdown">
|
| 19 |
+
<a href="#" id="newButton" class="dropdownItem" data-action="new">New</a>
|
| 20 |
+
<a href="#" id="loadButton" class="dropdownItem" data-action="open">Open</a>
|
| 21 |
+
<a href="#" id="saveButton" class="dropdownItem" data-action="download">Download</a>
|
| 22 |
</div>
|
| 23 |
</div>
|
| 24 |
|
| 25 |
<div class="menuGroup">
|
| 26 |
<button class="menuButton">Edit</button>
|
| 27 |
<div class="dropdown">
|
| 28 |
+
<a href="#" id="undoButton" class="dropdownItem" data-action="undo">Undo</a>
|
| 29 |
+
<a href="#" id="redoButton" class="dropdownItem" data-action="redo">Redo</a>
|
| 30 |
+
<a href="#" id="cleanWorkspace" class="dropdownItem" data-action="cleanup">Clean up</a>
|
|
|
|
| 31 |
</div>
|
| 32 |
</div>
|
| 33 |
|
project/src/index.js
CHANGED
|
@@ -41,6 +41,66 @@ const ws = Blockly.inject(blocklyDiv, {
|
|
| 41 |
|
| 42 |
window.workspace = ws;
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
// Observe any size change to the blockly container
|
| 45 |
const observer = new ResizeObserver(() => {
|
| 46 |
Blockly.svgResize(ws);
|
|
|
|
| 41 |
|
| 42 |
window.workspace = ws;
|
| 43 |
|
| 44 |
+
const newButton = document.querySelector('#newButton');
|
| 45 |
+
|
| 46 |
+
newButton.addEventListener("click", () => {
|
| 47 |
+
ws.clear()
|
| 48 |
+
|
| 49 |
+
// Create the MCP block
|
| 50 |
+
const mcpBlock = ws.newBlock('create_mcp');
|
| 51 |
+
mcpBlock.initSvg();
|
| 52 |
+
mcpBlock.setDeletable(false);
|
| 53 |
+
mcpBlock.setMovable(true); // Allow moving but not deleting
|
| 54 |
+
|
| 55 |
+
// Position it in a reasonable spot
|
| 56 |
+
mcpBlock.moveBy(50, 50);
|
| 57 |
+
mcpBlock.render();
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
loadButton.addEventListener("click", () => {
|
| 61 |
+
const input = document.createElement('input');
|
| 62 |
+
let fileContent;
|
| 63 |
+
input.type = 'file';
|
| 64 |
+
input.accept = '.txt'; // Specify the file types you want to accept
|
| 65 |
+
input.onchange = function (event) {
|
| 66 |
+
const file = event.target.files[0];
|
| 67 |
+
const reader = new FileReader();
|
| 68 |
+
reader.onload = function (event) {
|
| 69 |
+
fileContent = JSON.parse(event.target.result); // Parse directly without decoding
|
| 70 |
+
Blockly.serialization.workspaces.load(fileContent, ws);
|
| 71 |
+
};
|
| 72 |
+
reader.readAsText(file);
|
| 73 |
+
};
|
| 74 |
+
input.click();
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
saveButton.addEventListener("click", () => {
|
| 78 |
+
const state = Blockly.serialization.workspaces.save(ws);
|
| 79 |
+
const stateString = JSON.stringify(state);
|
| 80 |
+
|
| 81 |
+
var filename = "mcpBlockly.txt";
|
| 82 |
+
var element = document.createElement('a');
|
| 83 |
+
|
| 84 |
+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(stateString));
|
| 85 |
+
element.setAttribute('download', filename);
|
| 86 |
+
element.style.display = 'none';
|
| 87 |
+
document.body.appendChild(element);
|
| 88 |
+
element.click();
|
| 89 |
+
document.body.removeChild(element);
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
undoButton.addEventListener("click", () => {
|
| 93 |
+
ws.undo(false);
|
| 94 |
+
});
|
| 95 |
+
|
| 96 |
+
redoButton.addEventListener("click", () => {
|
| 97 |
+
ws.undo(true);
|
| 98 |
+
});
|
| 99 |
+
|
| 100 |
+
cleanWorkspace.addEventListener("click", () => {
|
| 101 |
+
ws.cleanUp();
|
| 102 |
+
});
|
| 103 |
+
|
| 104 |
// Observe any size change to the blockly container
|
| 105 |
const observer = new ResizeObserver(() => {
|
| 106 |
Blockly.svgResize(ws);
|