An Open Source Implementation of Svelte Components for Web Development using Google Blockly
This project provides Svelte components for visual programming using Google Blockly. It allows developers to create block-based programming interfaces within Svelte applications, making it easier to implement visual programming features in your web projects.
npm install svelte-web-blocks
<script>
import { BlocklyWorkspaceWithPreview } from 'svelte-web-blocks';
// Variables to store generated code
let htmlOutput = '';
let jsonOutput = '';
</script>
<BlocklyWorkspaceWithPreview
bind:generatedHtml={htmlOutput}
bind:generatedJson={jsonOutput}
/>
<script>
import { BlocklyWorkspaceWithPreview } from 'svelte-web-blocks';
// Variables to store generated code
let htmlOutput = '';
let jsonOutput = '';
// Function to log JSON to console
function logJson() {
console.log(JSON.parse(jsonOutput));
}
// Function to download JSON
function downloadJson() {
const blob = new Blob([jsonOutput], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'blockly-workspace.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
<div class="workspace-container">
<BlocklyWorkspaceWithPreview
bind:generatedHtml={htmlOutput}
bind:generatedJson={jsonOutput}
/>
</div>
<div class="json-actions">
<button on:click={logJson}>Log JSON to Console</button>
<button on:click={downloadJson}>Download JSON</button>
</div>
This package includes several example components demonstrating different use cases:
QuickStart.svelte
: Simple Blockly workspace setupBasicBlockly.svelte
: Convert Blockly to HTMLBlocklyToJson.svelte
: Convert Blockly to JSONJsonToBlocks.svelte
: Convert JSON structures to Blockly blocksHtmlToPug.svelte
: Transform HTML to PUGYou can view a live deployment of these examples here.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)This project is licensed under the MIT License - see the LICENSE file for details.