File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,18 +12,13 @@ import * as Blockly from 'blockly/core';
1212// own custom blocks.
1313const addText = {
1414 type : 'add_text' ,
15- message0 : 'Add text %1 with color %2 ' ,
15+ message0 : 'Add text %1' ,
1616 args0 : [
1717 {
1818 type : 'input_value' ,
1919 name : 'TEXT' ,
2020 check : 'String' ,
2121 } ,
22- {
23- type : 'input_value' ,
24- name : 'COLOR' ,
25- check : 'Colour' ,
26- } ,
2722 ] ,
2823 previousStatement : null ,
2924 nextStatement : null ,
Original file line number Diff line number Diff line change @@ -17,22 +17,18 @@ forBlock['add_text'] = function (
1717 generator : Blockly . CodeGenerator ,
1818) {
1919 const text = generator . valueToCode ( block , 'TEXT' , Order . NONE ) || "''" ;
20- const color =
21- generator . valueToCode ( block , 'COLOR' , Order . ATOMIC ) || "'#ffffff'" ;
22-
2320 const addText = generator . provideFunction_ (
2421 'addText' ,
25- `function ${ generator . FUNCTION_NAME_PLACEHOLDER_ } (text, color ) {
22+ `function ${ generator . FUNCTION_NAME_PLACEHOLDER_ } (text) {
2623
2724 // Add text to the output area.
2825 const outputDiv = document.getElementById('output');
2926 const textEl = document.createElement('p');
3027 textEl.innerText = text;
31- textEl.style.color = color;
3228 outputDiv.appendChild(textEl);
3329}` ,
3430 ) ;
3531 // Generate the function call for this block.
36- const code = `${ addText } (${ text } , ${ color } );\n` ;
32+ const code = `${ addText } (${ text } );\n` ;
3733 return code ;
3834} ;
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ Object.assign(javascriptGenerator.forBlock, forBlock);
2020const codeDiv = document . getElementById ( 'generatedCode' ) ?. firstChild ;
2121const outputDiv = document . getElementById ( 'output' ) ;
2222const blocklyDiv = document . getElementById ( 'blocklyDiv' ) ;
23- const ws = blocklyDiv && Blockly . inject ( blocklyDiv , { toolbox} ) ;
23+
24+ if ( ! blocklyDiv ) {
25+ throw new Error ( `div with id 'blocklyDiv' not found` ) ;
26+ }
27+ const ws = Blockly . inject ( blocklyDiv , { toolbox} ) ;
2428
2529// This function resets the code and output divs, shows the
2630// generated code from the workspace, and evals the code.
Original file line number Diff line number Diff line change @@ -491,6 +491,20 @@ export const toolbox = {
491491 } ,
492492 } ,
493493 } ,
494+ {
495+ kind : 'block' ,
496+ type : 'add_text' ,
497+ inputs : {
498+ TEXT : {
499+ shadow : {
500+ type : 'text' ,
501+ fields : {
502+ TEXT : 'abc' ,
503+ } ,
504+ } ,
505+ } ,
506+ } ,
507+ } ,
494508 ] ,
495509 } ,
496510 {
Original file line number Diff line number Diff line change @@ -12,18 +12,13 @@ import * as Blockly from 'blockly/core';
1212// own custom blocks.
1313const addText = {
1414 type : 'add_text' ,
15- message0 : 'Add text %1 with color %2 ' ,
15+ message0 : 'Add text %1' ,
1616 args0 : [
1717 {
1818 type : 'input_value' ,
1919 name : 'TEXT' ,
2020 check : 'String' ,
2121 } ,
22- {
23- type : 'input_value' ,
24- name : 'COLOR' ,
25- check : 'Colour' ,
26- } ,
2722 ] ,
2823 previousStatement : null ,
2924 nextStatement : null ,
Original file line number Diff line number Diff line change @@ -13,22 +13,18 @@ export const forBlock = Object.create(null);
1313
1414forBlock [ 'add_text' ] = function ( block , generator ) {
1515 const text = generator . valueToCode ( block , 'TEXT' , Order . NONE ) || "''" ;
16- const color =
17- generator . valueToCode ( block , 'COLOR' , Order . ATOMIC ) || "'#ffffff'" ;
18-
1916 const addText = generator . provideFunction_ (
2017 'addText' ,
21- `function ${ generator . FUNCTION_NAME_PLACEHOLDER_ } (text, color ) {
18+ `function ${ generator . FUNCTION_NAME_PLACEHOLDER_ } (text) {
2219
2320 // Add text to the output area.
2421 const outputDiv = document.getElementById('output');
2522 const textEl = document.createElement('p');
2623 textEl.innerText = text;
27- textEl.style.color = color;
2824 outputDiv.appendChild(textEl);
2925}` ,
3026 ) ;
3127 // Generate the function call for this block.
32- const code = `${ addText } (${ text } , ${ color } );\n` ;
28+ const code = `${ addText } (${ text } );\n` ;
3329 return code ;
3430} ;
Original file line number Diff line number Diff line change @@ -491,6 +491,20 @@ export const toolbox = {
491491 } ,
492492 } ,
493493 } ,
494+ {
495+ kind : 'block' ,
496+ type : 'add_text' ,
497+ inputs : {
498+ TEXT : {
499+ shadow : {
500+ type : 'text' ,
501+ fields : {
502+ TEXT : 'abc' ,
503+ } ,
504+ } ,
505+ } ,
506+ } ,
507+ } ,
494508 ] ,
495509 } ,
496510 {
You can’t perform that action at this time.
0 commit comments