Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"packages/plugins/theme-tritanopia",
"packages/plugins/block-test",
"packages/plugins/dev-tools",
"packages/plugins/sample-app",
"packages/plugins/sample-app-ts",
"packages/plugins/field-grid-dropdown",
"packages/plugins/block-dynamic-connection",
"packages/plugins/block-plus-minus",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/dev-create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"templates/sample-app-ts/*"
],
"scripts": {
"prepack": "cp -r ../../examples/sample-app ./templates && cp -r ../../examples/sample-app-ts ./templates"
"prepack": "cp -r ../sample-app ./templates && cp -r ../sample-app-ts ./templates"
},
"homepage": "https://github.com/RaspberryPiFoundation/blockly/tree/main/packages/plugins/dev-create#readme",
"bugs": {
Expand Down
22 changes: 22 additions & 0 deletions packages/plugins/sample-app-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Dependency directories
node_modules/

# Generated files
dist/
build/
.DS_Store

# Optional npm cache directory
.npm

# IDEs and editors
.idea
*.sublime-workspace
.vscode/*
31 changes: 31 additions & 0 deletions packages/plugins/sample-app-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "sample-app-typescript",
"version": "1.0.0",
"description": "A sample app using Blockly",
"main": "index.js",
"private": true,
"scripts": {
"test": "echo \"Warning: no test specified\" && exit 0",
"build": "webpack --mode production",
"start": "webpack serve --open --mode development"
},
"keywords": [
"blockly"
],
"author": "Blockly team",
"license": "Apache-2.0",
"devDependencies": {
"css-loader": "^7.1.4",
"html-webpack-plugin": "^5.6.7",
"source-map-loader": "^5.0.0",
"style-loader": "^4.0.0",
"ts-loader": "^9.6.1",
"typescript": "^6.0.3",
"webpack": "^5.107.2",
"webpack-cli": "^7.0.3",
"webpack-dev-server": "^5.2.5"
},
"dependencies": {
"blockly": "^13.2.0"
}
}
35 changes: 35 additions & 0 deletions packages/plugins/sample-app-ts/src/blocks/text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import * as Blockly from 'blockly/core';

// Create a custom block called 'add_text' that adds
// text to the output div on the sample app.
// This is just an example and you should replace this with your
// own custom blocks.
const addText = {
type: 'add_text',
message0: 'Add text %1',
args0: [
{
type: 'input_value',
name: 'TEXT',
check: 'String',
},
],
previousStatement: null,
nextStatement: null,
colour: 160,
tooltip: '',
helpUrl: '',
};

// Create the block definitions for the JSON-only blocks.
// This does not register their definitions with Blockly.
// This file has no side effects!
export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([
addText,
]);
1 change: 1 addition & 0 deletions packages/plugins/sample-app-ts/src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.css';
34 changes: 34 additions & 0 deletions packages/plugins/sample-app-ts/src/generators/javascript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {Order} from 'blockly/javascript';
import * as Blockly from 'blockly/core';

// Export all the code generators for our custom blocks,
// but don't register them with Blockly yet.
// This file has no side effects!
export const forBlock = Object.create(null);

forBlock['add_text'] = function (
block: Blockly.Block,
generator: Blockly.CodeGenerator,
) {
const text = generator.valueToCode(block, 'TEXT', Order.NONE) || "''";
const addText = generator.provideFunction_(
'addText',
`function ${generator.FUNCTION_NAME_PLACEHOLDER_}(text) {

// Add text to the output area.
const outputDiv = document.getElementById('output');
const textEl = document.createElement('p');
textEl.innerText = text;
outputDiv.appendChild(textEl);
}`,
);
// Generate the function call for this block.
const code = `${addText}(${text});\n`;
return code;
};
40 changes: 40 additions & 0 deletions packages/plugins/sample-app-ts/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
body {
margin: 0;
max-width: 100vw;
}

pre,
code {
overflow: auto;
}

#pageContainer {
display: flex;
width: 100%;
max-width: 100vw;
height: 100vh;
}

#blocklyDiv {
flex-basis: 100%;
height: 100%;
min-width: 600px;
}

#outputPane {
display: flex;
flex-direction: column;
width: 400px;
flex: 0 0 400px;
overflow: auto;
margin: 1rem;
}

#generatedCode {
height: 50%;
background-color: rgb(247, 240, 228);
}

#output {
height: 50%;
}
16 changes: 16 additions & 0 deletions packages/plugins/sample-app-ts/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Blockly Sample App</title>
</head>
<body>
<div id="pageContainer">
<div id="outputPane">
<pre id="generatedCode"><code></code></pre>
<div id="output"></div>
</div>
<div id="blocklyDiv"></div>
</div>
</body>
</html>
Loading