How to use the blockly.Block function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miguel76 / SparqlBlocks / src / shims / shadowMorph.js View on Github external
*/
Blockly.FieldVariable.prototype.setValue = function(newValue) {
  if (newValue != this.value_) {
    var that = this;
    this.fieldHasChanged(this.value_, newValue, function() {
      that.value_ = newValue;
      that.setText(newValue);
    });
  }
};

/**
 * Set whether this block is a shadow block or not.
 * @param {boolean} shadow True if a shadow.
 */
Blockly.Block.prototype.setShadow = function(shadow) {
  if (this.isShadow_ != shadow) {
    Blockly.Events.fire(new Blockly.Events.Change(
      this, 'shadow', null, this.isShadow_, shadow));
    this.isShadow_ = shadow;
  }
};

/**
 * Run a change event.
 * @param {boolean} forward True if run forward, false if run backward (undo).
 */
Blockly.Events.Change.prototype.run = function(forward) {
  var workspace = Blockly.Workspace.getById(this.workspaceId);
  var block = workspace.getBlockById(this.blockId);
  if (!block) {
    console.warn("Can't change non-existant block: " + this.blockId);
github miguel76 / SparqlBlocks / src / blocks / text.js View on Github external
decompose: function(workspace) {
    var containerBlock = Blockly.Block.obtain(workspace,
                                           'sparql_text_create_join_container');
    containerBlock.initSvg();
    var connection = containerBlock.getInput('STACK').connection;
    for (var i = 0; i < this.itemCount_; i++) {
      var itemBlock = workspace.newBlock('sparql_text_create_join_item');
      itemBlock.initSvg();
      connection.connect(itemBlock.previousConnection);
      connection = itemBlock.nextConnection;
    }
    return containerBlock;
  },
  /**
github miguel76 / SparqlBlocks / src / shims / shadowMorph.js View on Github external
var morphShadowRec = function(block) {
  var parentBlock = block.getParent();
  if (parentBlock) {
    morphShadowRec(parentBlock);
  }
  block.setShadow(false);
};

/**
 * When a field changes, generate event and manage shadow state.
 * @param {Object} oldValue The old field value
 * @param {Object} newValue The new field value
 * @protected
 */
Blockly.Block.prototype.blockIsTargetOfConnection = function(childBlock, manageEvent) {
  var noGroup = false;
  if (Blockly.Events.recordUndo) {
    if (Blockly.Events.isEnabled()) {
      noGroup = true; //!Blockly.Events.getGroup();
      Blockly.Events.setGroup(true);
    }
    morphShadowRec(this);
  }
  manageEvent();
  if (noGroup) {
    Blockly.Events.setGroup(false);
  }
};

/**
 * When a field changes, generate event and manage shadow state.