pilas-bloques-blocks
Advanced tools
Comparing version 0.0.3 to 0.0.5
{ | ||
"name": "pilas-bloques-blocks", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"description": "Block gallery used for Pilas Bloques challenges", | ||
"main": "pilas-bloques-blocks.js", | ||
"scripts": { | ||
"updatedemo": "cd docs && npm update --save && git add . && git commit -m \"updated demo\" && git push", | ||
"start": "cd docs && npm install && http-server", | ||
"updatedemo": "cd docs && npm install pilas-bloques-blocks@latest --save && git add . && git commit -m \"updated demo\" && git push", | ||
"publish:patch": "release patch && npm publish && npm run updatedemo" | ||
@@ -9,0 +10,0 @@ }, |
@@ -0,3 +1,5 @@ | ||
import Blockly from 'blockly' | ||
const blockBuilder = { | ||
createCustomBlock(name, options, callback_to_change_block) { | ||
createCustomBlock(name, options, callback_to_change_block) { | ||
options.colour = options.colour || '#4453ff'; | ||
@@ -58,5 +60,5 @@ | ||
this. | ||
appendDummyInput(). | ||
appendField(options.label || ""). | ||
appendField(new Blockly.FieldDropdown(options.callbackDropdown), 'DROPDOWN_VALUE'); | ||
appendDummyInput(). | ||
appendField(options.label || ""). | ||
appendField(new Blockly.FieldDropdown(options.callbackDropdown), 'DROPDOWN_VALUE'); | ||
} | ||
@@ -119,4 +121,4 @@ | ||
return Object.keys(Blockly.Blocks).filter((e) => { | ||
return Blockly.Blocks[e].isCustomBlock; | ||
} | ||
return Blockly.Blocks[e].isCustomBlock; | ||
} | ||
); | ||
@@ -145,2 +147,2 @@ }, | ||
export default blockBuilder; | ||
export default blockBuilder; |
@@ -0,4 +1,6 @@ | ||
import Blockly from 'blockly' | ||
const pbToolboxBuilder = { | ||
toolboxXmlFromBlockTypes(types, withCategories) { | ||
return this.toolboxXmlFromTree(this.toolboxTreeFromBlockTypes(types,withCategories)) | ||
return this.toolboxXmlFromTree(this.toolboxTreeFromBlockTypes(types, withCategories)) | ||
}, | ||
@@ -28,7 +30,5 @@ toolboxXmlFromTree(bloques) { | ||
if(Blockly.Blocks[bloque_en_categoria].toolbox) | ||
{ | ||
if (Blockly.Blocks[bloque_en_categoria].toolbox) { | ||
toolbox.push(Blockly.Blocks[bloque_en_categoria].toolbox); | ||
} | ||
else { | ||
} else { | ||
toolbox.push(` <block type="${bloque_en_categoria}"></block>`); | ||
@@ -80,3 +80,3 @@ } | ||
*/ | ||
toolboxTreeFromBlockTypes(bloques,conCategorias=true) { | ||
toolboxTreeFromBlockTypes(bloques, conCategorias = true) { | ||
@@ -100,14 +100,8 @@ if (bloques === undefined) { | ||
toolbox.push({ category: 'Separator', isSeparator: true }); | ||
toolbox.push({category: 'Separator', isSeparator: true}); | ||
return this._aplicarEstiloAToolbox(this.ordenar_toolbox(toolbox),conCategorias); | ||
return this._aplicarEstiloAToolbox(this.ordenar_toolbox(toolbox), conCategorias); | ||
}, | ||
/** | ||
* Dependiendo del desafío, puede pasar que sea necesario no mostrar las categorías | ||
* sino directamente los bloques en el toolbox. | ||
* | ||
* TODO: Falta implementar el estilo "desplegado" | ||
*/ | ||
_aplicarEstiloAToolbox(toolbox,conCategorias) { | ||
_aplicarEstiloAToolbox(toolbox, conCategorias) { | ||
var aplanado = toolbox; | ||
@@ -120,3 +114,3 @@ if (!conCategorias) { | ||
} else { | ||
aplanado = aplanado.concat(this._aplicarEstiloAToolbox(bloque.blocks,conCategorias)); | ||
aplanado = aplanado.concat(this._aplicarEstiloAToolbox(bloque.blocks, conCategorias)); | ||
} | ||
@@ -130,5 +124,5 @@ }); | ||
* Ordena la lista de ítems de un toolbox (usualmente categorias), por el orden | ||
* establecido en Pilas Bloques. | ||
* establecido en Pilas Bloques. | ||
* Las categorías que no están en la lista definida por Pilas Bloques, quedan al final. | ||
* @param {*} toolbox | ||
* @param {*} toolbox | ||
*/ | ||
@@ -150,11 +144,7 @@ ordenar_toolbox(toolbox) { | ||
return toolbox.sort((cat1, cat2) => | ||
orden_inicial.indexOf(cat1.category) >= orden_inicial.indexOf(cat2.category) | ||
orden_inicial.indexOf(cat1.category) >= orden_inicial.indexOf(cat2.category) | ||
); | ||
}, | ||
/** | ||
* Permite obtener el bloque desde blockly a partir de su nombre simple. | ||
* | ||
* TODO: Mover a ember-blockly. Debería estar dentro del servicio blockly. | ||
*/ | ||
_obtenerBloqueDesdeBlockly(bloqueComoString) { | ||
@@ -193,2 +183,2 @@ return Blockly.Blocks[bloqueComoString]; | ||
export default pbToolboxBuilder; | ||
export default pbToolboxBuilder; |
import blockBuilder from "./pbBlockBuilder.js" | ||
import Blockly from 'blockly' | ||
function shouldAddRequiredShadow(connection) { | ||
return connection.getShadowDom() == null // Should have not a shadow block | ||
&& [Blockly.INPUT_VALUE, Blockly.NEXT_STATEMENT].includes(connection.type) // Should be a "block hole" | ||
&& [Blockly.INPUT_VALUE, Blockly.NEXT_STATEMENT].includes(connection.type) // Should be a "block hole" | ||
} | ||
@@ -11,4 +12,4 @@ | ||
block.inputList | ||
.filter(input => input.connection && shouldAddRequiredShadow(input.connection)) | ||
.forEach(input => requiredInput(block, input.name)) | ||
.filter(input => input.connection && shouldAddRequiredShadow(input.connection)) | ||
.forEach(input => requiredInput(block, input.name)) | ||
} | ||
@@ -19,4 +20,4 @@ | ||
let shadowType = (connection.type == Blockly.INPUT_VALUE) | ||
? "required_value" | ||
: "required_statement" | ||
? "required_value" | ||
: "required_statement" | ||
var shadowValue = Blockly.Xml.textToDom(`<shadow type="${shadowType}"></shadow>`) | ||
@@ -52,3 +53,3 @@ connection.setShadowDom(shadowValue) | ||
return Object.getOwnPropertyNames(Blockly.Blocks).filter( | ||
prop => Blockly.Blocks[prop].categoria | ||
prop => Blockly.Blocks[prop].categoria | ||
); | ||
@@ -149,3 +150,2 @@ }, | ||
}); | ||
// TODO: Arreglar generacion de codigo | ||
bloque.categoria = "Sensores"; | ||
@@ -649,16 +649,16 @@ | ||
let bloque = blockBuilder.createCustomBlock('MoverA', { | ||
message0: "Mover a %1", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "input_value", | ||
"name": "direccion", | ||
} | ||
], | ||
code: 'hacer(actor_id, "MovimientoEnCuadricula", {direccionCasilla: $direccion});' | ||
}, | ||
function() { requiredAllInputs(this) } | ||
message0: "Mover a %1", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "input_value", | ||
"name": "direccion", | ||
} | ||
], | ||
code: 'hacer(actor_id, "MovimientoEnCuadricula", {direccionCasilla: $direccion});' | ||
}, | ||
function() { requiredAllInputs(this) } | ||
); | ||
@@ -743,23 +743,23 @@ | ||
blockBuilder.createCustomBlock('SaltarHaciaAdelante', { | ||
message0: "%1 Saltar hacia adelante %2", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.arriba.png`, | ||
"width": 16, | ||
"height": 20, | ||
"alt": "*" | ||
message0: "%1 Saltar hacia adelante %2", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.arriba.png`, | ||
"width": 16, | ||
"height": 20, | ||
"alt": "*" | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "longitud", | ||
} | ||
], | ||
code: 'hacer(actor_id, "SaltarHaciaAdelante", {distancia: $longitud, alturaDeseada: 50, velocidad_inicial: 20, nombreAnimacion: "saltar"});' | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "longitud", | ||
} | ||
], | ||
code: 'hacer(actor_id, "SaltarHaciaAdelante", {distancia: $longitud, alturaDeseada: 50, velocidad_inicial: 20, nombreAnimacion: "saltar"});' | ||
}, | ||
function() { requiredAllInputs(this) } | ||
function() { requiredAllInputs(this) } | ||
); | ||
@@ -779,23 +779,23 @@ | ||
blockBuilder.createCustomBlock('DibujarLado', { | ||
message0: "%1 Dibujar lado de %2", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.DibujarLinea.png`, | ||
"width": 16, | ||
"height": 16, | ||
"alt": "*" | ||
message0: "%1 Dibujar lado de %2", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.DibujarLinea.png`, | ||
"width": 16, | ||
"height": 16, | ||
"alt": "*" | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "longitud", | ||
} | ||
], | ||
code: 'hacer(actor_id, "DibujarHaciaAdelante", {distancia: $longitud, voltearAlIrAIzquierda: false, velocidad: 60});' | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "longitud", | ||
} | ||
], | ||
code: 'hacer(actor_id, "DibujarHaciaAdelante", {distancia: $longitud, voltearAlIrAIzquierda: false, velocidad: 60});' | ||
}, | ||
function() { requiredAllInputs(this) } | ||
function() { requiredAllInputs(this) } | ||
); | ||
@@ -889,26 +889,26 @@ | ||
blockBuilder.createCustomBlock('GirarGrados', { | ||
message0: "%1 Girar %2 grados", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.Girar.png`, | ||
"width": 16, | ||
"height": 16, | ||
"alt": "*" | ||
message0: "%1 Girar %2 grados", | ||
colour: Blockly.Blocks.primitivas.COLOUR, | ||
inputsInline: true, | ||
previousStatement: true, | ||
nextStatement: true, | ||
args0: [ | ||
{ | ||
"type": "field_image", | ||
"src": `${this.iconsPath}/icono.Girar.png`, | ||
"width": 16, | ||
"height": 16, | ||
"alt": "*" | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "grados", | ||
} | ||
], | ||
code: 'hacer(actor_id, "Rotar", {angulo: - ($grados), voltearAlIrAIzquierda: false, velocidad: 60});' | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "grados", | ||
} | ||
], | ||
code: 'hacer(actor_id, "Rotar", {angulo: - ($grados), voltearAlIrAIzquierda: false, velocidad: 60});' | ||
}, | ||
function() { requiredAllInputs(this) } | ||
function() { requiredAllInputs(this) } | ||
); | ||
Blockly.Blocks.GirarGrados.toolbox = ` | ||
@@ -1336,8 +1336,8 @@ <block type="GirarGrados"> | ||
this.appendValueInput('count') | ||
.setCheck('Number') | ||
.appendField('Repetir'); | ||
.setCheck('Number') | ||
.appendField('Repetir'); | ||
this.appendDummyInput() | ||
.appendField('veces'); | ||
.appendField('veces'); | ||
this.appendStatementInput('block'); | ||
requiredAllInputs(this); | ||
@@ -1366,4 +1366,4 @@ requiredAllInputs(this); | ||
this.appendValueInput('condition') | ||
.setCheck('Boolean') | ||
.appendField('Repetir hasta que'); | ||
.setCheck('Boolean') | ||
.appendField('Repetir hasta que'); | ||
this.appendStatementInput('block'); | ||
@@ -1384,4 +1384,4 @@ this.setPreviousStatement(true); | ||
this.appendValueInput('condition') | ||
.setCheck('Boolean') | ||
.appendField('Si'); | ||
.setCheck('Boolean') | ||
.appendField('Si'); | ||
this.setInputsInline(true); | ||
@@ -1402,8 +1402,8 @@ this.appendStatementInput('block'); | ||
this.appendValueInput('condition') | ||
.setCheck('Boolean') | ||
.appendField('Si'); | ||
.setCheck('Boolean') | ||
.appendField('Si'); | ||
this.appendStatementInput('block1'); | ||
this.setInputsInline(true); | ||
this.appendDummyInput() | ||
.appendField('si no'); | ||
.appendField('si no'); | ||
this.appendStatementInput('block2'); | ||
@@ -1429,3 +1429,3 @@ this.setPreviousStatement(true); | ||
Blockly.Blocks.procedures_callnoreturn.onchange = function () { | ||
requiredAllInputs(this) // Input fields are added after instantiation | ||
requiredAllInputs(this) // Input fields are added after instantiation | ||
}; | ||
@@ -1493,8 +1493,8 @@ | ||
this.setDisabled(!ok) | ||
var warning = | ||
(ok || isFlying(this) || !procedureDef) | ||
? null | ||
: (hasParam(procedureDef, this)) | ||
? `Este bloque no puede usarse aquí. Es un parámetro que sólo puede usarse en ${getName(procedureDef)}.` | ||
: "Este bloque ya no puede usarse, el parámetro ha sido eliminado." | ||
var warning = | ||
(ok || isFlying(this) || !procedureDef) | ||
? null | ||
: (hasParam(procedureDef, this)) | ||
? `Este bloque no puede usarse aquí. Es un parámetro que sólo puede usarse en ${getName(procedureDef)}.` | ||
: "Este bloque ya no puede usarse, el parámetro ha sido eliminado." | ||
this.setWarningText(warning) | ||
@@ -1538,3 +1538,3 @@ } | ||
var repeats = Blockly.MyLanguage.valueToCode(block, 'count', | ||
Blockly.MyLanguage.ORDER_ASSIGNMENT) || '0'; | ||
Blockly.MyLanguage.ORDER_ASSIGNMENT) || '0'; | ||
@@ -1546,13 +1546,13 @@ var branch = Blockly.MyLanguage.statementToCode(block, 'block'); | ||
var loopVar = Blockly.JavaScript.variableDB_.getDistinctName( | ||
'count', Blockly.Variables.NAME_TYPE); | ||
'count', Blockly.Variables.NAME_TYPE); | ||
var endVar = repeats; | ||
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) { | ||
endVar = Blockly.MyLanguage.variableDB_.getDistinctName( | ||
'repeat_end', Blockly.Variables.NAME_TYPE); | ||
'repeat_end', Blockly.Variables.NAME_TYPE); | ||
code += 'var ' + endVar + ' = ' + repeats + ';\n'; | ||
} | ||
code += 'for (var ' + loopVar + ' = 0; ' + | ||
loopVar + ' < ' + endVar + '; ' + | ||
loopVar + '++) {\n' + | ||
branch + '}\n'; | ||
loopVar + ' < ' + endVar + '; ' + | ||
loopVar + '++) {\n' + | ||
branch + '}\n'; | ||
return code; | ||
@@ -1597,37 +1597,37 @@ }; | ||
this.blockBuilder.createCustomBlock('OpAritmetica', { | ||
"type": "math_arithmetic", | ||
"message0": "%1 %2 %3", | ||
"args0": [ | ||
{ | ||
"type": "input_value", | ||
"name": "A", | ||
"check": "Number" | ||
"type": "math_arithmetic", | ||
"message0": "%1 %2 %3", | ||
"args0": [ | ||
{ | ||
"type": "input_value", | ||
"name": "A", | ||
"check": "Number" | ||
}, | ||
{ | ||
"type": "field_dropdown", | ||
"name": "OP", | ||
"options": [ | ||
["%{BKY_MATH_ADDITION_SYMBOL}", "ADD"], | ||
["%{BKY_MATH_SUBTRACTION_SYMBOL}", "MINUS"], | ||
["%{BKY_MATH_MULTIPLICATION_SYMBOL}", "MULTIPLY"], | ||
["%{BKY_MATH_DIVISION_SYMBOL}", "DIVIDE"], | ||
["%{BKY_MATH_POWER_SYMBOL}", "POWER"] | ||
] | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "B", | ||
"check": "Number" | ||
} | ||
], | ||
"inputsInline": true, | ||
"output": "Number", | ||
"colour": "%{BKY_MATH_HUE}", | ||
"helpUrl": "%{BKY_MATH_ARITHMETIC_HELPURL}", | ||
"extensions": ["math_op_tooltip"] | ||
}, | ||
{ | ||
"type": "field_dropdown", | ||
"name": "OP", | ||
"options": [ | ||
["%{BKY_MATH_ADDITION_SYMBOL}", "ADD"], | ||
["%{BKY_MATH_SUBTRACTION_SYMBOL}", "MINUS"], | ||
["%{BKY_MATH_MULTIPLICATION_SYMBOL}", "MULTIPLY"], | ||
["%{BKY_MATH_DIVISION_SYMBOL}", "DIVIDE"], | ||
["%{BKY_MATH_POWER_SYMBOL}", "POWER"] | ||
] | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "B", | ||
"check": "Number" | ||
function() { | ||
requiredAllInputs(this) | ||
requiredAllInputs(this) | ||
} | ||
], | ||
"inputsInline": true, | ||
"output": "Number", | ||
"colour": "%{BKY_MATH_HUE}", | ||
"helpUrl": "%{BKY_MATH_ARITHMETIC_HELPURL}", | ||
"extensions": ["math_op_tooltip"] | ||
}, | ||
function() { | ||
requiredAllInputs(this) | ||
requiredAllInputs(this) | ||
} | ||
); | ||
@@ -1672,38 +1672,38 @@ | ||
this.blockBuilder.createCustomBlock('OpComparacion', { | ||
"type": "logic_compare", | ||
"message0": "%1 %2 %3", | ||
"args0": [ | ||
{ | ||
"type": "input_value", | ||
"name": "A" | ||
"type": "logic_compare", | ||
"message0": "%1 %2 %3", | ||
"args0": [ | ||
{ | ||
"type": "input_value", | ||
"name": "A" | ||
}, | ||
{ | ||
"type": "field_dropdown", | ||
"name": "OP", | ||
"options": [ | ||
["=", "EQ"], | ||
["\u2260", "NEQ"], | ||
["\u200F<", "LT"], | ||
["\u200F\u2264", "LTE"], | ||
["\u200F>", "GT"], | ||
["\u200F\u2265", "GTE"] | ||
] | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "B" | ||
} | ||
], | ||
"inputsInline": true, | ||
"output": "Boolean", | ||
"style": "logic_blocks", | ||
"helpUrl": "%{BKY_LOGIC_COMPARE_HELPURL}", | ||
"extensions": ["logic_compare", "logic_op_tooltip"] | ||
}, | ||
{ | ||
"type": "field_dropdown", | ||
"name": "OP", | ||
"options": [ | ||
["=", "EQ"], | ||
["\u2260", "NEQ"], | ||
["\u200F<", "LT"], | ||
["\u200F\u2264", "LTE"], | ||
["\u200F>", "GT"], | ||
["\u200F\u2265", "GTE"] | ||
] | ||
}, | ||
{ | ||
"type": "input_value", | ||
"name": "B" | ||
function() { | ||
requiredAllInputs(this) | ||
requiredAllInputs(this) | ||
} | ||
], | ||
"inputsInline": true, | ||
"output": "Boolean", | ||
"style": "logic_blocks", | ||
"helpUrl": "%{BKY_LOGIC_COMPARE_HELPURL}", | ||
"extensions": ["logic_compare", "logic_op_tooltip"] | ||
}, | ||
function() { | ||
requiredAllInputs(this) | ||
requiredAllInputs(this) | ||
} | ||
); | ||
Blockly.MyLanguage.OpComparacion = function(block) { | ||
@@ -1726,3 +1726,3 @@ // Comparison operator. | ||
return [code, order]; | ||
}; | ||
}; | ||
@@ -1804,2 +1804,2 @@ Blockly.Blocks.OpComparacion.categoria = 'Operadores'; | ||
export default pbBlocks; | ||
export default pbBlocks; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239228
82
1822
1