tuple.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Blockly.Blocks['tuple_create'] = {
  2. /**
  3. * Block for creating a list with any number of elements of any type.
  4. * @this Blockly.Block
  5. */
  6. init: function() {
  7. this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);
  8. this.setColour(Blockly.Blocks.lists.HUE+10);
  9. this.itemCount_ = 3;
  10. this.updateShape_();
  11. this.setOutput(true, 'Tuple');
  12. this.setInputsInline(true);
  13. this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP);
  14. },
  15. /**
  16. * Create XML to represent list inputs.
  17. * @return {!Element} XML storage element.
  18. * @this Blockly.Block
  19. */
  20. mutationToDom: function() {
  21. var container = document.createElement('mutation');
  22. container.setAttribute('items', this.itemCount_);
  23. return container;
  24. },
  25. /**
  26. * Parse XML to restore the list inputs.
  27. * @param {!Element} xmlElement XML storage element.
  28. * @this Blockly.Block
  29. */
  30. domToMutation: function(xmlElement) {
  31. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  32. this.updateShape_();
  33. },
  34. /**
  35. * Modify this block to have the correct number of inputs.
  36. * @private
  37. * @this Blockly.Block
  38. */
  39. updateShape_: PLUS_MINUS_updateShape('ADD', "create tuple of")
  40. };